]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.8.8-201304241907.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.8.8-201304241907.patch
CommitLineData
e25c7ebc
PK
1diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2index b89a739..b47493f 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,6 +75,7 @@ Image
45 Module.markers
46 Module.symvers
47 PENDING
48+PERF*
49 SCCS
50 System.map*
51 TAGS
52@@ -80,6 +87,7 @@ aic7*seq.h*
53 aicasm
54 aicdb.h*
55 altivec*.c
56+ashldi3.S
57 asm-offsets.h
58 asm_offsets.h
59 autoconf.h*
60@@ -92,19 +100,24 @@ bounds.h
61 bsetup
62 btfixupprep
63 build
64+builtin-policy.h
65 bvmlinux
66 bzImage*
67 capability_names.h
68 capflags.c
69 classlist.h*
70+clut_vga16.c
71+common-cmds.h
72 comp*.log
73 compile.h*
74 conf
75 config
76 config-*
77 config_data.h*
78+config.c
79 config.mak
80 config.mak.autogen
81+config.tmp
82 conmakehash
83 consolemap_deftbl.c*
84 cpustr.h
85@@ -115,9 +128,11 @@ devlist.h*
86 dnotify_test
87 docproc
88 dslm
89+dtc-lexer.lex.c
90 elf2ecoff
91 elfconfig.h*
92 evergreen_reg_safe.h
93+exception_policy.conf
94 fixdep
95 flask.h
96 fore200e_mkfirm
97@@ -125,12 +140,15 @@ fore200e_pca_fw.c*
98 gconf
99 gconf.glade.h
100 gen-devlist
101+gen-kdb_cmds.c
102 gen_crc32table
103 gen_init_cpio
104 generated
105 genheaders
106 genksyms
107 *_gray256.c
108+hash
109+hid-example
110 hpet_example
111 hugepage-mmap
112 hugepage-shm
113@@ -145,14 +163,14 @@ int32.c
114 int4.c
115 int8.c
116 kallsyms
117-kconfig
118+kern_constants.h
119 keywords.c
120 ksym.c*
121 ksym.h*
122 kxgettext
123 lex.c
124 lex.*.c
125-linux
126+lib1funcs.S
127 logo_*.c
128 logo_*_clut224.c
129 logo_*_mono.c
130@@ -162,14 +180,15 @@ mach-types.h
131 machtypes.h
132 map
133 map_hugetlb
134-media
135 mconf
136+mdp
137 miboot*
138 mk_elfconfig
139 mkboot
140 mkbugboot
141 mkcpustr
142 mkdep
143+mkpiggy
144 mkprep
145 mkregtable
146 mktables
147@@ -185,6 +204,8 @@ oui.c*
148 page-types
149 parse.c
150 parse.h
151+parse-events*
152+pasyms.h
153 patches*
154 pca200e.bin
155 pca200e_ecd.bin2
156@@ -194,6 +215,7 @@ perf-archive
157 piggyback
158 piggy.gzip
159 piggy.S
160+pmu-*
161 pnmtologo
162 ppc_defs.h*
163 pss_boot.h
164@@ -203,7 +225,10 @@ r200_reg_safe.h
165 r300_reg_safe.h
166 r420_reg_safe.h
167 r600_reg_safe.h
168+realmode.lds
169+realmode.relocs
170 recordmcount
171+regdb.c
172 relocs
173 rlim_names.h
174 rn50_reg_safe.h
175@@ -213,8 +238,12 @@ series
176 setup
177 setup.bin
178 setup.elf
179+signing_key*
180+size_overflow_hash.h
181 sImage
182+slabinfo
183 sm_tbl*
184+sortextable
185 split-include
186 syscalltab.h
187 tables.c
188@@ -224,6 +253,7 @@ tftpboot.img
189 timeconst.h
190 times.h*
191 trix_boot.h
192+user_constants.h
193 utsrelease.h*
194 vdso-syms.lds
195 vdso.lds
196@@ -235,13 +265,17 @@ vdso32.lds
197 vdso32.so.dbg
198 vdso64.lds
199 vdso64.so.dbg
200+vdsox32.lds
201+vdsox32-syms.lds
202 version.h*
203 vmImage
204 vmlinux
205 vmlinux-*
206 vmlinux.aout
207 vmlinux.bin.all
208+vmlinux.bin.bz2
209 vmlinux.lds
210+vmlinux.relocs
211 vmlinuz
212 voffset.h
213 vsyscall.lds
214@@ -249,9 +283,12 @@ vsyscall_32.lds
215 wanxlfw.inc
216 uImage
217 unifdef
218+utsrelease.h
219 wakeup.bin
220 wakeup.elf
221 wakeup.lds
222+x509*
223 zImage*
224 zconf.hash.c
225+zconf.lex.c
226 zoffset.h
227diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
228index 986614d..e8bfedc 100644
229--- a/Documentation/kernel-parameters.txt
230+++ b/Documentation/kernel-parameters.txt
231@@ -922,6 +922,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
232 Format: <unsigned int> such that (rxsize & ~0x1fffc0) == 0.
233 Default: 1024
234
235+ grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
236+ ignore grsecurity's /proc restrictions
237+
238+
239 hashdist= [KNL,NUMA] Large hashes allocated during boot
240 are distributed across NUMA nodes. Defaults on
241 for 64-bit NUMA, off otherwise.
242@@ -2121,6 +2125,18 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
243 the specified number of seconds. This is to be used if
244 your oopses keep scrolling off the screen.
245
246+ pax_nouderef [X86] disables UDEREF. Most likely needed under certain
247+ virtualization environments that don't cope well with the
248+ expand down segment used by UDEREF on X86-32 or the frequent
249+ page table updates on X86-64.
250+
251+ pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
252+
253+ pax_extra_latent_entropy
254+ Enable a very simple form of latent entropy extraction
255+ from the first 4GB of memory as the bootmem allocator
256+ passes the memory pages to the buddy allocator.
257+
258 pcbit= [HW,ISDN]
259
260 pcd. [PARIDE]
261diff --git a/Makefile b/Makefile
262index 7684f95..12f2f86 100644
263--- a/Makefile
264+++ b/Makefile
265@@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
266
267 HOSTCC = gcc
268 HOSTCXX = g++
269-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
270-HOSTCXXFLAGS = -O2
271+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
272+HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
273+HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
274
275 # Decide whether to build built-in, modular, or both.
276 # Normally, just do built-in.
277@@ -414,8 +415,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
278 # Rules shared between *config targets and build targets
279
280 # Basic helpers built in scripts/
281-PHONY += scripts_basic
282-scripts_basic:
283+PHONY += scripts_basic gcc-plugins
284+scripts_basic: gcc-plugins
285 $(Q)$(MAKE) $(build)=scripts/basic
286 $(Q)rm -f .tmp_quiet_recordmcount
287
288@@ -575,6 +576,65 @@ else
289 KBUILD_CFLAGS += -O2
290 endif
291
292+ifndef DISABLE_PAX_PLUGINS
293+ifeq ($(call cc-ifversion, -ge, 0408, y), y)
294+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
295+else
296+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
297+endif
298+ifneq ($(PLUGINCC),)
299+ifdef CONFIG_PAX_CONSTIFY_PLUGIN
300+CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
301+endif
302+ifdef CONFIG_PAX_MEMORY_STACKLEAK
303+STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
304+STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
305+endif
306+ifdef CONFIG_KALLOCSTAT_PLUGIN
307+KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
308+endif
309+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
310+KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
311+KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
312+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
313+endif
314+ifdef CONFIG_CHECKER_PLUGIN
315+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
316+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
317+endif
318+endif
319+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
320+ifdef CONFIG_PAX_SIZE_OVERFLOW
321+SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
322+endif
323+ifdef CONFIG_PAX_LATENT_ENTROPY
324+LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
325+endif
326+ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
327+STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
328+endif
329+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
330+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
331+GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
332+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
333+export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
334+ifeq ($(KBUILD_EXTMOD),)
335+gcc-plugins:
336+ $(Q)$(MAKE) $(build)=tools/gcc
337+else
338+gcc-plugins: ;
339+endif
340+else
341+gcc-plugins:
342+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
343+ $(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.))
344+else
345+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
346+endif
347+ $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
348+endif
349+endif
350+
351 include $(srctree)/arch/$(SRCARCH)/Makefile
352
353 ifdef CONFIG_READABLE_ASM
354@@ -731,7 +791,7 @@ export mod_sign_cmd
355
356
357 ifeq ($(KBUILD_EXTMOD),)
358-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
359+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
360
361 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
362 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
363@@ -778,6 +838,8 @@ endif
364
365 # The actual objects are generated when descending,
366 # make sure no implicit rule kicks in
367+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
368+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
369 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
370
371 # Handle descending into subdirectories listed in $(vmlinux-dirs)
372@@ -787,7 +849,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
373 # Error messages still appears in the original language
374
375 PHONY += $(vmlinux-dirs)
376-$(vmlinux-dirs): prepare scripts
377+$(vmlinux-dirs): gcc-plugins prepare scripts
378 $(Q)$(MAKE) $(build)=$@
379
380 # Store (new) KERNELRELASE string in include/config/kernel.release
381@@ -831,6 +893,7 @@ prepare0: archprepare FORCE
382 $(Q)$(MAKE) $(build)=.
383
384 # All the preparing..
385+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
386 prepare: prepare0
387
388 # Generate some files
389@@ -938,6 +1001,8 @@ all: modules
390 # using awk while concatenating to the final file.
391
392 PHONY += modules
393+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
394+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
395 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
396 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
397 @$(kecho) ' Building modules, stage 2.';
398@@ -953,7 +1018,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
399
400 # Target to prepare building external modules
401 PHONY += modules_prepare
402-modules_prepare: prepare scripts
403+modules_prepare: gcc-plugins prepare scripts
404
405 # Target to install modules
406 PHONY += modules_install
407@@ -1019,7 +1084,7 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
408 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
409 signing_key.priv signing_key.x509 x509.genkey \
410 extra_certificates signing_key.x509.keyid \
411- signing_key.x509.signer
412+ signing_key.x509.signer tools/gcc/size_overflow_hash.h
413
414 # clean - Delete most, but leave enough to build external modules
415 #
416@@ -1059,6 +1124,7 @@ distclean: mrproper
417 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
418 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
419 -o -name '.*.rej' \
420+ -o -name '.*.rej' -o -name '*.so' \
421 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
422 -type f -print | xargs rm -f
423
424@@ -1219,6 +1285,8 @@ PHONY += $(module-dirs) modules
425 $(module-dirs): crmodverdir $(objtree)/Module.symvers
426 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
427
428+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
429+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
430 modules: $(module-dirs)
431 @$(kecho) ' Building modules, stage 2.';
432 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
433@@ -1355,17 +1423,21 @@ else
434 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
435 endif
436
437-%.s: %.c prepare scripts FORCE
438+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
439+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
440+%.s: %.c gcc-plugins prepare scripts FORCE
441 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
442 %.i: %.c prepare scripts FORCE
443 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
444-%.o: %.c prepare scripts FORCE
445+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
446+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
447+%.o: %.c gcc-plugins prepare scripts FORCE
448 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
449 %.lst: %.c prepare scripts FORCE
450 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
451-%.s: %.S prepare scripts FORCE
452+%.s: %.S gcc-plugins prepare scripts FORCE
453 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
454-%.o: %.S prepare scripts FORCE
455+%.o: %.S gcc-plugins prepare scripts FORCE
456 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
457 %.symtypes: %.c prepare scripts FORCE
458 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
459@@ -1375,11 +1447,15 @@ endif
460 $(cmd_crmodverdir)
461 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
462 $(build)=$(build-dir)
463-%/: prepare scripts FORCE
464+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
465+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
466+%/: gcc-plugins prepare scripts FORCE
467 $(cmd_crmodverdir)
468 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
469 $(build)=$(build-dir)
470-%.ko: prepare scripts FORCE
471+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
472+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
473+%.ko: gcc-plugins prepare scripts FORCE
474 $(cmd_crmodverdir)
475 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
476 $(build)=$(build-dir) $(@:.ko=.o)
477diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
478index c2cbe4f..f7264b4 100644
479--- a/arch/alpha/include/asm/atomic.h
480+++ b/arch/alpha/include/asm/atomic.h
481@@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
482 #define atomic_dec(v) atomic_sub(1,(v))
483 #define atomic64_dec(v) atomic64_sub(1,(v))
484
485+#define atomic64_read_unchecked(v) atomic64_read(v)
486+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
487+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
488+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
489+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
490+#define atomic64_inc_unchecked(v) atomic64_inc(v)
491+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
492+#define atomic64_dec_unchecked(v) atomic64_dec(v)
493+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
494+
495 #define smp_mb__before_atomic_dec() smp_mb()
496 #define smp_mb__after_atomic_dec() smp_mb()
497 #define smp_mb__before_atomic_inc() smp_mb()
498diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
499index ad368a9..fbe0f25 100644
500--- a/arch/alpha/include/asm/cache.h
501+++ b/arch/alpha/include/asm/cache.h
502@@ -4,19 +4,19 @@
503 #ifndef __ARCH_ALPHA_CACHE_H
504 #define __ARCH_ALPHA_CACHE_H
505
506+#include <linux/const.h>
507
508 /* Bytes per L1 (data) cache line. */
509 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
510-# define L1_CACHE_BYTES 64
511 # define L1_CACHE_SHIFT 6
512 #else
513 /* Both EV4 and EV5 are write-through, read-allocate,
514 direct-mapped, physical.
515 */
516-# define L1_CACHE_BYTES 32
517 # define L1_CACHE_SHIFT 5
518 #endif
519
520+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
521 #define SMP_CACHE_BYTES L1_CACHE_BYTES
522
523 #endif
524diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
525index 968d999..d36b2df 100644
526--- a/arch/alpha/include/asm/elf.h
527+++ b/arch/alpha/include/asm/elf.h
528@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
529
530 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
531
532+#ifdef CONFIG_PAX_ASLR
533+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
534+
535+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
536+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
537+#endif
538+
539 /* $0 is set by ld.so to a pointer to a function which might be
540 registered using atexit. This provides a mean for the dynamic
541 linker to call DT_FINI functions for shared libraries that have
542diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
543index bc2a0da..8ad11ee 100644
544--- a/arch/alpha/include/asm/pgalloc.h
545+++ b/arch/alpha/include/asm/pgalloc.h
546@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
547 pgd_set(pgd, pmd);
548 }
549
550+static inline void
551+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
552+{
553+ pgd_populate(mm, pgd, pmd);
554+}
555+
556 extern pgd_t *pgd_alloc(struct mm_struct *mm);
557
558 static inline void
559diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
560index 81a4342..348b927 100644
561--- a/arch/alpha/include/asm/pgtable.h
562+++ b/arch/alpha/include/asm/pgtable.h
563@@ -102,6 +102,17 @@ struct vm_area_struct;
564 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
565 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
566 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
567+
568+#ifdef CONFIG_PAX_PAGEEXEC
569+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
570+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
571+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
572+#else
573+# define PAGE_SHARED_NOEXEC PAGE_SHARED
574+# define PAGE_COPY_NOEXEC PAGE_COPY
575+# define PAGE_READONLY_NOEXEC PAGE_READONLY
576+#endif
577+
578 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
579
580 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
581diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
582index 2fd00b7..cfd5069 100644
583--- a/arch/alpha/kernel/module.c
584+++ b/arch/alpha/kernel/module.c
585@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
586
587 /* The small sections were sorted to the end of the segment.
588 The following should definitely cover them. */
589- gp = (u64)me->module_core + me->core_size - 0x8000;
590+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
591 got = sechdrs[me->arch.gotsecindex].sh_addr;
592
593 for (i = 0; i < n; i++) {
594diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
595index 14db93e..47bed62 100644
596--- a/arch/alpha/kernel/osf_sys.c
597+++ b/arch/alpha/kernel/osf_sys.c
598@@ -1295,16 +1295,16 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
599 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
600
601 static unsigned long
602-arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
603- unsigned long limit)
604+arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
605+ unsigned long limit, unsigned long flags)
606 {
607 struct vm_area_struct *vma = find_vma(current->mm, addr);
608-
609+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
610 while (1) {
611 /* At this point: (!vma || addr < vma->vm_end). */
612 if (limit - len < addr)
613 return -ENOMEM;
614- if (!vma || addr + len <= vma->vm_start)
615+ if (check_heap_stack_gap(vma, addr, len, offset))
616 return addr;
617 addr = vma->vm_end;
618 vma = vma->vm_next;
619@@ -1340,20 +1340,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
620 merely specific addresses, but regions of memory -- perhaps
621 this feature should be incorporated into all ports? */
622
623+#ifdef CONFIG_PAX_RANDMMAP
624+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
625+#endif
626+
627 if (addr) {
628- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
629+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
630 if (addr != (unsigned long) -ENOMEM)
631 return addr;
632 }
633
634 /* Next, try allocating at TASK_UNMAPPED_BASE. */
635- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
636- len, limit);
637+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
638+
639 if (addr != (unsigned long) -ENOMEM)
640 return addr;
641
642 /* Finally, try allocating in low memory. */
643- addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
644+ addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
645
646 return addr;
647 }
648diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
649index 0c4132d..88f0d53 100644
650--- a/arch/alpha/mm/fault.c
651+++ b/arch/alpha/mm/fault.c
652@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
653 __reload_thread(pcb);
654 }
655
656+#ifdef CONFIG_PAX_PAGEEXEC
657+/*
658+ * PaX: decide what to do with offenders (regs->pc = fault address)
659+ *
660+ * returns 1 when task should be killed
661+ * 2 when patched PLT trampoline was detected
662+ * 3 when unpatched PLT trampoline was detected
663+ */
664+static int pax_handle_fetch_fault(struct pt_regs *regs)
665+{
666+
667+#ifdef CONFIG_PAX_EMUPLT
668+ int err;
669+
670+ do { /* PaX: patched PLT emulation #1 */
671+ unsigned int ldah, ldq, jmp;
672+
673+ err = get_user(ldah, (unsigned int *)regs->pc);
674+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
675+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
676+
677+ if (err)
678+ break;
679+
680+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
681+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
682+ jmp == 0x6BFB0000U)
683+ {
684+ unsigned long r27, addr;
685+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
686+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
687+
688+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
689+ err = get_user(r27, (unsigned long *)addr);
690+ if (err)
691+ break;
692+
693+ regs->r27 = r27;
694+ regs->pc = r27;
695+ return 2;
696+ }
697+ } while (0);
698+
699+ do { /* PaX: patched PLT emulation #2 */
700+ unsigned int ldah, lda, br;
701+
702+ err = get_user(ldah, (unsigned int *)regs->pc);
703+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
704+ err |= get_user(br, (unsigned int *)(regs->pc+8));
705+
706+ if (err)
707+ break;
708+
709+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
710+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
711+ (br & 0xFFE00000U) == 0xC3E00000U)
712+ {
713+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
714+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
715+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
716+
717+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
718+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
719+ return 2;
720+ }
721+ } while (0);
722+
723+ do { /* PaX: unpatched PLT emulation */
724+ unsigned int br;
725+
726+ err = get_user(br, (unsigned int *)regs->pc);
727+
728+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
729+ unsigned int br2, ldq, nop, jmp;
730+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
731+
732+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
733+ err = get_user(br2, (unsigned int *)addr);
734+ err |= get_user(ldq, (unsigned int *)(addr+4));
735+ err |= get_user(nop, (unsigned int *)(addr+8));
736+ err |= get_user(jmp, (unsigned int *)(addr+12));
737+ err |= get_user(resolver, (unsigned long *)(addr+16));
738+
739+ if (err)
740+ break;
741+
742+ if (br2 == 0xC3600000U &&
743+ ldq == 0xA77B000CU &&
744+ nop == 0x47FF041FU &&
745+ jmp == 0x6B7B0000U)
746+ {
747+ regs->r28 = regs->pc+4;
748+ regs->r27 = addr+16;
749+ regs->pc = resolver;
750+ return 3;
751+ }
752+ }
753+ } while (0);
754+#endif
755+
756+ return 1;
757+}
758+
759+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
760+{
761+ unsigned long i;
762+
763+ printk(KERN_ERR "PAX: bytes at PC: ");
764+ for (i = 0; i < 5; i++) {
765+ unsigned int c;
766+ if (get_user(c, (unsigned int *)pc+i))
767+ printk(KERN_CONT "???????? ");
768+ else
769+ printk(KERN_CONT "%08x ", c);
770+ }
771+ printk("\n");
772+}
773+#endif
774
775 /*
776 * This routine handles page faults. It determines the address,
777@@ -133,8 +251,29 @@ retry:
778 good_area:
779 si_code = SEGV_ACCERR;
780 if (cause < 0) {
781- if (!(vma->vm_flags & VM_EXEC))
782+ if (!(vma->vm_flags & VM_EXEC)) {
783+
784+#ifdef CONFIG_PAX_PAGEEXEC
785+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
786+ goto bad_area;
787+
788+ up_read(&mm->mmap_sem);
789+ switch (pax_handle_fetch_fault(regs)) {
790+
791+#ifdef CONFIG_PAX_EMUPLT
792+ case 2:
793+ case 3:
794+ return;
795+#endif
796+
797+ }
798+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
799+ do_group_exit(SIGKILL);
800+#else
801 goto bad_area;
802+#endif
803+
804+ }
805 } else if (!cause) {
806 /* Allow reads even for write-only mappings */
807 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
808diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
809index 67874b8..9aa2d62 100644
810--- a/arch/arm/Kconfig
811+++ b/arch/arm/Kconfig
812@@ -1427,6 +1427,16 @@ config ARM_ERRATA_775420
813 to deadlock. This workaround puts DSB before executing ISB if
814 an abort may occur on cache maintenance.
815
816+config ARM_ERRATA_798181
817+ bool "ARM errata: TLBI/DSB failure on Cortex-A15"
818+ depends on CPU_V7 && SMP
819+ help
820+ On Cortex-A15 (r0p0..r3p2) the TLBI*IS/DSB operations are not
821+ adequately shooting down all use of the old entries. This
822+ option enables the Linux kernel workaround for this erratum
823+ which sends an IPI to the CPUs that are running the same ASID
824+ as the one being invalidated.
825+
826 endmenu
827
828 source "arch/arm/common/Kconfig"
829@@ -1813,7 +1823,7 @@ config ALIGNMENT_TRAP
830
831 config UACCESS_WITH_MEMCPY
832 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
833- depends on MMU
834+ depends on MMU && !PAX_MEMORY_UDEREF
835 default y if CPU_FEROCEON
836 help
837 Implement faster copy_to_user and clear_user methods for CPU
838diff --git a/arch/arm/common/gic.c b/arch/arm/common/gic.c
839index 87dfa902..3a523fc 100644
840--- a/arch/arm/common/gic.c
841+++ b/arch/arm/common/gic.c
842@@ -81,7 +81,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
843 * Supported arch specific GIC irq extension.
844 * Default make them NULL.
845 */
846-struct irq_chip gic_arch_extn = {
847+irq_chip_no_const gic_arch_extn __read_only = {
848 .irq_eoi = NULL,
849 .irq_mask = NULL,
850 .irq_unmask = NULL,
851@@ -329,7 +329,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
852 chained_irq_exit(chip, desc);
853 }
854
855-static struct irq_chip gic_chip = {
856+static irq_chip_no_const gic_chip __read_only = {
857 .name = "GIC",
858 .irq_mask = gic_mask_irq,
859 .irq_unmask = gic_unmask_irq,
860diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
861index c79f61f..9ac0642 100644
862--- a/arch/arm/include/asm/atomic.h
863+++ b/arch/arm/include/asm/atomic.h
864@@ -17,17 +17,35 @@
865 #include <asm/barrier.h>
866 #include <asm/cmpxchg.h>
867
868+#ifdef CONFIG_GENERIC_ATOMIC64
869+#include <asm-generic/atomic64.h>
870+#endif
871+
872 #define ATOMIC_INIT(i) { (i) }
873
874 #ifdef __KERNEL__
875
876+#define _ASM_EXTABLE(from, to) \
877+" .pushsection __ex_table,\"a\"\n"\
878+" .align 3\n" \
879+" .long " #from ", " #to"\n" \
880+" .popsection"
881+
882 /*
883 * On ARM, ordinary assignment (str instruction) doesn't clear the local
884 * strex/ldrex monitor on some implementations. The reason we can use it for
885 * atomic_set() is the clrex or dummy strex done on every exception return.
886 */
887 #define atomic_read(v) (*(volatile int *)&(v)->counter)
888+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
889+{
890+ return v->counter;
891+}
892 #define atomic_set(v,i) (((v)->counter) = (i))
893+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
894+{
895+ v->counter = i;
896+}
897
898 #if __LINUX_ARM_ARCH__ >= 6
899
900@@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
901 int result;
902
903 __asm__ __volatile__("@ atomic_add\n"
904+"1: ldrex %1, [%3]\n"
905+" adds %0, %1, %4\n"
906+
907+#ifdef CONFIG_PAX_REFCOUNT
908+" bvc 3f\n"
909+"2: bkpt 0xf103\n"
910+"3:\n"
911+#endif
912+
913+" strex %1, %0, [%3]\n"
914+" teq %1, #0\n"
915+" bne 1b"
916+
917+#ifdef CONFIG_PAX_REFCOUNT
918+"\n4:\n"
919+ _ASM_EXTABLE(2b, 4b)
920+#endif
921+
922+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
923+ : "r" (&v->counter), "Ir" (i)
924+ : "cc");
925+}
926+
927+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
928+{
929+ unsigned long tmp;
930+ int result;
931+
932+ __asm__ __volatile__("@ atomic_add_unchecked\n"
933 "1: ldrex %0, [%3]\n"
934 " add %0, %0, %4\n"
935 " strex %1, %0, [%3]\n"
936@@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
937 smp_mb();
938
939 __asm__ __volatile__("@ atomic_add_return\n"
940+"1: ldrex %1, [%3]\n"
941+" adds %0, %1, %4\n"
942+
943+#ifdef CONFIG_PAX_REFCOUNT
944+" bvc 3f\n"
945+" mov %0, %1\n"
946+"2: bkpt 0xf103\n"
947+"3:\n"
948+#endif
949+
950+" strex %1, %0, [%3]\n"
951+" teq %1, #0\n"
952+" bne 1b"
953+
954+#ifdef CONFIG_PAX_REFCOUNT
955+"\n4:\n"
956+ _ASM_EXTABLE(2b, 4b)
957+#endif
958+
959+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
960+ : "r" (&v->counter), "Ir" (i)
961+ : "cc");
962+
963+ smp_mb();
964+
965+ return result;
966+}
967+
968+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
969+{
970+ unsigned long tmp;
971+ int result;
972+
973+ smp_mb();
974+
975+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
976 "1: ldrex %0, [%3]\n"
977 " add %0, %0, %4\n"
978 " strex %1, %0, [%3]\n"
979@@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
980 int result;
981
982 __asm__ __volatile__("@ atomic_sub\n"
983+"1: ldrex %1, [%3]\n"
984+" subs %0, %1, %4\n"
985+
986+#ifdef CONFIG_PAX_REFCOUNT
987+" bvc 3f\n"
988+"2: bkpt 0xf103\n"
989+"3:\n"
990+#endif
991+
992+" strex %1, %0, [%3]\n"
993+" teq %1, #0\n"
994+" bne 1b"
995+
996+#ifdef CONFIG_PAX_REFCOUNT
997+"\n4:\n"
998+ _ASM_EXTABLE(2b, 4b)
999+#endif
1000+
1001+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1002+ : "r" (&v->counter), "Ir" (i)
1003+ : "cc");
1004+}
1005+
1006+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1007+{
1008+ unsigned long tmp;
1009+ int result;
1010+
1011+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
1012 "1: ldrex %0, [%3]\n"
1013 " sub %0, %0, %4\n"
1014 " strex %1, %0, [%3]\n"
1015@@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1016 smp_mb();
1017
1018 __asm__ __volatile__("@ atomic_sub_return\n"
1019-"1: ldrex %0, [%3]\n"
1020-" sub %0, %0, %4\n"
1021+"1: ldrex %1, [%3]\n"
1022+" subs %0, %1, %4\n"
1023+
1024+#ifdef CONFIG_PAX_REFCOUNT
1025+" bvc 3f\n"
1026+" mov %0, %1\n"
1027+"2: bkpt 0xf103\n"
1028+"3:\n"
1029+#endif
1030+
1031 " strex %1, %0, [%3]\n"
1032 " teq %1, #0\n"
1033 " bne 1b"
1034+
1035+#ifdef CONFIG_PAX_REFCOUNT
1036+"\n4:\n"
1037+ _ASM_EXTABLE(2b, 4b)
1038+#endif
1039+
1040 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1041 : "r" (&v->counter), "Ir" (i)
1042 : "cc");
1043@@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1044 return oldval;
1045 }
1046
1047+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1048+{
1049+ unsigned long oldval, res;
1050+
1051+ smp_mb();
1052+
1053+ do {
1054+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1055+ "ldrex %1, [%3]\n"
1056+ "mov %0, #0\n"
1057+ "teq %1, %4\n"
1058+ "strexeq %0, %5, [%3]\n"
1059+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1060+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
1061+ : "cc");
1062+ } while (res);
1063+
1064+ smp_mb();
1065+
1066+ return oldval;
1067+}
1068+
1069 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1070 {
1071 unsigned long tmp, tmp2;
1072@@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1073
1074 return val;
1075 }
1076+
1077+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1078+{
1079+ return atomic_add_return(i, v);
1080+}
1081+
1082 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1083+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1084+{
1085+ (void) atomic_add_return(i, v);
1086+}
1087
1088 static inline int atomic_sub_return(int i, atomic_t *v)
1089 {
1090@@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1091 return val;
1092 }
1093 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1094+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1095+{
1096+ (void) atomic_sub_return(i, v);
1097+}
1098
1099 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1100 {
1101@@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1102 return ret;
1103 }
1104
1105+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1106+{
1107+ return atomic_cmpxchg(v, old, new);
1108+}
1109+
1110 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1111 {
1112 unsigned long flags;
1113@@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1114 #endif /* __LINUX_ARM_ARCH__ */
1115
1116 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1117+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1118+{
1119+ return xchg(&v->counter, new);
1120+}
1121
1122 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1123 {
1124@@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1125 }
1126
1127 #define atomic_inc(v) atomic_add(1, v)
1128+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1129+{
1130+ atomic_add_unchecked(1, v);
1131+}
1132 #define atomic_dec(v) atomic_sub(1, v)
1133+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1134+{
1135+ atomic_sub_unchecked(1, v);
1136+}
1137
1138 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1139+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1140+{
1141+ return atomic_add_return_unchecked(1, v) == 0;
1142+}
1143 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1144 #define atomic_inc_return(v) (atomic_add_return(1, v))
1145+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1146+{
1147+ return atomic_add_return_unchecked(1, v);
1148+}
1149 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1150 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1151
1152@@ -241,6 +428,14 @@ typedef struct {
1153 u64 __aligned(8) counter;
1154 } atomic64_t;
1155
1156+#ifdef CONFIG_PAX_REFCOUNT
1157+typedef struct {
1158+ u64 __aligned(8) counter;
1159+} atomic64_unchecked_t;
1160+#else
1161+typedef atomic64_t atomic64_unchecked_t;
1162+#endif
1163+
1164 #define ATOMIC64_INIT(i) { (i) }
1165
1166 static inline u64 atomic64_read(const atomic64_t *v)
1167@@ -256,6 +451,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1168 return result;
1169 }
1170
1171+static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1172+{
1173+ u64 result;
1174+
1175+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1176+" ldrexd %0, %H0, [%1]"
1177+ : "=&r" (result)
1178+ : "r" (&v->counter), "Qo" (v->counter)
1179+ );
1180+
1181+ return result;
1182+}
1183+
1184 static inline void atomic64_set(atomic64_t *v, u64 i)
1185 {
1186 u64 tmp;
1187@@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1188 : "cc");
1189 }
1190
1191+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1192+{
1193+ u64 tmp;
1194+
1195+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1196+"1: ldrexd %0, %H0, [%2]\n"
1197+" strexd %0, %3, %H3, [%2]\n"
1198+" teq %0, #0\n"
1199+" bne 1b"
1200+ : "=&r" (tmp), "=Qo" (v->counter)
1201+ : "r" (&v->counter), "r" (i)
1202+ : "cc");
1203+}
1204+
1205 static inline void atomic64_add(u64 i, atomic64_t *v)
1206 {
1207 u64 result;
1208@@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1209 __asm__ __volatile__("@ atomic64_add\n"
1210 "1: ldrexd %0, %H0, [%3]\n"
1211 " adds %0, %0, %4\n"
1212+" adcs %H0, %H0, %H4\n"
1213+
1214+#ifdef CONFIG_PAX_REFCOUNT
1215+" bvc 3f\n"
1216+"2: bkpt 0xf103\n"
1217+"3:\n"
1218+#endif
1219+
1220+" strexd %1, %0, %H0, [%3]\n"
1221+" teq %1, #0\n"
1222+" bne 1b"
1223+
1224+#ifdef CONFIG_PAX_REFCOUNT
1225+"\n4:\n"
1226+ _ASM_EXTABLE(2b, 4b)
1227+#endif
1228+
1229+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1230+ : "r" (&v->counter), "r" (i)
1231+ : "cc");
1232+}
1233+
1234+static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1235+{
1236+ u64 result;
1237+ unsigned long tmp;
1238+
1239+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1240+"1: ldrexd %0, %H0, [%3]\n"
1241+" adds %0, %0, %4\n"
1242 " adc %H0, %H0, %H4\n"
1243 " strexd %1, %0, %H0, [%3]\n"
1244 " teq %1, #0\n"
1245@@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1246
1247 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1248 {
1249- u64 result;
1250- unsigned long tmp;
1251+ u64 result, tmp;
1252
1253 smp_mb();
1254
1255 __asm__ __volatile__("@ atomic64_add_return\n"
1256+"1: ldrexd %1, %H1, [%3]\n"
1257+" adds %0, %1, %4\n"
1258+" adcs %H0, %H1, %H4\n"
1259+
1260+#ifdef CONFIG_PAX_REFCOUNT
1261+" bvc 3f\n"
1262+" mov %0, %1\n"
1263+" mov %H0, %H1\n"
1264+"2: bkpt 0xf103\n"
1265+"3:\n"
1266+#endif
1267+
1268+" strexd %1, %0, %H0, [%3]\n"
1269+" teq %1, #0\n"
1270+" bne 1b"
1271+
1272+#ifdef CONFIG_PAX_REFCOUNT
1273+"\n4:\n"
1274+ _ASM_EXTABLE(2b, 4b)
1275+#endif
1276+
1277+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1278+ : "r" (&v->counter), "r" (i)
1279+ : "cc");
1280+
1281+ smp_mb();
1282+
1283+ return result;
1284+}
1285+
1286+static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1287+{
1288+ u64 result;
1289+ unsigned long tmp;
1290+
1291+ smp_mb();
1292+
1293+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1294 "1: ldrexd %0, %H0, [%3]\n"
1295 " adds %0, %0, %4\n"
1296 " adc %H0, %H0, %H4\n"
1297@@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1298 __asm__ __volatile__("@ atomic64_sub\n"
1299 "1: ldrexd %0, %H0, [%3]\n"
1300 " subs %0, %0, %4\n"
1301+" sbcs %H0, %H0, %H4\n"
1302+
1303+#ifdef CONFIG_PAX_REFCOUNT
1304+" bvc 3f\n"
1305+"2: bkpt 0xf103\n"
1306+"3:\n"
1307+#endif
1308+
1309+" strexd %1, %0, %H0, [%3]\n"
1310+" teq %1, #0\n"
1311+" bne 1b"
1312+
1313+#ifdef CONFIG_PAX_REFCOUNT
1314+"\n4:\n"
1315+ _ASM_EXTABLE(2b, 4b)
1316+#endif
1317+
1318+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1319+ : "r" (&v->counter), "r" (i)
1320+ : "cc");
1321+}
1322+
1323+static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1324+{
1325+ u64 result;
1326+ unsigned long tmp;
1327+
1328+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1329+"1: ldrexd %0, %H0, [%3]\n"
1330+" subs %0, %0, %4\n"
1331 " sbc %H0, %H0, %H4\n"
1332 " strexd %1, %0, %H0, [%3]\n"
1333 " teq %1, #0\n"
1334@@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1335
1336 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1337 {
1338- u64 result;
1339- unsigned long tmp;
1340+ u64 result, tmp;
1341
1342 smp_mb();
1343
1344 __asm__ __volatile__("@ atomic64_sub_return\n"
1345-"1: ldrexd %0, %H0, [%3]\n"
1346-" subs %0, %0, %4\n"
1347-" sbc %H0, %H0, %H4\n"
1348+"1: ldrexd %1, %H1, [%3]\n"
1349+" subs %0, %1, %4\n"
1350+" sbcs %H0, %H1, %H4\n"
1351+
1352+#ifdef CONFIG_PAX_REFCOUNT
1353+" bvc 3f\n"
1354+" mov %0, %1\n"
1355+" mov %H0, %H1\n"
1356+"2: bkpt 0xf103\n"
1357+"3:\n"
1358+#endif
1359+
1360 " strexd %1, %0, %H0, [%3]\n"
1361 " teq %1, #0\n"
1362 " bne 1b"
1363+
1364+#ifdef CONFIG_PAX_REFCOUNT
1365+"\n4:\n"
1366+ _ASM_EXTABLE(2b, 4b)
1367+#endif
1368+
1369 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1370 : "r" (&v->counter), "r" (i)
1371 : "cc");
1372@@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1373 return oldval;
1374 }
1375
1376+static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1377+{
1378+ u64 oldval;
1379+ unsigned long res;
1380+
1381+ smp_mb();
1382+
1383+ do {
1384+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1385+ "ldrexd %1, %H1, [%3]\n"
1386+ "mov %0, #0\n"
1387+ "teq %1, %4\n"
1388+ "teqeq %H1, %H4\n"
1389+ "strexdeq %0, %5, %H5, [%3]"
1390+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1391+ : "r" (&ptr->counter), "r" (old), "r" (new)
1392+ : "cc");
1393+ } while (res);
1394+
1395+ smp_mb();
1396+
1397+ return oldval;
1398+}
1399+
1400 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1401 {
1402 u64 result;
1403@@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1404
1405 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1406 {
1407- u64 result;
1408- unsigned long tmp;
1409+ u64 result, tmp;
1410
1411 smp_mb();
1412
1413 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1414-"1: ldrexd %0, %H0, [%3]\n"
1415-" subs %0, %0, #1\n"
1416-" sbc %H0, %H0, #0\n"
1417+"1: ldrexd %1, %H1, [%3]\n"
1418+" subs %0, %1, #1\n"
1419+" sbcs %H0, %H1, #0\n"
1420+
1421+#ifdef CONFIG_PAX_REFCOUNT
1422+" bvc 3f\n"
1423+" mov %0, %1\n"
1424+" mov %H0, %H1\n"
1425+"2: bkpt 0xf103\n"
1426+"3:\n"
1427+#endif
1428+
1429 " teq %H0, #0\n"
1430-" bmi 2f\n"
1431+" bmi 4f\n"
1432 " strexd %1, %0, %H0, [%3]\n"
1433 " teq %1, #0\n"
1434 " bne 1b\n"
1435-"2:"
1436+"4:\n"
1437+
1438+#ifdef CONFIG_PAX_REFCOUNT
1439+ _ASM_EXTABLE(2b, 4b)
1440+#endif
1441+
1442 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1443 : "r" (&v->counter)
1444 : "cc");
1445@@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1446 " teq %0, %5\n"
1447 " teqeq %H0, %H5\n"
1448 " moveq %1, #0\n"
1449-" beq 2f\n"
1450+" beq 4f\n"
1451 " adds %0, %0, %6\n"
1452-" adc %H0, %H0, %H6\n"
1453+" adcs %H0, %H0, %H6\n"
1454+
1455+#ifdef CONFIG_PAX_REFCOUNT
1456+" bvc 3f\n"
1457+"2: bkpt 0xf103\n"
1458+"3:\n"
1459+#endif
1460+
1461 " strexd %2, %0, %H0, [%4]\n"
1462 " teq %2, #0\n"
1463 " bne 1b\n"
1464-"2:"
1465+"4:\n"
1466+
1467+#ifdef CONFIG_PAX_REFCOUNT
1468+ _ASM_EXTABLE(2b, 4b)
1469+#endif
1470+
1471 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1472 : "r" (&v->counter), "r" (u), "r" (a)
1473 : "cc");
1474@@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1475
1476 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1477 #define atomic64_inc(v) atomic64_add(1LL, (v))
1478+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1479 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1480+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1481 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1482 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1483 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1484+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1485 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1486 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1487 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1488diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1489index 75fe66b..ba3dee4 100644
1490--- a/arch/arm/include/asm/cache.h
1491+++ b/arch/arm/include/asm/cache.h
1492@@ -4,8 +4,10 @@
1493 #ifndef __ASMARM_CACHE_H
1494 #define __ASMARM_CACHE_H
1495
1496+#include <linux/const.h>
1497+
1498 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1499-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1500+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1501
1502 /*
1503 * Memory returned by kmalloc() may be used for DMA, so we must make
1504@@ -24,5 +26,6 @@
1505 #endif
1506
1507 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1508+#define __read_only __attribute__ ((__section__(".data..read_only")))
1509
1510 #endif
1511diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1512index e1489c5..d418304 100644
1513--- a/arch/arm/include/asm/cacheflush.h
1514+++ b/arch/arm/include/asm/cacheflush.h
1515@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1516 void (*dma_unmap_area)(const void *, size_t, int);
1517
1518 void (*dma_flush_range)(const void *, const void *);
1519-};
1520+} __no_const;
1521
1522 /*
1523 * Select the calling method
1524diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1525index 6dcc164..b14d917 100644
1526--- a/arch/arm/include/asm/checksum.h
1527+++ b/arch/arm/include/asm/checksum.h
1528@@ -37,7 +37,19 @@ __wsum
1529 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1530
1531 __wsum
1532-csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1533+__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1534+
1535+static inline __wsum
1536+csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1537+{
1538+ __wsum ret;
1539+ pax_open_userland();
1540+ ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1541+ pax_close_userland();
1542+ return ret;
1543+}
1544+
1545+
1546
1547 /*
1548 * Fold a partial checksum without adding pseudo headers
1549diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1550index 7eb18c1..e38b6d2 100644
1551--- a/arch/arm/include/asm/cmpxchg.h
1552+++ b/arch/arm/include/asm/cmpxchg.h
1553@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1554
1555 #define xchg(ptr,x) \
1556 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1557+#define xchg_unchecked(ptr,x) \
1558+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1559
1560 #include <asm-generic/cmpxchg-local.h>
1561
1562diff --git a/arch/arm/include/asm/delay.h b/arch/arm/include/asm/delay.h
1563index 720799f..2f67631 100644
1564--- a/arch/arm/include/asm/delay.h
1565+++ b/arch/arm/include/asm/delay.h
1566@@ -25,9 +25,9 @@ extern struct arm_delay_ops {
1567 void (*const_udelay)(unsigned long);
1568 void (*udelay)(unsigned long);
1569 bool const_clock;
1570-} arm_delay_ops;
1571+} *arm_delay_ops;
1572
1573-#define __delay(n) arm_delay_ops.delay(n)
1574+#define __delay(n) arm_delay_ops->delay(n)
1575
1576 /*
1577 * This function intentionally does not exist; if you see references to
1578@@ -48,8 +48,8 @@ extern void __bad_udelay(void);
1579 * first constant multiplications gets optimized away if the delay is
1580 * a constant)
1581 */
1582-#define __udelay(n) arm_delay_ops.udelay(n)
1583-#define __const_udelay(n) arm_delay_ops.const_udelay(n)
1584+#define __udelay(n) arm_delay_ops->udelay(n)
1585+#define __const_udelay(n) arm_delay_ops->const_udelay(n)
1586
1587 #define udelay(n) \
1588 (__builtin_constant_p(n) ? \
1589diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1590index 6ddbe44..b5e38b1 100644
1591--- a/arch/arm/include/asm/domain.h
1592+++ b/arch/arm/include/asm/domain.h
1593@@ -48,18 +48,37 @@
1594 * Domain types
1595 */
1596 #define DOMAIN_NOACCESS 0
1597-#define DOMAIN_CLIENT 1
1598 #ifdef CONFIG_CPU_USE_DOMAINS
1599+#define DOMAIN_USERCLIENT 1
1600+#define DOMAIN_KERNELCLIENT 1
1601 #define DOMAIN_MANAGER 3
1602+#define DOMAIN_VECTORS DOMAIN_USER
1603 #else
1604+
1605+#ifdef CONFIG_PAX_KERNEXEC
1606 #define DOMAIN_MANAGER 1
1607+#define DOMAIN_KERNEXEC 3
1608+#else
1609+#define DOMAIN_MANAGER 1
1610+#endif
1611+
1612+#ifdef CONFIG_PAX_MEMORY_UDEREF
1613+#define DOMAIN_USERCLIENT 0
1614+#define DOMAIN_UDEREF 1
1615+#define DOMAIN_VECTORS DOMAIN_KERNEL
1616+#else
1617+#define DOMAIN_USERCLIENT 1
1618+#define DOMAIN_VECTORS DOMAIN_USER
1619+#endif
1620+#define DOMAIN_KERNELCLIENT 1
1621+
1622 #endif
1623
1624 #define domain_val(dom,type) ((type) << (2*(dom)))
1625
1626 #ifndef __ASSEMBLY__
1627
1628-#ifdef CONFIG_CPU_USE_DOMAINS
1629+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1630 static inline void set_domain(unsigned val)
1631 {
1632 asm volatile(
1633@@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1634 isb();
1635 }
1636
1637-#define modify_domain(dom,type) \
1638- do { \
1639- struct thread_info *thread = current_thread_info(); \
1640- unsigned int domain = thread->cpu_domain; \
1641- domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1642- thread->cpu_domain = domain | domain_val(dom, type); \
1643- set_domain(thread->cpu_domain); \
1644- } while (0)
1645-
1646+extern void modify_domain(unsigned int dom, unsigned int type);
1647 #else
1648 static inline void set_domain(unsigned val) { }
1649 static inline void modify_domain(unsigned dom, unsigned type) { }
1650diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1651index 38050b1..9d90e8b 100644
1652--- a/arch/arm/include/asm/elf.h
1653+++ b/arch/arm/include/asm/elf.h
1654@@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1655 the loader. We need to make sure that it is out of the way of the program
1656 that it will "exec", and that there is sufficient room for the brk. */
1657
1658-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1659+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1660+
1661+#ifdef CONFIG_PAX_ASLR
1662+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1663+
1664+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1665+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1666+#endif
1667
1668 /* When the program starts, a1 contains a pointer to a function to be
1669 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1670@@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1671 extern void elf_set_personality(const struct elf32_hdr *);
1672 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1673
1674-struct mm_struct;
1675-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1676-#define arch_randomize_brk arch_randomize_brk
1677-
1678 #endif
1679diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1680index de53547..52b9a28 100644
1681--- a/arch/arm/include/asm/fncpy.h
1682+++ b/arch/arm/include/asm/fncpy.h
1683@@ -81,7 +81,9 @@
1684 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1685 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1686 \
1687+ pax_open_kernel(); \
1688 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1689+ pax_close_kernel(); \
1690 flush_icache_range((unsigned long)(dest_buf), \
1691 (unsigned long)(dest_buf) + (size)); \
1692 \
1693diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1694index e42cf59..7b94b8f 100644
1695--- a/arch/arm/include/asm/futex.h
1696+++ b/arch/arm/include/asm/futex.h
1697@@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1698 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1699 return -EFAULT;
1700
1701+ pax_open_userland();
1702+
1703 smp_mb();
1704 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1705 "1: ldrex %1, [%4]\n"
1706@@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1707 : "cc", "memory");
1708 smp_mb();
1709
1710+ pax_close_userland();
1711+
1712 *uval = val;
1713 return ret;
1714 }
1715@@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1716 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1717 return -EFAULT;
1718
1719+ pax_open_userland();
1720+
1721 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1722 "1: " TUSER(ldr) " %1, [%4]\n"
1723 " teq %1, %2\n"
1724@@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1725 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1726 : "cc", "memory");
1727
1728+ pax_close_userland();
1729+
1730 *uval = val;
1731 return ret;
1732 }
1733@@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1734 return -EFAULT;
1735
1736 pagefault_disable(); /* implies preempt_disable() */
1737+ pax_open_userland();
1738
1739 switch (op) {
1740 case FUTEX_OP_SET:
1741@@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1742 ret = -ENOSYS;
1743 }
1744
1745+ pax_close_userland();
1746 pagefault_enable(); /* subsumes preempt_enable() */
1747
1748 if (!ret) {
1749diff --git a/arch/arm/include/asm/hardware/gic.h b/arch/arm/include/asm/hardware/gic.h
1750index 4b1ce6c..bea3f73 100644
1751--- a/arch/arm/include/asm/hardware/gic.h
1752+++ b/arch/arm/include/asm/hardware/gic.h
1753@@ -34,9 +34,10 @@
1754
1755 #ifndef __ASSEMBLY__
1756 #include <linux/irqdomain.h>
1757+#include <linux/irq.h>
1758 struct device_node;
1759
1760-extern struct irq_chip gic_arch_extn;
1761+extern irq_chip_no_const gic_arch_extn;
1762
1763 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
1764 u32 offset, struct device_node *);
1765diff --git a/arch/arm/include/asm/highmem.h b/arch/arm/include/asm/highmem.h
1766index 8c5e828..91b99ab 100644
1767--- a/arch/arm/include/asm/highmem.h
1768+++ b/arch/arm/include/asm/highmem.h
1769@@ -41,6 +41,13 @@ extern void kunmap_high(struct page *page);
1770 #endif
1771 #endif
1772
1773+/*
1774+ * Needed to be able to broadcast the TLB invalidation for kmap.
1775+ */
1776+#ifdef CONFIG_ARM_ERRATA_798181
1777+#undef ARCH_NEEDS_KMAP_HIGH_GET
1778+#endif
1779+
1780 #ifdef ARCH_NEEDS_KMAP_HIGH_GET
1781 extern void *kmap_high_get(struct page *page);
1782 #else
1783diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1784index 83eb2f7..ed77159 100644
1785--- a/arch/arm/include/asm/kmap_types.h
1786+++ b/arch/arm/include/asm/kmap_types.h
1787@@ -4,6 +4,6 @@
1788 /*
1789 * This is the "bare minimum". AIO seems to require this.
1790 */
1791-#define KM_TYPE_NR 16
1792+#define KM_TYPE_NR 17
1793
1794 #endif
1795diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1796index 9e614a1..3302cca 100644
1797--- a/arch/arm/include/asm/mach/dma.h
1798+++ b/arch/arm/include/asm/mach/dma.h
1799@@ -22,7 +22,7 @@ struct dma_ops {
1800 int (*residue)(unsigned int, dma_t *); /* optional */
1801 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1802 const char *type;
1803-};
1804+} __do_const;
1805
1806 struct dma_struct {
1807 void *addr; /* single DMA address */
1808diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1809index 2fe141f..192dc01 100644
1810--- a/arch/arm/include/asm/mach/map.h
1811+++ b/arch/arm/include/asm/mach/map.h
1812@@ -27,13 +27,16 @@ struct map_desc {
1813 #define MT_MINICLEAN 6
1814 #define MT_LOW_VECTORS 7
1815 #define MT_HIGH_VECTORS 8
1816-#define MT_MEMORY 9
1817+#define MT_MEMORY_RWX 9
1818 #define MT_ROM 10
1819-#define MT_MEMORY_NONCACHED 11
1820+#define MT_MEMORY_NONCACHED_RX 11
1821 #define MT_MEMORY_DTCM 12
1822 #define MT_MEMORY_ITCM 13
1823 #define MT_MEMORY_SO 14
1824 #define MT_MEMORY_DMA_READY 15
1825+#define MT_MEMORY_RW 16
1826+#define MT_MEMORY_RX 17
1827+#define MT_MEMORY_NONCACHED_RW 18
1828
1829 #ifdef CONFIG_MMU
1830 extern void iotable_init(struct map_desc *, int);
1831diff --git a/arch/arm/include/asm/mmu_context.h b/arch/arm/include/asm/mmu_context.h
1832index 863a661..a7b85e0 100644
1833--- a/arch/arm/include/asm/mmu_context.h
1834+++ b/arch/arm/include/asm/mmu_context.h
1835@@ -27,6 +27,8 @@ void __check_vmalloc_seq(struct mm_struct *mm);
1836 void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk);
1837 #define init_new_context(tsk,mm) ({ atomic64_set(&mm->context.id, 0); 0; })
1838
1839+DECLARE_PER_CPU(atomic64_t, active_asids);
1840+
1841 #else /* !CONFIG_CPU_HAS_ASID */
1842
1843 #ifdef CONFIG_MMU
1844diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1845index 53426c6..c7baff3 100644
1846--- a/arch/arm/include/asm/outercache.h
1847+++ b/arch/arm/include/asm/outercache.h
1848@@ -35,7 +35,7 @@ struct outer_cache_fns {
1849 #endif
1850 void (*set_debug)(unsigned long);
1851 void (*resume)(void);
1852-};
1853+} __no_const;
1854
1855 #ifdef CONFIG_OUTER_CACHE
1856
1857diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1858index 812a494..71fc0b6 100644
1859--- a/arch/arm/include/asm/page.h
1860+++ b/arch/arm/include/asm/page.h
1861@@ -114,7 +114,7 @@ struct cpu_user_fns {
1862 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1863 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1864 unsigned long vaddr, struct vm_area_struct *vma);
1865-};
1866+} __no_const;
1867
1868 #ifdef MULTI_USER
1869 extern struct cpu_user_fns cpu_user;
1870diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1871index 943504f..c37a730 100644
1872--- a/arch/arm/include/asm/pgalloc.h
1873+++ b/arch/arm/include/asm/pgalloc.h
1874@@ -17,6 +17,7 @@
1875 #include <asm/processor.h>
1876 #include <asm/cacheflush.h>
1877 #include <asm/tlbflush.h>
1878+#include <asm/system_info.h>
1879
1880 #define check_pgt_cache() do { } while (0)
1881
1882@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1883 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1884 }
1885
1886+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1887+{
1888+ pud_populate(mm, pud, pmd);
1889+}
1890+
1891 #else /* !CONFIG_ARM_LPAE */
1892
1893 /*
1894@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1895 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1896 #define pmd_free(mm, pmd) do { } while (0)
1897 #define pud_populate(mm,pmd,pte) BUG()
1898+#define pud_populate_kernel(mm,pmd,pte) BUG()
1899
1900 #endif /* CONFIG_ARM_LPAE */
1901
1902@@ -126,6 +133,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1903 __free_page(pte);
1904 }
1905
1906+static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1907+{
1908+#ifdef CONFIG_ARM_LPAE
1909+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1910+#else
1911+ if (addr & SECTION_SIZE)
1912+ pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1913+ else
1914+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1915+#endif
1916+ flush_pmd_entry(pmdp);
1917+}
1918+
1919 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1920 pmdval_t prot)
1921 {
1922@@ -155,7 +175,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1923 static inline void
1924 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1925 {
1926- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1927+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1928 }
1929 #define pmd_pgtable(pmd) pmd_page(pmd)
1930
1931diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1932index 5cfba15..f415e1a 100644
1933--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1934+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1935@@ -20,12 +20,15 @@
1936 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1937 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1938 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1939+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1940 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1941 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1942 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1943+
1944 /*
1945 * - section
1946 */
1947+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1948 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1949 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1950 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1951@@ -37,6 +40,7 @@
1952 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1953 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1954 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1955+#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1956
1957 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1958 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1959@@ -66,6 +70,7 @@
1960 * - extended small page/tiny page
1961 */
1962 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1963+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1964 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1965 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1966 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1967diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1968index f97ee02..07f1be5 100644
1969--- a/arch/arm/include/asm/pgtable-2level.h
1970+++ b/arch/arm/include/asm/pgtable-2level.h
1971@@ -125,6 +125,7 @@
1972 #define L_PTE_XN (_AT(pteval_t, 1) << 9)
1973 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1974 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1975+#define L_PTE_PXN (_AT(pteval_t, 1) << 12) /* v7*/
1976
1977 /*
1978 * These are the memory types, defined to be compatible with
1979diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1980index d795282..a43ea90 100644
1981--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1982+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1983@@ -32,15 +32,18 @@
1984 #define PMD_TYPE_SECT (_AT(pmdval_t, 1) << 0)
1985 #define PMD_BIT4 (_AT(pmdval_t, 0))
1986 #define PMD_DOMAIN(x) (_AT(pmdval_t, 0))
1987+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 59) /* PXNTable */
1988
1989 /*
1990 * - section
1991 */
1992 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1993 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1994+#define PMD_SECT_RDONLY (_AT(pmdval_t, 1) << 7)
1995 #define PMD_SECT_S (_AT(pmdval_t, 3) << 8)
1996 #define PMD_SECT_AF (_AT(pmdval_t, 1) << 10)
1997 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 11)
1998+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 53)
1999 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 54)
2000 #define PMD_SECT_AP_WRITE (_AT(pmdval_t, 0))
2001 #define PMD_SECT_AP_READ (_AT(pmdval_t, 0))
2002@@ -66,6 +69,7 @@
2003 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
2004 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
2005 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
2006+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2007 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
2008
2009 /*
2010diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
2011index a3f3792..7b932a6 100644
2012--- a/arch/arm/include/asm/pgtable-3level.h
2013+++ b/arch/arm/include/asm/pgtable-3level.h
2014@@ -74,6 +74,7 @@
2015 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
2016 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
2017 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
2018+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2019 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
2020 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
2021 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
2022@@ -82,6 +83,7 @@
2023 /*
2024 * To be used in assembly code with the upper page attributes.
2025 */
2026+#define L_PTE_PXN_HIGH (1 << (53 - 32))
2027 #define L_PTE_XN_HIGH (1 << (54 - 32))
2028 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
2029
2030diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
2031index c094749..a6ff605 100644
2032--- a/arch/arm/include/asm/pgtable.h
2033+++ b/arch/arm/include/asm/pgtable.h
2034@@ -30,6 +30,9 @@
2035 #include <asm/pgtable-2level.h>
2036 #endif
2037
2038+#define ktla_ktva(addr) (addr)
2039+#define ktva_ktla(addr) (addr)
2040+
2041 /*
2042 * Just any arbitrary offset to the start of the vmalloc VM area: the
2043 * current 8MB value just means that there will be a 8MB "hole" after the
2044@@ -45,6 +48,9 @@
2045 #define LIBRARY_TEXT_START 0x0c000000
2046
2047 #ifndef __ASSEMBLY__
2048+extern pteval_t __supported_pte_mask;
2049+extern pmdval_t __supported_pmd_mask;
2050+
2051 extern void __pte_error(const char *file, int line, pte_t);
2052 extern void __pmd_error(const char *file, int line, pmd_t);
2053 extern void __pgd_error(const char *file, int line, pgd_t);
2054@@ -53,6 +59,50 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2055 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2056 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2057
2058+#define __HAVE_ARCH_PAX_OPEN_KERNEL
2059+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2060+
2061+#ifdef CONFIG_PAX_KERNEXEC
2062+#include <asm/domain.h>
2063+#include <linux/thread_info.h>
2064+#include <linux/preempt.h>
2065+#endif
2066+
2067+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2068+static inline int test_domain(int domain, int domaintype)
2069+{
2070+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2071+}
2072+#endif
2073+
2074+#ifdef CONFIG_PAX_KERNEXEC
2075+static inline unsigned long pax_open_kernel(void) {
2076+#ifdef CONFIG_ARM_LPAE
2077+ /* TODO */
2078+#else
2079+ preempt_disable();
2080+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2081+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2082+#endif
2083+ return 0;
2084+}
2085+
2086+static inline unsigned long pax_close_kernel(void) {
2087+#ifdef CONFIG_ARM_LPAE
2088+ /* TODO */
2089+#else
2090+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2091+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
2092+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2093+ preempt_enable_no_resched();
2094+#endif
2095+ return 0;
2096+}
2097+#else
2098+static inline unsigned long pax_open_kernel(void) { return 0; }
2099+static inline unsigned long pax_close_kernel(void) { return 0; }
2100+#endif
2101+
2102 /*
2103 * This is the lowest virtual address we can permit any user space
2104 * mapping to be mapped at. This is particularly important for
2105@@ -63,8 +113,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2106 /*
2107 * The pgprot_* and protection_map entries will be fixed up in runtime
2108 * to include the cachable and bufferable bits based on memory policy,
2109- * as well as any architecture dependent bits like global/ASID and SMP
2110- * shared mapping bits.
2111+ * as well as any architecture dependent bits like global/ASID, PXN,
2112+ * and SMP shared mapping bits.
2113 */
2114 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2115
2116@@ -241,7 +291,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2117 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2118 {
2119 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2120- L_PTE_NONE | L_PTE_VALID;
2121+ L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2122 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2123 return pte;
2124 }
2125diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
2126index f3628fb..a0672dd 100644
2127--- a/arch/arm/include/asm/proc-fns.h
2128+++ b/arch/arm/include/asm/proc-fns.h
2129@@ -75,7 +75,7 @@ extern struct processor {
2130 unsigned int suspend_size;
2131 void (*do_suspend)(void *);
2132 void (*do_resume)(void *);
2133-} processor;
2134+} __do_const processor;
2135
2136 #ifndef MULTI_CPU
2137 extern void cpu_proc_init(void);
2138diff --git a/arch/arm/include/asm/processor.h b/arch/arm/include/asm/processor.h
2139index 06e7d50..8a8e251 100644
2140--- a/arch/arm/include/asm/processor.h
2141+++ b/arch/arm/include/asm/processor.h
2142@@ -65,9 +65,8 @@ struct thread_struct {
2143 regs->ARM_cpsr |= PSR_ENDSTATE; \
2144 regs->ARM_pc = pc & ~1; /* pc */ \
2145 regs->ARM_sp = sp; /* sp */ \
2146- regs->ARM_r2 = stack[2]; /* r2 (envp) */ \
2147- regs->ARM_r1 = stack[1]; /* r1 (argv) */ \
2148- regs->ARM_r0 = stack[0]; /* r0 (argc) */ \
2149+ /* r2 (envp), r1 (argv), r0 (argc) */ \
2150+ (void)copy_from_user(&regs->ARM_r0, (const char __user *)stack, 3 * sizeof(unsigned long)); \
2151 nommu_start_thread(regs); \
2152 })
2153
2154diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2155index d3a22be..3a69ad5 100644
2156--- a/arch/arm/include/asm/smp.h
2157+++ b/arch/arm/include/asm/smp.h
2158@@ -107,7 +107,7 @@ struct smp_operations {
2159 int (*cpu_disable)(unsigned int cpu);
2160 #endif
2161 #endif
2162-};
2163+} __no_const;
2164
2165 /*
2166 * set platform specific SMP operations
2167diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2168index cddda1f..ff357f7 100644
2169--- a/arch/arm/include/asm/thread_info.h
2170+++ b/arch/arm/include/asm/thread_info.h
2171@@ -77,9 +77,9 @@ struct thread_info {
2172 .flags = 0, \
2173 .preempt_count = INIT_PREEMPT_COUNT, \
2174 .addr_limit = KERNEL_DS, \
2175- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2176- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2177- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2178+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2179+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2180+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2181 .restart_block = { \
2182 .fn = do_no_restart_syscall, \
2183 }, \
2184@@ -152,6 +152,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2185 #define TIF_SYSCALL_AUDIT 9
2186 #define TIF_SYSCALL_TRACEPOINT 10
2187 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2188+
2189+/* within 8 bits of TIF_SYSCALL_TRACE
2190+ * to meet flexible second operand requirements
2191+ */
2192+#define TIF_GRSEC_SETXID 12
2193+
2194 #define TIF_USING_IWMMXT 17
2195 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2196 #define TIF_RESTORE_SIGMASK 20
2197@@ -165,10 +171,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2198 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2199 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2200 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2201+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2202
2203 /* Checks for any syscall work in entry-common.S */
2204 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2205- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2206+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2207
2208 /*
2209 * Change these and you break ASM code in entry-common.S
2210diff --git a/arch/arm/include/asm/tlbflush.h b/arch/arm/include/asm/tlbflush.h
2211index 6e924d3..a9f3ddf 100644
2212--- a/arch/arm/include/asm/tlbflush.h
2213+++ b/arch/arm/include/asm/tlbflush.h
2214@@ -430,6 +430,21 @@ static inline void local_flush_tlb_kernel_page(unsigned long kaddr)
2215 }
2216 }
2217
2218+#ifdef CONFIG_ARM_ERRATA_798181
2219+static inline void dummy_flush_tlb_a15_erratum(void)
2220+{
2221+ /*
2222+ * Dummy TLBIMVAIS. Using the unmapped address 0 and ASID 0.
2223+ */
2224+ asm("mcr p15, 0, %0, c8, c3, 1" : : "r" (0));
2225+ dsb();
2226+}
2227+#else
2228+static inline void dummy_flush_tlb_a15_erratum(void)
2229+{
2230+}
2231+#endif
2232+
2233 /*
2234 * flush_pmd_entry
2235 *
2236diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2237index 7e1f760..752fcb7 100644
2238--- a/arch/arm/include/asm/uaccess.h
2239+++ b/arch/arm/include/asm/uaccess.h
2240@@ -18,6 +18,7 @@
2241 #include <asm/domain.h>
2242 #include <asm/unified.h>
2243 #include <asm/compiler.h>
2244+#include <asm/pgtable.h>
2245
2246 #define VERIFY_READ 0
2247 #define VERIFY_WRITE 1
2248@@ -60,10 +61,34 @@ extern int __put_user_bad(void);
2249 #define USER_DS TASK_SIZE
2250 #define get_fs() (current_thread_info()->addr_limit)
2251
2252+static inline void pax_open_userland(void)
2253+{
2254+
2255+#ifdef CONFIG_PAX_MEMORY_UDEREF
2256+ if (get_fs() == USER_DS) {
2257+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2258+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2259+ }
2260+#endif
2261+
2262+}
2263+
2264+static inline void pax_close_userland(void)
2265+{
2266+
2267+#ifdef CONFIG_PAX_MEMORY_UDEREF
2268+ if (get_fs() == USER_DS) {
2269+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2270+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2271+ }
2272+#endif
2273+
2274+}
2275+
2276 static inline void set_fs(mm_segment_t fs)
2277 {
2278 current_thread_info()->addr_limit = fs;
2279- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2280+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2281 }
2282
2283 #define segment_eq(a,b) ((a) == (b))
2284@@ -143,8 +168,12 @@ extern int __get_user_4(void *);
2285
2286 #define get_user(x,p) \
2287 ({ \
2288+ int __e; \
2289 might_fault(); \
2290- __get_user_check(x,p); \
2291+ pax_open_userland(); \
2292+ __e = __get_user_check(x,p); \
2293+ pax_close_userland(); \
2294+ __e; \
2295 })
2296
2297 extern int __put_user_1(void *, unsigned int);
2298@@ -188,8 +217,12 @@ extern int __put_user_8(void *, unsigned long long);
2299
2300 #define put_user(x,p) \
2301 ({ \
2302+ int __e; \
2303 might_fault(); \
2304- __put_user_check(x,p); \
2305+ pax_open_userland(); \
2306+ __e = __put_user_check(x,p); \
2307+ pax_close_userland(); \
2308+ __e; \
2309 })
2310
2311 #else /* CONFIG_MMU */
2312@@ -230,13 +263,17 @@ static inline void set_fs(mm_segment_t fs)
2313 #define __get_user(x,ptr) \
2314 ({ \
2315 long __gu_err = 0; \
2316+ pax_open_userland(); \
2317 __get_user_err((x),(ptr),__gu_err); \
2318+ pax_close_userland(); \
2319 __gu_err; \
2320 })
2321
2322 #define __get_user_error(x,ptr,err) \
2323 ({ \
2324+ pax_open_userland(); \
2325 __get_user_err((x),(ptr),err); \
2326+ pax_close_userland(); \
2327 (void) 0; \
2328 })
2329
2330@@ -312,13 +349,17 @@ do { \
2331 #define __put_user(x,ptr) \
2332 ({ \
2333 long __pu_err = 0; \
2334+ pax_open_userland(); \
2335 __put_user_err((x),(ptr),__pu_err); \
2336+ pax_close_userland(); \
2337 __pu_err; \
2338 })
2339
2340 #define __put_user_error(x,ptr,err) \
2341 ({ \
2342+ pax_open_userland(); \
2343 __put_user_err((x),(ptr),err); \
2344+ pax_close_userland(); \
2345 (void) 0; \
2346 })
2347
2348@@ -418,11 +459,44 @@ do { \
2349
2350
2351 #ifdef CONFIG_MMU
2352-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2353-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2354+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2355+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2356+
2357+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2358+{
2359+ unsigned long ret;
2360+
2361+ check_object_size(to, n, false);
2362+ pax_open_userland();
2363+ ret = ___copy_from_user(to, from, n);
2364+ pax_close_userland();
2365+ return ret;
2366+}
2367+
2368+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2369+{
2370+ unsigned long ret;
2371+
2372+ check_object_size(from, n, true);
2373+ pax_open_userland();
2374+ ret = ___copy_to_user(to, from, n);
2375+ pax_close_userland();
2376+ return ret;
2377+}
2378+
2379 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2380-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2381+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2382 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2383+
2384+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2385+{
2386+ unsigned long ret;
2387+ pax_open_userland();
2388+ ret = ___clear_user(addr, n);
2389+ pax_close_userland();
2390+ return ret;
2391+}
2392+
2393 #else
2394 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2395 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2396@@ -431,6 +505,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2397
2398 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2399 {
2400+ if ((long)n < 0)
2401+ return n;
2402+
2403 if (access_ok(VERIFY_READ, from, n))
2404 n = __copy_from_user(to, from, n);
2405 else /* security hole - plug it */
2406@@ -440,6 +517,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2407
2408 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2409 {
2410+ if ((long)n < 0)
2411+ return n;
2412+
2413 if (access_ok(VERIFY_WRITE, to, n))
2414 n = __copy_to_user(to, from, n);
2415 return n;
2416diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2417index 96ee092..37f1844 100644
2418--- a/arch/arm/include/uapi/asm/ptrace.h
2419+++ b/arch/arm/include/uapi/asm/ptrace.h
2420@@ -73,7 +73,7 @@
2421 * ARMv7 groups of PSR bits
2422 */
2423 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2424-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2425+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2426 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2427 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2428
2429diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2430index 60d3b73..d27ee09 100644
2431--- a/arch/arm/kernel/armksyms.c
2432+++ b/arch/arm/kernel/armksyms.c
2433@@ -89,9 +89,9 @@ EXPORT_SYMBOL(__memzero);
2434 #ifdef CONFIG_MMU
2435 EXPORT_SYMBOL(copy_page);
2436
2437-EXPORT_SYMBOL(__copy_from_user);
2438-EXPORT_SYMBOL(__copy_to_user);
2439-EXPORT_SYMBOL(__clear_user);
2440+EXPORT_SYMBOL(___copy_from_user);
2441+EXPORT_SYMBOL(___copy_to_user);
2442+EXPORT_SYMBOL(___clear_user);
2443
2444 EXPORT_SYMBOL(__get_user_1);
2445 EXPORT_SYMBOL(__get_user_2);
2446diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2447index 0f82098..3dbd3ee 100644
2448--- a/arch/arm/kernel/entry-armv.S
2449+++ b/arch/arm/kernel/entry-armv.S
2450@@ -47,6 +47,87 @@
2451 9997:
2452 .endm
2453
2454+ .macro pax_enter_kernel
2455+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2456+ @ make aligned space for saved DACR
2457+ sub sp, sp, #8
2458+ @ save regs
2459+ stmdb sp!, {r1, r2}
2460+ @ read DACR from cpu_domain into r1
2461+ mov r2, sp
2462+ @ assume 8K pages, since we have to split the immediate in two
2463+ bic r2, r2, #(0x1fc0)
2464+ bic r2, r2, #(0x3f)
2465+ ldr r1, [r2, #TI_CPU_DOMAIN]
2466+ @ store old DACR on stack
2467+ str r1, [sp, #8]
2468+#ifdef CONFIG_PAX_KERNEXEC
2469+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2470+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2471+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2472+#endif
2473+#ifdef CONFIG_PAX_MEMORY_UDEREF
2474+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2475+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2476+#endif
2477+ @ write r1 to current_thread_info()->cpu_domain
2478+ str r1, [r2, #TI_CPU_DOMAIN]
2479+ @ write r1 to DACR
2480+ mcr p15, 0, r1, c3, c0, 0
2481+ @ instruction sync
2482+ instr_sync
2483+ @ restore regs
2484+ ldmia sp!, {r1, r2}
2485+#endif
2486+ .endm
2487+
2488+ .macro pax_open_userland
2489+#ifdef CONFIG_PAX_MEMORY_UDEREF
2490+ @ save regs
2491+ stmdb sp!, {r0, r1}
2492+ @ read DACR from cpu_domain into r1
2493+ mov r0, sp
2494+ @ assume 8K pages, since we have to split the immediate in two
2495+ bic r0, r0, #(0x1fc0)
2496+ bic r0, r0, #(0x3f)
2497+ ldr r1, [r0, #TI_CPU_DOMAIN]
2498+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2499+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2500+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2501+ @ write r1 to current_thread_info()->cpu_domain
2502+ str r1, [r0, #TI_CPU_DOMAIN]
2503+ @ write r1 to DACR
2504+ mcr p15, 0, r1, c3, c0, 0
2505+ @ instruction sync
2506+ instr_sync
2507+ @ restore regs
2508+ ldmia sp!, {r0, r1}
2509+#endif
2510+ .endm
2511+
2512+ .macro pax_close_userland
2513+#ifdef CONFIG_PAX_MEMORY_UDEREF
2514+ @ save regs
2515+ stmdb sp!, {r0, r1}
2516+ @ read DACR from cpu_domain into r1
2517+ mov r0, sp
2518+ @ assume 8K pages, since we have to split the immediate in two
2519+ bic r0, r0, #(0x1fc0)
2520+ bic r0, r0, #(0x3f)
2521+ ldr r1, [r0, #TI_CPU_DOMAIN]
2522+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2523+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2524+ @ write r1 to current_thread_info()->cpu_domain
2525+ str r1, [r0, #TI_CPU_DOMAIN]
2526+ @ write r1 to DACR
2527+ mcr p15, 0, r1, c3, c0, 0
2528+ @ instruction sync
2529+ instr_sync
2530+ @ restore regs
2531+ ldmia sp!, {r0, r1}
2532+#endif
2533+ .endm
2534+
2535 .macro pabt_helper
2536 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2537 #ifdef MULTI_PABORT
2538@@ -89,11 +170,15 @@
2539 * Invalid mode handlers
2540 */
2541 .macro inv_entry, reason
2542+
2543+ pax_enter_kernel
2544+
2545 sub sp, sp, #S_FRAME_SIZE
2546 ARM( stmib sp, {r1 - lr} )
2547 THUMB( stmia sp, {r0 - r12} )
2548 THUMB( str sp, [sp, #S_SP] )
2549 THUMB( str lr, [sp, #S_LR] )
2550+
2551 mov r1, #\reason
2552 .endm
2553
2554@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2555 .macro svc_entry, stack_hole=0
2556 UNWIND(.fnstart )
2557 UNWIND(.save {r0 - pc} )
2558+
2559+ pax_enter_kernel
2560+
2561 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2562+
2563 #ifdef CONFIG_THUMB2_KERNEL
2564 SPFIX( str r0, [sp] ) @ temporarily saved
2565 SPFIX( mov r0, sp )
2566@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2567 ldmia r0, {r3 - r5}
2568 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2569 mov r6, #-1 @ "" "" "" ""
2570+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2571+ @ offset sp by 8 as done in pax_enter_kernel
2572+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2573+#else
2574 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2575+#endif
2576 SPFIX( addeq r2, r2, #4 )
2577 str r3, [sp, #-4]! @ save the "real" r0 copied
2578 @ from the exception stack
2579@@ -359,6 +453,9 @@ ENDPROC(__pabt_svc)
2580 .macro usr_entry
2581 UNWIND(.fnstart )
2582 UNWIND(.cantunwind ) @ don't unwind the user space
2583+
2584+ pax_enter_kernel_user
2585+
2586 sub sp, sp, #S_FRAME_SIZE
2587 ARM( stmib sp, {r1 - r12} )
2588 THUMB( stmia sp, {r0 - r12} )
2589@@ -456,7 +553,9 @@ __und_usr:
2590 tst r3, #PSR_T_BIT @ Thumb mode?
2591 bne __und_usr_thumb
2592 sub r4, r2, #4 @ ARM instr at LR - 4
2593+ pax_open_userland
2594 1: ldrt r0, [r4]
2595+ pax_close_userland
2596 #ifdef CONFIG_CPU_ENDIAN_BE8
2597 rev r0, r0 @ little endian instruction
2598 #endif
2599@@ -491,10 +590,14 @@ __und_usr_thumb:
2600 */
2601 .arch armv6t2
2602 #endif
2603+ pax_open_userland
2604 2: ldrht r5, [r4]
2605+ pax_close_userland
2606 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2607 blo __und_usr_fault_16 @ 16bit undefined instruction
2608+ pax_open_userland
2609 3: ldrht r0, [r2]
2610+ pax_close_userland
2611 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2612 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2613 orr r0, r0, r5, lsl #16
2614@@ -733,7 +836,7 @@ ENTRY(__switch_to)
2615 THUMB( stmia ip!, {r4 - sl, fp} ) @ Store most regs on stack
2616 THUMB( str sp, [ip], #4 )
2617 THUMB( str lr, [ip], #4 )
2618-#ifdef CONFIG_CPU_USE_DOMAINS
2619+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC)
2620 ldr r6, [r2, #TI_CPU_DOMAIN]
2621 #endif
2622 set_tls r3, r4, r5
2623@@ -742,7 +845,7 @@ ENTRY(__switch_to)
2624 ldr r8, =__stack_chk_guard
2625 ldr r7, [r7, #TSK_STACK_CANARY]
2626 #endif
2627-#ifdef CONFIG_CPU_USE_DOMAINS
2628+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC)
2629 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2630 #endif
2631 mov r5, r0
2632diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2633index a6c301e..908821b 100644
2634--- a/arch/arm/kernel/entry-common.S
2635+++ b/arch/arm/kernel/entry-common.S
2636@@ -10,18 +10,46 @@
2637
2638 #include <asm/unistd.h>
2639 #include <asm/ftrace.h>
2640+#include <asm/domain.h>
2641 #include <asm/unwind.h>
2642
2643+#include "entry-header.S"
2644+
2645 #ifdef CONFIG_NEED_RET_TO_USER
2646 #include <mach/entry-macro.S>
2647 #else
2648 .macro arch_ret_to_user, tmp1, tmp2
2649+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2650+ @ save regs
2651+ stmdb sp!, {r1, r2}
2652+ @ read DACR from cpu_domain into r1
2653+ mov r2, sp
2654+ @ assume 8K pages, since we have to split the immediate in two
2655+ bic r2, r2, #(0x1fc0)
2656+ bic r2, r2, #(0x3f)
2657+ ldr r1, [r2, #TI_CPU_DOMAIN]
2658+#ifdef CONFIG_PAX_KERNEXEC
2659+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2660+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2661+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2662+#endif
2663+#ifdef CONFIG_PAX_MEMORY_UDEREF
2664+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2665+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2666+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2667+#endif
2668+ @ write r1 to current_thread_info()->cpu_domain
2669+ str r1, [r2, #TI_CPU_DOMAIN]
2670+ @ write r1 to DACR
2671+ mcr p15, 0, r1, c3, c0, 0
2672+ @ instruction sync
2673+ instr_sync
2674+ @ restore regs
2675+ ldmia sp!, {r1, r2}
2676+#endif
2677 .endm
2678 #endif
2679
2680-#include "entry-header.S"
2681-
2682-
2683 .align 5
2684 /*
2685 * This is the fast syscall return path. We do as little as
2686@@ -339,6 +367,7 @@ ENDPROC(ftrace_stub)
2687
2688 .align 5
2689 ENTRY(vector_swi)
2690+
2691 sub sp, sp, #S_FRAME_SIZE
2692 stmia sp, {r0 - r12} @ Calling r0 - r12
2693 ARM( add r8, sp, #S_PC )
2694@@ -388,6 +417,12 @@ ENTRY(vector_swi)
2695 ldr scno, [lr, #-4] @ get SWI instruction
2696 #endif
2697
2698+ /*
2699+ * do this here to avoid a performance hit of wrapping the code above
2700+ * that directly dereferences userland to parse the SWI instruction
2701+ */
2702+ pax_enter_kernel_user
2703+
2704 #ifdef CONFIG_ALIGNMENT_TRAP
2705 ldr ip, __cr_alignment
2706 ldr ip, [ip]
2707diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2708index 9a8531e..812e287 100644
2709--- a/arch/arm/kernel/entry-header.S
2710+++ b/arch/arm/kernel/entry-header.S
2711@@ -73,9 +73,66 @@
2712 msr cpsr_c, \rtemp @ switch back to the SVC mode
2713 .endm
2714
2715+ .macro pax_enter_kernel_user
2716+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2717+ @ save regs
2718+ stmdb sp!, {r0, r1}
2719+ @ read DACR from cpu_domain into r1
2720+ mov r0, sp
2721+ @ assume 8K pages, since we have to split the immediate in two
2722+ bic r0, r0, #(0x1fc0)
2723+ bic r0, r0, #(0x3f)
2724+ ldr r1, [r0, #TI_CPU_DOMAIN]
2725+#ifdef CONFIG_PAX_MEMORY_UDEREF
2726+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2727+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2728+#endif
2729+#ifdef CONFIG_PAX_KERNEXEC
2730+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2731+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2732+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2733+#endif
2734+ @ write r1 to current_thread_info()->cpu_domain
2735+ str r1, [r0, #TI_CPU_DOMAIN]
2736+ @ write r1 to DACR
2737+ mcr p15, 0, r1, c3, c0, 0
2738+ @ instruction sync
2739+ instr_sync
2740+ @ restore regs
2741+ ldmia sp!, {r0, r1}
2742+#endif
2743+ .endm
2744+
2745+ .macro pax_exit_kernel
2746+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2747+ @ save regs
2748+ stmdb sp!, {r0, r1}
2749+ @ read old DACR from stack into r1
2750+ ldr r1, [sp, #(8 + S_SP)]
2751+ sub r1, r1, #8
2752+ ldr r1, [r1]
2753+
2754+ @ write r1 to current_thread_info()->cpu_domain
2755+ mov r0, sp
2756+ @ assume 8K pages, since we have to split the immediate in two
2757+ bic r0, r0, #(0x1fc0)
2758+ bic r0, r0, #(0x3f)
2759+ str r1, [r0, #TI_CPU_DOMAIN]
2760+ @ write r1 to DACR
2761+ mcr p15, 0, r1, c3, c0, 0
2762+ @ instruction sync
2763+ instr_sync
2764+ @ restore regs
2765+ ldmia sp!, {r0, r1}
2766+#endif
2767+ .endm
2768+
2769 #ifndef CONFIG_THUMB2_KERNEL
2770 .macro svc_exit, rpsr
2771 msr spsr_cxsf, \rpsr
2772+
2773+ pax_exit_kernel
2774+
2775 #if defined(CONFIG_CPU_V6)
2776 ldr r0, [sp]
2777 strex r1, r2, [sp] @ clear the exclusive monitor
2778@@ -121,6 +178,9 @@
2779 .endm
2780 #else /* CONFIG_THUMB2_KERNEL */
2781 .macro svc_exit, rpsr
2782+
2783+ pax_exit_kernel
2784+
2785 ldr lr, [sp, #S_SP] @ top of the stack
2786 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2787 clrex @ clear the exclusive monitor
2788diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2789index 2adda11..7fbe958 100644
2790--- a/arch/arm/kernel/fiq.c
2791+++ b/arch/arm/kernel/fiq.c
2792@@ -82,7 +82,9 @@ void set_fiq_handler(void *start, unsigned int length)
2793 #if defined(CONFIG_CPU_USE_DOMAINS)
2794 memcpy((void *)0xffff001c, start, length);
2795 #else
2796+ pax_open_kernel();
2797 memcpy(vectors_page + 0x1c, start, length);
2798+ pax_close_kernel();
2799 #endif
2800 flush_icache_range(0xffff001c, 0xffff001c + length);
2801 if (!vectors_high())
2802diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2803index e0eb9a1..caee108 100644
2804--- a/arch/arm/kernel/head.S
2805+++ b/arch/arm/kernel/head.S
2806@@ -52,7 +52,9 @@
2807 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2808
2809 .macro pgtbl, rd, phys
2810- add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2811+ mov \rd, #TEXT_OFFSET
2812+ sub \rd, #PG_DIR_SIZE
2813+ add \rd, \rd, \phys
2814 .endm
2815
2816 /*
2817@@ -267,7 +269,7 @@ __create_page_tables:
2818 addne r6, r6, #1 << SECTION_SHIFT
2819 strne r6, [r3]
2820
2821-#if defined(CONFIG_LPAE) && defined(CONFIG_CPU_ENDIAN_BE8)
2822+#if defined(CONFIG_ARM_LPAE) && defined(CONFIG_CPU_ENDIAN_BE8)
2823 sub r4, r4, #4 @ Fixup page table pointer
2824 @ for 64-bit descriptors
2825 #endif
2826@@ -434,7 +436,7 @@ __enable_mmu:
2827 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2828 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2829 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2830- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2831+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2832 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2833 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2834 #endif
2835diff --git a/arch/arm/kernel/hw_breakpoint.c b/arch/arm/kernel/hw_breakpoint.c
2836index 5ff2e77..556d030 100644
2837--- a/arch/arm/kernel/hw_breakpoint.c
2838+++ b/arch/arm/kernel/hw_breakpoint.c
2839@@ -1011,7 +1011,7 @@ static int __cpuinit dbg_reset_notify(struct notifier_block *self,
2840 return NOTIFY_OK;
2841 }
2842
2843-static struct notifier_block __cpuinitdata dbg_reset_nb = {
2844+static struct notifier_block dbg_reset_nb = {
2845 .notifier_call = dbg_reset_notify,
2846 };
2847
2848diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2849index 1e9be5d..03edbc2 100644
2850--- a/arch/arm/kernel/module.c
2851+++ b/arch/arm/kernel/module.c
2852@@ -37,12 +37,37 @@
2853 #endif
2854
2855 #ifdef CONFIG_MMU
2856-void *module_alloc(unsigned long size)
2857+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2858 {
2859+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2860+ return NULL;
2861 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2862- GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
2863+ GFP_KERNEL, prot, -1,
2864 __builtin_return_address(0));
2865 }
2866+
2867+void *module_alloc(unsigned long size)
2868+{
2869+
2870+#ifdef CONFIG_PAX_KERNEXEC
2871+ return __module_alloc(size, PAGE_KERNEL);
2872+#else
2873+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2874+#endif
2875+
2876+}
2877+
2878+#ifdef CONFIG_PAX_KERNEXEC
2879+void module_free_exec(struct module *mod, void *module_region)
2880+{
2881+ module_free(mod, module_region);
2882+}
2883+
2884+void *module_alloc_exec(unsigned long size)
2885+{
2886+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2887+}
2888+#endif
2889 #endif
2890
2891 int
2892diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2893index 07314af..c46655c 100644
2894--- a/arch/arm/kernel/patch.c
2895+++ b/arch/arm/kernel/patch.c
2896@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2897 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2898 int size;
2899
2900+ pax_open_kernel();
2901 if (thumb2 && __opcode_is_thumb16(insn)) {
2902 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2903 size = sizeof(u16);
2904@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2905 *(u32 *)addr = insn;
2906 size = sizeof(u32);
2907 }
2908+ pax_close_kernel();
2909
2910 flush_icache_range((uintptr_t)(addr),
2911 (uintptr_t)(addr) + size);
2912diff --git a/arch/arm/kernel/perf_event_cpu.c b/arch/arm/kernel/perf_event_cpu.c
2913index 5f66206..dce492f 100644
2914--- a/arch/arm/kernel/perf_event_cpu.c
2915+++ b/arch/arm/kernel/perf_event_cpu.c
2916@@ -171,7 +171,7 @@ static int __cpuinit cpu_pmu_notify(struct notifier_block *b,
2917 return NOTIFY_OK;
2918 }
2919
2920-static struct notifier_block __cpuinitdata cpu_pmu_hotplug_notifier = {
2921+static struct notifier_block cpu_pmu_hotplug_notifier = {
2922 .notifier_call = cpu_pmu_notify,
2923 };
2924
2925diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2926index c6dec5f..e0fddd1 100644
2927--- a/arch/arm/kernel/process.c
2928+++ b/arch/arm/kernel/process.c
2929@@ -28,7 +28,6 @@
2930 #include <linux/tick.h>
2931 #include <linux/utsname.h>
2932 #include <linux/uaccess.h>
2933-#include <linux/random.h>
2934 #include <linux/hw_breakpoint.h>
2935 #include <linux/cpuidle.h>
2936 #include <linux/leds.h>
2937@@ -256,9 +255,10 @@ void machine_power_off(void)
2938 machine_shutdown();
2939 if (pm_power_off)
2940 pm_power_off();
2941+ BUG();
2942 }
2943
2944-void machine_restart(char *cmd)
2945+__noreturn void machine_restart(char *cmd)
2946 {
2947 machine_shutdown();
2948
2949@@ -283,8 +283,8 @@ void __show_regs(struct pt_regs *regs)
2950 init_utsname()->release,
2951 (int)strcspn(init_utsname()->version, " "),
2952 init_utsname()->version);
2953- print_symbol("PC is at %s\n", instruction_pointer(regs));
2954- print_symbol("LR is at %s\n", regs->ARM_lr);
2955+ printk("PC is at %pA\n", instruction_pointer(regs));
2956+ printk("LR is at %pA\n", regs->ARM_lr);
2957 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2958 "sp : %08lx ip : %08lx fp : %08lx\n",
2959 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2960@@ -452,12 +452,6 @@ unsigned long get_wchan(struct task_struct *p)
2961 return 0;
2962 }
2963
2964-unsigned long arch_randomize_brk(struct mm_struct *mm)
2965-{
2966- unsigned long range_end = mm->brk + 0x02000000;
2967- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2968-}
2969-
2970 #ifdef CONFIG_MMU
2971 /*
2972 * The vectors page is always readable from user space for the
2973@@ -470,9 +464,8 @@ static int __init gate_vma_init(void)
2974 {
2975 gate_vma.vm_start = 0xffff0000;
2976 gate_vma.vm_end = 0xffff0000 + PAGE_SIZE;
2977- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2978- gate_vma.vm_flags = VM_READ | VM_EXEC |
2979- VM_MAYREAD | VM_MAYEXEC;
2980+ gate_vma.vm_flags = VM_NONE;
2981+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2982 return 0;
2983 }
2984 arch_initcall(gate_vma_init);
2985diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2986index 03deeff..741ce88 100644
2987--- a/arch/arm/kernel/ptrace.c
2988+++ b/arch/arm/kernel/ptrace.c
2989@@ -937,10 +937,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2990 return current_thread_info()->syscall;
2991 }
2992
2993+#ifdef CONFIG_GRKERNSEC_SETXID
2994+extern void gr_delayed_cred_worker(void);
2995+#endif
2996+
2997 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2998 {
2999 current_thread_info()->syscall = scno;
3000
3001+#ifdef CONFIG_GRKERNSEC_SETXID
3002+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3003+ gr_delayed_cred_worker();
3004+#endif
3005+
3006 /* Do the secure computing check first; failures should be fast. */
3007 if (secure_computing(scno) == -1)
3008 return -1;
3009diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
3010index 3f6cbb2..39305c7 100644
3011--- a/arch/arm/kernel/setup.c
3012+++ b/arch/arm/kernel/setup.c
3013@@ -97,21 +97,23 @@ EXPORT_SYMBOL(system_serial_high);
3014 unsigned int elf_hwcap __read_mostly;
3015 EXPORT_SYMBOL(elf_hwcap);
3016
3017+pteval_t __supported_pte_mask __read_only;
3018+pmdval_t __supported_pmd_mask __read_only;
3019
3020 #ifdef MULTI_CPU
3021-struct processor processor __read_mostly;
3022+struct processor processor;
3023 #endif
3024 #ifdef MULTI_TLB
3025-struct cpu_tlb_fns cpu_tlb __read_mostly;
3026+struct cpu_tlb_fns cpu_tlb __read_only;
3027 #endif
3028 #ifdef MULTI_USER
3029-struct cpu_user_fns cpu_user __read_mostly;
3030+struct cpu_user_fns cpu_user __read_only;
3031 #endif
3032 #ifdef MULTI_CACHE
3033-struct cpu_cache_fns cpu_cache __read_mostly;
3034+struct cpu_cache_fns cpu_cache __read_only;
3035 #endif
3036 #ifdef CONFIG_OUTER_CACHE
3037-struct outer_cache_fns outer_cache __read_mostly;
3038+struct outer_cache_fns outer_cache __read_only;
3039 EXPORT_SYMBOL(outer_cache);
3040 #endif
3041
3042@@ -236,9 +238,13 @@ static int __get_cpu_architecture(void)
3043 asm("mrc p15, 0, %0, c0, c1, 4"
3044 : "=r" (mmfr0));
3045 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3046- (mmfr0 & 0x000000f0) >= 0x00000030)
3047+ (mmfr0 & 0x000000f0) >= 0x00000030) {
3048 cpu_arch = CPU_ARCH_ARMv7;
3049- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3050+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3051+ __supported_pte_mask |= L_PTE_PXN;
3052+ __supported_pmd_mask |= PMD_PXNTABLE;
3053+ }
3054+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3055 (mmfr0 & 0x000000f0) == 0x00000020)
3056 cpu_arch = CPU_ARCH_ARMv6;
3057 else
3058@@ -462,7 +468,7 @@ static void __init setup_processor(void)
3059 __cpu_architecture = __get_cpu_architecture();
3060
3061 #ifdef MULTI_CPU
3062- processor = *list->proc;
3063+ memcpy((void *)&processor, list->proc, sizeof processor);
3064 #endif
3065 #ifdef MULTI_TLB
3066 cpu_tlb = *list->tlb;
3067@@ -524,7 +530,7 @@ int __init arm_add_memory(phys_addr_t start, phys_addr_t size)
3068 size -= start & ~PAGE_MASK;
3069 bank->start = PAGE_ALIGN(start);
3070
3071-#ifndef CONFIG_LPAE
3072+#ifndef CONFIG_ARM_LPAE
3073 if (bank->start + size < bank->start) {
3074 printk(KERN_CRIT "Truncating memory at 0x%08llx to fit in "
3075 "32-bit physical address space\n", (long long)start);
3076diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3077index 56f72d2..6924200 100644
3078--- a/arch/arm/kernel/signal.c
3079+++ b/arch/arm/kernel/signal.c
3080@@ -433,22 +433,14 @@ setup_return(struct pt_regs *regs, struct k_sigaction *ka,
3081 __put_user(sigreturn_codes[idx+1], rc+1))
3082 return 1;
3083
3084- if (cpsr & MODE32_BIT) {
3085- /*
3086- * 32-bit code can use the new high-page
3087- * signal return code support.
3088- */
3089- retcode = KERN_SIGRETURN_CODE + (idx << 2) + thumb;
3090- } else {
3091- /*
3092- * Ensure that the instruction cache sees
3093- * the return code written onto the stack.
3094- */
3095- flush_icache_range((unsigned long)rc,
3096- (unsigned long)(rc + 2));
3097+ /*
3098+ * Ensure that the instruction cache sees
3099+ * the return code written onto the stack.
3100+ */
3101+ flush_icache_range((unsigned long)rc,
3102+ (unsigned long)(rc + 2));
3103
3104- retcode = ((unsigned long)rc) + thumb;
3105- }
3106+ retcode = ((unsigned long)rc) + thumb;
3107 }
3108
3109 regs->ARM_r0 = usig;
3110diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3111index 58af91c..343ce99 100644
3112--- a/arch/arm/kernel/smp.c
3113+++ b/arch/arm/kernel/smp.c
3114@@ -70,7 +70,7 @@ enum ipi_msg_type {
3115
3116 static DECLARE_COMPLETION(cpu_running);
3117
3118-static struct smp_operations smp_ops;
3119+static struct smp_operations smp_ops __read_only;
3120
3121 void __init smp_set_ops(struct smp_operations *ops)
3122 {
3123diff --git a/arch/arm/kernel/smp_tlb.c b/arch/arm/kernel/smp_tlb.c
3124index 02c5d2c..e5695ad 100644
3125--- a/arch/arm/kernel/smp_tlb.c
3126+++ b/arch/arm/kernel/smp_tlb.c
3127@@ -12,6 +12,7 @@
3128
3129 #include <asm/smp_plat.h>
3130 #include <asm/tlbflush.h>
3131+#include <asm/mmu_context.h>
3132
3133 /**********************************************************************/
3134
3135@@ -64,12 +65,72 @@ static inline void ipi_flush_tlb_kernel_range(void *arg)
3136 local_flush_tlb_kernel_range(ta->ta_start, ta->ta_end);
3137 }
3138
3139+#ifdef CONFIG_ARM_ERRATA_798181
3140+static int erratum_a15_798181(void)
3141+{
3142+ unsigned int midr = read_cpuid_id();
3143+
3144+ /* Cortex-A15 r0p0..r3p2 affected */
3145+ if ((midr & 0xff0ffff0) != 0x410fc0f0 || midr > 0x413fc0f2)
3146+ return 0;
3147+ return 1;
3148+}
3149+#else
3150+static int erratum_a15_798181(void)
3151+{
3152+ return 0;
3153+}
3154+#endif
3155+
3156+static void ipi_flush_tlb_a15_erratum(void *arg)
3157+{
3158+ dmb();
3159+}
3160+
3161+static void broadcast_tlb_a15_erratum(void)
3162+{
3163+ if (!erratum_a15_798181())
3164+ return;
3165+
3166+ dummy_flush_tlb_a15_erratum();
3167+ smp_call_function_many(cpu_online_mask, ipi_flush_tlb_a15_erratum,
3168+ NULL, 1);
3169+}
3170+
3171+static void broadcast_tlb_mm_a15_erratum(struct mm_struct *mm)
3172+{
3173+ int cpu;
3174+ cpumask_t mask = { CPU_BITS_NONE };
3175+
3176+ if (!erratum_a15_798181())
3177+ return;
3178+
3179+ dummy_flush_tlb_a15_erratum();
3180+ for_each_online_cpu(cpu) {
3181+ if (cpu == smp_processor_id())
3182+ continue;
3183+ /*
3184+ * We only need to send an IPI if the other CPUs are running
3185+ * the same ASID as the one being invalidated. There is no
3186+ * need for locking around the active_asids check since the
3187+ * switch_mm() function has at least one dmb() (as required by
3188+ * this workaround) in case a context switch happens on
3189+ * another CPU after the condition below.
3190+ */
3191+ if (atomic64_read(&mm->context.id) ==
3192+ atomic64_read(&per_cpu(active_asids, cpu)))
3193+ cpumask_set_cpu(cpu, &mask);
3194+ }
3195+ smp_call_function_many(&mask, ipi_flush_tlb_a15_erratum, NULL, 1);
3196+}
3197+
3198 void flush_tlb_all(void)
3199 {
3200 if (tlb_ops_need_broadcast())
3201 on_each_cpu(ipi_flush_tlb_all, NULL, 1);
3202 else
3203 local_flush_tlb_all();
3204+ broadcast_tlb_a15_erratum();
3205 }
3206
3207 void flush_tlb_mm(struct mm_struct *mm)
3208@@ -78,6 +139,7 @@ void flush_tlb_mm(struct mm_struct *mm)
3209 on_each_cpu_mask(mm_cpumask(mm), ipi_flush_tlb_mm, mm, 1);
3210 else
3211 local_flush_tlb_mm(mm);
3212+ broadcast_tlb_mm_a15_erratum(mm);
3213 }
3214
3215 void flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr)
3216@@ -90,6 +152,7 @@ void flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr)
3217 &ta, 1);
3218 } else
3219 local_flush_tlb_page(vma, uaddr);
3220+ broadcast_tlb_mm_a15_erratum(vma->vm_mm);
3221 }
3222
3223 void flush_tlb_kernel_page(unsigned long kaddr)
3224@@ -100,6 +163,7 @@ void flush_tlb_kernel_page(unsigned long kaddr)
3225 on_each_cpu(ipi_flush_tlb_kernel_page, &ta, 1);
3226 } else
3227 local_flush_tlb_kernel_page(kaddr);
3228+ broadcast_tlb_a15_erratum();
3229 }
3230
3231 void flush_tlb_range(struct vm_area_struct *vma,
3232@@ -114,6 +178,7 @@ void flush_tlb_range(struct vm_area_struct *vma,
3233 &ta, 1);
3234 } else
3235 local_flush_tlb_range(vma, start, end);
3236+ broadcast_tlb_mm_a15_erratum(vma->vm_mm);
3237 }
3238
3239 void flush_tlb_kernel_range(unsigned long start, unsigned long end)
3240@@ -125,5 +190,6 @@ void flush_tlb_kernel_range(unsigned long start, unsigned long end)
3241 on_each_cpu(ipi_flush_tlb_kernel_range, &ta, 1);
3242 } else
3243 local_flush_tlb_kernel_range(start, end);
3244+ broadcast_tlb_a15_erratum();
3245 }
3246
3247diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3248index b0179b8..829510e 100644
3249--- a/arch/arm/kernel/traps.c
3250+++ b/arch/arm/kernel/traps.c
3251@@ -57,7 +57,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3252 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3253 {
3254 #ifdef CONFIG_KALLSYMS
3255- printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3256+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3257 #else
3258 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3259 #endif
3260@@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3261 static int die_owner = -1;
3262 static unsigned int die_nest_count;
3263
3264+extern void gr_handle_kernel_exploit(void);
3265+
3266 static unsigned long oops_begin(void)
3267 {
3268 int cpu;
3269@@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3270 panic("Fatal exception in interrupt");
3271 if (panic_on_oops)
3272 panic("Fatal exception");
3273+
3274+ gr_handle_kernel_exploit();
3275+
3276 if (signr)
3277 do_exit(signr);
3278 }
3279@@ -601,7 +606,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3280 * The user helper at 0xffff0fe0 must be used instead.
3281 * (see entry-armv.S for details)
3282 */
3283+ pax_open_kernel();
3284 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3285+ pax_close_kernel();
3286 }
3287 return 0;
3288
3289@@ -841,13 +848,10 @@ void __init early_trap_init(void *vectors_base)
3290 */
3291 kuser_get_tls_init(vectors);
3292
3293- /*
3294- * Copy signal return handlers into the vector page, and
3295- * set sigreturn to be a pointer to these.
3296- */
3297- memcpy((void *)(vectors + KERN_SIGRETURN_CODE - CONFIG_VECTORS_BASE),
3298- sigreturn_codes, sizeof(sigreturn_codes));
3299-
3300 flush_icache_range(vectors, vectors + PAGE_SIZE);
3301- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3302+
3303+#ifndef CONFIG_PAX_MEMORY_UDEREF
3304+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3305+#endif
3306+
3307 }
3308diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3309index 11c1785..1b209f4 100644
3310--- a/arch/arm/kernel/vmlinux.lds.S
3311+++ b/arch/arm/kernel/vmlinux.lds.S
3312@@ -8,7 +8,11 @@
3313 #include <asm/thread_info.h>
3314 #include <asm/memory.h>
3315 #include <asm/page.h>
3316-
3317+
3318+#ifdef CONFIG_PAX_KERNEXEC
3319+#include <asm/pgtable.h>
3320+#endif
3321+
3322 #define PROC_INFO \
3323 . = ALIGN(4); \
3324 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3325@@ -90,6 +94,11 @@ SECTIONS
3326 _text = .;
3327 HEAD_TEXT
3328 }
3329+
3330+#ifdef CONFIG_PAX_KERNEXEC
3331+ . = ALIGN(1<<SECTION_SHIFT);
3332+#endif
3333+
3334 .text : { /* Real text segment */
3335 _stext = .; /* Text and read-only data */
3336 __exception_text_start = .;
3337@@ -112,6 +121,8 @@ SECTIONS
3338 ARM_CPU_KEEP(PROC_INFO)
3339 }
3340
3341+ _etext = .; /* End of text section */
3342+
3343 RO_DATA(PAGE_SIZE)
3344
3345 . = ALIGN(4);
3346@@ -142,7 +153,9 @@ SECTIONS
3347
3348 NOTES
3349
3350- _etext = .; /* End of text and rodata section */
3351+#ifdef CONFIG_PAX_KERNEXEC
3352+ . = ALIGN(1<<SECTION_SHIFT);
3353+#endif
3354
3355 #ifndef CONFIG_XIP_KERNEL
3356 . = ALIGN(PAGE_SIZE);
3357@@ -203,6 +216,11 @@ SECTIONS
3358 . = PAGE_OFFSET + TEXT_OFFSET;
3359 #else
3360 __init_end = .;
3361+
3362+#ifdef CONFIG_PAX_KERNEXEC
3363+ . = ALIGN(1<<SECTION_SHIFT);
3364+#endif
3365+
3366 . = ALIGN(THREAD_SIZE);
3367 __data_loc = .;
3368 #endif
3369diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3370index 14a0d98..7771a7d 100644
3371--- a/arch/arm/lib/clear_user.S
3372+++ b/arch/arm/lib/clear_user.S
3373@@ -12,14 +12,14 @@
3374
3375 .text
3376
3377-/* Prototype: int __clear_user(void *addr, size_t sz)
3378+/* Prototype: int ___clear_user(void *addr, size_t sz)
3379 * Purpose : clear some user memory
3380 * Params : addr - user memory address to clear
3381 * : sz - number of bytes to clear
3382 * Returns : number of bytes NOT cleared
3383 */
3384 ENTRY(__clear_user_std)
3385-WEAK(__clear_user)
3386+WEAK(___clear_user)
3387 stmfd sp!, {r1, lr}
3388 mov r2, #0
3389 cmp r1, #4
3390@@ -44,7 +44,7 @@ WEAK(__clear_user)
3391 USER( strnebt r2, [r0])
3392 mov r0, #0
3393 ldmfd sp!, {r1, pc}
3394-ENDPROC(__clear_user)
3395+ENDPROC(___clear_user)
3396 ENDPROC(__clear_user_std)
3397
3398 .pushsection .fixup,"ax"
3399diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3400index 66a477a..bee61d3 100644
3401--- a/arch/arm/lib/copy_from_user.S
3402+++ b/arch/arm/lib/copy_from_user.S
3403@@ -16,7 +16,7 @@
3404 /*
3405 * Prototype:
3406 *
3407- * size_t __copy_from_user(void *to, const void *from, size_t n)
3408+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3409 *
3410 * Purpose:
3411 *
3412@@ -84,11 +84,11 @@
3413
3414 .text
3415
3416-ENTRY(__copy_from_user)
3417+ENTRY(___copy_from_user)
3418
3419 #include "copy_template.S"
3420
3421-ENDPROC(__copy_from_user)
3422+ENDPROC(___copy_from_user)
3423
3424 .pushsection .fixup,"ax"
3425 .align 0
3426diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3427index 6ee2f67..d1cce76 100644
3428--- a/arch/arm/lib/copy_page.S
3429+++ b/arch/arm/lib/copy_page.S
3430@@ -10,6 +10,7 @@
3431 * ASM optimised string functions
3432 */
3433 #include <linux/linkage.h>
3434+#include <linux/const.h>
3435 #include <asm/assembler.h>
3436 #include <asm/asm-offsets.h>
3437 #include <asm/cache.h>
3438diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3439index d066df6..df28194 100644
3440--- a/arch/arm/lib/copy_to_user.S
3441+++ b/arch/arm/lib/copy_to_user.S
3442@@ -16,7 +16,7 @@
3443 /*
3444 * Prototype:
3445 *
3446- * size_t __copy_to_user(void *to, const void *from, size_t n)
3447+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3448 *
3449 * Purpose:
3450 *
3451@@ -88,11 +88,11 @@
3452 .text
3453
3454 ENTRY(__copy_to_user_std)
3455-WEAK(__copy_to_user)
3456+WEAK(___copy_to_user)
3457
3458 #include "copy_template.S"
3459
3460-ENDPROC(__copy_to_user)
3461+ENDPROC(___copy_to_user)
3462 ENDPROC(__copy_to_user_std)
3463
3464 .pushsection .fixup,"ax"
3465diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3466index 7d08b43..f7ca7ea 100644
3467--- a/arch/arm/lib/csumpartialcopyuser.S
3468+++ b/arch/arm/lib/csumpartialcopyuser.S
3469@@ -57,8 +57,8 @@
3470 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3471 */
3472
3473-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3474-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3475+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3476+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3477
3478 #include "csumpartialcopygeneric.S"
3479
3480diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3481index 6b93f6a..1aa92d0 100644
3482--- a/arch/arm/lib/delay.c
3483+++ b/arch/arm/lib/delay.c
3484@@ -28,12 +28,15 @@
3485 /*
3486 * Default to the loop-based delay implementation.
3487 */
3488-struct arm_delay_ops arm_delay_ops = {
3489+static struct arm_delay_ops arm_loop_delay_ops = {
3490 .delay = __loop_delay,
3491 .const_udelay = __loop_const_udelay,
3492 .udelay = __loop_udelay,
3493+ .const_clock = false,
3494 };
3495
3496+struct arm_delay_ops *arm_delay_ops __read_only = &arm_loop_delay_ops;
3497+
3498 static const struct delay_timer *delay_timer;
3499 static bool delay_calibrated;
3500
3501@@ -67,6 +70,13 @@ static void __timer_udelay(unsigned long usecs)
3502 __timer_const_udelay(usecs * UDELAY_MULT);
3503 }
3504
3505+static struct arm_delay_ops arm_timer_delay_ops = {
3506+ .delay = __timer_delay,
3507+ .const_udelay = __timer_const_udelay,
3508+ .udelay = __timer_udelay,
3509+ .const_clock = true,
3510+};
3511+
3512 void __init register_current_timer_delay(const struct delay_timer *timer)
3513 {
3514 if (!delay_calibrated) {
3515@@ -74,10 +84,7 @@ void __init register_current_timer_delay(const struct delay_timer *timer)
3516 delay_timer = timer;
3517 lpj_fine = timer->freq / HZ;
3518 loops_per_jiffy = lpj_fine;
3519- arm_delay_ops.delay = __timer_delay;
3520- arm_delay_ops.const_udelay = __timer_const_udelay;
3521- arm_delay_ops.udelay = __timer_udelay;
3522- arm_delay_ops.const_clock = true;
3523+ arm_delay_ops = &arm_timer_delay_ops;
3524 delay_calibrated = true;
3525 } else {
3526 pr_info("Ignoring duplicate/late registration of read_current_timer delay\n");
3527diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3528index 025f742..8432b08 100644
3529--- a/arch/arm/lib/uaccess_with_memcpy.c
3530+++ b/arch/arm/lib/uaccess_with_memcpy.c
3531@@ -104,7 +104,7 @@ out:
3532 }
3533
3534 unsigned long
3535-__copy_to_user(void __user *to, const void *from, unsigned long n)
3536+___copy_to_user(void __user *to, const void *from, unsigned long n)
3537 {
3538 /*
3539 * This test is stubbed out of the main function above to keep
3540diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3541index bac21a5..b67ef8e 100644
3542--- a/arch/arm/mach-kirkwood/common.c
3543+++ b/arch/arm/mach-kirkwood/common.c
3544@@ -150,7 +150,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3545 clk_gate_ops.disable(hw);
3546 }
3547
3548-static struct clk_ops clk_gate_fn_ops;
3549+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3550+{
3551+ return clk_gate_ops.is_enabled(hw);
3552+}
3553+
3554+static struct clk_ops clk_gate_fn_ops = {
3555+ .enable = clk_gate_fn_enable,
3556+ .disable = clk_gate_fn_disable,
3557+ .is_enabled = clk_gate_fn_is_enabled,
3558+};
3559
3560 static struct clk __init *clk_register_gate_fn(struct device *dev,
3561 const char *name,
3562@@ -184,14 +193,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3563 gate_fn->fn_en = fn_en;
3564 gate_fn->fn_dis = fn_dis;
3565
3566- /* ops is the gate ops, but with our enable/disable functions */
3567- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3568- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3569- clk_gate_fn_ops = clk_gate_ops;
3570- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3571- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3572- }
3573-
3574 clk = clk_register(dev, &gate_fn->gate.hw);
3575
3576 if (IS_ERR(clk))
3577diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3578index 0abb30f..54064da 100644
3579--- a/arch/arm/mach-omap2/board-n8x0.c
3580+++ b/arch/arm/mach-omap2/board-n8x0.c
3581@@ -631,7 +631,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3582 }
3583 #endif
3584
3585-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3586+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3587 .late_init = n8x0_menelaus_late_init,
3588 };
3589
3590diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3591index 8033cb7..2f7cb62 100644
3592--- a/arch/arm/mach-omap2/gpmc.c
3593+++ b/arch/arm/mach-omap2/gpmc.c
3594@@ -139,7 +139,6 @@ struct omap3_gpmc_regs {
3595 };
3596
3597 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3598-static struct irq_chip gpmc_irq_chip;
3599 static unsigned gpmc_irq_start;
3600
3601 static struct resource gpmc_mem_root;
3602@@ -700,6 +699,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3603
3604 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3605
3606+static struct irq_chip gpmc_irq_chip = {
3607+ .name = "gpmc",
3608+ .irq_startup = gpmc_irq_noop_ret,
3609+ .irq_enable = gpmc_irq_enable,
3610+ .irq_disable = gpmc_irq_disable,
3611+ .irq_shutdown = gpmc_irq_noop,
3612+ .irq_ack = gpmc_irq_noop,
3613+ .irq_mask = gpmc_irq_noop,
3614+ .irq_unmask = gpmc_irq_noop,
3615+
3616+};
3617+
3618 static int gpmc_setup_irq(void)
3619 {
3620 int i;
3621@@ -714,15 +725,6 @@ static int gpmc_setup_irq(void)
3622 return gpmc_irq_start;
3623 }
3624
3625- gpmc_irq_chip.name = "gpmc";
3626- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3627- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3628- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3629- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3630- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3631- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3632- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3633-
3634 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3635 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3636
3637diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3638index 5d3b4f4..ddba3c0 100644
3639--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3640+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3641@@ -340,7 +340,7 @@ static int __cpuinit irq_cpu_hotplug_notify(struct notifier_block *self,
3642 return NOTIFY_OK;
3643 }
3644
3645-static struct notifier_block __refdata irq_hotplug_notifier = {
3646+static struct notifier_block irq_hotplug_notifier = {
3647 .notifier_call = irq_cpu_hotplug_notify,
3648 };
3649
3650diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3651index e065daa..7b1ad9b 100644
3652--- a/arch/arm/mach-omap2/omap_device.c
3653+++ b/arch/arm/mach-omap2/omap_device.c
3654@@ -686,7 +686,7 @@ void omap_device_delete(struct omap_device *od)
3655 * passes along the return value of omap_device_build_ss().
3656 */
3657 struct platform_device __init *omap_device_build(const char *pdev_name, int pdev_id,
3658- struct omap_hwmod *oh, void *pdata,
3659+ struct omap_hwmod *oh, const void *pdata,
3660 int pdata_len,
3661 struct omap_device_pm_latency *pm_lats,
3662 int pm_lats_cnt, int is_early_device)
3663@@ -720,7 +720,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name, int pdev
3664 */
3665 struct platform_device __init *omap_device_build_ss(const char *pdev_name, int pdev_id,
3666 struct omap_hwmod **ohs, int oh_cnt,
3667- void *pdata, int pdata_len,
3668+ const void *pdata, int pdata_len,
3669 struct omap_device_pm_latency *pm_lats,
3670 int pm_lats_cnt, int is_early_device)
3671 {
3672diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3673index 0933c59..42b8e2d 100644
3674--- a/arch/arm/mach-omap2/omap_device.h
3675+++ b/arch/arm/mach-omap2/omap_device.h
3676@@ -91,14 +91,14 @@ int omap_device_shutdown(struct platform_device *pdev);
3677 /* Core code interface */
3678
3679 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3680- struct omap_hwmod *oh, void *pdata,
3681+ struct omap_hwmod *oh, const void *pdata,
3682 int pdata_len,
3683 struct omap_device_pm_latency *pm_lats,
3684 int pm_lats_cnt, int is_early_device);
3685
3686 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3687 struct omap_hwmod **oh, int oh_cnt,
3688- void *pdata, int pdata_len,
3689+ const void *pdata, int pdata_len,
3690 struct omap_device_pm_latency *pm_lats,
3691 int pm_lats_cnt, int is_early_device);
3692
3693diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3694index 4653efb..8c60bf7 100644
3695--- a/arch/arm/mach-omap2/omap_hwmod.c
3696+++ b/arch/arm/mach-omap2/omap_hwmod.c
3697@@ -189,10 +189,10 @@ struct omap_hwmod_soc_ops {
3698 int (*init_clkdm)(struct omap_hwmod *oh);
3699 void (*update_context_lost)(struct omap_hwmod *oh);
3700 int (*get_context_lost)(struct omap_hwmod *oh);
3701-};
3702+} __no_const;
3703
3704 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3705-static struct omap_hwmod_soc_ops soc_ops;
3706+static struct omap_hwmod_soc_ops soc_ops __read_only;
3707
3708 /* omap_hwmod_list contains all registered struct omap_hwmods */
3709 static LIST_HEAD(omap_hwmod_list);
3710diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3711index 7c2b4ed..b2ea51f 100644
3712--- a/arch/arm/mach-omap2/wd_timer.c
3713+++ b/arch/arm/mach-omap2/wd_timer.c
3714@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3715 struct omap_hwmod *oh;
3716 char *oh_name = "wd_timer2";
3717 char *dev_name = "omap_wdt";
3718- struct omap_wd_timer_platform_data pdata;
3719+ static struct omap_wd_timer_platform_data pdata = {
3720+ .read_reset_sources = prm_read_reset_sources
3721+ };
3722
3723 if (!cpu_class_is_omap2() || of_have_populated_dt())
3724 return 0;
3725@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3726 return -EINVAL;
3727 }
3728
3729- pdata.read_reset_sources = prm_read_reset_sources;
3730-
3731 pdev = omap_device_build(dev_name, id, oh, &pdata,
3732 sizeof(struct omap_wd_timer_platform_data),
3733 NULL, 0, 0);
3734diff --git a/arch/arm/mach-ux500/include/mach/setup.h b/arch/arm/mach-ux500/include/mach/setup.h
3735index 6be4c4d..32ac32a 100644
3736--- a/arch/arm/mach-ux500/include/mach/setup.h
3737+++ b/arch/arm/mach-ux500/include/mach/setup.h
3738@@ -38,13 +38,6 @@ extern struct sys_timer ux500_timer;
3739 .type = MT_DEVICE, \
3740 }
3741
3742-#define __MEM_DEV_DESC(x, sz) { \
3743- .virtual = IO_ADDRESS(x), \
3744- .pfn = __phys_to_pfn(x), \
3745- .length = sz, \
3746- .type = MT_MEMORY, \
3747-}
3748-
3749 extern struct smp_operations ux500_smp_ops;
3750 extern void ux500_cpu_die(unsigned int cpu);
3751
3752diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3753index 3fd629d..8b1aca9 100644
3754--- a/arch/arm/mm/Kconfig
3755+++ b/arch/arm/mm/Kconfig
3756@@ -425,7 +425,7 @@ config CPU_32v5
3757
3758 config CPU_32v6
3759 bool
3760- select CPU_USE_DOMAINS if CPU_V6 && MMU
3761+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC
3762 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3763
3764 config CPU_32v6K
3765@@ -577,6 +577,7 @@ config CPU_CP15_MPU
3766
3767 config CPU_USE_DOMAINS
3768 bool
3769+ depends on !ARM_LPAE && !PAX_KERNEXEC
3770 help
3771 This option enables or disables the use of domain switching
3772 via the set_fs() function.
3773diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3774index db26e2e..ee44569 100644
3775--- a/arch/arm/mm/alignment.c
3776+++ b/arch/arm/mm/alignment.c
3777@@ -211,10 +211,12 @@ union offset_union {
3778 #define __get16_unaligned_check(ins,val,addr) \
3779 do { \
3780 unsigned int err = 0, v, a = addr; \
3781+ pax_open_userland(); \
3782 __get8_unaligned_check(ins,v,a,err); \
3783 val = v << ((BE) ? 8 : 0); \
3784 __get8_unaligned_check(ins,v,a,err); \
3785 val |= v << ((BE) ? 0 : 8); \
3786+ pax_close_userland(); \
3787 if (err) \
3788 goto fault; \
3789 } while (0)
3790@@ -228,6 +230,7 @@ union offset_union {
3791 #define __get32_unaligned_check(ins,val,addr) \
3792 do { \
3793 unsigned int err = 0, v, a = addr; \
3794+ pax_open_userland(); \
3795 __get8_unaligned_check(ins,v,a,err); \
3796 val = v << ((BE) ? 24 : 0); \
3797 __get8_unaligned_check(ins,v,a,err); \
3798@@ -236,6 +239,7 @@ union offset_union {
3799 val |= v << ((BE) ? 8 : 16); \
3800 __get8_unaligned_check(ins,v,a,err); \
3801 val |= v << ((BE) ? 0 : 24); \
3802+ pax_close_userland(); \
3803 if (err) \
3804 goto fault; \
3805 } while (0)
3806@@ -249,6 +253,7 @@ union offset_union {
3807 #define __put16_unaligned_check(ins,val,addr) \
3808 do { \
3809 unsigned int err = 0, v = val, a = addr; \
3810+ pax_open_userland(); \
3811 __asm__( FIRST_BYTE_16 \
3812 ARM( "1: "ins" %1, [%2], #1\n" ) \
3813 THUMB( "1: "ins" %1, [%2]\n" ) \
3814@@ -268,6 +273,7 @@ union offset_union {
3815 " .popsection\n" \
3816 : "=r" (err), "=&r" (v), "=&r" (a) \
3817 : "0" (err), "1" (v), "2" (a)); \
3818+ pax_close_userland(); \
3819 if (err) \
3820 goto fault; \
3821 } while (0)
3822@@ -281,6 +287,7 @@ union offset_union {
3823 #define __put32_unaligned_check(ins,val,addr) \
3824 do { \
3825 unsigned int err = 0, v = val, a = addr; \
3826+ pax_open_userland(); \
3827 __asm__( FIRST_BYTE_32 \
3828 ARM( "1: "ins" %1, [%2], #1\n" ) \
3829 THUMB( "1: "ins" %1, [%2]\n" ) \
3830@@ -310,6 +317,7 @@ union offset_union {
3831 " .popsection\n" \
3832 : "=r" (err), "=&r" (v), "=&r" (a) \
3833 : "0" (err), "1" (v), "2" (a)); \
3834+ pax_close_userland(); \
3835 if (err) \
3836 goto fault; \
3837 } while (0)
3838diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3839index d07df17..59d5493 100644
3840--- a/arch/arm/mm/context.c
3841+++ b/arch/arm/mm/context.c
3842@@ -45,7 +45,7 @@ static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3843 static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3844 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3845
3846-static DEFINE_PER_CPU(atomic64_t, active_asids);
3847+DEFINE_PER_CPU(atomic64_t, active_asids);
3848 static DEFINE_PER_CPU(u64, reserved_asids);
3849 static cpumask_t tlb_flush_pending;
3850
3851@@ -209,8 +209,10 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3852 atomic64_set(&mm->context.id, asid);
3853 }
3854
3855- if (cpumask_test_and_clear_cpu(cpu, &tlb_flush_pending))
3856+ if (cpumask_test_and_clear_cpu(cpu, &tlb_flush_pending)) {
3857 local_flush_tlb_all();
3858+ dummy_flush_tlb_a15_erratum();
3859+ }
3860
3861 atomic64_set(&per_cpu(active_asids, cpu), asid);
3862 cpumask_set_cpu(cpu, mm_cpumask(mm));
3863diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3864index 5dbf13f..1a60561 100644
3865--- a/arch/arm/mm/fault.c
3866+++ b/arch/arm/mm/fault.c
3867@@ -25,6 +25,7 @@
3868 #include <asm/system_misc.h>
3869 #include <asm/system_info.h>
3870 #include <asm/tlbflush.h>
3871+#include <asm/sections.h>
3872
3873 #include "fault.h"
3874
3875@@ -138,6 +139,20 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3876 if (fixup_exception(regs))
3877 return;
3878
3879+#ifdef CONFIG_PAX_KERNEXEC
3880+ if ((fsr & FSR_WRITE) &&
3881+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3882+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3883+ {
3884+ if (current->signal->curr_ip)
3885+ 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),
3886+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3887+ else
3888+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3889+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3890+ }
3891+#endif
3892+
3893 /*
3894 * No handler, we'll have to terminate things with extreme prejudice.
3895 */
3896@@ -174,6 +189,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3897 }
3898 #endif
3899
3900+#ifdef CONFIG_PAX_PAGEEXEC
3901+ if (fsr & FSR_LNX_PF) {
3902+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3903+ do_group_exit(SIGKILL);
3904+ }
3905+#endif
3906+
3907 tsk->thread.address = addr;
3908 tsk->thread.error_code = fsr;
3909 tsk->thread.trap_no = 14;
3910@@ -398,6 +420,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3911 }
3912 #endif /* CONFIG_MMU */
3913
3914+#ifdef CONFIG_PAX_PAGEEXEC
3915+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3916+{
3917+ long i;
3918+
3919+ printk(KERN_ERR "PAX: bytes at PC: ");
3920+ for (i = 0; i < 20; i++) {
3921+ unsigned char c;
3922+ if (get_user(c, (__force unsigned char __user *)pc+i))
3923+ printk(KERN_CONT "?? ");
3924+ else
3925+ printk(KERN_CONT "%02x ", c);
3926+ }
3927+ printk("\n");
3928+
3929+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3930+ for (i = -1; i < 20; i++) {
3931+ unsigned long c;
3932+ if (get_user(c, (__force unsigned long __user *)sp+i))
3933+ printk(KERN_CONT "???????? ");
3934+ else
3935+ printk(KERN_CONT "%08lx ", c);
3936+ }
3937+ printk("\n");
3938+}
3939+#endif
3940+
3941 /*
3942 * First Level Translation Fault Handler
3943 *
3944@@ -543,9 +592,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3945 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3946 struct siginfo info;
3947
3948+#ifdef CONFIG_PAX_MEMORY_UDEREF
3949+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3950+ if (current->signal->curr_ip)
3951+ 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),
3952+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3953+ else
3954+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3955+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3956+ goto die;
3957+ }
3958+#endif
3959+
3960 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3961 return;
3962
3963+die:
3964 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3965 inf->name, fsr, addr);
3966
3967@@ -575,9 +637,49 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3968 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3969 struct siginfo info;
3970
3971+ if (user_mode(regs)) {
3972+ if (addr == 0xffff0fe0UL) {
3973+ /*
3974+ * PaX: __kuser_get_tls emulation
3975+ */
3976+ regs->ARM_r0 = current_thread_info()->tp_value;
3977+ regs->ARM_pc = regs->ARM_lr;
3978+ return;
3979+ }
3980+ }
3981+
3982+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3983+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
3984+ if (current->signal->curr_ip)
3985+ 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),
3986+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3987+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3988+ else
3989+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
3990+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3991+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3992+ goto die;
3993+ }
3994+#endif
3995+
3996+#ifdef CONFIG_PAX_REFCOUNT
3997+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
3998+ unsigned int bkpt;
3999+
4000+ if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
4001+ current->thread.error_code = ifsr;
4002+ current->thread.trap_no = 0;
4003+ pax_report_refcount_overflow(regs);
4004+ fixup_exception(regs);
4005+ return;
4006+ }
4007+ }
4008+#endif
4009+
4010 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4011 return;
4012
4013+die:
4014 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4015 inf->name, ifsr, addr);
4016
4017diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4018index cf08bdf..772656c 100644
4019--- a/arch/arm/mm/fault.h
4020+++ b/arch/arm/mm/fault.h
4021@@ -3,6 +3,7 @@
4022
4023 /*
4024 * Fault status register encodings. We steal bit 31 for our own purposes.
4025+ * Set when the FSR value is from an instruction fault.
4026 */
4027 #define FSR_LNX_PF (1 << 31)
4028 #define FSR_WRITE (1 << 11)
4029@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4030 }
4031 #endif
4032
4033+/* valid for LPAE and !LPAE */
4034+static inline int is_xn_fault(unsigned int fsr)
4035+{
4036+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
4037+}
4038+
4039+static inline int is_domain_fault(unsigned int fsr)
4040+{
4041+ return ((fsr_fs(fsr) & 0xD) == 0x9);
4042+}
4043+
4044 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4045 unsigned long search_exception_table(unsigned long addr);
4046
4047diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4048index ad722f1..763fdd3 100644
4049--- a/arch/arm/mm/init.c
4050+++ b/arch/arm/mm/init.c
4051@@ -30,6 +30,8 @@
4052 #include <asm/setup.h>
4053 #include <asm/tlb.h>
4054 #include <asm/fixmap.h>
4055+#include <asm/system_info.h>
4056+#include <asm/cp15.h>
4057
4058 #include <asm/mach/arch.h>
4059 #include <asm/mach/map.h>
4060@@ -736,7 +738,46 @@ void free_initmem(void)
4061 {
4062 #ifdef CONFIG_HAVE_TCM
4063 extern char __tcm_start, __tcm_end;
4064+#endif
4065
4066+#ifdef CONFIG_PAX_KERNEXEC
4067+ unsigned long addr;
4068+ pgd_t *pgd;
4069+ pud_t *pud;
4070+ pmd_t *pmd;
4071+ int cpu_arch = cpu_architecture();
4072+ unsigned int cr = get_cr();
4073+
4074+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4075+ /* make pages tables, etc before .text NX */
4076+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4077+ pgd = pgd_offset_k(addr);
4078+ pud = pud_offset(pgd, addr);
4079+ pmd = pmd_offset(pud, addr);
4080+ __section_update(pmd, addr, PMD_SECT_XN);
4081+ }
4082+ /* make init NX */
4083+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4084+ pgd = pgd_offset_k(addr);
4085+ pud = pud_offset(pgd, addr);
4086+ pmd = pmd_offset(pud, addr);
4087+ __section_update(pmd, addr, PMD_SECT_XN);
4088+ }
4089+ /* make kernel code/rodata RX */
4090+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4091+ pgd = pgd_offset_k(addr);
4092+ pud = pud_offset(pgd, addr);
4093+ pmd = pmd_offset(pud, addr);
4094+#ifdef CONFIG_ARM_LPAE
4095+ __section_update(pmd, addr, PMD_SECT_RDONLY);
4096+#else
4097+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4098+#endif
4099+ }
4100+ }
4101+#endif
4102+
4103+#ifdef CONFIG_HAVE_TCM
4104 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4105 totalram_pages += free_area(__phys_to_pfn(__pa(&__tcm_start)),
4106 __phys_to_pfn(__pa(&__tcm_end)),
4107diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4108index 88fd86c..7a224ce 100644
4109--- a/arch/arm/mm/ioremap.c
4110+++ b/arch/arm/mm/ioremap.c
4111@@ -335,9 +335,9 @@ __arm_ioremap_exec(unsigned long phys_addr, size_t size, bool cached)
4112 unsigned int mtype;
4113
4114 if (cached)
4115- mtype = MT_MEMORY;
4116+ mtype = MT_MEMORY_RX;
4117 else
4118- mtype = MT_MEMORY_NONCACHED;
4119+ mtype = MT_MEMORY_NONCACHED_RX;
4120
4121 return __arm_ioremap_caller(phys_addr, size, mtype,
4122 __builtin_return_address(0));
4123diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4124index 10062ce..aa96dd7 100644
4125--- a/arch/arm/mm/mmap.c
4126+++ b/arch/arm/mm/mmap.c
4127@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4128 struct vm_area_struct *vma;
4129 int do_align = 0;
4130 int aliasing = cache_is_vipt_aliasing();
4131+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4132 struct vm_unmapped_area_info info;
4133
4134 /*
4135@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4136 if (len > TASK_SIZE)
4137 return -ENOMEM;
4138
4139+#ifdef CONFIG_PAX_RANDMMAP
4140+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4141+#endif
4142+
4143 if (addr) {
4144 if (do_align)
4145 addr = COLOUR_ALIGN(addr, pgoff);
4146@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4147 addr = PAGE_ALIGN(addr);
4148
4149 vma = find_vma(mm, addr);
4150- if (TASK_SIZE - len >= addr &&
4151- (!vma || addr + len <= vma->vm_start))
4152+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4153 return addr;
4154 }
4155
4156@@ -112,6 +116,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4157 unsigned long addr = addr0;
4158 int do_align = 0;
4159 int aliasing = cache_is_vipt_aliasing();
4160+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4161 struct vm_unmapped_area_info info;
4162
4163 /*
4164@@ -132,6 +137,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4165 return addr;
4166 }
4167
4168+#ifdef CONFIG_PAX_RANDMMAP
4169+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4170+#endif
4171+
4172 /* requesting a specific address */
4173 if (addr) {
4174 if (do_align)
4175@@ -139,8 +148,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4176 else
4177 addr = PAGE_ALIGN(addr);
4178 vma = find_vma(mm, addr);
4179- if (TASK_SIZE - len >= addr &&
4180- (!vma || addr + len <= vma->vm_start))
4181+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4182 return addr;
4183 }
4184
4185@@ -162,6 +170,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4186 VM_BUG_ON(addr != -ENOMEM);
4187 info.flags = 0;
4188 info.low_limit = mm->mmap_base;
4189+
4190+#ifdef CONFIG_PAX_RANDMMAP
4191+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4192+ info.low_limit += mm->delta_mmap;
4193+#endif
4194+
4195 info.high_limit = TASK_SIZE;
4196 addr = vm_unmapped_area(&info);
4197 }
4198@@ -173,6 +187,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4199 {
4200 unsigned long random_factor = 0UL;
4201
4202+#ifdef CONFIG_PAX_RANDMMAP
4203+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4204+#endif
4205+
4206 /* 8 bits of randomness in 20 address space bits */
4207 if ((current->flags & PF_RANDOMIZE) &&
4208 !(current->personality & ADDR_NO_RANDOMIZE))
4209@@ -180,10 +198,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4210
4211 if (mmap_is_legacy()) {
4212 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4213+
4214+#ifdef CONFIG_PAX_RANDMMAP
4215+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4216+ mm->mmap_base += mm->delta_mmap;
4217+#endif
4218+
4219 mm->get_unmapped_area = arch_get_unmapped_area;
4220 mm->unmap_area = arch_unmap_area;
4221 } else {
4222 mm->mmap_base = mmap_base(random_factor);
4223+
4224+#ifdef CONFIG_PAX_RANDMMAP
4225+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4226+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4227+#endif
4228+
4229 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4230 mm->unmap_area = arch_unmap_area_topdown;
4231 }
4232diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4233index ce328c7..35b88dc 100644
4234--- a/arch/arm/mm/mmu.c
4235+++ b/arch/arm/mm/mmu.c
4236@@ -35,6 +35,23 @@
4237
4238 #include "mm.h"
4239
4240+
4241+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4242+void modify_domain(unsigned int dom, unsigned int type)
4243+{
4244+ struct thread_info *thread = current_thread_info();
4245+ unsigned int domain = thread->cpu_domain;
4246+ /*
4247+ * DOMAIN_MANAGER might be defined to some other value,
4248+ * use the arch-defined constant
4249+ */
4250+ domain &= ~domain_val(dom, 3);
4251+ thread->cpu_domain = domain | domain_val(dom, type);
4252+ set_domain(thread->cpu_domain);
4253+}
4254+EXPORT_SYMBOL(modify_domain);
4255+#endif
4256+
4257 /*
4258 * empty_zero_page is a special page that is used for
4259 * zero-initialized data and COW.
4260@@ -195,10 +212,18 @@ void adjust_cr(unsigned long mask, unsigned long set)
4261 }
4262 #endif
4263
4264-#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
4265+#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
4266 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4267
4268-static struct mem_type mem_types[] = {
4269+#ifdef CONFIG_PAX_KERNEXEC
4270+#define L_PTE_KERNEXEC L_PTE_RDONLY
4271+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4272+#else
4273+#define L_PTE_KERNEXEC L_PTE_DIRTY
4274+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4275+#endif
4276+
4277+static struct mem_type mem_types[] __read_only = {
4278 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4279 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4280 L_PTE_SHARED,
4281@@ -227,16 +252,16 @@ static struct mem_type mem_types[] = {
4282 [MT_UNCACHED] = {
4283 .prot_pte = PROT_PTE_DEVICE,
4284 .prot_l1 = PMD_TYPE_TABLE,
4285- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4286+ .prot_sect = PROT_SECT_DEVICE,
4287 .domain = DOMAIN_IO,
4288 },
4289 [MT_CACHECLEAN] = {
4290- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4291+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4292 .domain = DOMAIN_KERNEL,
4293 },
4294 #ifndef CONFIG_ARM_LPAE
4295 [MT_MINICLEAN] = {
4296- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4297+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
4298 .domain = DOMAIN_KERNEL,
4299 },
4300 #endif
4301@@ -244,36 +269,54 @@ static struct mem_type mem_types[] = {
4302 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4303 L_PTE_RDONLY,
4304 .prot_l1 = PMD_TYPE_TABLE,
4305- .domain = DOMAIN_USER,
4306+ .domain = DOMAIN_VECTORS,
4307 },
4308 [MT_HIGH_VECTORS] = {
4309 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4310- L_PTE_USER | L_PTE_RDONLY,
4311+ L_PTE_RDONLY,
4312 .prot_l1 = PMD_TYPE_TABLE,
4313- .domain = DOMAIN_USER,
4314+ .domain = DOMAIN_VECTORS,
4315 },
4316- [MT_MEMORY] = {
4317+ [MT_MEMORY_RWX] = {
4318 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4319 .prot_l1 = PMD_TYPE_TABLE,
4320 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4321 .domain = DOMAIN_KERNEL,
4322 },
4323+ [MT_MEMORY_RW] = {
4324+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4325+ .prot_l1 = PMD_TYPE_TABLE,
4326+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4327+ .domain = DOMAIN_KERNEL,
4328+ },
4329+ [MT_MEMORY_RX] = {
4330+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4331+ .prot_l1 = PMD_TYPE_TABLE,
4332+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4333+ .domain = DOMAIN_KERNEL,
4334+ },
4335 [MT_ROM] = {
4336- .prot_sect = PMD_TYPE_SECT,
4337+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4338 .domain = DOMAIN_KERNEL,
4339 },
4340- [MT_MEMORY_NONCACHED] = {
4341+ [MT_MEMORY_NONCACHED_RW] = {
4342 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4343 L_PTE_MT_BUFFERABLE,
4344 .prot_l1 = PMD_TYPE_TABLE,
4345 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4346 .domain = DOMAIN_KERNEL,
4347 },
4348+ [MT_MEMORY_NONCACHED_RX] = {
4349+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4350+ L_PTE_MT_BUFFERABLE,
4351+ .prot_l1 = PMD_TYPE_TABLE,
4352+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4353+ .domain = DOMAIN_KERNEL,
4354+ },
4355 [MT_MEMORY_DTCM] = {
4356- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4357- L_PTE_XN,
4358+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4359 .prot_l1 = PMD_TYPE_TABLE,
4360- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4361+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4362 .domain = DOMAIN_KERNEL,
4363 },
4364 [MT_MEMORY_ITCM] = {
4365@@ -283,10 +326,10 @@ static struct mem_type mem_types[] = {
4366 },
4367 [MT_MEMORY_SO] = {
4368 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4369- L_PTE_MT_UNCACHED | L_PTE_XN,
4370+ L_PTE_MT_UNCACHED,
4371 .prot_l1 = PMD_TYPE_TABLE,
4372 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
4373- PMD_SECT_UNCACHED | PMD_SECT_XN,
4374+ PMD_SECT_UNCACHED,
4375 .domain = DOMAIN_KERNEL,
4376 },
4377 [MT_MEMORY_DMA_READY] = {
4378@@ -371,9 +414,35 @@ static void __init build_mem_type_table(void)
4379 * to prevent speculative instruction fetches.
4380 */
4381 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
4382+ mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
4383 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
4384+ mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
4385 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
4386+ mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
4387 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
4388+ mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
4389+
4390+ /* Mark other regions on ARMv6+ as execute-never */
4391+
4392+#ifdef CONFIG_PAX_KERNEXEC
4393+ mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
4394+ mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
4395+ mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
4396+ mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
4397+#ifndef CONFIG_ARM_LPAE
4398+ mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
4399+ mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
4400+#endif
4401+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
4402+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
4403+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
4404+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
4405+ mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
4406+ mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
4407+#endif
4408+
4409+ mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
4410+ mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
4411 }
4412 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4413 /*
4414@@ -432,6 +501,9 @@ static void __init build_mem_type_table(void)
4415 * from SVC mode and no access from userspace.
4416 */
4417 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4418+#ifdef CONFIG_PAX_KERNEXEC
4419+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4420+#endif
4421 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4422 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4423 #endif
4424@@ -448,11 +520,17 @@ static void __init build_mem_type_table(void)
4425 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4426 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4427 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4428- mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
4429- mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
4430+ mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4431+ mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4432+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4433+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4434+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4435+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4436 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4437- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
4438- mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
4439+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
4440+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
4441+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
4442+ mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
4443 }
4444 }
4445
4446@@ -463,15 +541,20 @@ static void __init build_mem_type_table(void)
4447 if (cpu_arch >= CPU_ARCH_ARMv6) {
4448 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4449 /* Non-cacheable Normal is XCB = 001 */
4450- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4451+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4452+ PMD_SECT_BUFFERED;
4453+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4454 PMD_SECT_BUFFERED;
4455 } else {
4456 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4457- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4458+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4459+ PMD_SECT_TEX(1);
4460+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4461 PMD_SECT_TEX(1);
4462 }
4463 } else {
4464- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4465+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
4466+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
4467 }
4468
4469 #ifdef CONFIG_ARM_LPAE
4470@@ -487,6 +570,8 @@ static void __init build_mem_type_table(void)
4471 vecs_pgprot |= PTE_EXT_AF;
4472 #endif
4473
4474+ user_pgprot |= __supported_pte_mask;
4475+
4476 for (i = 0; i < 16; i++) {
4477 pteval_t v = pgprot_val(protection_map[i]);
4478 protection_map[i] = __pgprot(v | user_pgprot);
4479@@ -501,10 +586,15 @@ static void __init build_mem_type_table(void)
4480
4481 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4482 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4483- mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4484- mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4485+ mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4486+ mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4487+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4488+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4489+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4490+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4491 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4492- mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4493+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4494+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4495 mem_types[MT_ROM].prot_sect |= cp->pmd;
4496
4497 switch (cp->pmd) {
4498@@ -1105,18 +1195,15 @@ void __init arm_mm_memblock_reserve(void)
4499 * called function. This means you can't use any function or debugging
4500 * method which may touch any device, otherwise the kernel _will_ crash.
4501 */
4502+
4503+static char vectors[PAGE_SIZE] __read_only __aligned(PAGE_SIZE);
4504+
4505 static void __init devicemaps_init(struct machine_desc *mdesc)
4506 {
4507 struct map_desc map;
4508 unsigned long addr;
4509- void *vectors;
4510
4511- /*
4512- * Allocate the vector page early.
4513- */
4514- vectors = early_alloc(PAGE_SIZE);
4515-
4516- early_trap_init(vectors);
4517+ early_trap_init(&vectors);
4518
4519 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4520 pmd_clear(pmd_off_k(addr));
4521@@ -1156,7 +1243,7 @@ static void __init devicemaps_init(struct machine_desc *mdesc)
4522 * location (0xffff0000). If we aren't using high-vectors, also
4523 * create a mapping at the low-vectors virtual address.
4524 */
4525- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4526+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4527 map.virtual = 0xffff0000;
4528 map.length = PAGE_SIZE;
4529 map.type = MT_HIGH_VECTORS;
4530@@ -1214,8 +1301,39 @@ static void __init map_lowmem(void)
4531 map.pfn = __phys_to_pfn(start);
4532 map.virtual = __phys_to_virt(start);
4533 map.length = end - start;
4534- map.type = MT_MEMORY;
4535
4536+#ifdef CONFIG_PAX_KERNEXEC
4537+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4538+ struct map_desc kernel;
4539+ struct map_desc initmap;
4540+
4541+ /* when freeing initmem we will make this RW */
4542+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4543+ initmap.virtual = (unsigned long)__init_begin;
4544+ initmap.length = _sdata - __init_begin;
4545+ initmap.type = MT_MEMORY_RWX;
4546+ create_mapping(&initmap);
4547+
4548+ /* when freeing initmem we will make this RX */
4549+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4550+ kernel.virtual = (unsigned long)_stext;
4551+ kernel.length = __init_begin - _stext;
4552+ kernel.type = MT_MEMORY_RWX;
4553+ create_mapping(&kernel);
4554+
4555+ if (map.virtual < (unsigned long)_stext) {
4556+ map.length = (unsigned long)_stext - map.virtual;
4557+ map.type = MT_MEMORY_RWX;
4558+ create_mapping(&map);
4559+ }
4560+
4561+ map.pfn = __phys_to_pfn(__pa(_sdata));
4562+ map.virtual = (unsigned long)_sdata;
4563+ map.length = end - __pa(_sdata);
4564+ }
4565+#endif
4566+
4567+ map.type = MT_MEMORY_RW;
4568 create_mapping(&map);
4569 }
4570 }
4571diff --git a/arch/arm/mm/proc-v7-2level.S b/arch/arm/mm/proc-v7-2level.S
4572index 6d98c13..3cfb174 100644
4573--- a/arch/arm/mm/proc-v7-2level.S
4574+++ b/arch/arm/mm/proc-v7-2level.S
4575@@ -99,6 +99,9 @@ ENTRY(cpu_v7_set_pte_ext)
4576 tst r1, #L_PTE_XN
4577 orrne r3, r3, #PTE_EXT_XN
4578
4579+ tst r1, #L_PTE_PXN
4580+ orrne r3, r3, #PTE_EXT_PXN
4581+
4582 tst r1, #L_PTE_YOUNG
4583 tstne r1, #L_PTE_VALID
4584 #ifndef CONFIG_CPU_USE_DOMAINS
4585diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4586index a5bc92d..0bb4730 100644
4587--- a/arch/arm/plat-omap/sram.c
4588+++ b/arch/arm/plat-omap/sram.c
4589@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4590 * Looks like we need to preserve some bootloader code at the
4591 * beginning of SRAM for jumping to flash for reboot to work...
4592 */
4593+ pax_open_kernel();
4594 memset_io(omap_sram_base + omap_sram_skip, 0,
4595 omap_sram_size - omap_sram_skip);
4596+ pax_close_kernel();
4597 }
4598diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4599index f5144cd..71f6d1f 100644
4600--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4601+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4602@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4603 int (*started)(unsigned ch);
4604 int (*flush)(unsigned ch);
4605 int (*stop)(unsigned ch);
4606-};
4607+} __no_const;
4608
4609 extern void *samsung_dmadev_get_ops(void);
4610 extern void *s3c_dma_get_ops(void);
4611diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c
4612index 0c3ba9f..95722b3 100644
4613--- a/arch/arm64/kernel/debug-monitors.c
4614+++ b/arch/arm64/kernel/debug-monitors.c
4615@@ -151,7 +151,7 @@ static int __cpuinit os_lock_notify(struct notifier_block *self,
4616 return NOTIFY_OK;
4617 }
4618
4619-static struct notifier_block __cpuinitdata os_lock_nb = {
4620+static struct notifier_block os_lock_nb = {
4621 .notifier_call = os_lock_notify,
4622 };
4623
4624diff --git a/arch/arm64/kernel/hw_breakpoint.c b/arch/arm64/kernel/hw_breakpoint.c
4625index 5ab825c..96aaec8 100644
4626--- a/arch/arm64/kernel/hw_breakpoint.c
4627+++ b/arch/arm64/kernel/hw_breakpoint.c
4628@@ -831,7 +831,7 @@ static int __cpuinit hw_breakpoint_reset_notify(struct notifier_block *self,
4629 return NOTIFY_OK;
4630 }
4631
4632-static struct notifier_block __cpuinitdata hw_breakpoint_reset_nb = {
4633+static struct notifier_block hw_breakpoint_reset_nb = {
4634 .notifier_call = hw_breakpoint_reset_notify,
4635 };
4636
4637diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4638index c3a58a1..78fbf54 100644
4639--- a/arch/avr32/include/asm/cache.h
4640+++ b/arch/avr32/include/asm/cache.h
4641@@ -1,8 +1,10 @@
4642 #ifndef __ASM_AVR32_CACHE_H
4643 #define __ASM_AVR32_CACHE_H
4644
4645+#include <linux/const.h>
4646+
4647 #define L1_CACHE_SHIFT 5
4648-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4649+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4650
4651 /*
4652 * Memory returned by kmalloc() may be used for DMA, so we must make
4653diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4654index e2c3287..6c4f98c 100644
4655--- a/arch/avr32/include/asm/elf.h
4656+++ b/arch/avr32/include/asm/elf.h
4657@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4658 the loader. We need to make sure that it is out of the way of the program
4659 that it will "exec", and that there is sufficient room for the brk. */
4660
4661-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4662+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4663
4664+#ifdef CONFIG_PAX_ASLR
4665+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4666+
4667+#define PAX_DELTA_MMAP_LEN 15
4668+#define PAX_DELTA_STACK_LEN 15
4669+#endif
4670
4671 /* This yields a mask that user programs can use to figure out what
4672 instruction set this CPU supports. This could be done in user space,
4673diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4674index 479330b..53717a8 100644
4675--- a/arch/avr32/include/asm/kmap_types.h
4676+++ b/arch/avr32/include/asm/kmap_types.h
4677@@ -2,9 +2,9 @@
4678 #define __ASM_AVR32_KMAP_TYPES_H
4679
4680 #ifdef CONFIG_DEBUG_HIGHMEM
4681-# define KM_TYPE_NR 29
4682+# define KM_TYPE_NR 30
4683 #else
4684-# define KM_TYPE_NR 14
4685+# define KM_TYPE_NR 15
4686 #endif
4687
4688 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4689diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4690index b2f2d2d..d1c85cb 100644
4691--- a/arch/avr32/mm/fault.c
4692+++ b/arch/avr32/mm/fault.c
4693@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4694
4695 int exception_trace = 1;
4696
4697+#ifdef CONFIG_PAX_PAGEEXEC
4698+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4699+{
4700+ unsigned long i;
4701+
4702+ printk(KERN_ERR "PAX: bytes at PC: ");
4703+ for (i = 0; i < 20; i++) {
4704+ unsigned char c;
4705+ if (get_user(c, (unsigned char *)pc+i))
4706+ printk(KERN_CONT "???????? ");
4707+ else
4708+ printk(KERN_CONT "%02x ", c);
4709+ }
4710+ printk("\n");
4711+}
4712+#endif
4713+
4714 /*
4715 * This routine handles page faults. It determines the address and the
4716 * problem, and then passes it off to one of the appropriate routines.
4717@@ -174,6 +191,16 @@ bad_area:
4718 up_read(&mm->mmap_sem);
4719
4720 if (user_mode(regs)) {
4721+
4722+#ifdef CONFIG_PAX_PAGEEXEC
4723+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4724+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4725+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4726+ do_group_exit(SIGKILL);
4727+ }
4728+ }
4729+#endif
4730+
4731 if (exception_trace && printk_ratelimit())
4732 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4733 "sp %08lx ecr %lu\n",
4734diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4735index 568885a..f8008df 100644
4736--- a/arch/blackfin/include/asm/cache.h
4737+++ b/arch/blackfin/include/asm/cache.h
4738@@ -7,6 +7,7 @@
4739 #ifndef __ARCH_BLACKFIN_CACHE_H
4740 #define __ARCH_BLACKFIN_CACHE_H
4741
4742+#include <linux/const.h>
4743 #include <linux/linkage.h> /* for asmlinkage */
4744
4745 /*
4746@@ -14,7 +15,7 @@
4747 * Blackfin loads 32 bytes for cache
4748 */
4749 #define L1_CACHE_SHIFT 5
4750-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4751+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4752 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4753
4754 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4755diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4756index aea2718..3639a60 100644
4757--- a/arch/cris/include/arch-v10/arch/cache.h
4758+++ b/arch/cris/include/arch-v10/arch/cache.h
4759@@ -1,8 +1,9 @@
4760 #ifndef _ASM_ARCH_CACHE_H
4761 #define _ASM_ARCH_CACHE_H
4762
4763+#include <linux/const.h>
4764 /* Etrax 100LX have 32-byte cache-lines. */
4765-#define L1_CACHE_BYTES 32
4766 #define L1_CACHE_SHIFT 5
4767+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4768
4769 #endif /* _ASM_ARCH_CACHE_H */
4770diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4771index 7caf25d..ee65ac5 100644
4772--- a/arch/cris/include/arch-v32/arch/cache.h
4773+++ b/arch/cris/include/arch-v32/arch/cache.h
4774@@ -1,11 +1,12 @@
4775 #ifndef _ASM_CRIS_ARCH_CACHE_H
4776 #define _ASM_CRIS_ARCH_CACHE_H
4777
4778+#include <linux/const.h>
4779 #include <arch/hwregs/dma.h>
4780
4781 /* A cache-line is 32 bytes. */
4782-#define L1_CACHE_BYTES 32
4783 #define L1_CACHE_SHIFT 5
4784+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4785
4786 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4787
4788diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4789index b86329d..6709906 100644
4790--- a/arch/frv/include/asm/atomic.h
4791+++ b/arch/frv/include/asm/atomic.h
4792@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4793 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4794 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4795
4796+#define atomic64_read_unchecked(v) atomic64_read(v)
4797+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4798+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4799+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4800+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4801+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4802+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4803+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4804+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4805+
4806 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4807 {
4808 int c, old;
4809diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4810index 2797163..c2a401d 100644
4811--- a/arch/frv/include/asm/cache.h
4812+++ b/arch/frv/include/asm/cache.h
4813@@ -12,10 +12,11 @@
4814 #ifndef __ASM_CACHE_H
4815 #define __ASM_CACHE_H
4816
4817+#include <linux/const.h>
4818
4819 /* bytes per L1 cache line */
4820 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4821-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4822+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4823
4824 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4825 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4826diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4827index 43901f2..0d8b865 100644
4828--- a/arch/frv/include/asm/kmap_types.h
4829+++ b/arch/frv/include/asm/kmap_types.h
4830@@ -2,6 +2,6 @@
4831 #ifndef _ASM_KMAP_TYPES_H
4832 #define _ASM_KMAP_TYPES_H
4833
4834-#define KM_TYPE_NR 17
4835+#define KM_TYPE_NR 18
4836
4837 #endif
4838diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4839index 385fd30..3aaf4fe 100644
4840--- a/arch/frv/mm/elf-fdpic.c
4841+++ b/arch/frv/mm/elf-fdpic.c
4842@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4843 {
4844 struct vm_area_struct *vma;
4845 unsigned long limit;
4846+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4847
4848 if (len > TASK_SIZE)
4849 return -ENOMEM;
4850@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4851 if (addr) {
4852 addr = PAGE_ALIGN(addr);
4853 vma = find_vma(current->mm, addr);
4854- if (TASK_SIZE - len >= addr &&
4855- (!vma || addr + len <= vma->vm_start))
4856+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4857 goto success;
4858 }
4859
4860@@ -89,7 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4861 for (; vma; vma = vma->vm_next) {
4862 if (addr > limit)
4863 break;
4864- if (addr + len <= vma->vm_start)
4865+ if (check_heap_stack_gap(vma, addr, len, offset))
4866 goto success;
4867 addr = vma->vm_end;
4868 }
4869@@ -104,7 +104,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4870 for (; vma; vma = vma->vm_next) {
4871 if (addr > limit)
4872 break;
4873- if (addr + len <= vma->vm_start)
4874+ if (check_heap_stack_gap(vma, addr, len, offset))
4875 goto success;
4876 addr = vma->vm_end;
4877 }
4878diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4879index f4ca594..adc72fd6 100644
4880--- a/arch/hexagon/include/asm/cache.h
4881+++ b/arch/hexagon/include/asm/cache.h
4882@@ -21,9 +21,11 @@
4883 #ifndef __ASM_CACHE_H
4884 #define __ASM_CACHE_H
4885
4886+#include <linux/const.h>
4887+
4888 /* Bytes per L1 cache line */
4889-#define L1_CACHE_SHIFT (5)
4890-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4891+#define L1_CACHE_SHIFT 5
4892+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4893
4894 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4895 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4896diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4897index 6e6fe18..a6ae668 100644
4898--- a/arch/ia64/include/asm/atomic.h
4899+++ b/arch/ia64/include/asm/atomic.h
4900@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4901 #define atomic64_inc(v) atomic64_add(1, (v))
4902 #define atomic64_dec(v) atomic64_sub(1, (v))
4903
4904+#define atomic64_read_unchecked(v) atomic64_read(v)
4905+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4906+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4907+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4908+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4909+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4910+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4911+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4912+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4913+
4914 /* Atomic operations are already serializing */
4915 #define smp_mb__before_atomic_dec() barrier()
4916 #define smp_mb__after_atomic_dec() barrier()
4917diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4918index 988254a..e1ee885 100644
4919--- a/arch/ia64/include/asm/cache.h
4920+++ b/arch/ia64/include/asm/cache.h
4921@@ -1,6 +1,7 @@
4922 #ifndef _ASM_IA64_CACHE_H
4923 #define _ASM_IA64_CACHE_H
4924
4925+#include <linux/const.h>
4926
4927 /*
4928 * Copyright (C) 1998-2000 Hewlett-Packard Co
4929@@ -9,7 +10,7 @@
4930
4931 /* Bytes per L1 (data) cache line. */
4932 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4933-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4934+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4935
4936 #ifdef CONFIG_SMP
4937 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4938diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4939index b5298eb..67c6e62 100644
4940--- a/arch/ia64/include/asm/elf.h
4941+++ b/arch/ia64/include/asm/elf.h
4942@@ -42,6 +42,13 @@
4943 */
4944 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4945
4946+#ifdef CONFIG_PAX_ASLR
4947+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4948+
4949+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4950+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4951+#endif
4952+
4953 #define PT_IA_64_UNWIND 0x70000001
4954
4955 /* IA-64 relocations: */
4956diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4957index 96a8d92..617a1cf 100644
4958--- a/arch/ia64/include/asm/pgalloc.h
4959+++ b/arch/ia64/include/asm/pgalloc.h
4960@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4961 pgd_val(*pgd_entry) = __pa(pud);
4962 }
4963
4964+static inline void
4965+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4966+{
4967+ pgd_populate(mm, pgd_entry, pud);
4968+}
4969+
4970 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4971 {
4972 return quicklist_alloc(0, GFP_KERNEL, NULL);
4973@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4974 pud_val(*pud_entry) = __pa(pmd);
4975 }
4976
4977+static inline void
4978+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4979+{
4980+ pud_populate(mm, pud_entry, pmd);
4981+}
4982+
4983 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
4984 {
4985 return quicklist_alloc(0, GFP_KERNEL, NULL);
4986diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
4987index 815810c..d60bd4c 100644
4988--- a/arch/ia64/include/asm/pgtable.h
4989+++ b/arch/ia64/include/asm/pgtable.h
4990@@ -12,7 +12,7 @@
4991 * David Mosberger-Tang <davidm@hpl.hp.com>
4992 */
4993
4994-
4995+#include <linux/const.h>
4996 #include <asm/mman.h>
4997 #include <asm/page.h>
4998 #include <asm/processor.h>
4999@@ -142,6 +142,17 @@
5000 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5001 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5002 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5003+
5004+#ifdef CONFIG_PAX_PAGEEXEC
5005+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5006+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5007+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5008+#else
5009+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5010+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5011+# define PAGE_COPY_NOEXEC PAGE_COPY
5012+#endif
5013+
5014 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5015 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5016 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5017diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5018index 54ff557..70c88b7 100644
5019--- a/arch/ia64/include/asm/spinlock.h
5020+++ b/arch/ia64/include/asm/spinlock.h
5021@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5022 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5023
5024 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5025- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5026+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5027 }
5028
5029 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5030diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5031index 449c8c0..18965fb 100644
5032--- a/arch/ia64/include/asm/uaccess.h
5033+++ b/arch/ia64/include/asm/uaccess.h
5034@@ -240,12 +240,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5035 static inline unsigned long
5036 __copy_to_user (void __user *to, const void *from, unsigned long count)
5037 {
5038+ if (count > INT_MAX)
5039+ return count;
5040+
5041+ if (!__builtin_constant_p(count))
5042+ check_object_size(from, count, true);
5043+
5044 return __copy_user(to, (__force void __user *) from, count);
5045 }
5046
5047 static inline unsigned long
5048 __copy_from_user (void *to, const void __user *from, unsigned long count)
5049 {
5050+ if (count > INT_MAX)
5051+ return count;
5052+
5053+ if (!__builtin_constant_p(count))
5054+ check_object_size(to, count, false);
5055+
5056 return __copy_user((__force void __user *) to, from, count);
5057 }
5058
5059@@ -255,10 +267,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5060 ({ \
5061 void __user *__cu_to = (to); \
5062 const void *__cu_from = (from); \
5063- long __cu_len = (n); \
5064+ unsigned long __cu_len = (n); \
5065 \
5066- if (__access_ok(__cu_to, __cu_len, get_fs())) \
5067+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5068+ if (!__builtin_constant_p(n)) \
5069+ check_object_size(__cu_from, __cu_len, true); \
5070 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5071+ } \
5072 __cu_len; \
5073 })
5074
5075@@ -266,11 +281,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5076 ({ \
5077 void *__cu_to = (to); \
5078 const void __user *__cu_from = (from); \
5079- long __cu_len = (n); \
5080+ unsigned long __cu_len = (n); \
5081 \
5082 __chk_user_ptr(__cu_from); \
5083- if (__access_ok(__cu_from, __cu_len, get_fs())) \
5084+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5085+ if (!__builtin_constant_p(n)) \
5086+ check_object_size(__cu_to, __cu_len, false); \
5087 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5088+ } \
5089 __cu_len; \
5090 })
5091
5092diff --git a/arch/ia64/kernel/err_inject.c b/arch/ia64/kernel/err_inject.c
5093index 2d67317..07d8bfa 100644
5094--- a/arch/ia64/kernel/err_inject.c
5095+++ b/arch/ia64/kernel/err_inject.c
5096@@ -256,7 +256,7 @@ static int __cpuinit err_inject_cpu_callback(struct notifier_block *nfb,
5097 return NOTIFY_OK;
5098 }
5099
5100-static struct notifier_block __cpuinitdata err_inject_cpu_notifier =
5101+static struct notifier_block err_inject_cpu_notifier =
5102 {
5103 .notifier_call = err_inject_cpu_callback,
5104 };
5105diff --git a/arch/ia64/kernel/mca.c b/arch/ia64/kernel/mca.c
5106index 65bf9cd..794f06b 100644
5107--- a/arch/ia64/kernel/mca.c
5108+++ b/arch/ia64/kernel/mca.c
5109@@ -1922,7 +1922,7 @@ static int __cpuinit mca_cpu_callback(struct notifier_block *nfb,
5110 return NOTIFY_OK;
5111 }
5112
5113-static struct notifier_block mca_cpu_notifier __cpuinitdata = {
5114+static struct notifier_block mca_cpu_notifier = {
5115 .notifier_call = mca_cpu_callback
5116 };
5117
5118diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5119index 24603be..948052d 100644
5120--- a/arch/ia64/kernel/module.c
5121+++ b/arch/ia64/kernel/module.c
5122@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5123 void
5124 module_free (struct module *mod, void *module_region)
5125 {
5126- if (mod && mod->arch.init_unw_table &&
5127- module_region == mod->module_init) {
5128+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5129 unw_remove_unwind_table(mod->arch.init_unw_table);
5130 mod->arch.init_unw_table = NULL;
5131 }
5132@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5133 }
5134
5135 static inline int
5136+in_init_rx (const struct module *mod, uint64_t addr)
5137+{
5138+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5139+}
5140+
5141+static inline int
5142+in_init_rw (const struct module *mod, uint64_t addr)
5143+{
5144+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5145+}
5146+
5147+static inline int
5148 in_init (const struct module *mod, uint64_t addr)
5149 {
5150- return addr - (uint64_t) mod->module_init < mod->init_size;
5151+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5152+}
5153+
5154+static inline int
5155+in_core_rx (const struct module *mod, uint64_t addr)
5156+{
5157+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5158+}
5159+
5160+static inline int
5161+in_core_rw (const struct module *mod, uint64_t addr)
5162+{
5163+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5164 }
5165
5166 static inline int
5167 in_core (const struct module *mod, uint64_t addr)
5168 {
5169- return addr - (uint64_t) mod->module_core < mod->core_size;
5170+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5171 }
5172
5173 static inline int
5174@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5175 break;
5176
5177 case RV_BDREL:
5178- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5179+ if (in_init_rx(mod, val))
5180+ val -= (uint64_t) mod->module_init_rx;
5181+ else if (in_init_rw(mod, val))
5182+ val -= (uint64_t) mod->module_init_rw;
5183+ else if (in_core_rx(mod, val))
5184+ val -= (uint64_t) mod->module_core_rx;
5185+ else if (in_core_rw(mod, val))
5186+ val -= (uint64_t) mod->module_core_rw;
5187 break;
5188
5189 case RV_LTV:
5190@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5191 * addresses have been selected...
5192 */
5193 uint64_t gp;
5194- if (mod->core_size > MAX_LTOFF)
5195+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5196 /*
5197 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5198 * at the end of the module.
5199 */
5200- gp = mod->core_size - MAX_LTOFF / 2;
5201+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5202 else
5203- gp = mod->core_size / 2;
5204- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5205+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5206+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5207 mod->arch.gp = gp;
5208 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5209 }
5210diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5211index 77597e5..189dd62f 100644
5212--- a/arch/ia64/kernel/palinfo.c
5213+++ b/arch/ia64/kernel/palinfo.c
5214@@ -977,7 +977,7 @@ create_palinfo_proc_entries(unsigned int cpu)
5215 struct proc_dir_entry **pdir;
5216 struct proc_dir_entry *cpu_dir;
5217 int j;
5218- char cpustr[sizeof(CPUSTR)];
5219+ char cpustr[3+4+1];
5220
5221
5222 /*
5223@@ -1045,7 +1045,7 @@ static int __cpuinit palinfo_cpu_callback(struct notifier_block *nfb,
5224 return NOTIFY_OK;
5225 }
5226
5227-static struct notifier_block __refdata palinfo_cpu_notifier =
5228+static struct notifier_block palinfo_cpu_notifier =
5229 {
5230 .notifier_call = palinfo_cpu_callback,
5231 .priority = 0,
5232diff --git a/arch/ia64/kernel/salinfo.c b/arch/ia64/kernel/salinfo.c
5233index 79802e5..1a89ec5 100644
5234--- a/arch/ia64/kernel/salinfo.c
5235+++ b/arch/ia64/kernel/salinfo.c
5236@@ -616,7 +616,7 @@ salinfo_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu
5237 return NOTIFY_OK;
5238 }
5239
5240-static struct notifier_block salinfo_cpu_notifier __cpuinitdata =
5241+static struct notifier_block salinfo_cpu_notifier =
5242 {
5243 .notifier_call = salinfo_cpu_callback,
5244 .priority = 0,
5245diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5246index d9439ef..d0cac6b 100644
5247--- a/arch/ia64/kernel/sys_ia64.c
5248+++ b/arch/ia64/kernel/sys_ia64.c
5249@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5250 unsigned long start_addr, align_mask = PAGE_SIZE - 1;
5251 struct mm_struct *mm = current->mm;
5252 struct vm_area_struct *vma;
5253+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5254
5255 if (len > RGN_MAP_LIMIT)
5256 return -ENOMEM;
5257@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5258 if (REGION_NUMBER(addr) == RGN_HPAGE)
5259 addr = 0;
5260 #endif
5261+
5262+#ifdef CONFIG_PAX_RANDMMAP
5263+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5264+ addr = mm->free_area_cache;
5265+ else
5266+#endif
5267+
5268 if (!addr)
5269 addr = mm->free_area_cache;
5270
5271@@ -61,14 +69,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5272 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
5273 /* At this point: (!vma || addr < vma->vm_end). */
5274 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
5275- if (start_addr != TASK_UNMAPPED_BASE) {
5276+ if (start_addr != mm->mmap_base) {
5277 /* Start a new search --- just in case we missed some holes. */
5278- addr = TASK_UNMAPPED_BASE;
5279+ addr = mm->mmap_base;
5280 goto full_search;
5281 }
5282 return -ENOMEM;
5283 }
5284- if (!vma || addr + len <= vma->vm_start) {
5285+ if (check_heap_stack_gap(vma, addr, len, offset)) {
5286 /* Remember the address where we stopped this search: */
5287 mm->free_area_cache = addr + len;
5288 return addr;
5289diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
5290index dc00b2c..cce53c2 100644
5291--- a/arch/ia64/kernel/topology.c
5292+++ b/arch/ia64/kernel/topology.c
5293@@ -445,7 +445,7 @@ static int __cpuinit cache_cpu_callback(struct notifier_block *nfb,
5294 return NOTIFY_OK;
5295 }
5296
5297-static struct notifier_block __cpuinitdata cache_cpu_notifier =
5298+static struct notifier_block cache_cpu_notifier =
5299 {
5300 .notifier_call = cache_cpu_callback
5301 };
5302diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5303index 0ccb28f..8992469 100644
5304--- a/arch/ia64/kernel/vmlinux.lds.S
5305+++ b/arch/ia64/kernel/vmlinux.lds.S
5306@@ -198,7 +198,7 @@ SECTIONS {
5307 /* Per-cpu data: */
5308 . = ALIGN(PERCPU_PAGE_SIZE);
5309 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5310- __phys_per_cpu_start = __per_cpu_load;
5311+ __phys_per_cpu_start = per_cpu_load;
5312 /*
5313 * ensure percpu data fits
5314 * into percpu page size
5315diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5316index 6cf0341..d352594 100644
5317--- a/arch/ia64/mm/fault.c
5318+++ b/arch/ia64/mm/fault.c
5319@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5320 return pte_present(pte);
5321 }
5322
5323+#ifdef CONFIG_PAX_PAGEEXEC
5324+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5325+{
5326+ unsigned long i;
5327+
5328+ printk(KERN_ERR "PAX: bytes at PC: ");
5329+ for (i = 0; i < 8; i++) {
5330+ unsigned int c;
5331+ if (get_user(c, (unsigned int *)pc+i))
5332+ printk(KERN_CONT "???????? ");
5333+ else
5334+ printk(KERN_CONT "%08x ", c);
5335+ }
5336+ printk("\n");
5337+}
5338+#endif
5339+
5340 # define VM_READ_BIT 0
5341 # define VM_WRITE_BIT 1
5342 # define VM_EXEC_BIT 2
5343@@ -149,8 +166,21 @@ retry:
5344 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5345 goto bad_area;
5346
5347- if ((vma->vm_flags & mask) != mask)
5348+ if ((vma->vm_flags & mask) != mask) {
5349+
5350+#ifdef CONFIG_PAX_PAGEEXEC
5351+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5352+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5353+ goto bad_area;
5354+
5355+ up_read(&mm->mmap_sem);
5356+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5357+ do_group_exit(SIGKILL);
5358+ }
5359+#endif
5360+
5361 goto bad_area;
5362+ }
5363
5364 /*
5365 * If for any reason at all we couldn't handle the fault, make
5366diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5367index 5ca674b..127c3cb 100644
5368--- a/arch/ia64/mm/hugetlbpage.c
5369+++ b/arch/ia64/mm/hugetlbpage.c
5370@@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5371 unsigned long pgoff, unsigned long flags)
5372 {
5373 struct vm_area_struct *vmm;
5374+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5375
5376 if (len > RGN_MAP_LIMIT)
5377 return -ENOMEM;
5378@@ -171,7 +172,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5379 /* At this point: (!vmm || addr < vmm->vm_end). */
5380 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
5381 return -ENOMEM;
5382- if (!vmm || (addr + len) <= vmm->vm_start)
5383+ if (check_heap_stack_gap(vmm, addr, len, offset))
5384 return addr;
5385 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
5386 }
5387diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5388index b755ea9..b9a969e 100644
5389--- a/arch/ia64/mm/init.c
5390+++ b/arch/ia64/mm/init.c
5391@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5392 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5393 vma->vm_end = vma->vm_start + PAGE_SIZE;
5394 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5395+
5396+#ifdef CONFIG_PAX_PAGEEXEC
5397+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5398+ vma->vm_flags &= ~VM_EXEC;
5399+
5400+#ifdef CONFIG_PAX_MPROTECT
5401+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5402+ vma->vm_flags &= ~VM_MAYEXEC;
5403+#endif
5404+
5405+ }
5406+#endif
5407+
5408 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5409 down_write(&current->mm->mmap_sem);
5410 if (insert_vm_struct(current->mm, vma)) {
5411diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5412index 40b3ee9..8c2c112 100644
5413--- a/arch/m32r/include/asm/cache.h
5414+++ b/arch/m32r/include/asm/cache.h
5415@@ -1,8 +1,10 @@
5416 #ifndef _ASM_M32R_CACHE_H
5417 #define _ASM_M32R_CACHE_H
5418
5419+#include <linux/const.h>
5420+
5421 /* L1 cache line size */
5422 #define L1_CACHE_SHIFT 4
5423-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5424+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5425
5426 #endif /* _ASM_M32R_CACHE_H */
5427diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5428index 82abd15..d95ae5d 100644
5429--- a/arch/m32r/lib/usercopy.c
5430+++ b/arch/m32r/lib/usercopy.c
5431@@ -14,6 +14,9 @@
5432 unsigned long
5433 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5434 {
5435+ if ((long)n < 0)
5436+ return n;
5437+
5438 prefetch(from);
5439 if (access_ok(VERIFY_WRITE, to, n))
5440 __copy_user(to,from,n);
5441@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5442 unsigned long
5443 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5444 {
5445+ if ((long)n < 0)
5446+ return n;
5447+
5448 prefetchw(to);
5449 if (access_ok(VERIFY_READ, from, n))
5450 __copy_user_zeroing(to,from,n);
5451diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5452index 0395c51..5f26031 100644
5453--- a/arch/m68k/include/asm/cache.h
5454+++ b/arch/m68k/include/asm/cache.h
5455@@ -4,9 +4,11 @@
5456 #ifndef __ARCH_M68K_CACHE_H
5457 #define __ARCH_M68K_CACHE_H
5458
5459+#include <linux/const.h>
5460+
5461 /* bytes per L1 cache line */
5462 #define L1_CACHE_SHIFT 4
5463-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5464+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5465
5466 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5467
5468diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5469index 4efe96a..60e8699 100644
5470--- a/arch/microblaze/include/asm/cache.h
5471+++ b/arch/microblaze/include/asm/cache.h
5472@@ -13,11 +13,12 @@
5473 #ifndef _ASM_MICROBLAZE_CACHE_H
5474 #define _ASM_MICROBLAZE_CACHE_H
5475
5476+#include <linux/const.h>
5477 #include <asm/registers.h>
5478
5479 #define L1_CACHE_SHIFT 5
5480 /* word-granular cache in microblaze */
5481-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5482+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5483
5484 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5485
5486diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5487index 01cc6ba..bcb7a5d 100644
5488--- a/arch/mips/include/asm/atomic.h
5489+++ b/arch/mips/include/asm/atomic.h
5490@@ -21,6 +21,10 @@
5491 #include <asm/cmpxchg.h>
5492 #include <asm/war.h>
5493
5494+#ifdef CONFIG_GENERIC_ATOMIC64
5495+#include <asm-generic/atomic64.h>
5496+#endif
5497+
5498 #define ATOMIC_INIT(i) { (i) }
5499
5500 /*
5501@@ -759,6 +763,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
5502 */
5503 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
5504
5505+#define atomic64_read_unchecked(v) atomic64_read(v)
5506+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5507+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5508+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5509+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5510+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5511+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5512+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5513+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5514+
5515 #endif /* CONFIG_64BIT */
5516
5517 /*
5518diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
5519index b4db69f..8f3b093 100644
5520--- a/arch/mips/include/asm/cache.h
5521+++ b/arch/mips/include/asm/cache.h
5522@@ -9,10 +9,11 @@
5523 #ifndef _ASM_CACHE_H
5524 #define _ASM_CACHE_H
5525
5526+#include <linux/const.h>
5527 #include <kmalloc.h>
5528
5529 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
5530-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5531+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5532
5533 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5534 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5535diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
5536index 455c0ac..ad65fbe 100644
5537--- a/arch/mips/include/asm/elf.h
5538+++ b/arch/mips/include/asm/elf.h
5539@@ -372,13 +372,16 @@ extern const char *__elf_platform;
5540 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
5541 #endif
5542
5543+#ifdef CONFIG_PAX_ASLR
5544+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5545+
5546+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5547+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5548+#endif
5549+
5550 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
5551 struct linux_binprm;
5552 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
5553 int uses_interp);
5554
5555-struct mm_struct;
5556-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5557-#define arch_randomize_brk arch_randomize_brk
5558-
5559 #endif /* _ASM_ELF_H */
5560diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
5561index c1f6afa..38cc6e9 100644
5562--- a/arch/mips/include/asm/exec.h
5563+++ b/arch/mips/include/asm/exec.h
5564@@ -12,6 +12,6 @@
5565 #ifndef _ASM_EXEC_H
5566 #define _ASM_EXEC_H
5567
5568-extern unsigned long arch_align_stack(unsigned long sp);
5569+#define arch_align_stack(x) ((x) & ~0xfUL)
5570
5571 #endif /* _ASM_EXEC_H */
5572diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
5573index dbaec94..6a14935 100644
5574--- a/arch/mips/include/asm/page.h
5575+++ b/arch/mips/include/asm/page.h
5576@@ -96,7 +96,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
5577 #ifdef CONFIG_CPU_MIPS32
5578 typedef struct { unsigned long pte_low, pte_high; } pte_t;
5579 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
5580- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
5581+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
5582 #else
5583 typedef struct { unsigned long long pte; } pte_t;
5584 #define pte_val(x) ((x).pte)
5585diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
5586index 881d18b..cea38bc 100644
5587--- a/arch/mips/include/asm/pgalloc.h
5588+++ b/arch/mips/include/asm/pgalloc.h
5589@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5590 {
5591 set_pud(pud, __pud((unsigned long)pmd));
5592 }
5593+
5594+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5595+{
5596+ pud_populate(mm, pud, pmd);
5597+}
5598 #endif
5599
5600 /*
5601diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
5602index b2050b9..d71bb1b 100644
5603--- a/arch/mips/include/asm/thread_info.h
5604+++ b/arch/mips/include/asm/thread_info.h
5605@@ -111,6 +111,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
5606 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
5607 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
5608 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
5609+/* li takes a 32bit immediate */
5610+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
5611 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
5612
5613 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
5614@@ -126,15 +128,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
5615 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
5616 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
5617 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
5618+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5619+
5620+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5621
5622 /* work to do in syscall_trace_leave() */
5623-#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
5624+#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5625
5626 /* work to do on interrupt/exception return */
5627 #define _TIF_WORK_MASK \
5628 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
5629 /* work to do on any return to u-space */
5630-#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT)
5631+#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
5632
5633 #endif /* __KERNEL__ */
5634
5635diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
5636index 9fdd8bc..4bd7f1a 100644
5637--- a/arch/mips/kernel/binfmt_elfn32.c
5638+++ b/arch/mips/kernel/binfmt_elfn32.c
5639@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5640 #undef ELF_ET_DYN_BASE
5641 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5642
5643+#ifdef CONFIG_PAX_ASLR
5644+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5645+
5646+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5647+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5648+#endif
5649+
5650 #include <asm/processor.h>
5651 #include <linux/module.h>
5652 #include <linux/elfcore.h>
5653diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
5654index ff44823..97f8906 100644
5655--- a/arch/mips/kernel/binfmt_elfo32.c
5656+++ b/arch/mips/kernel/binfmt_elfo32.c
5657@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5658 #undef ELF_ET_DYN_BASE
5659 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5660
5661+#ifdef CONFIG_PAX_ASLR
5662+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5663+
5664+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5665+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5666+#endif
5667+
5668 #include <asm/processor.h>
5669
5670 /*
5671diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
5672index a11c6f9..be5e164 100644
5673--- a/arch/mips/kernel/process.c
5674+++ b/arch/mips/kernel/process.c
5675@@ -460,15 +460,3 @@ unsigned long get_wchan(struct task_struct *task)
5676 out:
5677 return pc;
5678 }
5679-
5680-/*
5681- * Don't forget that the stack pointer must be aligned on a 8 bytes
5682- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
5683- */
5684-unsigned long arch_align_stack(unsigned long sp)
5685-{
5686- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5687- sp -= get_random_int() & ~PAGE_MASK;
5688-
5689- return sp & ALMASK;
5690-}
5691diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
5692index 4812c6d..2069554 100644
5693--- a/arch/mips/kernel/ptrace.c
5694+++ b/arch/mips/kernel/ptrace.c
5695@@ -528,6 +528,10 @@ static inline int audit_arch(void)
5696 return arch;
5697 }
5698
5699+#ifdef CONFIG_GRKERNSEC_SETXID
5700+extern void gr_delayed_cred_worker(void);
5701+#endif
5702+
5703 /*
5704 * Notification of system call entry/exit
5705 * - triggered by current->work.syscall_trace
5706@@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
5707 /* do the secure computing check first */
5708 secure_computing_strict(regs->regs[2]);
5709
5710+#ifdef CONFIG_GRKERNSEC_SETXID
5711+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5712+ gr_delayed_cred_worker();
5713+#endif
5714+
5715 if (!(current->ptrace & PT_PTRACED))
5716 goto out;
5717
5718diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
5719index d20a4bc..7096ae5 100644
5720--- a/arch/mips/kernel/scall32-o32.S
5721+++ b/arch/mips/kernel/scall32-o32.S
5722@@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5723
5724 stack_done:
5725 lw t0, TI_FLAGS($28) # syscall tracing enabled?
5726- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5727+ li t1, _TIF_SYSCALL_WORK
5728 and t0, t1
5729 bnez t0, syscall_trace_entry # -> yes
5730
5731diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
5732index b64f642..0fe6eab 100644
5733--- a/arch/mips/kernel/scall64-64.S
5734+++ b/arch/mips/kernel/scall64-64.S
5735@@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
5736
5737 sd a3, PT_R26(sp) # save a3 for syscall restarting
5738
5739- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5740+ li t1, _TIF_SYSCALL_WORK
5741 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5742 and t0, t1, t0
5743 bnez t0, syscall_trace_entry
5744diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
5745index c29ac19..c592d05 100644
5746--- a/arch/mips/kernel/scall64-n32.S
5747+++ b/arch/mips/kernel/scall64-n32.S
5748@@ -47,7 +47,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
5749
5750 sd a3, PT_R26(sp) # save a3 for syscall restarting
5751
5752- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5753+ li t1, _TIF_SYSCALL_WORK
5754 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5755 and t0, t1, t0
5756 bnez t0, n32_syscall_trace_entry
5757diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
5758index cf3e75e..72e93fe 100644
5759--- a/arch/mips/kernel/scall64-o32.S
5760+++ b/arch/mips/kernel/scall64-o32.S
5761@@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5762 PTR 4b, bad_stack
5763 .previous
5764
5765- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5766+ li t1, _TIF_SYSCALL_WORK
5767 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5768 and t0, t1, t0
5769 bnez t0, trace_a_syscall
5770diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
5771index ddcec1e..c7f983e 100644
5772--- a/arch/mips/mm/fault.c
5773+++ b/arch/mips/mm/fault.c
5774@@ -27,6 +27,23 @@
5775 #include <asm/highmem.h> /* For VMALLOC_END */
5776 #include <linux/kdebug.h>
5777
5778+#ifdef CONFIG_PAX_PAGEEXEC
5779+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5780+{
5781+ unsigned long i;
5782+
5783+ printk(KERN_ERR "PAX: bytes at PC: ");
5784+ for (i = 0; i < 5; i++) {
5785+ unsigned int c;
5786+ if (get_user(c, (unsigned int *)pc+i))
5787+ printk(KERN_CONT "???????? ");
5788+ else
5789+ printk(KERN_CONT "%08x ", c);
5790+ }
5791+ printk("\n");
5792+}
5793+#endif
5794+
5795 /*
5796 * This routine handles page faults. It determines the address,
5797 * and the problem, and then passes it off to one of the appropriate
5798diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
5799index 7e5fe27..479a219 100644
5800--- a/arch/mips/mm/mmap.c
5801+++ b/arch/mips/mm/mmap.c
5802@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5803 struct vm_area_struct *vma;
5804 unsigned long addr = addr0;
5805 int do_color_align;
5806+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5807 struct vm_unmapped_area_info info;
5808
5809 if (unlikely(len > TASK_SIZE))
5810@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5811 do_color_align = 1;
5812
5813 /* requesting a specific address */
5814+
5815+#ifdef CONFIG_PAX_RANDMMAP
5816+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
5817+#endif
5818+
5819 if (addr) {
5820 if (do_color_align)
5821 addr = COLOUR_ALIGN(addr, pgoff);
5822@@ -91,8 +97,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5823 addr = PAGE_ALIGN(addr);
5824
5825 vma = find_vma(mm, addr);
5826- if (TASK_SIZE - len >= addr &&
5827- (!vma || addr + len <= vma->vm_start))
5828+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
5829 return addr;
5830 }
5831
5832@@ -146,6 +151,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5833 {
5834 unsigned long random_factor = 0UL;
5835
5836+#ifdef CONFIG_PAX_RANDMMAP
5837+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5838+#endif
5839+
5840 if (current->flags & PF_RANDOMIZE) {
5841 random_factor = get_random_int();
5842 random_factor = random_factor << PAGE_SHIFT;
5843@@ -157,42 +166,27 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5844
5845 if (mmap_is_legacy()) {
5846 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5847+
5848+#ifdef CONFIG_PAX_RANDMMAP
5849+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5850+ mm->mmap_base += mm->delta_mmap;
5851+#endif
5852+
5853 mm->get_unmapped_area = arch_get_unmapped_area;
5854 mm->unmap_area = arch_unmap_area;
5855 } else {
5856 mm->mmap_base = mmap_base(random_factor);
5857+
5858+#ifdef CONFIG_PAX_RANDMMAP
5859+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5860+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5861+#endif
5862+
5863 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5864 mm->unmap_area = arch_unmap_area_topdown;
5865 }
5866 }
5867
5868-static inline unsigned long brk_rnd(void)
5869-{
5870- unsigned long rnd = get_random_int();
5871-
5872- rnd = rnd << PAGE_SHIFT;
5873- /* 8MB for 32bit, 256MB for 64bit */
5874- if (TASK_IS_32BIT_ADDR)
5875- rnd = rnd & 0x7ffffful;
5876- else
5877- rnd = rnd & 0xffffffful;
5878-
5879- return rnd;
5880-}
5881-
5882-unsigned long arch_randomize_brk(struct mm_struct *mm)
5883-{
5884- unsigned long base = mm->brk;
5885- unsigned long ret;
5886-
5887- ret = PAGE_ALIGN(base + brk_rnd());
5888-
5889- if (ret < mm->brk)
5890- return mm->brk;
5891-
5892- return ret;
5893-}
5894-
5895 int __virt_addr_valid(const volatile void *kaddr)
5896 {
5897 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
5898diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5899index 967d144..db12197 100644
5900--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
5901+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5902@@ -11,12 +11,14 @@
5903 #ifndef _ASM_PROC_CACHE_H
5904 #define _ASM_PROC_CACHE_H
5905
5906+#include <linux/const.h>
5907+
5908 /* L1 cache */
5909
5910 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5911 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
5912-#define L1_CACHE_BYTES 16 /* bytes per entry */
5913 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
5914+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5915 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
5916
5917 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5918diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5919index bcb5df2..84fabd2 100644
5920--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5921+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5922@@ -16,13 +16,15 @@
5923 #ifndef _ASM_PROC_CACHE_H
5924 #define _ASM_PROC_CACHE_H
5925
5926+#include <linux/const.h>
5927+
5928 /*
5929 * L1 cache
5930 */
5931 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5932 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
5933-#define L1_CACHE_BYTES 32 /* bytes per entry */
5934 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
5935+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5936 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
5937
5938 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5939diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
5940index 4ce7a01..449202a 100644
5941--- a/arch/openrisc/include/asm/cache.h
5942+++ b/arch/openrisc/include/asm/cache.h
5943@@ -19,11 +19,13 @@
5944 #ifndef __ASM_OPENRISC_CACHE_H
5945 #define __ASM_OPENRISC_CACHE_H
5946
5947+#include <linux/const.h>
5948+
5949 /* FIXME: How can we replace these with values from the CPU...
5950 * they shouldn't be hard-coded!
5951 */
5952
5953-#define L1_CACHE_BYTES 16
5954 #define L1_CACHE_SHIFT 4
5955+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5956
5957 #endif /* __ASM_OPENRISC_CACHE_H */
5958diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
5959index af9cf30..2aae9b2 100644
5960--- a/arch/parisc/include/asm/atomic.h
5961+++ b/arch/parisc/include/asm/atomic.h
5962@@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
5963
5964 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5965
5966+#define atomic64_read_unchecked(v) atomic64_read(v)
5967+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5968+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5969+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5970+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5971+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5972+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5973+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5974+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5975+
5976 #endif /* !CONFIG_64BIT */
5977
5978
5979diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
5980index 47f11c7..3420df2 100644
5981--- a/arch/parisc/include/asm/cache.h
5982+++ b/arch/parisc/include/asm/cache.h
5983@@ -5,6 +5,7 @@
5984 #ifndef __ARCH_PARISC_CACHE_H
5985 #define __ARCH_PARISC_CACHE_H
5986
5987+#include <linux/const.h>
5988
5989 /*
5990 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
5991@@ -15,13 +16,13 @@
5992 * just ruin performance.
5993 */
5994 #ifdef CONFIG_PA20
5995-#define L1_CACHE_BYTES 64
5996 #define L1_CACHE_SHIFT 6
5997 #else
5998-#define L1_CACHE_BYTES 32
5999 #define L1_CACHE_SHIFT 5
6000 #endif
6001
6002+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6003+
6004 #ifndef __ASSEMBLY__
6005
6006 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6007diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
6008index 19f6cb1..6c78cf2 100644
6009--- a/arch/parisc/include/asm/elf.h
6010+++ b/arch/parisc/include/asm/elf.h
6011@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
6012
6013 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
6014
6015+#ifdef CONFIG_PAX_ASLR
6016+#define PAX_ELF_ET_DYN_BASE 0x10000UL
6017+
6018+#define PAX_DELTA_MMAP_LEN 16
6019+#define PAX_DELTA_STACK_LEN 16
6020+#endif
6021+
6022 /* This yields a mask that user programs can use to figure out what
6023 instruction set this CPU supports. This could be done in user space,
6024 but it's not easy, and we've already done it here. */
6025diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
6026index fc987a1..6e068ef 100644
6027--- a/arch/parisc/include/asm/pgalloc.h
6028+++ b/arch/parisc/include/asm/pgalloc.h
6029@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
6030 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
6031 }
6032
6033+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
6034+{
6035+ pgd_populate(mm, pgd, pmd);
6036+}
6037+
6038 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
6039 {
6040 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
6041@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
6042 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
6043 #define pmd_free(mm, x) do { } while (0)
6044 #define pgd_populate(mm, pmd, pte) BUG()
6045+#define pgd_populate_kernel(mm, pmd, pte) BUG()
6046
6047 #endif
6048
6049diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
6050index 7df49fa..38b62bf 100644
6051--- a/arch/parisc/include/asm/pgtable.h
6052+++ b/arch/parisc/include/asm/pgtable.h
6053@@ -218,6 +218,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
6054 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
6055 #define PAGE_COPY PAGE_EXECREAD
6056 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
6057+
6058+#ifdef CONFIG_PAX_PAGEEXEC
6059+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
6060+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
6061+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
6062+#else
6063+# define PAGE_SHARED_NOEXEC PAGE_SHARED
6064+# define PAGE_COPY_NOEXEC PAGE_COPY
6065+# define PAGE_READONLY_NOEXEC PAGE_READONLY
6066+#endif
6067+
6068 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
6069 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
6070 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
6071diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
6072index 4ba2c93..f5e3974 100644
6073--- a/arch/parisc/include/asm/uaccess.h
6074+++ b/arch/parisc/include/asm/uaccess.h
6075@@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
6076 const void __user *from,
6077 unsigned long n)
6078 {
6079- int sz = __compiletime_object_size(to);
6080+ size_t sz = __compiletime_object_size(to);
6081 int ret = -EFAULT;
6082
6083- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
6084+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
6085 ret = __copy_from_user(to, from, n);
6086 else
6087 copy_from_user_overflow();
6088diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
6089index 2a625fb..9908930 100644
6090--- a/arch/parisc/kernel/module.c
6091+++ b/arch/parisc/kernel/module.c
6092@@ -98,16 +98,38 @@
6093
6094 /* three functions to determine where in the module core
6095 * or init pieces the location is */
6096+static inline int in_init_rx(struct module *me, void *loc)
6097+{
6098+ return (loc >= me->module_init_rx &&
6099+ loc < (me->module_init_rx + me->init_size_rx));
6100+}
6101+
6102+static inline int in_init_rw(struct module *me, void *loc)
6103+{
6104+ return (loc >= me->module_init_rw &&
6105+ loc < (me->module_init_rw + me->init_size_rw));
6106+}
6107+
6108 static inline int in_init(struct module *me, void *loc)
6109 {
6110- return (loc >= me->module_init &&
6111- loc <= (me->module_init + me->init_size));
6112+ return in_init_rx(me, loc) || in_init_rw(me, loc);
6113+}
6114+
6115+static inline int in_core_rx(struct module *me, void *loc)
6116+{
6117+ return (loc >= me->module_core_rx &&
6118+ loc < (me->module_core_rx + me->core_size_rx));
6119+}
6120+
6121+static inline int in_core_rw(struct module *me, void *loc)
6122+{
6123+ return (loc >= me->module_core_rw &&
6124+ loc < (me->module_core_rw + me->core_size_rw));
6125 }
6126
6127 static inline int in_core(struct module *me, void *loc)
6128 {
6129- return (loc >= me->module_core &&
6130- loc <= (me->module_core + me->core_size));
6131+ return in_core_rx(me, loc) || in_core_rw(me, loc);
6132 }
6133
6134 static inline int in_local(struct module *me, void *loc)
6135@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
6136 }
6137
6138 /* align things a bit */
6139- me->core_size = ALIGN(me->core_size, 16);
6140- me->arch.got_offset = me->core_size;
6141- me->core_size += gots * sizeof(struct got_entry);
6142+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
6143+ me->arch.got_offset = me->core_size_rw;
6144+ me->core_size_rw += gots * sizeof(struct got_entry);
6145
6146- me->core_size = ALIGN(me->core_size, 16);
6147- me->arch.fdesc_offset = me->core_size;
6148- me->core_size += fdescs * sizeof(Elf_Fdesc);
6149+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
6150+ me->arch.fdesc_offset = me->core_size_rw;
6151+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
6152
6153 me->arch.got_max = gots;
6154 me->arch.fdesc_max = fdescs;
6155@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
6156
6157 BUG_ON(value == 0);
6158
6159- got = me->module_core + me->arch.got_offset;
6160+ got = me->module_core_rw + me->arch.got_offset;
6161 for (i = 0; got[i].addr; i++)
6162 if (got[i].addr == value)
6163 goto out;
6164@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
6165 #ifdef CONFIG_64BIT
6166 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
6167 {
6168- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
6169+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
6170
6171 if (!value) {
6172 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
6173@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
6174
6175 /* Create new one */
6176 fdesc->addr = value;
6177- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
6178+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
6179 return (Elf_Addr)fdesc;
6180 }
6181 #endif /* CONFIG_64BIT */
6182@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
6183
6184 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
6185 end = table + sechdrs[me->arch.unwind_section].sh_size;
6186- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
6187+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
6188
6189 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
6190 me->arch.unwind_section, table, end, gp);
6191diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
6192index f76c108..92bad82 100644
6193--- a/arch/parisc/kernel/sys_parisc.c
6194+++ b/arch/parisc/kernel/sys_parisc.c
6195@@ -33,9 +33,11 @@
6196 #include <linux/utsname.h>
6197 #include <linux/personality.h>
6198
6199-static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
6200+static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
6201+ unsigned long flags)
6202 {
6203 struct vm_area_struct *vma;
6204+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
6205
6206 addr = PAGE_ALIGN(addr);
6207
6208@@ -43,7 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
6209 /* At this point: (!vma || addr < vma->vm_end). */
6210 if (TASK_SIZE - len < addr)
6211 return -ENOMEM;
6212- if (!vma || addr + len <= vma->vm_start)
6213+ if (check_heap_stack_gap(vma, addr, len, offset))
6214 return addr;
6215 addr = vma->vm_end;
6216 }
6217@@ -67,11 +69,12 @@ static int get_offset(struct address_space *mapping)
6218 return offset & 0x3FF000;
6219 }
6220
6221-static unsigned long get_shared_area(struct address_space *mapping,
6222- unsigned long addr, unsigned long len, unsigned long pgoff)
6223+static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
6224+ unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
6225 {
6226 struct vm_area_struct *vma;
6227 int offset = mapping ? get_offset(mapping) : 0;
6228+ unsigned long rand_offset = gr_rand_threadstack_offset(current->mm, filp, flags);
6229
6230 offset = (offset + (pgoff << PAGE_SHIFT)) & 0x3FF000;
6231
6232@@ -81,7 +84,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
6233 /* At this point: (!vma || addr < vma->vm_end). */
6234 if (TASK_SIZE - len < addr)
6235 return -ENOMEM;
6236- if (!vma || addr + len <= vma->vm_start)
6237+ if (check_heap_stack_gap(vma, addr, len, rand_offset))
6238 return addr;
6239 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
6240 if (addr < vma->vm_end) /* handle wraparound */
6241@@ -100,14 +103,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
6242 if (flags & MAP_FIXED)
6243 return addr;
6244 if (!addr)
6245- addr = TASK_UNMAPPED_BASE;
6246+ addr = current->mm->mmap_base;
6247
6248 if (filp) {
6249- addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
6250+ addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
6251 } else if(flags & MAP_SHARED) {
6252- addr = get_shared_area(NULL, addr, len, pgoff);
6253+ addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
6254 } else {
6255- addr = get_unshared_area(addr, len);
6256+ addr = get_unshared_area(filp, addr, len, flags);
6257 }
6258 return addr;
6259 }
6260diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
6261index 45ba99f..8e22c33 100644
6262--- a/arch/parisc/kernel/traps.c
6263+++ b/arch/parisc/kernel/traps.c
6264@@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
6265
6266 down_read(&current->mm->mmap_sem);
6267 vma = find_vma(current->mm,regs->iaoq[0]);
6268- if (vma && (regs->iaoq[0] >= vma->vm_start)
6269- && (vma->vm_flags & VM_EXEC)) {
6270-
6271+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
6272 fault_address = regs->iaoq[0];
6273 fault_space = regs->iasq[0];
6274
6275diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
6276index 18162ce..94de376 100644
6277--- a/arch/parisc/mm/fault.c
6278+++ b/arch/parisc/mm/fault.c
6279@@ -15,6 +15,7 @@
6280 #include <linux/sched.h>
6281 #include <linux/interrupt.h>
6282 #include <linux/module.h>
6283+#include <linux/unistd.h>
6284
6285 #include <asm/uaccess.h>
6286 #include <asm/traps.h>
6287@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
6288 static unsigned long
6289 parisc_acctyp(unsigned long code, unsigned int inst)
6290 {
6291- if (code == 6 || code == 16)
6292+ if (code == 6 || code == 7 || code == 16)
6293 return VM_EXEC;
6294
6295 switch (inst & 0xf0000000) {
6296@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
6297 }
6298 #endif
6299
6300+#ifdef CONFIG_PAX_PAGEEXEC
6301+/*
6302+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
6303+ *
6304+ * returns 1 when task should be killed
6305+ * 2 when rt_sigreturn trampoline was detected
6306+ * 3 when unpatched PLT trampoline was detected
6307+ */
6308+static int pax_handle_fetch_fault(struct pt_regs *regs)
6309+{
6310+
6311+#ifdef CONFIG_PAX_EMUPLT
6312+ int err;
6313+
6314+ do { /* PaX: unpatched PLT emulation */
6315+ unsigned int bl, depwi;
6316+
6317+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
6318+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
6319+
6320+ if (err)
6321+ break;
6322+
6323+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
6324+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
6325+
6326+ err = get_user(ldw, (unsigned int *)addr);
6327+ err |= get_user(bv, (unsigned int *)(addr+4));
6328+ err |= get_user(ldw2, (unsigned int *)(addr+8));
6329+
6330+ if (err)
6331+ break;
6332+
6333+ if (ldw == 0x0E801096U &&
6334+ bv == 0xEAC0C000U &&
6335+ ldw2 == 0x0E881095U)
6336+ {
6337+ unsigned int resolver, map;
6338+
6339+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
6340+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
6341+ if (err)
6342+ break;
6343+
6344+ regs->gr[20] = instruction_pointer(regs)+8;
6345+ regs->gr[21] = map;
6346+ regs->gr[22] = resolver;
6347+ regs->iaoq[0] = resolver | 3UL;
6348+ regs->iaoq[1] = regs->iaoq[0] + 4;
6349+ return 3;
6350+ }
6351+ }
6352+ } while (0);
6353+#endif
6354+
6355+#ifdef CONFIG_PAX_EMUTRAMP
6356+
6357+#ifndef CONFIG_PAX_EMUSIGRT
6358+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
6359+ return 1;
6360+#endif
6361+
6362+ do { /* PaX: rt_sigreturn emulation */
6363+ unsigned int ldi1, ldi2, bel, nop;
6364+
6365+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
6366+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
6367+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
6368+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
6369+
6370+ if (err)
6371+ break;
6372+
6373+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
6374+ ldi2 == 0x3414015AU &&
6375+ bel == 0xE4008200U &&
6376+ nop == 0x08000240U)
6377+ {
6378+ regs->gr[25] = (ldi1 & 2) >> 1;
6379+ regs->gr[20] = __NR_rt_sigreturn;
6380+ regs->gr[31] = regs->iaoq[1] + 16;
6381+ regs->sr[0] = regs->iasq[1];
6382+ regs->iaoq[0] = 0x100UL;
6383+ regs->iaoq[1] = regs->iaoq[0] + 4;
6384+ regs->iasq[0] = regs->sr[2];
6385+ regs->iasq[1] = regs->sr[2];
6386+ return 2;
6387+ }
6388+ } while (0);
6389+#endif
6390+
6391+ return 1;
6392+}
6393+
6394+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6395+{
6396+ unsigned long i;
6397+
6398+ printk(KERN_ERR "PAX: bytes at PC: ");
6399+ for (i = 0; i < 5; i++) {
6400+ unsigned int c;
6401+ if (get_user(c, (unsigned int *)pc+i))
6402+ printk(KERN_CONT "???????? ");
6403+ else
6404+ printk(KERN_CONT "%08x ", c);
6405+ }
6406+ printk("\n");
6407+}
6408+#endif
6409+
6410 int fixup_exception(struct pt_regs *regs)
6411 {
6412 const struct exception_table_entry *fix;
6413@@ -192,8 +303,33 @@ good_area:
6414
6415 acc_type = parisc_acctyp(code,regs->iir);
6416
6417- if ((vma->vm_flags & acc_type) != acc_type)
6418+ if ((vma->vm_flags & acc_type) != acc_type) {
6419+
6420+#ifdef CONFIG_PAX_PAGEEXEC
6421+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
6422+ (address & ~3UL) == instruction_pointer(regs))
6423+ {
6424+ up_read(&mm->mmap_sem);
6425+ switch (pax_handle_fetch_fault(regs)) {
6426+
6427+#ifdef CONFIG_PAX_EMUPLT
6428+ case 3:
6429+ return;
6430+#endif
6431+
6432+#ifdef CONFIG_PAX_EMUTRAMP
6433+ case 2:
6434+ return;
6435+#endif
6436+
6437+ }
6438+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
6439+ do_group_exit(SIGKILL);
6440+ }
6441+#endif
6442+
6443 goto bad_area;
6444+ }
6445
6446 /*
6447 * If for any reason at all we couldn't handle the fault, make
6448diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
6449index e3b1d41..8e81edf 100644
6450--- a/arch/powerpc/include/asm/atomic.h
6451+++ b/arch/powerpc/include/asm/atomic.h
6452@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
6453 return t1;
6454 }
6455
6456+#define atomic64_read_unchecked(v) atomic64_read(v)
6457+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
6458+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
6459+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
6460+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
6461+#define atomic64_inc_unchecked(v) atomic64_inc(v)
6462+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
6463+#define atomic64_dec_unchecked(v) atomic64_dec(v)
6464+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
6465+
6466 #endif /* __powerpc64__ */
6467
6468 #endif /* __KERNEL__ */
6469diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
6470index 9e495c9..b6878e5 100644
6471--- a/arch/powerpc/include/asm/cache.h
6472+++ b/arch/powerpc/include/asm/cache.h
6473@@ -3,6 +3,7 @@
6474
6475 #ifdef __KERNEL__
6476
6477+#include <linux/const.h>
6478
6479 /* bytes per L1 cache line */
6480 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
6481@@ -22,7 +23,7 @@
6482 #define L1_CACHE_SHIFT 7
6483 #endif
6484
6485-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6486+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6487
6488 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6489
6490diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
6491index 6abf0a1..459d0f1 100644
6492--- a/arch/powerpc/include/asm/elf.h
6493+++ b/arch/powerpc/include/asm/elf.h
6494@@ -28,8 +28,19 @@
6495 the loader. We need to make sure that it is out of the way of the program
6496 that it will "exec", and that there is sufficient room for the brk. */
6497
6498-extern unsigned long randomize_et_dyn(unsigned long base);
6499-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
6500+#define ELF_ET_DYN_BASE (0x20000000)
6501+
6502+#ifdef CONFIG_PAX_ASLR
6503+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
6504+
6505+#ifdef __powerpc64__
6506+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
6507+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
6508+#else
6509+#define PAX_DELTA_MMAP_LEN 15
6510+#define PAX_DELTA_STACK_LEN 15
6511+#endif
6512+#endif
6513
6514 /*
6515 * Our registers are always unsigned longs, whether we're a 32 bit
6516@@ -124,10 +135,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6517 (0x7ff >> (PAGE_SHIFT - 12)) : \
6518 (0x3ffff >> (PAGE_SHIFT - 12)))
6519
6520-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6521-#define arch_randomize_brk arch_randomize_brk
6522-
6523-
6524 #ifdef CONFIG_SPU_BASE
6525 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
6526 #define NT_SPU 1
6527diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
6528index 8196e9c..d83a9f3 100644
6529--- a/arch/powerpc/include/asm/exec.h
6530+++ b/arch/powerpc/include/asm/exec.h
6531@@ -4,6 +4,6 @@
6532 #ifndef _ASM_POWERPC_EXEC_H
6533 #define _ASM_POWERPC_EXEC_H
6534
6535-extern unsigned long arch_align_stack(unsigned long sp);
6536+#define arch_align_stack(x) ((x) & ~0xfUL)
6537
6538 #endif /* _ASM_POWERPC_EXEC_H */
6539diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
6540index 5acabbd..7ea14fa 100644
6541--- a/arch/powerpc/include/asm/kmap_types.h
6542+++ b/arch/powerpc/include/asm/kmap_types.h
6543@@ -10,7 +10,7 @@
6544 * 2 of the License, or (at your option) any later version.
6545 */
6546
6547-#define KM_TYPE_NR 16
6548+#define KM_TYPE_NR 17
6549
6550 #endif /* __KERNEL__ */
6551 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
6552diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
6553index 8565c25..2865190 100644
6554--- a/arch/powerpc/include/asm/mman.h
6555+++ b/arch/powerpc/include/asm/mman.h
6556@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
6557 }
6558 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
6559
6560-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
6561+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
6562 {
6563 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
6564 }
6565diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
6566index f072e97..b436dee 100644
6567--- a/arch/powerpc/include/asm/page.h
6568+++ b/arch/powerpc/include/asm/page.h
6569@@ -220,8 +220,9 @@ extern long long virt_phys_offset;
6570 * and needs to be executable. This means the whole heap ends
6571 * up being executable.
6572 */
6573-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6574- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6575+#define VM_DATA_DEFAULT_FLAGS32 \
6576+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6577+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6578
6579 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6580 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6581@@ -249,6 +250,9 @@ extern long long virt_phys_offset;
6582 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
6583 #endif
6584
6585+#define ktla_ktva(addr) (addr)
6586+#define ktva_ktla(addr) (addr)
6587+
6588 /*
6589 * Use the top bit of the higher-level page table entries to indicate whether
6590 * the entries we point to contain hugepages. This works because we know that
6591diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
6592index cd915d6..c10cee8 100644
6593--- a/arch/powerpc/include/asm/page_64.h
6594+++ b/arch/powerpc/include/asm/page_64.h
6595@@ -154,15 +154,18 @@ do { \
6596 * stack by default, so in the absence of a PT_GNU_STACK program header
6597 * we turn execute permission off.
6598 */
6599-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6600- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6601+#define VM_STACK_DEFAULT_FLAGS32 \
6602+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6603+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6604
6605 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6606 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6607
6608+#ifndef CONFIG_PAX_PAGEEXEC
6609 #define VM_STACK_DEFAULT_FLAGS \
6610 (is_32bit_task() ? \
6611 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
6612+#endif
6613
6614 #include <asm-generic/getorder.h>
6615
6616diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
6617index 292725c..f87ae14 100644
6618--- a/arch/powerpc/include/asm/pgalloc-64.h
6619+++ b/arch/powerpc/include/asm/pgalloc-64.h
6620@@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
6621 #ifndef CONFIG_PPC_64K_PAGES
6622
6623 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
6624+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
6625
6626 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
6627 {
6628@@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6629 pud_set(pud, (unsigned long)pmd);
6630 }
6631
6632+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6633+{
6634+ pud_populate(mm, pud, pmd);
6635+}
6636+
6637 #define pmd_populate(mm, pmd, pte_page) \
6638 pmd_populate_kernel(mm, pmd, page_address(pte_page))
6639 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
6640@@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6641 #else /* CONFIG_PPC_64K_PAGES */
6642
6643 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
6644+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
6645
6646 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
6647 pte_t *pte)
6648diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
6649index a9cbd3b..3b67efa 100644
6650--- a/arch/powerpc/include/asm/pgtable.h
6651+++ b/arch/powerpc/include/asm/pgtable.h
6652@@ -2,6 +2,7 @@
6653 #define _ASM_POWERPC_PGTABLE_H
6654 #ifdef __KERNEL__
6655
6656+#include <linux/const.h>
6657 #ifndef __ASSEMBLY__
6658 #include <asm/processor.h> /* For TASK_SIZE */
6659 #include <asm/mmu.h>
6660diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
6661index 4aad413..85d86bf 100644
6662--- a/arch/powerpc/include/asm/pte-hash32.h
6663+++ b/arch/powerpc/include/asm/pte-hash32.h
6664@@ -21,6 +21,7 @@
6665 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
6666 #define _PAGE_USER 0x004 /* usermode access allowed */
6667 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
6668+#define _PAGE_EXEC _PAGE_GUARDED
6669 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
6670 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
6671 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
6672diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
6673index 3d5c9dc..62f8414 100644
6674--- a/arch/powerpc/include/asm/reg.h
6675+++ b/arch/powerpc/include/asm/reg.h
6676@@ -215,6 +215,7 @@
6677 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
6678 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
6679 #define DSISR_NOHPTE 0x40000000 /* no translation found */
6680+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
6681 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
6682 #define DSISR_ISSTORE 0x02000000 /* access was a store */
6683 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
6684diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
6685index 195ce2a..ab5c614 100644
6686--- a/arch/powerpc/include/asm/smp.h
6687+++ b/arch/powerpc/include/asm/smp.h
6688@@ -50,7 +50,7 @@ struct smp_ops_t {
6689 int (*cpu_disable)(void);
6690 void (*cpu_die)(unsigned int nr);
6691 int (*cpu_bootable)(unsigned int nr);
6692-};
6693+} __no_const;
6694
6695 extern void smp_send_debugger_break(void);
6696 extern void start_secondary_resume(void);
6697diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
6698index 406b7b9..af63426 100644
6699--- a/arch/powerpc/include/asm/thread_info.h
6700+++ b/arch/powerpc/include/asm/thread_info.h
6701@@ -97,7 +97,6 @@ static inline struct thread_info *current_thread_info(void)
6702 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
6703 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
6704 #define TIF_SINGLESTEP 8 /* singlestepping active */
6705-#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
6706 #define TIF_SECCOMP 10 /* secure computing */
6707 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
6708 #define TIF_NOERROR 12 /* Force successful syscall return */
6709@@ -106,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
6710 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
6711 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
6712 for stack store? */
6713+#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
6714+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
6715+#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
6716
6717 /* as above, but as bit values */
6718 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6719@@ -124,8 +126,10 @@ static inline struct thread_info *current_thread_info(void)
6720 #define _TIF_UPROBE (1<<TIF_UPROBE)
6721 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6722 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
6723+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6724 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
6725- _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
6726+ _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
6727+ _TIF_GRSEC_SETXID)
6728
6729 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
6730 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
6731diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
6732index 4db4959..aba5c41 100644
6733--- a/arch/powerpc/include/asm/uaccess.h
6734+++ b/arch/powerpc/include/asm/uaccess.h
6735@@ -318,52 +318,6 @@ do { \
6736 extern unsigned long __copy_tofrom_user(void __user *to,
6737 const void __user *from, unsigned long size);
6738
6739-#ifndef __powerpc64__
6740-
6741-static inline unsigned long copy_from_user(void *to,
6742- const void __user *from, unsigned long n)
6743-{
6744- unsigned long over;
6745-
6746- if (access_ok(VERIFY_READ, from, n))
6747- return __copy_tofrom_user((__force void __user *)to, from, n);
6748- if ((unsigned long)from < TASK_SIZE) {
6749- over = (unsigned long)from + n - TASK_SIZE;
6750- return __copy_tofrom_user((__force void __user *)to, from,
6751- n - over) + over;
6752- }
6753- return n;
6754-}
6755-
6756-static inline unsigned long copy_to_user(void __user *to,
6757- const void *from, unsigned long n)
6758-{
6759- unsigned long over;
6760-
6761- if (access_ok(VERIFY_WRITE, to, n))
6762- return __copy_tofrom_user(to, (__force void __user *)from, n);
6763- if ((unsigned long)to < TASK_SIZE) {
6764- over = (unsigned long)to + n - TASK_SIZE;
6765- return __copy_tofrom_user(to, (__force void __user *)from,
6766- n - over) + over;
6767- }
6768- return n;
6769-}
6770-
6771-#else /* __powerpc64__ */
6772-
6773-#define __copy_in_user(to, from, size) \
6774- __copy_tofrom_user((to), (from), (size))
6775-
6776-extern unsigned long copy_from_user(void *to, const void __user *from,
6777- unsigned long n);
6778-extern unsigned long copy_to_user(void __user *to, const void *from,
6779- unsigned long n);
6780-extern unsigned long copy_in_user(void __user *to, const void __user *from,
6781- unsigned long n);
6782-
6783-#endif /* __powerpc64__ */
6784-
6785 static inline unsigned long __copy_from_user_inatomic(void *to,
6786 const void __user *from, unsigned long n)
6787 {
6788@@ -387,6 +341,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
6789 if (ret == 0)
6790 return 0;
6791 }
6792+
6793+ if (!__builtin_constant_p(n))
6794+ check_object_size(to, n, false);
6795+
6796 return __copy_tofrom_user((__force void __user *)to, from, n);
6797 }
6798
6799@@ -413,6 +371,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
6800 if (ret == 0)
6801 return 0;
6802 }
6803+
6804+ if (!__builtin_constant_p(n))
6805+ check_object_size(from, n, true);
6806+
6807 return __copy_tofrom_user(to, (__force const void __user *)from, n);
6808 }
6809
6810@@ -430,6 +392,92 @@ static inline unsigned long __copy_to_user(void __user *to,
6811 return __copy_to_user_inatomic(to, from, size);
6812 }
6813
6814+#ifndef __powerpc64__
6815+
6816+static inline unsigned long __must_check copy_from_user(void *to,
6817+ const void __user *from, unsigned long n)
6818+{
6819+ unsigned long over;
6820+
6821+ if ((long)n < 0)
6822+ return n;
6823+
6824+ if (access_ok(VERIFY_READ, from, n)) {
6825+ if (!__builtin_constant_p(n))
6826+ check_object_size(to, n, false);
6827+ return __copy_tofrom_user((__force void __user *)to, from, n);
6828+ }
6829+ if ((unsigned long)from < TASK_SIZE) {
6830+ over = (unsigned long)from + n - TASK_SIZE;
6831+ if (!__builtin_constant_p(n - over))
6832+ check_object_size(to, n - over, false);
6833+ return __copy_tofrom_user((__force void __user *)to, from,
6834+ n - over) + over;
6835+ }
6836+ return n;
6837+}
6838+
6839+static inline unsigned long __must_check copy_to_user(void __user *to,
6840+ const void *from, unsigned long n)
6841+{
6842+ unsigned long over;
6843+
6844+ if ((long)n < 0)
6845+ return n;
6846+
6847+ if (access_ok(VERIFY_WRITE, to, n)) {
6848+ if (!__builtin_constant_p(n))
6849+ check_object_size(from, n, true);
6850+ return __copy_tofrom_user(to, (__force void __user *)from, n);
6851+ }
6852+ if ((unsigned long)to < TASK_SIZE) {
6853+ over = (unsigned long)to + n - TASK_SIZE;
6854+ if (!__builtin_constant_p(n))
6855+ check_object_size(from, n - over, true);
6856+ return __copy_tofrom_user(to, (__force void __user *)from,
6857+ n - over) + over;
6858+ }
6859+ return n;
6860+}
6861+
6862+#else /* __powerpc64__ */
6863+
6864+#define __copy_in_user(to, from, size) \
6865+ __copy_tofrom_user((to), (from), (size))
6866+
6867+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
6868+{
6869+ if ((long)n < 0 || n > INT_MAX)
6870+ return n;
6871+
6872+ if (!__builtin_constant_p(n))
6873+ check_object_size(to, n, false);
6874+
6875+ if (likely(access_ok(VERIFY_READ, from, n)))
6876+ n = __copy_from_user(to, from, n);
6877+ else
6878+ memset(to, 0, n);
6879+ return n;
6880+}
6881+
6882+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
6883+{
6884+ if ((long)n < 0 || n > INT_MAX)
6885+ return n;
6886+
6887+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
6888+ if (!__builtin_constant_p(n))
6889+ check_object_size(from, n, true);
6890+ n = __copy_to_user(to, from, n);
6891+ }
6892+ return n;
6893+}
6894+
6895+extern unsigned long copy_in_user(void __user *to, const void __user *from,
6896+ unsigned long n);
6897+
6898+#endif /* __powerpc64__ */
6899+
6900 extern unsigned long __clear_user(void __user *addr, unsigned long size);
6901
6902 static inline unsigned long clear_user(void __user *addr, unsigned long size)
6903diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
6904index 4684e33..acc4d19e 100644
6905--- a/arch/powerpc/kernel/exceptions-64e.S
6906+++ b/arch/powerpc/kernel/exceptions-64e.S
6907@@ -715,6 +715,7 @@ storage_fault_common:
6908 std r14,_DAR(r1)
6909 std r15,_DSISR(r1)
6910 addi r3,r1,STACK_FRAME_OVERHEAD
6911+ bl .save_nvgprs
6912 mr r4,r14
6913 mr r5,r15
6914 ld r14,PACA_EXGEN+EX_R14(r13)
6915@@ -723,8 +724,7 @@ storage_fault_common:
6916 cmpdi r3,0
6917 bne- 1f
6918 b .ret_from_except_lite
6919-1: bl .save_nvgprs
6920- mr r5,r3
6921+1: mr r5,r3
6922 addi r3,r1,STACK_FRAME_OVERHEAD
6923 ld r4,_DAR(r1)
6924 bl .bad_page_fault
6925diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
6926index 3684cbd..bc89eab 100644
6927--- a/arch/powerpc/kernel/exceptions-64s.S
6928+++ b/arch/powerpc/kernel/exceptions-64s.S
6929@@ -1206,10 +1206,10 @@ handle_page_fault:
6930 11: ld r4,_DAR(r1)
6931 ld r5,_DSISR(r1)
6932 addi r3,r1,STACK_FRAME_OVERHEAD
6933+ bl .save_nvgprs
6934 bl .do_page_fault
6935 cmpdi r3,0
6936 beq+ 12f
6937- bl .save_nvgprs
6938 mr r5,r3
6939 addi r3,r1,STACK_FRAME_OVERHEAD
6940 lwz r4,_DAR(r1)
6941diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
6942index 2e3200c..72095ce 100644
6943--- a/arch/powerpc/kernel/module_32.c
6944+++ b/arch/powerpc/kernel/module_32.c
6945@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
6946 me->arch.core_plt_section = i;
6947 }
6948 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
6949- printk("Module doesn't contain .plt or .init.plt sections.\n");
6950+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
6951 return -ENOEXEC;
6952 }
6953
6954@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
6955
6956 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
6957 /* Init, or core PLT? */
6958- if (location >= mod->module_core
6959- && location < mod->module_core + mod->core_size)
6960+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
6961+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
6962 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
6963- else
6964+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
6965+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
6966 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
6967+ else {
6968+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
6969+ return ~0UL;
6970+ }
6971
6972 /* Find this entry, or if that fails, the next avail. entry */
6973 while (entry->jump[0]) {
6974diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
6975index 8143067..21ae55b 100644
6976--- a/arch/powerpc/kernel/process.c
6977+++ b/arch/powerpc/kernel/process.c
6978@@ -680,8 +680,8 @@ void show_regs(struct pt_regs * regs)
6979 * Lookup NIP late so we have the best change of getting the
6980 * above info out without failing
6981 */
6982- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
6983- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
6984+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
6985+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
6986 #endif
6987 show_stack(current, (unsigned long *) regs->gpr[1]);
6988 if (!user_mode(regs))
6989@@ -1129,10 +1129,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6990 newsp = stack[0];
6991 ip = stack[STACK_FRAME_LR_SAVE];
6992 if (!firstframe || ip != lr) {
6993- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
6994+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
6995 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6996 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
6997- printk(" (%pS)",
6998+ printk(" (%pA)",
6999 (void *)current->ret_stack[curr_frame].ret);
7000 curr_frame--;
7001 }
7002@@ -1152,7 +1152,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
7003 struct pt_regs *regs = (struct pt_regs *)
7004 (sp + STACK_FRAME_OVERHEAD);
7005 lr = regs->link;
7006- printk("--- Exception: %lx at %pS\n LR = %pS\n",
7007+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
7008 regs->trap, (void *)regs->nip, (void *)lr);
7009 firstframe = 1;
7010 }
7011@@ -1194,58 +1194,3 @@ void __ppc64_runlatch_off(void)
7012 mtspr(SPRN_CTRLT, ctrl);
7013 }
7014 #endif /* CONFIG_PPC64 */
7015-
7016-unsigned long arch_align_stack(unsigned long sp)
7017-{
7018- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7019- sp -= get_random_int() & ~PAGE_MASK;
7020- return sp & ~0xf;
7021-}
7022-
7023-static inline unsigned long brk_rnd(void)
7024-{
7025- unsigned long rnd = 0;
7026-
7027- /* 8MB for 32bit, 1GB for 64bit */
7028- if (is_32bit_task())
7029- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
7030- else
7031- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
7032-
7033- return rnd << PAGE_SHIFT;
7034-}
7035-
7036-unsigned long arch_randomize_brk(struct mm_struct *mm)
7037-{
7038- unsigned long base = mm->brk;
7039- unsigned long ret;
7040-
7041-#ifdef CONFIG_PPC_STD_MMU_64
7042- /*
7043- * If we are using 1TB segments and we are allowed to randomise
7044- * the heap, we can put it above 1TB so it is backed by a 1TB
7045- * segment. Otherwise the heap will be in the bottom 1TB
7046- * which always uses 256MB segments and this may result in a
7047- * performance penalty.
7048- */
7049- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
7050- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
7051-#endif
7052-
7053- ret = PAGE_ALIGN(base + brk_rnd());
7054-
7055- if (ret < mm->brk)
7056- return mm->brk;
7057-
7058- return ret;
7059-}
7060-
7061-unsigned long randomize_et_dyn(unsigned long base)
7062-{
7063- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
7064-
7065- if (ret < base)
7066- return base;
7067-
7068- return ret;
7069-}
7070diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
7071index c497000..8fde506 100644
7072--- a/arch/powerpc/kernel/ptrace.c
7073+++ b/arch/powerpc/kernel/ptrace.c
7074@@ -1737,6 +1737,10 @@ long arch_ptrace(struct task_struct *child, long request,
7075 return ret;
7076 }
7077
7078+#ifdef CONFIG_GRKERNSEC_SETXID
7079+extern void gr_delayed_cred_worker(void);
7080+#endif
7081+
7082 /*
7083 * We must return the syscall number to actually look up in the table.
7084 * This can be -1L to skip running any syscall at all.
7085@@ -1747,6 +1751,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
7086
7087 secure_computing_strict(regs->gpr[0]);
7088
7089+#ifdef CONFIG_GRKERNSEC_SETXID
7090+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
7091+ gr_delayed_cred_worker();
7092+#endif
7093+
7094 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
7095 tracehook_report_syscall_entry(regs))
7096 /*
7097@@ -1781,6 +1790,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
7098 {
7099 int step;
7100
7101+#ifdef CONFIG_GRKERNSEC_SETXID
7102+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
7103+ gr_delayed_cred_worker();
7104+#endif
7105+
7106 audit_syscall_exit(regs);
7107
7108 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
7109diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
7110index 804e323..79181c1 100644
7111--- a/arch/powerpc/kernel/signal_32.c
7112+++ b/arch/powerpc/kernel/signal_32.c
7113@@ -851,7 +851,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
7114 /* Save user registers on the stack */
7115 frame = &rt_sf->uc.uc_mcontext;
7116 addr = frame;
7117- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
7118+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
7119 if (save_user_regs(regs, frame, 0, 1))
7120 goto badframe;
7121 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
7122diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
7123index 1ca045d..139c3f7 100644
7124--- a/arch/powerpc/kernel/signal_64.c
7125+++ b/arch/powerpc/kernel/signal_64.c
7126@@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
7127 current->thread.fpscr.val = 0;
7128
7129 /* Set up to return from userspace. */
7130- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
7131+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
7132 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
7133 } else {
7134 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
7135diff --git a/arch/powerpc/kernel/sysfs.c b/arch/powerpc/kernel/sysfs.c
7136index 3ce1f86..c30e629 100644
7137--- a/arch/powerpc/kernel/sysfs.c
7138+++ b/arch/powerpc/kernel/sysfs.c
7139@@ -522,7 +522,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
7140 return NOTIFY_OK;
7141 }
7142
7143-static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
7144+static struct notifier_block sysfs_cpu_nb = {
7145 .notifier_call = sysfs_cpu_notify,
7146 };
7147
7148diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
7149index 3251840..3f7c77a 100644
7150--- a/arch/powerpc/kernel/traps.c
7151+++ b/arch/powerpc/kernel/traps.c
7152@@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
7153 return flags;
7154 }
7155
7156+extern void gr_handle_kernel_exploit(void);
7157+
7158 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
7159 int signr)
7160 {
7161@@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
7162 panic("Fatal exception in interrupt");
7163 if (panic_on_oops)
7164 panic("Fatal exception");
7165+
7166+ gr_handle_kernel_exploit();
7167+
7168 do_exit(signr);
7169 }
7170
7171diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
7172index 1b2076f..835e4be 100644
7173--- a/arch/powerpc/kernel/vdso.c
7174+++ b/arch/powerpc/kernel/vdso.c
7175@@ -34,6 +34,7 @@
7176 #include <asm/firmware.h>
7177 #include <asm/vdso.h>
7178 #include <asm/vdso_datapage.h>
7179+#include <asm/mman.h>
7180
7181 #include "setup.h"
7182
7183@@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
7184 vdso_base = VDSO32_MBASE;
7185 #endif
7186
7187- current->mm->context.vdso_base = 0;
7188+ current->mm->context.vdso_base = ~0UL;
7189
7190 /* vDSO has a problem and was disabled, just don't "enable" it for the
7191 * process
7192@@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
7193 vdso_base = get_unmapped_area(NULL, vdso_base,
7194 (vdso_pages << PAGE_SHIFT) +
7195 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
7196- 0, 0);
7197+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
7198 if (IS_ERR_VALUE(vdso_base)) {
7199 rc = vdso_base;
7200 goto fail_mmapsem;
7201diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
7202index 5eea6f3..5d10396 100644
7203--- a/arch/powerpc/lib/usercopy_64.c
7204+++ b/arch/powerpc/lib/usercopy_64.c
7205@@ -9,22 +9,6 @@
7206 #include <linux/module.h>
7207 #include <asm/uaccess.h>
7208
7209-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
7210-{
7211- if (likely(access_ok(VERIFY_READ, from, n)))
7212- n = __copy_from_user(to, from, n);
7213- else
7214- memset(to, 0, n);
7215- return n;
7216-}
7217-
7218-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
7219-{
7220- if (likely(access_ok(VERIFY_WRITE, to, n)))
7221- n = __copy_to_user(to, from, n);
7222- return n;
7223-}
7224-
7225 unsigned long copy_in_user(void __user *to, const void __user *from,
7226 unsigned long n)
7227 {
7228@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
7229 return n;
7230 }
7231
7232-EXPORT_SYMBOL(copy_from_user);
7233-EXPORT_SYMBOL(copy_to_user);
7234 EXPORT_SYMBOL(copy_in_user);
7235
7236diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
7237index 3a8489a..6a63b3b 100644
7238--- a/arch/powerpc/mm/fault.c
7239+++ b/arch/powerpc/mm/fault.c
7240@@ -32,6 +32,10 @@
7241 #include <linux/perf_event.h>
7242 #include <linux/magic.h>
7243 #include <linux/ratelimit.h>
7244+#include <linux/slab.h>
7245+#include <linux/pagemap.h>
7246+#include <linux/compiler.h>
7247+#include <linux/unistd.h>
7248
7249 #include <asm/firmware.h>
7250 #include <asm/page.h>
7251@@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
7252 }
7253 #endif
7254
7255+#ifdef CONFIG_PAX_PAGEEXEC
7256+/*
7257+ * PaX: decide what to do with offenders (regs->nip = fault address)
7258+ *
7259+ * returns 1 when task should be killed
7260+ */
7261+static int pax_handle_fetch_fault(struct pt_regs *regs)
7262+{
7263+ return 1;
7264+}
7265+
7266+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7267+{
7268+ unsigned long i;
7269+
7270+ printk(KERN_ERR "PAX: bytes at PC: ");
7271+ for (i = 0; i < 5; i++) {
7272+ unsigned int c;
7273+ if (get_user(c, (unsigned int __user *)pc+i))
7274+ printk(KERN_CONT "???????? ");
7275+ else
7276+ printk(KERN_CONT "%08x ", c);
7277+ }
7278+ printk("\n");
7279+}
7280+#endif
7281+
7282 /*
7283 * Check whether the instruction at regs->nip is a store using
7284 * an update addressing form which will update r1.
7285@@ -213,7 +244,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
7286 * indicate errors in DSISR but can validly be set in SRR1.
7287 */
7288 if (trap == 0x400)
7289- error_code &= 0x48200000;
7290+ error_code &= 0x58200000;
7291 else
7292 is_write = error_code & DSISR_ISSTORE;
7293 #else
7294@@ -364,7 +395,7 @@ good_area:
7295 * "undefined". Of those that can be set, this is the only
7296 * one which seems bad.
7297 */
7298- if (error_code & 0x10000000)
7299+ if (error_code & DSISR_GUARDED)
7300 /* Guarded storage error. */
7301 goto bad_area;
7302 #endif /* CONFIG_8xx */
7303@@ -379,7 +410,7 @@ good_area:
7304 * processors use the same I/D cache coherency mechanism
7305 * as embedded.
7306 */
7307- if (error_code & DSISR_PROTFAULT)
7308+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
7309 goto bad_area;
7310 #endif /* CONFIG_PPC_STD_MMU */
7311
7312@@ -462,6 +493,23 @@ bad_area:
7313 bad_area_nosemaphore:
7314 /* User mode accesses cause a SIGSEGV */
7315 if (user_mode(regs)) {
7316+
7317+#ifdef CONFIG_PAX_PAGEEXEC
7318+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
7319+#ifdef CONFIG_PPC_STD_MMU
7320+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
7321+#else
7322+ if (is_exec && regs->nip == address) {
7323+#endif
7324+ switch (pax_handle_fetch_fault(regs)) {
7325+ }
7326+
7327+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
7328+ do_group_exit(SIGKILL);
7329+ }
7330+ }
7331+#endif
7332+
7333 _exception(SIGSEGV, regs, code, address);
7334 return 0;
7335 }
7336diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
7337index 67a42ed..cd463e0 100644
7338--- a/arch/powerpc/mm/mmap_64.c
7339+++ b/arch/powerpc/mm/mmap_64.c
7340@@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
7341 {
7342 unsigned long rnd = 0;
7343
7344+#ifdef CONFIG_PAX_RANDMMAP
7345+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7346+#endif
7347+
7348 if (current->flags & PF_RANDOMIZE) {
7349 /* 8MB for 32bit, 1GB for 64bit */
7350 if (is_32bit_task())
7351@@ -91,10 +95,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7352 */
7353 if (mmap_is_legacy()) {
7354 mm->mmap_base = TASK_UNMAPPED_BASE;
7355+
7356+#ifdef CONFIG_PAX_RANDMMAP
7357+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7358+ mm->mmap_base += mm->delta_mmap;
7359+#endif
7360+
7361 mm->get_unmapped_area = arch_get_unmapped_area;
7362 mm->unmap_area = arch_unmap_area;
7363 } else {
7364 mm->mmap_base = mmap_base();
7365+
7366+#ifdef CONFIG_PAX_RANDMMAP
7367+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7368+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7369+#endif
7370+
7371 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7372 mm->unmap_area = arch_unmap_area_topdown;
7373 }
7374diff --git a/arch/powerpc/mm/mmu_context_nohash.c b/arch/powerpc/mm/mmu_context_nohash.c
7375index e779642..e5bb889 100644
7376--- a/arch/powerpc/mm/mmu_context_nohash.c
7377+++ b/arch/powerpc/mm/mmu_context_nohash.c
7378@@ -363,7 +363,7 @@ static int __cpuinit mmu_context_cpu_notify(struct notifier_block *self,
7379 return NOTIFY_OK;
7380 }
7381
7382-static struct notifier_block __cpuinitdata mmu_context_cpu_nb = {
7383+static struct notifier_block mmu_context_cpu_nb = {
7384 .notifier_call = mmu_context_cpu_notify,
7385 };
7386
7387diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
7388index bba87ca..c346a33 100644
7389--- a/arch/powerpc/mm/numa.c
7390+++ b/arch/powerpc/mm/numa.c
7391@@ -932,7 +932,7 @@ static void __init *careful_zallocation(int nid, unsigned long size,
7392 return ret;
7393 }
7394
7395-static struct notifier_block __cpuinitdata ppc64_numa_nb = {
7396+static struct notifier_block ppc64_numa_nb = {
7397 .notifier_call = cpu_numa_callback,
7398 .priority = 1 /* Must run before sched domains notifier. */
7399 };
7400diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
7401index cf9dada..241529f 100644
7402--- a/arch/powerpc/mm/slice.c
7403+++ b/arch/powerpc/mm/slice.c
7404@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
7405 if ((mm->task_size - len) < addr)
7406 return 0;
7407 vma = find_vma(mm, addr);
7408- return (!vma || (addr + len) <= vma->vm_start);
7409+ return check_heap_stack_gap(vma, addr, len, 0);
7410 }
7411
7412 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
7413@@ -272,7 +272,7 @@ full_search:
7414 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
7415 continue;
7416 }
7417- if (!vma || addr + len <= vma->vm_start) {
7418+ if (check_heap_stack_gap(vma, addr, len, 0)) {
7419 /*
7420 * Remember the place where we stopped the search:
7421 */
7422@@ -329,10 +329,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
7423 }
7424 }
7425
7426- addr = mm->mmap_base;
7427- while (addr > len) {
7428+ if (mm->mmap_base < len)
7429+ addr = -ENOMEM;
7430+ else
7431+ addr = mm->mmap_base - len;
7432+
7433+ while (!IS_ERR_VALUE(addr)) {
7434 /* Go down by chunk size */
7435- addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
7436+ addr = _ALIGN_DOWN(addr, 1ul << pshift);
7437
7438 /* Check for hit with different page size */
7439 mask = slice_range_to_mask(addr, len);
7440@@ -352,7 +356,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
7441 * return with success:
7442 */
7443 vma = find_vma(mm, addr);
7444- if (!vma || (addr + len) <= vma->vm_start) {
7445+ if (check_heap_stack_gap(vma, addr, len, 0)) {
7446 /* remember the address as a hint for next time */
7447 if (use_cache)
7448 mm->free_area_cache = addr;
7449@@ -364,7 +368,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
7450 mm->cached_hole_size = vma->vm_start - addr;
7451
7452 /* try just below the current vma->vm_start */
7453- addr = vma->vm_start;
7454+ addr = skip_heap_stack_gap(vma, len, 0);
7455 }
7456
7457 /*
7458@@ -442,6 +446,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
7459 if (fixed && addr > (mm->task_size - len))
7460 return -EINVAL;
7461
7462+#ifdef CONFIG_PAX_RANDMMAP
7463+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
7464+ addr = 0;
7465+#endif
7466+
7467 /* If hint, make sure it matches our alignment restrictions */
7468 if (!fixed && addr) {
7469 addr = _ALIGN_UP(addr, 1ul << pshift);
7470diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
7471index 0cfece4..2f1a0e5 100644
7472--- a/arch/powerpc/platforms/cell/spufs/file.c
7473+++ b/arch/powerpc/platforms/cell/spufs/file.c
7474@@ -281,9 +281,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
7475 return VM_FAULT_NOPAGE;
7476 }
7477
7478-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
7479+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
7480 unsigned long address,
7481- void *buf, int len, int write)
7482+ void *buf, size_t len, int write)
7483 {
7484 struct spu_context *ctx = vma->vm_file->private_data;
7485 unsigned long offset = address - vma->vm_start;
7486diff --git a/arch/powerpc/platforms/powermac/smp.c b/arch/powerpc/platforms/powermac/smp.c
7487index bdb738a..49c9f95 100644
7488--- a/arch/powerpc/platforms/powermac/smp.c
7489+++ b/arch/powerpc/platforms/powermac/smp.c
7490@@ -885,7 +885,7 @@ static int smp_core99_cpu_notify(struct notifier_block *self,
7491 return NOTIFY_OK;
7492 }
7493
7494-static struct notifier_block __cpuinitdata smp_core99_cpu_nb = {
7495+static struct notifier_block smp_core99_cpu_nb = {
7496 .notifier_call = smp_core99_cpu_notify,
7497 };
7498 #endif /* CONFIG_HOTPLUG_CPU */
7499diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
7500index c797832..ce575c8 100644
7501--- a/arch/s390/include/asm/atomic.h
7502+++ b/arch/s390/include/asm/atomic.h
7503@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
7504 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
7505 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7506
7507+#define atomic64_read_unchecked(v) atomic64_read(v)
7508+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7509+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7510+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7511+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7512+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7513+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7514+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7515+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7516+
7517 #define smp_mb__before_atomic_dec() smp_mb()
7518 #define smp_mb__after_atomic_dec() smp_mb()
7519 #define smp_mb__before_atomic_inc() smp_mb()
7520diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
7521index 4d7ccac..d03d0ad 100644
7522--- a/arch/s390/include/asm/cache.h
7523+++ b/arch/s390/include/asm/cache.h
7524@@ -9,8 +9,10 @@
7525 #ifndef __ARCH_S390_CACHE_H
7526 #define __ARCH_S390_CACHE_H
7527
7528-#define L1_CACHE_BYTES 256
7529+#include <linux/const.h>
7530+
7531 #define L1_CACHE_SHIFT 8
7532+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7533 #define NET_SKB_PAD 32
7534
7535 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7536diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
7537index 178ff96..8c93bd1 100644
7538--- a/arch/s390/include/asm/elf.h
7539+++ b/arch/s390/include/asm/elf.h
7540@@ -160,8 +160,14 @@ extern unsigned int vdso_enabled;
7541 the loader. We need to make sure that it is out of the way of the program
7542 that it will "exec", and that there is sufficient room for the brk. */
7543
7544-extern unsigned long randomize_et_dyn(unsigned long base);
7545-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
7546+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
7547+
7548+#ifdef CONFIG_PAX_ASLR
7549+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
7550+
7551+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
7552+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
7553+#endif
7554
7555 /* This yields a mask that user programs can use to figure out what
7556 instruction set this CPU supports. */
7557@@ -210,9 +216,6 @@ struct linux_binprm;
7558 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
7559 int arch_setup_additional_pages(struct linux_binprm *, int);
7560
7561-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7562-#define arch_randomize_brk arch_randomize_brk
7563-
7564 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
7565
7566 #endif
7567diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
7568index c4a93d6..4d2a9b4 100644
7569--- a/arch/s390/include/asm/exec.h
7570+++ b/arch/s390/include/asm/exec.h
7571@@ -7,6 +7,6 @@
7572 #ifndef __ASM_EXEC_H
7573 #define __ASM_EXEC_H
7574
7575-extern unsigned long arch_align_stack(unsigned long sp);
7576+#define arch_align_stack(x) ((x) & ~0xfUL)
7577
7578 #endif /* __ASM_EXEC_H */
7579diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
7580index 34268df..ea97318 100644
7581--- a/arch/s390/include/asm/uaccess.h
7582+++ b/arch/s390/include/asm/uaccess.h
7583@@ -252,6 +252,10 @@ static inline unsigned long __must_check
7584 copy_to_user(void __user *to, const void *from, unsigned long n)
7585 {
7586 might_fault();
7587+
7588+ if ((long)n < 0)
7589+ return n;
7590+
7591 if (access_ok(VERIFY_WRITE, to, n))
7592 n = __copy_to_user(to, from, n);
7593 return n;
7594@@ -277,6 +281,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
7595 static inline unsigned long __must_check
7596 __copy_from_user(void *to, const void __user *from, unsigned long n)
7597 {
7598+ if ((long)n < 0)
7599+ return n;
7600+
7601 if (__builtin_constant_p(n) && (n <= 256))
7602 return uaccess.copy_from_user_small(n, from, to);
7603 else
7604@@ -308,10 +315,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
7605 static inline unsigned long __must_check
7606 copy_from_user(void *to, const void __user *from, unsigned long n)
7607 {
7608- unsigned int sz = __compiletime_object_size(to);
7609+ size_t sz = __compiletime_object_size(to);
7610
7611 might_fault();
7612- if (unlikely(sz != -1 && sz < n)) {
7613+
7614+ if ((long)n < 0)
7615+ return n;
7616+
7617+ if (unlikely(sz != (size_t)-1 && sz < n)) {
7618 copy_from_user_overflow();
7619 return n;
7620 }
7621diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
7622index 4610dea..cf0af21 100644
7623--- a/arch/s390/kernel/module.c
7624+++ b/arch/s390/kernel/module.c
7625@@ -171,11 +171,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
7626
7627 /* Increase core size by size of got & plt and set start
7628 offsets for got and plt. */
7629- me->core_size = ALIGN(me->core_size, 4);
7630- me->arch.got_offset = me->core_size;
7631- me->core_size += me->arch.got_size;
7632- me->arch.plt_offset = me->core_size;
7633- me->core_size += me->arch.plt_size;
7634+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
7635+ me->arch.got_offset = me->core_size_rw;
7636+ me->core_size_rw += me->arch.got_size;
7637+ me->arch.plt_offset = me->core_size_rx;
7638+ me->core_size_rx += me->arch.plt_size;
7639 return 0;
7640 }
7641
7642@@ -252,7 +252,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7643 if (info->got_initialized == 0) {
7644 Elf_Addr *gotent;
7645
7646- gotent = me->module_core + me->arch.got_offset +
7647+ gotent = me->module_core_rw + me->arch.got_offset +
7648 info->got_offset;
7649 *gotent = val;
7650 info->got_initialized = 1;
7651@@ -276,7 +276,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7652 else if (r_type == R_390_GOTENT ||
7653 r_type == R_390_GOTPLTENT)
7654 *(unsigned int *) loc =
7655- (val + (Elf_Addr) me->module_core - loc) >> 1;
7656+ (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
7657 else if (r_type == R_390_GOT64 ||
7658 r_type == R_390_GOTPLT64)
7659 *(unsigned long *) loc = val;
7660@@ -290,7 +290,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7661 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
7662 if (info->plt_initialized == 0) {
7663 unsigned int *ip;
7664- ip = me->module_core + me->arch.plt_offset +
7665+ ip = me->module_core_rx + me->arch.plt_offset +
7666 info->plt_offset;
7667 #ifndef CONFIG_64BIT
7668 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
7669@@ -315,7 +315,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7670 val - loc + 0xffffUL < 0x1ffffeUL) ||
7671 (r_type == R_390_PLT32DBL &&
7672 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
7673- val = (Elf_Addr) me->module_core +
7674+ val = (Elf_Addr) me->module_core_rx +
7675 me->arch.plt_offset +
7676 info->plt_offset;
7677 val += rela->r_addend - loc;
7678@@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7679 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
7680 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
7681 val = val + rela->r_addend -
7682- ((Elf_Addr) me->module_core + me->arch.got_offset);
7683+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
7684 if (r_type == R_390_GOTOFF16)
7685 *(unsigned short *) loc = val;
7686 else if (r_type == R_390_GOTOFF32)
7687@@ -347,7 +347,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7688 break;
7689 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
7690 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
7691- val = (Elf_Addr) me->module_core + me->arch.got_offset +
7692+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
7693 rela->r_addend - loc;
7694 if (r_type == R_390_GOTPC)
7695 *(unsigned int *) loc = val;
7696diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
7697index 536d645..4a5bd9e 100644
7698--- a/arch/s390/kernel/process.c
7699+++ b/arch/s390/kernel/process.c
7700@@ -250,39 +250,3 @@ unsigned long get_wchan(struct task_struct *p)
7701 }
7702 return 0;
7703 }
7704-
7705-unsigned long arch_align_stack(unsigned long sp)
7706-{
7707- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7708- sp -= get_random_int() & ~PAGE_MASK;
7709- return sp & ~0xf;
7710-}
7711-
7712-static inline unsigned long brk_rnd(void)
7713-{
7714- /* 8MB for 32bit, 1GB for 64bit */
7715- if (is_32bit_task())
7716- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
7717- else
7718- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
7719-}
7720-
7721-unsigned long arch_randomize_brk(struct mm_struct *mm)
7722-{
7723- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
7724-
7725- if (ret < mm->brk)
7726- return mm->brk;
7727- return ret;
7728-}
7729-
7730-unsigned long randomize_et_dyn(unsigned long base)
7731-{
7732- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
7733-
7734- if (!(current->flags & PF_RANDOMIZE))
7735- return base;
7736- if (ret < base)
7737- return base;
7738- return ret;
7739-}
7740diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
7741index c59a5ef..3fae59c 100644
7742--- a/arch/s390/mm/mmap.c
7743+++ b/arch/s390/mm/mmap.c
7744@@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7745 */
7746 if (mmap_is_legacy()) {
7747 mm->mmap_base = TASK_UNMAPPED_BASE;
7748+
7749+#ifdef CONFIG_PAX_RANDMMAP
7750+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7751+ mm->mmap_base += mm->delta_mmap;
7752+#endif
7753+
7754 mm->get_unmapped_area = arch_get_unmapped_area;
7755 mm->unmap_area = arch_unmap_area;
7756 } else {
7757 mm->mmap_base = mmap_base();
7758+
7759+#ifdef CONFIG_PAX_RANDMMAP
7760+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7761+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7762+#endif
7763+
7764 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7765 mm->unmap_area = arch_unmap_area_topdown;
7766 }
7767@@ -172,10 +184,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7768 */
7769 if (mmap_is_legacy()) {
7770 mm->mmap_base = TASK_UNMAPPED_BASE;
7771+
7772+#ifdef CONFIG_PAX_RANDMMAP
7773+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7774+ mm->mmap_base += mm->delta_mmap;
7775+#endif
7776+
7777 mm->get_unmapped_area = s390_get_unmapped_area;
7778 mm->unmap_area = arch_unmap_area;
7779 } else {
7780 mm->mmap_base = mmap_base();
7781+
7782+#ifdef CONFIG_PAX_RANDMMAP
7783+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7784+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7785+#endif
7786+
7787 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
7788 mm->unmap_area = arch_unmap_area_topdown;
7789 }
7790diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
7791index ae3d59f..f65f075 100644
7792--- a/arch/score/include/asm/cache.h
7793+++ b/arch/score/include/asm/cache.h
7794@@ -1,7 +1,9 @@
7795 #ifndef _ASM_SCORE_CACHE_H
7796 #define _ASM_SCORE_CACHE_H
7797
7798+#include <linux/const.h>
7799+
7800 #define L1_CACHE_SHIFT 4
7801-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7802+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7803
7804 #endif /* _ASM_SCORE_CACHE_H */
7805diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
7806index f9f3cd5..58ff438 100644
7807--- a/arch/score/include/asm/exec.h
7808+++ b/arch/score/include/asm/exec.h
7809@@ -1,6 +1,6 @@
7810 #ifndef _ASM_SCORE_EXEC_H
7811 #define _ASM_SCORE_EXEC_H
7812
7813-extern unsigned long arch_align_stack(unsigned long sp);
7814+#define arch_align_stack(x) (x)
7815
7816 #endif /* _ASM_SCORE_EXEC_H */
7817diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
7818index 7956846..5f37677 100644
7819--- a/arch/score/kernel/process.c
7820+++ b/arch/score/kernel/process.c
7821@@ -134,8 +134,3 @@ unsigned long get_wchan(struct task_struct *task)
7822
7823 return task_pt_regs(task)->cp0_epc;
7824 }
7825-
7826-unsigned long arch_align_stack(unsigned long sp)
7827-{
7828- return sp;
7829-}
7830diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
7831index ef9e555..331bd29 100644
7832--- a/arch/sh/include/asm/cache.h
7833+++ b/arch/sh/include/asm/cache.h
7834@@ -9,10 +9,11 @@
7835 #define __ASM_SH_CACHE_H
7836 #ifdef __KERNEL__
7837
7838+#include <linux/const.h>
7839 #include <linux/init.h>
7840 #include <cpu/cache.h>
7841
7842-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7843+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7844
7845 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7846
7847diff --git a/arch/sh/kernel/cpu/sh4a/smp-shx3.c b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7848index 03f2b55..b027032 100644
7849--- a/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7850+++ b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7851@@ -143,7 +143,7 @@ shx3_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
7852 return NOTIFY_OK;
7853 }
7854
7855-static struct notifier_block __cpuinitdata shx3_cpu_notifier = {
7856+static struct notifier_block shx3_cpu_notifier = {
7857 .notifier_call = shx3_cpu_callback,
7858 };
7859
7860diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
7861index 6777177..cb5e44f 100644
7862--- a/arch/sh/mm/mmap.c
7863+++ b/arch/sh/mm/mmap.c
7864@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7865 struct mm_struct *mm = current->mm;
7866 struct vm_area_struct *vma;
7867 int do_colour_align;
7868+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7869 struct vm_unmapped_area_info info;
7870
7871 if (flags & MAP_FIXED) {
7872@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7873 if (filp || (flags & MAP_SHARED))
7874 do_colour_align = 1;
7875
7876+#ifdef CONFIG_PAX_RANDMMAP
7877+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7878+#endif
7879+
7880 if (addr) {
7881 if (do_colour_align)
7882 addr = COLOUR_ALIGN(addr, pgoff);
7883@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7884 addr = PAGE_ALIGN(addr);
7885
7886 vma = find_vma(mm, addr);
7887- if (TASK_SIZE - len >= addr &&
7888- (!vma || addr + len <= vma->vm_start))
7889+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7890 return addr;
7891 }
7892
7893 info.flags = 0;
7894 info.length = len;
7895- info.low_limit = TASK_UNMAPPED_BASE;
7896+ info.low_limit = mm->mmap_base;
7897 info.high_limit = TASK_SIZE;
7898 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
7899 info.align_offset = pgoff << PAGE_SHIFT;
7900@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7901 struct mm_struct *mm = current->mm;
7902 unsigned long addr = addr0;
7903 int do_colour_align;
7904+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7905 struct vm_unmapped_area_info info;
7906
7907 if (flags & MAP_FIXED) {
7908@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7909 if (filp || (flags & MAP_SHARED))
7910 do_colour_align = 1;
7911
7912+#ifdef CONFIG_PAX_RANDMMAP
7913+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7914+#endif
7915+
7916 /* requesting a specific address */
7917 if (addr) {
7918 if (do_colour_align)
7919@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7920 addr = PAGE_ALIGN(addr);
7921
7922 vma = find_vma(mm, addr);
7923- if (TASK_SIZE - len >= addr &&
7924- (!vma || addr + len <= vma->vm_start))
7925+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7926 return addr;
7927 }
7928
7929@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7930 VM_BUG_ON(addr != -ENOMEM);
7931 info.flags = 0;
7932 info.low_limit = TASK_UNMAPPED_BASE;
7933+
7934+#ifdef CONFIG_PAX_RANDMMAP
7935+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7936+ info.low_limit += mm->delta_mmap;
7937+#endif
7938+
7939 info.high_limit = TASK_SIZE;
7940 addr = vm_unmapped_area(&info);
7941 }
7942diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
7943index be56a24..443328f 100644
7944--- a/arch/sparc/include/asm/atomic_64.h
7945+++ b/arch/sparc/include/asm/atomic_64.h
7946@@ -14,18 +14,40 @@
7947 #define ATOMIC64_INIT(i) { (i) }
7948
7949 #define atomic_read(v) (*(volatile int *)&(v)->counter)
7950+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
7951+{
7952+ return v->counter;
7953+}
7954 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
7955+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
7956+{
7957+ return v->counter;
7958+}
7959
7960 #define atomic_set(v, i) (((v)->counter) = i)
7961+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
7962+{
7963+ v->counter = i;
7964+}
7965 #define atomic64_set(v, i) (((v)->counter) = i)
7966+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
7967+{
7968+ v->counter = i;
7969+}
7970
7971 extern void atomic_add(int, atomic_t *);
7972+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
7973 extern void atomic64_add(long, atomic64_t *);
7974+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
7975 extern void atomic_sub(int, atomic_t *);
7976+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
7977 extern void atomic64_sub(long, atomic64_t *);
7978+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
7979
7980 extern int atomic_add_ret(int, atomic_t *);
7981+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
7982 extern long atomic64_add_ret(long, atomic64_t *);
7983+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
7984 extern int atomic_sub_ret(int, atomic_t *);
7985 extern long atomic64_sub_ret(long, atomic64_t *);
7986
7987@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7988 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
7989
7990 #define atomic_inc_return(v) atomic_add_ret(1, v)
7991+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
7992+{
7993+ return atomic_add_ret_unchecked(1, v);
7994+}
7995 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
7996+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
7997+{
7998+ return atomic64_add_ret_unchecked(1, v);
7999+}
8000
8001 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
8002 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
8003
8004 #define atomic_add_return(i, v) atomic_add_ret(i, v)
8005+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
8006+{
8007+ return atomic_add_ret_unchecked(i, v);
8008+}
8009 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
8010+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
8011+{
8012+ return atomic64_add_ret_unchecked(i, v);
8013+}
8014
8015 /*
8016 * atomic_inc_and_test - increment and test
8017@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8018 * other cases.
8019 */
8020 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
8021+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
8022+{
8023+ return atomic_inc_return_unchecked(v) == 0;
8024+}
8025 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
8026
8027 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
8028@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8029 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
8030
8031 #define atomic_inc(v) atomic_add(1, v)
8032+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
8033+{
8034+ atomic_add_unchecked(1, v);
8035+}
8036 #define atomic64_inc(v) atomic64_add(1, v)
8037+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
8038+{
8039+ atomic64_add_unchecked(1, v);
8040+}
8041
8042 #define atomic_dec(v) atomic_sub(1, v)
8043+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
8044+{
8045+ atomic_sub_unchecked(1, v);
8046+}
8047 #define atomic64_dec(v) atomic64_sub(1, v)
8048+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
8049+{
8050+ atomic64_sub_unchecked(1, v);
8051+}
8052
8053 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
8054 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
8055
8056 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
8057+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
8058+{
8059+ return cmpxchg(&v->counter, old, new);
8060+}
8061 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
8062+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
8063+{
8064+ return xchg(&v->counter, new);
8065+}
8066
8067 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
8068 {
8069- int c, old;
8070+ int c, old, new;
8071 c = atomic_read(v);
8072 for (;;) {
8073- if (unlikely(c == (u)))
8074+ if (unlikely(c == u))
8075 break;
8076- old = atomic_cmpxchg((v), c, c + (a));
8077+
8078+ asm volatile("addcc %2, %0, %0\n"
8079+
8080+#ifdef CONFIG_PAX_REFCOUNT
8081+ "tvs %%icc, 6\n"
8082+#endif
8083+
8084+ : "=r" (new)
8085+ : "0" (c), "ir" (a)
8086+ : "cc");
8087+
8088+ old = atomic_cmpxchg(v, c, new);
8089 if (likely(old == c))
8090 break;
8091 c = old;
8092@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
8093 #define atomic64_cmpxchg(v, o, n) \
8094 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
8095 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
8096+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
8097+{
8098+ return xchg(&v->counter, new);
8099+}
8100
8101 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
8102 {
8103- long c, old;
8104+ long c, old, new;
8105 c = atomic64_read(v);
8106 for (;;) {
8107- if (unlikely(c == (u)))
8108+ if (unlikely(c == u))
8109 break;
8110- old = atomic64_cmpxchg((v), c, c + (a));
8111+
8112+ asm volatile("addcc %2, %0, %0\n"
8113+
8114+#ifdef CONFIG_PAX_REFCOUNT
8115+ "tvs %%xcc, 6\n"
8116+#endif
8117+
8118+ : "=r" (new)
8119+ : "0" (c), "ir" (a)
8120+ : "cc");
8121+
8122+ old = atomic64_cmpxchg(v, c, new);
8123 if (likely(old == c))
8124 break;
8125 c = old;
8126 }
8127- return c != (u);
8128+ return c != u;
8129 }
8130
8131 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8132diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
8133index 5bb6991..5c2132e 100644
8134--- a/arch/sparc/include/asm/cache.h
8135+++ b/arch/sparc/include/asm/cache.h
8136@@ -7,10 +7,12 @@
8137 #ifndef _SPARC_CACHE_H
8138 #define _SPARC_CACHE_H
8139
8140+#include <linux/const.h>
8141+
8142 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
8143
8144 #define L1_CACHE_SHIFT 5
8145-#define L1_CACHE_BYTES 32
8146+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8147
8148 #ifdef CONFIG_SPARC32
8149 #define SMP_CACHE_BYTES_SHIFT 5
8150diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
8151index ac74a2c..a9e58af 100644
8152--- a/arch/sparc/include/asm/elf_32.h
8153+++ b/arch/sparc/include/asm/elf_32.h
8154@@ -114,6 +114,13 @@ typedef struct {
8155
8156 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
8157
8158+#ifdef CONFIG_PAX_ASLR
8159+#define PAX_ELF_ET_DYN_BASE 0x10000UL
8160+
8161+#define PAX_DELTA_MMAP_LEN 16
8162+#define PAX_DELTA_STACK_LEN 16
8163+#endif
8164+
8165 /* This yields a mask that user programs can use to figure out what
8166 instruction set this cpu supports. This can NOT be done in userspace
8167 on Sparc. */
8168diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
8169index 370ca1e..d4f4a98 100644
8170--- a/arch/sparc/include/asm/elf_64.h
8171+++ b/arch/sparc/include/asm/elf_64.h
8172@@ -189,6 +189,13 @@ typedef struct {
8173 #define ELF_ET_DYN_BASE 0x0000010000000000UL
8174 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
8175
8176+#ifdef CONFIG_PAX_ASLR
8177+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
8178+
8179+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
8180+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
8181+#endif
8182+
8183 extern unsigned long sparc64_elf_hwcap;
8184 #define ELF_HWCAP sparc64_elf_hwcap
8185
8186diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
8187index 9b1c36d..209298b 100644
8188--- a/arch/sparc/include/asm/pgalloc_32.h
8189+++ b/arch/sparc/include/asm/pgalloc_32.h
8190@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
8191 }
8192
8193 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
8194+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
8195
8196 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
8197 unsigned long address)
8198diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
8199index bcfe063..b333142 100644
8200--- a/arch/sparc/include/asm/pgalloc_64.h
8201+++ b/arch/sparc/include/asm/pgalloc_64.h
8202@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
8203 }
8204
8205 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
8206+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
8207
8208 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
8209 {
8210diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
8211index 6fc1348..390c50a 100644
8212--- a/arch/sparc/include/asm/pgtable_32.h
8213+++ b/arch/sparc/include/asm/pgtable_32.h
8214@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
8215 #define PAGE_SHARED SRMMU_PAGE_SHARED
8216 #define PAGE_COPY SRMMU_PAGE_COPY
8217 #define PAGE_READONLY SRMMU_PAGE_RDONLY
8218+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
8219+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
8220+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
8221 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
8222
8223 /* Top-level page directory - dummy used by init-mm.
8224@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
8225
8226 /* xwr */
8227 #define __P000 PAGE_NONE
8228-#define __P001 PAGE_READONLY
8229-#define __P010 PAGE_COPY
8230-#define __P011 PAGE_COPY
8231+#define __P001 PAGE_READONLY_NOEXEC
8232+#define __P010 PAGE_COPY_NOEXEC
8233+#define __P011 PAGE_COPY_NOEXEC
8234 #define __P100 PAGE_READONLY
8235 #define __P101 PAGE_READONLY
8236 #define __P110 PAGE_COPY
8237 #define __P111 PAGE_COPY
8238
8239 #define __S000 PAGE_NONE
8240-#define __S001 PAGE_READONLY
8241-#define __S010 PAGE_SHARED
8242-#define __S011 PAGE_SHARED
8243+#define __S001 PAGE_READONLY_NOEXEC
8244+#define __S010 PAGE_SHARED_NOEXEC
8245+#define __S011 PAGE_SHARED_NOEXEC
8246 #define __S100 PAGE_READONLY
8247 #define __S101 PAGE_READONLY
8248 #define __S110 PAGE_SHARED
8249diff --git a/arch/sparc/include/asm/pgtable_64.h b/arch/sparc/include/asm/pgtable_64.h
8250index 08fcce9..7619f2f 100644
8251--- a/arch/sparc/include/asm/pgtable_64.h
8252+++ b/arch/sparc/include/asm/pgtable_64.h
8253@@ -915,6 +915,7 @@ static inline int io_remap_pfn_range(struct vm_area_struct *vma,
8254 return remap_pfn_range(vma, from, phys_base >> PAGE_SHIFT, size, prot);
8255 }
8256
8257+#include <asm/tlbflush.h>
8258 #include <asm-generic/pgtable.h>
8259
8260 /* We provide our own get_unmapped_area to cope with VA holes and
8261diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
8262index 79da178..c2eede8 100644
8263--- a/arch/sparc/include/asm/pgtsrmmu.h
8264+++ b/arch/sparc/include/asm/pgtsrmmu.h
8265@@ -115,6 +115,11 @@
8266 SRMMU_EXEC | SRMMU_REF)
8267 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
8268 SRMMU_EXEC | SRMMU_REF)
8269+
8270+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
8271+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
8272+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
8273+
8274 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
8275 SRMMU_DIRTY | SRMMU_REF)
8276
8277diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
8278index 9689176..63c18ea 100644
8279--- a/arch/sparc/include/asm/spinlock_64.h
8280+++ b/arch/sparc/include/asm/spinlock_64.h
8281@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
8282
8283 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
8284
8285-static void inline arch_read_lock(arch_rwlock_t *lock)
8286+static inline void arch_read_lock(arch_rwlock_t *lock)
8287 {
8288 unsigned long tmp1, tmp2;
8289
8290 __asm__ __volatile__ (
8291 "1: ldsw [%2], %0\n"
8292 " brlz,pn %0, 2f\n"
8293-"4: add %0, 1, %1\n"
8294+"4: addcc %0, 1, %1\n"
8295+
8296+#ifdef CONFIG_PAX_REFCOUNT
8297+" tvs %%icc, 6\n"
8298+#endif
8299+
8300 " cas [%2], %0, %1\n"
8301 " cmp %0, %1\n"
8302 " bne,pn %%icc, 1b\n"
8303@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
8304 " .previous"
8305 : "=&r" (tmp1), "=&r" (tmp2)
8306 : "r" (lock)
8307- : "memory");
8308+ : "memory", "cc");
8309 }
8310
8311-static int inline arch_read_trylock(arch_rwlock_t *lock)
8312+static inline int arch_read_trylock(arch_rwlock_t *lock)
8313 {
8314 int tmp1, tmp2;
8315
8316@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
8317 "1: ldsw [%2], %0\n"
8318 " brlz,a,pn %0, 2f\n"
8319 " mov 0, %0\n"
8320-" add %0, 1, %1\n"
8321+" addcc %0, 1, %1\n"
8322+
8323+#ifdef CONFIG_PAX_REFCOUNT
8324+" tvs %%icc, 6\n"
8325+#endif
8326+
8327 " cas [%2], %0, %1\n"
8328 " cmp %0, %1\n"
8329 " bne,pn %%icc, 1b\n"
8330@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
8331 return tmp1;
8332 }
8333
8334-static void inline arch_read_unlock(arch_rwlock_t *lock)
8335+static inline void arch_read_unlock(arch_rwlock_t *lock)
8336 {
8337 unsigned long tmp1, tmp2;
8338
8339 __asm__ __volatile__(
8340 "1: lduw [%2], %0\n"
8341-" sub %0, 1, %1\n"
8342+" subcc %0, 1, %1\n"
8343+
8344+#ifdef CONFIG_PAX_REFCOUNT
8345+" tvs %%icc, 6\n"
8346+#endif
8347+
8348 " cas [%2], %0, %1\n"
8349 " cmp %0, %1\n"
8350 " bne,pn %%xcc, 1b\n"
8351@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
8352 : "memory");
8353 }
8354
8355-static void inline arch_write_lock(arch_rwlock_t *lock)
8356+static inline void arch_write_lock(arch_rwlock_t *lock)
8357 {
8358 unsigned long mask, tmp1, tmp2;
8359
8360@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
8361 : "memory");
8362 }
8363
8364-static void inline arch_write_unlock(arch_rwlock_t *lock)
8365+static inline void arch_write_unlock(arch_rwlock_t *lock)
8366 {
8367 __asm__ __volatile__(
8368 " stw %%g0, [%0]"
8369@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
8370 : "memory");
8371 }
8372
8373-static int inline arch_write_trylock(arch_rwlock_t *lock)
8374+static inline int arch_write_trylock(arch_rwlock_t *lock)
8375 {
8376 unsigned long mask, tmp1, tmp2, result;
8377
8378diff --git a/arch/sparc/include/asm/switch_to_64.h b/arch/sparc/include/asm/switch_to_64.h
8379index cad36f5..c7de332 100644
8380--- a/arch/sparc/include/asm/switch_to_64.h
8381+++ b/arch/sparc/include/asm/switch_to_64.h
8382@@ -18,8 +18,7 @@ do { \
8383 * and 2 stores in this critical code path. -DaveM
8384 */
8385 #define switch_to(prev, next, last) \
8386-do { flush_tlb_pending(); \
8387- save_and_clear_fpu(); \
8388+do { save_and_clear_fpu(); \
8389 /* If you are tempted to conditionalize the following */ \
8390 /* so that ASI is only written if it changes, think again. */ \
8391 __asm__ __volatile__("wr %%g0, %0, %%asi" \
8392diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
8393index 25849ae..924c54b 100644
8394--- a/arch/sparc/include/asm/thread_info_32.h
8395+++ b/arch/sparc/include/asm/thread_info_32.h
8396@@ -49,6 +49,8 @@ struct thread_info {
8397 unsigned long w_saved;
8398
8399 struct restart_block restart_block;
8400+
8401+ unsigned long lowest_stack;
8402 };
8403
8404 /*
8405diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
8406index 269bd92..e46a9b8 100644
8407--- a/arch/sparc/include/asm/thread_info_64.h
8408+++ b/arch/sparc/include/asm/thread_info_64.h
8409@@ -63,6 +63,8 @@ struct thread_info {
8410 struct pt_regs *kern_una_regs;
8411 unsigned int kern_una_insn;
8412
8413+ unsigned long lowest_stack;
8414+
8415 unsigned long fpregs[0] __attribute__ ((aligned(64)));
8416 };
8417
8418@@ -192,10 +194,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
8419 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
8420 /* flag bit 6 is available */
8421 #define TIF_32BIT 7 /* 32-bit binary */
8422-/* flag bit 8 is available */
8423+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
8424 #define TIF_SECCOMP 9 /* secure computing */
8425 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
8426 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
8427+
8428 /* NOTE: Thread flags >= 12 should be ones we have no interest
8429 * in using in assembly, else we can't use the mask as
8430 * an immediate value in instructions such as andcc.
8431@@ -214,12 +217,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
8432 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
8433 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8434 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
8435+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8436
8437 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
8438 _TIF_DO_NOTIFY_RESUME_MASK | \
8439 _TIF_NEED_RESCHED)
8440 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
8441
8442+#define _TIF_WORK_SYSCALL \
8443+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
8444+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
8445+
8446+
8447 /*
8448 * Thread-synchronous status.
8449 *
8450diff --git a/arch/sparc/include/asm/tlbflush_64.h b/arch/sparc/include/asm/tlbflush_64.h
8451index 2ef4634..f0d6a97 100644
8452--- a/arch/sparc/include/asm/tlbflush_64.h
8453+++ b/arch/sparc/include/asm/tlbflush_64.h
8454@@ -11,24 +11,40 @@
8455 struct tlb_batch {
8456 struct mm_struct *mm;
8457 unsigned long tlb_nr;
8458+ unsigned long active;
8459 unsigned long vaddrs[TLB_BATCH_NR];
8460 };
8461
8462 extern void flush_tsb_kernel_range(unsigned long start, unsigned long end);
8463 extern void flush_tsb_user(struct tlb_batch *tb);
8464+extern void flush_tsb_user_page(struct mm_struct *mm, unsigned long vaddr);
8465
8466 /* TLB flush operations. */
8467
8468+static inline void flush_tlb_mm(struct mm_struct *mm)
8469+{
8470+}
8471+
8472+static inline void flush_tlb_page(struct vm_area_struct *vma,
8473+ unsigned long vmaddr)
8474+{
8475+}
8476+
8477+static inline void flush_tlb_range(struct vm_area_struct *vma,
8478+ unsigned long start, unsigned long end)
8479+{
8480+}
8481+
8482+#define __HAVE_ARCH_ENTER_LAZY_MMU_MODE
8483+
8484 extern void flush_tlb_pending(void);
8485-
8486-#define flush_tlb_range(vma,start,end) \
8487- do { (void)(start); flush_tlb_pending(); } while (0)
8488-#define flush_tlb_page(vma,addr) flush_tlb_pending()
8489-#define flush_tlb_mm(mm) flush_tlb_pending()
8490+extern void arch_enter_lazy_mmu_mode(void);
8491+extern void arch_leave_lazy_mmu_mode(void);
8492+#define arch_flush_lazy_mmu_mode() do {} while (0)
8493
8494 /* Local cpu only. */
8495 extern void __flush_tlb_all(void);
8496-
8497+extern void __flush_tlb_page(unsigned long context, unsigned long vaddr);
8498 extern void __flush_tlb_kernel_range(unsigned long start, unsigned long end);
8499
8500 #ifndef CONFIG_SMP
8501@@ -38,15 +54,24 @@ do { flush_tsb_kernel_range(start,end); \
8502 __flush_tlb_kernel_range(start,end); \
8503 } while (0)
8504
8505+static inline void global_flush_tlb_page(struct mm_struct *mm, unsigned long vaddr)
8506+{
8507+ __flush_tlb_page(CTX_HWBITS(mm->context), vaddr);
8508+}
8509+
8510 #else /* CONFIG_SMP */
8511
8512 extern void smp_flush_tlb_kernel_range(unsigned long start, unsigned long end);
8513+extern void smp_flush_tlb_page(struct mm_struct *mm, unsigned long vaddr);
8514
8515 #define flush_tlb_kernel_range(start, end) \
8516 do { flush_tsb_kernel_range(start,end); \
8517 smp_flush_tlb_kernel_range(start, end); \
8518 } while (0)
8519
8520+#define global_flush_tlb_page(mm, vaddr) \
8521+ smp_flush_tlb_page(mm, vaddr)
8522+
8523 #endif /* ! CONFIG_SMP */
8524
8525 #endif /* _SPARC64_TLBFLUSH_H */
8526diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
8527index 0167d26..767bb0c 100644
8528--- a/arch/sparc/include/asm/uaccess.h
8529+++ b/arch/sparc/include/asm/uaccess.h
8530@@ -1,5 +1,6 @@
8531 #ifndef ___ASM_SPARC_UACCESS_H
8532 #define ___ASM_SPARC_UACCESS_H
8533+
8534 #if defined(__sparc__) && defined(__arch64__)
8535 #include <asm/uaccess_64.h>
8536 #else
8537diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
8538index 53a28dd..50c38c3 100644
8539--- a/arch/sparc/include/asm/uaccess_32.h
8540+++ b/arch/sparc/include/asm/uaccess_32.h
8541@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
8542
8543 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8544 {
8545- if (n && __access_ok((unsigned long) to, n))
8546+ if ((long)n < 0)
8547+ return n;
8548+
8549+ if (n && __access_ok((unsigned long) to, n)) {
8550+ if (!__builtin_constant_p(n))
8551+ check_object_size(from, n, true);
8552 return __copy_user(to, (__force void __user *) from, n);
8553- else
8554+ } else
8555 return n;
8556 }
8557
8558 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
8559 {
8560+ if ((long)n < 0)
8561+ return n;
8562+
8563+ if (!__builtin_constant_p(n))
8564+ check_object_size(from, n, true);
8565+
8566 return __copy_user(to, (__force void __user *) from, n);
8567 }
8568
8569 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8570 {
8571- if (n && __access_ok((unsigned long) from, n))
8572+ if ((long)n < 0)
8573+ return n;
8574+
8575+ if (n && __access_ok((unsigned long) from, n)) {
8576+ if (!__builtin_constant_p(n))
8577+ check_object_size(to, n, false);
8578 return __copy_user((__force void __user *) to, from, n);
8579- else
8580+ } else
8581 return n;
8582 }
8583
8584 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
8585 {
8586+ if ((long)n < 0)
8587+ return n;
8588+
8589 return __copy_user((__force void __user *) to, from, n);
8590 }
8591
8592diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
8593index e562d3c..191f176 100644
8594--- a/arch/sparc/include/asm/uaccess_64.h
8595+++ b/arch/sparc/include/asm/uaccess_64.h
8596@@ -10,6 +10,7 @@
8597 #include <linux/compiler.h>
8598 #include <linux/string.h>
8599 #include <linux/thread_info.h>
8600+#include <linux/kernel.h>
8601 #include <asm/asi.h>
8602 #include <asm/spitfire.h>
8603 #include <asm-generic/uaccess-unaligned.h>
8604@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
8605 static inline unsigned long __must_check
8606 copy_from_user(void *to, const void __user *from, unsigned long size)
8607 {
8608- unsigned long ret = ___copy_from_user(to, from, size);
8609+ unsigned long ret;
8610
8611+ if ((long)size < 0 || size > INT_MAX)
8612+ return size;
8613+
8614+ if (!__builtin_constant_p(size))
8615+ check_object_size(to, size, false);
8616+
8617+ ret = ___copy_from_user(to, from, size);
8618 if (unlikely(ret))
8619 ret = copy_from_user_fixup(to, from, size);
8620
8621@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
8622 static inline unsigned long __must_check
8623 copy_to_user(void __user *to, const void *from, unsigned long size)
8624 {
8625- unsigned long ret = ___copy_to_user(to, from, size);
8626+ unsigned long ret;
8627
8628+ if ((long)size < 0 || size > INT_MAX)
8629+ return size;
8630+
8631+ if (!__builtin_constant_p(size))
8632+ check_object_size(from, size, true);
8633+
8634+ ret = ___copy_to_user(to, from, size);
8635 if (unlikely(ret))
8636 ret = copy_to_user_fixup(to, from, size);
8637 return ret;
8638diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
8639index 6cf591b..b49e65a 100644
8640--- a/arch/sparc/kernel/Makefile
8641+++ b/arch/sparc/kernel/Makefile
8642@@ -3,7 +3,7 @@
8643 #
8644
8645 asflags-y := -ansi
8646-ccflags-y := -Werror
8647+#ccflags-y := -Werror
8648
8649 extra-y := head_$(BITS).o
8650
8651diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
8652index be8e862..5b50b12 100644
8653--- a/arch/sparc/kernel/process_32.c
8654+++ b/arch/sparc/kernel/process_32.c
8655@@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
8656
8657 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
8658 r->psr, r->pc, r->npc, r->y, print_tainted());
8659- printk("PC: <%pS>\n", (void *) r->pc);
8660+ printk("PC: <%pA>\n", (void *) r->pc);
8661 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8662 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
8663 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
8664 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8665 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
8666 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
8667- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
8668+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
8669
8670 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8671 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
8672@@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8673 rw = (struct reg_window32 *) fp;
8674 pc = rw->ins[7];
8675 printk("[%08lx : ", pc);
8676- printk("%pS ] ", (void *) pc);
8677+ printk("%pA ] ", (void *) pc);
8678 fp = rw->ins[6];
8679 } while (++count < 16);
8680 printk("\n");
8681diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
8682index cdb80b2..5ca141d 100644
8683--- a/arch/sparc/kernel/process_64.c
8684+++ b/arch/sparc/kernel/process_64.c
8685@@ -181,14 +181,14 @@ static void show_regwindow(struct pt_regs *regs)
8686 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
8687 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
8688 if (regs->tstate & TSTATE_PRIV)
8689- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
8690+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
8691 }
8692
8693 void show_regs(struct pt_regs *regs)
8694 {
8695 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
8696 regs->tpc, regs->tnpc, regs->y, print_tainted());
8697- printk("TPC: <%pS>\n", (void *) regs->tpc);
8698+ printk("TPC: <%pA>\n", (void *) regs->tpc);
8699 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
8700 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
8701 regs->u_regs[3]);
8702@@ -201,7 +201,7 @@ void show_regs(struct pt_regs *regs)
8703 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
8704 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
8705 regs->u_regs[15]);
8706- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
8707+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
8708 show_regwindow(regs);
8709 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
8710 }
8711@@ -290,7 +290,7 @@ void arch_trigger_all_cpu_backtrace(void)
8712 ((tp && tp->task) ? tp->task->pid : -1));
8713
8714 if (gp->tstate & TSTATE_PRIV) {
8715- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
8716+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
8717 (void *) gp->tpc,
8718 (void *) gp->o7,
8719 (void *) gp->i7,
8720diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
8721index 1303021..c2a6321 100644
8722--- a/arch/sparc/kernel/prom_common.c
8723+++ b/arch/sparc/kernel/prom_common.c
8724@@ -143,7 +143,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
8725
8726 unsigned int prom_early_allocated __initdata;
8727
8728-static struct of_pdt_ops prom_sparc_ops __initdata = {
8729+static struct of_pdt_ops prom_sparc_ops __initconst = {
8730 .nextprop = prom_common_nextprop,
8731 .getproplen = prom_getproplen,
8732 .getproperty = prom_getproperty,
8733diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
8734index 7ff45e4..a58f271 100644
8735--- a/arch/sparc/kernel/ptrace_64.c
8736+++ b/arch/sparc/kernel/ptrace_64.c
8737@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
8738 return ret;
8739 }
8740
8741+#ifdef CONFIG_GRKERNSEC_SETXID
8742+extern void gr_delayed_cred_worker(void);
8743+#endif
8744+
8745 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8746 {
8747 int ret = 0;
8748@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8749 /* do the secure computing check first */
8750 secure_computing_strict(regs->u_regs[UREG_G1]);
8751
8752+#ifdef CONFIG_GRKERNSEC_SETXID
8753+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8754+ gr_delayed_cred_worker();
8755+#endif
8756+
8757 if (test_thread_flag(TIF_SYSCALL_TRACE))
8758 ret = tracehook_report_syscall_entry(regs);
8759
8760@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8761
8762 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
8763 {
8764+#ifdef CONFIG_GRKERNSEC_SETXID
8765+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8766+ gr_delayed_cred_worker();
8767+#endif
8768+
8769 audit_syscall_exit(regs);
8770
8771 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8772diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
8773index 537eb66..ca64d2a 100644
8774--- a/arch/sparc/kernel/smp_64.c
8775+++ b/arch/sparc/kernel/smp_64.c
8776@@ -849,7 +849,7 @@ void smp_tsb_sync(struct mm_struct *mm)
8777 }
8778
8779 extern unsigned long xcall_flush_tlb_mm;
8780-extern unsigned long xcall_flush_tlb_pending;
8781+extern unsigned long xcall_flush_tlb_page;
8782 extern unsigned long xcall_flush_tlb_kernel_range;
8783 extern unsigned long xcall_fetch_glob_regs;
8784 extern unsigned long xcall_fetch_glob_pmu;
8785@@ -1074,23 +1074,56 @@ local_flush_and_out:
8786 put_cpu();
8787 }
8788
8789+struct tlb_pending_info {
8790+ unsigned long ctx;
8791+ unsigned long nr;
8792+ unsigned long *vaddrs;
8793+};
8794+
8795+static void tlb_pending_func(void *info)
8796+{
8797+ struct tlb_pending_info *t = info;
8798+
8799+ __flush_tlb_pending(t->ctx, t->nr, t->vaddrs);
8800+}
8801+
8802 void smp_flush_tlb_pending(struct mm_struct *mm, unsigned long nr, unsigned long *vaddrs)
8803 {
8804 u32 ctx = CTX_HWBITS(mm->context);
8805+ struct tlb_pending_info info;
8806 int cpu = get_cpu();
8807
8808+ info.ctx = ctx;
8809+ info.nr = nr;
8810+ info.vaddrs = vaddrs;
8811+
8812 if (mm == current->mm && atomic_read(&mm->mm_users) == 1)
8813 cpumask_copy(mm_cpumask(mm), cpumask_of(cpu));
8814 else
8815- smp_cross_call_masked(&xcall_flush_tlb_pending,
8816- ctx, nr, (unsigned long) vaddrs,
8817- mm_cpumask(mm));
8818+ smp_call_function_many(mm_cpumask(mm), tlb_pending_func,
8819+ &info, 1);
8820
8821 __flush_tlb_pending(ctx, nr, vaddrs);
8822
8823 put_cpu();
8824 }
8825
8826+void smp_flush_tlb_page(struct mm_struct *mm, unsigned long vaddr)
8827+{
8828+ unsigned long context = CTX_HWBITS(mm->context);
8829+ int cpu = get_cpu();
8830+
8831+ if (mm == current->mm && atomic_read(&mm->mm_users) == 1)
8832+ cpumask_copy(mm_cpumask(mm), cpumask_of(cpu));
8833+ else
8834+ smp_cross_call_masked(&xcall_flush_tlb_page,
8835+ context, vaddr, 0,
8836+ mm_cpumask(mm));
8837+ __flush_tlb_page(context, vaddr);
8838+
8839+ put_cpu();
8840+}
8841+
8842 void smp_flush_tlb_kernel_range(unsigned long start, unsigned long end)
8843 {
8844 start &= PAGE_MASK;
8845diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
8846index 2da0bdc..79128d2 100644
8847--- a/arch/sparc/kernel/sys_sparc_32.c
8848+++ b/arch/sparc/kernel/sys_sparc_32.c
8849@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8850 if (len > TASK_SIZE - PAGE_SIZE)
8851 return -ENOMEM;
8852 if (!addr)
8853- addr = TASK_UNMAPPED_BASE;
8854+ addr = current->mm->mmap_base;
8855
8856 info.flags = 0;
8857 info.length = len;
8858diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
8859index 708bc29..f0129cb 100644
8860--- a/arch/sparc/kernel/sys_sparc_64.c
8861+++ b/arch/sparc/kernel/sys_sparc_64.c
8862@@ -90,13 +90,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8863 struct vm_area_struct * vma;
8864 unsigned long task_size = TASK_SIZE;
8865 int do_color_align;
8866+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8867 struct vm_unmapped_area_info info;
8868
8869 if (flags & MAP_FIXED) {
8870 /* We do not accept a shared mapping if it would violate
8871 * cache aliasing constraints.
8872 */
8873- if ((flags & MAP_SHARED) &&
8874+ if ((filp || (flags & MAP_SHARED)) &&
8875 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8876 return -EINVAL;
8877 return addr;
8878@@ -111,6 +112,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8879 if (filp || (flags & MAP_SHARED))
8880 do_color_align = 1;
8881
8882+#ifdef CONFIG_PAX_RANDMMAP
8883+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8884+#endif
8885+
8886 if (addr) {
8887 if (do_color_align)
8888 addr = COLOR_ALIGN(addr, pgoff);
8889@@ -118,14 +123,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8890 addr = PAGE_ALIGN(addr);
8891
8892 vma = find_vma(mm, addr);
8893- if (task_size - len >= addr &&
8894- (!vma || addr + len <= vma->vm_start))
8895+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8896 return addr;
8897 }
8898
8899 info.flags = 0;
8900 info.length = len;
8901- info.low_limit = TASK_UNMAPPED_BASE;
8902+ info.low_limit = mm->mmap_base;
8903 info.high_limit = min(task_size, VA_EXCLUDE_START);
8904 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
8905 info.align_offset = pgoff << PAGE_SHIFT;
8906@@ -134,6 +138,12 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8907 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
8908 VM_BUG_ON(addr != -ENOMEM);
8909 info.low_limit = VA_EXCLUDE_END;
8910+
8911+#ifdef CONFIG_PAX_RANDMMAP
8912+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8913+ info.low_limit += mm->delta_mmap;
8914+#endif
8915+
8916 info.high_limit = task_size;
8917 addr = vm_unmapped_area(&info);
8918 }
8919@@ -151,6 +161,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8920 unsigned long task_size = STACK_TOP32;
8921 unsigned long addr = addr0;
8922 int do_color_align;
8923+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8924 struct vm_unmapped_area_info info;
8925
8926 /* This should only ever run for 32-bit processes. */
8927@@ -160,7 +171,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8928 /* We do not accept a shared mapping if it would violate
8929 * cache aliasing constraints.
8930 */
8931- if ((flags & MAP_SHARED) &&
8932+ if ((filp || (flags & MAP_SHARED)) &&
8933 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8934 return -EINVAL;
8935 return addr;
8936@@ -173,6 +184,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8937 if (filp || (flags & MAP_SHARED))
8938 do_color_align = 1;
8939
8940+#ifdef CONFIG_PAX_RANDMMAP
8941+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8942+#endif
8943+
8944 /* requesting a specific address */
8945 if (addr) {
8946 if (do_color_align)
8947@@ -181,8 +196,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8948 addr = PAGE_ALIGN(addr);
8949
8950 vma = find_vma(mm, addr);
8951- if (task_size - len >= addr &&
8952- (!vma || addr + len <= vma->vm_start))
8953+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8954 return addr;
8955 }
8956
8957@@ -204,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8958 VM_BUG_ON(addr != -ENOMEM);
8959 info.flags = 0;
8960 info.low_limit = TASK_UNMAPPED_BASE;
8961+
8962+#ifdef CONFIG_PAX_RANDMMAP
8963+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8964+ info.low_limit += mm->delta_mmap;
8965+#endif
8966+
8967 info.high_limit = STACK_TOP32;
8968 addr = vm_unmapped_area(&info);
8969 }
8970@@ -264,6 +284,10 @@ static unsigned long mmap_rnd(void)
8971 {
8972 unsigned long rnd = 0UL;
8973
8974+#ifdef CONFIG_PAX_RANDMMAP
8975+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8976+#endif
8977+
8978 if (current->flags & PF_RANDOMIZE) {
8979 unsigned long val = get_random_int();
8980 if (test_thread_flag(TIF_32BIT))
8981@@ -289,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8982 gap == RLIM_INFINITY ||
8983 sysctl_legacy_va_layout) {
8984 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
8985+
8986+#ifdef CONFIG_PAX_RANDMMAP
8987+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8988+ mm->mmap_base += mm->delta_mmap;
8989+#endif
8990+
8991 mm->get_unmapped_area = arch_get_unmapped_area;
8992 mm->unmap_area = arch_unmap_area;
8993 } else {
8994@@ -301,6 +331,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8995 gap = (task_size / 6 * 5);
8996
8997 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
8998+
8999+#ifdef CONFIG_PAX_RANDMMAP
9000+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9001+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9002+#endif
9003+
9004 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9005 mm->unmap_area = arch_unmap_area_topdown;
9006 }
9007diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
9008index e0fed77..604a7e5 100644
9009--- a/arch/sparc/kernel/syscalls.S
9010+++ b/arch/sparc/kernel/syscalls.S
9011@@ -58,7 +58,7 @@ sys32_rt_sigreturn:
9012 #endif
9013 .align 32
9014 1: ldx [%g6 + TI_FLAGS], %l5
9015- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9016+ andcc %l5, _TIF_WORK_SYSCALL, %g0
9017 be,pt %icc, rtrap
9018 nop
9019 call syscall_trace_leave
9020@@ -190,7 +190,7 @@ linux_sparc_syscall32:
9021
9022 srl %i5, 0, %o5 ! IEU1
9023 srl %i2, 0, %o2 ! IEU0 Group
9024- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9025+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9026 bne,pn %icc, linux_syscall_trace32 ! CTI
9027 mov %i0, %l5 ! IEU1
9028 call %l7 ! CTI Group brk forced
9029@@ -213,7 +213,7 @@ linux_sparc_syscall:
9030
9031 mov %i3, %o3 ! IEU1
9032 mov %i4, %o4 ! IEU0 Group
9033- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9034+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9035 bne,pn %icc, linux_syscall_trace ! CTI Group
9036 mov %i0, %l5 ! IEU0
9037 2: call %l7 ! CTI Group brk forced
9038@@ -229,7 +229,7 @@ ret_sys_call:
9039
9040 cmp %o0, -ERESTART_RESTARTBLOCK
9041 bgeu,pn %xcc, 1f
9042- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9043+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9044 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
9045
9046 2:
9047diff --git a/arch/sparc/kernel/sysfs.c b/arch/sparc/kernel/sysfs.c
9048index 654e8aa..45f431b 100644
9049--- a/arch/sparc/kernel/sysfs.c
9050+++ b/arch/sparc/kernel/sysfs.c
9051@@ -266,7 +266,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
9052 return NOTIFY_OK;
9053 }
9054
9055-static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
9056+static struct notifier_block sysfs_cpu_nb = {
9057 .notifier_call = sysfs_cpu_notify,
9058 };
9059
9060diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
9061index a5785ea..405c5f7 100644
9062--- a/arch/sparc/kernel/traps_32.c
9063+++ b/arch/sparc/kernel/traps_32.c
9064@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
9065 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
9066 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
9067
9068+extern void gr_handle_kernel_exploit(void);
9069+
9070 void die_if_kernel(char *str, struct pt_regs *regs)
9071 {
9072 static int die_counter;
9073@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
9074 count++ < 30 &&
9075 (((unsigned long) rw) >= PAGE_OFFSET) &&
9076 !(((unsigned long) rw) & 0x7)) {
9077- printk("Caller[%08lx]: %pS\n", rw->ins[7],
9078+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
9079 (void *) rw->ins[7]);
9080 rw = (struct reg_window32 *)rw->ins[6];
9081 }
9082 }
9083 printk("Instruction DUMP:");
9084 instruction_dump ((unsigned long *) regs->pc);
9085- if(regs->psr & PSR_PS)
9086+ if(regs->psr & PSR_PS) {
9087+ gr_handle_kernel_exploit();
9088 do_exit(SIGKILL);
9089+ }
9090 do_exit(SIGSEGV);
9091 }
9092
9093diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
9094index e7ecf15..6520e65 100644
9095--- a/arch/sparc/kernel/traps_64.c
9096+++ b/arch/sparc/kernel/traps_64.c
9097@@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
9098 i + 1,
9099 p->trapstack[i].tstate, p->trapstack[i].tpc,
9100 p->trapstack[i].tnpc, p->trapstack[i].tt);
9101- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
9102+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
9103 }
9104 }
9105
9106@@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
9107
9108 lvl -= 0x100;
9109 if (regs->tstate & TSTATE_PRIV) {
9110+
9111+#ifdef CONFIG_PAX_REFCOUNT
9112+ if (lvl == 6)
9113+ pax_report_refcount_overflow(regs);
9114+#endif
9115+
9116 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
9117 die_if_kernel(buffer, regs);
9118 }
9119@@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
9120 void bad_trap_tl1(struct pt_regs *regs, long lvl)
9121 {
9122 char buffer[32];
9123-
9124+
9125 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
9126 0, lvl, SIGTRAP) == NOTIFY_STOP)
9127 return;
9128
9129+#ifdef CONFIG_PAX_REFCOUNT
9130+ if (lvl == 6)
9131+ pax_report_refcount_overflow(regs);
9132+#endif
9133+
9134 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
9135
9136 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
9137@@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
9138 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
9139 printk("%s" "ERROR(%d): ",
9140 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
9141- printk("TPC<%pS>\n", (void *) regs->tpc);
9142+ printk("TPC<%pA>\n", (void *) regs->tpc);
9143 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
9144 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
9145 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
9146@@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
9147 smp_processor_id(),
9148 (type & 0x1) ? 'I' : 'D',
9149 regs->tpc);
9150- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
9151+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
9152 panic("Irrecoverable Cheetah+ parity error.");
9153 }
9154
9155@@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
9156 smp_processor_id(),
9157 (type & 0x1) ? 'I' : 'D',
9158 regs->tpc);
9159- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
9160+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
9161 }
9162
9163 struct sun4v_error_entry {
9164@@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
9165
9166 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
9167 regs->tpc, tl);
9168- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
9169+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
9170 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
9171- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
9172+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
9173 (void *) regs->u_regs[UREG_I7]);
9174 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
9175 "pte[%lx] error[%lx]\n",
9176@@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
9177
9178 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
9179 regs->tpc, tl);
9180- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
9181+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
9182 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
9183- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
9184+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
9185 (void *) regs->u_regs[UREG_I7]);
9186 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
9187 "pte[%lx] error[%lx]\n",
9188@@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
9189 fp = (unsigned long)sf->fp + STACK_BIAS;
9190 }
9191
9192- printk(" [%016lx] %pS\n", pc, (void *) pc);
9193+ printk(" [%016lx] %pA\n", pc, (void *) pc);
9194 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
9195 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
9196 int index = tsk->curr_ret_stack;
9197 if (tsk->ret_stack && index >= graph) {
9198 pc = tsk->ret_stack[index - graph].ret;
9199- printk(" [%016lx] %pS\n", pc, (void *) pc);
9200+ printk(" [%016lx] %pA\n", pc, (void *) pc);
9201 graph++;
9202 }
9203 }
9204@@ -2367,6 +2378,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
9205 return (struct reg_window *) (fp + STACK_BIAS);
9206 }
9207
9208+extern void gr_handle_kernel_exploit(void);
9209+
9210 void die_if_kernel(char *str, struct pt_regs *regs)
9211 {
9212 static int die_counter;
9213@@ -2395,7 +2408,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
9214 while (rw &&
9215 count++ < 30 &&
9216 kstack_valid(tp, (unsigned long) rw)) {
9217- printk("Caller[%016lx]: %pS\n", rw->ins[7],
9218+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
9219 (void *) rw->ins[7]);
9220
9221 rw = kernel_stack_up(rw);
9222@@ -2408,8 +2421,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
9223 }
9224 user_instruction_dump ((unsigned int __user *) regs->tpc);
9225 }
9226- if (regs->tstate & TSTATE_PRIV)
9227+ if (regs->tstate & TSTATE_PRIV) {
9228+ gr_handle_kernel_exploit();
9229 do_exit(SIGKILL);
9230+ }
9231 do_exit(SIGSEGV);
9232 }
9233 EXPORT_SYMBOL(die_if_kernel);
9234diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
9235index 8201c25e..072a2a7 100644
9236--- a/arch/sparc/kernel/unaligned_64.c
9237+++ b/arch/sparc/kernel/unaligned_64.c
9238@@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
9239 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
9240
9241 if (__ratelimit(&ratelimit)) {
9242- printk("Kernel unaligned access at TPC[%lx] %pS\n",
9243+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
9244 regs->tpc, (void *) regs->tpc);
9245 }
9246 }
9247diff --git a/arch/sparc/kernel/us3_cpufreq.c b/arch/sparc/kernel/us3_cpufreq.c
9248index eb1624b..f9f4ddb 100644
9249--- a/arch/sparc/kernel/us3_cpufreq.c
9250+++ b/arch/sparc/kernel/us3_cpufreq.c
9251@@ -18,14 +18,12 @@
9252 #include <asm/head.h>
9253 #include <asm/timer.h>
9254
9255-static struct cpufreq_driver *cpufreq_us3_driver;
9256-
9257 struct us3_freq_percpu_info {
9258 struct cpufreq_frequency_table table[4];
9259 };
9260
9261 /* Indexed by cpu number. */
9262-static struct us3_freq_percpu_info *us3_freq_table;
9263+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
9264
9265 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
9266 * in the Safari config register.
9267@@ -191,12 +189,25 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
9268
9269 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
9270 {
9271- if (cpufreq_us3_driver)
9272- us3_set_cpu_divider_index(policy->cpu, 0);
9273+ us3_set_cpu_divider_index(policy->cpu, 0);
9274
9275 return 0;
9276 }
9277
9278+static int __init us3_freq_init(void);
9279+static void __exit us3_freq_exit(void);
9280+
9281+static struct cpufreq_driver cpufreq_us3_driver = {
9282+ .init = us3_freq_cpu_init,
9283+ .verify = us3_freq_verify,
9284+ .target = us3_freq_target,
9285+ .get = us3_freq_get,
9286+ .exit = us3_freq_cpu_exit,
9287+ .owner = THIS_MODULE,
9288+ .name = "UltraSPARC-III",
9289+
9290+};
9291+
9292 static int __init us3_freq_init(void)
9293 {
9294 unsigned long manuf, impl, ver;
9295@@ -213,57 +224,15 @@ static int __init us3_freq_init(void)
9296 (impl == CHEETAH_IMPL ||
9297 impl == CHEETAH_PLUS_IMPL ||
9298 impl == JAGUAR_IMPL ||
9299- impl == PANTHER_IMPL)) {
9300- struct cpufreq_driver *driver;
9301-
9302- ret = -ENOMEM;
9303- driver = kzalloc(sizeof(struct cpufreq_driver), GFP_KERNEL);
9304- if (!driver)
9305- goto err_out;
9306-
9307- us3_freq_table = kzalloc(
9308- (NR_CPUS * sizeof(struct us3_freq_percpu_info)),
9309- GFP_KERNEL);
9310- if (!us3_freq_table)
9311- goto err_out;
9312-
9313- driver->init = us3_freq_cpu_init;
9314- driver->verify = us3_freq_verify;
9315- driver->target = us3_freq_target;
9316- driver->get = us3_freq_get;
9317- driver->exit = us3_freq_cpu_exit;
9318- driver->owner = THIS_MODULE,
9319- strcpy(driver->name, "UltraSPARC-III");
9320-
9321- cpufreq_us3_driver = driver;
9322- ret = cpufreq_register_driver(driver);
9323- if (ret)
9324- goto err_out;
9325-
9326- return 0;
9327-
9328-err_out:
9329- if (driver) {
9330- kfree(driver);
9331- cpufreq_us3_driver = NULL;
9332- }
9333- kfree(us3_freq_table);
9334- us3_freq_table = NULL;
9335- return ret;
9336- }
9337+ impl == PANTHER_IMPL))
9338+ return cpufreq_register_driver(cpufreq_us3_driver);
9339
9340 return -ENODEV;
9341 }
9342
9343 static void __exit us3_freq_exit(void)
9344 {
9345- if (cpufreq_us3_driver) {
9346- cpufreq_unregister_driver(cpufreq_us3_driver);
9347- kfree(cpufreq_us3_driver);
9348- cpufreq_us3_driver = NULL;
9349- kfree(us3_freq_table);
9350- us3_freq_table = NULL;
9351- }
9352+ cpufreq_unregister_driver(cpufreq_us3_driver);
9353 }
9354
9355 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
9356diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
9357index 8410065f2..4fd4ca22 100644
9358--- a/arch/sparc/lib/Makefile
9359+++ b/arch/sparc/lib/Makefile
9360@@ -2,7 +2,7 @@
9361 #
9362
9363 asflags-y := -ansi -DST_DIV0=0x02
9364-ccflags-y := -Werror
9365+#ccflags-y := -Werror
9366
9367 lib-$(CONFIG_SPARC32) += ashrdi3.o
9368 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
9369diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
9370index 85c233d..68500e0 100644
9371--- a/arch/sparc/lib/atomic_64.S
9372+++ b/arch/sparc/lib/atomic_64.S
9373@@ -17,7 +17,12 @@
9374 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
9375 BACKOFF_SETUP(%o2)
9376 1: lduw [%o1], %g1
9377- add %g1, %o0, %g7
9378+ addcc %g1, %o0, %g7
9379+
9380+#ifdef CONFIG_PAX_REFCOUNT
9381+ tvs %icc, 6
9382+#endif
9383+
9384 cas [%o1], %g1, %g7
9385 cmp %g1, %g7
9386 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
9387@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
9388 2: BACKOFF_SPIN(%o2, %o3, 1b)
9389 ENDPROC(atomic_add)
9390
9391+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
9392+ BACKOFF_SETUP(%o2)
9393+1: lduw [%o1], %g1
9394+ add %g1, %o0, %g7
9395+ cas [%o1], %g1, %g7
9396+ cmp %g1, %g7
9397+ bne,pn %icc, 2f
9398+ nop
9399+ retl
9400+ nop
9401+2: BACKOFF_SPIN(%o2, %o3, 1b)
9402+ENDPROC(atomic_add_unchecked)
9403+
9404 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
9405 BACKOFF_SETUP(%o2)
9406 1: lduw [%o1], %g1
9407- sub %g1, %o0, %g7
9408+ subcc %g1, %o0, %g7
9409+
9410+#ifdef CONFIG_PAX_REFCOUNT
9411+ tvs %icc, 6
9412+#endif
9413+
9414 cas [%o1], %g1, %g7
9415 cmp %g1, %g7
9416 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
9417@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
9418 2: BACKOFF_SPIN(%o2, %o3, 1b)
9419 ENDPROC(atomic_sub)
9420
9421+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
9422+ BACKOFF_SETUP(%o2)
9423+1: lduw [%o1], %g1
9424+ sub %g1, %o0, %g7
9425+ cas [%o1], %g1, %g7
9426+ cmp %g1, %g7
9427+ bne,pn %icc, 2f
9428+ nop
9429+ retl
9430+ nop
9431+2: BACKOFF_SPIN(%o2, %o3, 1b)
9432+ENDPROC(atomic_sub_unchecked)
9433+
9434 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
9435 BACKOFF_SETUP(%o2)
9436 1: lduw [%o1], %g1
9437- add %g1, %o0, %g7
9438+ addcc %g1, %o0, %g7
9439+
9440+#ifdef CONFIG_PAX_REFCOUNT
9441+ tvs %icc, 6
9442+#endif
9443+
9444 cas [%o1], %g1, %g7
9445 cmp %g1, %g7
9446 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
9447@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
9448 2: BACKOFF_SPIN(%o2, %o3, 1b)
9449 ENDPROC(atomic_add_ret)
9450
9451+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
9452+ BACKOFF_SETUP(%o2)
9453+1: lduw [%o1], %g1
9454+ addcc %g1, %o0, %g7
9455+ cas [%o1], %g1, %g7
9456+ cmp %g1, %g7
9457+ bne,pn %icc, 2f
9458+ add %g7, %o0, %g7
9459+ sra %g7, 0, %o0
9460+ retl
9461+ nop
9462+2: BACKOFF_SPIN(%o2, %o3, 1b)
9463+ENDPROC(atomic_add_ret_unchecked)
9464+
9465 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
9466 BACKOFF_SETUP(%o2)
9467 1: lduw [%o1], %g1
9468- sub %g1, %o0, %g7
9469+ subcc %g1, %o0, %g7
9470+
9471+#ifdef CONFIG_PAX_REFCOUNT
9472+ tvs %icc, 6
9473+#endif
9474+
9475 cas [%o1], %g1, %g7
9476 cmp %g1, %g7
9477 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
9478@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
9479 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
9480 BACKOFF_SETUP(%o2)
9481 1: ldx [%o1], %g1
9482- add %g1, %o0, %g7
9483+ addcc %g1, %o0, %g7
9484+
9485+#ifdef CONFIG_PAX_REFCOUNT
9486+ tvs %xcc, 6
9487+#endif
9488+
9489 casx [%o1], %g1, %g7
9490 cmp %g1, %g7
9491 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9492@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
9493 2: BACKOFF_SPIN(%o2, %o3, 1b)
9494 ENDPROC(atomic64_add)
9495
9496+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
9497+ BACKOFF_SETUP(%o2)
9498+1: ldx [%o1], %g1
9499+ addcc %g1, %o0, %g7
9500+ casx [%o1], %g1, %g7
9501+ cmp %g1, %g7
9502+ bne,pn %xcc, 2f
9503+ nop
9504+ retl
9505+ nop
9506+2: BACKOFF_SPIN(%o2, %o3, 1b)
9507+ENDPROC(atomic64_add_unchecked)
9508+
9509 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
9510 BACKOFF_SETUP(%o2)
9511 1: ldx [%o1], %g1
9512- sub %g1, %o0, %g7
9513+ subcc %g1, %o0, %g7
9514+
9515+#ifdef CONFIG_PAX_REFCOUNT
9516+ tvs %xcc, 6
9517+#endif
9518+
9519 casx [%o1], %g1, %g7
9520 cmp %g1, %g7
9521 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9522@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
9523 2: BACKOFF_SPIN(%o2, %o3, 1b)
9524 ENDPROC(atomic64_sub)
9525
9526+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
9527+ BACKOFF_SETUP(%o2)
9528+1: ldx [%o1], %g1
9529+ subcc %g1, %o0, %g7
9530+ casx [%o1], %g1, %g7
9531+ cmp %g1, %g7
9532+ bne,pn %xcc, 2f
9533+ nop
9534+ retl
9535+ nop
9536+2: BACKOFF_SPIN(%o2, %o3, 1b)
9537+ENDPROC(atomic64_sub_unchecked)
9538+
9539 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
9540 BACKOFF_SETUP(%o2)
9541 1: ldx [%o1], %g1
9542- add %g1, %o0, %g7
9543+ addcc %g1, %o0, %g7
9544+
9545+#ifdef CONFIG_PAX_REFCOUNT
9546+ tvs %xcc, 6
9547+#endif
9548+
9549 casx [%o1], %g1, %g7
9550 cmp %g1, %g7
9551 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9552@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
9553 2: BACKOFF_SPIN(%o2, %o3, 1b)
9554 ENDPROC(atomic64_add_ret)
9555
9556+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
9557+ BACKOFF_SETUP(%o2)
9558+1: ldx [%o1], %g1
9559+ addcc %g1, %o0, %g7
9560+ casx [%o1], %g1, %g7
9561+ cmp %g1, %g7
9562+ bne,pn %xcc, 2f
9563+ add %g7, %o0, %g7
9564+ mov %g7, %o0
9565+ retl
9566+ nop
9567+2: BACKOFF_SPIN(%o2, %o3, 1b)
9568+ENDPROC(atomic64_add_ret_unchecked)
9569+
9570 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
9571 BACKOFF_SETUP(%o2)
9572 1: ldx [%o1], %g1
9573- sub %g1, %o0, %g7
9574+ subcc %g1, %o0, %g7
9575+
9576+#ifdef CONFIG_PAX_REFCOUNT
9577+ tvs %xcc, 6
9578+#endif
9579+
9580 casx [%o1], %g1, %g7
9581 cmp %g1, %g7
9582 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9583diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
9584index 0c4e35e..745d3e4 100644
9585--- a/arch/sparc/lib/ksyms.c
9586+++ b/arch/sparc/lib/ksyms.c
9587@@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
9588
9589 /* Atomic counter implementation. */
9590 EXPORT_SYMBOL(atomic_add);
9591+EXPORT_SYMBOL(atomic_add_unchecked);
9592 EXPORT_SYMBOL(atomic_add_ret);
9593+EXPORT_SYMBOL(atomic_add_ret_unchecked);
9594 EXPORT_SYMBOL(atomic_sub);
9595+EXPORT_SYMBOL(atomic_sub_unchecked);
9596 EXPORT_SYMBOL(atomic_sub_ret);
9597 EXPORT_SYMBOL(atomic64_add);
9598+EXPORT_SYMBOL(atomic64_add_unchecked);
9599 EXPORT_SYMBOL(atomic64_add_ret);
9600+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
9601 EXPORT_SYMBOL(atomic64_sub);
9602+EXPORT_SYMBOL(atomic64_sub_unchecked);
9603 EXPORT_SYMBOL(atomic64_sub_ret);
9604 EXPORT_SYMBOL(atomic64_dec_if_positive);
9605
9606diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
9607index 30c3ecc..736f015 100644
9608--- a/arch/sparc/mm/Makefile
9609+++ b/arch/sparc/mm/Makefile
9610@@ -2,7 +2,7 @@
9611 #
9612
9613 asflags-y := -ansi
9614-ccflags-y := -Werror
9615+#ccflags-y := -Werror
9616
9617 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
9618 obj-y += fault_$(BITS).o
9619diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
9620index e98bfda..ea8d221 100644
9621--- a/arch/sparc/mm/fault_32.c
9622+++ b/arch/sparc/mm/fault_32.c
9623@@ -21,6 +21,9 @@
9624 #include <linux/perf_event.h>
9625 #include <linux/interrupt.h>
9626 #include <linux/kdebug.h>
9627+#include <linux/slab.h>
9628+#include <linux/pagemap.h>
9629+#include <linux/compiler.h>
9630
9631 #include <asm/page.h>
9632 #include <asm/pgtable.h>
9633@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
9634 return safe_compute_effective_address(regs, insn);
9635 }
9636
9637+#ifdef CONFIG_PAX_PAGEEXEC
9638+#ifdef CONFIG_PAX_DLRESOLVE
9639+static void pax_emuplt_close(struct vm_area_struct *vma)
9640+{
9641+ vma->vm_mm->call_dl_resolve = 0UL;
9642+}
9643+
9644+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9645+{
9646+ unsigned int *kaddr;
9647+
9648+ vmf->page = alloc_page(GFP_HIGHUSER);
9649+ if (!vmf->page)
9650+ return VM_FAULT_OOM;
9651+
9652+ kaddr = kmap(vmf->page);
9653+ memset(kaddr, 0, PAGE_SIZE);
9654+ kaddr[0] = 0x9DE3BFA8U; /* save */
9655+ flush_dcache_page(vmf->page);
9656+ kunmap(vmf->page);
9657+ return VM_FAULT_MAJOR;
9658+}
9659+
9660+static const struct vm_operations_struct pax_vm_ops = {
9661+ .close = pax_emuplt_close,
9662+ .fault = pax_emuplt_fault
9663+};
9664+
9665+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
9666+{
9667+ int ret;
9668+
9669+ INIT_LIST_HEAD(&vma->anon_vma_chain);
9670+ vma->vm_mm = current->mm;
9671+ vma->vm_start = addr;
9672+ vma->vm_end = addr + PAGE_SIZE;
9673+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
9674+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
9675+ vma->vm_ops = &pax_vm_ops;
9676+
9677+ ret = insert_vm_struct(current->mm, vma);
9678+ if (ret)
9679+ return ret;
9680+
9681+ ++current->mm->total_vm;
9682+ return 0;
9683+}
9684+#endif
9685+
9686+/*
9687+ * PaX: decide what to do with offenders (regs->pc = fault address)
9688+ *
9689+ * returns 1 when task should be killed
9690+ * 2 when patched PLT trampoline was detected
9691+ * 3 when unpatched PLT trampoline was detected
9692+ */
9693+static int pax_handle_fetch_fault(struct pt_regs *regs)
9694+{
9695+
9696+#ifdef CONFIG_PAX_EMUPLT
9697+ int err;
9698+
9699+ do { /* PaX: patched PLT emulation #1 */
9700+ unsigned int sethi1, sethi2, jmpl;
9701+
9702+ err = get_user(sethi1, (unsigned int *)regs->pc);
9703+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
9704+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
9705+
9706+ if (err)
9707+ break;
9708+
9709+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
9710+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
9711+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
9712+ {
9713+ unsigned int addr;
9714+
9715+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
9716+ addr = regs->u_regs[UREG_G1];
9717+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9718+ regs->pc = addr;
9719+ regs->npc = addr+4;
9720+ return 2;
9721+ }
9722+ } while (0);
9723+
9724+ do { /* PaX: patched PLT emulation #2 */
9725+ unsigned int ba;
9726+
9727+ err = get_user(ba, (unsigned int *)regs->pc);
9728+
9729+ if (err)
9730+ break;
9731+
9732+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
9733+ unsigned int addr;
9734+
9735+ if ((ba & 0xFFC00000U) == 0x30800000U)
9736+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
9737+ else
9738+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9739+ regs->pc = addr;
9740+ regs->npc = addr+4;
9741+ return 2;
9742+ }
9743+ } while (0);
9744+
9745+ do { /* PaX: patched PLT emulation #3 */
9746+ unsigned int sethi, bajmpl, nop;
9747+
9748+ err = get_user(sethi, (unsigned int *)regs->pc);
9749+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
9750+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
9751+
9752+ if (err)
9753+ break;
9754+
9755+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9756+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
9757+ nop == 0x01000000U)
9758+ {
9759+ unsigned int addr;
9760+
9761+ addr = (sethi & 0x003FFFFFU) << 10;
9762+ regs->u_regs[UREG_G1] = addr;
9763+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
9764+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9765+ else
9766+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9767+ regs->pc = addr;
9768+ regs->npc = addr+4;
9769+ return 2;
9770+ }
9771+ } while (0);
9772+
9773+ do { /* PaX: unpatched PLT emulation step 1 */
9774+ unsigned int sethi, ba, nop;
9775+
9776+ err = get_user(sethi, (unsigned int *)regs->pc);
9777+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
9778+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
9779+
9780+ if (err)
9781+ break;
9782+
9783+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9784+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
9785+ nop == 0x01000000U)
9786+ {
9787+ unsigned int addr, save, call;
9788+
9789+ if ((ba & 0xFFC00000U) == 0x30800000U)
9790+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
9791+ else
9792+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9793+
9794+ err = get_user(save, (unsigned int *)addr);
9795+ err |= get_user(call, (unsigned int *)(addr+4));
9796+ err |= get_user(nop, (unsigned int *)(addr+8));
9797+ if (err)
9798+ break;
9799+
9800+#ifdef CONFIG_PAX_DLRESOLVE
9801+ if (save == 0x9DE3BFA8U &&
9802+ (call & 0xC0000000U) == 0x40000000U &&
9803+ nop == 0x01000000U)
9804+ {
9805+ struct vm_area_struct *vma;
9806+ unsigned long call_dl_resolve;
9807+
9808+ down_read(&current->mm->mmap_sem);
9809+ call_dl_resolve = current->mm->call_dl_resolve;
9810+ up_read(&current->mm->mmap_sem);
9811+ if (likely(call_dl_resolve))
9812+ goto emulate;
9813+
9814+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
9815+
9816+ down_write(&current->mm->mmap_sem);
9817+ if (current->mm->call_dl_resolve) {
9818+ call_dl_resolve = current->mm->call_dl_resolve;
9819+ up_write(&current->mm->mmap_sem);
9820+ if (vma)
9821+ kmem_cache_free(vm_area_cachep, vma);
9822+ goto emulate;
9823+ }
9824+
9825+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
9826+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
9827+ up_write(&current->mm->mmap_sem);
9828+ if (vma)
9829+ kmem_cache_free(vm_area_cachep, vma);
9830+ return 1;
9831+ }
9832+
9833+ if (pax_insert_vma(vma, call_dl_resolve)) {
9834+ up_write(&current->mm->mmap_sem);
9835+ kmem_cache_free(vm_area_cachep, vma);
9836+ return 1;
9837+ }
9838+
9839+ current->mm->call_dl_resolve = call_dl_resolve;
9840+ up_write(&current->mm->mmap_sem);
9841+
9842+emulate:
9843+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9844+ regs->pc = call_dl_resolve;
9845+ regs->npc = addr+4;
9846+ return 3;
9847+ }
9848+#endif
9849+
9850+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
9851+ if ((save & 0xFFC00000U) == 0x05000000U &&
9852+ (call & 0xFFFFE000U) == 0x85C0A000U &&
9853+ nop == 0x01000000U)
9854+ {
9855+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9856+ regs->u_regs[UREG_G2] = addr + 4;
9857+ addr = (save & 0x003FFFFFU) << 10;
9858+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9859+ regs->pc = addr;
9860+ regs->npc = addr+4;
9861+ return 3;
9862+ }
9863+ }
9864+ } while (0);
9865+
9866+ do { /* PaX: unpatched PLT emulation step 2 */
9867+ unsigned int save, call, nop;
9868+
9869+ err = get_user(save, (unsigned int *)(regs->pc-4));
9870+ err |= get_user(call, (unsigned int *)regs->pc);
9871+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
9872+ if (err)
9873+ break;
9874+
9875+ if (save == 0x9DE3BFA8U &&
9876+ (call & 0xC0000000U) == 0x40000000U &&
9877+ nop == 0x01000000U)
9878+ {
9879+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
9880+
9881+ regs->u_regs[UREG_RETPC] = regs->pc;
9882+ regs->pc = dl_resolve;
9883+ regs->npc = dl_resolve+4;
9884+ return 3;
9885+ }
9886+ } while (0);
9887+#endif
9888+
9889+ return 1;
9890+}
9891+
9892+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9893+{
9894+ unsigned long i;
9895+
9896+ printk(KERN_ERR "PAX: bytes at PC: ");
9897+ for (i = 0; i < 8; i++) {
9898+ unsigned int c;
9899+ if (get_user(c, (unsigned int *)pc+i))
9900+ printk(KERN_CONT "???????? ");
9901+ else
9902+ printk(KERN_CONT "%08x ", c);
9903+ }
9904+ printk("\n");
9905+}
9906+#endif
9907+
9908 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
9909 int text_fault)
9910 {
9911@@ -230,6 +504,24 @@ good_area:
9912 if (!(vma->vm_flags & VM_WRITE))
9913 goto bad_area;
9914 } else {
9915+
9916+#ifdef CONFIG_PAX_PAGEEXEC
9917+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
9918+ up_read(&mm->mmap_sem);
9919+ switch (pax_handle_fetch_fault(regs)) {
9920+
9921+#ifdef CONFIG_PAX_EMUPLT
9922+ case 2:
9923+ case 3:
9924+ return;
9925+#endif
9926+
9927+ }
9928+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
9929+ do_group_exit(SIGKILL);
9930+ }
9931+#endif
9932+
9933 /* Allow reads even for write-only mappings */
9934 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
9935 goto bad_area;
9936diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
9937index 5062ff3..e0b75f3 100644
9938--- a/arch/sparc/mm/fault_64.c
9939+++ b/arch/sparc/mm/fault_64.c
9940@@ -21,6 +21,9 @@
9941 #include <linux/kprobes.h>
9942 #include <linux/kdebug.h>
9943 #include <linux/percpu.h>
9944+#include <linux/slab.h>
9945+#include <linux/pagemap.h>
9946+#include <linux/compiler.h>
9947
9948 #include <asm/page.h>
9949 #include <asm/pgtable.h>
9950@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
9951 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
9952 regs->tpc);
9953 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
9954- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
9955+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
9956 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
9957 dump_stack();
9958 unhandled_fault(regs->tpc, current, regs);
9959@@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
9960 show_regs(regs);
9961 }
9962
9963+#ifdef CONFIG_PAX_PAGEEXEC
9964+#ifdef CONFIG_PAX_DLRESOLVE
9965+static void pax_emuplt_close(struct vm_area_struct *vma)
9966+{
9967+ vma->vm_mm->call_dl_resolve = 0UL;
9968+}
9969+
9970+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9971+{
9972+ unsigned int *kaddr;
9973+
9974+ vmf->page = alloc_page(GFP_HIGHUSER);
9975+ if (!vmf->page)
9976+ return VM_FAULT_OOM;
9977+
9978+ kaddr = kmap(vmf->page);
9979+ memset(kaddr, 0, PAGE_SIZE);
9980+ kaddr[0] = 0x9DE3BFA8U; /* save */
9981+ flush_dcache_page(vmf->page);
9982+ kunmap(vmf->page);
9983+ return VM_FAULT_MAJOR;
9984+}
9985+
9986+static const struct vm_operations_struct pax_vm_ops = {
9987+ .close = pax_emuplt_close,
9988+ .fault = pax_emuplt_fault
9989+};
9990+
9991+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
9992+{
9993+ int ret;
9994+
9995+ INIT_LIST_HEAD(&vma->anon_vma_chain);
9996+ vma->vm_mm = current->mm;
9997+ vma->vm_start = addr;
9998+ vma->vm_end = addr + PAGE_SIZE;
9999+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10000+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10001+ vma->vm_ops = &pax_vm_ops;
10002+
10003+ ret = insert_vm_struct(current->mm, vma);
10004+ if (ret)
10005+ return ret;
10006+
10007+ ++current->mm->total_vm;
10008+ return 0;
10009+}
10010+#endif
10011+
10012+/*
10013+ * PaX: decide what to do with offenders (regs->tpc = fault address)
10014+ *
10015+ * returns 1 when task should be killed
10016+ * 2 when patched PLT trampoline was detected
10017+ * 3 when unpatched PLT trampoline was detected
10018+ */
10019+static int pax_handle_fetch_fault(struct pt_regs *regs)
10020+{
10021+
10022+#ifdef CONFIG_PAX_EMUPLT
10023+ int err;
10024+
10025+ do { /* PaX: patched PLT emulation #1 */
10026+ unsigned int sethi1, sethi2, jmpl;
10027+
10028+ err = get_user(sethi1, (unsigned int *)regs->tpc);
10029+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
10030+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
10031+
10032+ if (err)
10033+ break;
10034+
10035+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
10036+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
10037+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
10038+ {
10039+ unsigned long addr;
10040+
10041+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
10042+ addr = regs->u_regs[UREG_G1];
10043+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10044+
10045+ if (test_thread_flag(TIF_32BIT))
10046+ addr &= 0xFFFFFFFFUL;
10047+
10048+ regs->tpc = addr;
10049+ regs->tnpc = addr+4;
10050+ return 2;
10051+ }
10052+ } while (0);
10053+
10054+ do { /* PaX: patched PLT emulation #2 */
10055+ unsigned int ba;
10056+
10057+ err = get_user(ba, (unsigned int *)regs->tpc);
10058+
10059+ if (err)
10060+ break;
10061+
10062+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
10063+ unsigned long addr;
10064+
10065+ if ((ba & 0xFFC00000U) == 0x30800000U)
10066+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
10067+ else
10068+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10069+
10070+ if (test_thread_flag(TIF_32BIT))
10071+ addr &= 0xFFFFFFFFUL;
10072+
10073+ regs->tpc = addr;
10074+ regs->tnpc = addr+4;
10075+ return 2;
10076+ }
10077+ } while (0);
10078+
10079+ do { /* PaX: patched PLT emulation #3 */
10080+ unsigned int sethi, bajmpl, nop;
10081+
10082+ err = get_user(sethi, (unsigned int *)regs->tpc);
10083+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
10084+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
10085+
10086+ if (err)
10087+ break;
10088+
10089+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10090+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
10091+ nop == 0x01000000U)
10092+ {
10093+ unsigned long addr;
10094+
10095+ addr = (sethi & 0x003FFFFFU) << 10;
10096+ regs->u_regs[UREG_G1] = addr;
10097+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
10098+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10099+ else
10100+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10101+
10102+ if (test_thread_flag(TIF_32BIT))
10103+ addr &= 0xFFFFFFFFUL;
10104+
10105+ regs->tpc = addr;
10106+ regs->tnpc = addr+4;
10107+ return 2;
10108+ }
10109+ } while (0);
10110+
10111+ do { /* PaX: patched PLT emulation #4 */
10112+ unsigned int sethi, mov1, call, mov2;
10113+
10114+ err = get_user(sethi, (unsigned int *)regs->tpc);
10115+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
10116+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
10117+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
10118+
10119+ if (err)
10120+ break;
10121+
10122+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10123+ mov1 == 0x8210000FU &&
10124+ (call & 0xC0000000U) == 0x40000000U &&
10125+ mov2 == 0x9E100001U)
10126+ {
10127+ unsigned long addr;
10128+
10129+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
10130+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
10131+
10132+ if (test_thread_flag(TIF_32BIT))
10133+ addr &= 0xFFFFFFFFUL;
10134+
10135+ regs->tpc = addr;
10136+ regs->tnpc = addr+4;
10137+ return 2;
10138+ }
10139+ } while (0);
10140+
10141+ do { /* PaX: patched PLT emulation #5 */
10142+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
10143+
10144+ err = get_user(sethi, (unsigned int *)regs->tpc);
10145+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
10146+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
10147+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
10148+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
10149+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
10150+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
10151+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
10152+
10153+ if (err)
10154+ break;
10155+
10156+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10157+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
10158+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
10159+ (or1 & 0xFFFFE000U) == 0x82106000U &&
10160+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
10161+ sllx == 0x83287020U &&
10162+ jmpl == 0x81C04005U &&
10163+ nop == 0x01000000U)
10164+ {
10165+ unsigned long addr;
10166+
10167+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
10168+ regs->u_regs[UREG_G1] <<= 32;
10169+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
10170+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
10171+ regs->tpc = addr;
10172+ regs->tnpc = addr+4;
10173+ return 2;
10174+ }
10175+ } while (0);
10176+
10177+ do { /* PaX: patched PLT emulation #6 */
10178+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
10179+
10180+ err = get_user(sethi, (unsigned int *)regs->tpc);
10181+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
10182+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
10183+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
10184+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
10185+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
10186+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
10187+
10188+ if (err)
10189+ break;
10190+
10191+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10192+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
10193+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
10194+ sllx == 0x83287020U &&
10195+ (or & 0xFFFFE000U) == 0x8A116000U &&
10196+ jmpl == 0x81C04005U &&
10197+ nop == 0x01000000U)
10198+ {
10199+ unsigned long addr;
10200+
10201+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
10202+ regs->u_regs[UREG_G1] <<= 32;
10203+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
10204+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
10205+ regs->tpc = addr;
10206+ regs->tnpc = addr+4;
10207+ return 2;
10208+ }
10209+ } while (0);
10210+
10211+ do { /* PaX: unpatched PLT emulation step 1 */
10212+ unsigned int sethi, ba, nop;
10213+
10214+ err = get_user(sethi, (unsigned int *)regs->tpc);
10215+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
10216+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
10217+
10218+ if (err)
10219+ break;
10220+
10221+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10222+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
10223+ nop == 0x01000000U)
10224+ {
10225+ unsigned long addr;
10226+ unsigned int save, call;
10227+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
10228+
10229+ if ((ba & 0xFFC00000U) == 0x30800000U)
10230+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
10231+ else
10232+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10233+
10234+ if (test_thread_flag(TIF_32BIT))
10235+ addr &= 0xFFFFFFFFUL;
10236+
10237+ err = get_user(save, (unsigned int *)addr);
10238+ err |= get_user(call, (unsigned int *)(addr+4));
10239+ err |= get_user(nop, (unsigned int *)(addr+8));
10240+ if (err)
10241+ break;
10242+
10243+#ifdef CONFIG_PAX_DLRESOLVE
10244+ if (save == 0x9DE3BFA8U &&
10245+ (call & 0xC0000000U) == 0x40000000U &&
10246+ nop == 0x01000000U)
10247+ {
10248+ struct vm_area_struct *vma;
10249+ unsigned long call_dl_resolve;
10250+
10251+ down_read(&current->mm->mmap_sem);
10252+ call_dl_resolve = current->mm->call_dl_resolve;
10253+ up_read(&current->mm->mmap_sem);
10254+ if (likely(call_dl_resolve))
10255+ goto emulate;
10256+
10257+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
10258+
10259+ down_write(&current->mm->mmap_sem);
10260+ if (current->mm->call_dl_resolve) {
10261+ call_dl_resolve = current->mm->call_dl_resolve;
10262+ up_write(&current->mm->mmap_sem);
10263+ if (vma)
10264+ kmem_cache_free(vm_area_cachep, vma);
10265+ goto emulate;
10266+ }
10267+
10268+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
10269+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
10270+ up_write(&current->mm->mmap_sem);
10271+ if (vma)
10272+ kmem_cache_free(vm_area_cachep, vma);
10273+ return 1;
10274+ }
10275+
10276+ if (pax_insert_vma(vma, call_dl_resolve)) {
10277+ up_write(&current->mm->mmap_sem);
10278+ kmem_cache_free(vm_area_cachep, vma);
10279+ return 1;
10280+ }
10281+
10282+ current->mm->call_dl_resolve = call_dl_resolve;
10283+ up_write(&current->mm->mmap_sem);
10284+
10285+emulate:
10286+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10287+ regs->tpc = call_dl_resolve;
10288+ regs->tnpc = addr+4;
10289+ return 3;
10290+ }
10291+#endif
10292+
10293+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
10294+ if ((save & 0xFFC00000U) == 0x05000000U &&
10295+ (call & 0xFFFFE000U) == 0x85C0A000U &&
10296+ nop == 0x01000000U)
10297+ {
10298+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10299+ regs->u_regs[UREG_G2] = addr + 4;
10300+ addr = (save & 0x003FFFFFU) << 10;
10301+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10302+
10303+ if (test_thread_flag(TIF_32BIT))
10304+ addr &= 0xFFFFFFFFUL;
10305+
10306+ regs->tpc = addr;
10307+ regs->tnpc = addr+4;
10308+ return 3;
10309+ }
10310+
10311+ /* PaX: 64-bit PLT stub */
10312+ err = get_user(sethi1, (unsigned int *)addr);
10313+ err |= get_user(sethi2, (unsigned int *)(addr+4));
10314+ err |= get_user(or1, (unsigned int *)(addr+8));
10315+ err |= get_user(or2, (unsigned int *)(addr+12));
10316+ err |= get_user(sllx, (unsigned int *)(addr+16));
10317+ err |= get_user(add, (unsigned int *)(addr+20));
10318+ err |= get_user(jmpl, (unsigned int *)(addr+24));
10319+ err |= get_user(nop, (unsigned int *)(addr+28));
10320+ if (err)
10321+ break;
10322+
10323+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
10324+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
10325+ (or1 & 0xFFFFE000U) == 0x88112000U &&
10326+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
10327+ sllx == 0x89293020U &&
10328+ add == 0x8A010005U &&
10329+ jmpl == 0x89C14000U &&
10330+ nop == 0x01000000U)
10331+ {
10332+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10333+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
10334+ regs->u_regs[UREG_G4] <<= 32;
10335+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
10336+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
10337+ regs->u_regs[UREG_G4] = addr + 24;
10338+ addr = regs->u_regs[UREG_G5];
10339+ regs->tpc = addr;
10340+ regs->tnpc = addr+4;
10341+ return 3;
10342+ }
10343+ }
10344+ } while (0);
10345+
10346+#ifdef CONFIG_PAX_DLRESOLVE
10347+ do { /* PaX: unpatched PLT emulation step 2 */
10348+ unsigned int save, call, nop;
10349+
10350+ err = get_user(save, (unsigned int *)(regs->tpc-4));
10351+ err |= get_user(call, (unsigned int *)regs->tpc);
10352+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
10353+ if (err)
10354+ break;
10355+
10356+ if (save == 0x9DE3BFA8U &&
10357+ (call & 0xC0000000U) == 0x40000000U &&
10358+ nop == 0x01000000U)
10359+ {
10360+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
10361+
10362+ if (test_thread_flag(TIF_32BIT))
10363+ dl_resolve &= 0xFFFFFFFFUL;
10364+
10365+ regs->u_regs[UREG_RETPC] = regs->tpc;
10366+ regs->tpc = dl_resolve;
10367+ regs->tnpc = dl_resolve+4;
10368+ return 3;
10369+ }
10370+ } while (0);
10371+#endif
10372+
10373+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
10374+ unsigned int sethi, ba, nop;
10375+
10376+ err = get_user(sethi, (unsigned int *)regs->tpc);
10377+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
10378+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
10379+
10380+ if (err)
10381+ break;
10382+
10383+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10384+ (ba & 0xFFF00000U) == 0x30600000U &&
10385+ nop == 0x01000000U)
10386+ {
10387+ unsigned long addr;
10388+
10389+ addr = (sethi & 0x003FFFFFU) << 10;
10390+ regs->u_regs[UREG_G1] = addr;
10391+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10392+
10393+ if (test_thread_flag(TIF_32BIT))
10394+ addr &= 0xFFFFFFFFUL;
10395+
10396+ regs->tpc = addr;
10397+ regs->tnpc = addr+4;
10398+ return 2;
10399+ }
10400+ } while (0);
10401+
10402+#endif
10403+
10404+ return 1;
10405+}
10406+
10407+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
10408+{
10409+ unsigned long i;
10410+
10411+ printk(KERN_ERR "PAX: bytes at PC: ");
10412+ for (i = 0; i < 8; i++) {
10413+ unsigned int c;
10414+ if (get_user(c, (unsigned int *)pc+i))
10415+ printk(KERN_CONT "???????? ");
10416+ else
10417+ printk(KERN_CONT "%08x ", c);
10418+ }
10419+ printk("\n");
10420+}
10421+#endif
10422+
10423 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
10424 {
10425 struct mm_struct *mm = current->mm;
10426@@ -341,6 +804,29 @@ retry:
10427 if (!vma)
10428 goto bad_area;
10429
10430+#ifdef CONFIG_PAX_PAGEEXEC
10431+ /* PaX: detect ITLB misses on non-exec pages */
10432+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
10433+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
10434+ {
10435+ if (address != regs->tpc)
10436+ goto good_area;
10437+
10438+ up_read(&mm->mmap_sem);
10439+ switch (pax_handle_fetch_fault(regs)) {
10440+
10441+#ifdef CONFIG_PAX_EMUPLT
10442+ case 2:
10443+ case 3:
10444+ return;
10445+#endif
10446+
10447+ }
10448+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
10449+ do_group_exit(SIGKILL);
10450+ }
10451+#endif
10452+
10453 /* Pure DTLB misses do not tell us whether the fault causing
10454 * load/store/atomic was a write or not, it only says that there
10455 * was no match. So in such a case we (carefully) read the
10456diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
10457index d2b5944..bd813f2 100644
10458--- a/arch/sparc/mm/hugetlbpage.c
10459+++ b/arch/sparc/mm/hugetlbpage.c
10460@@ -38,7 +38,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
10461
10462 info.flags = 0;
10463 info.length = len;
10464- info.low_limit = TASK_UNMAPPED_BASE;
10465+ info.low_limit = mm->mmap_base;
10466 info.high_limit = min(task_size, VA_EXCLUDE_START);
10467 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
10468 info.align_offset = 0;
10469@@ -47,6 +47,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
10470 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10471 VM_BUG_ON(addr != -ENOMEM);
10472 info.low_limit = VA_EXCLUDE_END;
10473+
10474+#ifdef CONFIG_PAX_RANDMMAP
10475+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10476+ info.low_limit += mm->delta_mmap;
10477+#endif
10478+
10479 info.high_limit = task_size;
10480 addr = vm_unmapped_area(&info);
10481 }
10482@@ -85,6 +91,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10483 VM_BUG_ON(addr != -ENOMEM);
10484 info.flags = 0;
10485 info.low_limit = TASK_UNMAPPED_BASE;
10486+
10487+#ifdef CONFIG_PAX_RANDMMAP
10488+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10489+ info.low_limit += mm->delta_mmap;
10490+#endif
10491+
10492 info.high_limit = STACK_TOP32;
10493 addr = vm_unmapped_area(&info);
10494 }
10495@@ -99,6 +111,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
10496 struct mm_struct *mm = current->mm;
10497 struct vm_area_struct *vma;
10498 unsigned long task_size = TASK_SIZE;
10499+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
10500
10501 if (test_thread_flag(TIF_32BIT))
10502 task_size = STACK_TOP32;
10503@@ -114,11 +127,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
10504 return addr;
10505 }
10506
10507+#ifdef CONFIG_PAX_RANDMMAP
10508+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10509+#endif
10510+
10511 if (addr) {
10512 addr = ALIGN(addr, HPAGE_SIZE);
10513 vma = find_vma(mm, addr);
10514- if (task_size - len >= addr &&
10515- (!vma || addr + len <= vma->vm_start))
10516+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10517 return addr;
10518 }
10519 if (mm->get_unmapped_area == arch_get_unmapped_area)
10520diff --git a/arch/sparc/mm/tlb.c b/arch/sparc/mm/tlb.c
10521index ba6ae7f..272aa4f 100644
10522--- a/arch/sparc/mm/tlb.c
10523+++ b/arch/sparc/mm/tlb.c
10524@@ -24,11 +24,17 @@ static DEFINE_PER_CPU(struct tlb_batch, tlb_batch);
10525 void flush_tlb_pending(void)
10526 {
10527 struct tlb_batch *tb = &get_cpu_var(tlb_batch);
10528+ struct mm_struct *mm = tb->mm;
10529
10530- if (tb->tlb_nr) {
10531- flush_tsb_user(tb);
10532+ if (!tb->tlb_nr)
10533+ goto out;
10534
10535- if (CTX_VALID(tb->mm->context)) {
10536+ flush_tsb_user(tb);
10537+
10538+ if (CTX_VALID(mm->context)) {
10539+ if (tb->tlb_nr == 1) {
10540+ global_flush_tlb_page(mm, tb->vaddrs[0]);
10541+ } else {
10542 #ifdef CONFIG_SMP
10543 smp_flush_tlb_pending(tb->mm, tb->tlb_nr,
10544 &tb->vaddrs[0]);
10545@@ -37,12 +43,30 @@ void flush_tlb_pending(void)
10546 tb->tlb_nr, &tb->vaddrs[0]);
10547 #endif
10548 }
10549- tb->tlb_nr = 0;
10550 }
10551
10552+ tb->tlb_nr = 0;
10553+
10554+out:
10555 put_cpu_var(tlb_batch);
10556 }
10557
10558+void arch_enter_lazy_mmu_mode(void)
10559+{
10560+ struct tlb_batch *tb = &__get_cpu_var(tlb_batch);
10561+
10562+ tb->active = 1;
10563+}
10564+
10565+void arch_leave_lazy_mmu_mode(void)
10566+{
10567+ struct tlb_batch *tb = &__get_cpu_var(tlb_batch);
10568+
10569+ if (tb->tlb_nr)
10570+ flush_tlb_pending();
10571+ tb->active = 0;
10572+}
10573+
10574 static void tlb_batch_add_one(struct mm_struct *mm, unsigned long vaddr,
10575 bool exec)
10576 {
10577@@ -60,6 +84,12 @@ static void tlb_batch_add_one(struct mm_struct *mm, unsigned long vaddr,
10578 nr = 0;
10579 }
10580
10581+ if (!tb->active) {
10582+ global_flush_tlb_page(mm, vaddr);
10583+ flush_tsb_user_page(mm, vaddr);
10584+ return;
10585+ }
10586+
10587 if (nr == 0)
10588 tb->mm = mm;
10589
10590diff --git a/arch/sparc/mm/tsb.c b/arch/sparc/mm/tsb.c
10591index 428982b..2cc3bce 100644
10592--- a/arch/sparc/mm/tsb.c
10593+++ b/arch/sparc/mm/tsb.c
10594@@ -7,11 +7,10 @@
10595 #include <linux/preempt.h>
10596 #include <linux/slab.h>
10597 #include <asm/page.h>
10598-#include <asm/tlbflush.h>
10599-#include <asm/tlb.h>
10600-#include <asm/mmu_context.h>
10601 #include <asm/pgtable.h>
10602+#include <asm/mmu_context.h>
10603 #include <asm/tsb.h>
10604+#include <asm/tlb.h>
10605 #include <asm/oplib.h>
10606
10607 extern struct tsb swapper_tsb[KERNEL_TSB_NENTRIES];
10608@@ -46,23 +45,27 @@ void flush_tsb_kernel_range(unsigned long start, unsigned long end)
10609 }
10610 }
10611
10612+static void __flush_tsb_one_entry(unsigned long tsb, unsigned long v,
10613+ unsigned long hash_shift,
10614+ unsigned long nentries)
10615+{
10616+ unsigned long tag, ent, hash;
10617+
10618+ v &= ~0x1UL;
10619+ hash = tsb_hash(v, hash_shift, nentries);
10620+ ent = tsb + (hash * sizeof(struct tsb));
10621+ tag = (v >> 22UL);
10622+
10623+ tsb_flush(ent, tag);
10624+}
10625+
10626 static void __flush_tsb_one(struct tlb_batch *tb, unsigned long hash_shift,
10627 unsigned long tsb, unsigned long nentries)
10628 {
10629 unsigned long i;
10630
10631- for (i = 0; i < tb->tlb_nr; i++) {
10632- unsigned long v = tb->vaddrs[i];
10633- unsigned long tag, ent, hash;
10634-
10635- v &= ~0x1UL;
10636-
10637- hash = tsb_hash(v, hash_shift, nentries);
10638- ent = tsb + (hash * sizeof(struct tsb));
10639- tag = (v >> 22UL);
10640-
10641- tsb_flush(ent, tag);
10642- }
10643+ for (i = 0; i < tb->tlb_nr; i++)
10644+ __flush_tsb_one_entry(tsb, tb->vaddrs[i], hash_shift, nentries);
10645 }
10646
10647 void flush_tsb_user(struct tlb_batch *tb)
10648@@ -90,6 +93,30 @@ void flush_tsb_user(struct tlb_batch *tb)
10649 spin_unlock_irqrestore(&mm->context.lock, flags);
10650 }
10651
10652+void flush_tsb_user_page(struct mm_struct *mm, unsigned long vaddr)
10653+{
10654+ unsigned long nentries, base, flags;
10655+
10656+ spin_lock_irqsave(&mm->context.lock, flags);
10657+
10658+ base = (unsigned long) mm->context.tsb_block[MM_TSB_BASE].tsb;
10659+ nentries = mm->context.tsb_block[MM_TSB_BASE].tsb_nentries;
10660+ if (tlb_type == cheetah_plus || tlb_type == hypervisor)
10661+ base = __pa(base);
10662+ __flush_tsb_one_entry(base, vaddr, PAGE_SHIFT, nentries);
10663+
10664+#if defined(CONFIG_HUGETLB_PAGE) || defined(CONFIG_TRANSPARENT_HUGEPAGE)
10665+ if (mm->context.tsb_block[MM_TSB_HUGE].tsb) {
10666+ base = (unsigned long) mm->context.tsb_block[MM_TSB_HUGE].tsb;
10667+ nentries = mm->context.tsb_block[MM_TSB_HUGE].tsb_nentries;
10668+ if (tlb_type == cheetah_plus || tlb_type == hypervisor)
10669+ base = __pa(base);
10670+ __flush_tsb_one_entry(base, vaddr, HPAGE_SHIFT, nentries);
10671+ }
10672+#endif
10673+ spin_unlock_irqrestore(&mm->context.lock, flags);
10674+}
10675+
10676 #define HV_PGSZ_IDX_BASE HV_PGSZ_IDX_8K
10677 #define HV_PGSZ_MASK_BASE HV_PGSZ_MASK_8K
10678
10679diff --git a/arch/sparc/mm/ultra.S b/arch/sparc/mm/ultra.S
10680index f8e13d4..432aa0c 100644
10681--- a/arch/sparc/mm/ultra.S
10682+++ b/arch/sparc/mm/ultra.S
10683@@ -53,6 +53,33 @@ __flush_tlb_mm: /* 18 insns */
10684 nop
10685
10686 .align 32
10687+ .globl __flush_tlb_page
10688+__flush_tlb_page: /* 22 insns */
10689+ /* %o0 = context, %o1 = vaddr */
10690+ rdpr %pstate, %g7
10691+ andn %g7, PSTATE_IE, %g2
10692+ wrpr %g2, %pstate
10693+ mov SECONDARY_CONTEXT, %o4
10694+ ldxa [%o4] ASI_DMMU, %g2
10695+ stxa %o0, [%o4] ASI_DMMU
10696+ andcc %o1, 1, %g0
10697+ andn %o1, 1, %o3
10698+ be,pn %icc, 1f
10699+ or %o3, 0x10, %o3
10700+ stxa %g0, [%o3] ASI_IMMU_DEMAP
10701+1: stxa %g0, [%o3] ASI_DMMU_DEMAP
10702+ membar #Sync
10703+ stxa %g2, [%o4] ASI_DMMU
10704+ sethi %hi(KERNBASE), %o4
10705+ flush %o4
10706+ retl
10707+ wrpr %g7, 0x0, %pstate
10708+ nop
10709+ nop
10710+ nop
10711+ nop
10712+
10713+ .align 32
10714 .globl __flush_tlb_pending
10715 __flush_tlb_pending: /* 26 insns */
10716 /* %o0 = context, %o1 = nr, %o2 = vaddrs[] */
10717@@ -203,6 +230,31 @@ __cheetah_flush_tlb_mm: /* 19 insns */
10718 retl
10719 wrpr %g7, 0x0, %pstate
10720
10721+__cheetah_flush_tlb_page: /* 22 insns */
10722+ /* %o0 = context, %o1 = vaddr */
10723+ rdpr %pstate, %g7
10724+ andn %g7, PSTATE_IE, %g2
10725+ wrpr %g2, 0x0, %pstate
10726+ wrpr %g0, 1, %tl
10727+ mov PRIMARY_CONTEXT, %o4
10728+ ldxa [%o4] ASI_DMMU, %g2
10729+ srlx %g2, CTX_PGSZ1_NUC_SHIFT, %o3
10730+ sllx %o3, CTX_PGSZ1_NUC_SHIFT, %o3
10731+ or %o0, %o3, %o0 /* Preserve nucleus page size fields */
10732+ stxa %o0, [%o4] ASI_DMMU
10733+ andcc %o1, 1, %g0
10734+ be,pn %icc, 1f
10735+ andn %o1, 1, %o3
10736+ stxa %g0, [%o3] ASI_IMMU_DEMAP
10737+1: stxa %g0, [%o3] ASI_DMMU_DEMAP
10738+ membar #Sync
10739+ stxa %g2, [%o4] ASI_DMMU
10740+ sethi %hi(KERNBASE), %o4
10741+ flush %o4
10742+ wrpr %g0, 0, %tl
10743+ retl
10744+ wrpr %g7, 0x0, %pstate
10745+
10746 __cheetah_flush_tlb_pending: /* 27 insns */
10747 /* %o0 = context, %o1 = nr, %o2 = vaddrs[] */
10748 rdpr %pstate, %g7
10749@@ -269,6 +321,20 @@ __hypervisor_flush_tlb_mm: /* 10 insns */
10750 retl
10751 nop
10752
10753+__hypervisor_flush_tlb_page: /* 11 insns */
10754+ /* %o0 = context, %o1 = vaddr */
10755+ mov %o0, %g2
10756+ mov %o1, %o0 /* ARG0: vaddr + IMMU-bit */
10757+ mov %g2, %o1 /* ARG1: mmu context */
10758+ mov HV_MMU_ALL, %o2 /* ARG2: flags */
10759+ srlx %o0, PAGE_SHIFT, %o0
10760+ sllx %o0, PAGE_SHIFT, %o0
10761+ ta HV_MMU_UNMAP_ADDR_TRAP
10762+ brnz,pn %o0, __hypervisor_tlb_tl0_error
10763+ mov HV_MMU_UNMAP_ADDR_TRAP, %o1
10764+ retl
10765+ nop
10766+
10767 __hypervisor_flush_tlb_pending: /* 16 insns */
10768 /* %o0 = context, %o1 = nr, %o2 = vaddrs[] */
10769 sllx %o1, 3, %g1
10770@@ -339,6 +405,13 @@ cheetah_patch_cachetlbops:
10771 call tlb_patch_one
10772 mov 19, %o2
10773
10774+ sethi %hi(__flush_tlb_page), %o0
10775+ or %o0, %lo(__flush_tlb_page), %o0
10776+ sethi %hi(__cheetah_flush_tlb_page), %o1
10777+ or %o1, %lo(__cheetah_flush_tlb_page), %o1
10778+ call tlb_patch_one
10779+ mov 22, %o2
10780+
10781 sethi %hi(__flush_tlb_pending), %o0
10782 or %o0, %lo(__flush_tlb_pending), %o0
10783 sethi %hi(__cheetah_flush_tlb_pending), %o1
10784@@ -397,10 +470,9 @@ xcall_flush_tlb_mm: /* 21 insns */
10785 nop
10786 nop
10787
10788- .globl xcall_flush_tlb_pending
10789-xcall_flush_tlb_pending: /* 21 insns */
10790- /* %g5=context, %g1=nr, %g7=vaddrs[] */
10791- sllx %g1, 3, %g1
10792+ .globl xcall_flush_tlb_page
10793+xcall_flush_tlb_page: /* 17 insns */
10794+ /* %g5=context, %g1=vaddr */
10795 mov PRIMARY_CONTEXT, %g4
10796 ldxa [%g4] ASI_DMMU, %g2
10797 srlx %g2, CTX_PGSZ1_NUC_SHIFT, %g4
10798@@ -408,20 +480,16 @@ xcall_flush_tlb_pending: /* 21 insns */
10799 or %g5, %g4, %g5
10800 mov PRIMARY_CONTEXT, %g4
10801 stxa %g5, [%g4] ASI_DMMU
10802-1: sub %g1, (1 << 3), %g1
10803- ldx [%g7 + %g1], %g5
10804- andcc %g5, 0x1, %g0
10805+ andcc %g1, 0x1, %g0
10806 be,pn %icc, 2f
10807-
10808- andn %g5, 0x1, %g5
10809+ andn %g1, 0x1, %g5
10810 stxa %g0, [%g5] ASI_IMMU_DEMAP
10811 2: stxa %g0, [%g5] ASI_DMMU_DEMAP
10812 membar #Sync
10813- brnz,pt %g1, 1b
10814- nop
10815 stxa %g2, [%g4] ASI_DMMU
10816 retry
10817 nop
10818+ nop
10819
10820 .globl xcall_flush_tlb_kernel_range
10821 xcall_flush_tlb_kernel_range: /* 25 insns */
10822@@ -656,15 +724,13 @@ __hypervisor_xcall_flush_tlb_mm: /* 21 insns */
10823 membar #Sync
10824 retry
10825
10826- .globl __hypervisor_xcall_flush_tlb_pending
10827-__hypervisor_xcall_flush_tlb_pending: /* 21 insns */
10828- /* %g5=ctx, %g1=nr, %g7=vaddrs[], %g2,%g3,%g4,g6=scratch */
10829- sllx %g1, 3, %g1
10830+ .globl __hypervisor_xcall_flush_tlb_page
10831+__hypervisor_xcall_flush_tlb_page: /* 17 insns */
10832+ /* %g5=ctx, %g1=vaddr */
10833 mov %o0, %g2
10834 mov %o1, %g3
10835 mov %o2, %g4
10836-1: sub %g1, (1 << 3), %g1
10837- ldx [%g7 + %g1], %o0 /* ARG0: virtual address */
10838+ mov %g1, %o0 /* ARG0: virtual address */
10839 mov %g5, %o1 /* ARG1: mmu context */
10840 mov HV_MMU_ALL, %o2 /* ARG2: flags */
10841 srlx %o0, PAGE_SHIFT, %o0
10842@@ -673,8 +739,6 @@ __hypervisor_xcall_flush_tlb_pending: /* 21 insns */
10843 mov HV_MMU_UNMAP_ADDR_TRAP, %g6
10844 brnz,a,pn %o0, __hypervisor_tlb_xcall_error
10845 mov %o0, %g5
10846- brnz,pt %g1, 1b
10847- nop
10848 mov %g2, %o0
10849 mov %g3, %o1
10850 mov %g4, %o2
10851@@ -757,6 +821,13 @@ hypervisor_patch_cachetlbops:
10852 call tlb_patch_one
10853 mov 10, %o2
10854
10855+ sethi %hi(__flush_tlb_page), %o0
10856+ or %o0, %lo(__flush_tlb_page), %o0
10857+ sethi %hi(__hypervisor_flush_tlb_page), %o1
10858+ or %o1, %lo(__hypervisor_flush_tlb_page), %o1
10859+ call tlb_patch_one
10860+ mov 11, %o2
10861+
10862 sethi %hi(__flush_tlb_pending), %o0
10863 or %o0, %lo(__flush_tlb_pending), %o0
10864 sethi %hi(__hypervisor_flush_tlb_pending), %o1
10865@@ -788,12 +859,12 @@ hypervisor_patch_cachetlbops:
10866 call tlb_patch_one
10867 mov 21, %o2
10868
10869- sethi %hi(xcall_flush_tlb_pending), %o0
10870- or %o0, %lo(xcall_flush_tlb_pending), %o0
10871- sethi %hi(__hypervisor_xcall_flush_tlb_pending), %o1
10872- or %o1, %lo(__hypervisor_xcall_flush_tlb_pending), %o1
10873+ sethi %hi(xcall_flush_tlb_page), %o0
10874+ or %o0, %lo(xcall_flush_tlb_page), %o0
10875+ sethi %hi(__hypervisor_xcall_flush_tlb_page), %o1
10876+ or %o1, %lo(__hypervisor_xcall_flush_tlb_page), %o1
10877 call tlb_patch_one
10878- mov 21, %o2
10879+ mov 17, %o2
10880
10881 sethi %hi(xcall_flush_tlb_kernel_range), %o0
10882 or %o0, %lo(xcall_flush_tlb_kernel_range), %o0
10883diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
10884index f4500c6..889656c 100644
10885--- a/arch/tile/include/asm/atomic_64.h
10886+++ b/arch/tile/include/asm/atomic_64.h
10887@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
10888
10889 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10890
10891+#define atomic64_read_unchecked(v) atomic64_read(v)
10892+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
10893+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
10894+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
10895+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
10896+#define atomic64_inc_unchecked(v) atomic64_inc(v)
10897+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
10898+#define atomic64_dec_unchecked(v) atomic64_dec(v)
10899+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
10900+
10901 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
10902 #define smp_mb__before_atomic_dec() smp_mb()
10903 #define smp_mb__after_atomic_dec() smp_mb()
10904diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
10905index a9a5299..0fce79e 100644
10906--- a/arch/tile/include/asm/cache.h
10907+++ b/arch/tile/include/asm/cache.h
10908@@ -15,11 +15,12 @@
10909 #ifndef _ASM_TILE_CACHE_H
10910 #define _ASM_TILE_CACHE_H
10911
10912+#include <linux/const.h>
10913 #include <arch/chip.h>
10914
10915 /* bytes per L1 data cache line */
10916 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
10917-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10918+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10919
10920 /* bytes per L2 cache line */
10921 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
10922diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
10923index 9ab078a..d6635c2 100644
10924--- a/arch/tile/include/asm/uaccess.h
10925+++ b/arch/tile/include/asm/uaccess.h
10926@@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
10927 const void __user *from,
10928 unsigned long n)
10929 {
10930- int sz = __compiletime_object_size(to);
10931+ size_t sz = __compiletime_object_size(to);
10932
10933- if (likely(sz == -1 || sz >= n))
10934+ if (likely(sz == (size_t)-1 || sz >= n))
10935 n = _copy_from_user(to, from, n);
10936 else
10937 copy_from_user_overflow();
10938diff --git a/arch/um/Makefile b/arch/um/Makefile
10939index 133f7de..1d6f2f1 100644
10940--- a/arch/um/Makefile
10941+++ b/arch/um/Makefile
10942@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
10943 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
10944 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
10945
10946+ifdef CONSTIFY_PLUGIN
10947+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10948+endif
10949+
10950 #This will adjust *FLAGS accordingly to the platform.
10951 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
10952
10953diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
10954index 19e1bdd..3665b77 100644
10955--- a/arch/um/include/asm/cache.h
10956+++ b/arch/um/include/asm/cache.h
10957@@ -1,6 +1,7 @@
10958 #ifndef __UM_CACHE_H
10959 #define __UM_CACHE_H
10960
10961+#include <linux/const.h>
10962
10963 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
10964 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10965@@ -12,6 +13,6 @@
10966 # define L1_CACHE_SHIFT 5
10967 #endif
10968
10969-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10970+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10971
10972 #endif
10973diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
10974index 2e0a6b1..a64d0f5 100644
10975--- a/arch/um/include/asm/kmap_types.h
10976+++ b/arch/um/include/asm/kmap_types.h
10977@@ -8,6 +8,6 @@
10978
10979 /* No more #include "asm/arch/kmap_types.h" ! */
10980
10981-#define KM_TYPE_NR 14
10982+#define KM_TYPE_NR 15
10983
10984 #endif
10985diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
10986index 5ff53d9..5850cdf 100644
10987--- a/arch/um/include/asm/page.h
10988+++ b/arch/um/include/asm/page.h
10989@@ -14,6 +14,9 @@
10990 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
10991 #define PAGE_MASK (~(PAGE_SIZE-1))
10992
10993+#define ktla_ktva(addr) (addr)
10994+#define ktva_ktla(addr) (addr)
10995+
10996 #ifndef __ASSEMBLY__
10997
10998 struct page;
10999diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
11000index 0032f92..cd151e0 100644
11001--- a/arch/um/include/asm/pgtable-3level.h
11002+++ b/arch/um/include/asm/pgtable-3level.h
11003@@ -58,6 +58,7 @@
11004 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
11005 #define pud_populate(mm, pud, pmd) \
11006 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
11007+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
11008
11009 #ifdef CONFIG_64BIT
11010 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
11011diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
11012index b462b13..e7a19aa 100644
11013--- a/arch/um/kernel/process.c
11014+++ b/arch/um/kernel/process.c
11015@@ -386,22 +386,6 @@ int singlestepping(void * t)
11016 return 2;
11017 }
11018
11019-/*
11020- * Only x86 and x86_64 have an arch_align_stack().
11021- * All other arches have "#define arch_align_stack(x) (x)"
11022- * in their asm/system.h
11023- * As this is included in UML from asm-um/system-generic.h,
11024- * we can use it to behave as the subarch does.
11025- */
11026-#ifndef arch_align_stack
11027-unsigned long arch_align_stack(unsigned long sp)
11028-{
11029- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
11030- sp -= get_random_int() % 8192;
11031- return sp & ~0xf;
11032-}
11033-#endif
11034-
11035 unsigned long get_wchan(struct task_struct *p)
11036 {
11037 unsigned long stack_page, sp, ip;
11038diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
11039index ad8f795..2c7eec6 100644
11040--- a/arch/unicore32/include/asm/cache.h
11041+++ b/arch/unicore32/include/asm/cache.h
11042@@ -12,8 +12,10 @@
11043 #ifndef __UNICORE_CACHE_H__
11044 #define __UNICORE_CACHE_H__
11045
11046-#define L1_CACHE_SHIFT (5)
11047-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11048+#include <linux/const.h>
11049+
11050+#define L1_CACHE_SHIFT 5
11051+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11052
11053 /*
11054 * Memory returned by kmalloc() may be used for DMA, so we must make
11055diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
11056index 0694d09..58ea1a1 100644
11057--- a/arch/x86/Kconfig
11058+++ b/arch/x86/Kconfig
11059@@ -238,7 +238,7 @@ config X86_HT
11060
11061 config X86_32_LAZY_GS
11062 def_bool y
11063- depends on X86_32 && !CC_STACKPROTECTOR
11064+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
11065
11066 config ARCH_HWEIGHT_CFLAGS
11067 string
11068@@ -1031,6 +1031,7 @@ config MICROCODE_OLD_INTERFACE
11069
11070 config X86_MSR
11071 tristate "/dev/cpu/*/msr - Model-specific register support"
11072+ depends on !GRKERNSEC_KMEM
11073 ---help---
11074 This device gives privileged processes access to the x86
11075 Model-Specific Registers (MSRs). It is a character device with
11076@@ -1054,7 +1055,7 @@ choice
11077
11078 config NOHIGHMEM
11079 bool "off"
11080- depends on !X86_NUMAQ
11081+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11082 ---help---
11083 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
11084 However, the address space of 32-bit x86 processors is only 4
11085@@ -1091,7 +1092,7 @@ config NOHIGHMEM
11086
11087 config HIGHMEM4G
11088 bool "4GB"
11089- depends on !X86_NUMAQ
11090+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11091 ---help---
11092 Select this if you have a 32-bit processor and between 1 and 4
11093 gigabytes of physical RAM.
11094@@ -1145,7 +1146,7 @@ config PAGE_OFFSET
11095 hex
11096 default 0xB0000000 if VMSPLIT_3G_OPT
11097 default 0x80000000 if VMSPLIT_2G
11098- default 0x78000000 if VMSPLIT_2G_OPT
11099+ default 0x70000000 if VMSPLIT_2G_OPT
11100 default 0x40000000 if VMSPLIT_1G
11101 default 0xC0000000
11102 depends on X86_32
11103@@ -1542,6 +1543,7 @@ config SECCOMP
11104
11105 config CC_STACKPROTECTOR
11106 bool "Enable -fstack-protector buffer overflow detection"
11107+ depends on X86_64 || !PAX_MEMORY_UDEREF
11108 ---help---
11109 This option turns on the -fstack-protector GCC feature. This
11110 feature puts, at the beginning of functions, a canary value on
11111@@ -1662,6 +1664,8 @@ config X86_NEED_RELOCS
11112 config PHYSICAL_ALIGN
11113 hex "Alignment value to which kernel should be aligned" if X86_32
11114 default "0x1000000"
11115+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
11116+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
11117 range 0x2000 0x1000000
11118 ---help---
11119 This value puts the alignment restrictions on physical address
11120@@ -1737,9 +1741,10 @@ config DEBUG_HOTPLUG_CPU0
11121 If unsure, say N.
11122
11123 config COMPAT_VDSO
11124- def_bool y
11125+ def_bool n
11126 prompt "Compat VDSO support"
11127 depends on X86_32 || IA32_EMULATION
11128+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
11129 ---help---
11130 Map the 32-bit VDSO to the predictable old-style address too.
11131
11132diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
11133index c026cca..14657ae 100644
11134--- a/arch/x86/Kconfig.cpu
11135+++ b/arch/x86/Kconfig.cpu
11136@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
11137
11138 config X86_F00F_BUG
11139 def_bool y
11140- depends on M586MMX || M586TSC || M586 || M486
11141+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
11142
11143 config X86_INVD_BUG
11144 def_bool y
11145@@ -327,7 +327,7 @@ config X86_INVD_BUG
11146
11147 config X86_ALIGNMENT_16
11148 def_bool y
11149- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11150+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11151
11152 config X86_INTEL_USERCOPY
11153 def_bool y
11154@@ -373,7 +373,7 @@ config X86_CMPXCHG64
11155 # generates cmov.
11156 config X86_CMOV
11157 def_bool y
11158- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11159+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11160
11161 config X86_MINIMUM_CPU_FAMILY
11162 int
11163diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
11164index b322f12..652d0d9 100644
11165--- a/arch/x86/Kconfig.debug
11166+++ b/arch/x86/Kconfig.debug
11167@@ -84,7 +84,7 @@ config X86_PTDUMP
11168 config DEBUG_RODATA
11169 bool "Write protect kernel read-only data structures"
11170 default y
11171- depends on DEBUG_KERNEL
11172+ depends on DEBUG_KERNEL && BROKEN
11173 ---help---
11174 Mark the kernel read-only data as write-protected in the pagetables,
11175 in order to catch accidental (and incorrect) writes to such const
11176@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
11177
11178 config DEBUG_SET_MODULE_RONX
11179 bool "Set loadable kernel module data as NX and text as RO"
11180- depends on MODULES
11181+ depends on MODULES && BROKEN
11182 ---help---
11183 This option helps catch unintended modifications to loadable
11184 kernel module's text and read-only data. It also prevents execution
11185@@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
11186
11187 config DEBUG_STRICT_USER_COPY_CHECKS
11188 bool "Strict copy size checks"
11189- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
11190+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
11191 ---help---
11192 Enabling this option turns a certain set of sanity checks for user
11193 copy operations into compile time failures.
11194diff --git a/arch/x86/Makefile b/arch/x86/Makefile
11195index e71fc42..7829607 100644
11196--- a/arch/x86/Makefile
11197+++ b/arch/x86/Makefile
11198@@ -50,6 +50,7 @@ else
11199 UTS_MACHINE := x86_64
11200 CHECKFLAGS += -D__x86_64__ -m64
11201
11202+ biarch := $(call cc-option,-m64)
11203 KBUILD_AFLAGS += -m64
11204 KBUILD_CFLAGS += -m64
11205
11206@@ -230,3 +231,12 @@ define archhelp
11207 echo ' FDARGS="..." arguments for the booted kernel'
11208 echo ' FDINITRD=file initrd for the booted kernel'
11209 endef
11210+
11211+define OLD_LD
11212+
11213+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
11214+*** Please upgrade your binutils to 2.18 or newer
11215+endef
11216+
11217+archprepare:
11218+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
11219diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
11220index 379814b..add62ce 100644
11221--- a/arch/x86/boot/Makefile
11222+++ b/arch/x86/boot/Makefile
11223@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
11224 $(call cc-option, -fno-stack-protector) \
11225 $(call cc-option, -mpreferred-stack-boundary=2)
11226 KBUILD_CFLAGS += $(call cc-option, -m32)
11227+ifdef CONSTIFY_PLUGIN
11228+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11229+endif
11230 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11231 GCOV_PROFILE := n
11232
11233diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
11234index 878e4b9..20537ab 100644
11235--- a/arch/x86/boot/bitops.h
11236+++ b/arch/x86/boot/bitops.h
11237@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11238 u8 v;
11239 const u32 *p = (const u32 *)addr;
11240
11241- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11242+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11243 return v;
11244 }
11245
11246@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11247
11248 static inline void set_bit(int nr, void *addr)
11249 {
11250- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11251+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11252 }
11253
11254 #endif /* BOOT_BITOPS_H */
11255diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
11256index 18997e5..83d9c67 100644
11257--- a/arch/x86/boot/boot.h
11258+++ b/arch/x86/boot/boot.h
11259@@ -85,7 +85,7 @@ static inline void io_delay(void)
11260 static inline u16 ds(void)
11261 {
11262 u16 seg;
11263- asm("movw %%ds,%0" : "=rm" (seg));
11264+ asm volatile("movw %%ds,%0" : "=rm" (seg));
11265 return seg;
11266 }
11267
11268@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
11269 static inline int memcmp(const void *s1, const void *s2, size_t len)
11270 {
11271 u8 diff;
11272- asm("repe; cmpsb; setnz %0"
11273+ asm volatile("repe; cmpsb; setnz %0"
11274 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
11275 return diff;
11276 }
11277diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
11278index 5ef205c..342191d 100644
11279--- a/arch/x86/boot/compressed/Makefile
11280+++ b/arch/x86/boot/compressed/Makefile
11281@@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
11282 KBUILD_CFLAGS += $(cflags-y)
11283 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
11284 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
11285+ifdef CONSTIFY_PLUGIN
11286+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11287+endif
11288
11289 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11290 GCOV_PROFILE := n
11291diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
11292index c205035..5853587 100644
11293--- a/arch/x86/boot/compressed/eboot.c
11294+++ b/arch/x86/boot/compressed/eboot.c
11295@@ -150,7 +150,6 @@ again:
11296 *addr = max_addr;
11297 }
11298
11299-free_pool:
11300 efi_call_phys1(sys_table->boottime->free_pool, map);
11301
11302 fail:
11303@@ -214,7 +213,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
11304 if (i == map_size / desc_size)
11305 status = EFI_NOT_FOUND;
11306
11307-free_pool:
11308 efi_call_phys1(sys_table->boottime->free_pool, map);
11309 fail:
11310 return status;
11311diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
11312index 1e3184f..0d11e2e 100644
11313--- a/arch/x86/boot/compressed/head_32.S
11314+++ b/arch/x86/boot/compressed/head_32.S
11315@@ -118,7 +118,7 @@ preferred_addr:
11316 notl %eax
11317 andl %eax, %ebx
11318 #else
11319- movl $LOAD_PHYSICAL_ADDR, %ebx
11320+ movl $____LOAD_PHYSICAL_ADDR, %ebx
11321 #endif
11322
11323 /* Target address to relocate to for decompression */
11324@@ -204,7 +204,7 @@ relocated:
11325 * and where it was actually loaded.
11326 */
11327 movl %ebp, %ebx
11328- subl $LOAD_PHYSICAL_ADDR, %ebx
11329+ subl $____LOAD_PHYSICAL_ADDR, %ebx
11330 jz 2f /* Nothing to be done if loaded at compiled addr. */
11331 /*
11332 * Process relocations.
11333@@ -212,8 +212,7 @@ relocated:
11334
11335 1: subl $4, %edi
11336 movl (%edi), %ecx
11337- testl %ecx, %ecx
11338- jz 2f
11339+ jecxz 2f
11340 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
11341 jmp 1b
11342 2:
11343diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
11344index f5d1aaa..cce11dc 100644
11345--- a/arch/x86/boot/compressed/head_64.S
11346+++ b/arch/x86/boot/compressed/head_64.S
11347@@ -91,7 +91,7 @@ ENTRY(startup_32)
11348 notl %eax
11349 andl %eax, %ebx
11350 #else
11351- movl $LOAD_PHYSICAL_ADDR, %ebx
11352+ movl $____LOAD_PHYSICAL_ADDR, %ebx
11353 #endif
11354
11355 /* Target address to relocate to for decompression */
11356@@ -273,7 +273,7 @@ preferred_addr:
11357 notq %rax
11358 andq %rax, %rbp
11359 #else
11360- movq $LOAD_PHYSICAL_ADDR, %rbp
11361+ movq $____LOAD_PHYSICAL_ADDR, %rbp
11362 #endif
11363
11364 /* Target address to relocate to for decompression */
11365diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
11366index 88f7ff6..ed695dd 100644
11367--- a/arch/x86/boot/compressed/misc.c
11368+++ b/arch/x86/boot/compressed/misc.c
11369@@ -303,7 +303,7 @@ static void parse_elf(void *output)
11370 case PT_LOAD:
11371 #ifdef CONFIG_RELOCATABLE
11372 dest = output;
11373- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
11374+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
11375 #else
11376 dest = (void *)(phdr->p_paddr);
11377 #endif
11378@@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
11379 error("Destination address too large");
11380 #endif
11381 #ifndef CONFIG_RELOCATABLE
11382- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
11383+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
11384 error("Wrong destination address");
11385 #endif
11386
11387diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
11388index 4d3ff03..e4972ff 100644
11389--- a/arch/x86/boot/cpucheck.c
11390+++ b/arch/x86/boot/cpucheck.c
11391@@ -74,7 +74,7 @@ static int has_fpu(void)
11392 u16 fcw = -1, fsw = -1;
11393 u32 cr0;
11394
11395- asm("movl %%cr0,%0" : "=r" (cr0));
11396+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
11397 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
11398 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
11399 asm volatile("movl %0,%%cr0" : : "r" (cr0));
11400@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
11401 {
11402 u32 f0, f1;
11403
11404- asm("pushfl ; "
11405+ asm volatile("pushfl ; "
11406 "pushfl ; "
11407 "popl %0 ; "
11408 "movl %0,%1 ; "
11409@@ -115,7 +115,7 @@ static void get_flags(void)
11410 set_bit(X86_FEATURE_FPU, cpu.flags);
11411
11412 if (has_eflag(X86_EFLAGS_ID)) {
11413- asm("cpuid"
11414+ asm volatile("cpuid"
11415 : "=a" (max_intel_level),
11416 "=b" (cpu_vendor[0]),
11417 "=d" (cpu_vendor[1]),
11418@@ -124,7 +124,7 @@ static void get_flags(void)
11419
11420 if (max_intel_level >= 0x00000001 &&
11421 max_intel_level <= 0x0000ffff) {
11422- asm("cpuid"
11423+ asm volatile("cpuid"
11424 : "=a" (tfms),
11425 "=c" (cpu.flags[4]),
11426 "=d" (cpu.flags[0])
11427@@ -136,7 +136,7 @@ static void get_flags(void)
11428 cpu.model += ((tfms >> 16) & 0xf) << 4;
11429 }
11430
11431- asm("cpuid"
11432+ asm volatile("cpuid"
11433 : "=a" (max_amd_level)
11434 : "a" (0x80000000)
11435 : "ebx", "ecx", "edx");
11436@@ -144,7 +144,7 @@ static void get_flags(void)
11437 if (max_amd_level >= 0x80000001 &&
11438 max_amd_level <= 0x8000ffff) {
11439 u32 eax = 0x80000001;
11440- asm("cpuid"
11441+ asm volatile("cpuid"
11442 : "+a" (eax),
11443 "=c" (cpu.flags[6]),
11444 "=d" (cpu.flags[1])
11445@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
11446 u32 ecx = MSR_K7_HWCR;
11447 u32 eax, edx;
11448
11449- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11450+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11451 eax &= ~(1 << 15);
11452- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11453+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11454
11455 get_flags(); /* Make sure it really did something */
11456 err = check_flags();
11457@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
11458 u32 ecx = MSR_VIA_FCR;
11459 u32 eax, edx;
11460
11461- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11462+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11463 eax |= (1<<1)|(1<<7);
11464- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11465+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11466
11467 set_bit(X86_FEATURE_CX8, cpu.flags);
11468 err = check_flags();
11469@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
11470 u32 eax, edx;
11471 u32 level = 1;
11472
11473- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11474- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
11475- asm("cpuid"
11476+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11477+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
11478+ asm volatile("cpuid"
11479 : "+a" (level), "=d" (cpu.flags[0])
11480 : : "ecx", "ebx");
11481- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11482+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11483
11484 err = check_flags();
11485 }
11486diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
11487index 944ce59..87ee37a 100644
11488--- a/arch/x86/boot/header.S
11489+++ b/arch/x86/boot/header.S
11490@@ -401,10 +401,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
11491 # single linked list of
11492 # struct setup_data
11493
11494-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
11495+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
11496
11497 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
11498+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
11499+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
11500+#else
11501 #define VO_INIT_SIZE (VO__end - VO__text)
11502+#endif
11503 #if ZO_INIT_SIZE > VO_INIT_SIZE
11504 #define INIT_SIZE ZO_INIT_SIZE
11505 #else
11506diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
11507index db75d07..8e6d0af 100644
11508--- a/arch/x86/boot/memory.c
11509+++ b/arch/x86/boot/memory.c
11510@@ -19,7 +19,7 @@
11511
11512 static int detect_memory_e820(void)
11513 {
11514- int count = 0;
11515+ unsigned int count = 0;
11516 struct biosregs ireg, oreg;
11517 struct e820entry *desc = boot_params.e820_map;
11518 static struct e820entry buf; /* static so it is zeroed */
11519diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
11520index 11e8c6e..fdbb1ed 100644
11521--- a/arch/x86/boot/video-vesa.c
11522+++ b/arch/x86/boot/video-vesa.c
11523@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
11524
11525 boot_params.screen_info.vesapm_seg = oreg.es;
11526 boot_params.screen_info.vesapm_off = oreg.di;
11527+ boot_params.screen_info.vesapm_size = oreg.cx;
11528 }
11529
11530 /*
11531diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
11532index 43eda28..5ab5fdb 100644
11533--- a/arch/x86/boot/video.c
11534+++ b/arch/x86/boot/video.c
11535@@ -96,7 +96,7 @@ static void store_mode_params(void)
11536 static unsigned int get_entry(void)
11537 {
11538 char entry_buf[4];
11539- int i, len = 0;
11540+ unsigned int i, len = 0;
11541 int key;
11542 unsigned int v;
11543
11544diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
11545index 5b577d5..3c1fed4 100644
11546--- a/arch/x86/crypto/aes-x86_64-asm_64.S
11547+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
11548@@ -8,6 +8,8 @@
11549 * including this sentence is retained in full.
11550 */
11551
11552+#include <asm/alternative-asm.h>
11553+
11554 .extern crypto_ft_tab
11555 .extern crypto_it_tab
11556 .extern crypto_fl_tab
11557@@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
11558 je B192; \
11559 leaq 32(r9),r9;
11560
11561+#define ret pax_force_retaddr 0, 1; ret
11562+
11563 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
11564 movq r1,r2; \
11565 movq r3,r4; \
11566diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
11567index 3470624..201259d 100644
11568--- a/arch/x86/crypto/aesni-intel_asm.S
11569+++ b/arch/x86/crypto/aesni-intel_asm.S
11570@@ -31,6 +31,7 @@
11571
11572 #include <linux/linkage.h>
11573 #include <asm/inst.h>
11574+#include <asm/alternative-asm.h>
11575
11576 #ifdef __x86_64__
11577 .data
11578@@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
11579 pop %r14
11580 pop %r13
11581 pop %r12
11582+ pax_force_retaddr 0, 1
11583 ret
11584+ENDPROC(aesni_gcm_dec)
11585
11586
11587 /*****************************************************************************
11588@@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
11589 pop %r14
11590 pop %r13
11591 pop %r12
11592+ pax_force_retaddr 0, 1
11593 ret
11594+ENDPROC(aesni_gcm_enc)
11595
11596 #endif
11597
11598@@ -1714,6 +1719,7 @@ _key_expansion_256a:
11599 pxor %xmm1, %xmm0
11600 movaps %xmm0, (TKEYP)
11601 add $0x10, TKEYP
11602+ pax_force_retaddr_bts
11603 ret
11604
11605 .align 4
11606@@ -1738,6 +1744,7 @@ _key_expansion_192a:
11607 shufps $0b01001110, %xmm2, %xmm1
11608 movaps %xmm1, 0x10(TKEYP)
11609 add $0x20, TKEYP
11610+ pax_force_retaddr_bts
11611 ret
11612
11613 .align 4
11614@@ -1757,6 +1764,7 @@ _key_expansion_192b:
11615
11616 movaps %xmm0, (TKEYP)
11617 add $0x10, TKEYP
11618+ pax_force_retaddr_bts
11619 ret
11620
11621 .align 4
11622@@ -1769,6 +1777,7 @@ _key_expansion_256b:
11623 pxor %xmm1, %xmm2
11624 movaps %xmm2, (TKEYP)
11625 add $0x10, TKEYP
11626+ pax_force_retaddr_bts
11627 ret
11628
11629 /*
11630@@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
11631 #ifndef __x86_64__
11632 popl KEYP
11633 #endif
11634+ pax_force_retaddr 0, 1
11635 ret
11636+ENDPROC(aesni_set_key)
11637
11638 /*
11639 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
11640@@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
11641 popl KLEN
11642 popl KEYP
11643 #endif
11644+ pax_force_retaddr 0, 1
11645 ret
11646+ENDPROC(aesni_enc)
11647
11648 /*
11649 * _aesni_enc1: internal ABI
11650@@ -1959,6 +1972,7 @@ _aesni_enc1:
11651 AESENC KEY STATE
11652 movaps 0x70(TKEYP), KEY
11653 AESENCLAST KEY STATE
11654+ pax_force_retaddr_bts
11655 ret
11656
11657 /*
11658@@ -2067,6 +2081,7 @@ _aesni_enc4:
11659 AESENCLAST KEY STATE2
11660 AESENCLAST KEY STATE3
11661 AESENCLAST KEY STATE4
11662+ pax_force_retaddr_bts
11663 ret
11664
11665 /*
11666@@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
11667 popl KLEN
11668 popl KEYP
11669 #endif
11670+ pax_force_retaddr 0, 1
11671 ret
11672+ENDPROC(aesni_dec)
11673
11674 /*
11675 * _aesni_dec1: internal ABI
11676@@ -2146,6 +2163,7 @@ _aesni_dec1:
11677 AESDEC KEY STATE
11678 movaps 0x70(TKEYP), KEY
11679 AESDECLAST KEY STATE
11680+ pax_force_retaddr_bts
11681 ret
11682
11683 /*
11684@@ -2254,6 +2272,7 @@ _aesni_dec4:
11685 AESDECLAST KEY STATE2
11686 AESDECLAST KEY STATE3
11687 AESDECLAST KEY STATE4
11688+ pax_force_retaddr_bts
11689 ret
11690
11691 /*
11692@@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
11693 popl KEYP
11694 popl LEN
11695 #endif
11696+ pax_force_retaddr 0, 1
11697 ret
11698+ENDPROC(aesni_ecb_enc)
11699
11700 /*
11701 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
11702@@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
11703 popl KEYP
11704 popl LEN
11705 #endif
11706+ pax_force_retaddr 0, 1
11707 ret
11708+ENDPROC(aesni_ecb_dec)
11709
11710 /*
11711 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
11712@@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
11713 popl LEN
11714 popl IVP
11715 #endif
11716+ pax_force_retaddr 0, 1
11717 ret
11718+ENDPROC(aesni_cbc_enc)
11719
11720 /*
11721 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
11722@@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
11723 popl LEN
11724 popl IVP
11725 #endif
11726+ pax_force_retaddr 0, 1
11727 ret
11728+ENDPROC(aesni_cbc_dec)
11729
11730 #ifdef __x86_64__
11731 .align 16
11732@@ -2526,6 +2553,7 @@ _aesni_inc_init:
11733 mov $1, TCTR_LOW
11734 MOVQ_R64_XMM TCTR_LOW INC
11735 MOVQ_R64_XMM CTR TCTR_LOW
11736+ pax_force_retaddr_bts
11737 ret
11738
11739 /*
11740@@ -2554,6 +2582,7 @@ _aesni_inc:
11741 .Linc_low:
11742 movaps CTR, IV
11743 PSHUFB_XMM BSWAP_MASK IV
11744+ pax_force_retaddr_bts
11745 ret
11746
11747 /*
11748@@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
11749 .Lctr_enc_ret:
11750 movups IV, (IVP)
11751 .Lctr_enc_just_ret:
11752+ pax_force_retaddr 0, 1
11753 ret
11754+ENDPROC(aesni_ctr_enc)
11755 #endif
11756diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
11757index 391d245..67f35c2 100644
11758--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
11759+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
11760@@ -20,6 +20,8 @@
11761 *
11762 */
11763
11764+#include <asm/alternative-asm.h>
11765+
11766 .file "blowfish-x86_64-asm.S"
11767 .text
11768
11769@@ -151,9 +153,11 @@ __blowfish_enc_blk:
11770 jnz __enc_xor;
11771
11772 write_block();
11773+ pax_force_retaddr 0, 1
11774 ret;
11775 __enc_xor:
11776 xor_block();
11777+ pax_force_retaddr 0, 1
11778 ret;
11779
11780 .align 8
11781@@ -188,6 +192,7 @@ blowfish_dec_blk:
11782
11783 movq %r11, %rbp;
11784
11785+ pax_force_retaddr 0, 1
11786 ret;
11787
11788 /**********************************************************************
11789@@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
11790
11791 popq %rbx;
11792 popq %rbp;
11793+ pax_force_retaddr 0, 1
11794 ret;
11795
11796 __enc_xor4:
11797@@ -349,6 +355,7 @@ __enc_xor4:
11798
11799 popq %rbx;
11800 popq %rbp;
11801+ pax_force_retaddr 0, 1
11802 ret;
11803
11804 .align 8
11805@@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
11806 popq %rbx;
11807 popq %rbp;
11808
11809+ pax_force_retaddr 0, 1
11810 ret;
11811
11812diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
11813index 0b33743..7a56206 100644
11814--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
11815+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
11816@@ -20,6 +20,8 @@
11817 *
11818 */
11819
11820+#include <asm/alternative-asm.h>
11821+
11822 .file "camellia-x86_64-asm_64.S"
11823 .text
11824
11825@@ -229,12 +231,14 @@ __enc_done:
11826 enc_outunpack(mov, RT1);
11827
11828 movq RRBP, %rbp;
11829+ pax_force_retaddr 0, 1
11830 ret;
11831
11832 __enc_xor:
11833 enc_outunpack(xor, RT1);
11834
11835 movq RRBP, %rbp;
11836+ pax_force_retaddr 0, 1
11837 ret;
11838
11839 .global camellia_dec_blk;
11840@@ -275,6 +279,7 @@ __dec_rounds16:
11841 dec_outunpack();
11842
11843 movq RRBP, %rbp;
11844+ pax_force_retaddr 0, 1
11845 ret;
11846
11847 /**********************************************************************
11848@@ -468,6 +473,7 @@ __enc2_done:
11849
11850 movq RRBP, %rbp;
11851 popq %rbx;
11852+ pax_force_retaddr 0, 1
11853 ret;
11854
11855 __enc2_xor:
11856@@ -475,6 +481,7 @@ __enc2_xor:
11857
11858 movq RRBP, %rbp;
11859 popq %rbx;
11860+ pax_force_retaddr 0, 1
11861 ret;
11862
11863 .global camellia_dec_blk_2way;
11864@@ -517,4 +524,5 @@ __dec2_rounds16:
11865
11866 movq RRBP, %rbp;
11867 movq RXOR, %rbx;
11868+ pax_force_retaddr 0, 1
11869 ret;
11870diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
11871index 15b00ac..2071784 100644
11872--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
11873+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
11874@@ -23,6 +23,8 @@
11875 *
11876 */
11877
11878+#include <asm/alternative-asm.h>
11879+
11880 .file "cast5-avx-x86_64-asm_64.S"
11881
11882 .extern cast_s1
11883@@ -281,6 +283,7 @@ __skip_enc:
11884 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
11885 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
11886
11887+ pax_force_retaddr 0, 1
11888 ret;
11889
11890 .align 16
11891@@ -353,6 +356,7 @@ __dec_tail:
11892 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
11893 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
11894
11895+ pax_force_retaddr 0, 1
11896 ret;
11897
11898 __skip_dec:
11899@@ -392,6 +396,7 @@ cast5_ecb_enc_16way:
11900 vmovdqu RR4, (6*4*4)(%r11);
11901 vmovdqu RL4, (7*4*4)(%r11);
11902
11903+ pax_force_retaddr
11904 ret;
11905
11906 .align 16
11907@@ -427,6 +432,7 @@ cast5_ecb_dec_16way:
11908 vmovdqu RR4, (6*4*4)(%r11);
11909 vmovdqu RL4, (7*4*4)(%r11);
11910
11911+ pax_force_retaddr
11912 ret;
11913
11914 .align 16
11915@@ -479,6 +485,7 @@ cast5_cbc_dec_16way:
11916
11917 popq %r12;
11918
11919+ pax_force_retaddr
11920 ret;
11921
11922 .align 16
11923@@ -555,4 +562,5 @@ cast5_ctr_16way:
11924
11925 popq %r12;
11926
11927+ pax_force_retaddr
11928 ret;
11929diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11930index 2569d0d..637c289 100644
11931--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11932+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11933@@ -23,6 +23,8 @@
11934 *
11935 */
11936
11937+#include <asm/alternative-asm.h>
11938+
11939 #include "glue_helper-asm-avx.S"
11940
11941 .file "cast6-avx-x86_64-asm_64.S"
11942@@ -294,6 +296,7 @@ __cast6_enc_blk8:
11943 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
11944 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
11945
11946+ pax_force_retaddr 0, 1
11947 ret;
11948
11949 .align 8
11950@@ -340,6 +343,7 @@ __cast6_dec_blk8:
11951 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
11952 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
11953
11954+ pax_force_retaddr 0, 1
11955 ret;
11956
11957 .align 8
11958@@ -361,6 +365,7 @@ cast6_ecb_enc_8way:
11959
11960 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11961
11962+ pax_force_retaddr
11963 ret;
11964
11965 .align 8
11966@@ -382,6 +387,7 @@ cast6_ecb_dec_8way:
11967
11968 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11969
11970+ pax_force_retaddr
11971 ret;
11972
11973 .align 8
11974@@ -408,6 +414,7 @@ cast6_cbc_dec_8way:
11975
11976 popq %r12;
11977
11978+ pax_force_retaddr
11979 ret;
11980
11981 .align 8
11982@@ -436,4 +443,5 @@ cast6_ctr_8way:
11983
11984 popq %r12;
11985
11986+ pax_force_retaddr
11987 ret;
11988diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
11989index 6214a9b..1f4fc9a 100644
11990--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
11991+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
11992@@ -1,3 +1,5 @@
11993+#include <asm/alternative-asm.h>
11994+
11995 # enter ECRYPT_encrypt_bytes
11996 .text
11997 .p2align 5
11998@@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
11999 add %r11,%rsp
12000 mov %rdi,%rax
12001 mov %rsi,%rdx
12002+ pax_force_retaddr 0, 1
12003 ret
12004 # bytesatleast65:
12005 ._bytesatleast65:
12006@@ -891,6 +894,7 @@ ECRYPT_keysetup:
12007 add %r11,%rsp
12008 mov %rdi,%rax
12009 mov %rsi,%rdx
12010+ pax_force_retaddr
12011 ret
12012 # enter ECRYPT_ivsetup
12013 .text
12014@@ -917,4 +921,5 @@ ECRYPT_ivsetup:
12015 add %r11,%rsp
12016 mov %rdi,%rax
12017 mov %rsi,%rdx
12018+ pax_force_retaddr
12019 ret
12020diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
12021index 02b0e9f..cf4cf5c 100644
12022--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
12023+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
12024@@ -24,6 +24,8 @@
12025 *
12026 */
12027
12028+#include <asm/alternative-asm.h>
12029+
12030 #include "glue_helper-asm-avx.S"
12031
12032 .file "serpent-avx-x86_64-asm_64.S"
12033@@ -618,6 +620,7 @@ __serpent_enc_blk8_avx:
12034 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12035 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12036
12037+ pax_force_retaddr
12038 ret;
12039
12040 .align 8
12041@@ -673,6 +676,7 @@ __serpent_dec_blk8_avx:
12042 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
12043 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
12044
12045+ pax_force_retaddr
12046 ret;
12047
12048 .align 8
12049@@ -692,6 +696,7 @@ serpent_ecb_enc_8way_avx:
12050
12051 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12052
12053+ pax_force_retaddr
12054 ret;
12055
12056 .align 8
12057@@ -711,6 +716,7 @@ serpent_ecb_dec_8way_avx:
12058
12059 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
12060
12061+ pax_force_retaddr
12062 ret;
12063
12064 .align 8
12065@@ -730,6 +736,7 @@ serpent_cbc_dec_8way_avx:
12066
12067 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
12068
12069+ pax_force_retaddr
12070 ret;
12071
12072 .align 8
12073@@ -751,4 +758,5 @@ serpent_ctr_8way_avx:
12074
12075 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12076
12077+ pax_force_retaddr
12078 ret;
12079diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
12080index 3ee1ff0..cbc568b 100644
12081--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
12082+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
12083@@ -24,6 +24,8 @@
12084 *
12085 */
12086
12087+#include <asm/alternative-asm.h>
12088+
12089 .file "serpent-sse2-x86_64-asm_64.S"
12090 .text
12091
12092@@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
12093 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12094 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12095
12096+ pax_force_retaddr
12097 ret;
12098
12099 __enc_xor8:
12100 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12101 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12102
12103+ pax_force_retaddr
12104 ret;
12105
12106 .align 8
12107@@ -755,4 +759,5 @@ serpent_dec_blk_8way:
12108 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
12109 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
12110
12111+ pax_force_retaddr
12112 ret;
12113diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
12114index 49d6987..df66bd4 100644
12115--- a/arch/x86/crypto/sha1_ssse3_asm.S
12116+++ b/arch/x86/crypto/sha1_ssse3_asm.S
12117@@ -28,6 +28,8 @@
12118 * (at your option) any later version.
12119 */
12120
12121+#include <asm/alternative-asm.h>
12122+
12123 #define CTX %rdi // arg1
12124 #define BUF %rsi // arg2
12125 #define CNT %rdx // arg3
12126@@ -104,6 +106,7 @@
12127 pop %r12
12128 pop %rbp
12129 pop %rbx
12130+ pax_force_retaddr 0, 1
12131 ret
12132
12133 .size \name, .-\name
12134diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
12135index ebac16b..8092eb9 100644
12136--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
12137+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
12138@@ -23,6 +23,8 @@
12139 *
12140 */
12141
12142+#include <asm/alternative-asm.h>
12143+
12144 #include "glue_helper-asm-avx.S"
12145
12146 .file "twofish-avx-x86_64-asm_64.S"
12147@@ -283,6 +285,7 @@ __twofish_enc_blk8:
12148 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
12149 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
12150
12151+ pax_force_retaddr 0, 1
12152 ret;
12153
12154 .align 8
12155@@ -324,6 +327,7 @@ __twofish_dec_blk8:
12156 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
12157 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
12158
12159+ pax_force_retaddr 0, 1
12160 ret;
12161
12162 .align 8
12163@@ -345,6 +349,7 @@ twofish_ecb_enc_8way:
12164
12165 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
12166
12167+ pax_force_retaddr 0, 1
12168 ret;
12169
12170 .align 8
12171@@ -366,6 +371,7 @@ twofish_ecb_dec_8way:
12172
12173 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12174
12175+ pax_force_retaddr 0, 1
12176 ret;
12177
12178 .align 8
12179@@ -392,6 +398,7 @@ twofish_cbc_dec_8way:
12180
12181 popq %r12;
12182
12183+ pax_force_retaddr 0, 1
12184 ret;
12185
12186 .align 8
12187@@ -420,4 +427,5 @@ twofish_ctr_8way:
12188
12189 popq %r12;
12190
12191+ pax_force_retaddr 0, 1
12192 ret;
12193diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
12194index 5b012a2..36d5364 100644
12195--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
12196+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
12197@@ -20,6 +20,8 @@
12198 *
12199 */
12200
12201+#include <asm/alternative-asm.h>
12202+
12203 .file "twofish-x86_64-asm-3way.S"
12204 .text
12205
12206@@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
12207 popq %r13;
12208 popq %r14;
12209 popq %r15;
12210+ pax_force_retaddr 0, 1
12211 ret;
12212
12213 __enc_xor3:
12214@@ -271,6 +274,7 @@ __enc_xor3:
12215 popq %r13;
12216 popq %r14;
12217 popq %r15;
12218+ pax_force_retaddr 0, 1
12219 ret;
12220
12221 .global twofish_dec_blk_3way
12222@@ -312,5 +316,6 @@ twofish_dec_blk_3way:
12223 popq %r13;
12224 popq %r14;
12225 popq %r15;
12226+ pax_force_retaddr 0, 1
12227 ret;
12228
12229diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
12230index 7bcf3fc..f53832f 100644
12231--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
12232+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
12233@@ -21,6 +21,7 @@
12234 .text
12235
12236 #include <asm/asm-offsets.h>
12237+#include <asm/alternative-asm.h>
12238
12239 #define a_offset 0
12240 #define b_offset 4
12241@@ -268,6 +269,7 @@ twofish_enc_blk:
12242
12243 popq R1
12244 movq $1,%rax
12245+ pax_force_retaddr 0, 1
12246 ret
12247
12248 twofish_dec_blk:
12249@@ -319,4 +321,5 @@ twofish_dec_blk:
12250
12251 popq R1
12252 movq $1,%rax
12253+ pax_force_retaddr 0, 1
12254 ret
12255diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
12256index a703af1..f5b9c36 100644
12257--- a/arch/x86/ia32/ia32_aout.c
12258+++ b/arch/x86/ia32/ia32_aout.c
12259@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
12260 unsigned long dump_start, dump_size;
12261 struct user32 dump;
12262
12263+ memset(&dump, 0, sizeof(dump));
12264+
12265 fs = get_fs();
12266 set_fs(KERNEL_DS);
12267 has_dumped = 1;
12268diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
12269index a1daf4a..f8c4537 100644
12270--- a/arch/x86/ia32/ia32_signal.c
12271+++ b/arch/x86/ia32/ia32_signal.c
12272@@ -348,7 +348,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
12273 sp -= frame_size;
12274 /* Align the stack pointer according to the i386 ABI,
12275 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
12276- sp = ((sp + 4) & -16ul) - 4;
12277+ sp = ((sp - 12) & -16ul) - 4;
12278 return (void __user *) sp;
12279 }
12280
12281@@ -406,7 +406,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
12282 * These are actually not used anymore, but left because some
12283 * gdb versions depend on them as a marker.
12284 */
12285- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
12286+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
12287 } put_user_catch(err);
12288
12289 if (err)
12290@@ -448,7 +448,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
12291 0xb8,
12292 __NR_ia32_rt_sigreturn,
12293 0x80cd,
12294- 0,
12295+ 0
12296 };
12297
12298 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
12299@@ -471,16 +471,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
12300
12301 if (ka->sa.sa_flags & SA_RESTORER)
12302 restorer = ka->sa.sa_restorer;
12303+ else if (current->mm->context.vdso)
12304+ /* Return stub is in 32bit vsyscall page */
12305+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
12306 else
12307- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
12308- rt_sigreturn);
12309+ restorer = &frame->retcode;
12310 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
12311
12312 /*
12313 * Not actually used anymore, but left because some gdb
12314 * versions need it.
12315 */
12316- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
12317+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
12318 } put_user_catch(err);
12319
12320 err |= copy_siginfo_to_user32(&frame->info, info);
12321diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
12322index 142c4ce..19b683f 100644
12323--- a/arch/x86/ia32/ia32entry.S
12324+++ b/arch/x86/ia32/ia32entry.S
12325@@ -15,8 +15,10 @@
12326 #include <asm/irqflags.h>
12327 #include <asm/asm.h>
12328 #include <asm/smap.h>
12329+#include <asm/pgtable.h>
12330 #include <linux/linkage.h>
12331 #include <linux/err.h>
12332+#include <asm/alternative-asm.h>
12333
12334 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
12335 #include <linux/elf-em.h>
12336@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
12337 ENDPROC(native_irq_enable_sysexit)
12338 #endif
12339
12340+ .macro pax_enter_kernel_user
12341+ pax_set_fptr_mask
12342+#ifdef CONFIG_PAX_MEMORY_UDEREF
12343+ call pax_enter_kernel_user
12344+#endif
12345+ .endm
12346+
12347+ .macro pax_exit_kernel_user
12348+#ifdef CONFIG_PAX_MEMORY_UDEREF
12349+ call pax_exit_kernel_user
12350+#endif
12351+#ifdef CONFIG_PAX_RANDKSTACK
12352+ pushq %rax
12353+ pushq %r11
12354+ call pax_randomize_kstack
12355+ popq %r11
12356+ popq %rax
12357+#endif
12358+ .endm
12359+
12360+.macro pax_erase_kstack
12361+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
12362+ call pax_erase_kstack
12363+#endif
12364+.endm
12365+
12366 /*
12367 * 32bit SYSENTER instruction entry.
12368 *
12369@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
12370 CFI_REGISTER rsp,rbp
12371 SWAPGS_UNSAFE_STACK
12372 movq PER_CPU_VAR(kernel_stack), %rsp
12373- addq $(KERNEL_STACK_OFFSET),%rsp
12374- /*
12375- * No need to follow this irqs on/off section: the syscall
12376- * disabled irqs, here we enable it straight after entry:
12377- */
12378- ENABLE_INTERRUPTS(CLBR_NONE)
12379 movl %ebp,%ebp /* zero extension */
12380 pushq_cfi $__USER32_DS
12381 /*CFI_REL_OFFSET ss,0*/
12382@@ -135,24 +157,44 @@ ENTRY(ia32_sysenter_target)
12383 CFI_REL_OFFSET rsp,0
12384 pushfq_cfi
12385 /*CFI_REL_OFFSET rflags,0*/
12386- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
12387- CFI_REGISTER rip,r10
12388+ orl $X86_EFLAGS_IF,(%rsp)
12389+ GET_THREAD_INFO(%r11)
12390+ movl TI_sysenter_return(%r11), %r11d
12391+ CFI_REGISTER rip,r11
12392 pushq_cfi $__USER32_CS
12393 /*CFI_REL_OFFSET cs,0*/
12394 movl %eax, %eax
12395- pushq_cfi %r10
12396+ pushq_cfi %r11
12397 CFI_REL_OFFSET rip,0
12398 pushq_cfi %rax
12399 cld
12400 SAVE_ARGS 0,1,0
12401+ pax_enter_kernel_user
12402+
12403+#ifdef CONFIG_PAX_RANDKSTACK
12404+ pax_erase_kstack
12405+#endif
12406+
12407+ /*
12408+ * No need to follow this irqs on/off section: the syscall
12409+ * disabled irqs, here we enable it straight after entry:
12410+ */
12411+ ENABLE_INTERRUPTS(CLBR_NONE)
12412 /* no need to do an access_ok check here because rbp has been
12413 32bit zero extended */
12414+
12415+#ifdef CONFIG_PAX_MEMORY_UDEREF
12416+ mov $PAX_USER_SHADOW_BASE,%r11
12417+ add %r11,%rbp
12418+#endif
12419+
12420 ASM_STAC
12421 1: movl (%rbp),%ebp
12422 _ASM_EXTABLE(1b,ia32_badarg)
12423 ASM_CLAC
12424- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12425- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12426+ GET_THREAD_INFO(%r11)
12427+ orl $TS_COMPAT,TI_status(%r11)
12428+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
12429 CFI_REMEMBER_STATE
12430 jnz sysenter_tracesys
12431 cmpq $(IA32_NR_syscalls-1),%rax
12432@@ -162,12 +204,15 @@ sysenter_do_call:
12433 sysenter_dispatch:
12434 call *ia32_sys_call_table(,%rax,8)
12435 movq %rax,RAX-ARGOFFSET(%rsp)
12436+ GET_THREAD_INFO(%r11)
12437 DISABLE_INTERRUPTS(CLBR_NONE)
12438 TRACE_IRQS_OFF
12439- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12440+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
12441 jnz sysexit_audit
12442 sysexit_from_sys_call:
12443- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12444+ pax_exit_kernel_user
12445+ pax_erase_kstack
12446+ andl $~TS_COMPAT,TI_status(%r11)
12447 /* clear IF, that popfq doesn't enable interrupts early */
12448 andl $~0x200,EFLAGS-R11(%rsp)
12449 movl RIP-R11(%rsp),%edx /* User %eip */
12450@@ -193,6 +238,9 @@ sysexit_from_sys_call:
12451 movl %eax,%esi /* 2nd arg: syscall number */
12452 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
12453 call __audit_syscall_entry
12454+
12455+ pax_erase_kstack
12456+
12457 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
12458 cmpq $(IA32_NR_syscalls-1),%rax
12459 ja ia32_badsys
12460@@ -204,7 +252,7 @@ sysexit_from_sys_call:
12461 .endm
12462
12463 .macro auditsys_exit exit
12464- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12465+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
12466 jnz ia32_ret_from_sys_call
12467 TRACE_IRQS_ON
12468 ENABLE_INTERRUPTS(CLBR_NONE)
12469@@ -215,11 +263,12 @@ sysexit_from_sys_call:
12470 1: setbe %al /* 1 if error, 0 if not */
12471 movzbl %al,%edi /* zero-extend that into %edi */
12472 call __audit_syscall_exit
12473+ GET_THREAD_INFO(%r11)
12474 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
12475 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
12476 DISABLE_INTERRUPTS(CLBR_NONE)
12477 TRACE_IRQS_OFF
12478- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12479+ testl %edi,TI_flags(%r11)
12480 jz \exit
12481 CLEAR_RREGS -ARGOFFSET
12482 jmp int_with_check
12483@@ -237,7 +286,7 @@ sysexit_audit:
12484
12485 sysenter_tracesys:
12486 #ifdef CONFIG_AUDITSYSCALL
12487- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12488+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
12489 jz sysenter_auditsys
12490 #endif
12491 SAVE_REST
12492@@ -249,6 +298,9 @@ sysenter_tracesys:
12493 RESTORE_REST
12494 cmpq $(IA32_NR_syscalls-1),%rax
12495 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
12496+
12497+ pax_erase_kstack
12498+
12499 jmp sysenter_do_call
12500 CFI_ENDPROC
12501 ENDPROC(ia32_sysenter_target)
12502@@ -276,19 +328,25 @@ ENDPROC(ia32_sysenter_target)
12503 ENTRY(ia32_cstar_target)
12504 CFI_STARTPROC32 simple
12505 CFI_SIGNAL_FRAME
12506- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
12507+ CFI_DEF_CFA rsp,0
12508 CFI_REGISTER rip,rcx
12509 /*CFI_REGISTER rflags,r11*/
12510 SWAPGS_UNSAFE_STACK
12511 movl %esp,%r8d
12512 CFI_REGISTER rsp,r8
12513 movq PER_CPU_VAR(kernel_stack),%rsp
12514+ SAVE_ARGS 8*6,0,0
12515+ pax_enter_kernel_user
12516+
12517+#ifdef CONFIG_PAX_RANDKSTACK
12518+ pax_erase_kstack
12519+#endif
12520+
12521 /*
12522 * No need to follow this irqs on/off section: the syscall
12523 * disabled irqs and here we enable it straight after entry:
12524 */
12525 ENABLE_INTERRUPTS(CLBR_NONE)
12526- SAVE_ARGS 8,0,0
12527 movl %eax,%eax /* zero extension */
12528 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
12529 movq %rcx,RIP-ARGOFFSET(%rsp)
12530@@ -304,12 +362,19 @@ ENTRY(ia32_cstar_target)
12531 /* no need to do an access_ok check here because r8 has been
12532 32bit zero extended */
12533 /* hardware stack frame is complete now */
12534+
12535+#ifdef CONFIG_PAX_MEMORY_UDEREF
12536+ mov $PAX_USER_SHADOW_BASE,%r11
12537+ add %r11,%r8
12538+#endif
12539+
12540 ASM_STAC
12541 1: movl (%r8),%r9d
12542 _ASM_EXTABLE(1b,ia32_badarg)
12543 ASM_CLAC
12544- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12545- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12546+ GET_THREAD_INFO(%r11)
12547+ orl $TS_COMPAT,TI_status(%r11)
12548+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
12549 CFI_REMEMBER_STATE
12550 jnz cstar_tracesys
12551 cmpq $IA32_NR_syscalls-1,%rax
12552@@ -319,12 +384,15 @@ cstar_do_call:
12553 cstar_dispatch:
12554 call *ia32_sys_call_table(,%rax,8)
12555 movq %rax,RAX-ARGOFFSET(%rsp)
12556+ GET_THREAD_INFO(%r11)
12557 DISABLE_INTERRUPTS(CLBR_NONE)
12558 TRACE_IRQS_OFF
12559- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12560+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
12561 jnz sysretl_audit
12562 sysretl_from_sys_call:
12563- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12564+ pax_exit_kernel_user
12565+ pax_erase_kstack
12566+ andl $~TS_COMPAT,TI_status(%r11)
12567 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
12568 movl RIP-ARGOFFSET(%rsp),%ecx
12569 CFI_REGISTER rip,rcx
12570@@ -352,7 +420,7 @@ sysretl_audit:
12571
12572 cstar_tracesys:
12573 #ifdef CONFIG_AUDITSYSCALL
12574- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12575+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
12576 jz cstar_auditsys
12577 #endif
12578 xchgl %r9d,%ebp
12579@@ -366,6 +434,9 @@ cstar_tracesys:
12580 xchgl %ebp,%r9d
12581 cmpq $(IA32_NR_syscalls-1),%rax
12582 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
12583+
12584+ pax_erase_kstack
12585+
12586 jmp cstar_do_call
12587 END(ia32_cstar_target)
12588
12589@@ -407,19 +478,26 @@ ENTRY(ia32_syscall)
12590 CFI_REL_OFFSET rip,RIP-RIP
12591 PARAVIRT_ADJUST_EXCEPTION_FRAME
12592 SWAPGS
12593- /*
12594- * No need to follow this irqs on/off section: the syscall
12595- * disabled irqs and here we enable it straight after entry:
12596- */
12597- ENABLE_INTERRUPTS(CLBR_NONE)
12598 movl %eax,%eax
12599 pushq_cfi %rax
12600 cld
12601 /* note the registers are not zero extended to the sf.
12602 this could be a problem. */
12603 SAVE_ARGS 0,1,0
12604- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12605- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12606+ pax_enter_kernel_user
12607+
12608+#ifdef CONFIG_PAX_RANDKSTACK
12609+ pax_erase_kstack
12610+#endif
12611+
12612+ /*
12613+ * No need to follow this irqs on/off section: the syscall
12614+ * disabled irqs and here we enable it straight after entry:
12615+ */
12616+ ENABLE_INTERRUPTS(CLBR_NONE)
12617+ GET_THREAD_INFO(%r11)
12618+ orl $TS_COMPAT,TI_status(%r11)
12619+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
12620 jnz ia32_tracesys
12621 cmpq $(IA32_NR_syscalls-1),%rax
12622 ja ia32_badsys
12623@@ -442,6 +520,9 @@ ia32_tracesys:
12624 RESTORE_REST
12625 cmpq $(IA32_NR_syscalls-1),%rax
12626 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
12627+
12628+ pax_erase_kstack
12629+
12630 jmp ia32_do_call
12631 END(ia32_syscall)
12632
12633diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
12634index d0b689b..6811ddc 100644
12635--- a/arch/x86/ia32/sys_ia32.c
12636+++ b/arch/x86/ia32/sys_ia32.c
12637@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
12638 */
12639 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
12640 {
12641- typeof(ubuf->st_uid) uid = 0;
12642- typeof(ubuf->st_gid) gid = 0;
12643+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
12644+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
12645 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
12646 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
12647 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
12648@@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
12649 mm_segment_t old_fs = get_fs();
12650
12651 set_fs(KERNEL_DS);
12652- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
12653+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
12654 set_fs(old_fs);
12655 if (put_compat_timespec(&t, interval))
12656 return -EFAULT;
12657@@ -313,13 +313,13 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
12658 asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
12659 compat_size_t sigsetsize)
12660 {
12661- sigset_t s;
12662+ sigset_t s = { };
12663 compat_sigset_t s32;
12664 int ret;
12665 mm_segment_t old_fs = get_fs();
12666
12667 set_fs(KERNEL_DS);
12668- ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
12669+ ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
12670 set_fs(old_fs);
12671 if (!ret) {
12672 switch (_NSIG_WORDS) {
12673@@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
12674 if (copy_siginfo_from_user32(&info, uinfo))
12675 return -EFAULT;
12676 set_fs(KERNEL_DS);
12677- ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
12678+ ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
12679 set_fs(old_fs);
12680 return ret;
12681 }
12682@@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
12683 return -EFAULT;
12684
12685 set_fs(KERNEL_DS);
12686- ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
12687+ ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
12688 count);
12689 set_fs(old_fs);
12690
12691diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
12692index 372231c..a5aa1a1 100644
12693--- a/arch/x86/include/asm/alternative-asm.h
12694+++ b/arch/x86/include/asm/alternative-asm.h
12695@@ -18,6 +18,45 @@
12696 .endm
12697 #endif
12698
12699+#ifdef KERNEXEC_PLUGIN
12700+ .macro pax_force_retaddr_bts rip=0
12701+ btsq $63,\rip(%rsp)
12702+ .endm
12703+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
12704+ .macro pax_force_retaddr rip=0, reload=0
12705+ btsq $63,\rip(%rsp)
12706+ .endm
12707+ .macro pax_force_fptr ptr
12708+ btsq $63,\ptr
12709+ .endm
12710+ .macro pax_set_fptr_mask
12711+ .endm
12712+#endif
12713+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
12714+ .macro pax_force_retaddr rip=0, reload=0
12715+ .if \reload
12716+ pax_set_fptr_mask
12717+ .endif
12718+ orq %r10,\rip(%rsp)
12719+ .endm
12720+ .macro pax_force_fptr ptr
12721+ orq %r10,\ptr
12722+ .endm
12723+ .macro pax_set_fptr_mask
12724+ movabs $0x8000000000000000,%r10
12725+ .endm
12726+#endif
12727+#else
12728+ .macro pax_force_retaddr rip=0, reload=0
12729+ .endm
12730+ .macro pax_force_fptr ptr
12731+ .endm
12732+ .macro pax_force_retaddr_bts rip=0
12733+ .endm
12734+ .macro pax_set_fptr_mask
12735+ .endm
12736+#endif
12737+
12738 .macro altinstruction_entry orig alt feature orig_len alt_len
12739 .long \orig - .
12740 .long \alt - .
12741diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
12742index 58ed6d9..f1cbe58 100644
12743--- a/arch/x86/include/asm/alternative.h
12744+++ b/arch/x86/include/asm/alternative.h
12745@@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
12746 ".pushsection .discard,\"aw\",@progbits\n" \
12747 DISCARD_ENTRY(1) \
12748 ".popsection\n" \
12749- ".pushsection .altinstr_replacement, \"ax\"\n" \
12750+ ".pushsection .altinstr_replacement, \"a\"\n" \
12751 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
12752 ".popsection"
12753
12754@@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
12755 DISCARD_ENTRY(1) \
12756 DISCARD_ENTRY(2) \
12757 ".popsection\n" \
12758- ".pushsection .altinstr_replacement, \"ax\"\n" \
12759+ ".pushsection .altinstr_replacement, \"a\"\n" \
12760 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
12761 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
12762 ".popsection"
12763diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
12764index 3388034..050f0b9 100644
12765--- a/arch/x86/include/asm/apic.h
12766+++ b/arch/x86/include/asm/apic.h
12767@@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
12768
12769 #ifdef CONFIG_X86_LOCAL_APIC
12770
12771-extern unsigned int apic_verbosity;
12772+extern int apic_verbosity;
12773 extern int local_apic_timer_c2_ok;
12774
12775 extern int disable_apic;
12776diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
12777index 20370c6..a2eb9b0 100644
12778--- a/arch/x86/include/asm/apm.h
12779+++ b/arch/x86/include/asm/apm.h
12780@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
12781 __asm__ __volatile__(APM_DO_ZERO_SEGS
12782 "pushl %%edi\n\t"
12783 "pushl %%ebp\n\t"
12784- "lcall *%%cs:apm_bios_entry\n\t"
12785+ "lcall *%%ss:apm_bios_entry\n\t"
12786 "setc %%al\n\t"
12787 "popl %%ebp\n\t"
12788 "popl %%edi\n\t"
12789@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
12790 __asm__ __volatile__(APM_DO_ZERO_SEGS
12791 "pushl %%edi\n\t"
12792 "pushl %%ebp\n\t"
12793- "lcall *%%cs:apm_bios_entry\n\t"
12794+ "lcall *%%ss:apm_bios_entry\n\t"
12795 "setc %%bl\n\t"
12796 "popl %%ebp\n\t"
12797 "popl %%edi\n\t"
12798diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
12799index 722aa3b..3a0bb27 100644
12800--- a/arch/x86/include/asm/atomic.h
12801+++ b/arch/x86/include/asm/atomic.h
12802@@ -22,7 +22,18 @@
12803 */
12804 static inline int atomic_read(const atomic_t *v)
12805 {
12806- return (*(volatile int *)&(v)->counter);
12807+ return (*(volatile const int *)&(v)->counter);
12808+}
12809+
12810+/**
12811+ * atomic_read_unchecked - read atomic variable
12812+ * @v: pointer of type atomic_unchecked_t
12813+ *
12814+ * Atomically reads the value of @v.
12815+ */
12816+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
12817+{
12818+ return (*(volatile const int *)&(v)->counter);
12819 }
12820
12821 /**
12822@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
12823 }
12824
12825 /**
12826+ * atomic_set_unchecked - set atomic variable
12827+ * @v: pointer of type atomic_unchecked_t
12828+ * @i: required value
12829+ *
12830+ * Atomically sets the value of @v to @i.
12831+ */
12832+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
12833+{
12834+ v->counter = i;
12835+}
12836+
12837+/**
12838 * atomic_add - add integer to atomic variable
12839 * @i: integer value to add
12840 * @v: pointer of type atomic_t
12841@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
12842 */
12843 static inline void atomic_add(int i, atomic_t *v)
12844 {
12845- asm volatile(LOCK_PREFIX "addl %1,%0"
12846+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
12847+
12848+#ifdef CONFIG_PAX_REFCOUNT
12849+ "jno 0f\n"
12850+ LOCK_PREFIX "subl %1,%0\n"
12851+ "int $4\n0:\n"
12852+ _ASM_EXTABLE(0b, 0b)
12853+#endif
12854+
12855+ : "+m" (v->counter)
12856+ : "ir" (i));
12857+}
12858+
12859+/**
12860+ * atomic_add_unchecked - add integer to atomic variable
12861+ * @i: integer value to add
12862+ * @v: pointer of type atomic_unchecked_t
12863+ *
12864+ * Atomically adds @i to @v.
12865+ */
12866+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
12867+{
12868+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
12869 : "+m" (v->counter)
12870 : "ir" (i));
12871 }
12872@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
12873 */
12874 static inline void atomic_sub(int i, atomic_t *v)
12875 {
12876- asm volatile(LOCK_PREFIX "subl %1,%0"
12877+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
12878+
12879+#ifdef CONFIG_PAX_REFCOUNT
12880+ "jno 0f\n"
12881+ LOCK_PREFIX "addl %1,%0\n"
12882+ "int $4\n0:\n"
12883+ _ASM_EXTABLE(0b, 0b)
12884+#endif
12885+
12886+ : "+m" (v->counter)
12887+ : "ir" (i));
12888+}
12889+
12890+/**
12891+ * atomic_sub_unchecked - subtract integer from atomic variable
12892+ * @i: integer value to subtract
12893+ * @v: pointer of type atomic_unchecked_t
12894+ *
12895+ * Atomically subtracts @i from @v.
12896+ */
12897+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
12898+{
12899+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
12900 : "+m" (v->counter)
12901 : "ir" (i));
12902 }
12903@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
12904 {
12905 unsigned char c;
12906
12907- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
12908+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
12909+
12910+#ifdef CONFIG_PAX_REFCOUNT
12911+ "jno 0f\n"
12912+ LOCK_PREFIX "addl %2,%0\n"
12913+ "int $4\n0:\n"
12914+ _ASM_EXTABLE(0b, 0b)
12915+#endif
12916+
12917+ "sete %1\n"
12918 : "+m" (v->counter), "=qm" (c)
12919 : "ir" (i) : "memory");
12920 return c;
12921@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
12922 */
12923 static inline void atomic_inc(atomic_t *v)
12924 {
12925- asm volatile(LOCK_PREFIX "incl %0"
12926+ asm volatile(LOCK_PREFIX "incl %0\n"
12927+
12928+#ifdef CONFIG_PAX_REFCOUNT
12929+ "jno 0f\n"
12930+ LOCK_PREFIX "decl %0\n"
12931+ "int $4\n0:\n"
12932+ _ASM_EXTABLE(0b, 0b)
12933+#endif
12934+
12935+ : "+m" (v->counter));
12936+}
12937+
12938+/**
12939+ * atomic_inc_unchecked - increment atomic variable
12940+ * @v: pointer of type atomic_unchecked_t
12941+ *
12942+ * Atomically increments @v by 1.
12943+ */
12944+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
12945+{
12946+ asm volatile(LOCK_PREFIX "incl %0\n"
12947 : "+m" (v->counter));
12948 }
12949
12950@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
12951 */
12952 static inline void atomic_dec(atomic_t *v)
12953 {
12954- asm volatile(LOCK_PREFIX "decl %0"
12955+ asm volatile(LOCK_PREFIX "decl %0\n"
12956+
12957+#ifdef CONFIG_PAX_REFCOUNT
12958+ "jno 0f\n"
12959+ LOCK_PREFIX "incl %0\n"
12960+ "int $4\n0:\n"
12961+ _ASM_EXTABLE(0b, 0b)
12962+#endif
12963+
12964+ : "+m" (v->counter));
12965+}
12966+
12967+/**
12968+ * atomic_dec_unchecked - decrement atomic variable
12969+ * @v: pointer of type atomic_unchecked_t
12970+ *
12971+ * Atomically decrements @v by 1.
12972+ */
12973+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
12974+{
12975+ asm volatile(LOCK_PREFIX "decl %0\n"
12976 : "+m" (v->counter));
12977 }
12978
12979@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
12980 {
12981 unsigned char c;
12982
12983- asm volatile(LOCK_PREFIX "decl %0; sete %1"
12984+ asm volatile(LOCK_PREFIX "decl %0\n"
12985+
12986+#ifdef CONFIG_PAX_REFCOUNT
12987+ "jno 0f\n"
12988+ LOCK_PREFIX "incl %0\n"
12989+ "int $4\n0:\n"
12990+ _ASM_EXTABLE(0b, 0b)
12991+#endif
12992+
12993+ "sete %1\n"
12994 : "+m" (v->counter), "=qm" (c)
12995 : : "memory");
12996 return c != 0;
12997@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
12998 {
12999 unsigned char c;
13000
13001- asm volatile(LOCK_PREFIX "incl %0; sete %1"
13002+ asm volatile(LOCK_PREFIX "incl %0\n"
13003+
13004+#ifdef CONFIG_PAX_REFCOUNT
13005+ "jno 0f\n"
13006+ LOCK_PREFIX "decl %0\n"
13007+ "int $4\n0:\n"
13008+ _ASM_EXTABLE(0b, 0b)
13009+#endif
13010+
13011+ "sete %1\n"
13012+ : "+m" (v->counter), "=qm" (c)
13013+ : : "memory");
13014+ return c != 0;
13015+}
13016+
13017+/**
13018+ * atomic_inc_and_test_unchecked - increment and test
13019+ * @v: pointer of type atomic_unchecked_t
13020+ *
13021+ * Atomically increments @v by 1
13022+ * and returns true if the result is zero, or false for all
13023+ * other cases.
13024+ */
13025+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
13026+{
13027+ unsigned char c;
13028+
13029+ asm volatile(LOCK_PREFIX "incl %0\n"
13030+ "sete %1\n"
13031 : "+m" (v->counter), "=qm" (c)
13032 : : "memory");
13033 return c != 0;
13034@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
13035 {
13036 unsigned char c;
13037
13038- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
13039+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
13040+
13041+#ifdef CONFIG_PAX_REFCOUNT
13042+ "jno 0f\n"
13043+ LOCK_PREFIX "subl %2,%0\n"
13044+ "int $4\n0:\n"
13045+ _ASM_EXTABLE(0b, 0b)
13046+#endif
13047+
13048+ "sets %1\n"
13049 : "+m" (v->counter), "=qm" (c)
13050 : "ir" (i) : "memory");
13051 return c;
13052@@ -172,6 +334,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
13053 */
13054 static inline int atomic_add_return(int i, atomic_t *v)
13055 {
13056+ return i + xadd_check_overflow(&v->counter, i);
13057+}
13058+
13059+/**
13060+ * atomic_add_return_unchecked - add integer and return
13061+ * @i: integer value to add
13062+ * @v: pointer of type atomic_unchecked_t
13063+ *
13064+ * Atomically adds @i to @v and returns @i + @v
13065+ */
13066+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
13067+{
13068 return i + xadd(&v->counter, i);
13069 }
13070
13071@@ -188,6 +362,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
13072 }
13073
13074 #define atomic_inc_return(v) (atomic_add_return(1, v))
13075+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
13076+{
13077+ return atomic_add_return_unchecked(1, v);
13078+}
13079 #define atomic_dec_return(v) (atomic_sub_return(1, v))
13080
13081 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
13082@@ -195,11 +373,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
13083 return cmpxchg(&v->counter, old, new);
13084 }
13085
13086+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
13087+{
13088+ return cmpxchg(&v->counter, old, new);
13089+}
13090+
13091 static inline int atomic_xchg(atomic_t *v, int new)
13092 {
13093 return xchg(&v->counter, new);
13094 }
13095
13096+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
13097+{
13098+ return xchg(&v->counter, new);
13099+}
13100+
13101 /**
13102 * __atomic_add_unless - add unless the number is already a given value
13103 * @v: pointer of type atomic_t
13104@@ -211,12 +399,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
13105 */
13106 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
13107 {
13108- int c, old;
13109+ int c, old, new;
13110 c = atomic_read(v);
13111 for (;;) {
13112- if (unlikely(c == (u)))
13113+ if (unlikely(c == u))
13114 break;
13115- old = atomic_cmpxchg((v), c, c + (a));
13116+
13117+ asm volatile("addl %2,%0\n"
13118+
13119+#ifdef CONFIG_PAX_REFCOUNT
13120+ "jno 0f\n"
13121+ "subl %2,%0\n"
13122+ "int $4\n0:\n"
13123+ _ASM_EXTABLE(0b, 0b)
13124+#endif
13125+
13126+ : "=r" (new)
13127+ : "0" (c), "ir" (a));
13128+
13129+ old = atomic_cmpxchg(v, c, new);
13130 if (likely(old == c))
13131 break;
13132 c = old;
13133@@ -225,6 +426,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
13134 }
13135
13136 /**
13137+ * atomic_inc_not_zero_hint - increment if not null
13138+ * @v: pointer of type atomic_t
13139+ * @hint: probable value of the atomic before the increment
13140+ *
13141+ * This version of atomic_inc_not_zero() gives a hint of probable
13142+ * value of the atomic. This helps processor to not read the memory
13143+ * before doing the atomic read/modify/write cycle, lowering
13144+ * number of bus transactions on some arches.
13145+ *
13146+ * Returns: 0 if increment was not done, 1 otherwise.
13147+ */
13148+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
13149+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
13150+{
13151+ int val, c = hint, new;
13152+
13153+ /* sanity test, should be removed by compiler if hint is a constant */
13154+ if (!hint)
13155+ return __atomic_add_unless(v, 1, 0);
13156+
13157+ do {
13158+ asm volatile("incl %0\n"
13159+
13160+#ifdef CONFIG_PAX_REFCOUNT
13161+ "jno 0f\n"
13162+ "decl %0\n"
13163+ "int $4\n0:\n"
13164+ _ASM_EXTABLE(0b, 0b)
13165+#endif
13166+
13167+ : "=r" (new)
13168+ : "0" (c));
13169+
13170+ val = atomic_cmpxchg(v, c, new);
13171+ if (val == c)
13172+ return 1;
13173+ c = val;
13174+ } while (c);
13175+
13176+ return 0;
13177+}
13178+
13179+/**
13180 * atomic_inc_short - increment of a short integer
13181 * @v: pointer to type int
13182 *
13183@@ -253,14 +497,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
13184 #endif
13185
13186 /* These are x86-specific, used by some header files */
13187-#define atomic_clear_mask(mask, addr) \
13188- asm volatile(LOCK_PREFIX "andl %0,%1" \
13189- : : "r" (~(mask)), "m" (*(addr)) : "memory")
13190+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
13191+{
13192+ asm volatile(LOCK_PREFIX "andl %1,%0"
13193+ : "+m" (v->counter)
13194+ : "r" (~(mask))
13195+ : "memory");
13196+}
13197
13198-#define atomic_set_mask(mask, addr) \
13199- asm volatile(LOCK_PREFIX "orl %0,%1" \
13200- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
13201- : "memory")
13202+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
13203+{
13204+ asm volatile(LOCK_PREFIX "andl %1,%0"
13205+ : "+m" (v->counter)
13206+ : "r" (~(mask))
13207+ : "memory");
13208+}
13209+
13210+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
13211+{
13212+ asm volatile(LOCK_PREFIX "orl %1,%0"
13213+ : "+m" (v->counter)
13214+ : "r" (mask)
13215+ : "memory");
13216+}
13217+
13218+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
13219+{
13220+ asm volatile(LOCK_PREFIX "orl %1,%0"
13221+ : "+m" (v->counter)
13222+ : "r" (mask)
13223+ : "memory");
13224+}
13225
13226 /* Atomic operations are already serializing on x86 */
13227 #define smp_mb__before_atomic_dec() barrier()
13228diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
13229index b154de7..aadebd8 100644
13230--- a/arch/x86/include/asm/atomic64_32.h
13231+++ b/arch/x86/include/asm/atomic64_32.h
13232@@ -12,6 +12,14 @@ typedef struct {
13233 u64 __aligned(8) counter;
13234 } atomic64_t;
13235
13236+#ifdef CONFIG_PAX_REFCOUNT
13237+typedef struct {
13238+ u64 __aligned(8) counter;
13239+} atomic64_unchecked_t;
13240+#else
13241+typedef atomic64_t atomic64_unchecked_t;
13242+#endif
13243+
13244 #define ATOMIC64_INIT(val) { (val) }
13245
13246 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
13247@@ -37,21 +45,31 @@ typedef struct {
13248 ATOMIC64_DECL_ONE(sym##_386)
13249
13250 ATOMIC64_DECL_ONE(add_386);
13251+ATOMIC64_DECL_ONE(add_unchecked_386);
13252 ATOMIC64_DECL_ONE(sub_386);
13253+ATOMIC64_DECL_ONE(sub_unchecked_386);
13254 ATOMIC64_DECL_ONE(inc_386);
13255+ATOMIC64_DECL_ONE(inc_unchecked_386);
13256 ATOMIC64_DECL_ONE(dec_386);
13257+ATOMIC64_DECL_ONE(dec_unchecked_386);
13258 #endif
13259
13260 #define alternative_atomic64(f, out, in...) \
13261 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
13262
13263 ATOMIC64_DECL(read);
13264+ATOMIC64_DECL(read_unchecked);
13265 ATOMIC64_DECL(set);
13266+ATOMIC64_DECL(set_unchecked);
13267 ATOMIC64_DECL(xchg);
13268 ATOMIC64_DECL(add_return);
13269+ATOMIC64_DECL(add_return_unchecked);
13270 ATOMIC64_DECL(sub_return);
13271+ATOMIC64_DECL(sub_return_unchecked);
13272 ATOMIC64_DECL(inc_return);
13273+ATOMIC64_DECL(inc_return_unchecked);
13274 ATOMIC64_DECL(dec_return);
13275+ATOMIC64_DECL(dec_return_unchecked);
13276 ATOMIC64_DECL(dec_if_positive);
13277 ATOMIC64_DECL(inc_not_zero);
13278 ATOMIC64_DECL(add_unless);
13279@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
13280 }
13281
13282 /**
13283+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
13284+ * @p: pointer to type atomic64_unchecked_t
13285+ * @o: expected value
13286+ * @n: new value
13287+ *
13288+ * Atomically sets @v to @n if it was equal to @o and returns
13289+ * the old value.
13290+ */
13291+
13292+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
13293+{
13294+ return cmpxchg64(&v->counter, o, n);
13295+}
13296+
13297+/**
13298 * atomic64_xchg - xchg atomic64 variable
13299 * @v: pointer to type atomic64_t
13300 * @n: value to assign
13301@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
13302 }
13303
13304 /**
13305+ * atomic64_set_unchecked - set atomic64 variable
13306+ * @v: pointer to type atomic64_unchecked_t
13307+ * @n: value to assign
13308+ *
13309+ * Atomically sets the value of @v to @n.
13310+ */
13311+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
13312+{
13313+ unsigned high = (unsigned)(i >> 32);
13314+ unsigned low = (unsigned)i;
13315+ alternative_atomic64(set, /* no output */,
13316+ "S" (v), "b" (low), "c" (high)
13317+ : "eax", "edx", "memory");
13318+}
13319+
13320+/**
13321 * atomic64_read - read atomic64 variable
13322 * @v: pointer to type atomic64_t
13323 *
13324@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
13325 }
13326
13327 /**
13328+ * atomic64_read_unchecked - read atomic64 variable
13329+ * @v: pointer to type atomic64_unchecked_t
13330+ *
13331+ * Atomically reads the value of @v and returns it.
13332+ */
13333+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
13334+{
13335+ long long r;
13336+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
13337+ return r;
13338+ }
13339+
13340+/**
13341 * atomic64_add_return - add and return
13342 * @i: integer value to add
13343 * @v: pointer to type atomic64_t
13344@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
13345 return i;
13346 }
13347
13348+/**
13349+ * atomic64_add_return_unchecked - add and return
13350+ * @i: integer value to add
13351+ * @v: pointer to type atomic64_unchecked_t
13352+ *
13353+ * Atomically adds @i to @v and returns @i + *@v
13354+ */
13355+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
13356+{
13357+ alternative_atomic64(add_return_unchecked,
13358+ ASM_OUTPUT2("+A" (i), "+c" (v)),
13359+ ASM_NO_INPUT_CLOBBER("memory"));
13360+ return i;
13361+}
13362+
13363 /*
13364 * Other variants with different arithmetic operators:
13365 */
13366@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
13367 return a;
13368 }
13369
13370+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
13371+{
13372+ long long a;
13373+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
13374+ "S" (v) : "memory", "ecx");
13375+ return a;
13376+}
13377+
13378 static inline long long atomic64_dec_return(atomic64_t *v)
13379 {
13380 long long a;
13381@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
13382 }
13383
13384 /**
13385+ * atomic64_add_unchecked - add integer to atomic64 variable
13386+ * @i: integer value to add
13387+ * @v: pointer to type atomic64_unchecked_t
13388+ *
13389+ * Atomically adds @i to @v.
13390+ */
13391+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
13392+{
13393+ __alternative_atomic64(add_unchecked, add_return_unchecked,
13394+ ASM_OUTPUT2("+A" (i), "+c" (v)),
13395+ ASM_NO_INPUT_CLOBBER("memory"));
13396+ return i;
13397+}
13398+
13399+/**
13400 * atomic64_sub - subtract the atomic64 variable
13401 * @i: integer value to subtract
13402 * @v: pointer to type atomic64_t
13403diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
13404index 0e1cbfc..5623683 100644
13405--- a/arch/x86/include/asm/atomic64_64.h
13406+++ b/arch/x86/include/asm/atomic64_64.h
13407@@ -18,7 +18,19 @@
13408 */
13409 static inline long atomic64_read(const atomic64_t *v)
13410 {
13411- return (*(volatile long *)&(v)->counter);
13412+ return (*(volatile const long *)&(v)->counter);
13413+}
13414+
13415+/**
13416+ * atomic64_read_unchecked - read atomic64 variable
13417+ * @v: pointer of type atomic64_unchecked_t
13418+ *
13419+ * Atomically reads the value of @v.
13420+ * Doesn't imply a read memory barrier.
13421+ */
13422+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
13423+{
13424+ return (*(volatile const long *)&(v)->counter);
13425 }
13426
13427 /**
13428@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
13429 }
13430
13431 /**
13432+ * atomic64_set_unchecked - set atomic64 variable
13433+ * @v: pointer to type atomic64_unchecked_t
13434+ * @i: required value
13435+ *
13436+ * Atomically sets the value of @v to @i.
13437+ */
13438+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
13439+{
13440+ v->counter = i;
13441+}
13442+
13443+/**
13444 * atomic64_add - add integer to atomic64 variable
13445 * @i: integer value to add
13446 * @v: pointer to type atomic64_t
13447@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
13448 */
13449 static inline void atomic64_add(long i, atomic64_t *v)
13450 {
13451+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
13452+
13453+#ifdef CONFIG_PAX_REFCOUNT
13454+ "jno 0f\n"
13455+ LOCK_PREFIX "subq %1,%0\n"
13456+ "int $4\n0:\n"
13457+ _ASM_EXTABLE(0b, 0b)
13458+#endif
13459+
13460+ : "=m" (v->counter)
13461+ : "er" (i), "m" (v->counter));
13462+}
13463+
13464+/**
13465+ * atomic64_add_unchecked - add integer to atomic64 variable
13466+ * @i: integer value to add
13467+ * @v: pointer to type atomic64_unchecked_t
13468+ *
13469+ * Atomically adds @i to @v.
13470+ */
13471+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
13472+{
13473 asm volatile(LOCK_PREFIX "addq %1,%0"
13474 : "=m" (v->counter)
13475 : "er" (i), "m" (v->counter));
13476@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
13477 */
13478 static inline void atomic64_sub(long i, atomic64_t *v)
13479 {
13480- asm volatile(LOCK_PREFIX "subq %1,%0"
13481+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
13482+
13483+#ifdef CONFIG_PAX_REFCOUNT
13484+ "jno 0f\n"
13485+ LOCK_PREFIX "addq %1,%0\n"
13486+ "int $4\n0:\n"
13487+ _ASM_EXTABLE(0b, 0b)
13488+#endif
13489+
13490+ : "=m" (v->counter)
13491+ : "er" (i), "m" (v->counter));
13492+}
13493+
13494+/**
13495+ * atomic64_sub_unchecked - subtract the atomic64 variable
13496+ * @i: integer value to subtract
13497+ * @v: pointer to type atomic64_unchecked_t
13498+ *
13499+ * Atomically subtracts @i from @v.
13500+ */
13501+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
13502+{
13503+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
13504 : "=m" (v->counter)
13505 : "er" (i), "m" (v->counter));
13506 }
13507@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
13508 {
13509 unsigned char c;
13510
13511- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
13512+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
13513+
13514+#ifdef CONFIG_PAX_REFCOUNT
13515+ "jno 0f\n"
13516+ LOCK_PREFIX "addq %2,%0\n"
13517+ "int $4\n0:\n"
13518+ _ASM_EXTABLE(0b, 0b)
13519+#endif
13520+
13521+ "sete %1\n"
13522 : "=m" (v->counter), "=qm" (c)
13523 : "er" (i), "m" (v->counter) : "memory");
13524 return c;
13525@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
13526 */
13527 static inline void atomic64_inc(atomic64_t *v)
13528 {
13529+ asm volatile(LOCK_PREFIX "incq %0\n"
13530+
13531+#ifdef CONFIG_PAX_REFCOUNT
13532+ "jno 0f\n"
13533+ LOCK_PREFIX "decq %0\n"
13534+ "int $4\n0:\n"
13535+ _ASM_EXTABLE(0b, 0b)
13536+#endif
13537+
13538+ : "=m" (v->counter)
13539+ : "m" (v->counter));
13540+}
13541+
13542+/**
13543+ * atomic64_inc_unchecked - increment atomic64 variable
13544+ * @v: pointer to type atomic64_unchecked_t
13545+ *
13546+ * Atomically increments @v by 1.
13547+ */
13548+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
13549+{
13550 asm volatile(LOCK_PREFIX "incq %0"
13551 : "=m" (v->counter)
13552 : "m" (v->counter));
13553@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
13554 */
13555 static inline void atomic64_dec(atomic64_t *v)
13556 {
13557- asm volatile(LOCK_PREFIX "decq %0"
13558+ asm volatile(LOCK_PREFIX "decq %0\n"
13559+
13560+#ifdef CONFIG_PAX_REFCOUNT
13561+ "jno 0f\n"
13562+ LOCK_PREFIX "incq %0\n"
13563+ "int $4\n0:\n"
13564+ _ASM_EXTABLE(0b, 0b)
13565+#endif
13566+
13567+ : "=m" (v->counter)
13568+ : "m" (v->counter));
13569+}
13570+
13571+/**
13572+ * atomic64_dec_unchecked - decrement atomic64 variable
13573+ * @v: pointer to type atomic64_t
13574+ *
13575+ * Atomically decrements @v by 1.
13576+ */
13577+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
13578+{
13579+ asm volatile(LOCK_PREFIX "decq %0\n"
13580 : "=m" (v->counter)
13581 : "m" (v->counter));
13582 }
13583@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
13584 {
13585 unsigned char c;
13586
13587- asm volatile(LOCK_PREFIX "decq %0; sete %1"
13588+ asm volatile(LOCK_PREFIX "decq %0\n"
13589+
13590+#ifdef CONFIG_PAX_REFCOUNT
13591+ "jno 0f\n"
13592+ LOCK_PREFIX "incq %0\n"
13593+ "int $4\n0:\n"
13594+ _ASM_EXTABLE(0b, 0b)
13595+#endif
13596+
13597+ "sete %1\n"
13598 : "=m" (v->counter), "=qm" (c)
13599 : "m" (v->counter) : "memory");
13600 return c != 0;
13601@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
13602 {
13603 unsigned char c;
13604
13605- asm volatile(LOCK_PREFIX "incq %0; sete %1"
13606+ asm volatile(LOCK_PREFIX "incq %0\n"
13607+
13608+#ifdef CONFIG_PAX_REFCOUNT
13609+ "jno 0f\n"
13610+ LOCK_PREFIX "decq %0\n"
13611+ "int $4\n0:\n"
13612+ _ASM_EXTABLE(0b, 0b)
13613+#endif
13614+
13615+ "sete %1\n"
13616 : "=m" (v->counter), "=qm" (c)
13617 : "m" (v->counter) : "memory");
13618 return c != 0;
13619@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
13620 {
13621 unsigned char c;
13622
13623- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
13624+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
13625+
13626+#ifdef CONFIG_PAX_REFCOUNT
13627+ "jno 0f\n"
13628+ LOCK_PREFIX "subq %2,%0\n"
13629+ "int $4\n0:\n"
13630+ _ASM_EXTABLE(0b, 0b)
13631+#endif
13632+
13633+ "sets %1\n"
13634 : "=m" (v->counter), "=qm" (c)
13635 : "er" (i), "m" (v->counter) : "memory");
13636 return c;
13637@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
13638 */
13639 static inline long atomic64_add_return(long i, atomic64_t *v)
13640 {
13641+ return i + xadd_check_overflow(&v->counter, i);
13642+}
13643+
13644+/**
13645+ * atomic64_add_return_unchecked - add and return
13646+ * @i: integer value to add
13647+ * @v: pointer to type atomic64_unchecked_t
13648+ *
13649+ * Atomically adds @i to @v and returns @i + @v
13650+ */
13651+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
13652+{
13653 return i + xadd(&v->counter, i);
13654 }
13655
13656@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
13657 }
13658
13659 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
13660+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
13661+{
13662+ return atomic64_add_return_unchecked(1, v);
13663+}
13664 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
13665
13666 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
13667@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
13668 return cmpxchg(&v->counter, old, new);
13669 }
13670
13671+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
13672+{
13673+ return cmpxchg(&v->counter, old, new);
13674+}
13675+
13676 static inline long atomic64_xchg(atomic64_t *v, long new)
13677 {
13678 return xchg(&v->counter, new);
13679@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
13680 */
13681 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
13682 {
13683- long c, old;
13684+ long c, old, new;
13685 c = atomic64_read(v);
13686 for (;;) {
13687- if (unlikely(c == (u)))
13688+ if (unlikely(c == u))
13689 break;
13690- old = atomic64_cmpxchg((v), c, c + (a));
13691+
13692+ asm volatile("add %2,%0\n"
13693+
13694+#ifdef CONFIG_PAX_REFCOUNT
13695+ "jno 0f\n"
13696+ "sub %2,%0\n"
13697+ "int $4\n0:\n"
13698+ _ASM_EXTABLE(0b, 0b)
13699+#endif
13700+
13701+ : "=r" (new)
13702+ : "0" (c), "ir" (a));
13703+
13704+ old = atomic64_cmpxchg(v, c, new);
13705 if (likely(old == c))
13706 break;
13707 c = old;
13708 }
13709- return c != (u);
13710+ return c != u;
13711 }
13712
13713 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
13714diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
13715index 6dfd019..28e188d 100644
13716--- a/arch/x86/include/asm/bitops.h
13717+++ b/arch/x86/include/asm/bitops.h
13718@@ -40,7 +40,7 @@
13719 * a mask operation on a byte.
13720 */
13721 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
13722-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
13723+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
13724 #define CONST_MASK(nr) (1 << ((nr) & 7))
13725
13726 /**
13727@@ -486,7 +486,7 @@ static inline int fls(int x)
13728 * at position 64.
13729 */
13730 #ifdef CONFIG_X86_64
13731-static __always_inline int fls64(__u64 x)
13732+static __always_inline long fls64(__u64 x)
13733 {
13734 int bitpos = -1;
13735 /*
13736diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
13737index 4fa687a..60f2d39 100644
13738--- a/arch/x86/include/asm/boot.h
13739+++ b/arch/x86/include/asm/boot.h
13740@@ -6,10 +6,15 @@
13741 #include <uapi/asm/boot.h>
13742
13743 /* Physical address where kernel should be loaded. */
13744-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
13745+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
13746 + (CONFIG_PHYSICAL_ALIGN - 1)) \
13747 & ~(CONFIG_PHYSICAL_ALIGN - 1))
13748
13749+#ifndef __ASSEMBLY__
13750+extern unsigned char __LOAD_PHYSICAL_ADDR[];
13751+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
13752+#endif
13753+
13754 /* Minimum kernel alignment, as a power of two */
13755 #ifdef CONFIG_X86_64
13756 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
13757diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
13758index 48f99f1..d78ebf9 100644
13759--- a/arch/x86/include/asm/cache.h
13760+++ b/arch/x86/include/asm/cache.h
13761@@ -5,12 +5,13 @@
13762
13763 /* L1 cache line size */
13764 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
13765-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
13766+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
13767
13768 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
13769+#define __read_only __attribute__((__section__(".data..read_only")))
13770
13771 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
13772-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
13773+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
13774
13775 #ifdef CONFIG_X86_VSMP
13776 #ifdef CONFIG_SMP
13777diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
13778index 9863ee3..4a1f8e1 100644
13779--- a/arch/x86/include/asm/cacheflush.h
13780+++ b/arch/x86/include/asm/cacheflush.h
13781@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
13782 unsigned long pg_flags = pg->flags & _PGMT_MASK;
13783
13784 if (pg_flags == _PGMT_DEFAULT)
13785- return -1;
13786+ return ~0UL;
13787 else if (pg_flags == _PGMT_WC)
13788 return _PAGE_CACHE_WC;
13789 else if (pg_flags == _PGMT_UC_MINUS)
13790diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
13791index 46fc474..b02b0f9 100644
13792--- a/arch/x86/include/asm/checksum_32.h
13793+++ b/arch/x86/include/asm/checksum_32.h
13794@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
13795 int len, __wsum sum,
13796 int *src_err_ptr, int *dst_err_ptr);
13797
13798+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
13799+ int len, __wsum sum,
13800+ int *src_err_ptr, int *dst_err_ptr);
13801+
13802+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
13803+ int len, __wsum sum,
13804+ int *src_err_ptr, int *dst_err_ptr);
13805+
13806 /*
13807 * Note: when you get a NULL pointer exception here this means someone
13808 * passed in an incorrect kernel address to one of these functions.
13809@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
13810 int *err_ptr)
13811 {
13812 might_sleep();
13813- return csum_partial_copy_generic((__force void *)src, dst,
13814+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
13815 len, sum, err_ptr, NULL);
13816 }
13817
13818@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
13819 {
13820 might_sleep();
13821 if (access_ok(VERIFY_WRITE, dst, len))
13822- return csum_partial_copy_generic(src, (__force void *)dst,
13823+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
13824 len, sum, NULL, err_ptr);
13825
13826 if (len)
13827diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
13828index 8d871ea..c1a0dc9 100644
13829--- a/arch/x86/include/asm/cmpxchg.h
13830+++ b/arch/x86/include/asm/cmpxchg.h
13831@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
13832 __compiletime_error("Bad argument size for cmpxchg");
13833 extern void __xadd_wrong_size(void)
13834 __compiletime_error("Bad argument size for xadd");
13835+extern void __xadd_check_overflow_wrong_size(void)
13836+ __compiletime_error("Bad argument size for xadd_check_overflow");
13837 extern void __add_wrong_size(void)
13838 __compiletime_error("Bad argument size for add");
13839+extern void __add_check_overflow_wrong_size(void)
13840+ __compiletime_error("Bad argument size for add_check_overflow");
13841
13842 /*
13843 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
13844@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
13845 __ret; \
13846 })
13847
13848+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
13849+ ({ \
13850+ __typeof__ (*(ptr)) __ret = (arg); \
13851+ switch (sizeof(*(ptr))) { \
13852+ case __X86_CASE_L: \
13853+ asm volatile (lock #op "l %0, %1\n" \
13854+ "jno 0f\n" \
13855+ "mov %0,%1\n" \
13856+ "int $4\n0:\n" \
13857+ _ASM_EXTABLE(0b, 0b) \
13858+ : "+r" (__ret), "+m" (*(ptr)) \
13859+ : : "memory", "cc"); \
13860+ break; \
13861+ case __X86_CASE_Q: \
13862+ asm volatile (lock #op "q %q0, %1\n" \
13863+ "jno 0f\n" \
13864+ "mov %0,%1\n" \
13865+ "int $4\n0:\n" \
13866+ _ASM_EXTABLE(0b, 0b) \
13867+ : "+r" (__ret), "+m" (*(ptr)) \
13868+ : : "memory", "cc"); \
13869+ break; \
13870+ default: \
13871+ __ ## op ## _check_overflow_wrong_size(); \
13872+ } \
13873+ __ret; \
13874+ })
13875+
13876 /*
13877 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
13878 * Since this is generally used to protect other memory information, we
13879@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
13880 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
13881 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
13882
13883+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
13884+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
13885+
13886 #define __add(ptr, inc, lock) \
13887 ({ \
13888 __typeof__ (*(ptr)) __ret = (inc); \
13889diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
13890index 59c6c40..5e0b22c 100644
13891--- a/arch/x86/include/asm/compat.h
13892+++ b/arch/x86/include/asm/compat.h
13893@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
13894 typedef u32 compat_uint_t;
13895 typedef u32 compat_ulong_t;
13896 typedef u64 __attribute__((aligned(4))) compat_u64;
13897-typedef u32 compat_uptr_t;
13898+typedef u32 __user compat_uptr_t;
13899
13900 struct compat_timespec {
13901 compat_time_t tv_sec;
13902diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
13903index 2d9075e..b75a844 100644
13904--- a/arch/x86/include/asm/cpufeature.h
13905+++ b/arch/x86/include/asm/cpufeature.h
13906@@ -206,7 +206,7 @@
13907 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
13908 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
13909 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
13910-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
13911+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
13912 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
13913 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
13914 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
13915@@ -375,7 +375,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
13916 ".section .discard,\"aw\",@progbits\n"
13917 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
13918 ".previous\n"
13919- ".section .altinstr_replacement,\"ax\"\n"
13920+ ".section .altinstr_replacement,\"a\"\n"
13921 "3: movb $1,%0\n"
13922 "4:\n"
13923 ".previous\n"
13924diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
13925index 8bf1c06..b6ae785 100644
13926--- a/arch/x86/include/asm/desc.h
13927+++ b/arch/x86/include/asm/desc.h
13928@@ -4,6 +4,7 @@
13929 #include <asm/desc_defs.h>
13930 #include <asm/ldt.h>
13931 #include <asm/mmu.h>
13932+#include <asm/pgtable.h>
13933
13934 #include <linux/smp.h>
13935 #include <linux/percpu.h>
13936@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
13937
13938 desc->type = (info->read_exec_only ^ 1) << 1;
13939 desc->type |= info->contents << 2;
13940+ desc->type |= info->seg_not_present ^ 1;
13941
13942 desc->s = 1;
13943 desc->dpl = 0x3;
13944@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
13945 }
13946
13947 extern struct desc_ptr idt_descr;
13948-extern gate_desc idt_table[];
13949 extern struct desc_ptr nmi_idt_descr;
13950-extern gate_desc nmi_idt_table[];
13951-
13952-struct gdt_page {
13953- struct desc_struct gdt[GDT_ENTRIES];
13954-} __attribute__((aligned(PAGE_SIZE)));
13955-
13956-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
13957+extern gate_desc idt_table[256];
13958+extern gate_desc nmi_idt_table[256];
13959
13960+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
13961 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
13962 {
13963- return per_cpu(gdt_page, cpu).gdt;
13964+ return cpu_gdt_table[cpu];
13965 }
13966
13967 #ifdef CONFIG_X86_64
13968@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
13969 unsigned long base, unsigned dpl, unsigned flags,
13970 unsigned short seg)
13971 {
13972- gate->a = (seg << 16) | (base & 0xffff);
13973- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
13974+ gate->gate.offset_low = base;
13975+ gate->gate.seg = seg;
13976+ gate->gate.reserved = 0;
13977+ gate->gate.type = type;
13978+ gate->gate.s = 0;
13979+ gate->gate.dpl = dpl;
13980+ gate->gate.p = 1;
13981+ gate->gate.offset_high = base >> 16;
13982 }
13983
13984 #endif
13985@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
13986
13987 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
13988 {
13989+ pax_open_kernel();
13990 memcpy(&idt[entry], gate, sizeof(*gate));
13991+ pax_close_kernel();
13992 }
13993
13994 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
13995 {
13996+ pax_open_kernel();
13997 memcpy(&ldt[entry], desc, 8);
13998+ pax_close_kernel();
13999 }
14000
14001 static inline void
14002@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
14003 default: size = sizeof(*gdt); break;
14004 }
14005
14006+ pax_open_kernel();
14007 memcpy(&gdt[entry], desc, size);
14008+ pax_close_kernel();
14009 }
14010
14011 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
14012@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
14013
14014 static inline void native_load_tr_desc(void)
14015 {
14016+ pax_open_kernel();
14017 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
14018+ pax_close_kernel();
14019 }
14020
14021 static inline void native_load_gdt(const struct desc_ptr *dtr)
14022@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
14023 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
14024 unsigned int i;
14025
14026+ pax_open_kernel();
14027 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
14028 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
14029+ pax_close_kernel();
14030 }
14031
14032 #define _LDT_empty(info) \
14033@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
14034 preempt_enable();
14035 }
14036
14037-static inline unsigned long get_desc_base(const struct desc_struct *desc)
14038+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
14039 {
14040 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
14041 }
14042@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
14043 }
14044
14045 #ifdef CONFIG_X86_64
14046-static inline void set_nmi_gate(int gate, void *addr)
14047+static inline void set_nmi_gate(int gate, const void *addr)
14048 {
14049 gate_desc s;
14050
14051@@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
14052 }
14053 #endif
14054
14055-static inline void _set_gate(int gate, unsigned type, void *addr,
14056+static inline void _set_gate(int gate, unsigned type, const void *addr,
14057 unsigned dpl, unsigned ist, unsigned seg)
14058 {
14059 gate_desc s;
14060@@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
14061 * Pentium F0 0F bugfix can have resulted in the mapped
14062 * IDT being write-protected.
14063 */
14064-static inline void set_intr_gate(unsigned int n, void *addr)
14065+static inline void set_intr_gate(unsigned int n, const void *addr)
14066 {
14067 BUG_ON((unsigned)n > 0xFF);
14068 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
14069@@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
14070 /*
14071 * This routine sets up an interrupt gate at directory privilege level 3.
14072 */
14073-static inline void set_system_intr_gate(unsigned int n, void *addr)
14074+static inline void set_system_intr_gate(unsigned int n, const void *addr)
14075 {
14076 BUG_ON((unsigned)n > 0xFF);
14077 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
14078 }
14079
14080-static inline void set_system_trap_gate(unsigned int n, void *addr)
14081+static inline void set_system_trap_gate(unsigned int n, const void *addr)
14082 {
14083 BUG_ON((unsigned)n > 0xFF);
14084 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
14085 }
14086
14087-static inline void set_trap_gate(unsigned int n, void *addr)
14088+static inline void set_trap_gate(unsigned int n, const void *addr)
14089 {
14090 BUG_ON((unsigned)n > 0xFF);
14091 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
14092@@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
14093 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
14094 {
14095 BUG_ON((unsigned)n > 0xFF);
14096- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
14097+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
14098 }
14099
14100-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
14101+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
14102 {
14103 BUG_ON((unsigned)n > 0xFF);
14104 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
14105 }
14106
14107-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
14108+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
14109 {
14110 BUG_ON((unsigned)n > 0xFF);
14111 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
14112 }
14113
14114+#ifdef CONFIG_X86_32
14115+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
14116+{
14117+ struct desc_struct d;
14118+
14119+ if (likely(limit))
14120+ limit = (limit - 1UL) >> PAGE_SHIFT;
14121+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
14122+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
14123+}
14124+#endif
14125+
14126 #endif /* _ASM_X86_DESC_H */
14127diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
14128index 278441f..b95a174 100644
14129--- a/arch/x86/include/asm/desc_defs.h
14130+++ b/arch/x86/include/asm/desc_defs.h
14131@@ -31,6 +31,12 @@ struct desc_struct {
14132 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
14133 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
14134 };
14135+ struct {
14136+ u16 offset_low;
14137+ u16 seg;
14138+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
14139+ unsigned offset_high: 16;
14140+ } gate;
14141 };
14142 } __attribute__((packed));
14143
14144diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
14145index ced283a..ffe04cc 100644
14146--- a/arch/x86/include/asm/div64.h
14147+++ b/arch/x86/include/asm/div64.h
14148@@ -39,7 +39,7 @@
14149 __mod; \
14150 })
14151
14152-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
14153+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
14154 {
14155 union {
14156 u64 v64;
14157diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
14158index 9c999c1..3860cb8 100644
14159--- a/arch/x86/include/asm/elf.h
14160+++ b/arch/x86/include/asm/elf.h
14161@@ -243,7 +243,25 @@ extern int force_personality32;
14162 the loader. We need to make sure that it is out of the way of the program
14163 that it will "exec", and that there is sufficient room for the brk. */
14164
14165+#ifdef CONFIG_PAX_SEGMEXEC
14166+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
14167+#else
14168 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
14169+#endif
14170+
14171+#ifdef CONFIG_PAX_ASLR
14172+#ifdef CONFIG_X86_32
14173+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
14174+
14175+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
14176+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
14177+#else
14178+#define PAX_ELF_ET_DYN_BASE 0x400000UL
14179+
14180+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
14181+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
14182+#endif
14183+#endif
14184
14185 /* This yields a mask that user programs can use to figure out what
14186 instruction set this CPU supports. This could be done in user space,
14187@@ -296,16 +314,12 @@ do { \
14188
14189 #define ARCH_DLINFO \
14190 do { \
14191- if (vdso_enabled) \
14192- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
14193- (unsigned long)current->mm->context.vdso); \
14194+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
14195 } while (0)
14196
14197 #define ARCH_DLINFO_X32 \
14198 do { \
14199- if (vdso_enabled) \
14200- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
14201- (unsigned long)current->mm->context.vdso); \
14202+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
14203 } while (0)
14204
14205 #define AT_SYSINFO 32
14206@@ -320,7 +334,7 @@ else \
14207
14208 #endif /* !CONFIG_X86_32 */
14209
14210-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
14211+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
14212
14213 #define VDSO_ENTRY \
14214 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
14215@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
14216 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
14217 #define compat_arch_setup_additional_pages syscall32_setup_pages
14218
14219-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
14220-#define arch_randomize_brk arch_randomize_brk
14221-
14222 /*
14223 * True on X86_32 or when emulating IA32 on X86_64
14224 */
14225diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
14226index 75ce3f4..882e801 100644
14227--- a/arch/x86/include/asm/emergency-restart.h
14228+++ b/arch/x86/include/asm/emergency-restart.h
14229@@ -13,6 +13,6 @@ enum reboot_type {
14230
14231 extern enum reboot_type reboot_type;
14232
14233-extern void machine_emergency_restart(void);
14234+extern void machine_emergency_restart(void) __noreturn;
14235
14236 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
14237diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
14238index 41ab26e..a88c9e6 100644
14239--- a/arch/x86/include/asm/fpu-internal.h
14240+++ b/arch/x86/include/asm/fpu-internal.h
14241@@ -126,7 +126,9 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
14242 ({ \
14243 int err; \
14244 asm volatile(ASM_STAC "\n" \
14245- "1:" #insn "\n\t" \
14246+ "1:" \
14247+ __copyuser_seg \
14248+ #insn "\n\t" \
14249 "2: " ASM_CLAC "\n" \
14250 ".section .fixup,\"ax\"\n" \
14251 "3: movl $-1,%[err]\n" \
14252@@ -299,7 +301,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
14253 "emms\n\t" /* clear stack tags */
14254 "fildl %P[addr]", /* set F?P to defined value */
14255 X86_FEATURE_FXSAVE_LEAK,
14256- [addr] "m" (tsk->thread.fpu.has_fpu));
14257+ [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
14258
14259 return fpu_restore_checking(&tsk->thread.fpu);
14260 }
14261diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
14262index be27ba1..8f13ff9 100644
14263--- a/arch/x86/include/asm/futex.h
14264+++ b/arch/x86/include/asm/futex.h
14265@@ -12,6 +12,7 @@
14266 #include <asm/smap.h>
14267
14268 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
14269+ typecheck(u32 __user *, uaddr); \
14270 asm volatile("\t" ASM_STAC "\n" \
14271 "1:\t" insn "\n" \
14272 "2:\t" ASM_CLAC "\n" \
14273@@ -20,15 +21,16 @@
14274 "\tjmp\t2b\n" \
14275 "\t.previous\n" \
14276 _ASM_EXTABLE(1b, 3b) \
14277- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
14278+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
14279 : "i" (-EFAULT), "0" (oparg), "1" (0))
14280
14281 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
14282+ typecheck(u32 __user *, uaddr); \
14283 asm volatile("\t" ASM_STAC "\n" \
14284 "1:\tmovl %2, %0\n" \
14285 "\tmovl\t%0, %3\n" \
14286 "\t" insn "\n" \
14287- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
14288+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
14289 "\tjnz\t1b\n" \
14290 "3:\t" ASM_CLAC "\n" \
14291 "\t.section .fixup,\"ax\"\n" \
14292@@ -38,7 +40,7 @@
14293 _ASM_EXTABLE(1b, 4b) \
14294 _ASM_EXTABLE(2b, 4b) \
14295 : "=&a" (oldval), "=&r" (ret), \
14296- "+m" (*uaddr), "=&r" (tem) \
14297+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
14298 : "r" (oparg), "i" (-EFAULT), "1" (0))
14299
14300 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
14301@@ -59,10 +61,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
14302
14303 switch (op) {
14304 case FUTEX_OP_SET:
14305- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
14306+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
14307 break;
14308 case FUTEX_OP_ADD:
14309- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
14310+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
14311 uaddr, oparg);
14312 break;
14313 case FUTEX_OP_OR:
14314@@ -116,14 +118,14 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
14315 return -EFAULT;
14316
14317 asm volatile("\t" ASM_STAC "\n"
14318- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
14319+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
14320 "2:\t" ASM_CLAC "\n"
14321 "\t.section .fixup, \"ax\"\n"
14322 "3:\tmov %3, %0\n"
14323 "\tjmp 2b\n"
14324 "\t.previous\n"
14325 _ASM_EXTABLE(1b, 3b)
14326- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
14327+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
14328 : "i" (-EFAULT), "r" (newval), "1" (oldval)
14329 : "memory"
14330 );
14331diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
14332index eb92a6e..b98b2f4 100644
14333--- a/arch/x86/include/asm/hw_irq.h
14334+++ b/arch/x86/include/asm/hw_irq.h
14335@@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
14336 extern void enable_IO_APIC(void);
14337
14338 /* Statistics */
14339-extern atomic_t irq_err_count;
14340-extern atomic_t irq_mis_count;
14341+extern atomic_unchecked_t irq_err_count;
14342+extern atomic_unchecked_t irq_mis_count;
14343
14344 /* EISA */
14345 extern void eisa_set_level_irq(unsigned int irq);
14346diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
14347index a203659..9889f1c 100644
14348--- a/arch/x86/include/asm/i8259.h
14349+++ b/arch/x86/include/asm/i8259.h
14350@@ -62,7 +62,7 @@ struct legacy_pic {
14351 void (*init)(int auto_eoi);
14352 int (*irq_pending)(unsigned int irq);
14353 void (*make_irq)(unsigned int irq);
14354-};
14355+} __do_const;
14356
14357 extern struct legacy_pic *legacy_pic;
14358 extern struct legacy_pic null_legacy_pic;
14359diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
14360index d8e8eef..1765f78 100644
14361--- a/arch/x86/include/asm/io.h
14362+++ b/arch/x86/include/asm/io.h
14363@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
14364 "m" (*(volatile type __force *)addr) barrier); }
14365
14366 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
14367-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
14368-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
14369+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
14370+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
14371
14372 build_mmio_read(__readb, "b", unsigned char, "=q", )
14373-build_mmio_read(__readw, "w", unsigned short, "=r", )
14374-build_mmio_read(__readl, "l", unsigned int, "=r", )
14375+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
14376+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
14377
14378 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
14379 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
14380@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
14381 return ioremap_nocache(offset, size);
14382 }
14383
14384-extern void iounmap(volatile void __iomem *addr);
14385+extern void iounmap(const volatile void __iomem *addr);
14386
14387 extern void set_iounmap_nonlazy(void);
14388
14389@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
14390
14391 #include <linux/vmalloc.h>
14392
14393+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
14394+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
14395+{
14396+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
14397+}
14398+
14399+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
14400+{
14401+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
14402+}
14403+
14404 /*
14405 * Convert a virtual cached pointer to an uncached pointer
14406 */
14407diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
14408index bba3cf8..06bc8da 100644
14409--- a/arch/x86/include/asm/irqflags.h
14410+++ b/arch/x86/include/asm/irqflags.h
14411@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
14412 sti; \
14413 sysexit
14414
14415+#define GET_CR0_INTO_RDI mov %cr0, %rdi
14416+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
14417+#define GET_CR3_INTO_RDI mov %cr3, %rdi
14418+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
14419+
14420 #else
14421 #define INTERRUPT_RETURN iret
14422 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
14423diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
14424index d3ddd17..c9fb0cc 100644
14425--- a/arch/x86/include/asm/kprobes.h
14426+++ b/arch/x86/include/asm/kprobes.h
14427@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
14428 #define RELATIVEJUMP_SIZE 5
14429 #define RELATIVECALL_OPCODE 0xe8
14430 #define RELATIVE_ADDR_SIZE 4
14431-#define MAX_STACK_SIZE 64
14432-#define MIN_STACK_SIZE(ADDR) \
14433- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
14434- THREAD_SIZE - (unsigned long)(ADDR))) \
14435- ? (MAX_STACK_SIZE) \
14436- : (((unsigned long)current_thread_info()) + \
14437- THREAD_SIZE - (unsigned long)(ADDR)))
14438+#define MAX_STACK_SIZE 64UL
14439+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
14440
14441 #define flush_insn_slot(p) do { } while (0)
14442
14443diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
14444index dc87b65..85039f9 100644
14445--- a/arch/x86/include/asm/kvm_host.h
14446+++ b/arch/x86/include/asm/kvm_host.h
14447@@ -419,8 +419,8 @@ struct kvm_vcpu_arch {
14448 gpa_t time;
14449 struct pvclock_vcpu_time_info hv_clock;
14450 unsigned int hw_tsc_khz;
14451- unsigned int time_offset;
14452- struct page *time_page;
14453+ struct gfn_to_hva_cache pv_time;
14454+ bool pv_time_enabled;
14455 /* set guest stopped flag in pvclock flags field */
14456 bool pvclock_set_guest_stopped_request;
14457
14458diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
14459index 2d89e39..baee879 100644
14460--- a/arch/x86/include/asm/local.h
14461+++ b/arch/x86/include/asm/local.h
14462@@ -10,33 +10,97 @@ typedef struct {
14463 atomic_long_t a;
14464 } local_t;
14465
14466+typedef struct {
14467+ atomic_long_unchecked_t a;
14468+} local_unchecked_t;
14469+
14470 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
14471
14472 #define local_read(l) atomic_long_read(&(l)->a)
14473+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
14474 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
14475+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
14476
14477 static inline void local_inc(local_t *l)
14478 {
14479- asm volatile(_ASM_INC "%0"
14480+ asm volatile(_ASM_INC "%0\n"
14481+
14482+#ifdef CONFIG_PAX_REFCOUNT
14483+ "jno 0f\n"
14484+ _ASM_DEC "%0\n"
14485+ "int $4\n0:\n"
14486+ _ASM_EXTABLE(0b, 0b)
14487+#endif
14488+
14489+ : "+m" (l->a.counter));
14490+}
14491+
14492+static inline void local_inc_unchecked(local_unchecked_t *l)
14493+{
14494+ asm volatile(_ASM_INC "%0\n"
14495 : "+m" (l->a.counter));
14496 }
14497
14498 static inline void local_dec(local_t *l)
14499 {
14500- asm volatile(_ASM_DEC "%0"
14501+ asm volatile(_ASM_DEC "%0\n"
14502+
14503+#ifdef CONFIG_PAX_REFCOUNT
14504+ "jno 0f\n"
14505+ _ASM_INC "%0\n"
14506+ "int $4\n0:\n"
14507+ _ASM_EXTABLE(0b, 0b)
14508+#endif
14509+
14510+ : "+m" (l->a.counter));
14511+}
14512+
14513+static inline void local_dec_unchecked(local_unchecked_t *l)
14514+{
14515+ asm volatile(_ASM_DEC "%0\n"
14516 : "+m" (l->a.counter));
14517 }
14518
14519 static inline void local_add(long i, local_t *l)
14520 {
14521- asm volatile(_ASM_ADD "%1,%0"
14522+ asm volatile(_ASM_ADD "%1,%0\n"
14523+
14524+#ifdef CONFIG_PAX_REFCOUNT
14525+ "jno 0f\n"
14526+ _ASM_SUB "%1,%0\n"
14527+ "int $4\n0:\n"
14528+ _ASM_EXTABLE(0b, 0b)
14529+#endif
14530+
14531+ : "+m" (l->a.counter)
14532+ : "ir" (i));
14533+}
14534+
14535+static inline void local_add_unchecked(long i, local_unchecked_t *l)
14536+{
14537+ asm volatile(_ASM_ADD "%1,%0\n"
14538 : "+m" (l->a.counter)
14539 : "ir" (i));
14540 }
14541
14542 static inline void local_sub(long i, local_t *l)
14543 {
14544- asm volatile(_ASM_SUB "%1,%0"
14545+ asm volatile(_ASM_SUB "%1,%0\n"
14546+
14547+#ifdef CONFIG_PAX_REFCOUNT
14548+ "jno 0f\n"
14549+ _ASM_ADD "%1,%0\n"
14550+ "int $4\n0:\n"
14551+ _ASM_EXTABLE(0b, 0b)
14552+#endif
14553+
14554+ : "+m" (l->a.counter)
14555+ : "ir" (i));
14556+}
14557+
14558+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
14559+{
14560+ asm volatile(_ASM_SUB "%1,%0\n"
14561 : "+m" (l->a.counter)
14562 : "ir" (i));
14563 }
14564@@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
14565 {
14566 unsigned char c;
14567
14568- asm volatile(_ASM_SUB "%2,%0; sete %1"
14569+ asm volatile(_ASM_SUB "%2,%0\n"
14570+
14571+#ifdef CONFIG_PAX_REFCOUNT
14572+ "jno 0f\n"
14573+ _ASM_ADD "%2,%0\n"
14574+ "int $4\n0:\n"
14575+ _ASM_EXTABLE(0b, 0b)
14576+#endif
14577+
14578+ "sete %1\n"
14579 : "+m" (l->a.counter), "=qm" (c)
14580 : "ir" (i) : "memory");
14581 return c;
14582@@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
14583 {
14584 unsigned char c;
14585
14586- asm volatile(_ASM_DEC "%0; sete %1"
14587+ asm volatile(_ASM_DEC "%0\n"
14588+
14589+#ifdef CONFIG_PAX_REFCOUNT
14590+ "jno 0f\n"
14591+ _ASM_INC "%0\n"
14592+ "int $4\n0:\n"
14593+ _ASM_EXTABLE(0b, 0b)
14594+#endif
14595+
14596+ "sete %1\n"
14597 : "+m" (l->a.counter), "=qm" (c)
14598 : : "memory");
14599 return c != 0;
14600@@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
14601 {
14602 unsigned char c;
14603
14604- asm volatile(_ASM_INC "%0; sete %1"
14605+ asm volatile(_ASM_INC "%0\n"
14606+
14607+#ifdef CONFIG_PAX_REFCOUNT
14608+ "jno 0f\n"
14609+ _ASM_DEC "%0\n"
14610+ "int $4\n0:\n"
14611+ _ASM_EXTABLE(0b, 0b)
14612+#endif
14613+
14614+ "sete %1\n"
14615 : "+m" (l->a.counter), "=qm" (c)
14616 : : "memory");
14617 return c != 0;
14618@@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
14619 {
14620 unsigned char c;
14621
14622- asm volatile(_ASM_ADD "%2,%0; sets %1"
14623+ asm volatile(_ASM_ADD "%2,%0\n"
14624+
14625+#ifdef CONFIG_PAX_REFCOUNT
14626+ "jno 0f\n"
14627+ _ASM_SUB "%2,%0\n"
14628+ "int $4\n0:\n"
14629+ _ASM_EXTABLE(0b, 0b)
14630+#endif
14631+
14632+ "sets %1\n"
14633 : "+m" (l->a.counter), "=qm" (c)
14634 : "ir" (i) : "memory");
14635 return c;
14636@@ -125,6 +225,30 @@ static inline int local_add_negative(long i, local_t *l)
14637 static inline long local_add_return(long i, local_t *l)
14638 {
14639 long __i = i;
14640+ asm volatile(_ASM_XADD "%0, %1\n"
14641+
14642+#ifdef CONFIG_PAX_REFCOUNT
14643+ "jno 0f\n"
14644+ _ASM_MOV "%0,%1\n"
14645+ "int $4\n0:\n"
14646+ _ASM_EXTABLE(0b, 0b)
14647+#endif
14648+
14649+ : "+r" (i), "+m" (l->a.counter)
14650+ : : "memory");
14651+ return i + __i;
14652+}
14653+
14654+/**
14655+ * local_add_return_unchecked - add and return
14656+ * @i: integer value to add
14657+ * @l: pointer to type local_unchecked_t
14658+ *
14659+ * Atomically adds @i to @l and returns @i + @l
14660+ */
14661+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
14662+{
14663+ long __i = i;
14664 asm volatile(_ASM_XADD "%0, %1;"
14665 : "+r" (i), "+m" (l->a.counter)
14666 : : "memory");
14667@@ -141,6 +265,8 @@ static inline long local_sub_return(long i, local_t *l)
14668
14669 #define local_cmpxchg(l, o, n) \
14670 (cmpxchg_local(&((l)->a.counter), (o), (n)))
14671+#define local_cmpxchg_unchecked(l, o, n) \
14672+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
14673 /* Always has a lock prefix */
14674 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
14675
14676diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
14677new file mode 100644
14678index 0000000..2bfd3ba
14679--- /dev/null
14680+++ b/arch/x86/include/asm/mman.h
14681@@ -0,0 +1,15 @@
14682+#ifndef _X86_MMAN_H
14683+#define _X86_MMAN_H
14684+
14685+#include <uapi/asm/mman.h>
14686+
14687+#ifdef __KERNEL__
14688+#ifndef __ASSEMBLY__
14689+#ifdef CONFIG_X86_32
14690+#define arch_mmap_check i386_mmap_check
14691+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
14692+#endif
14693+#endif
14694+#endif
14695+
14696+#endif /* X86_MMAN_H */
14697diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
14698index 5f55e69..e20bfb1 100644
14699--- a/arch/x86/include/asm/mmu.h
14700+++ b/arch/x86/include/asm/mmu.h
14701@@ -9,7 +9,7 @@
14702 * we put the segment information here.
14703 */
14704 typedef struct {
14705- void *ldt;
14706+ struct desc_struct *ldt;
14707 int size;
14708
14709 #ifdef CONFIG_X86_64
14710@@ -18,7 +18,19 @@ typedef struct {
14711 #endif
14712
14713 struct mutex lock;
14714- void *vdso;
14715+ unsigned long vdso;
14716+
14717+#ifdef CONFIG_X86_32
14718+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
14719+ unsigned long user_cs_base;
14720+ unsigned long user_cs_limit;
14721+
14722+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
14723+ cpumask_t cpu_user_cs_mask;
14724+#endif
14725+
14726+#endif
14727+#endif
14728 } mm_context_t;
14729
14730 #ifdef CONFIG_SMP
14731diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
14732index cdbf367..adb37ac 100644
14733--- a/arch/x86/include/asm/mmu_context.h
14734+++ b/arch/x86/include/asm/mmu_context.h
14735@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
14736
14737 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
14738 {
14739+
14740+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14741+ unsigned int i;
14742+ pgd_t *pgd;
14743+
14744+ pax_open_kernel();
14745+ pgd = get_cpu_pgd(smp_processor_id());
14746+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
14747+ set_pgd_batched(pgd+i, native_make_pgd(0));
14748+ pax_close_kernel();
14749+#endif
14750+
14751 #ifdef CONFIG_SMP
14752 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
14753 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
14754@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
14755 struct task_struct *tsk)
14756 {
14757 unsigned cpu = smp_processor_id();
14758+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
14759+ int tlbstate = TLBSTATE_OK;
14760+#endif
14761
14762 if (likely(prev != next)) {
14763 #ifdef CONFIG_SMP
14764+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
14765+ tlbstate = this_cpu_read(cpu_tlbstate.state);
14766+#endif
14767 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
14768 this_cpu_write(cpu_tlbstate.active_mm, next);
14769 #endif
14770 cpumask_set_cpu(cpu, mm_cpumask(next));
14771
14772 /* Re-load page tables */
14773+#ifdef CONFIG_PAX_PER_CPU_PGD
14774+ pax_open_kernel();
14775+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
14776+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
14777+ pax_close_kernel();
14778+ load_cr3(get_cpu_pgd(cpu));
14779+#else
14780 load_cr3(next->pgd);
14781+#endif
14782
14783 /* stop flush ipis for the previous mm */
14784 cpumask_clear_cpu(cpu, mm_cpumask(prev));
14785@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
14786 */
14787 if (unlikely(prev->context.ldt != next->context.ldt))
14788 load_LDT_nolock(&next->context);
14789- }
14790+
14791+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
14792+ if (!(__supported_pte_mask & _PAGE_NX)) {
14793+ smp_mb__before_clear_bit();
14794+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
14795+ smp_mb__after_clear_bit();
14796+ cpu_set(cpu, next->context.cpu_user_cs_mask);
14797+ }
14798+#endif
14799+
14800+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
14801+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
14802+ prev->context.user_cs_limit != next->context.user_cs_limit))
14803+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
14804 #ifdef CONFIG_SMP
14805+ else if (unlikely(tlbstate != TLBSTATE_OK))
14806+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
14807+#endif
14808+#endif
14809+
14810+ }
14811 else {
14812+
14813+#ifdef CONFIG_PAX_PER_CPU_PGD
14814+ pax_open_kernel();
14815+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
14816+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
14817+ pax_close_kernel();
14818+ load_cr3(get_cpu_pgd(cpu));
14819+#endif
14820+
14821+#ifdef CONFIG_SMP
14822 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
14823 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
14824
14825@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
14826 * tlb flush IPI delivery. We must reload CR3
14827 * to make sure to use no freed page tables.
14828 */
14829+
14830+#ifndef CONFIG_PAX_PER_CPU_PGD
14831 load_cr3(next->pgd);
14832+#endif
14833+
14834 load_LDT_nolock(&next->context);
14835+
14836+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
14837+ if (!(__supported_pte_mask & _PAGE_NX))
14838+ cpu_set(cpu, next->context.cpu_user_cs_mask);
14839+#endif
14840+
14841+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
14842+#ifdef CONFIG_PAX_PAGEEXEC
14843+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
14844+#endif
14845+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
14846+#endif
14847+
14848 }
14849+#endif
14850 }
14851-#endif
14852 }
14853
14854 #define activate_mm(prev, next) \
14855diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
14856index e3b7819..b257c64 100644
14857--- a/arch/x86/include/asm/module.h
14858+++ b/arch/x86/include/asm/module.h
14859@@ -5,6 +5,7 @@
14860
14861 #ifdef CONFIG_X86_64
14862 /* X86_64 does not define MODULE_PROC_FAMILY */
14863+#define MODULE_PROC_FAMILY ""
14864 #elif defined CONFIG_M486
14865 #define MODULE_PROC_FAMILY "486 "
14866 #elif defined CONFIG_M586
14867@@ -57,8 +58,20 @@
14868 #error unknown processor family
14869 #endif
14870
14871-#ifdef CONFIG_X86_32
14872-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
14873+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
14874+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
14875+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
14876+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
14877+#else
14878+#define MODULE_PAX_KERNEXEC ""
14879 #endif
14880
14881+#ifdef CONFIG_PAX_MEMORY_UDEREF
14882+#define MODULE_PAX_UDEREF "UDEREF "
14883+#else
14884+#define MODULE_PAX_UDEREF ""
14885+#endif
14886+
14887+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
14888+
14889 #endif /* _ASM_X86_MODULE_H */
14890diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
14891index c0fa356..07a498a 100644
14892--- a/arch/x86/include/asm/nmi.h
14893+++ b/arch/x86/include/asm/nmi.h
14894@@ -42,11 +42,11 @@ struct nmiaction {
14895 nmi_handler_t handler;
14896 unsigned long flags;
14897 const char *name;
14898-};
14899+} __do_const;
14900
14901 #define register_nmi_handler(t, fn, fg, n, init...) \
14902 ({ \
14903- static struct nmiaction init fn##_na = { \
14904+ static const struct nmiaction init fn##_na = { \
14905 .handler = (fn), \
14906 .name = (n), \
14907 .flags = (fg), \
14908@@ -54,7 +54,7 @@ struct nmiaction {
14909 __register_nmi_handler((t), &fn##_na); \
14910 })
14911
14912-int __register_nmi_handler(unsigned int, struct nmiaction *);
14913+int __register_nmi_handler(unsigned int, const struct nmiaction *);
14914
14915 void unregister_nmi_handler(unsigned int, const char *);
14916
14917diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
14918index 320f7bb..e89f8f8 100644
14919--- a/arch/x86/include/asm/page_64_types.h
14920+++ b/arch/x86/include/asm/page_64_types.h
14921@@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
14922
14923 /* duplicated to the one in bootmem.h */
14924 extern unsigned long max_pfn;
14925-extern unsigned long phys_base;
14926+extern const unsigned long phys_base;
14927
14928 extern unsigned long __phys_addr(unsigned long);
14929 #define __phys_reloc_hide(x) (x)
14930diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
14931index 7361e47..16dc226 100644
14932--- a/arch/x86/include/asm/paravirt.h
14933+++ b/arch/x86/include/asm/paravirt.h
14934@@ -564,7 +564,7 @@ static inline pmd_t __pmd(pmdval_t val)
14935 return (pmd_t) { ret };
14936 }
14937
14938-static inline pmdval_t pmd_val(pmd_t pmd)
14939+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
14940 {
14941 pmdval_t ret;
14942
14943@@ -630,6 +630,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
14944 val);
14945 }
14946
14947+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
14948+{
14949+ pgdval_t val = native_pgd_val(pgd);
14950+
14951+ if (sizeof(pgdval_t) > sizeof(long))
14952+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
14953+ val, (u64)val >> 32);
14954+ else
14955+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
14956+ val);
14957+}
14958+
14959 static inline void pgd_clear(pgd_t *pgdp)
14960 {
14961 set_pgd(pgdp, __pgd(0));
14962@@ -714,6 +726,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
14963 pv_mmu_ops.set_fixmap(idx, phys, flags);
14964 }
14965
14966+#ifdef CONFIG_PAX_KERNEXEC
14967+static inline unsigned long pax_open_kernel(void)
14968+{
14969+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
14970+}
14971+
14972+static inline unsigned long pax_close_kernel(void)
14973+{
14974+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
14975+}
14976+#else
14977+static inline unsigned long pax_open_kernel(void) { return 0; }
14978+static inline unsigned long pax_close_kernel(void) { return 0; }
14979+#endif
14980+
14981 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
14982
14983 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
14984@@ -930,7 +957,7 @@ extern void default_banner(void);
14985
14986 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
14987 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
14988-#define PARA_INDIRECT(addr) *%cs:addr
14989+#define PARA_INDIRECT(addr) *%ss:addr
14990 #endif
14991
14992 #define INTERRUPT_RETURN \
14993@@ -1005,6 +1032,21 @@ extern void default_banner(void);
14994 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
14995 CLBR_NONE, \
14996 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
14997+
14998+#define GET_CR0_INTO_RDI \
14999+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
15000+ mov %rax,%rdi
15001+
15002+#define SET_RDI_INTO_CR0 \
15003+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
15004+
15005+#define GET_CR3_INTO_RDI \
15006+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
15007+ mov %rax,%rdi
15008+
15009+#define SET_RDI_INTO_CR3 \
15010+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
15011+
15012 #endif /* CONFIG_X86_32 */
15013
15014 #endif /* __ASSEMBLY__ */
15015diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
15016index b3b0ec1..b1cd3eb 100644
15017--- a/arch/x86/include/asm/paravirt_types.h
15018+++ b/arch/x86/include/asm/paravirt_types.h
15019@@ -84,7 +84,7 @@ struct pv_init_ops {
15020 */
15021 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
15022 unsigned long addr, unsigned len);
15023-};
15024+} __no_const;
15025
15026
15027 struct pv_lazy_ops {
15028@@ -98,7 +98,7 @@ struct pv_time_ops {
15029 unsigned long long (*sched_clock)(void);
15030 unsigned long long (*steal_clock)(int cpu);
15031 unsigned long (*get_tsc_khz)(void);
15032-};
15033+} __no_const;
15034
15035 struct pv_cpu_ops {
15036 /* hooks for various privileged instructions */
15037@@ -192,7 +192,7 @@ struct pv_cpu_ops {
15038
15039 void (*start_context_switch)(struct task_struct *prev);
15040 void (*end_context_switch)(struct task_struct *next);
15041-};
15042+} __no_const;
15043
15044 struct pv_irq_ops {
15045 /*
15046@@ -223,7 +223,7 @@ struct pv_apic_ops {
15047 unsigned long start_eip,
15048 unsigned long start_esp);
15049 #endif
15050-};
15051+} __no_const;
15052
15053 struct pv_mmu_ops {
15054 unsigned long (*read_cr2)(void);
15055@@ -313,6 +313,7 @@ struct pv_mmu_ops {
15056 struct paravirt_callee_save make_pud;
15057
15058 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
15059+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
15060 #endif /* PAGETABLE_LEVELS == 4 */
15061 #endif /* PAGETABLE_LEVELS >= 3 */
15062
15063@@ -324,6 +325,12 @@ struct pv_mmu_ops {
15064 an mfn. We can tell which is which from the index. */
15065 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
15066 phys_addr_t phys, pgprot_t flags);
15067+
15068+#ifdef CONFIG_PAX_KERNEXEC
15069+ unsigned long (*pax_open_kernel)(void);
15070+ unsigned long (*pax_close_kernel)(void);
15071+#endif
15072+
15073 };
15074
15075 struct arch_spinlock;
15076@@ -334,7 +341,7 @@ struct pv_lock_ops {
15077 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
15078 int (*spin_trylock)(struct arch_spinlock *lock);
15079 void (*spin_unlock)(struct arch_spinlock *lock);
15080-};
15081+} __no_const;
15082
15083 /* This contains all the paravirt structures: we get a convenient
15084 * number for each function using the offset which we use to indicate
15085diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
15086index b4389a4..7024269 100644
15087--- a/arch/x86/include/asm/pgalloc.h
15088+++ b/arch/x86/include/asm/pgalloc.h
15089@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
15090 pmd_t *pmd, pte_t *pte)
15091 {
15092 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
15093+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
15094+}
15095+
15096+static inline void pmd_populate_user(struct mm_struct *mm,
15097+ pmd_t *pmd, pte_t *pte)
15098+{
15099+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
15100 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
15101 }
15102
15103@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
15104
15105 #ifdef CONFIG_X86_PAE
15106 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
15107+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
15108+{
15109+ pud_populate(mm, pudp, pmd);
15110+}
15111 #else /* !CONFIG_X86_PAE */
15112 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
15113 {
15114 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
15115 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
15116 }
15117+
15118+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
15119+{
15120+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
15121+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
15122+}
15123 #endif /* CONFIG_X86_PAE */
15124
15125 #if PAGETABLE_LEVELS > 3
15126@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
15127 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
15128 }
15129
15130+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
15131+{
15132+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
15133+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
15134+}
15135+
15136 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
15137 {
15138 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
15139diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
15140index f2b489c..4f7e2e5 100644
15141--- a/arch/x86/include/asm/pgtable-2level.h
15142+++ b/arch/x86/include/asm/pgtable-2level.h
15143@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
15144
15145 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
15146 {
15147+ pax_open_kernel();
15148 *pmdp = pmd;
15149+ pax_close_kernel();
15150 }
15151
15152 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
15153diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
15154index 4cc9f2b..5fd9226 100644
15155--- a/arch/x86/include/asm/pgtable-3level.h
15156+++ b/arch/x86/include/asm/pgtable-3level.h
15157@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
15158
15159 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
15160 {
15161+ pax_open_kernel();
15162 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
15163+ pax_close_kernel();
15164 }
15165
15166 static inline void native_set_pud(pud_t *pudp, pud_t pud)
15167 {
15168+ pax_open_kernel();
15169 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
15170+ pax_close_kernel();
15171 }
15172
15173 /*
15174diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
15175index 1c1a955..50f828c 100644
15176--- a/arch/x86/include/asm/pgtable.h
15177+++ b/arch/x86/include/asm/pgtable.h
15178@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
15179
15180 #ifndef __PAGETABLE_PUD_FOLDED
15181 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
15182+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
15183 #define pgd_clear(pgd) native_pgd_clear(pgd)
15184 #endif
15185
15186@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
15187
15188 #define arch_end_context_switch(prev) do {} while(0)
15189
15190+#define pax_open_kernel() native_pax_open_kernel()
15191+#define pax_close_kernel() native_pax_close_kernel()
15192 #endif /* CONFIG_PARAVIRT */
15193
15194+#define __HAVE_ARCH_PAX_OPEN_KERNEL
15195+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
15196+
15197+#ifdef CONFIG_PAX_KERNEXEC
15198+static inline unsigned long native_pax_open_kernel(void)
15199+{
15200+ unsigned long cr0;
15201+
15202+ preempt_disable();
15203+ barrier();
15204+ cr0 = read_cr0() ^ X86_CR0_WP;
15205+ BUG_ON(cr0 & X86_CR0_WP);
15206+ write_cr0(cr0);
15207+ return cr0 ^ X86_CR0_WP;
15208+}
15209+
15210+static inline unsigned long native_pax_close_kernel(void)
15211+{
15212+ unsigned long cr0;
15213+
15214+ cr0 = read_cr0() ^ X86_CR0_WP;
15215+ BUG_ON(!(cr0 & X86_CR0_WP));
15216+ write_cr0(cr0);
15217+ barrier();
15218+ preempt_enable_no_resched();
15219+ return cr0 ^ X86_CR0_WP;
15220+}
15221+#else
15222+static inline unsigned long native_pax_open_kernel(void) { return 0; }
15223+static inline unsigned long native_pax_close_kernel(void) { return 0; }
15224+#endif
15225+
15226 /*
15227 * The following only work if pte_present() is true.
15228 * Undefined behaviour if not..
15229 */
15230+static inline int pte_user(pte_t pte)
15231+{
15232+ return pte_val(pte) & _PAGE_USER;
15233+}
15234+
15235 static inline int pte_dirty(pte_t pte)
15236 {
15237 return pte_flags(pte) & _PAGE_DIRTY;
15238@@ -200,9 +240,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
15239 return pte_clear_flags(pte, _PAGE_RW);
15240 }
15241
15242+static inline pte_t pte_mkread(pte_t pte)
15243+{
15244+ return __pte(pte_val(pte) | _PAGE_USER);
15245+}
15246+
15247 static inline pte_t pte_mkexec(pte_t pte)
15248 {
15249- return pte_clear_flags(pte, _PAGE_NX);
15250+#ifdef CONFIG_X86_PAE
15251+ if (__supported_pte_mask & _PAGE_NX)
15252+ return pte_clear_flags(pte, _PAGE_NX);
15253+ else
15254+#endif
15255+ return pte_set_flags(pte, _PAGE_USER);
15256+}
15257+
15258+static inline pte_t pte_exprotect(pte_t pte)
15259+{
15260+#ifdef CONFIG_X86_PAE
15261+ if (__supported_pte_mask & _PAGE_NX)
15262+ return pte_set_flags(pte, _PAGE_NX);
15263+ else
15264+#endif
15265+ return pte_clear_flags(pte, _PAGE_USER);
15266 }
15267
15268 static inline pte_t pte_mkdirty(pte_t pte)
15269@@ -394,6 +454,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
15270 #endif
15271
15272 #ifndef __ASSEMBLY__
15273+
15274+#ifdef CONFIG_PAX_PER_CPU_PGD
15275+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
15276+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
15277+{
15278+ return cpu_pgd[cpu];
15279+}
15280+#endif
15281+
15282 #include <linux/mm_types.h>
15283
15284 static inline int pte_none(pte_t pte)
15285@@ -583,7 +652,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
15286
15287 static inline int pgd_bad(pgd_t pgd)
15288 {
15289- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
15290+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
15291 }
15292
15293 static inline int pgd_none(pgd_t pgd)
15294@@ -606,7 +675,12 @@ static inline int pgd_none(pgd_t pgd)
15295 * pgd_offset() returns a (pgd_t *)
15296 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
15297 */
15298-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
15299+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
15300+
15301+#ifdef CONFIG_PAX_PER_CPU_PGD
15302+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
15303+#endif
15304+
15305 /*
15306 * a shortcut which implies the use of the kernel's pgd, instead
15307 * of a process's
15308@@ -617,6 +691,20 @@ static inline int pgd_none(pgd_t pgd)
15309 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
15310 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
15311
15312+#ifdef CONFIG_X86_32
15313+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
15314+#else
15315+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
15316+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
15317+
15318+#ifdef CONFIG_PAX_MEMORY_UDEREF
15319+#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
15320+#else
15321+#define PAX_USER_SHADOW_BASE (_AC(0,UL))
15322+#endif
15323+
15324+#endif
15325+
15326 #ifndef __ASSEMBLY__
15327
15328 extern int direct_gbpages;
15329@@ -781,11 +869,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
15330 * dst and src can be on the same page, but the range must not overlap,
15331 * and must not cross a page boundary.
15332 */
15333-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
15334+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
15335 {
15336- memcpy(dst, src, count * sizeof(pgd_t));
15337+ pax_open_kernel();
15338+ while (count--)
15339+ *dst++ = *src++;
15340+ pax_close_kernel();
15341 }
15342
15343+#ifdef CONFIG_PAX_PER_CPU_PGD
15344+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
15345+#endif
15346+
15347+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15348+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
15349+#else
15350+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
15351+#endif
15352
15353 #include <asm-generic/pgtable.h>
15354 #endif /* __ASSEMBLY__ */
15355diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
15356index 8faa215..a8a17ea 100644
15357--- a/arch/x86/include/asm/pgtable_32.h
15358+++ b/arch/x86/include/asm/pgtable_32.h
15359@@ -25,9 +25,6 @@
15360 struct mm_struct;
15361 struct vm_area_struct;
15362
15363-extern pgd_t swapper_pg_dir[1024];
15364-extern pgd_t initial_page_table[1024];
15365-
15366 static inline void pgtable_cache_init(void) { }
15367 static inline void check_pgt_cache(void) { }
15368 void paging_init(void);
15369@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
15370 # include <asm/pgtable-2level.h>
15371 #endif
15372
15373+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
15374+extern pgd_t initial_page_table[PTRS_PER_PGD];
15375+#ifdef CONFIG_X86_PAE
15376+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
15377+#endif
15378+
15379 #if defined(CONFIG_HIGHPTE)
15380 #define pte_offset_map(dir, address) \
15381 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
15382@@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
15383 /* Clear a kernel PTE and flush it from the TLB */
15384 #define kpte_clear_flush(ptep, vaddr) \
15385 do { \
15386+ pax_open_kernel(); \
15387 pte_clear(&init_mm, (vaddr), (ptep)); \
15388+ pax_close_kernel(); \
15389 __flush_tlb_one((vaddr)); \
15390 } while (0)
15391
15392@@ -75,6 +80,9 @@ do { \
15393
15394 #endif /* !__ASSEMBLY__ */
15395
15396+#define HAVE_ARCH_UNMAPPED_AREA
15397+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
15398+
15399 /*
15400 * kern_addr_valid() is (1) for FLATMEM and (0) for
15401 * SPARSEMEM and DISCONTIGMEM
15402diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
15403index ed5903b..c7fe163 100644
15404--- a/arch/x86/include/asm/pgtable_32_types.h
15405+++ b/arch/x86/include/asm/pgtable_32_types.h
15406@@ -8,7 +8,7 @@
15407 */
15408 #ifdef CONFIG_X86_PAE
15409 # include <asm/pgtable-3level_types.h>
15410-# define PMD_SIZE (1UL << PMD_SHIFT)
15411+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
15412 # define PMD_MASK (~(PMD_SIZE - 1))
15413 #else
15414 # include <asm/pgtable-2level_types.h>
15415@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
15416 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
15417 #endif
15418
15419+#ifdef CONFIG_PAX_KERNEXEC
15420+#ifndef __ASSEMBLY__
15421+extern unsigned char MODULES_EXEC_VADDR[];
15422+extern unsigned char MODULES_EXEC_END[];
15423+#endif
15424+#include <asm/boot.h>
15425+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
15426+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
15427+#else
15428+#define ktla_ktva(addr) (addr)
15429+#define ktva_ktla(addr) (addr)
15430+#endif
15431+
15432 #define MODULES_VADDR VMALLOC_START
15433 #define MODULES_END VMALLOC_END
15434 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
15435diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
15436index 47356f9..deb94a2 100644
15437--- a/arch/x86/include/asm/pgtable_64.h
15438+++ b/arch/x86/include/asm/pgtable_64.h
15439@@ -16,10 +16,14 @@
15440
15441 extern pud_t level3_kernel_pgt[512];
15442 extern pud_t level3_ident_pgt[512];
15443+extern pud_t level3_vmalloc_start_pgt[512];
15444+extern pud_t level3_vmalloc_end_pgt[512];
15445+extern pud_t level3_vmemmap_pgt[512];
15446+extern pud_t level2_vmemmap_pgt[512];
15447 extern pmd_t level2_kernel_pgt[512];
15448 extern pmd_t level2_fixmap_pgt[512];
15449-extern pmd_t level2_ident_pgt[512];
15450-extern pgd_t init_level4_pgt[];
15451+extern pmd_t level2_ident_pgt[512*2];
15452+extern pgd_t init_level4_pgt[512];
15453
15454 #define swapper_pg_dir init_level4_pgt
15455
15456@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
15457
15458 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
15459 {
15460+ pax_open_kernel();
15461 *pmdp = pmd;
15462+ pax_close_kernel();
15463 }
15464
15465 static inline void native_pmd_clear(pmd_t *pmd)
15466@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
15467
15468 static inline void native_set_pud(pud_t *pudp, pud_t pud)
15469 {
15470+ pax_open_kernel();
15471 *pudp = pud;
15472+ pax_close_kernel();
15473 }
15474
15475 static inline void native_pud_clear(pud_t *pud)
15476@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
15477
15478 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
15479 {
15480+ pax_open_kernel();
15481+ *pgdp = pgd;
15482+ pax_close_kernel();
15483+}
15484+
15485+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
15486+{
15487 *pgdp = pgd;
15488 }
15489
15490diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
15491index 766ea16..5b96cb3 100644
15492--- a/arch/x86/include/asm/pgtable_64_types.h
15493+++ b/arch/x86/include/asm/pgtable_64_types.h
15494@@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
15495 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
15496 #define MODULES_END _AC(0xffffffffff000000, UL)
15497 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
15498+#define MODULES_EXEC_VADDR MODULES_VADDR
15499+#define MODULES_EXEC_END MODULES_END
15500+
15501+#define ktla_ktva(addr) (addr)
15502+#define ktva_ktla(addr) (addr)
15503
15504 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
15505diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
15506index 3c32db8..1ddccf5 100644
15507--- a/arch/x86/include/asm/pgtable_types.h
15508+++ b/arch/x86/include/asm/pgtable_types.h
15509@@ -16,13 +16,12 @@
15510 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
15511 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
15512 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
15513-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
15514+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
15515 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
15516 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
15517 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
15518-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
15519-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
15520-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
15521+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
15522+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
15523 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
15524
15525 /* If _PAGE_BIT_PRESENT is clear, we use these: */
15526@@ -40,7 +39,6 @@
15527 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
15528 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
15529 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
15530-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
15531 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
15532 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
15533 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
15534@@ -57,8 +55,10 @@
15535
15536 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
15537 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
15538-#else
15539+#elif defined(CONFIG_KMEMCHECK)
15540 #define _PAGE_NX (_AT(pteval_t, 0))
15541+#else
15542+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
15543 #endif
15544
15545 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
15546@@ -116,6 +116,9 @@
15547 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
15548 _PAGE_ACCESSED)
15549
15550+#define PAGE_READONLY_NOEXEC PAGE_READONLY
15551+#define PAGE_SHARED_NOEXEC PAGE_SHARED
15552+
15553 #define __PAGE_KERNEL_EXEC \
15554 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
15555 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
15556@@ -126,7 +129,7 @@
15557 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
15558 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
15559 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
15560-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
15561+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
15562 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
15563 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
15564 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
15565@@ -188,8 +191,8 @@
15566 * bits are combined, this will alow user to access the high address mapped
15567 * VDSO in the presence of CONFIG_COMPAT_VDSO
15568 */
15569-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
15570-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
15571+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
15572+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
15573 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
15574 #endif
15575
15576@@ -227,7 +230,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
15577 {
15578 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
15579 }
15580+#endif
15581
15582+#if PAGETABLE_LEVELS == 3
15583+#include <asm-generic/pgtable-nopud.h>
15584+#endif
15585+
15586+#if PAGETABLE_LEVELS == 2
15587+#include <asm-generic/pgtable-nopmd.h>
15588+#endif
15589+
15590+#ifndef __ASSEMBLY__
15591 #if PAGETABLE_LEVELS > 3
15592 typedef struct { pudval_t pud; } pud_t;
15593
15594@@ -241,8 +254,6 @@ static inline pudval_t native_pud_val(pud_t pud)
15595 return pud.pud;
15596 }
15597 #else
15598-#include <asm-generic/pgtable-nopud.h>
15599-
15600 static inline pudval_t native_pud_val(pud_t pud)
15601 {
15602 return native_pgd_val(pud.pgd);
15603@@ -262,8 +273,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
15604 return pmd.pmd;
15605 }
15606 #else
15607-#include <asm-generic/pgtable-nopmd.h>
15608-
15609 static inline pmdval_t native_pmd_val(pmd_t pmd)
15610 {
15611 return native_pgd_val(pmd.pud.pgd);
15612@@ -303,7 +312,6 @@ typedef struct page *pgtable_t;
15613
15614 extern pteval_t __supported_pte_mask;
15615 extern void set_nx(void);
15616-extern int nx_enabled;
15617
15618 #define pgprot_writecombine pgprot_writecombine
15619 extern pgprot_t pgprot_writecombine(pgprot_t prot);
15620diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
15621index 888184b..a07ac89 100644
15622--- a/arch/x86/include/asm/processor.h
15623+++ b/arch/x86/include/asm/processor.h
15624@@ -287,7 +287,7 @@ struct tss_struct {
15625
15626 } ____cacheline_aligned;
15627
15628-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
15629+extern struct tss_struct init_tss[NR_CPUS];
15630
15631 /*
15632 * Save the original ist values for checking stack pointers during debugging
15633@@ -827,11 +827,18 @@ static inline void spin_lock_prefetch(const void *x)
15634 */
15635 #define TASK_SIZE PAGE_OFFSET
15636 #define TASK_SIZE_MAX TASK_SIZE
15637+
15638+#ifdef CONFIG_PAX_SEGMEXEC
15639+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
15640+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
15641+#else
15642 #define STACK_TOP TASK_SIZE
15643-#define STACK_TOP_MAX STACK_TOP
15644+#endif
15645+
15646+#define STACK_TOP_MAX TASK_SIZE
15647
15648 #define INIT_THREAD { \
15649- .sp0 = sizeof(init_stack) + (long)&init_stack, \
15650+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
15651 .vm86_info = NULL, \
15652 .sysenter_cs = __KERNEL_CS, \
15653 .io_bitmap_ptr = NULL, \
15654@@ -845,7 +852,7 @@ static inline void spin_lock_prefetch(const void *x)
15655 */
15656 #define INIT_TSS { \
15657 .x86_tss = { \
15658- .sp0 = sizeof(init_stack) + (long)&init_stack, \
15659+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
15660 .ss0 = __KERNEL_DS, \
15661 .ss1 = __KERNEL_CS, \
15662 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
15663@@ -856,11 +863,7 @@ static inline void spin_lock_prefetch(const void *x)
15664 extern unsigned long thread_saved_pc(struct task_struct *tsk);
15665
15666 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
15667-#define KSTK_TOP(info) \
15668-({ \
15669- unsigned long *__ptr = (unsigned long *)(info); \
15670- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
15671-})
15672+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
15673
15674 /*
15675 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
15676@@ -875,7 +878,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
15677 #define task_pt_regs(task) \
15678 ({ \
15679 struct pt_regs *__regs__; \
15680- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
15681+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
15682 __regs__ - 1; \
15683 })
15684
15685@@ -885,13 +888,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
15686 /*
15687 * User space process size. 47bits minus one guard page.
15688 */
15689-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
15690+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
15691
15692 /* This decides where the kernel will search for a free chunk of vm
15693 * space during mmap's.
15694 */
15695 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
15696- 0xc0000000 : 0xFFFFe000)
15697+ 0xc0000000 : 0xFFFFf000)
15698
15699 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
15700 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
15701@@ -902,11 +905,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
15702 #define STACK_TOP_MAX TASK_SIZE_MAX
15703
15704 #define INIT_THREAD { \
15705- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
15706+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
15707 }
15708
15709 #define INIT_TSS { \
15710- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
15711+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
15712 }
15713
15714 /*
15715@@ -934,6 +937,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
15716 */
15717 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
15718
15719+#ifdef CONFIG_PAX_SEGMEXEC
15720+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
15721+#endif
15722+
15723 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
15724
15725 /* Get/set a process' ability to use the timestamp counter instruction */
15726@@ -994,12 +1001,12 @@ extern bool cpu_has_amd_erratum(const int *);
15727 #define cpu_has_amd_erratum(x) (false)
15728 #endif /* CONFIG_CPU_SUP_AMD */
15729
15730-extern unsigned long arch_align_stack(unsigned long sp);
15731+#define arch_align_stack(x) ((x) & ~0xfUL)
15732 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
15733
15734 void default_idle(void);
15735 bool set_pm_idle_to_default(void);
15736
15737-void stop_this_cpu(void *dummy);
15738+void stop_this_cpu(void *dummy) __noreturn;
15739
15740 #endif /* _ASM_X86_PROCESSOR_H */
15741diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
15742index 942a086..6c26446 100644
15743--- a/arch/x86/include/asm/ptrace.h
15744+++ b/arch/x86/include/asm/ptrace.h
15745@@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
15746 }
15747
15748 /*
15749- * user_mode_vm(regs) determines whether a register set came from user mode.
15750+ * user_mode(regs) determines whether a register set came from user mode.
15751 * This is true if V8086 mode was enabled OR if the register set was from
15752 * protected mode with RPL-3 CS value. This tricky test checks that with
15753 * one comparison. Many places in the kernel can bypass this full check
15754- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
15755+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
15756+ * be used.
15757 */
15758-static inline int user_mode(struct pt_regs *regs)
15759+static inline int user_mode_novm(struct pt_regs *regs)
15760 {
15761 #ifdef CONFIG_X86_32
15762 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
15763 #else
15764- return !!(regs->cs & 3);
15765+ return !!(regs->cs & SEGMENT_RPL_MASK);
15766 #endif
15767 }
15768
15769-static inline int user_mode_vm(struct pt_regs *regs)
15770+static inline int user_mode(struct pt_regs *regs)
15771 {
15772 #ifdef CONFIG_X86_32
15773 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
15774 USER_RPL;
15775 #else
15776- return user_mode(regs);
15777+ return user_mode_novm(regs);
15778 #endif
15779 }
15780
15781@@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
15782 #ifdef CONFIG_X86_64
15783 static inline bool user_64bit_mode(struct pt_regs *regs)
15784 {
15785+ unsigned long cs = regs->cs & 0xffff;
15786 #ifndef CONFIG_PARAVIRT
15787 /*
15788 * On non-paravirt systems, this is the only long mode CPL 3
15789 * selector. We do not allow long mode selectors in the LDT.
15790 */
15791- return regs->cs == __USER_CS;
15792+ return cs == __USER_CS;
15793 #else
15794 /* Headers are too twisted for this to go in paravirt.h. */
15795- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
15796+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
15797 #endif
15798 }
15799
15800@@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
15801 * Traps from the kernel do not save sp and ss.
15802 * Use the helper function to retrieve sp.
15803 */
15804- if (offset == offsetof(struct pt_regs, sp) &&
15805- regs->cs == __KERNEL_CS)
15806- return kernel_stack_pointer(regs);
15807+ if (offset == offsetof(struct pt_regs, sp)) {
15808+ unsigned long cs = regs->cs & 0xffff;
15809+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
15810+ return kernel_stack_pointer(regs);
15811+ }
15812 #endif
15813 return *(unsigned long *)((unsigned long)regs + offset);
15814 }
15815diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
15816index fe1ec5b..dc5c3fe 100644
15817--- a/arch/x86/include/asm/realmode.h
15818+++ b/arch/x86/include/asm/realmode.h
15819@@ -22,16 +22,14 @@ struct real_mode_header {
15820 #endif
15821 /* APM/BIOS reboot */
15822 u32 machine_real_restart_asm;
15823-#ifdef CONFIG_X86_64
15824 u32 machine_real_restart_seg;
15825-#endif
15826 };
15827
15828 /* This must match data at trampoline_32/64.S */
15829 struct trampoline_header {
15830 #ifdef CONFIG_X86_32
15831 u32 start;
15832- u16 gdt_pad;
15833+ u16 boot_cs;
15834 u16 gdt_limit;
15835 u32 gdt_base;
15836 #else
15837diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
15838index a82c4f1..ac45053 100644
15839--- a/arch/x86/include/asm/reboot.h
15840+++ b/arch/x86/include/asm/reboot.h
15841@@ -6,13 +6,13 @@
15842 struct pt_regs;
15843
15844 struct machine_ops {
15845- void (*restart)(char *cmd);
15846- void (*halt)(void);
15847- void (*power_off)(void);
15848+ void (* __noreturn restart)(char *cmd);
15849+ void (* __noreturn halt)(void);
15850+ void (* __noreturn power_off)(void);
15851 void (*shutdown)(void);
15852 void (*crash_shutdown)(struct pt_regs *);
15853- void (*emergency_restart)(void);
15854-};
15855+ void (* __noreturn emergency_restart)(void);
15856+} __no_const;
15857
15858 extern struct machine_ops machine_ops;
15859
15860diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
15861index 2dbe4a7..ce1db00 100644
15862--- a/arch/x86/include/asm/rwsem.h
15863+++ b/arch/x86/include/asm/rwsem.h
15864@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
15865 {
15866 asm volatile("# beginning down_read\n\t"
15867 LOCK_PREFIX _ASM_INC "(%1)\n\t"
15868+
15869+#ifdef CONFIG_PAX_REFCOUNT
15870+ "jno 0f\n"
15871+ LOCK_PREFIX _ASM_DEC "(%1)\n"
15872+ "int $4\n0:\n"
15873+ _ASM_EXTABLE(0b, 0b)
15874+#endif
15875+
15876 /* adds 0x00000001 */
15877 " jns 1f\n"
15878 " call call_rwsem_down_read_failed\n"
15879@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
15880 "1:\n\t"
15881 " mov %1,%2\n\t"
15882 " add %3,%2\n\t"
15883+
15884+#ifdef CONFIG_PAX_REFCOUNT
15885+ "jno 0f\n"
15886+ "sub %3,%2\n"
15887+ "int $4\n0:\n"
15888+ _ASM_EXTABLE(0b, 0b)
15889+#endif
15890+
15891 " jle 2f\n\t"
15892 LOCK_PREFIX " cmpxchg %2,%0\n\t"
15893 " jnz 1b\n\t"
15894@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
15895 long tmp;
15896 asm volatile("# beginning down_write\n\t"
15897 LOCK_PREFIX " xadd %1,(%2)\n\t"
15898+
15899+#ifdef CONFIG_PAX_REFCOUNT
15900+ "jno 0f\n"
15901+ "mov %1,(%2)\n"
15902+ "int $4\n0:\n"
15903+ _ASM_EXTABLE(0b, 0b)
15904+#endif
15905+
15906 /* adds 0xffff0001, returns the old value */
15907 " test %1,%1\n\t"
15908 /* was the count 0 before? */
15909@@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
15910 long tmp;
15911 asm volatile("# beginning __up_read\n\t"
15912 LOCK_PREFIX " xadd %1,(%2)\n\t"
15913+
15914+#ifdef CONFIG_PAX_REFCOUNT
15915+ "jno 0f\n"
15916+ "mov %1,(%2)\n"
15917+ "int $4\n0:\n"
15918+ _ASM_EXTABLE(0b, 0b)
15919+#endif
15920+
15921 /* subtracts 1, returns the old value */
15922 " jns 1f\n\t"
15923 " call call_rwsem_wake\n" /* expects old value in %edx */
15924@@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
15925 long tmp;
15926 asm volatile("# beginning __up_write\n\t"
15927 LOCK_PREFIX " xadd %1,(%2)\n\t"
15928+
15929+#ifdef CONFIG_PAX_REFCOUNT
15930+ "jno 0f\n"
15931+ "mov %1,(%2)\n"
15932+ "int $4\n0:\n"
15933+ _ASM_EXTABLE(0b, 0b)
15934+#endif
15935+
15936 /* subtracts 0xffff0001, returns the old value */
15937 " jns 1f\n\t"
15938 " call call_rwsem_wake\n" /* expects old value in %edx */
15939@@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
15940 {
15941 asm volatile("# beginning __downgrade_write\n\t"
15942 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
15943+
15944+#ifdef CONFIG_PAX_REFCOUNT
15945+ "jno 0f\n"
15946+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
15947+ "int $4\n0:\n"
15948+ _ASM_EXTABLE(0b, 0b)
15949+#endif
15950+
15951 /*
15952 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
15953 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
15954@@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
15955 */
15956 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
15957 {
15958- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
15959+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
15960+
15961+#ifdef CONFIG_PAX_REFCOUNT
15962+ "jno 0f\n"
15963+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
15964+ "int $4\n0:\n"
15965+ _ASM_EXTABLE(0b, 0b)
15966+#endif
15967+
15968 : "+m" (sem->count)
15969 : "er" (delta));
15970 }
15971@@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
15972 */
15973 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
15974 {
15975- return delta + xadd(&sem->count, delta);
15976+ return delta + xadd_check_overflow(&sem->count, delta);
15977 }
15978
15979 #endif /* __KERNEL__ */
15980diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
15981index c48a950..c6d7468 100644
15982--- a/arch/x86/include/asm/segment.h
15983+++ b/arch/x86/include/asm/segment.h
15984@@ -64,10 +64,15 @@
15985 * 26 - ESPFIX small SS
15986 * 27 - per-cpu [ offset to per-cpu data area ]
15987 * 28 - stack_canary-20 [ for stack protector ]
15988- * 29 - unused
15989- * 30 - unused
15990+ * 29 - PCI BIOS CS
15991+ * 30 - PCI BIOS DS
15992 * 31 - TSS for double fault handler
15993 */
15994+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
15995+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
15996+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
15997+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
15998+
15999 #define GDT_ENTRY_TLS_MIN 6
16000 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
16001
16002@@ -79,6 +84,8 @@
16003
16004 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
16005
16006+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
16007+
16008 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
16009
16010 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
16011@@ -104,6 +111,12 @@
16012 #define __KERNEL_STACK_CANARY 0
16013 #endif
16014
16015+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
16016+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
16017+
16018+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
16019+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
16020+
16021 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
16022
16023 /*
16024@@ -141,7 +154,7 @@
16025 */
16026
16027 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
16028-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
16029+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
16030
16031
16032 #else
16033@@ -165,6 +178,8 @@
16034 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
16035 #define __USER32_DS __USER_DS
16036
16037+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
16038+
16039 #define GDT_ENTRY_TSS 8 /* needs two entries */
16040 #define GDT_ENTRY_LDT 10 /* needs two entries */
16041 #define GDT_ENTRY_TLS_MIN 12
16042@@ -185,6 +200,7 @@
16043 #endif
16044
16045 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
16046+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
16047 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
16048 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
16049 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
16050@@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
16051 {
16052 unsigned long __limit;
16053 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
16054- return __limit + 1;
16055+ return __limit;
16056 }
16057
16058 #endif /* !__ASSEMBLY__ */
16059diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
16060index b073aae..39f9bdd 100644
16061--- a/arch/x86/include/asm/smp.h
16062+++ b/arch/x86/include/asm/smp.h
16063@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
16064 /* cpus sharing the last level cache: */
16065 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
16066 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
16067-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
16068+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
16069
16070 static inline struct cpumask *cpu_sibling_mask(int cpu)
16071 {
16072@@ -79,7 +79,7 @@ struct smp_ops {
16073
16074 void (*send_call_func_ipi)(const struct cpumask *mask);
16075 void (*send_call_func_single_ipi)(int cpu);
16076-};
16077+} __no_const;
16078
16079 /* Globals due to paravirt */
16080 extern void set_cpu_sibling_map(int cpu);
16081@@ -191,14 +191,8 @@ extern unsigned disabled_cpus __cpuinitdata;
16082 extern int safe_smp_processor_id(void);
16083
16084 #elif defined(CONFIG_X86_64_SMP)
16085-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
16086-
16087-#define stack_smp_processor_id() \
16088-({ \
16089- struct thread_info *ti; \
16090- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
16091- ti->cpu; \
16092-})
16093+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
16094+#define stack_smp_processor_id() raw_smp_processor_id()
16095 #define safe_smp_processor_id() smp_processor_id()
16096
16097 #endif
16098diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
16099index 33692ea..350a534 100644
16100--- a/arch/x86/include/asm/spinlock.h
16101+++ b/arch/x86/include/asm/spinlock.h
16102@@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
16103 static inline void arch_read_lock(arch_rwlock_t *rw)
16104 {
16105 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
16106+
16107+#ifdef CONFIG_PAX_REFCOUNT
16108+ "jno 0f\n"
16109+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
16110+ "int $4\n0:\n"
16111+ _ASM_EXTABLE(0b, 0b)
16112+#endif
16113+
16114 "jns 1f\n"
16115 "call __read_lock_failed\n\t"
16116 "1:\n"
16117@@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
16118 static inline void arch_write_lock(arch_rwlock_t *rw)
16119 {
16120 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
16121+
16122+#ifdef CONFIG_PAX_REFCOUNT
16123+ "jno 0f\n"
16124+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
16125+ "int $4\n0:\n"
16126+ _ASM_EXTABLE(0b, 0b)
16127+#endif
16128+
16129 "jz 1f\n"
16130 "call __write_lock_failed\n\t"
16131 "1:\n"
16132@@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
16133
16134 static inline void arch_read_unlock(arch_rwlock_t *rw)
16135 {
16136- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
16137+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
16138+
16139+#ifdef CONFIG_PAX_REFCOUNT
16140+ "jno 0f\n"
16141+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
16142+ "int $4\n0:\n"
16143+ _ASM_EXTABLE(0b, 0b)
16144+#endif
16145+
16146 :"+m" (rw->lock) : : "memory");
16147 }
16148
16149 static inline void arch_write_unlock(arch_rwlock_t *rw)
16150 {
16151- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
16152+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
16153+
16154+#ifdef CONFIG_PAX_REFCOUNT
16155+ "jno 0f\n"
16156+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
16157+ "int $4\n0:\n"
16158+ _ASM_EXTABLE(0b, 0b)
16159+#endif
16160+
16161 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
16162 }
16163
16164diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
16165index 6a99859..03cb807 100644
16166--- a/arch/x86/include/asm/stackprotector.h
16167+++ b/arch/x86/include/asm/stackprotector.h
16168@@ -47,7 +47,7 @@
16169 * head_32 for boot CPU and setup_per_cpu_areas() for others.
16170 */
16171 #define GDT_STACK_CANARY_INIT \
16172- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
16173+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
16174
16175 /*
16176 * Initialize the stackprotector canary value.
16177@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
16178
16179 static inline void load_stack_canary_segment(void)
16180 {
16181-#ifdef CONFIG_X86_32
16182+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
16183 asm volatile ("mov %0, %%gs" : : "r" (0));
16184 #endif
16185 }
16186diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
16187index 70bbe39..4ae2bd4 100644
16188--- a/arch/x86/include/asm/stacktrace.h
16189+++ b/arch/x86/include/asm/stacktrace.h
16190@@ -11,28 +11,20 @@
16191
16192 extern int kstack_depth_to_print;
16193
16194-struct thread_info;
16195+struct task_struct;
16196 struct stacktrace_ops;
16197
16198-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
16199- unsigned long *stack,
16200- unsigned long bp,
16201- const struct stacktrace_ops *ops,
16202- void *data,
16203- unsigned long *end,
16204- int *graph);
16205+typedef unsigned long walk_stack_t(struct task_struct *task,
16206+ void *stack_start,
16207+ unsigned long *stack,
16208+ unsigned long bp,
16209+ const struct stacktrace_ops *ops,
16210+ void *data,
16211+ unsigned long *end,
16212+ int *graph);
16213
16214-extern unsigned long
16215-print_context_stack(struct thread_info *tinfo,
16216- unsigned long *stack, unsigned long bp,
16217- const struct stacktrace_ops *ops, void *data,
16218- unsigned long *end, int *graph);
16219-
16220-extern unsigned long
16221-print_context_stack_bp(struct thread_info *tinfo,
16222- unsigned long *stack, unsigned long bp,
16223- const struct stacktrace_ops *ops, void *data,
16224- unsigned long *end, int *graph);
16225+extern walk_stack_t print_context_stack;
16226+extern walk_stack_t print_context_stack_bp;
16227
16228 /* Generic stack tracer with callbacks */
16229
16230@@ -40,7 +32,7 @@ struct stacktrace_ops {
16231 void (*address)(void *data, unsigned long address, int reliable);
16232 /* On negative return stop dumping */
16233 int (*stack)(void *data, char *name);
16234- walk_stack_t walk_stack;
16235+ walk_stack_t *walk_stack;
16236 };
16237
16238 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
16239diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
16240index 4ec45b3..a4f0a8a 100644
16241--- a/arch/x86/include/asm/switch_to.h
16242+++ b/arch/x86/include/asm/switch_to.h
16243@@ -108,7 +108,7 @@ do { \
16244 "call __switch_to\n\t" \
16245 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
16246 __switch_canary \
16247- "movq %P[thread_info](%%rsi),%%r8\n\t" \
16248+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
16249 "movq %%rax,%%rdi\n\t" \
16250 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
16251 "jnz ret_from_fork\n\t" \
16252@@ -119,7 +119,7 @@ do { \
16253 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
16254 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
16255 [_tif_fork] "i" (_TIF_FORK), \
16256- [thread_info] "i" (offsetof(struct task_struct, stack)), \
16257+ [thread_info] "m" (current_tinfo), \
16258 [current_task] "m" (current_task) \
16259 __switch_canary_iparam \
16260 : "memory", "cc" __EXTRA_CLOBBER)
16261diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
16262index 2d946e6..e453ec4 100644
16263--- a/arch/x86/include/asm/thread_info.h
16264+++ b/arch/x86/include/asm/thread_info.h
16265@@ -10,6 +10,7 @@
16266 #include <linux/compiler.h>
16267 #include <asm/page.h>
16268 #include <asm/types.h>
16269+#include <asm/percpu.h>
16270
16271 /*
16272 * low level task data that entry.S needs immediate access to
16273@@ -24,7 +25,6 @@ struct exec_domain;
16274 #include <linux/atomic.h>
16275
16276 struct thread_info {
16277- struct task_struct *task; /* main task structure */
16278 struct exec_domain *exec_domain; /* execution domain */
16279 __u32 flags; /* low level flags */
16280 __u32 status; /* thread synchronous flags */
16281@@ -34,19 +34,13 @@ struct thread_info {
16282 mm_segment_t addr_limit;
16283 struct restart_block restart_block;
16284 void __user *sysenter_return;
16285-#ifdef CONFIG_X86_32
16286- unsigned long previous_esp; /* ESP of the previous stack in
16287- case of nested (IRQ) stacks
16288- */
16289- __u8 supervisor_stack[0];
16290-#endif
16291+ unsigned long lowest_stack;
16292 unsigned int sig_on_uaccess_error:1;
16293 unsigned int uaccess_err:1; /* uaccess failed */
16294 };
16295
16296-#define INIT_THREAD_INFO(tsk) \
16297+#define INIT_THREAD_INFO \
16298 { \
16299- .task = &tsk, \
16300 .exec_domain = &default_exec_domain, \
16301 .flags = 0, \
16302 .cpu = 0, \
16303@@ -57,7 +51,7 @@ struct thread_info {
16304 }, \
16305 }
16306
16307-#define init_thread_info (init_thread_union.thread_info)
16308+#define init_thread_info (init_thread_union.stack)
16309 #define init_stack (init_thread_union.stack)
16310
16311 #else /* !__ASSEMBLY__ */
16312@@ -98,6 +92,7 @@ struct thread_info {
16313 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
16314 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
16315 #define TIF_X32 30 /* 32-bit native x86-64 binary */
16316+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
16317
16318 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
16319 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
16320@@ -122,17 +117,18 @@ struct thread_info {
16321 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
16322 #define _TIF_ADDR32 (1 << TIF_ADDR32)
16323 #define _TIF_X32 (1 << TIF_X32)
16324+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
16325
16326 /* work to do in syscall_trace_enter() */
16327 #define _TIF_WORK_SYSCALL_ENTRY \
16328 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
16329 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
16330- _TIF_NOHZ)
16331+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
16332
16333 /* work to do in syscall_trace_leave() */
16334 #define _TIF_WORK_SYSCALL_EXIT \
16335 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
16336- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
16337+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
16338
16339 /* work to do on interrupt/exception return */
16340 #define _TIF_WORK_MASK \
16341@@ -143,7 +139,7 @@ struct thread_info {
16342 /* work to do on any return to user space */
16343 #define _TIF_ALLWORK_MASK \
16344 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
16345- _TIF_NOHZ)
16346+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
16347
16348 /* Only used for 64 bit */
16349 #define _TIF_DO_NOTIFY_MASK \
16350@@ -159,45 +155,40 @@ struct thread_info {
16351
16352 #define PREEMPT_ACTIVE 0x10000000
16353
16354-#ifdef CONFIG_X86_32
16355-
16356-#define STACK_WARN (THREAD_SIZE/8)
16357-/*
16358- * macros/functions for gaining access to the thread information structure
16359- *
16360- * preempt_count needs to be 1 initially, until the scheduler is functional.
16361- */
16362-#ifndef __ASSEMBLY__
16363-
16364-
16365-/* how to get the current stack pointer from C */
16366-register unsigned long current_stack_pointer asm("esp") __used;
16367-
16368-/* how to get the thread information struct from C */
16369-static inline struct thread_info *current_thread_info(void)
16370-{
16371- return (struct thread_info *)
16372- (current_stack_pointer & ~(THREAD_SIZE - 1));
16373-}
16374-
16375-#else /* !__ASSEMBLY__ */
16376-
16377+#ifdef __ASSEMBLY__
16378 /* how to get the thread information struct from ASM */
16379 #define GET_THREAD_INFO(reg) \
16380- movl $-THREAD_SIZE, reg; \
16381- andl %esp, reg
16382+ mov PER_CPU_VAR(current_tinfo), reg
16383
16384 /* use this one if reg already contains %esp */
16385-#define GET_THREAD_INFO_WITH_ESP(reg) \
16386- andl $-THREAD_SIZE, reg
16387+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
16388+#else
16389+/* how to get the thread information struct from C */
16390+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
16391+
16392+static __always_inline struct thread_info *current_thread_info(void)
16393+{
16394+ return this_cpu_read_stable(current_tinfo);
16395+}
16396+#endif
16397+
16398+#ifdef CONFIG_X86_32
16399+
16400+#define STACK_WARN (THREAD_SIZE/8)
16401+/*
16402+ * macros/functions for gaining access to the thread information structure
16403+ *
16404+ * preempt_count needs to be 1 initially, until the scheduler is functional.
16405+ */
16406+#ifndef __ASSEMBLY__
16407+
16408+/* how to get the current stack pointer from C */
16409+register unsigned long current_stack_pointer asm("esp") __used;
16410
16411 #endif
16412
16413 #else /* X86_32 */
16414
16415-#include <asm/percpu.h>
16416-#define KERNEL_STACK_OFFSET (5*8)
16417-
16418 /*
16419 * macros/functions for gaining access to the thread information structure
16420 * preempt_count needs to be 1 initially, until the scheduler is functional.
16421@@ -205,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
16422 #ifndef __ASSEMBLY__
16423 DECLARE_PER_CPU(unsigned long, kernel_stack);
16424
16425-static inline struct thread_info *current_thread_info(void)
16426-{
16427- struct thread_info *ti;
16428- ti = (void *)(this_cpu_read_stable(kernel_stack) +
16429- KERNEL_STACK_OFFSET - THREAD_SIZE);
16430- return ti;
16431-}
16432-
16433-#else /* !__ASSEMBLY__ */
16434-
16435-/* how to get the thread information struct from ASM */
16436-#define GET_THREAD_INFO(reg) \
16437- movq PER_CPU_VAR(kernel_stack),reg ; \
16438- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
16439-
16440-/*
16441- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
16442- * a certain register (to be used in assembler memory operands).
16443- */
16444-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
16445-
16446+/* how to get the current stack pointer from C */
16447+register unsigned long current_stack_pointer asm("rsp") __used;
16448 #endif
16449
16450 #endif /* !X86_32 */
16451@@ -286,5 +258,12 @@ static inline bool is_ia32_task(void)
16452 extern void arch_task_cache_init(void);
16453 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
16454 extern void arch_release_task_struct(struct task_struct *tsk);
16455+
16456+#define __HAVE_THREAD_FUNCTIONS
16457+#define task_thread_info(task) (&(task)->tinfo)
16458+#define task_stack_page(task) ((task)->stack)
16459+#define setup_thread_stack(p, org) do {} while (0)
16460+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
16461+
16462 #endif
16463 #endif /* _ASM_X86_THREAD_INFO_H */
16464diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
16465index 1709801..0a60f2f 100644
16466--- a/arch/x86/include/asm/uaccess.h
16467+++ b/arch/x86/include/asm/uaccess.h
16468@@ -7,6 +7,7 @@
16469 #include <linux/compiler.h>
16470 #include <linux/thread_info.h>
16471 #include <linux/string.h>
16472+#include <linux/sched.h>
16473 #include <asm/asm.h>
16474 #include <asm/page.h>
16475 #include <asm/smap.h>
16476@@ -29,7 +30,12 @@
16477
16478 #define get_ds() (KERNEL_DS)
16479 #define get_fs() (current_thread_info()->addr_limit)
16480+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
16481+void __set_fs(mm_segment_t x);
16482+void set_fs(mm_segment_t x);
16483+#else
16484 #define set_fs(x) (current_thread_info()->addr_limit = (x))
16485+#endif
16486
16487 #define segment_eq(a, b) ((a).seg == (b).seg)
16488
16489@@ -77,8 +83,33 @@
16490 * checks that the pointer is in the user space range - after calling
16491 * this function, memory access functions may still return -EFAULT.
16492 */
16493-#define access_ok(type, addr, size) \
16494- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
16495+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
16496+#define access_ok(type, addr, size) \
16497+({ \
16498+ long __size = size; \
16499+ unsigned long __addr = (unsigned long)addr; \
16500+ unsigned long __addr_ao = __addr & PAGE_MASK; \
16501+ unsigned long __end_ao = __addr + __size - 1; \
16502+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
16503+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
16504+ while(__addr_ao <= __end_ao) { \
16505+ char __c_ao; \
16506+ __addr_ao += PAGE_SIZE; \
16507+ if (__size > PAGE_SIZE) \
16508+ cond_resched(); \
16509+ if (__get_user(__c_ao, (char __user *)__addr)) \
16510+ break; \
16511+ if (type != VERIFY_WRITE) { \
16512+ __addr = __addr_ao; \
16513+ continue; \
16514+ } \
16515+ if (__put_user(__c_ao, (char __user *)__addr)) \
16516+ break; \
16517+ __addr = __addr_ao; \
16518+ } \
16519+ } \
16520+ __ret_ao; \
16521+})
16522
16523 /*
16524 * The exception table consists of pairs of addresses relative to the
16525@@ -189,13 +220,21 @@ extern int __get_user_bad(void);
16526 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
16527 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
16528
16529-
16530+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
16531+#define __copyuser_seg "gs;"
16532+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
16533+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
16534+#else
16535+#define __copyuser_seg
16536+#define __COPYUSER_SET_ES
16537+#define __COPYUSER_RESTORE_ES
16538+#endif
16539
16540 #ifdef CONFIG_X86_32
16541 #define __put_user_asm_u64(x, addr, err, errret) \
16542 asm volatile(ASM_STAC "\n" \
16543- "1: movl %%eax,0(%2)\n" \
16544- "2: movl %%edx,4(%2)\n" \
16545+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
16546+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
16547 "3: " ASM_CLAC "\n" \
16548 ".section .fixup,\"ax\"\n" \
16549 "4: movl %3,%0\n" \
16550@@ -208,8 +247,8 @@ extern int __get_user_bad(void);
16551
16552 #define __put_user_asm_ex_u64(x, addr) \
16553 asm volatile(ASM_STAC "\n" \
16554- "1: movl %%eax,0(%1)\n" \
16555- "2: movl %%edx,4(%1)\n" \
16556+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
16557+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
16558 "3: " ASM_CLAC "\n" \
16559 _ASM_EXTABLE_EX(1b, 2b) \
16560 _ASM_EXTABLE_EX(2b, 3b) \
16561@@ -259,7 +298,7 @@ extern void __put_user_8(void);
16562 __typeof__(*(ptr)) __pu_val; \
16563 __chk_user_ptr(ptr); \
16564 might_fault(); \
16565- __pu_val = x; \
16566+ __pu_val = (x); \
16567 switch (sizeof(*(ptr))) { \
16568 case 1: \
16569 __put_user_x(1, __pu_val, ptr, __ret_pu); \
16570@@ -358,7 +397,7 @@ do { \
16571
16572 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
16573 asm volatile(ASM_STAC "\n" \
16574- "1: mov"itype" %2,%"rtype"1\n" \
16575+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
16576 "2: " ASM_CLAC "\n" \
16577 ".section .fixup,\"ax\"\n" \
16578 "3: mov %3,%0\n" \
16579@@ -366,7 +405,7 @@ do { \
16580 " jmp 2b\n" \
16581 ".previous\n" \
16582 _ASM_EXTABLE(1b, 3b) \
16583- : "=r" (err), ltype(x) \
16584+ : "=r" (err), ltype (x) \
16585 : "m" (__m(addr)), "i" (errret), "0" (err))
16586
16587 #define __get_user_size_ex(x, ptr, size) \
16588@@ -391,7 +430,7 @@ do { \
16589 } while (0)
16590
16591 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
16592- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
16593+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
16594 "2:\n" \
16595 _ASM_EXTABLE_EX(1b, 2b) \
16596 : ltype(x) : "m" (__m(addr)))
16597@@ -408,13 +447,24 @@ do { \
16598 int __gu_err; \
16599 unsigned long __gu_val; \
16600 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
16601- (x) = (__force __typeof__(*(ptr)))__gu_val; \
16602+ (x) = (__typeof__(*(ptr)))__gu_val; \
16603 __gu_err; \
16604 })
16605
16606 /* FIXME: this hack is definitely wrong -AK */
16607 struct __large_struct { unsigned long buf[100]; };
16608-#define __m(x) (*(struct __large_struct __user *)(x))
16609+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16610+#define ____m(x) \
16611+({ \
16612+ unsigned long ____x = (unsigned long)(x); \
16613+ if (____x < PAX_USER_SHADOW_BASE) \
16614+ ____x += PAX_USER_SHADOW_BASE; \
16615+ (void __user *)____x; \
16616+})
16617+#else
16618+#define ____m(x) (x)
16619+#endif
16620+#define __m(x) (*(struct __large_struct __user *)____m(x))
16621
16622 /*
16623 * Tell gcc we read from memory instead of writing: this is because
16624@@ -423,7 +473,7 @@ struct __large_struct { unsigned long buf[100]; };
16625 */
16626 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
16627 asm volatile(ASM_STAC "\n" \
16628- "1: mov"itype" %"rtype"1,%2\n" \
16629+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
16630 "2: " ASM_CLAC "\n" \
16631 ".section .fixup,\"ax\"\n" \
16632 "3: mov %3,%0\n" \
16633@@ -431,10 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
16634 ".previous\n" \
16635 _ASM_EXTABLE(1b, 3b) \
16636 : "=r"(err) \
16637- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
16638+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
16639
16640 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
16641- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
16642+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
16643 "2:\n" \
16644 _ASM_EXTABLE_EX(1b, 2b) \
16645 : : ltype(x), "m" (__m(addr)))
16646@@ -473,8 +523,12 @@ struct __large_struct { unsigned long buf[100]; };
16647 * On error, the variable @x is set to zero.
16648 */
16649
16650+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16651+#define __get_user(x, ptr) get_user((x), (ptr))
16652+#else
16653 #define __get_user(x, ptr) \
16654 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
16655+#endif
16656
16657 /**
16658 * __put_user: - Write a simple value into user space, with less checking.
16659@@ -496,8 +550,12 @@ struct __large_struct { unsigned long buf[100]; };
16660 * Returns zero on success, or -EFAULT on error.
16661 */
16662
16663+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16664+#define __put_user(x, ptr) put_user((x), (ptr))
16665+#else
16666 #define __put_user(x, ptr) \
16667 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
16668+#endif
16669
16670 #define __get_user_unaligned __get_user
16671 #define __put_user_unaligned __put_user
16672@@ -515,7 +573,7 @@ struct __large_struct { unsigned long buf[100]; };
16673 #define get_user_ex(x, ptr) do { \
16674 unsigned long __gue_val; \
16675 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
16676- (x) = (__force __typeof__(*(ptr)))__gue_val; \
16677+ (x) = (__typeof__(*(ptr)))__gue_val; \
16678 } while (0)
16679
16680 #define put_user_try uaccess_try
16681@@ -532,8 +590,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
16682 extern __must_check long strlen_user(const char __user *str);
16683 extern __must_check long strnlen_user(const char __user *str, long n);
16684
16685-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
16686-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
16687+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
16688+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
16689
16690 /*
16691 * movsl can be slow when source and dest are not both 8-byte aligned
16692diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
16693index 7f760a9..04b1c65 100644
16694--- a/arch/x86/include/asm/uaccess_32.h
16695+++ b/arch/x86/include/asm/uaccess_32.h
16696@@ -11,15 +11,15 @@
16697 #include <asm/page.h>
16698
16699 unsigned long __must_check __copy_to_user_ll
16700- (void __user *to, const void *from, unsigned long n);
16701+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
16702 unsigned long __must_check __copy_from_user_ll
16703- (void *to, const void __user *from, unsigned long n);
16704+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
16705 unsigned long __must_check __copy_from_user_ll_nozero
16706- (void *to, const void __user *from, unsigned long n);
16707+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
16708 unsigned long __must_check __copy_from_user_ll_nocache
16709- (void *to, const void __user *from, unsigned long n);
16710+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
16711 unsigned long __must_check __copy_from_user_ll_nocache_nozero
16712- (void *to, const void __user *from, unsigned long n);
16713+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
16714
16715 /**
16716 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
16717@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
16718 static __always_inline unsigned long __must_check
16719 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
16720 {
16721+ if ((long)n < 0)
16722+ return n;
16723+
16724+ check_object_size(from, n, true);
16725+
16726 if (__builtin_constant_p(n)) {
16727 unsigned long ret;
16728
16729@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
16730 __copy_to_user(void __user *to, const void *from, unsigned long n)
16731 {
16732 might_fault();
16733+
16734 return __copy_to_user_inatomic(to, from, n);
16735 }
16736
16737 static __always_inline unsigned long
16738 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
16739 {
16740+ if ((long)n < 0)
16741+ return n;
16742+
16743 /* Avoid zeroing the tail if the copy fails..
16744 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
16745 * but as the zeroing behaviour is only significant when n is not
16746@@ -137,6 +146,12 @@ static __always_inline unsigned long
16747 __copy_from_user(void *to, const void __user *from, unsigned long n)
16748 {
16749 might_fault();
16750+
16751+ if ((long)n < 0)
16752+ return n;
16753+
16754+ check_object_size(to, n, false);
16755+
16756 if (__builtin_constant_p(n)) {
16757 unsigned long ret;
16758
16759@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
16760 const void __user *from, unsigned long n)
16761 {
16762 might_fault();
16763+
16764+ if ((long)n < 0)
16765+ return n;
16766+
16767 if (__builtin_constant_p(n)) {
16768 unsigned long ret;
16769
16770@@ -181,15 +200,19 @@ static __always_inline unsigned long
16771 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
16772 unsigned long n)
16773 {
16774- return __copy_from_user_ll_nocache_nozero(to, from, n);
16775+ if ((long)n < 0)
16776+ return n;
16777+
16778+ return __copy_from_user_ll_nocache_nozero(to, from, n);
16779 }
16780
16781-unsigned long __must_check copy_to_user(void __user *to,
16782- const void *from, unsigned long n);
16783-unsigned long __must_check _copy_from_user(void *to,
16784- const void __user *from,
16785- unsigned long n);
16786-
16787+extern void copy_to_user_overflow(void)
16788+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16789+ __compiletime_error("copy_to_user() buffer size is not provably correct")
16790+#else
16791+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
16792+#endif
16793+;
16794
16795 extern void copy_from_user_overflow(void)
16796 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16797@@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
16798 #endif
16799 ;
16800
16801-static inline unsigned long __must_check copy_from_user(void *to,
16802- const void __user *from,
16803- unsigned long n)
16804+/**
16805+ * copy_to_user: - Copy a block of data into user space.
16806+ * @to: Destination address, in user space.
16807+ * @from: Source address, in kernel space.
16808+ * @n: Number of bytes to copy.
16809+ *
16810+ * Context: User context only. This function may sleep.
16811+ *
16812+ * Copy data from kernel space to user space.
16813+ *
16814+ * Returns number of bytes that could not be copied.
16815+ * On success, this will be zero.
16816+ */
16817+static inline unsigned long __must_check
16818+copy_to_user(void __user *to, const void *from, unsigned long n)
16819 {
16820- int sz = __compiletime_object_size(to);
16821+ size_t sz = __compiletime_object_size(from);
16822
16823- if (likely(sz == -1 || sz >= n))
16824- n = _copy_from_user(to, from, n);
16825- else
16826+ if (unlikely(sz != (size_t)-1 && sz < n))
16827+ copy_to_user_overflow();
16828+ else if (access_ok(VERIFY_WRITE, to, n))
16829+ n = __copy_to_user(to, from, n);
16830+ return n;
16831+}
16832+
16833+/**
16834+ * copy_from_user: - Copy a block of data from user space.
16835+ * @to: Destination address, in kernel space.
16836+ * @from: Source address, in user space.
16837+ * @n: Number of bytes to copy.
16838+ *
16839+ * Context: User context only. This function may sleep.
16840+ *
16841+ * Copy data from user space to kernel space.
16842+ *
16843+ * Returns number of bytes that could not be copied.
16844+ * On success, this will be zero.
16845+ *
16846+ * If some data could not be copied, this function will pad the copied
16847+ * data to the requested size using zero bytes.
16848+ */
16849+static inline unsigned long __must_check
16850+copy_from_user(void *to, const void __user *from, unsigned long n)
16851+{
16852+ size_t sz = __compiletime_object_size(to);
16853+
16854+ check_object_size(to, n, false);
16855+
16856+ if (unlikely(sz != (size_t)-1 && sz < n))
16857 copy_from_user_overflow();
16858-
16859+ else if (access_ok(VERIFY_READ, from, n))
16860+ n = __copy_from_user(to, from, n);
16861+ else if ((long)n > 0)
16862+ memset(to, 0, n);
16863 return n;
16864 }
16865
16866diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
16867index 142810c..1f2a0a7 100644
16868--- a/arch/x86/include/asm/uaccess_64.h
16869+++ b/arch/x86/include/asm/uaccess_64.h
16870@@ -10,6 +10,9 @@
16871 #include <asm/alternative.h>
16872 #include <asm/cpufeature.h>
16873 #include <asm/page.h>
16874+#include <asm/pgtable.h>
16875+
16876+#define set_fs(x) (current_thread_info()->addr_limit = (x))
16877
16878 /*
16879 * Copy To/From Userspace
16880@@ -17,13 +20,13 @@
16881
16882 /* Handles exceptions in both to and from, but doesn't do access_ok */
16883 __must_check unsigned long
16884-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
16885+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
16886 __must_check unsigned long
16887-copy_user_generic_string(void *to, const void *from, unsigned len);
16888+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
16889 __must_check unsigned long
16890-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
16891+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
16892
16893-static __always_inline __must_check unsigned long
16894+static __always_inline __must_check __size_overflow(3) unsigned long
16895 copy_user_generic(void *to, const void *from, unsigned len)
16896 {
16897 unsigned ret;
16898@@ -41,142 +44,204 @@ copy_user_generic(void *to, const void *from, unsigned len)
16899 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
16900 "=d" (len)),
16901 "1" (to), "2" (from), "3" (len)
16902- : "memory", "rcx", "r8", "r9", "r10", "r11");
16903+ : "memory", "rcx", "r8", "r9", "r11");
16904 return ret;
16905 }
16906
16907+static __always_inline __must_check unsigned long
16908+__copy_to_user(void __user *to, const void *from, unsigned long len);
16909+static __always_inline __must_check unsigned long
16910+__copy_from_user(void *to, const void __user *from, unsigned long len);
16911 __must_check unsigned long
16912-_copy_to_user(void __user *to, const void *from, unsigned len);
16913-__must_check unsigned long
16914-_copy_from_user(void *to, const void __user *from, unsigned len);
16915-__must_check unsigned long
16916-copy_in_user(void __user *to, const void __user *from, unsigned len);
16917+copy_in_user(void __user *to, const void __user *from, unsigned long len);
16918+
16919+extern void copy_to_user_overflow(void)
16920+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16921+ __compiletime_error("copy_to_user() buffer size is not provably correct")
16922+#else
16923+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
16924+#endif
16925+;
16926+
16927+extern void copy_from_user_overflow(void)
16928+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16929+ __compiletime_error("copy_from_user() buffer size is not provably correct")
16930+#else
16931+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
16932+#endif
16933+;
16934
16935 static inline unsigned long __must_check copy_from_user(void *to,
16936 const void __user *from,
16937 unsigned long n)
16938 {
16939- int sz = __compiletime_object_size(to);
16940-
16941 might_fault();
16942- if (likely(sz == -1 || sz >= n))
16943- n = _copy_from_user(to, from, n);
16944-#ifdef CONFIG_DEBUG_VM
16945- else
16946- WARN(1, "Buffer overflow detected!\n");
16947-#endif
16948+
16949+ check_object_size(to, n, false);
16950+
16951+ if (access_ok(VERIFY_READ, from, n))
16952+ n = __copy_from_user(to, from, n);
16953+ else if (n < INT_MAX)
16954+ memset(to, 0, n);
16955 return n;
16956 }
16957
16958 static __always_inline __must_check
16959-int copy_to_user(void __user *dst, const void *src, unsigned size)
16960+int copy_to_user(void __user *dst, const void *src, unsigned long size)
16961 {
16962 might_fault();
16963
16964- return _copy_to_user(dst, src, size);
16965+ if (access_ok(VERIFY_WRITE, dst, size))
16966+ size = __copy_to_user(dst, src, size);
16967+ return size;
16968 }
16969
16970 static __always_inline __must_check
16971-int __copy_from_user(void *dst, const void __user *src, unsigned size)
16972+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
16973 {
16974- int ret = 0;
16975+ size_t sz = __compiletime_object_size(dst);
16976+ unsigned ret = 0;
16977
16978 might_fault();
16979+
16980+ if (size > INT_MAX)
16981+ return size;
16982+
16983+ check_object_size(dst, size, false);
16984+
16985+#ifdef CONFIG_PAX_MEMORY_UDEREF
16986+ if (!__access_ok(VERIFY_READ, src, size))
16987+ return size;
16988+#endif
16989+
16990+ if (unlikely(sz != (size_t)-1 && sz < size)) {
16991+ copy_from_user_overflow();
16992+ return size;
16993+ }
16994+
16995 if (!__builtin_constant_p(size))
16996- return copy_user_generic(dst, (__force void *)src, size);
16997+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16998 switch (size) {
16999- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
17000+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
17001 ret, "b", "b", "=q", 1);
17002 return ret;
17003- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
17004+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
17005 ret, "w", "w", "=r", 2);
17006 return ret;
17007- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
17008+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
17009 ret, "l", "k", "=r", 4);
17010 return ret;
17011- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
17012+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
17013 ret, "q", "", "=r", 8);
17014 return ret;
17015 case 10:
17016- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
17017+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
17018 ret, "q", "", "=r", 10);
17019 if (unlikely(ret))
17020 return ret;
17021 __get_user_asm(*(u16 *)(8 + (char *)dst),
17022- (u16 __user *)(8 + (char __user *)src),
17023+ (const u16 __user *)(8 + (const char __user *)src),
17024 ret, "w", "w", "=r", 2);
17025 return ret;
17026 case 16:
17027- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
17028+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
17029 ret, "q", "", "=r", 16);
17030 if (unlikely(ret))
17031 return ret;
17032 __get_user_asm(*(u64 *)(8 + (char *)dst),
17033- (u64 __user *)(8 + (char __user *)src),
17034+ (const u64 __user *)(8 + (const char __user *)src),
17035 ret, "q", "", "=r", 8);
17036 return ret;
17037 default:
17038- return copy_user_generic(dst, (__force void *)src, size);
17039+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
17040 }
17041 }
17042
17043 static __always_inline __must_check
17044-int __copy_to_user(void __user *dst, const void *src, unsigned size)
17045+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
17046 {
17047- int ret = 0;
17048+ size_t sz = __compiletime_object_size(src);
17049+ unsigned ret = 0;
17050
17051 might_fault();
17052+
17053+ if (size > INT_MAX)
17054+ return size;
17055+
17056+ check_object_size(src, size, true);
17057+
17058+#ifdef CONFIG_PAX_MEMORY_UDEREF
17059+ if (!__access_ok(VERIFY_WRITE, dst, size))
17060+ return size;
17061+#endif
17062+
17063+ if (unlikely(sz != (size_t)-1 && sz < size)) {
17064+ copy_to_user_overflow();
17065+ return size;
17066+ }
17067+
17068 if (!__builtin_constant_p(size))
17069- return copy_user_generic((__force void *)dst, src, size);
17070+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
17071 switch (size) {
17072- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
17073+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
17074 ret, "b", "b", "iq", 1);
17075 return ret;
17076- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
17077+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
17078 ret, "w", "w", "ir", 2);
17079 return ret;
17080- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
17081+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
17082 ret, "l", "k", "ir", 4);
17083 return ret;
17084- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
17085+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
17086 ret, "q", "", "er", 8);
17087 return ret;
17088 case 10:
17089- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
17090+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
17091 ret, "q", "", "er", 10);
17092 if (unlikely(ret))
17093 return ret;
17094 asm("":::"memory");
17095- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
17096+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
17097 ret, "w", "w", "ir", 2);
17098 return ret;
17099 case 16:
17100- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
17101+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
17102 ret, "q", "", "er", 16);
17103 if (unlikely(ret))
17104 return ret;
17105 asm("":::"memory");
17106- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
17107+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
17108 ret, "q", "", "er", 8);
17109 return ret;
17110 default:
17111- return copy_user_generic((__force void *)dst, src, size);
17112+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
17113 }
17114 }
17115
17116 static __always_inline __must_check
17117-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
17118+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
17119 {
17120- int ret = 0;
17121+ unsigned ret = 0;
17122
17123 might_fault();
17124+
17125+ if (size > INT_MAX)
17126+ return size;
17127+
17128+#ifdef CONFIG_PAX_MEMORY_UDEREF
17129+ if (!__access_ok(VERIFY_READ, src, size))
17130+ return size;
17131+ if (!__access_ok(VERIFY_WRITE, dst, size))
17132+ return size;
17133+#endif
17134+
17135 if (!__builtin_constant_p(size))
17136- return copy_user_generic((__force void *)dst,
17137- (__force void *)src, size);
17138+ return copy_user_generic((__force_kernel void *)____m(dst),
17139+ (__force_kernel const void *)____m(src), size);
17140 switch (size) {
17141 case 1: {
17142 u8 tmp;
17143- __get_user_asm(tmp, (u8 __user *)src,
17144+ __get_user_asm(tmp, (const u8 __user *)src,
17145 ret, "b", "b", "=q", 1);
17146 if (likely(!ret))
17147 __put_user_asm(tmp, (u8 __user *)dst,
17148@@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
17149 }
17150 case 2: {
17151 u16 tmp;
17152- __get_user_asm(tmp, (u16 __user *)src,
17153+ __get_user_asm(tmp, (const u16 __user *)src,
17154 ret, "w", "w", "=r", 2);
17155 if (likely(!ret))
17156 __put_user_asm(tmp, (u16 __user *)dst,
17157@@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
17158
17159 case 4: {
17160 u32 tmp;
17161- __get_user_asm(tmp, (u32 __user *)src,
17162+ __get_user_asm(tmp, (const u32 __user *)src,
17163 ret, "l", "k", "=r", 4);
17164 if (likely(!ret))
17165 __put_user_asm(tmp, (u32 __user *)dst,
17166@@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
17167 }
17168 case 8: {
17169 u64 tmp;
17170- __get_user_asm(tmp, (u64 __user *)src,
17171+ __get_user_asm(tmp, (const u64 __user *)src,
17172 ret, "q", "", "=r", 8);
17173 if (likely(!ret))
17174 __put_user_asm(tmp, (u64 __user *)dst,
17175@@ -212,41 +277,72 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
17176 return ret;
17177 }
17178 default:
17179- return copy_user_generic((__force void *)dst,
17180- (__force void *)src, size);
17181+ return copy_user_generic((__force_kernel void *)____m(dst),
17182+ (__force_kernel const void *)____m(src), size);
17183 }
17184 }
17185
17186 static __must_check __always_inline int
17187-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
17188+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
17189 {
17190- return copy_user_generic(dst, (__force const void *)src, size);
17191+ if (size > INT_MAX)
17192+ return size;
17193+
17194+#ifdef CONFIG_PAX_MEMORY_UDEREF
17195+ if (!__access_ok(VERIFY_READ, src, size))
17196+ return size;
17197+#endif
17198+
17199+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
17200 }
17201
17202-static __must_check __always_inline int
17203-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
17204+static __must_check __always_inline unsigned long
17205+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
17206 {
17207- return copy_user_generic((__force void *)dst, src, size);
17208+ if (size > INT_MAX)
17209+ return size;
17210+
17211+#ifdef CONFIG_PAX_MEMORY_UDEREF
17212+ if (!__access_ok(VERIFY_WRITE, dst, size))
17213+ return size;
17214+#endif
17215+
17216+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
17217 }
17218
17219-extern long __copy_user_nocache(void *dst, const void __user *src,
17220- unsigned size, int zerorest);
17221+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
17222+ unsigned long size, int zerorest) __size_overflow(3);
17223
17224-static inline int
17225-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
17226+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
17227 {
17228 might_sleep();
17229+
17230+ if (size > INT_MAX)
17231+ return size;
17232+
17233+#ifdef CONFIG_PAX_MEMORY_UDEREF
17234+ if (!__access_ok(VERIFY_READ, src, size))
17235+ return size;
17236+#endif
17237+
17238 return __copy_user_nocache(dst, src, size, 1);
17239 }
17240
17241-static inline int
17242-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
17243- unsigned size)
17244+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
17245+ unsigned long size)
17246 {
17247+ if (size > INT_MAX)
17248+ return size;
17249+
17250+#ifdef CONFIG_PAX_MEMORY_UDEREF
17251+ if (!__access_ok(VERIFY_READ, src, size))
17252+ return size;
17253+#endif
17254+
17255 return __copy_user_nocache(dst, src, size, 0);
17256 }
17257
17258-unsigned long
17259-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
17260+extern unsigned long
17261+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
17262
17263 #endif /* _ASM_X86_UACCESS_64_H */
17264diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
17265index 5b238981..77fdd78 100644
17266--- a/arch/x86/include/asm/word-at-a-time.h
17267+++ b/arch/x86/include/asm/word-at-a-time.h
17268@@ -11,7 +11,7 @@
17269 * and shift, for example.
17270 */
17271 struct word_at_a_time {
17272- const unsigned long one_bits, high_bits;
17273+ unsigned long one_bits, high_bits;
17274 };
17275
17276 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
17277diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
17278index 5769349..a3d3e2a 100644
17279--- a/arch/x86/include/asm/x86_init.h
17280+++ b/arch/x86/include/asm/x86_init.h
17281@@ -141,7 +141,7 @@ struct x86_init_ops {
17282 struct x86_init_timers timers;
17283 struct x86_init_iommu iommu;
17284 struct x86_init_pci pci;
17285-};
17286+} __no_const;
17287
17288 /**
17289 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
17290@@ -152,7 +152,7 @@ struct x86_cpuinit_ops {
17291 void (*setup_percpu_clockev)(void);
17292 void (*early_percpu_clock_init)(void);
17293 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
17294-};
17295+} __no_const;
17296
17297 /**
17298 * struct x86_platform_ops - platform specific runtime functions
17299@@ -178,7 +178,7 @@ struct x86_platform_ops {
17300 void (*save_sched_clock_state)(void);
17301 void (*restore_sched_clock_state)(void);
17302 void (*apic_post_init)(void);
17303-};
17304+} __no_const;
17305
17306 struct pci_dev;
17307
17308@@ -187,14 +187,14 @@ struct x86_msi_ops {
17309 void (*teardown_msi_irq)(unsigned int irq);
17310 void (*teardown_msi_irqs)(struct pci_dev *dev);
17311 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
17312-};
17313+} __no_const;
17314
17315 struct x86_io_apic_ops {
17316 void (*init) (void);
17317 unsigned int (*read) (unsigned int apic, unsigned int reg);
17318 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
17319 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
17320-};
17321+} __no_const;
17322
17323 extern struct x86_init_ops x86_init;
17324 extern struct x86_cpuinit_ops x86_cpuinit;
17325diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
17326index 0415cda..b43d877 100644
17327--- a/arch/x86/include/asm/xsave.h
17328+++ b/arch/x86/include/asm/xsave.h
17329@@ -71,7 +71,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
17330 return -EFAULT;
17331
17332 __asm__ __volatile__(ASM_STAC "\n"
17333- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
17334+ "1:"
17335+ __copyuser_seg
17336+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
17337 "2: " ASM_CLAC "\n"
17338 ".section .fixup,\"ax\"\n"
17339 "3: movl $-1,%[err]\n"
17340@@ -87,12 +89,14 @@ static inline int xsave_user(struct xsave_struct __user *buf)
17341 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
17342 {
17343 int err;
17344- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
17345+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
17346 u32 lmask = mask;
17347 u32 hmask = mask >> 32;
17348
17349 __asm__ __volatile__(ASM_STAC "\n"
17350- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
17351+ "1:"
17352+ __copyuser_seg
17353+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
17354 "2: " ASM_CLAC "\n"
17355 ".section .fixup,\"ax\"\n"
17356 "3: movl $-1,%[err]\n"
17357diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
17358index bbae024..e1528f9 100644
17359--- a/arch/x86/include/uapi/asm/e820.h
17360+++ b/arch/x86/include/uapi/asm/e820.h
17361@@ -63,7 +63,7 @@ struct e820map {
17362 #define ISA_START_ADDRESS 0xa0000
17363 #define ISA_END_ADDRESS 0x100000
17364
17365-#define BIOS_BEGIN 0x000a0000
17366+#define BIOS_BEGIN 0x000c0000
17367 #define BIOS_END 0x00100000
17368
17369 #define BIOS_ROM_BASE 0xffe00000
17370diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
17371index 34e923a..0c6bb6e 100644
17372--- a/arch/x86/kernel/Makefile
17373+++ b/arch/x86/kernel/Makefile
17374@@ -22,7 +22,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
17375 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
17376 obj-$(CONFIG_IRQ_WORK) += irq_work.o
17377 obj-y += probe_roms.o
17378-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
17379+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
17380 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
17381 obj-y += syscall_$(BITS).o
17382 obj-$(CONFIG_X86_64) += vsyscall_64.o
17383diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
17384index bacf4b0..4ede72e 100644
17385--- a/arch/x86/kernel/acpi/boot.c
17386+++ b/arch/x86/kernel/acpi/boot.c
17387@@ -1358,7 +1358,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
17388 * If your system is blacklisted here, but you find that acpi=force
17389 * works for you, please contact linux-acpi@vger.kernel.org
17390 */
17391-static struct dmi_system_id __initdata acpi_dmi_table[] = {
17392+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
17393 /*
17394 * Boxes that need ACPI disabled
17395 */
17396@@ -1433,7 +1433,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
17397 };
17398
17399 /* second table for DMI checks that should run after early-quirks */
17400-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
17401+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
17402 /*
17403 * HP laptops which use a DSDT reporting as HP/SB400/10000,
17404 * which includes some code which overrides all temperature
17405diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
17406index d5e0d71..6533e08 100644
17407--- a/arch/x86/kernel/acpi/sleep.c
17408+++ b/arch/x86/kernel/acpi/sleep.c
17409@@ -74,8 +74,12 @@ int acpi_suspend_lowlevel(void)
17410 #else /* CONFIG_64BIT */
17411 #ifdef CONFIG_SMP
17412 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
17413+
17414+ pax_open_kernel();
17415 early_gdt_descr.address =
17416 (unsigned long)get_cpu_gdt_table(smp_processor_id());
17417+ pax_close_kernel();
17418+
17419 initial_gs = per_cpu_offset(smp_processor_id());
17420 #endif
17421 initial_code = (unsigned long)wakeup_long64;
17422diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
17423index 13ab720..95d5442 100644
17424--- a/arch/x86/kernel/acpi/wakeup_32.S
17425+++ b/arch/x86/kernel/acpi/wakeup_32.S
17426@@ -30,13 +30,11 @@ wakeup_pmode_return:
17427 # and restore the stack ... but you need gdt for this to work
17428 movl saved_context_esp, %esp
17429
17430- movl %cs:saved_magic, %eax
17431- cmpl $0x12345678, %eax
17432+ cmpl $0x12345678, saved_magic
17433 jne bogus_magic
17434
17435 # jump to place where we left off
17436- movl saved_eip, %eax
17437- jmp *%eax
17438+ jmp *(saved_eip)
17439
17440 bogus_magic:
17441 jmp bogus_magic
17442diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
17443index ef5ccca..bd83949 100644
17444--- a/arch/x86/kernel/alternative.c
17445+++ b/arch/x86/kernel/alternative.c
17446@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
17447 */
17448 for (a = start; a < end; a++) {
17449 instr = (u8 *)&a->instr_offset + a->instr_offset;
17450+
17451+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17452+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
17453+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
17454+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
17455+#endif
17456+
17457 replacement = (u8 *)&a->repl_offset + a->repl_offset;
17458 BUG_ON(a->replacementlen > a->instrlen);
17459 BUG_ON(a->instrlen > sizeof(insnbuf));
17460@@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
17461 for (poff = start; poff < end; poff++) {
17462 u8 *ptr = (u8 *)poff + *poff;
17463
17464+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17465+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
17466+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
17467+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
17468+#endif
17469+
17470 if (!*poff || ptr < text || ptr >= text_end)
17471 continue;
17472 /* turn DS segment override prefix into lock prefix */
17473- if (*ptr == 0x3e)
17474+ if (*ktla_ktva(ptr) == 0x3e)
17475 text_poke(ptr, ((unsigned char []){0xf0}), 1);
17476 }
17477 mutex_unlock(&text_mutex);
17478@@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
17479 for (poff = start; poff < end; poff++) {
17480 u8 *ptr = (u8 *)poff + *poff;
17481
17482+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17483+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
17484+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
17485+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
17486+#endif
17487+
17488 if (!*poff || ptr < text || ptr >= text_end)
17489 continue;
17490 /* turn lock prefix into DS segment override prefix */
17491- if (*ptr == 0xf0)
17492+ if (*ktla_ktva(ptr) == 0xf0)
17493 text_poke(ptr, ((unsigned char []){0x3E}), 1);
17494 }
17495 mutex_unlock(&text_mutex);
17496@@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
17497
17498 BUG_ON(p->len > MAX_PATCH_LEN);
17499 /* prep the buffer with the original instructions */
17500- memcpy(insnbuf, p->instr, p->len);
17501+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
17502 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
17503 (unsigned long)p->instr, p->len);
17504
17505@@ -515,7 +534,7 @@ void __init alternative_instructions(void)
17506 if (!uniproc_patched || num_possible_cpus() == 1)
17507 free_init_pages("SMP alternatives",
17508 (unsigned long)__smp_locks,
17509- (unsigned long)__smp_locks_end);
17510+ PAGE_ALIGN((unsigned long)__smp_locks_end));
17511 #endif
17512
17513 apply_paravirt(__parainstructions, __parainstructions_end);
17514@@ -535,13 +554,17 @@ void __init alternative_instructions(void)
17515 * instructions. And on the local CPU you need to be protected again NMI or MCE
17516 * handlers seeing an inconsistent instruction while you patch.
17517 */
17518-void *__init_or_module text_poke_early(void *addr, const void *opcode,
17519+void *__kprobes text_poke_early(void *addr, const void *opcode,
17520 size_t len)
17521 {
17522 unsigned long flags;
17523 local_irq_save(flags);
17524- memcpy(addr, opcode, len);
17525+
17526+ pax_open_kernel();
17527+ memcpy(ktla_ktva(addr), opcode, len);
17528 sync_core();
17529+ pax_close_kernel();
17530+
17531 local_irq_restore(flags);
17532 /* Could also do a CLFLUSH here to speed up CPU recovery; but
17533 that causes hangs on some VIA CPUs. */
17534@@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
17535 */
17536 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
17537 {
17538- unsigned long flags;
17539- char *vaddr;
17540+ unsigned char *vaddr = ktla_ktva(addr);
17541 struct page *pages[2];
17542- int i;
17543+ size_t i;
17544
17545 if (!core_kernel_text((unsigned long)addr)) {
17546- pages[0] = vmalloc_to_page(addr);
17547- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
17548+ pages[0] = vmalloc_to_page(vaddr);
17549+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
17550 } else {
17551- pages[0] = virt_to_page(addr);
17552+ pages[0] = virt_to_page(vaddr);
17553 WARN_ON(!PageReserved(pages[0]));
17554- pages[1] = virt_to_page(addr + PAGE_SIZE);
17555+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
17556 }
17557 BUG_ON(!pages[0]);
17558- local_irq_save(flags);
17559- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
17560- if (pages[1])
17561- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
17562- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
17563- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
17564- clear_fixmap(FIX_TEXT_POKE0);
17565- if (pages[1])
17566- clear_fixmap(FIX_TEXT_POKE1);
17567- local_flush_tlb();
17568- sync_core();
17569- /* Could also do a CLFLUSH here to speed up CPU recovery; but
17570- that causes hangs on some VIA CPUs. */
17571+ text_poke_early(addr, opcode, len);
17572 for (i = 0; i < len; i++)
17573- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
17574- local_irq_restore(flags);
17575+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
17576 return addr;
17577 }
17578
17579diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
17580index cbf5121..812b537 100644
17581--- a/arch/x86/kernel/apic/apic.c
17582+++ b/arch/x86/kernel/apic/apic.c
17583@@ -189,7 +189,7 @@ int first_system_vector = 0xfe;
17584 /*
17585 * Debug level, exported for io_apic.c
17586 */
17587-unsigned int apic_verbosity;
17588+int apic_verbosity;
17589
17590 int pic_mode;
17591
17592@@ -1956,7 +1956,7 @@ void smp_error_interrupt(struct pt_regs *regs)
17593 apic_write(APIC_ESR, 0);
17594 v1 = apic_read(APIC_ESR);
17595 ack_APIC_irq();
17596- atomic_inc(&irq_err_count);
17597+ atomic_inc_unchecked(&irq_err_count);
17598
17599 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
17600 smp_processor_id(), v0 , v1);
17601diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
17602index 00c77cf..2dc6a2d 100644
17603--- a/arch/x86/kernel/apic/apic_flat_64.c
17604+++ b/arch/x86/kernel/apic/apic_flat_64.c
17605@@ -157,7 +157,7 @@ static int flat_probe(void)
17606 return 1;
17607 }
17608
17609-static struct apic apic_flat = {
17610+static struct apic apic_flat __read_only = {
17611 .name = "flat",
17612 .probe = flat_probe,
17613 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
17614@@ -271,7 +271,7 @@ static int physflat_probe(void)
17615 return 0;
17616 }
17617
17618-static struct apic apic_physflat = {
17619+static struct apic apic_physflat __read_only = {
17620
17621 .name = "physical flat",
17622 .probe = physflat_probe,
17623diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
17624index e145f28..2752888 100644
17625--- a/arch/x86/kernel/apic/apic_noop.c
17626+++ b/arch/x86/kernel/apic/apic_noop.c
17627@@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
17628 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
17629 }
17630
17631-struct apic apic_noop = {
17632+struct apic apic_noop __read_only = {
17633 .name = "noop",
17634 .probe = noop_probe,
17635 .acpi_madt_oem_check = NULL,
17636diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
17637index d50e364..543bee3 100644
17638--- a/arch/x86/kernel/apic/bigsmp_32.c
17639+++ b/arch/x86/kernel/apic/bigsmp_32.c
17640@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
17641 return dmi_bigsmp;
17642 }
17643
17644-static struct apic apic_bigsmp = {
17645+static struct apic apic_bigsmp __read_only = {
17646
17647 .name = "bigsmp",
17648 .probe = probe_bigsmp,
17649diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
17650index 0874799..a7a7892 100644
17651--- a/arch/x86/kernel/apic/es7000_32.c
17652+++ b/arch/x86/kernel/apic/es7000_32.c
17653@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
17654 return ret && es7000_apic_is_cluster();
17655 }
17656
17657-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
17658-static struct apic __refdata apic_es7000_cluster = {
17659+static struct apic apic_es7000_cluster __read_only = {
17660
17661 .name = "es7000",
17662 .probe = probe_es7000,
17663@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
17664 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
17665 };
17666
17667-static struct apic __refdata apic_es7000 = {
17668+static struct apic apic_es7000 __read_only = {
17669
17670 .name = "es7000",
17671 .probe = probe_es7000,
17672diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
17673index b739d39..aebc14c 100644
17674--- a/arch/x86/kernel/apic/io_apic.c
17675+++ b/arch/x86/kernel/apic/io_apic.c
17676@@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
17677 }
17678 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
17679
17680-void lock_vector_lock(void)
17681+void lock_vector_lock(void) __acquires(vector_lock)
17682 {
17683 /* Used to the online set of cpus does not change
17684 * during assign_irq_vector.
17685@@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
17686 raw_spin_lock(&vector_lock);
17687 }
17688
17689-void unlock_vector_lock(void)
17690+void unlock_vector_lock(void) __releases(vector_lock)
17691 {
17692 raw_spin_unlock(&vector_lock);
17693 }
17694@@ -2399,7 +2399,7 @@ static void ack_apic_edge(struct irq_data *data)
17695 ack_APIC_irq();
17696 }
17697
17698-atomic_t irq_mis_count;
17699+atomic_unchecked_t irq_mis_count;
17700
17701 #ifdef CONFIG_GENERIC_PENDING_IRQ
17702 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
17703@@ -2540,7 +2540,7 @@ static void ack_apic_level(struct irq_data *data)
17704 * at the cpu.
17705 */
17706 if (!(v & (1 << (i & 0x1f)))) {
17707- atomic_inc(&irq_mis_count);
17708+ atomic_inc_unchecked(&irq_mis_count);
17709
17710 eoi_ioapic_irq(irq, cfg);
17711 }
17712@@ -2567,11 +2567,13 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
17713
17714 static void irq_remap_modify_chip_defaults(struct irq_chip *chip)
17715 {
17716- chip->irq_print_chip = ir_print_prefix;
17717- chip->irq_ack = ir_ack_apic_edge;
17718- chip->irq_eoi = ir_ack_apic_level;
17719+ pax_open_kernel();
17720+ *(void **)&chip->irq_print_chip = ir_print_prefix;
17721+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
17722+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
17723
17724- chip->irq_set_affinity = set_remapped_irq_affinity;
17725+ *(void **)&chip->irq_set_affinity = set_remapped_irq_affinity;
17726+ pax_close_kernel();
17727 }
17728 #endif /* CONFIG_IRQ_REMAP */
17729
17730diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
17731index d661ee9..791fd33 100644
17732--- a/arch/x86/kernel/apic/numaq_32.c
17733+++ b/arch/x86/kernel/apic/numaq_32.c
17734@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
17735 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
17736 }
17737
17738-/* Use __refdata to keep false positive warning calm. */
17739-static struct apic __refdata apic_numaq = {
17740+static struct apic apic_numaq __read_only = {
17741
17742 .name = "NUMAQ",
17743 .probe = probe_numaq,
17744diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
17745index eb35ef9..f184a21 100644
17746--- a/arch/x86/kernel/apic/probe_32.c
17747+++ b/arch/x86/kernel/apic/probe_32.c
17748@@ -72,7 +72,7 @@ static int probe_default(void)
17749 return 1;
17750 }
17751
17752-static struct apic apic_default = {
17753+static struct apic apic_default __read_only = {
17754
17755 .name = "default",
17756 .probe = probe_default,
17757diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
17758index 77c95c0..434f8a4 100644
17759--- a/arch/x86/kernel/apic/summit_32.c
17760+++ b/arch/x86/kernel/apic/summit_32.c
17761@@ -486,7 +486,7 @@ void setup_summit(void)
17762 }
17763 #endif
17764
17765-static struct apic apic_summit = {
17766+static struct apic apic_summit __read_only = {
17767
17768 .name = "summit",
17769 .probe = probe_summit,
17770diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
17771index c88baa4..757aee1 100644
17772--- a/arch/x86/kernel/apic/x2apic_cluster.c
17773+++ b/arch/x86/kernel/apic/x2apic_cluster.c
17774@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
17775 return notifier_from_errno(err);
17776 }
17777
17778-static struct notifier_block __refdata x2apic_cpu_notifier = {
17779+static struct notifier_block x2apic_cpu_notifier = {
17780 .notifier_call = update_clusterinfo,
17781 };
17782
17783@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
17784 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
17785 }
17786
17787-static struct apic apic_x2apic_cluster = {
17788+static struct apic apic_x2apic_cluster __read_only = {
17789
17790 .name = "cluster x2apic",
17791 .probe = x2apic_cluster_probe,
17792diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
17793index 562a76d..a003c0f 100644
17794--- a/arch/x86/kernel/apic/x2apic_phys.c
17795+++ b/arch/x86/kernel/apic/x2apic_phys.c
17796@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
17797 return apic == &apic_x2apic_phys;
17798 }
17799
17800-static struct apic apic_x2apic_phys = {
17801+static struct apic apic_x2apic_phys __read_only = {
17802
17803 .name = "physical x2apic",
17804 .probe = x2apic_phys_probe,
17805diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
17806index 8cfade9..b9d04fc 100644
17807--- a/arch/x86/kernel/apic/x2apic_uv_x.c
17808+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
17809@@ -333,7 +333,7 @@ static int uv_probe(void)
17810 return apic == &apic_x2apic_uv_x;
17811 }
17812
17813-static struct apic __refdata apic_x2apic_uv_x = {
17814+static struct apic apic_x2apic_uv_x __read_only = {
17815
17816 .name = "UV large system",
17817 .probe = uv_probe,
17818diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
17819index d65464e..1035d31 100644
17820--- a/arch/x86/kernel/apm_32.c
17821+++ b/arch/x86/kernel/apm_32.c
17822@@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
17823 * This is for buggy BIOS's that refer to (real mode) segment 0x40
17824 * even though they are called in protected mode.
17825 */
17826-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
17827+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
17828 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
17829
17830 static const char driver_version[] = "1.16ac"; /* no spaces */
17831@@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
17832 BUG_ON(cpu != 0);
17833 gdt = get_cpu_gdt_table(cpu);
17834 save_desc_40 = gdt[0x40 / 8];
17835+
17836+ pax_open_kernel();
17837 gdt[0x40 / 8] = bad_bios_desc;
17838+ pax_close_kernel();
17839
17840 apm_irq_save(flags);
17841 APM_DO_SAVE_SEGS;
17842@@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
17843 &call->esi);
17844 APM_DO_RESTORE_SEGS;
17845 apm_irq_restore(flags);
17846+
17847+ pax_open_kernel();
17848 gdt[0x40 / 8] = save_desc_40;
17849+ pax_close_kernel();
17850+
17851 put_cpu();
17852
17853 return call->eax & 0xff;
17854@@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
17855 BUG_ON(cpu != 0);
17856 gdt = get_cpu_gdt_table(cpu);
17857 save_desc_40 = gdt[0x40 / 8];
17858+
17859+ pax_open_kernel();
17860 gdt[0x40 / 8] = bad_bios_desc;
17861+ pax_close_kernel();
17862
17863 apm_irq_save(flags);
17864 APM_DO_SAVE_SEGS;
17865@@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
17866 &call->eax);
17867 APM_DO_RESTORE_SEGS;
17868 apm_irq_restore(flags);
17869+
17870+ pax_open_kernel();
17871 gdt[0x40 / 8] = save_desc_40;
17872+ pax_close_kernel();
17873+
17874 put_cpu();
17875 return error;
17876 }
17877@@ -2345,12 +2359,15 @@ static int __init apm_init(void)
17878 * code to that CPU.
17879 */
17880 gdt = get_cpu_gdt_table(0);
17881+
17882+ pax_open_kernel();
17883 set_desc_base(&gdt[APM_CS >> 3],
17884 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
17885 set_desc_base(&gdt[APM_CS_16 >> 3],
17886 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
17887 set_desc_base(&gdt[APM_DS >> 3],
17888 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
17889+ pax_close_kernel();
17890
17891 proc_create("apm", 0, NULL, &apm_file_ops);
17892
17893diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
17894index 2861082..6d4718e 100644
17895--- a/arch/x86/kernel/asm-offsets.c
17896+++ b/arch/x86/kernel/asm-offsets.c
17897@@ -33,6 +33,8 @@ void common(void) {
17898 OFFSET(TI_status, thread_info, status);
17899 OFFSET(TI_addr_limit, thread_info, addr_limit);
17900 OFFSET(TI_preempt_count, thread_info, preempt_count);
17901+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
17902+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
17903
17904 BLANK();
17905 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
17906@@ -53,8 +55,26 @@ void common(void) {
17907 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
17908 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
17909 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
17910+
17911+#ifdef CONFIG_PAX_KERNEXEC
17912+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
17913 #endif
17914
17915+#ifdef CONFIG_PAX_MEMORY_UDEREF
17916+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
17917+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
17918+#ifdef CONFIG_X86_64
17919+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
17920+#endif
17921+#endif
17922+
17923+#endif
17924+
17925+ BLANK();
17926+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
17927+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
17928+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
17929+
17930 #ifdef CONFIG_XEN
17931 BLANK();
17932 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
17933diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
17934index 1b4754f..fbb4227 100644
17935--- a/arch/x86/kernel/asm-offsets_64.c
17936+++ b/arch/x86/kernel/asm-offsets_64.c
17937@@ -76,6 +76,7 @@ int main(void)
17938 BLANK();
17939 #undef ENTRY
17940
17941+ DEFINE(TSS_size, sizeof(struct tss_struct));
17942 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
17943 BLANK();
17944
17945diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
17946index a0e067d..9c7db16 100644
17947--- a/arch/x86/kernel/cpu/Makefile
17948+++ b/arch/x86/kernel/cpu/Makefile
17949@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
17950 CFLAGS_REMOVE_perf_event.o = -pg
17951 endif
17952
17953-# Make sure load_percpu_segment has no stackprotector
17954-nostackp := $(call cc-option, -fno-stack-protector)
17955-CFLAGS_common.o := $(nostackp)
17956-
17957 obj-y := intel_cacheinfo.o scattered.o topology.o
17958 obj-y += proc.o capflags.o powerflags.o common.o
17959 obj-y += vmware.o hypervisor.o mshyperv.o
17960diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
17961index 15239ff..e23e04e 100644
17962--- a/arch/x86/kernel/cpu/amd.c
17963+++ b/arch/x86/kernel/cpu/amd.c
17964@@ -733,7 +733,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
17965 unsigned int size)
17966 {
17967 /* AMD errata T13 (order #21922) */
17968- if ((c->x86 == 6)) {
17969+ if (c->x86 == 6) {
17970 /* Duron Rev A0 */
17971 if (c->x86_model == 3 && c->x86_mask == 0)
17972 size = 64;
17973diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
17974index 9c3ab43..51e6366 100644
17975--- a/arch/x86/kernel/cpu/common.c
17976+++ b/arch/x86/kernel/cpu/common.c
17977@@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
17978
17979 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
17980
17981-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
17982-#ifdef CONFIG_X86_64
17983- /*
17984- * We need valid kernel segments for data and code in long mode too
17985- * IRET will check the segment types kkeil 2000/10/28
17986- * Also sysret mandates a special GDT layout
17987- *
17988- * TLS descriptors are currently at a different place compared to i386.
17989- * Hopefully nobody expects them at a fixed place (Wine?)
17990- */
17991- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
17992- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
17993- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
17994- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
17995- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
17996- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
17997-#else
17998- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
17999- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
18000- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
18001- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
18002- /*
18003- * Segments used for calling PnP BIOS have byte granularity.
18004- * They code segments and data segments have fixed 64k limits,
18005- * the transfer segment sizes are set at run time.
18006- */
18007- /* 32-bit code */
18008- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
18009- /* 16-bit code */
18010- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
18011- /* 16-bit data */
18012- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
18013- /* 16-bit data */
18014- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
18015- /* 16-bit data */
18016- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
18017- /*
18018- * The APM segments have byte granularity and their bases
18019- * are set at run time. All have 64k limits.
18020- */
18021- /* 32-bit code */
18022- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
18023- /* 16-bit code */
18024- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
18025- /* data */
18026- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
18027-
18028- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
18029- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
18030- GDT_STACK_CANARY_INIT
18031-#endif
18032-} };
18033-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
18034-
18035 static int __init x86_xsave_setup(char *s)
18036 {
18037 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
18038@@ -389,7 +335,7 @@ void switch_to_new_gdt(int cpu)
18039 {
18040 struct desc_ptr gdt_descr;
18041
18042- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
18043+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
18044 gdt_descr.size = GDT_SIZE - 1;
18045 load_gdt(&gdt_descr);
18046 /* Reload the per-cpu base */
18047@@ -885,6 +831,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
18048 /* Filter out anything that depends on CPUID levels we don't have */
18049 filter_cpuid_features(c, true);
18050
18051+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18052+ setup_clear_cpu_cap(X86_FEATURE_SEP);
18053+#endif
18054+
18055 /* If the model name is still unset, do table lookup. */
18056 if (!c->x86_model_id[0]) {
18057 const char *p;
18058@@ -1068,10 +1018,12 @@ static __init int setup_disablecpuid(char *arg)
18059 }
18060 __setup("clearcpuid=", setup_disablecpuid);
18061
18062+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
18063+EXPORT_PER_CPU_SYMBOL(current_tinfo);
18064+
18065 #ifdef CONFIG_X86_64
18066 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
18067-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
18068- (unsigned long) nmi_idt_table };
18069+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
18070
18071 DEFINE_PER_CPU_FIRST(union irq_stack_union,
18072 irq_stack_union) __aligned(PAGE_SIZE);
18073@@ -1085,7 +1037,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
18074 EXPORT_PER_CPU_SYMBOL(current_task);
18075
18076 DEFINE_PER_CPU(unsigned long, kernel_stack) =
18077- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
18078+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
18079 EXPORT_PER_CPU_SYMBOL(kernel_stack);
18080
18081 DEFINE_PER_CPU(char *, irq_stack_ptr) =
18082@@ -1224,7 +1176,7 @@ void __cpuinit cpu_init(void)
18083 int i;
18084
18085 cpu = stack_smp_processor_id();
18086- t = &per_cpu(init_tss, cpu);
18087+ t = init_tss + cpu;
18088 oist = &per_cpu(orig_ist, cpu);
18089
18090 #ifdef CONFIG_NUMA
18091@@ -1250,7 +1202,7 @@ void __cpuinit cpu_init(void)
18092 switch_to_new_gdt(cpu);
18093 loadsegment(fs, 0);
18094
18095- load_idt((const struct desc_ptr *)&idt_descr);
18096+ load_idt(&idt_descr);
18097
18098 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
18099 syscall_init();
18100@@ -1259,7 +1211,6 @@ void __cpuinit cpu_init(void)
18101 wrmsrl(MSR_KERNEL_GS_BASE, 0);
18102 barrier();
18103
18104- x86_configure_nx();
18105 enable_x2apic();
18106
18107 /*
18108@@ -1311,7 +1262,7 @@ void __cpuinit cpu_init(void)
18109 {
18110 int cpu = smp_processor_id();
18111 struct task_struct *curr = current;
18112- struct tss_struct *t = &per_cpu(init_tss, cpu);
18113+ struct tss_struct *t = init_tss + cpu;
18114 struct thread_struct *thread = &curr->thread;
18115
18116 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
18117diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
18118index fcaabd0..7b55a26 100644
18119--- a/arch/x86/kernel/cpu/intel.c
18120+++ b/arch/x86/kernel/cpu/intel.c
18121@@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
18122 * Update the IDT descriptor and reload the IDT so that
18123 * it uses the read-only mapped virtual address.
18124 */
18125- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
18126+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
18127 load_idt(&idt_descr);
18128 }
18129 #endif
18130diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
18131index 84c1309..39b7224 100644
18132--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
18133+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
18134@@ -1017,6 +1017,22 @@ static struct attribute *default_attrs[] = {
18135 };
18136
18137 #ifdef CONFIG_AMD_NB
18138+static struct attribute *default_attrs_amd_nb[] = {
18139+ &type.attr,
18140+ &level.attr,
18141+ &coherency_line_size.attr,
18142+ &physical_line_partition.attr,
18143+ &ways_of_associativity.attr,
18144+ &number_of_sets.attr,
18145+ &size.attr,
18146+ &shared_cpu_map.attr,
18147+ &shared_cpu_list.attr,
18148+ NULL,
18149+ NULL,
18150+ NULL,
18151+ NULL
18152+};
18153+
18154 static struct attribute ** __cpuinit amd_l3_attrs(void)
18155 {
18156 static struct attribute **attrs;
18157@@ -1027,18 +1043,7 @@ static struct attribute ** __cpuinit amd_l3_attrs(void)
18158
18159 n = ARRAY_SIZE(default_attrs);
18160
18161- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
18162- n += 2;
18163-
18164- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
18165- n += 1;
18166-
18167- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
18168- if (attrs == NULL)
18169- return attrs = default_attrs;
18170-
18171- for (n = 0; default_attrs[n]; n++)
18172- attrs[n] = default_attrs[n];
18173+ attrs = default_attrs_amd_nb;
18174
18175 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
18176 attrs[n++] = &cache_disable_0.attr;
18177@@ -1089,6 +1094,13 @@ static struct kobj_type ktype_cache = {
18178 .default_attrs = default_attrs,
18179 };
18180
18181+#ifdef CONFIG_AMD_NB
18182+static struct kobj_type ktype_cache_amd_nb = {
18183+ .sysfs_ops = &sysfs_ops,
18184+ .default_attrs = default_attrs_amd_nb,
18185+};
18186+#endif
18187+
18188 static struct kobj_type ktype_percpu_entry = {
18189 .sysfs_ops = &sysfs_ops,
18190 };
18191@@ -1154,20 +1166,26 @@ static int __cpuinit cache_add_dev(struct device *dev)
18192 return retval;
18193 }
18194
18195+#ifdef CONFIG_AMD_NB
18196+ amd_l3_attrs();
18197+#endif
18198+
18199 for (i = 0; i < num_cache_leaves; i++) {
18200+ struct kobj_type *ktype;
18201+
18202 this_object = INDEX_KOBJECT_PTR(cpu, i);
18203 this_object->cpu = cpu;
18204 this_object->index = i;
18205
18206 this_leaf = CPUID4_INFO_IDX(cpu, i);
18207
18208- ktype_cache.default_attrs = default_attrs;
18209+ ktype = &ktype_cache;
18210 #ifdef CONFIG_AMD_NB
18211 if (this_leaf->base.nb)
18212- ktype_cache.default_attrs = amd_l3_attrs();
18213+ ktype = &ktype_cache_amd_nb;
18214 #endif
18215 retval = kobject_init_and_add(&(this_object->kobj),
18216- &ktype_cache,
18217+ ktype,
18218 per_cpu(ici_cache_kobject, cpu),
18219 "index%1lu", i);
18220 if (unlikely(retval)) {
18221@@ -1222,7 +1240,7 @@ static int __cpuinit cacheinfo_cpu_callback(struct notifier_block *nfb,
18222 return NOTIFY_OK;
18223 }
18224
18225-static struct notifier_block __cpuinitdata cacheinfo_cpu_notifier = {
18226+static struct notifier_block cacheinfo_cpu_notifier = {
18227 .notifier_call = cacheinfo_cpu_callback,
18228 };
18229
18230diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
18231index 80dbda8..be16652 100644
18232--- a/arch/x86/kernel/cpu/mcheck/mce.c
18233+++ b/arch/x86/kernel/cpu/mcheck/mce.c
18234@@ -45,6 +45,7 @@
18235 #include <asm/processor.h>
18236 #include <asm/mce.h>
18237 #include <asm/msr.h>
18238+#include <asm/local.h>
18239
18240 #include "mce-internal.h"
18241
18242@@ -246,7 +247,7 @@ static void print_mce(struct mce *m)
18243 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
18244 m->cs, m->ip);
18245
18246- if (m->cs == __KERNEL_CS)
18247+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
18248 print_symbol("{%s}", m->ip);
18249 pr_cont("\n");
18250 }
18251@@ -279,10 +280,10 @@ static void print_mce(struct mce *m)
18252
18253 #define PANIC_TIMEOUT 5 /* 5 seconds */
18254
18255-static atomic_t mce_paniced;
18256+static atomic_unchecked_t mce_paniced;
18257
18258 static int fake_panic;
18259-static atomic_t mce_fake_paniced;
18260+static atomic_unchecked_t mce_fake_paniced;
18261
18262 /* Panic in progress. Enable interrupts and wait for final IPI */
18263 static void wait_for_panic(void)
18264@@ -306,7 +307,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
18265 /*
18266 * Make sure only one CPU runs in machine check panic
18267 */
18268- if (atomic_inc_return(&mce_paniced) > 1)
18269+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
18270 wait_for_panic();
18271 barrier();
18272
18273@@ -314,7 +315,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
18274 console_verbose();
18275 } else {
18276 /* Don't log too much for fake panic */
18277- if (atomic_inc_return(&mce_fake_paniced) > 1)
18278+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
18279 return;
18280 }
18281 /* First print corrected ones that are still unlogged */
18282@@ -686,7 +687,7 @@ static int mce_timed_out(u64 *t)
18283 * might have been modified by someone else.
18284 */
18285 rmb();
18286- if (atomic_read(&mce_paniced))
18287+ if (atomic_read_unchecked(&mce_paniced))
18288 wait_for_panic();
18289 if (!mca_cfg.monarch_timeout)
18290 goto out;
18291@@ -1662,7 +1663,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
18292 }
18293
18294 /* Call the installed machine check handler for this CPU setup. */
18295-void (*machine_check_vector)(struct pt_regs *, long error_code) =
18296+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
18297 unexpected_machine_check;
18298
18299 /*
18300@@ -1685,7 +1686,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
18301 return;
18302 }
18303
18304+ pax_open_kernel();
18305 machine_check_vector = do_machine_check;
18306+ pax_close_kernel();
18307
18308 __mcheck_cpu_init_generic();
18309 __mcheck_cpu_init_vendor(c);
18310@@ -1699,7 +1702,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
18311 */
18312
18313 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
18314-static int mce_chrdev_open_count; /* #times opened */
18315+static local_t mce_chrdev_open_count; /* #times opened */
18316 static int mce_chrdev_open_exclu; /* already open exclusive? */
18317
18318 static int mce_chrdev_open(struct inode *inode, struct file *file)
18319@@ -1707,7 +1710,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
18320 spin_lock(&mce_chrdev_state_lock);
18321
18322 if (mce_chrdev_open_exclu ||
18323- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
18324+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
18325 spin_unlock(&mce_chrdev_state_lock);
18326
18327 return -EBUSY;
18328@@ -1715,7 +1718,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
18329
18330 if (file->f_flags & O_EXCL)
18331 mce_chrdev_open_exclu = 1;
18332- mce_chrdev_open_count++;
18333+ local_inc(&mce_chrdev_open_count);
18334
18335 spin_unlock(&mce_chrdev_state_lock);
18336
18337@@ -1726,7 +1729,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
18338 {
18339 spin_lock(&mce_chrdev_state_lock);
18340
18341- mce_chrdev_open_count--;
18342+ local_dec(&mce_chrdev_open_count);
18343 mce_chrdev_open_exclu = 0;
18344
18345 spin_unlock(&mce_chrdev_state_lock);
18346@@ -2372,7 +2375,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
18347 return NOTIFY_OK;
18348 }
18349
18350-static struct notifier_block mce_cpu_notifier __cpuinitdata = {
18351+static struct notifier_block mce_cpu_notifier = {
18352 .notifier_call = mce_cpu_callback,
18353 };
18354
18355@@ -2382,7 +2385,7 @@ static __init void mce_init_banks(void)
18356
18357 for (i = 0; i < mca_cfg.banks; i++) {
18358 struct mce_bank *b = &mce_banks[i];
18359- struct device_attribute *a = &b->attr;
18360+ device_attribute_no_const *a = &b->attr;
18361
18362 sysfs_attr_init(&a->attr);
18363 a->attr.name = b->attrname;
18364@@ -2450,7 +2453,7 @@ struct dentry *mce_get_debugfs_dir(void)
18365 static void mce_reset(void)
18366 {
18367 cpu_missing = 0;
18368- atomic_set(&mce_fake_paniced, 0);
18369+ atomic_set_unchecked(&mce_fake_paniced, 0);
18370 atomic_set(&mce_executing, 0);
18371 atomic_set(&mce_callin, 0);
18372 atomic_set(&global_nwo, 0);
18373diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
18374index 2d5454c..51987eb 100644
18375--- a/arch/x86/kernel/cpu/mcheck/p5.c
18376+++ b/arch/x86/kernel/cpu/mcheck/p5.c
18377@@ -11,6 +11,7 @@
18378 #include <asm/processor.h>
18379 #include <asm/mce.h>
18380 #include <asm/msr.h>
18381+#include <asm/pgtable.h>
18382
18383 /* By default disabled */
18384 int mce_p5_enabled __read_mostly;
18385@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
18386 if (!cpu_has(c, X86_FEATURE_MCE))
18387 return;
18388
18389+ pax_open_kernel();
18390 machine_check_vector = pentium_machine_check;
18391+ pax_close_kernel();
18392 /* Make sure the vector pointer is visible before we enable MCEs: */
18393 wmb();
18394
18395diff --git a/arch/x86/kernel/cpu/mcheck/therm_throt.c b/arch/x86/kernel/cpu/mcheck/therm_throt.c
18396index 47a1870..8c019a7 100644
18397--- a/arch/x86/kernel/cpu/mcheck/therm_throt.c
18398+++ b/arch/x86/kernel/cpu/mcheck/therm_throt.c
18399@@ -288,7 +288,7 @@ thermal_throttle_cpu_callback(struct notifier_block *nfb,
18400 return notifier_from_errno(err);
18401 }
18402
18403-static struct notifier_block thermal_throttle_cpu_notifier __cpuinitdata =
18404+static struct notifier_block thermal_throttle_cpu_notifier =
18405 {
18406 .notifier_call = thermal_throttle_cpu_callback,
18407 };
18408diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
18409index 2d7998f..17c9de1 100644
18410--- a/arch/x86/kernel/cpu/mcheck/winchip.c
18411+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
18412@@ -10,6 +10,7 @@
18413 #include <asm/processor.h>
18414 #include <asm/mce.h>
18415 #include <asm/msr.h>
18416+#include <asm/pgtable.h>
18417
18418 /* Machine check handler for WinChip C6: */
18419 static void winchip_machine_check(struct pt_regs *regs, long error_code)
18420@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
18421 {
18422 u32 lo, hi;
18423
18424+ pax_open_kernel();
18425 machine_check_vector = winchip_machine_check;
18426+ pax_close_kernel();
18427 /* Make sure the vector pointer is visible before we enable MCEs: */
18428 wmb();
18429
18430diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
18431index 726bf96..81f0526 100644
18432--- a/arch/x86/kernel/cpu/mtrr/main.c
18433+++ b/arch/x86/kernel/cpu/mtrr/main.c
18434@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
18435 u64 size_or_mask, size_and_mask;
18436 static bool mtrr_aps_delayed_init;
18437
18438-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
18439+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
18440
18441 const struct mtrr_ops *mtrr_if;
18442
18443diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
18444index df5e41f..816c719 100644
18445--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
18446+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
18447@@ -25,7 +25,7 @@ struct mtrr_ops {
18448 int (*validate_add_page)(unsigned long base, unsigned long size,
18449 unsigned int type);
18450 int (*have_wrcomb)(void);
18451-};
18452+} __do_const;
18453
18454 extern int generic_get_free_region(unsigned long base, unsigned long size,
18455 int replace_reg);
18456diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
18457index 6774c17..72c1b22 100644
18458--- a/arch/x86/kernel/cpu/perf_event.c
18459+++ b/arch/x86/kernel/cpu/perf_event.c
18460@@ -1305,7 +1305,7 @@ static void __init pmu_check_apic(void)
18461 pr_info("no hardware sampling interrupt available.\n");
18462 }
18463
18464-static struct attribute_group x86_pmu_format_group = {
18465+static attribute_group_no_const x86_pmu_format_group = {
18466 .name = "format",
18467 .attrs = NULL,
18468 };
18469@@ -1313,7 +1313,7 @@ static struct attribute_group x86_pmu_format_group = {
18470 struct perf_pmu_events_attr {
18471 struct device_attribute attr;
18472 u64 id;
18473-};
18474+} __do_const;
18475
18476 /*
18477 * Remove all undefined events (x86_pmu.event_map(id) == 0)
18478@@ -1381,7 +1381,7 @@ static struct attribute *events_attr[] = {
18479 NULL,
18480 };
18481
18482-static struct attribute_group x86_pmu_events_group = {
18483+static attribute_group_no_const x86_pmu_events_group = {
18484 .name = "events",
18485 .attrs = events_attr,
18486 };
18487@@ -1880,7 +1880,7 @@ static unsigned long get_segment_base(unsigned int segment)
18488 if (idx > GDT_ENTRIES)
18489 return 0;
18490
18491- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
18492+ desc = get_cpu_gdt_table(smp_processor_id());
18493 }
18494
18495 return get_desc_base(desc + idx);
18496@@ -1970,7 +1970,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
18497 break;
18498
18499 perf_callchain_store(entry, frame.return_address);
18500- fp = frame.next_frame;
18501+ fp = (const void __force_user *)frame.next_frame;
18502 }
18503 }
18504
18505diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
18506index 4914e94..60b06e3 100644
18507--- a/arch/x86/kernel/cpu/perf_event_intel.c
18508+++ b/arch/x86/kernel/cpu/perf_event_intel.c
18509@@ -1958,10 +1958,10 @@ __init int intel_pmu_init(void)
18510 * v2 and above have a perf capabilities MSR
18511 */
18512 if (version > 1) {
18513- u64 capabilities;
18514+ u64 capabilities = x86_pmu.intel_cap.capabilities;
18515
18516- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
18517- x86_pmu.intel_cap.capabilities = capabilities;
18518+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
18519+ x86_pmu.intel_cap.capabilities = capabilities;
18520 }
18521
18522 intel_ds_init();
18523diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
18524index b43200d..d235b3e 100644
18525--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
18526+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
18527@@ -2428,7 +2428,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
18528 static int __init uncore_type_init(struct intel_uncore_type *type)
18529 {
18530 struct intel_uncore_pmu *pmus;
18531- struct attribute_group *events_group;
18532+ attribute_group_no_const *attr_group;
18533 struct attribute **attrs;
18534 int i, j;
18535
18536@@ -2455,19 +2455,19 @@ static int __init uncore_type_init(struct intel_uncore_type *type)
18537 while (type->event_descs[i].attr.attr.name)
18538 i++;
18539
18540- events_group = kzalloc(sizeof(struct attribute *) * (i + 1) +
18541- sizeof(*events_group), GFP_KERNEL);
18542- if (!events_group)
18543+ attr_group = kzalloc(sizeof(struct attribute *) * (i + 1) +
18544+ sizeof(*attr_group), GFP_KERNEL);
18545+ if (!attr_group)
18546 goto fail;
18547
18548- attrs = (struct attribute **)(events_group + 1);
18549- events_group->name = "events";
18550- events_group->attrs = attrs;
18551+ attrs = (struct attribute **)(attr_group + 1);
18552+ attr_group->name = "events";
18553+ attr_group->attrs = attrs;
18554
18555 for (j = 0; j < i; j++)
18556 attrs[j] = &type->event_descs[j].attr.attr;
18557
18558- type->events_group = events_group;
18559+ type->events_group = attr_group;
18560 }
18561
18562 type->pmu_group = &uncore_pmu_attr_group;
18563@@ -2826,7 +2826,7 @@ static int
18564 return NOTIFY_OK;
18565 }
18566
18567-static struct notifier_block uncore_cpu_nb __cpuinitdata = {
18568+static struct notifier_block uncore_cpu_nb = {
18569 .notifier_call = uncore_cpu_notifier,
18570 /*
18571 * to migrate uncore events, our notifier should be executed
18572diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
18573index e68a455..975a932 100644
18574--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
18575+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
18576@@ -428,7 +428,7 @@ struct intel_uncore_box {
18577 struct uncore_event_desc {
18578 struct kobj_attribute attr;
18579 const char *config;
18580-};
18581+} __do_const;
18582
18583 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
18584 { \
18585diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
18586index 60c7891..9e911d3 100644
18587--- a/arch/x86/kernel/cpuid.c
18588+++ b/arch/x86/kernel/cpuid.c
18589@@ -171,7 +171,7 @@ static int __cpuinit cpuid_class_cpu_callback(struct notifier_block *nfb,
18590 return notifier_from_errno(err);
18591 }
18592
18593-static struct notifier_block __refdata cpuid_class_cpu_notifier =
18594+static struct notifier_block cpuid_class_cpu_notifier =
18595 {
18596 .notifier_call = cpuid_class_cpu_callback,
18597 };
18598diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
18599index 74467fe..18793d5 100644
18600--- a/arch/x86/kernel/crash.c
18601+++ b/arch/x86/kernel/crash.c
18602@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
18603 {
18604 #ifdef CONFIG_X86_32
18605 struct pt_regs fixed_regs;
18606-#endif
18607
18608-#ifdef CONFIG_X86_32
18609- if (!user_mode_vm(regs)) {
18610+ if (!user_mode(regs)) {
18611 crash_fixup_ss_esp(&fixed_regs, regs);
18612 regs = &fixed_regs;
18613 }
18614diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
18615index 37250fe..bf2ec74 100644
18616--- a/arch/x86/kernel/doublefault_32.c
18617+++ b/arch/x86/kernel/doublefault_32.c
18618@@ -11,7 +11,7 @@
18619
18620 #define DOUBLEFAULT_STACKSIZE (1024)
18621 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
18622-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
18623+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
18624
18625 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
18626
18627@@ -21,7 +21,7 @@ static void doublefault_fn(void)
18628 unsigned long gdt, tss;
18629
18630 store_gdt(&gdt_desc);
18631- gdt = gdt_desc.address;
18632+ gdt = (unsigned long)gdt_desc.address;
18633
18634 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
18635
18636@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
18637 /* 0x2 bit is always set */
18638 .flags = X86_EFLAGS_SF | 0x2,
18639 .sp = STACK_START,
18640- .es = __USER_DS,
18641+ .es = __KERNEL_DS,
18642 .cs = __KERNEL_CS,
18643 .ss = __KERNEL_DS,
18644- .ds = __USER_DS,
18645+ .ds = __KERNEL_DS,
18646 .fs = __KERNEL_PERCPU,
18647
18648 .__cr3 = __pa_nodebug(swapper_pg_dir),
18649diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
18650index ae42418b..787c16b 100644
18651--- a/arch/x86/kernel/dumpstack.c
18652+++ b/arch/x86/kernel/dumpstack.c
18653@@ -2,6 +2,9 @@
18654 * Copyright (C) 1991, 1992 Linus Torvalds
18655 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
18656 */
18657+#ifdef CONFIG_GRKERNSEC_HIDESYM
18658+#define __INCLUDED_BY_HIDESYM 1
18659+#endif
18660 #include <linux/kallsyms.h>
18661 #include <linux/kprobes.h>
18662 #include <linux/uaccess.h>
18663@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
18664 static void
18665 print_ftrace_graph_addr(unsigned long addr, void *data,
18666 const struct stacktrace_ops *ops,
18667- struct thread_info *tinfo, int *graph)
18668+ struct task_struct *task, int *graph)
18669 {
18670- struct task_struct *task;
18671 unsigned long ret_addr;
18672 int index;
18673
18674 if (addr != (unsigned long)return_to_handler)
18675 return;
18676
18677- task = tinfo->task;
18678 index = task->curr_ret_stack;
18679
18680 if (!task->ret_stack || index < *graph)
18681@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
18682 static inline void
18683 print_ftrace_graph_addr(unsigned long addr, void *data,
18684 const struct stacktrace_ops *ops,
18685- struct thread_info *tinfo, int *graph)
18686+ struct task_struct *task, int *graph)
18687 { }
18688 #endif
18689
18690@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
18691 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
18692 */
18693
18694-static inline int valid_stack_ptr(struct thread_info *tinfo,
18695- void *p, unsigned int size, void *end)
18696+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
18697 {
18698- void *t = tinfo;
18699 if (end) {
18700 if (p < end && p >= (end-THREAD_SIZE))
18701 return 1;
18702@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
18703 }
18704
18705 unsigned long
18706-print_context_stack(struct thread_info *tinfo,
18707+print_context_stack(struct task_struct *task, void *stack_start,
18708 unsigned long *stack, unsigned long bp,
18709 const struct stacktrace_ops *ops, void *data,
18710 unsigned long *end, int *graph)
18711 {
18712 struct stack_frame *frame = (struct stack_frame *)bp;
18713
18714- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
18715+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
18716 unsigned long addr;
18717
18718 addr = *stack;
18719@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
18720 } else {
18721 ops->address(data, addr, 0);
18722 }
18723- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
18724+ print_ftrace_graph_addr(addr, data, ops, task, graph);
18725 }
18726 stack++;
18727 }
18728@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
18729 EXPORT_SYMBOL_GPL(print_context_stack);
18730
18731 unsigned long
18732-print_context_stack_bp(struct thread_info *tinfo,
18733+print_context_stack_bp(struct task_struct *task, void *stack_start,
18734 unsigned long *stack, unsigned long bp,
18735 const struct stacktrace_ops *ops, void *data,
18736 unsigned long *end, int *graph)
18737@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
18738 struct stack_frame *frame = (struct stack_frame *)bp;
18739 unsigned long *ret_addr = &frame->return_address;
18740
18741- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
18742+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
18743 unsigned long addr = *ret_addr;
18744
18745 if (!__kernel_text_address(addr))
18746@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
18747 ops->address(data, addr, 1);
18748 frame = frame->next_frame;
18749 ret_addr = &frame->return_address;
18750- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
18751+ print_ftrace_graph_addr(addr, data, ops, task, graph);
18752 }
18753
18754 return (unsigned long)frame;
18755@@ -189,7 +188,7 @@ void dump_stack(void)
18756
18757 bp = stack_frame(current, NULL);
18758 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
18759- current->pid, current->comm, print_tainted(),
18760+ task_pid_nr(current), current->comm, print_tainted(),
18761 init_utsname()->release,
18762 (int)strcspn(init_utsname()->version, " "),
18763 init_utsname()->version);
18764@@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
18765 }
18766 EXPORT_SYMBOL_GPL(oops_begin);
18767
18768+extern void gr_handle_kernel_exploit(void);
18769+
18770 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
18771 {
18772 if (regs && kexec_should_crash(current))
18773@@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
18774 panic("Fatal exception in interrupt");
18775 if (panic_on_oops)
18776 panic("Fatal exception");
18777- do_exit(signr);
18778+
18779+ gr_handle_kernel_exploit();
18780+
18781+ do_group_exit(signr);
18782 }
18783
18784 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
18785@@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
18786 print_modules();
18787 show_regs(regs);
18788 #ifdef CONFIG_X86_32
18789- if (user_mode_vm(regs)) {
18790+ if (user_mode(regs)) {
18791 sp = regs->sp;
18792 ss = regs->ss & 0xffff;
18793 } else {
18794@@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
18795 unsigned long flags = oops_begin();
18796 int sig = SIGSEGV;
18797
18798- if (!user_mode_vm(regs))
18799+ if (!user_mode(regs))
18800 report_bug(regs->ip, regs);
18801
18802 if (__die(str, regs, err))
18803diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
18804index 1038a41..db2c12b 100644
18805--- a/arch/x86/kernel/dumpstack_32.c
18806+++ b/arch/x86/kernel/dumpstack_32.c
18807@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18808 bp = stack_frame(task, regs);
18809
18810 for (;;) {
18811- struct thread_info *context;
18812+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
18813
18814- context = (struct thread_info *)
18815- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
18816- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
18817+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
18818
18819- stack = (unsigned long *)context->previous_esp;
18820- if (!stack)
18821+ if (stack_start == task_stack_page(task))
18822 break;
18823+ stack = *(unsigned long **)stack_start;
18824 if (ops->stack(data, "IRQ") < 0)
18825 break;
18826 touch_nmi_watchdog();
18827@@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
18828 {
18829 int i;
18830
18831- __show_regs(regs, !user_mode_vm(regs));
18832+ __show_regs(regs, !user_mode(regs));
18833
18834 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
18835 TASK_COMM_LEN, current->comm, task_pid_nr(current),
18836@@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
18837 * When in-kernel, we also print out the stack and code at the
18838 * time of the fault..
18839 */
18840- if (!user_mode_vm(regs)) {
18841+ if (!user_mode(regs)) {
18842 unsigned int code_prologue = code_bytes * 43 / 64;
18843 unsigned int code_len = code_bytes;
18844 unsigned char c;
18845 u8 *ip;
18846+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
18847
18848 pr_emerg("Stack:\n");
18849 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
18850
18851 pr_emerg("Code:");
18852
18853- ip = (u8 *)regs->ip - code_prologue;
18854+ ip = (u8 *)regs->ip - code_prologue + cs_base;
18855 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
18856 /* try starting at IP */
18857- ip = (u8 *)regs->ip;
18858+ ip = (u8 *)regs->ip + cs_base;
18859 code_len = code_len - code_prologue + 1;
18860 }
18861 for (i = 0; i < code_len; i++, ip++) {
18862@@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
18863 pr_cont(" Bad EIP value.");
18864 break;
18865 }
18866- if (ip == (u8 *)regs->ip)
18867+ if (ip == (u8 *)regs->ip + cs_base)
18868 pr_cont(" <%02x>", c);
18869 else
18870 pr_cont(" %02x", c);
18871@@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
18872 {
18873 unsigned short ud2;
18874
18875+ ip = ktla_ktva(ip);
18876 if (ip < PAGE_OFFSET)
18877 return 0;
18878 if (probe_kernel_address((unsigned short *)ip, ud2))
18879@@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
18880
18881 return ud2 == 0x0b0f;
18882 }
18883+
18884+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18885+void pax_check_alloca(unsigned long size)
18886+{
18887+ unsigned long sp = (unsigned long)&sp, stack_left;
18888+
18889+ /* all kernel stacks are of the same size */
18890+ stack_left = sp & (THREAD_SIZE - 1);
18891+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18892+}
18893+EXPORT_SYMBOL(pax_check_alloca);
18894+#endif
18895diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
18896index b653675..51cc8c0 100644
18897--- a/arch/x86/kernel/dumpstack_64.c
18898+++ b/arch/x86/kernel/dumpstack_64.c
18899@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18900 unsigned long *irq_stack_end =
18901 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
18902 unsigned used = 0;
18903- struct thread_info *tinfo;
18904 int graph = 0;
18905 unsigned long dummy;
18906+ void *stack_start;
18907
18908 if (!task)
18909 task = current;
18910@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18911 * current stack address. If the stacks consist of nested
18912 * exceptions
18913 */
18914- tinfo = task_thread_info(task);
18915 for (;;) {
18916 char *id;
18917 unsigned long *estack_end;
18918+
18919 estack_end = in_exception_stack(cpu, (unsigned long)stack,
18920 &used, &id);
18921
18922@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18923 if (ops->stack(data, id) < 0)
18924 break;
18925
18926- bp = ops->walk_stack(tinfo, stack, bp, ops,
18927+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
18928 data, estack_end, &graph);
18929 ops->stack(data, "<EOE>");
18930 /*
18931@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18932 * second-to-last pointer (index -2 to end) in the
18933 * exception stack:
18934 */
18935+ if ((u16)estack_end[-1] != __KERNEL_DS)
18936+ goto out;
18937 stack = (unsigned long *) estack_end[-2];
18938 continue;
18939 }
18940@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18941 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
18942 if (ops->stack(data, "IRQ") < 0)
18943 break;
18944- bp = ops->walk_stack(tinfo, stack, bp,
18945+ bp = ops->walk_stack(task, irq_stack, stack, bp,
18946 ops, data, irq_stack_end, &graph);
18947 /*
18948 * We link to the next stack (which would be
18949@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18950 /*
18951 * This handles the process stack:
18952 */
18953- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
18954+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
18955+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
18956+out:
18957 put_cpu();
18958 }
18959 EXPORT_SYMBOL(dump_trace);
18960@@ -249,7 +253,7 @@ void show_regs(struct pt_regs *regs)
18961 {
18962 int i;
18963 unsigned long sp;
18964- const int cpu = smp_processor_id();
18965+ const int cpu = raw_smp_processor_id();
18966 struct task_struct *cur = current;
18967
18968 sp = regs->sp;
18969@@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
18970
18971 return ud2 == 0x0b0f;
18972 }
18973+
18974+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18975+void pax_check_alloca(unsigned long size)
18976+{
18977+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
18978+ unsigned cpu, used;
18979+ char *id;
18980+
18981+ /* check the process stack first */
18982+ stack_start = (unsigned long)task_stack_page(current);
18983+ stack_end = stack_start + THREAD_SIZE;
18984+ if (likely(stack_start <= sp && sp < stack_end)) {
18985+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
18986+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18987+ return;
18988+ }
18989+
18990+ cpu = get_cpu();
18991+
18992+ /* check the irq stacks */
18993+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
18994+ stack_start = stack_end - IRQ_STACK_SIZE;
18995+ if (stack_start <= sp && sp < stack_end) {
18996+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
18997+ put_cpu();
18998+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18999+ return;
19000+ }
19001+
19002+ /* check the exception stacks */
19003+ used = 0;
19004+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
19005+ stack_start = stack_end - EXCEPTION_STKSZ;
19006+ if (stack_end && stack_start <= sp && sp < stack_end) {
19007+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
19008+ put_cpu();
19009+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
19010+ return;
19011+ }
19012+
19013+ put_cpu();
19014+
19015+ /* unknown stack */
19016+ BUG();
19017+}
19018+EXPORT_SYMBOL(pax_check_alloca);
19019+#endif
19020diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
19021index 9b9f18b..9fcaa04 100644
19022--- a/arch/x86/kernel/early_printk.c
19023+++ b/arch/x86/kernel/early_printk.c
19024@@ -7,6 +7,7 @@
19025 #include <linux/pci_regs.h>
19026 #include <linux/pci_ids.h>
19027 #include <linux/errno.h>
19028+#include <linux/sched.h>
19029 #include <asm/io.h>
19030 #include <asm/processor.h>
19031 #include <asm/fcntl.h>
19032diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
19033index 6ed91d9..6cc365b 100644
19034--- a/arch/x86/kernel/entry_32.S
19035+++ b/arch/x86/kernel/entry_32.S
19036@@ -177,13 +177,153 @@
19037 /*CFI_REL_OFFSET gs, PT_GS*/
19038 .endm
19039 .macro SET_KERNEL_GS reg
19040+
19041+#ifdef CONFIG_CC_STACKPROTECTOR
19042 movl $(__KERNEL_STACK_CANARY), \reg
19043+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
19044+ movl $(__USER_DS), \reg
19045+#else
19046+ xorl \reg, \reg
19047+#endif
19048+
19049 movl \reg, %gs
19050 .endm
19051
19052 #endif /* CONFIG_X86_32_LAZY_GS */
19053
19054-.macro SAVE_ALL
19055+.macro pax_enter_kernel
19056+#ifdef CONFIG_PAX_KERNEXEC
19057+ call pax_enter_kernel
19058+#endif
19059+.endm
19060+
19061+.macro pax_exit_kernel
19062+#ifdef CONFIG_PAX_KERNEXEC
19063+ call pax_exit_kernel
19064+#endif
19065+.endm
19066+
19067+#ifdef CONFIG_PAX_KERNEXEC
19068+ENTRY(pax_enter_kernel)
19069+#ifdef CONFIG_PARAVIRT
19070+ pushl %eax
19071+ pushl %ecx
19072+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
19073+ mov %eax, %esi
19074+#else
19075+ mov %cr0, %esi
19076+#endif
19077+ bts $16, %esi
19078+ jnc 1f
19079+ mov %cs, %esi
19080+ cmp $__KERNEL_CS, %esi
19081+ jz 3f
19082+ ljmp $__KERNEL_CS, $3f
19083+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
19084+2:
19085+#ifdef CONFIG_PARAVIRT
19086+ mov %esi, %eax
19087+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
19088+#else
19089+ mov %esi, %cr0
19090+#endif
19091+3:
19092+#ifdef CONFIG_PARAVIRT
19093+ popl %ecx
19094+ popl %eax
19095+#endif
19096+ ret
19097+ENDPROC(pax_enter_kernel)
19098+
19099+ENTRY(pax_exit_kernel)
19100+#ifdef CONFIG_PARAVIRT
19101+ pushl %eax
19102+ pushl %ecx
19103+#endif
19104+ mov %cs, %esi
19105+ cmp $__KERNEXEC_KERNEL_CS, %esi
19106+ jnz 2f
19107+#ifdef CONFIG_PARAVIRT
19108+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
19109+ mov %eax, %esi
19110+#else
19111+ mov %cr0, %esi
19112+#endif
19113+ btr $16, %esi
19114+ ljmp $__KERNEL_CS, $1f
19115+1:
19116+#ifdef CONFIG_PARAVIRT
19117+ mov %esi, %eax
19118+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
19119+#else
19120+ mov %esi, %cr0
19121+#endif
19122+2:
19123+#ifdef CONFIG_PARAVIRT
19124+ popl %ecx
19125+ popl %eax
19126+#endif
19127+ ret
19128+ENDPROC(pax_exit_kernel)
19129+#endif
19130+
19131+.macro pax_erase_kstack
19132+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
19133+ call pax_erase_kstack
19134+#endif
19135+.endm
19136+
19137+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
19138+/*
19139+ * ebp: thread_info
19140+ */
19141+ENTRY(pax_erase_kstack)
19142+ pushl %edi
19143+ pushl %ecx
19144+ pushl %eax
19145+
19146+ mov TI_lowest_stack(%ebp), %edi
19147+ mov $-0xBEEF, %eax
19148+ std
19149+
19150+1: mov %edi, %ecx
19151+ and $THREAD_SIZE_asm - 1, %ecx
19152+ shr $2, %ecx
19153+ repne scasl
19154+ jecxz 2f
19155+
19156+ cmp $2*16, %ecx
19157+ jc 2f
19158+
19159+ mov $2*16, %ecx
19160+ repe scasl
19161+ jecxz 2f
19162+ jne 1b
19163+
19164+2: cld
19165+ mov %esp, %ecx
19166+ sub %edi, %ecx
19167+
19168+ cmp $THREAD_SIZE_asm, %ecx
19169+ jb 3f
19170+ ud2
19171+3:
19172+
19173+ shr $2, %ecx
19174+ rep stosl
19175+
19176+ mov TI_task_thread_sp0(%ebp), %edi
19177+ sub $128, %edi
19178+ mov %edi, TI_lowest_stack(%ebp)
19179+
19180+ popl %eax
19181+ popl %ecx
19182+ popl %edi
19183+ ret
19184+ENDPROC(pax_erase_kstack)
19185+#endif
19186+
19187+.macro __SAVE_ALL _DS
19188 cld
19189 PUSH_GS
19190 pushl_cfi %fs
19191@@ -206,7 +346,7 @@
19192 CFI_REL_OFFSET ecx, 0
19193 pushl_cfi %ebx
19194 CFI_REL_OFFSET ebx, 0
19195- movl $(__USER_DS), %edx
19196+ movl $\_DS, %edx
19197 movl %edx, %ds
19198 movl %edx, %es
19199 movl $(__KERNEL_PERCPU), %edx
19200@@ -214,6 +354,15 @@
19201 SET_KERNEL_GS %edx
19202 .endm
19203
19204+.macro SAVE_ALL
19205+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
19206+ __SAVE_ALL __KERNEL_DS
19207+ pax_enter_kernel
19208+#else
19209+ __SAVE_ALL __USER_DS
19210+#endif
19211+.endm
19212+
19213 .macro RESTORE_INT_REGS
19214 popl_cfi %ebx
19215 CFI_RESTORE ebx
19216@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
19217 popfl_cfi
19218 jmp syscall_exit
19219 CFI_ENDPROC
19220-END(ret_from_fork)
19221+ENDPROC(ret_from_fork)
19222
19223 ENTRY(ret_from_kernel_thread)
19224 CFI_STARTPROC
19225@@ -344,7 +493,15 @@ ret_from_intr:
19226 andl $SEGMENT_RPL_MASK, %eax
19227 #endif
19228 cmpl $USER_RPL, %eax
19229+
19230+#ifdef CONFIG_PAX_KERNEXEC
19231+ jae resume_userspace
19232+
19233+ pax_exit_kernel
19234+ jmp resume_kernel
19235+#else
19236 jb resume_kernel # not returning to v8086 or userspace
19237+#endif
19238
19239 ENTRY(resume_userspace)
19240 LOCKDEP_SYS_EXIT
19241@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
19242 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
19243 # int/exception return?
19244 jne work_pending
19245- jmp restore_all
19246-END(ret_from_exception)
19247+ jmp restore_all_pax
19248+ENDPROC(ret_from_exception)
19249
19250 #ifdef CONFIG_PREEMPT
19251 ENTRY(resume_kernel)
19252@@ -372,7 +529,7 @@ need_resched:
19253 jz restore_all
19254 call preempt_schedule_irq
19255 jmp need_resched
19256-END(resume_kernel)
19257+ENDPROC(resume_kernel)
19258 #endif
19259 CFI_ENDPROC
19260 /*
19261@@ -406,30 +563,45 @@ sysenter_past_esp:
19262 /*CFI_REL_OFFSET cs, 0*/
19263 /*
19264 * Push current_thread_info()->sysenter_return to the stack.
19265- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
19266- * pushed above; +8 corresponds to copy_thread's esp0 setting.
19267 */
19268- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
19269+ pushl_cfi $0
19270 CFI_REL_OFFSET eip, 0
19271
19272 pushl_cfi %eax
19273 SAVE_ALL
19274+ GET_THREAD_INFO(%ebp)
19275+ movl TI_sysenter_return(%ebp),%ebp
19276+ movl %ebp,PT_EIP(%esp)
19277 ENABLE_INTERRUPTS(CLBR_NONE)
19278
19279 /*
19280 * Load the potential sixth argument from user stack.
19281 * Careful about security.
19282 */
19283+ movl PT_OLDESP(%esp),%ebp
19284+
19285+#ifdef CONFIG_PAX_MEMORY_UDEREF
19286+ mov PT_OLDSS(%esp),%ds
19287+1: movl %ds:(%ebp),%ebp
19288+ push %ss
19289+ pop %ds
19290+#else
19291 cmpl $__PAGE_OFFSET-3,%ebp
19292 jae syscall_fault
19293 ASM_STAC
19294 1: movl (%ebp),%ebp
19295 ASM_CLAC
19296+#endif
19297+
19298 movl %ebp,PT_EBP(%esp)
19299 _ASM_EXTABLE(1b,syscall_fault)
19300
19301 GET_THREAD_INFO(%ebp)
19302
19303+#ifdef CONFIG_PAX_RANDKSTACK
19304+ pax_erase_kstack
19305+#endif
19306+
19307 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
19308 jnz sysenter_audit
19309 sysenter_do_call:
19310@@ -444,12 +616,24 @@ sysenter_do_call:
19311 testl $_TIF_ALLWORK_MASK, %ecx
19312 jne sysexit_audit
19313 sysenter_exit:
19314+
19315+#ifdef CONFIG_PAX_RANDKSTACK
19316+ pushl_cfi %eax
19317+ movl %esp, %eax
19318+ call pax_randomize_kstack
19319+ popl_cfi %eax
19320+#endif
19321+
19322+ pax_erase_kstack
19323+
19324 /* if something modifies registers it must also disable sysexit */
19325 movl PT_EIP(%esp), %edx
19326 movl PT_OLDESP(%esp), %ecx
19327 xorl %ebp,%ebp
19328 TRACE_IRQS_ON
19329 1: mov PT_FS(%esp), %fs
19330+2: mov PT_DS(%esp), %ds
19331+3: mov PT_ES(%esp), %es
19332 PTGS_TO_GS
19333 ENABLE_INTERRUPTS_SYSEXIT
19334
19335@@ -466,6 +650,9 @@ sysenter_audit:
19336 movl %eax,%edx /* 2nd arg: syscall number */
19337 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
19338 call __audit_syscall_entry
19339+
19340+ pax_erase_kstack
19341+
19342 pushl_cfi %ebx
19343 movl PT_EAX(%esp),%eax /* reload syscall number */
19344 jmp sysenter_do_call
19345@@ -491,10 +678,16 @@ sysexit_audit:
19346
19347 CFI_ENDPROC
19348 .pushsection .fixup,"ax"
19349-2: movl $0,PT_FS(%esp)
19350+4: movl $0,PT_FS(%esp)
19351+ jmp 1b
19352+5: movl $0,PT_DS(%esp)
19353+ jmp 1b
19354+6: movl $0,PT_ES(%esp)
19355 jmp 1b
19356 .popsection
19357- _ASM_EXTABLE(1b,2b)
19358+ _ASM_EXTABLE(1b,4b)
19359+ _ASM_EXTABLE(2b,5b)
19360+ _ASM_EXTABLE(3b,6b)
19361 PTGS_TO_GS_EX
19362 ENDPROC(ia32_sysenter_target)
19363
19364@@ -509,6 +702,11 @@ ENTRY(system_call)
19365 pushl_cfi %eax # save orig_eax
19366 SAVE_ALL
19367 GET_THREAD_INFO(%ebp)
19368+
19369+#ifdef CONFIG_PAX_RANDKSTACK
19370+ pax_erase_kstack
19371+#endif
19372+
19373 # system call tracing in operation / emulation
19374 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
19375 jnz syscall_trace_entry
19376@@ -527,6 +725,15 @@ syscall_exit:
19377 testl $_TIF_ALLWORK_MASK, %ecx # current->work
19378 jne syscall_exit_work
19379
19380+restore_all_pax:
19381+
19382+#ifdef CONFIG_PAX_RANDKSTACK
19383+ movl %esp, %eax
19384+ call pax_randomize_kstack
19385+#endif
19386+
19387+ pax_erase_kstack
19388+
19389 restore_all:
19390 TRACE_IRQS_IRET
19391 restore_all_notrace:
19392@@ -583,14 +790,34 @@ ldt_ss:
19393 * compensating for the offset by changing to the ESPFIX segment with
19394 * a base address that matches for the difference.
19395 */
19396-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
19397+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
19398 mov %esp, %edx /* load kernel esp */
19399 mov PT_OLDESP(%esp), %eax /* load userspace esp */
19400 mov %dx, %ax /* eax: new kernel esp */
19401 sub %eax, %edx /* offset (low word is 0) */
19402+#ifdef CONFIG_SMP
19403+ movl PER_CPU_VAR(cpu_number), %ebx
19404+ shll $PAGE_SHIFT_asm, %ebx
19405+ addl $cpu_gdt_table, %ebx
19406+#else
19407+ movl $cpu_gdt_table, %ebx
19408+#endif
19409 shr $16, %edx
19410- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
19411- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
19412+
19413+#ifdef CONFIG_PAX_KERNEXEC
19414+ mov %cr0, %esi
19415+ btr $16, %esi
19416+ mov %esi, %cr0
19417+#endif
19418+
19419+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
19420+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
19421+
19422+#ifdef CONFIG_PAX_KERNEXEC
19423+ bts $16, %esi
19424+ mov %esi, %cr0
19425+#endif
19426+
19427 pushl_cfi $__ESPFIX_SS
19428 pushl_cfi %eax /* new kernel esp */
19429 /* Disable interrupts, but do not irqtrace this section: we
19430@@ -619,20 +846,18 @@ work_resched:
19431 movl TI_flags(%ebp), %ecx
19432 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
19433 # than syscall tracing?
19434- jz restore_all
19435+ jz restore_all_pax
19436 testb $_TIF_NEED_RESCHED, %cl
19437 jnz work_resched
19438
19439 work_notifysig: # deal with pending signals and
19440 # notify-resume requests
19441+ movl %esp, %eax
19442 #ifdef CONFIG_VM86
19443 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
19444- movl %esp, %eax
19445 jne work_notifysig_v86 # returning to kernel-space or
19446 # vm86-space
19447 1:
19448-#else
19449- movl %esp, %eax
19450 #endif
19451 TRACE_IRQS_ON
19452 ENABLE_INTERRUPTS(CLBR_NONE)
19453@@ -653,7 +878,7 @@ work_notifysig_v86:
19454 movl %eax, %esp
19455 jmp 1b
19456 #endif
19457-END(work_pending)
19458+ENDPROC(work_pending)
19459
19460 # perform syscall exit tracing
19461 ALIGN
19462@@ -661,11 +886,14 @@ syscall_trace_entry:
19463 movl $-ENOSYS,PT_EAX(%esp)
19464 movl %esp, %eax
19465 call syscall_trace_enter
19466+
19467+ pax_erase_kstack
19468+
19469 /* What it returned is what we'll actually use. */
19470 cmpl $(NR_syscalls), %eax
19471 jnae syscall_call
19472 jmp syscall_exit
19473-END(syscall_trace_entry)
19474+ENDPROC(syscall_trace_entry)
19475
19476 # perform syscall exit tracing
19477 ALIGN
19478@@ -678,21 +906,25 @@ syscall_exit_work:
19479 movl %esp, %eax
19480 call syscall_trace_leave
19481 jmp resume_userspace
19482-END(syscall_exit_work)
19483+ENDPROC(syscall_exit_work)
19484 CFI_ENDPROC
19485
19486 RING0_INT_FRAME # can't unwind into user space anyway
19487 syscall_fault:
19488+#ifdef CONFIG_PAX_MEMORY_UDEREF
19489+ push %ss
19490+ pop %ds
19491+#endif
19492 ASM_CLAC
19493 GET_THREAD_INFO(%ebp)
19494 movl $-EFAULT,PT_EAX(%esp)
19495 jmp resume_userspace
19496-END(syscall_fault)
19497+ENDPROC(syscall_fault)
19498
19499 syscall_badsys:
19500 movl $-ENOSYS,PT_EAX(%esp)
19501 jmp resume_userspace
19502-END(syscall_badsys)
19503+ENDPROC(syscall_badsys)
19504 CFI_ENDPROC
19505 /*
19506 * End of kprobes section
19507@@ -753,8 +985,15 @@ PTREGSCALL1(vm86old)
19508 * normal stack and adjusts ESP with the matching offset.
19509 */
19510 /* fixup the stack */
19511- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
19512- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
19513+#ifdef CONFIG_SMP
19514+ movl PER_CPU_VAR(cpu_number), %ebx
19515+ shll $PAGE_SHIFT_asm, %ebx
19516+ addl $cpu_gdt_table, %ebx
19517+#else
19518+ movl $cpu_gdt_table, %ebx
19519+#endif
19520+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
19521+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
19522 shl $16, %eax
19523 addl %esp, %eax /* the adjusted stack pointer */
19524 pushl_cfi $__KERNEL_DS
19525@@ -807,7 +1046,7 @@ vector=vector+1
19526 .endr
19527 2: jmp common_interrupt
19528 .endr
19529-END(irq_entries_start)
19530+ENDPROC(irq_entries_start)
19531
19532 .previous
19533 END(interrupt)
19534@@ -858,7 +1097,7 @@ ENTRY(coprocessor_error)
19535 pushl_cfi $do_coprocessor_error
19536 jmp error_code
19537 CFI_ENDPROC
19538-END(coprocessor_error)
19539+ENDPROC(coprocessor_error)
19540
19541 ENTRY(simd_coprocessor_error)
19542 RING0_INT_FRAME
19543@@ -880,7 +1119,7 @@ ENTRY(simd_coprocessor_error)
19544 #endif
19545 jmp error_code
19546 CFI_ENDPROC
19547-END(simd_coprocessor_error)
19548+ENDPROC(simd_coprocessor_error)
19549
19550 ENTRY(device_not_available)
19551 RING0_INT_FRAME
19552@@ -889,18 +1128,18 @@ ENTRY(device_not_available)
19553 pushl_cfi $do_device_not_available
19554 jmp error_code
19555 CFI_ENDPROC
19556-END(device_not_available)
19557+ENDPROC(device_not_available)
19558
19559 #ifdef CONFIG_PARAVIRT
19560 ENTRY(native_iret)
19561 iret
19562 _ASM_EXTABLE(native_iret, iret_exc)
19563-END(native_iret)
19564+ENDPROC(native_iret)
19565
19566 ENTRY(native_irq_enable_sysexit)
19567 sti
19568 sysexit
19569-END(native_irq_enable_sysexit)
19570+ENDPROC(native_irq_enable_sysexit)
19571 #endif
19572
19573 ENTRY(overflow)
19574@@ -910,7 +1149,7 @@ ENTRY(overflow)
19575 pushl_cfi $do_overflow
19576 jmp error_code
19577 CFI_ENDPROC
19578-END(overflow)
19579+ENDPROC(overflow)
19580
19581 ENTRY(bounds)
19582 RING0_INT_FRAME
19583@@ -919,7 +1158,7 @@ ENTRY(bounds)
19584 pushl_cfi $do_bounds
19585 jmp error_code
19586 CFI_ENDPROC
19587-END(bounds)
19588+ENDPROC(bounds)
19589
19590 ENTRY(invalid_op)
19591 RING0_INT_FRAME
19592@@ -928,7 +1167,7 @@ ENTRY(invalid_op)
19593 pushl_cfi $do_invalid_op
19594 jmp error_code
19595 CFI_ENDPROC
19596-END(invalid_op)
19597+ENDPROC(invalid_op)
19598
19599 ENTRY(coprocessor_segment_overrun)
19600 RING0_INT_FRAME
19601@@ -937,7 +1176,7 @@ ENTRY(coprocessor_segment_overrun)
19602 pushl_cfi $do_coprocessor_segment_overrun
19603 jmp error_code
19604 CFI_ENDPROC
19605-END(coprocessor_segment_overrun)
19606+ENDPROC(coprocessor_segment_overrun)
19607
19608 ENTRY(invalid_TSS)
19609 RING0_EC_FRAME
19610@@ -945,7 +1184,7 @@ ENTRY(invalid_TSS)
19611 pushl_cfi $do_invalid_TSS
19612 jmp error_code
19613 CFI_ENDPROC
19614-END(invalid_TSS)
19615+ENDPROC(invalid_TSS)
19616
19617 ENTRY(segment_not_present)
19618 RING0_EC_FRAME
19619@@ -953,7 +1192,7 @@ ENTRY(segment_not_present)
19620 pushl_cfi $do_segment_not_present
19621 jmp error_code
19622 CFI_ENDPROC
19623-END(segment_not_present)
19624+ENDPROC(segment_not_present)
19625
19626 ENTRY(stack_segment)
19627 RING0_EC_FRAME
19628@@ -961,7 +1200,7 @@ ENTRY(stack_segment)
19629 pushl_cfi $do_stack_segment
19630 jmp error_code
19631 CFI_ENDPROC
19632-END(stack_segment)
19633+ENDPROC(stack_segment)
19634
19635 ENTRY(alignment_check)
19636 RING0_EC_FRAME
19637@@ -969,7 +1208,7 @@ ENTRY(alignment_check)
19638 pushl_cfi $do_alignment_check
19639 jmp error_code
19640 CFI_ENDPROC
19641-END(alignment_check)
19642+ENDPROC(alignment_check)
19643
19644 ENTRY(divide_error)
19645 RING0_INT_FRAME
19646@@ -978,7 +1217,7 @@ ENTRY(divide_error)
19647 pushl_cfi $do_divide_error
19648 jmp error_code
19649 CFI_ENDPROC
19650-END(divide_error)
19651+ENDPROC(divide_error)
19652
19653 #ifdef CONFIG_X86_MCE
19654 ENTRY(machine_check)
19655@@ -988,7 +1227,7 @@ ENTRY(machine_check)
19656 pushl_cfi machine_check_vector
19657 jmp error_code
19658 CFI_ENDPROC
19659-END(machine_check)
19660+ENDPROC(machine_check)
19661 #endif
19662
19663 ENTRY(spurious_interrupt_bug)
19664@@ -998,7 +1237,7 @@ ENTRY(spurious_interrupt_bug)
19665 pushl_cfi $do_spurious_interrupt_bug
19666 jmp error_code
19667 CFI_ENDPROC
19668-END(spurious_interrupt_bug)
19669+ENDPROC(spurious_interrupt_bug)
19670 /*
19671 * End of kprobes section
19672 */
19673@@ -1101,7 +1340,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
19674
19675 ENTRY(mcount)
19676 ret
19677-END(mcount)
19678+ENDPROC(mcount)
19679
19680 ENTRY(ftrace_caller)
19681 cmpl $0, function_trace_stop
19682@@ -1134,7 +1373,7 @@ ftrace_graph_call:
19683 .globl ftrace_stub
19684 ftrace_stub:
19685 ret
19686-END(ftrace_caller)
19687+ENDPROC(ftrace_caller)
19688
19689 ENTRY(ftrace_regs_caller)
19690 pushf /* push flags before compare (in cs location) */
19691@@ -1235,7 +1474,7 @@ trace:
19692 popl %ecx
19693 popl %eax
19694 jmp ftrace_stub
19695-END(mcount)
19696+ENDPROC(mcount)
19697 #endif /* CONFIG_DYNAMIC_FTRACE */
19698 #endif /* CONFIG_FUNCTION_TRACER */
19699
19700@@ -1253,7 +1492,7 @@ ENTRY(ftrace_graph_caller)
19701 popl %ecx
19702 popl %eax
19703 ret
19704-END(ftrace_graph_caller)
19705+ENDPROC(ftrace_graph_caller)
19706
19707 .globl return_to_handler
19708 return_to_handler:
19709@@ -1309,15 +1548,18 @@ error_code:
19710 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
19711 REG_TO_PTGS %ecx
19712 SET_KERNEL_GS %ecx
19713- movl $(__USER_DS), %ecx
19714+ movl $(__KERNEL_DS), %ecx
19715 movl %ecx, %ds
19716 movl %ecx, %es
19717+
19718+ pax_enter_kernel
19719+
19720 TRACE_IRQS_OFF
19721 movl %esp,%eax # pt_regs pointer
19722 call *%edi
19723 jmp ret_from_exception
19724 CFI_ENDPROC
19725-END(page_fault)
19726+ENDPROC(page_fault)
19727
19728 /*
19729 * Debug traps and NMI can happen at the one SYSENTER instruction
19730@@ -1360,7 +1602,7 @@ debug_stack_correct:
19731 call do_debug
19732 jmp ret_from_exception
19733 CFI_ENDPROC
19734-END(debug)
19735+ENDPROC(debug)
19736
19737 /*
19738 * NMI is doubly nasty. It can happen _while_ we're handling
19739@@ -1398,6 +1640,9 @@ nmi_stack_correct:
19740 xorl %edx,%edx # zero error code
19741 movl %esp,%eax # pt_regs pointer
19742 call do_nmi
19743+
19744+ pax_exit_kernel
19745+
19746 jmp restore_all_notrace
19747 CFI_ENDPROC
19748
19749@@ -1434,12 +1679,15 @@ nmi_espfix_stack:
19750 FIXUP_ESPFIX_STACK # %eax == %esp
19751 xorl %edx,%edx # zero error code
19752 call do_nmi
19753+
19754+ pax_exit_kernel
19755+
19756 RESTORE_REGS
19757 lss 12+4(%esp), %esp # back to espfix stack
19758 CFI_ADJUST_CFA_OFFSET -24
19759 jmp irq_return
19760 CFI_ENDPROC
19761-END(nmi)
19762+ENDPROC(nmi)
19763
19764 ENTRY(int3)
19765 RING0_INT_FRAME
19766@@ -1452,14 +1700,14 @@ ENTRY(int3)
19767 call do_int3
19768 jmp ret_from_exception
19769 CFI_ENDPROC
19770-END(int3)
19771+ENDPROC(int3)
19772
19773 ENTRY(general_protection)
19774 RING0_EC_FRAME
19775 pushl_cfi $do_general_protection
19776 jmp error_code
19777 CFI_ENDPROC
19778-END(general_protection)
19779+ENDPROC(general_protection)
19780
19781 #ifdef CONFIG_KVM_GUEST
19782 ENTRY(async_page_fault)
19783@@ -1468,7 +1716,7 @@ ENTRY(async_page_fault)
19784 pushl_cfi $do_async_page_fault
19785 jmp error_code
19786 CFI_ENDPROC
19787-END(async_page_fault)
19788+ENDPROC(async_page_fault)
19789 #endif
19790
19791 /*
19792diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
19793index cb3c591..7ba137c 100644
19794--- a/arch/x86/kernel/entry_64.S
19795+++ b/arch/x86/kernel/entry_64.S
19796@@ -59,6 +59,8 @@
19797 #include <asm/context_tracking.h>
19798 #include <asm/smap.h>
19799 #include <linux/err.h>
19800+#include <asm/pgtable.h>
19801+#include <asm/alternative-asm.h>
19802
19803 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
19804 #include <linux/elf-em.h>
19805@@ -80,8 +82,9 @@
19806 #ifdef CONFIG_DYNAMIC_FTRACE
19807
19808 ENTRY(function_hook)
19809+ pax_force_retaddr
19810 retq
19811-END(function_hook)
19812+ENDPROC(function_hook)
19813
19814 /* skip is set if stack has been adjusted */
19815 .macro ftrace_caller_setup skip=0
19816@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
19817 #endif
19818
19819 GLOBAL(ftrace_stub)
19820+ pax_force_retaddr
19821 retq
19822-END(ftrace_caller)
19823+ENDPROC(ftrace_caller)
19824
19825 ENTRY(ftrace_regs_caller)
19826 /* Save the current flags before compare (in SS location)*/
19827@@ -191,7 +195,7 @@ ftrace_restore_flags:
19828 popfq
19829 jmp ftrace_stub
19830
19831-END(ftrace_regs_caller)
19832+ENDPROC(ftrace_regs_caller)
19833
19834
19835 #else /* ! CONFIG_DYNAMIC_FTRACE */
19836@@ -212,6 +216,7 @@ ENTRY(function_hook)
19837 #endif
19838
19839 GLOBAL(ftrace_stub)
19840+ pax_force_retaddr
19841 retq
19842
19843 trace:
19844@@ -225,12 +230,13 @@ trace:
19845 #endif
19846 subq $MCOUNT_INSN_SIZE, %rdi
19847
19848+ pax_force_fptr ftrace_trace_function
19849 call *ftrace_trace_function
19850
19851 MCOUNT_RESTORE_FRAME
19852
19853 jmp ftrace_stub
19854-END(function_hook)
19855+ENDPROC(function_hook)
19856 #endif /* CONFIG_DYNAMIC_FTRACE */
19857 #endif /* CONFIG_FUNCTION_TRACER */
19858
19859@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
19860
19861 MCOUNT_RESTORE_FRAME
19862
19863+ pax_force_retaddr
19864 retq
19865-END(ftrace_graph_caller)
19866+ENDPROC(ftrace_graph_caller)
19867
19868 GLOBAL(return_to_handler)
19869 subq $24, %rsp
19870@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
19871 movq 8(%rsp), %rdx
19872 movq (%rsp), %rax
19873 addq $24, %rsp
19874+ pax_force_fptr %rdi
19875 jmp *%rdi
19876+ENDPROC(return_to_handler)
19877 #endif
19878
19879
19880@@ -284,6 +293,273 @@ ENTRY(native_usergs_sysret64)
19881 ENDPROC(native_usergs_sysret64)
19882 #endif /* CONFIG_PARAVIRT */
19883
19884+ .macro ljmpq sel, off
19885+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
19886+ .byte 0x48; ljmp *1234f(%rip)
19887+ .pushsection .rodata
19888+ .align 16
19889+ 1234: .quad \off; .word \sel
19890+ .popsection
19891+#else
19892+ pushq $\sel
19893+ pushq $\off
19894+ lretq
19895+#endif
19896+ .endm
19897+
19898+ .macro pax_enter_kernel
19899+ pax_set_fptr_mask
19900+#ifdef CONFIG_PAX_KERNEXEC
19901+ call pax_enter_kernel
19902+#endif
19903+ .endm
19904+
19905+ .macro pax_exit_kernel
19906+#ifdef CONFIG_PAX_KERNEXEC
19907+ call pax_exit_kernel
19908+#endif
19909+ .endm
19910+
19911+#ifdef CONFIG_PAX_KERNEXEC
19912+ENTRY(pax_enter_kernel)
19913+ pushq %rdi
19914+
19915+#ifdef CONFIG_PARAVIRT
19916+ PV_SAVE_REGS(CLBR_RDI)
19917+#endif
19918+
19919+ GET_CR0_INTO_RDI
19920+ bts $16,%rdi
19921+ jnc 3f
19922+ mov %cs,%edi
19923+ cmp $__KERNEL_CS,%edi
19924+ jnz 2f
19925+1:
19926+
19927+#ifdef CONFIG_PARAVIRT
19928+ PV_RESTORE_REGS(CLBR_RDI)
19929+#endif
19930+
19931+ popq %rdi
19932+ pax_force_retaddr
19933+ retq
19934+
19935+2: ljmpq __KERNEL_CS,1b
19936+3: ljmpq __KERNEXEC_KERNEL_CS,4f
19937+4: SET_RDI_INTO_CR0
19938+ jmp 1b
19939+ENDPROC(pax_enter_kernel)
19940+
19941+ENTRY(pax_exit_kernel)
19942+ pushq %rdi
19943+
19944+#ifdef CONFIG_PARAVIRT
19945+ PV_SAVE_REGS(CLBR_RDI)
19946+#endif
19947+
19948+ mov %cs,%rdi
19949+ cmp $__KERNEXEC_KERNEL_CS,%edi
19950+ jz 2f
19951+1:
19952+
19953+#ifdef CONFIG_PARAVIRT
19954+ PV_RESTORE_REGS(CLBR_RDI);
19955+#endif
19956+
19957+ popq %rdi
19958+ pax_force_retaddr
19959+ retq
19960+
19961+2: GET_CR0_INTO_RDI
19962+ btr $16,%rdi
19963+ ljmpq __KERNEL_CS,3f
19964+3: SET_RDI_INTO_CR0
19965+ jmp 1b
19966+ENDPROC(pax_exit_kernel)
19967+#endif
19968+
19969+ .macro pax_enter_kernel_user
19970+ pax_set_fptr_mask
19971+#ifdef CONFIG_PAX_MEMORY_UDEREF
19972+ call pax_enter_kernel_user
19973+#endif
19974+ .endm
19975+
19976+ .macro pax_exit_kernel_user
19977+#ifdef CONFIG_PAX_MEMORY_UDEREF
19978+ call pax_exit_kernel_user
19979+#endif
19980+#ifdef CONFIG_PAX_RANDKSTACK
19981+ pushq %rax
19982+ call pax_randomize_kstack
19983+ popq %rax
19984+#endif
19985+ .endm
19986+
19987+#ifdef CONFIG_PAX_MEMORY_UDEREF
19988+ENTRY(pax_enter_kernel_user)
19989+ pushq %rdi
19990+ pushq %rbx
19991+
19992+#ifdef CONFIG_PARAVIRT
19993+ PV_SAVE_REGS(CLBR_RDI)
19994+#endif
19995+
19996+ GET_CR3_INTO_RDI
19997+ mov %rdi,%rbx
19998+ add $__START_KERNEL_map,%rbx
19999+ sub phys_base(%rip),%rbx
20000+
20001+#ifdef CONFIG_PARAVIRT
20002+ pushq %rdi
20003+ cmpl $0, pv_info+PARAVIRT_enabled
20004+ jz 1f
20005+ i = 0
20006+ .rept USER_PGD_PTRS
20007+ mov i*8(%rbx),%rsi
20008+ mov $0,%sil
20009+ lea i*8(%rbx),%rdi
20010+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
20011+ i = i + 1
20012+ .endr
20013+ jmp 2f
20014+1:
20015+#endif
20016+
20017+ i = 0
20018+ .rept USER_PGD_PTRS
20019+ movb $0,i*8(%rbx)
20020+ i = i + 1
20021+ .endr
20022+
20023+#ifdef CONFIG_PARAVIRT
20024+2: popq %rdi
20025+#endif
20026+ SET_RDI_INTO_CR3
20027+
20028+#ifdef CONFIG_PAX_KERNEXEC
20029+ GET_CR0_INTO_RDI
20030+ bts $16,%rdi
20031+ SET_RDI_INTO_CR0
20032+#endif
20033+
20034+#ifdef CONFIG_PARAVIRT
20035+ PV_RESTORE_REGS(CLBR_RDI)
20036+#endif
20037+
20038+ popq %rbx
20039+ popq %rdi
20040+ pax_force_retaddr
20041+ retq
20042+ENDPROC(pax_enter_kernel_user)
20043+
20044+ENTRY(pax_exit_kernel_user)
20045+ push %rdi
20046+
20047+#ifdef CONFIG_PARAVIRT
20048+ pushq %rbx
20049+ PV_SAVE_REGS(CLBR_RDI)
20050+#endif
20051+
20052+#ifdef CONFIG_PAX_KERNEXEC
20053+ GET_CR0_INTO_RDI
20054+ btr $16,%rdi
20055+ SET_RDI_INTO_CR0
20056+#endif
20057+
20058+ GET_CR3_INTO_RDI
20059+ add $__START_KERNEL_map,%rdi
20060+ sub phys_base(%rip),%rdi
20061+
20062+#ifdef CONFIG_PARAVIRT
20063+ cmpl $0, pv_info+PARAVIRT_enabled
20064+ jz 1f
20065+ mov %rdi,%rbx
20066+ i = 0
20067+ .rept USER_PGD_PTRS
20068+ mov i*8(%rbx),%rsi
20069+ mov $0x67,%sil
20070+ lea i*8(%rbx),%rdi
20071+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
20072+ i = i + 1
20073+ .endr
20074+ jmp 2f
20075+1:
20076+#endif
20077+
20078+ i = 0
20079+ .rept USER_PGD_PTRS
20080+ movb $0x67,i*8(%rdi)
20081+ i = i + 1
20082+ .endr
20083+
20084+#ifdef CONFIG_PARAVIRT
20085+2: PV_RESTORE_REGS(CLBR_RDI)
20086+ popq %rbx
20087+#endif
20088+
20089+ popq %rdi
20090+ pax_force_retaddr
20091+ retq
20092+ENDPROC(pax_exit_kernel_user)
20093+#endif
20094+
20095+.macro pax_erase_kstack
20096+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20097+ call pax_erase_kstack
20098+#endif
20099+.endm
20100+
20101+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20102+ENTRY(pax_erase_kstack)
20103+ pushq %rdi
20104+ pushq %rcx
20105+ pushq %rax
20106+ pushq %r11
20107+
20108+ GET_THREAD_INFO(%r11)
20109+ mov TI_lowest_stack(%r11), %rdi
20110+ mov $-0xBEEF, %rax
20111+ std
20112+
20113+1: mov %edi, %ecx
20114+ and $THREAD_SIZE_asm - 1, %ecx
20115+ shr $3, %ecx
20116+ repne scasq
20117+ jecxz 2f
20118+
20119+ cmp $2*8, %ecx
20120+ jc 2f
20121+
20122+ mov $2*8, %ecx
20123+ repe scasq
20124+ jecxz 2f
20125+ jne 1b
20126+
20127+2: cld
20128+ mov %esp, %ecx
20129+ sub %edi, %ecx
20130+
20131+ cmp $THREAD_SIZE_asm, %rcx
20132+ jb 3f
20133+ ud2
20134+3:
20135+
20136+ shr $3, %ecx
20137+ rep stosq
20138+
20139+ mov TI_task_thread_sp0(%r11), %rdi
20140+ sub $256, %rdi
20141+ mov %rdi, TI_lowest_stack(%r11)
20142+
20143+ popq %r11
20144+ popq %rax
20145+ popq %rcx
20146+ popq %rdi
20147+ pax_force_retaddr
20148+ ret
20149+ENDPROC(pax_erase_kstack)
20150+#endif
20151
20152 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
20153 #ifdef CONFIG_TRACE_IRQFLAGS
20154@@ -375,8 +651,8 @@ ENDPROC(native_usergs_sysret64)
20155 .endm
20156
20157 .macro UNFAKE_STACK_FRAME
20158- addq $8*6, %rsp
20159- CFI_ADJUST_CFA_OFFSET -(6*8)
20160+ addq $8*6 + ARG_SKIP, %rsp
20161+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
20162 .endm
20163
20164 /*
20165@@ -463,7 +739,7 @@ ENDPROC(native_usergs_sysret64)
20166 movq %rsp, %rsi
20167
20168 leaq -RBP(%rsp),%rdi /* arg1 for handler */
20169- testl $3, CS-RBP(%rsi)
20170+ testb $3, CS-RBP(%rsi)
20171 je 1f
20172 SWAPGS
20173 /*
20174@@ -498,9 +774,10 @@ ENTRY(save_rest)
20175 movq_cfi r15, R15+16
20176 movq %r11, 8(%rsp) /* return address */
20177 FIXUP_TOP_OF_STACK %r11, 16
20178+ pax_force_retaddr
20179 ret
20180 CFI_ENDPROC
20181-END(save_rest)
20182+ENDPROC(save_rest)
20183
20184 /* save complete stack frame */
20185 .pushsection .kprobes.text, "ax"
20186@@ -529,9 +806,10 @@ ENTRY(save_paranoid)
20187 js 1f /* negative -> in kernel */
20188 SWAPGS
20189 xorl %ebx,%ebx
20190-1: ret
20191+1: pax_force_retaddr_bts
20192+ ret
20193 CFI_ENDPROC
20194-END(save_paranoid)
20195+ENDPROC(save_paranoid)
20196 .popsection
20197
20198 /*
20199@@ -553,7 +831,7 @@ ENTRY(ret_from_fork)
20200
20201 RESTORE_REST
20202
20203- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
20204+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
20205 jz 1f
20206
20207 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
20208@@ -571,7 +849,7 @@ ENTRY(ret_from_fork)
20209 RESTORE_REST
20210 jmp int_ret_from_sys_call
20211 CFI_ENDPROC
20212-END(ret_from_fork)
20213+ENDPROC(ret_from_fork)
20214
20215 /*
20216 * System call entry. Up to 6 arguments in registers are supported.
20217@@ -608,7 +886,7 @@ END(ret_from_fork)
20218 ENTRY(system_call)
20219 CFI_STARTPROC simple
20220 CFI_SIGNAL_FRAME
20221- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
20222+ CFI_DEF_CFA rsp,0
20223 CFI_REGISTER rip,rcx
20224 /*CFI_REGISTER rflags,r11*/
20225 SWAPGS_UNSAFE_STACK
20226@@ -621,16 +899,23 @@ GLOBAL(system_call_after_swapgs)
20227
20228 movq %rsp,PER_CPU_VAR(old_rsp)
20229 movq PER_CPU_VAR(kernel_stack),%rsp
20230+ SAVE_ARGS 8*6,0
20231+ pax_enter_kernel_user
20232+
20233+#ifdef CONFIG_PAX_RANDKSTACK
20234+ pax_erase_kstack
20235+#endif
20236+
20237 /*
20238 * No need to follow this irqs off/on section - it's straight
20239 * and short:
20240 */
20241 ENABLE_INTERRUPTS(CLBR_NONE)
20242- SAVE_ARGS 8,0
20243 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
20244 movq %rcx,RIP-ARGOFFSET(%rsp)
20245 CFI_REL_OFFSET rip,RIP-ARGOFFSET
20246- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
20247+ GET_THREAD_INFO(%rcx)
20248+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
20249 jnz tracesys
20250 system_call_fastpath:
20251 #if __SYSCALL_MASK == ~0
20252@@ -640,7 +925,7 @@ system_call_fastpath:
20253 cmpl $__NR_syscall_max,%eax
20254 #endif
20255 ja badsys
20256- movq %r10,%rcx
20257+ movq R10-ARGOFFSET(%rsp),%rcx
20258 call *sys_call_table(,%rax,8) # XXX: rip relative
20259 movq %rax,RAX-ARGOFFSET(%rsp)
20260 /*
20261@@ -654,10 +939,13 @@ sysret_check:
20262 LOCKDEP_SYS_EXIT
20263 DISABLE_INTERRUPTS(CLBR_NONE)
20264 TRACE_IRQS_OFF
20265- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
20266+ GET_THREAD_INFO(%rcx)
20267+ movl TI_flags(%rcx),%edx
20268 andl %edi,%edx
20269 jnz sysret_careful
20270 CFI_REMEMBER_STATE
20271+ pax_exit_kernel_user
20272+ pax_erase_kstack
20273 /*
20274 * sysretq will re-enable interrupts:
20275 */
20276@@ -709,14 +997,18 @@ badsys:
20277 * jump back to the normal fast path.
20278 */
20279 auditsys:
20280- movq %r10,%r9 /* 6th arg: 4th syscall arg */
20281+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
20282 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
20283 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
20284 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
20285 movq %rax,%rsi /* 2nd arg: syscall number */
20286 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
20287 call __audit_syscall_entry
20288+
20289+ pax_erase_kstack
20290+
20291 LOAD_ARGS 0 /* reload call-clobbered registers */
20292+ pax_set_fptr_mask
20293 jmp system_call_fastpath
20294
20295 /*
20296@@ -737,7 +1029,7 @@ sysret_audit:
20297 /* Do syscall tracing */
20298 tracesys:
20299 #ifdef CONFIG_AUDITSYSCALL
20300- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
20301+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
20302 jz auditsys
20303 #endif
20304 SAVE_REST
20305@@ -745,12 +1037,16 @@ tracesys:
20306 FIXUP_TOP_OF_STACK %rdi
20307 movq %rsp,%rdi
20308 call syscall_trace_enter
20309+
20310+ pax_erase_kstack
20311+
20312 /*
20313 * Reload arg registers from stack in case ptrace changed them.
20314 * We don't reload %rax because syscall_trace_enter() returned
20315 * the value it wants us to use in the table lookup.
20316 */
20317 LOAD_ARGS ARGOFFSET, 1
20318+ pax_set_fptr_mask
20319 RESTORE_REST
20320 #if __SYSCALL_MASK == ~0
20321 cmpq $__NR_syscall_max,%rax
20322@@ -759,7 +1055,7 @@ tracesys:
20323 cmpl $__NR_syscall_max,%eax
20324 #endif
20325 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
20326- movq %r10,%rcx /* fixup for C */
20327+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
20328 call *sys_call_table(,%rax,8)
20329 movq %rax,RAX-ARGOFFSET(%rsp)
20330 /* Use IRET because user could have changed frame */
20331@@ -780,7 +1076,9 @@ GLOBAL(int_with_check)
20332 andl %edi,%edx
20333 jnz int_careful
20334 andl $~TS_COMPAT,TI_status(%rcx)
20335- jmp retint_swapgs
20336+ pax_exit_kernel_user
20337+ pax_erase_kstack
20338+ jmp retint_swapgs_pax
20339
20340 /* Either reschedule or signal or syscall exit tracking needed. */
20341 /* First do a reschedule test. */
20342@@ -826,7 +1124,7 @@ int_restore_rest:
20343 TRACE_IRQS_OFF
20344 jmp int_with_check
20345 CFI_ENDPROC
20346-END(system_call)
20347+ENDPROC(system_call)
20348
20349 /*
20350 * Certain special system calls that need to save a complete full stack frame.
20351@@ -842,7 +1140,7 @@ ENTRY(\label)
20352 call \func
20353 jmp ptregscall_common
20354 CFI_ENDPROC
20355-END(\label)
20356+ENDPROC(\label)
20357 .endm
20358
20359 .macro FORK_LIKE func
20360@@ -856,9 +1154,10 @@ ENTRY(stub_\func)
20361 DEFAULT_FRAME 0 8 /* offset 8: return address */
20362 call sys_\func
20363 RESTORE_TOP_OF_STACK %r11, 8
20364+ pax_force_retaddr
20365 ret $REST_SKIP /* pop extended registers */
20366 CFI_ENDPROC
20367-END(stub_\func)
20368+ENDPROC(stub_\func)
20369 .endm
20370
20371 FORK_LIKE clone
20372@@ -875,9 +1174,10 @@ ENTRY(ptregscall_common)
20373 movq_cfi_restore R12+8, r12
20374 movq_cfi_restore RBP+8, rbp
20375 movq_cfi_restore RBX+8, rbx
20376+ pax_force_retaddr
20377 ret $REST_SKIP /* pop extended registers */
20378 CFI_ENDPROC
20379-END(ptregscall_common)
20380+ENDPROC(ptregscall_common)
20381
20382 ENTRY(stub_execve)
20383 CFI_STARTPROC
20384@@ -891,7 +1191,7 @@ ENTRY(stub_execve)
20385 RESTORE_REST
20386 jmp int_ret_from_sys_call
20387 CFI_ENDPROC
20388-END(stub_execve)
20389+ENDPROC(stub_execve)
20390
20391 /*
20392 * sigreturn is special because it needs to restore all registers on return.
20393@@ -909,7 +1209,7 @@ ENTRY(stub_rt_sigreturn)
20394 RESTORE_REST
20395 jmp int_ret_from_sys_call
20396 CFI_ENDPROC
20397-END(stub_rt_sigreturn)
20398+ENDPROC(stub_rt_sigreturn)
20399
20400 #ifdef CONFIG_X86_X32_ABI
20401 ENTRY(stub_x32_rt_sigreturn)
20402@@ -975,7 +1275,7 @@ vector=vector+1
20403 2: jmp common_interrupt
20404 .endr
20405 CFI_ENDPROC
20406-END(irq_entries_start)
20407+ENDPROC(irq_entries_start)
20408
20409 .previous
20410 END(interrupt)
20411@@ -995,6 +1295,16 @@ END(interrupt)
20412 subq $ORIG_RAX-RBP, %rsp
20413 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
20414 SAVE_ARGS_IRQ
20415+#ifdef CONFIG_PAX_MEMORY_UDEREF
20416+ testb $3, CS(%rdi)
20417+ jnz 1f
20418+ pax_enter_kernel
20419+ jmp 2f
20420+1: pax_enter_kernel_user
20421+2:
20422+#else
20423+ pax_enter_kernel
20424+#endif
20425 call \func
20426 .endm
20427
20428@@ -1027,7 +1337,7 @@ ret_from_intr:
20429
20430 exit_intr:
20431 GET_THREAD_INFO(%rcx)
20432- testl $3,CS-ARGOFFSET(%rsp)
20433+ testb $3,CS-ARGOFFSET(%rsp)
20434 je retint_kernel
20435
20436 /* Interrupt came from user space */
20437@@ -1049,12 +1359,16 @@ retint_swapgs: /* return to user-space */
20438 * The iretq could re-enable interrupts:
20439 */
20440 DISABLE_INTERRUPTS(CLBR_ANY)
20441+ pax_exit_kernel_user
20442+retint_swapgs_pax:
20443 TRACE_IRQS_IRETQ
20444 SWAPGS
20445 jmp restore_args
20446
20447 retint_restore_args: /* return to kernel space */
20448 DISABLE_INTERRUPTS(CLBR_ANY)
20449+ pax_exit_kernel
20450+ pax_force_retaddr (RIP-ARGOFFSET)
20451 /*
20452 * The iretq could re-enable interrupts:
20453 */
20454@@ -1137,7 +1451,7 @@ ENTRY(retint_kernel)
20455 #endif
20456
20457 CFI_ENDPROC
20458-END(common_interrupt)
20459+ENDPROC(common_interrupt)
20460 /*
20461 * End of kprobes section
20462 */
20463@@ -1155,7 +1469,7 @@ ENTRY(\sym)
20464 interrupt \do_sym
20465 jmp ret_from_intr
20466 CFI_ENDPROC
20467-END(\sym)
20468+ENDPROC(\sym)
20469 .endm
20470
20471 #ifdef CONFIG_SMP
20472@@ -1211,12 +1525,22 @@ ENTRY(\sym)
20473 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
20474 call error_entry
20475 DEFAULT_FRAME 0
20476+#ifdef CONFIG_PAX_MEMORY_UDEREF
20477+ testb $3, CS(%rsp)
20478+ jnz 1f
20479+ pax_enter_kernel
20480+ jmp 2f
20481+1: pax_enter_kernel_user
20482+2:
20483+#else
20484+ pax_enter_kernel
20485+#endif
20486 movq %rsp,%rdi /* pt_regs pointer */
20487 xorl %esi,%esi /* no error code */
20488 call \do_sym
20489 jmp error_exit /* %ebx: no swapgs flag */
20490 CFI_ENDPROC
20491-END(\sym)
20492+ENDPROC(\sym)
20493 .endm
20494
20495 .macro paranoidzeroentry sym do_sym
20496@@ -1229,15 +1553,25 @@ ENTRY(\sym)
20497 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
20498 call save_paranoid
20499 TRACE_IRQS_OFF
20500+#ifdef CONFIG_PAX_MEMORY_UDEREF
20501+ testb $3, CS(%rsp)
20502+ jnz 1f
20503+ pax_enter_kernel
20504+ jmp 2f
20505+1: pax_enter_kernel_user
20506+2:
20507+#else
20508+ pax_enter_kernel
20509+#endif
20510 movq %rsp,%rdi /* pt_regs pointer */
20511 xorl %esi,%esi /* no error code */
20512 call \do_sym
20513 jmp paranoid_exit /* %ebx: no swapgs flag */
20514 CFI_ENDPROC
20515-END(\sym)
20516+ENDPROC(\sym)
20517 .endm
20518
20519-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
20520+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
20521 .macro paranoidzeroentry_ist sym do_sym ist
20522 ENTRY(\sym)
20523 INTR_FRAME
20524@@ -1248,14 +1582,30 @@ ENTRY(\sym)
20525 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
20526 call save_paranoid
20527 TRACE_IRQS_OFF_DEBUG
20528+#ifdef CONFIG_PAX_MEMORY_UDEREF
20529+ testb $3, CS(%rsp)
20530+ jnz 1f
20531+ pax_enter_kernel
20532+ jmp 2f
20533+1: pax_enter_kernel_user
20534+2:
20535+#else
20536+ pax_enter_kernel
20537+#endif
20538 movq %rsp,%rdi /* pt_regs pointer */
20539 xorl %esi,%esi /* no error code */
20540+#ifdef CONFIG_SMP
20541+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
20542+ lea init_tss(%r12), %r12
20543+#else
20544+ lea init_tss(%rip), %r12
20545+#endif
20546 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
20547 call \do_sym
20548 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
20549 jmp paranoid_exit /* %ebx: no swapgs flag */
20550 CFI_ENDPROC
20551-END(\sym)
20552+ENDPROC(\sym)
20553 .endm
20554
20555 .macro errorentry sym do_sym
20556@@ -1267,13 +1617,23 @@ ENTRY(\sym)
20557 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
20558 call error_entry
20559 DEFAULT_FRAME 0
20560+#ifdef CONFIG_PAX_MEMORY_UDEREF
20561+ testb $3, CS(%rsp)
20562+ jnz 1f
20563+ pax_enter_kernel
20564+ jmp 2f
20565+1: pax_enter_kernel_user
20566+2:
20567+#else
20568+ pax_enter_kernel
20569+#endif
20570 movq %rsp,%rdi /* pt_regs pointer */
20571 movq ORIG_RAX(%rsp),%rsi /* get error code */
20572 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
20573 call \do_sym
20574 jmp error_exit /* %ebx: no swapgs flag */
20575 CFI_ENDPROC
20576-END(\sym)
20577+ENDPROC(\sym)
20578 .endm
20579
20580 /* error code is on the stack already */
20581@@ -1287,13 +1647,23 @@ ENTRY(\sym)
20582 call save_paranoid
20583 DEFAULT_FRAME 0
20584 TRACE_IRQS_OFF
20585+#ifdef CONFIG_PAX_MEMORY_UDEREF
20586+ testb $3, CS(%rsp)
20587+ jnz 1f
20588+ pax_enter_kernel
20589+ jmp 2f
20590+1: pax_enter_kernel_user
20591+2:
20592+#else
20593+ pax_enter_kernel
20594+#endif
20595 movq %rsp,%rdi /* pt_regs pointer */
20596 movq ORIG_RAX(%rsp),%rsi /* get error code */
20597 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
20598 call \do_sym
20599 jmp paranoid_exit /* %ebx: no swapgs flag */
20600 CFI_ENDPROC
20601-END(\sym)
20602+ENDPROC(\sym)
20603 .endm
20604
20605 zeroentry divide_error do_divide_error
20606@@ -1323,9 +1693,10 @@ gs_change:
20607 2: mfence /* workaround */
20608 SWAPGS
20609 popfq_cfi
20610+ pax_force_retaddr
20611 ret
20612 CFI_ENDPROC
20613-END(native_load_gs_index)
20614+ENDPROC(native_load_gs_index)
20615
20616 _ASM_EXTABLE(gs_change,bad_gs)
20617 .section .fixup,"ax"
20618@@ -1353,9 +1724,10 @@ ENTRY(call_softirq)
20619 CFI_DEF_CFA_REGISTER rsp
20620 CFI_ADJUST_CFA_OFFSET -8
20621 decl PER_CPU_VAR(irq_count)
20622+ pax_force_retaddr
20623 ret
20624 CFI_ENDPROC
20625-END(call_softirq)
20626+ENDPROC(call_softirq)
20627
20628 #ifdef CONFIG_XEN
20629 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
20630@@ -1393,7 +1765,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
20631 decl PER_CPU_VAR(irq_count)
20632 jmp error_exit
20633 CFI_ENDPROC
20634-END(xen_do_hypervisor_callback)
20635+ENDPROC(xen_do_hypervisor_callback)
20636
20637 /*
20638 * Hypervisor uses this for application faults while it executes.
20639@@ -1452,7 +1824,7 @@ ENTRY(xen_failsafe_callback)
20640 SAVE_ALL
20641 jmp error_exit
20642 CFI_ENDPROC
20643-END(xen_failsafe_callback)
20644+ENDPROC(xen_failsafe_callback)
20645
20646 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
20647 xen_hvm_callback_vector xen_evtchn_do_upcall
20648@@ -1501,16 +1873,31 @@ ENTRY(paranoid_exit)
20649 TRACE_IRQS_OFF_DEBUG
20650 testl %ebx,%ebx /* swapgs needed? */
20651 jnz paranoid_restore
20652- testl $3,CS(%rsp)
20653+ testb $3,CS(%rsp)
20654 jnz paranoid_userspace
20655+#ifdef CONFIG_PAX_MEMORY_UDEREF
20656+ pax_exit_kernel
20657+ TRACE_IRQS_IRETQ 0
20658+ SWAPGS_UNSAFE_STACK
20659+ RESTORE_ALL 8
20660+ pax_force_retaddr_bts
20661+ jmp irq_return
20662+#endif
20663 paranoid_swapgs:
20664+#ifdef CONFIG_PAX_MEMORY_UDEREF
20665+ pax_exit_kernel_user
20666+#else
20667+ pax_exit_kernel
20668+#endif
20669 TRACE_IRQS_IRETQ 0
20670 SWAPGS_UNSAFE_STACK
20671 RESTORE_ALL 8
20672 jmp irq_return
20673 paranoid_restore:
20674+ pax_exit_kernel
20675 TRACE_IRQS_IRETQ_DEBUG 0
20676 RESTORE_ALL 8
20677+ pax_force_retaddr_bts
20678 jmp irq_return
20679 paranoid_userspace:
20680 GET_THREAD_INFO(%rcx)
20681@@ -1539,7 +1926,7 @@ paranoid_schedule:
20682 TRACE_IRQS_OFF
20683 jmp paranoid_userspace
20684 CFI_ENDPROC
20685-END(paranoid_exit)
20686+ENDPROC(paranoid_exit)
20687
20688 /*
20689 * Exception entry point. This expects an error code/orig_rax on the stack.
20690@@ -1566,12 +1953,13 @@ ENTRY(error_entry)
20691 movq_cfi r14, R14+8
20692 movq_cfi r15, R15+8
20693 xorl %ebx,%ebx
20694- testl $3,CS+8(%rsp)
20695+ testb $3,CS+8(%rsp)
20696 je error_kernelspace
20697 error_swapgs:
20698 SWAPGS
20699 error_sti:
20700 TRACE_IRQS_OFF
20701+ pax_force_retaddr_bts
20702 ret
20703
20704 /*
20705@@ -1598,7 +1986,7 @@ bstep_iret:
20706 movq %rcx,RIP+8(%rsp)
20707 jmp error_swapgs
20708 CFI_ENDPROC
20709-END(error_entry)
20710+ENDPROC(error_entry)
20711
20712
20713 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
20714@@ -1618,7 +2006,7 @@ ENTRY(error_exit)
20715 jnz retint_careful
20716 jmp retint_swapgs
20717 CFI_ENDPROC
20718-END(error_exit)
20719+ENDPROC(error_exit)
20720
20721 /*
20722 * Test if a given stack is an NMI stack or not.
20723@@ -1676,9 +2064,11 @@ ENTRY(nmi)
20724 * If %cs was not the kernel segment, then the NMI triggered in user
20725 * space, which means it is definitely not nested.
20726 */
20727+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
20728+ je 1f
20729 cmpl $__KERNEL_CS, 16(%rsp)
20730 jne first_nmi
20731-
20732+1:
20733 /*
20734 * Check the special variable on the stack to see if NMIs are
20735 * executing.
20736@@ -1712,14 +2102,13 @@ nested_nmi:
20737
20738 1:
20739 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
20740- leaq -1*8(%rsp), %rdx
20741- movq %rdx, %rsp
20742+ subq $8, %rsp
20743 CFI_ADJUST_CFA_OFFSET 1*8
20744 leaq -10*8(%rsp), %rdx
20745 pushq_cfi $__KERNEL_DS
20746 pushq_cfi %rdx
20747 pushfq_cfi
20748- pushq_cfi $__KERNEL_CS
20749+ pushq_cfi 6*8(%rsp)
20750 pushq_cfi $repeat_nmi
20751
20752 /* Put stack back */
20753@@ -1731,6 +2120,7 @@ nested_nmi_out:
20754 CFI_RESTORE rdx
20755
20756 /* No need to check faults here */
20757+ pax_force_retaddr_bts
20758 INTERRUPT_RETURN
20759
20760 CFI_RESTORE_STATE
20761@@ -1847,6 +2237,17 @@ end_repeat_nmi:
20762 */
20763 movq %cr2, %r12
20764
20765+#ifdef CONFIG_PAX_MEMORY_UDEREF
20766+ testb $3, CS(%rsp)
20767+ jnz 1f
20768+ pax_enter_kernel
20769+ jmp 2f
20770+1: pax_enter_kernel_user
20771+2:
20772+#else
20773+ pax_enter_kernel
20774+#endif
20775+
20776 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
20777 movq %rsp,%rdi
20778 movq $-1,%rsi
20779@@ -1862,23 +2263,34 @@ end_repeat_nmi:
20780 testl %ebx,%ebx /* swapgs needed? */
20781 jnz nmi_restore
20782 nmi_swapgs:
20783+#ifdef CONFIG_PAX_MEMORY_UDEREF
20784+ pax_exit_kernel_user
20785+#else
20786+ pax_exit_kernel
20787+#endif
20788 SWAPGS_UNSAFE_STACK
20789+ RESTORE_ALL 6*8
20790+ /* Clear the NMI executing stack variable */
20791+ movq $0, 5*8(%rsp)
20792+ jmp irq_return
20793 nmi_restore:
20794+ pax_exit_kernel
20795 /* Pop the extra iret frame at once */
20796 RESTORE_ALL 6*8
20797+ pax_force_retaddr_bts
20798
20799 /* Clear the NMI executing stack variable */
20800 movq $0, 5*8(%rsp)
20801 jmp irq_return
20802 CFI_ENDPROC
20803-END(nmi)
20804+ENDPROC(nmi)
20805
20806 ENTRY(ignore_sysret)
20807 CFI_STARTPROC
20808 mov $-ENOSYS,%eax
20809 sysret
20810 CFI_ENDPROC
20811-END(ignore_sysret)
20812+ENDPROC(ignore_sysret)
20813
20814 /*
20815 * End of kprobes section
20816diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
20817index 1d41402..af9a46a 100644
20818--- a/arch/x86/kernel/ftrace.c
20819+++ b/arch/x86/kernel/ftrace.c
20820@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
20821 {
20822 unsigned char replaced[MCOUNT_INSN_SIZE];
20823
20824+ ip = ktla_ktva(ip);
20825+
20826 /*
20827 * Note: Due to modules and __init, code can
20828 * disappear and change, we need to protect against faulting
20829@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
20830 unsigned char old[MCOUNT_INSN_SIZE], *new;
20831 int ret;
20832
20833- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
20834+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
20835 new = ftrace_call_replace(ip, (unsigned long)func);
20836
20837 /* See comment above by declaration of modifying_ftrace_code */
20838@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
20839 /* Also update the regs callback function */
20840 if (!ret) {
20841 ip = (unsigned long)(&ftrace_regs_call);
20842- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
20843+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
20844 new = ftrace_call_replace(ip, (unsigned long)func);
20845 ret = ftrace_modify_code(ip, old, new);
20846 }
20847@@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
20848 * kernel identity mapping to modify code.
20849 */
20850 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
20851- ip = (unsigned long)__va(__pa(ip));
20852+ ip = (unsigned long)__va(__pa(ktla_ktva(ip)));
20853
20854 return probe_kernel_write((void *)ip, val, size);
20855 }
20856@@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
20857 unsigned char replaced[MCOUNT_INSN_SIZE];
20858 unsigned char brk = BREAKPOINT_INSTRUCTION;
20859
20860- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
20861+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
20862 return -EFAULT;
20863
20864 /* Make sure it is what we expect it to be */
20865@@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
20866 return ret;
20867
20868 fail_update:
20869- probe_kernel_write((void *)ip, &old_code[0], 1);
20870+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
20871 goto out;
20872 }
20873
20874@@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
20875 {
20876 unsigned char code[MCOUNT_INSN_SIZE];
20877
20878+ ip = ktla_ktva(ip);
20879+
20880 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
20881 return -EFAULT;
20882
20883diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
20884index c18f59d..9c0c9f6 100644
20885--- a/arch/x86/kernel/head32.c
20886+++ b/arch/x86/kernel/head32.c
20887@@ -18,6 +18,7 @@
20888 #include <asm/io_apic.h>
20889 #include <asm/bios_ebda.h>
20890 #include <asm/tlbflush.h>
20891+#include <asm/boot.h>
20892
20893 static void __init i386_default_early_setup(void)
20894 {
20895@@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
20896
20897 void __init i386_start_kernel(void)
20898 {
20899- memblock_reserve(__pa_symbol(&_text),
20900- __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
20901+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
20902
20903 #ifdef CONFIG_BLK_DEV_INITRD
20904 /* Reserve INITRD */
20905diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
20906index c8932c7..d56b622 100644
20907--- a/arch/x86/kernel/head_32.S
20908+++ b/arch/x86/kernel/head_32.S
20909@@ -26,6 +26,12 @@
20910 /* Physical address */
20911 #define pa(X) ((X) - __PAGE_OFFSET)
20912
20913+#ifdef CONFIG_PAX_KERNEXEC
20914+#define ta(X) (X)
20915+#else
20916+#define ta(X) ((X) - __PAGE_OFFSET)
20917+#endif
20918+
20919 /*
20920 * References to members of the new_cpu_data structure.
20921 */
20922@@ -55,11 +61,7 @@
20923 * and small than max_low_pfn, otherwise will waste some page table entries
20924 */
20925
20926-#if PTRS_PER_PMD > 1
20927-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
20928-#else
20929-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
20930-#endif
20931+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
20932
20933 /* Number of possible pages in the lowmem region */
20934 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
20935@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
20936 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
20937
20938 /*
20939+ * Real beginning of normal "text" segment
20940+ */
20941+ENTRY(stext)
20942+ENTRY(_stext)
20943+
20944+/*
20945 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
20946 * %esi points to the real-mode code as a 32-bit pointer.
20947 * CS and DS must be 4 GB flat segments, but we don't depend on
20948@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
20949 * can.
20950 */
20951 __HEAD
20952+
20953+#ifdef CONFIG_PAX_KERNEXEC
20954+ jmp startup_32
20955+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
20956+.fill PAGE_SIZE-5,1,0xcc
20957+#endif
20958+
20959 ENTRY(startup_32)
20960 movl pa(stack_start),%ecx
20961
20962@@ -106,6 +121,59 @@ ENTRY(startup_32)
20963 2:
20964 leal -__PAGE_OFFSET(%ecx),%esp
20965
20966+#ifdef CONFIG_SMP
20967+ movl $pa(cpu_gdt_table),%edi
20968+ movl $__per_cpu_load,%eax
20969+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
20970+ rorl $16,%eax
20971+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
20972+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
20973+ movl $__per_cpu_end - 1,%eax
20974+ subl $__per_cpu_start,%eax
20975+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
20976+#endif
20977+
20978+#ifdef CONFIG_PAX_MEMORY_UDEREF
20979+ movl $NR_CPUS,%ecx
20980+ movl $pa(cpu_gdt_table),%edi
20981+1:
20982+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
20983+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
20984+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
20985+ addl $PAGE_SIZE_asm,%edi
20986+ loop 1b
20987+#endif
20988+
20989+#ifdef CONFIG_PAX_KERNEXEC
20990+ movl $pa(boot_gdt),%edi
20991+ movl $__LOAD_PHYSICAL_ADDR,%eax
20992+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
20993+ rorl $16,%eax
20994+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
20995+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
20996+ rorl $16,%eax
20997+
20998+ ljmp $(__BOOT_CS),$1f
20999+1:
21000+
21001+ movl $NR_CPUS,%ecx
21002+ movl $pa(cpu_gdt_table),%edi
21003+ addl $__PAGE_OFFSET,%eax
21004+1:
21005+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
21006+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
21007+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
21008+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
21009+ rorl $16,%eax
21010+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
21011+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
21012+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
21013+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
21014+ rorl $16,%eax
21015+ addl $PAGE_SIZE_asm,%edi
21016+ loop 1b
21017+#endif
21018+
21019 /*
21020 * Clear BSS first so that there are no surprises...
21021 */
21022@@ -196,8 +264,11 @@ ENTRY(startup_32)
21023 movl %eax, pa(max_pfn_mapped)
21024
21025 /* Do early initialization of the fixmap area */
21026- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
21027- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
21028+#ifdef CONFIG_COMPAT_VDSO
21029+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
21030+#else
21031+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
21032+#endif
21033 #else /* Not PAE */
21034
21035 page_pde_offset = (__PAGE_OFFSET >> 20);
21036@@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
21037 movl %eax, pa(max_pfn_mapped)
21038
21039 /* Do early initialization of the fixmap area */
21040- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
21041- movl %eax,pa(initial_page_table+0xffc)
21042+#ifdef CONFIG_COMPAT_VDSO
21043+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
21044+#else
21045+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
21046+#endif
21047 #endif
21048
21049 #ifdef CONFIG_PARAVIRT
21050@@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
21051 cmpl $num_subarch_entries, %eax
21052 jae bad_subarch
21053
21054- movl pa(subarch_entries)(,%eax,4), %eax
21055- subl $__PAGE_OFFSET, %eax
21056- jmp *%eax
21057+ jmp *pa(subarch_entries)(,%eax,4)
21058
21059 bad_subarch:
21060 WEAK(lguest_entry)
21061@@ -256,10 +328,10 @@ WEAK(xen_entry)
21062 __INITDATA
21063
21064 subarch_entries:
21065- .long default_entry /* normal x86/PC */
21066- .long lguest_entry /* lguest hypervisor */
21067- .long xen_entry /* Xen hypervisor */
21068- .long default_entry /* Moorestown MID */
21069+ .long ta(default_entry) /* normal x86/PC */
21070+ .long ta(lguest_entry) /* lguest hypervisor */
21071+ .long ta(xen_entry) /* Xen hypervisor */
21072+ .long ta(default_entry) /* Moorestown MID */
21073 num_subarch_entries = (. - subarch_entries) / 4
21074 .previous
21075 #else
21076@@ -335,6 +407,7 @@ default_entry:
21077 movl pa(mmu_cr4_features),%eax
21078 movl %eax,%cr4
21079
21080+#ifdef CONFIG_X86_PAE
21081 testb $X86_CR4_PAE, %al # check if PAE is enabled
21082 jz 6f
21083
21084@@ -363,6 +436,9 @@ default_entry:
21085 /* Make changes effective */
21086 wrmsr
21087
21088+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
21089+#endif
21090+
21091 6:
21092
21093 /*
21094@@ -460,14 +536,20 @@ is386: movl $2,%ecx # set MP
21095 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
21096 movl %eax,%ss # after changing gdt.
21097
21098- movl $(__USER_DS),%eax # DS/ES contains default USER segment
21099+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
21100 movl %eax,%ds
21101 movl %eax,%es
21102
21103 movl $(__KERNEL_PERCPU), %eax
21104 movl %eax,%fs # set this cpu's percpu
21105
21106+#ifdef CONFIG_CC_STACKPROTECTOR
21107 movl $(__KERNEL_STACK_CANARY),%eax
21108+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
21109+ movl $(__USER_DS),%eax
21110+#else
21111+ xorl %eax,%eax
21112+#endif
21113 movl %eax,%gs
21114
21115 xorl %eax,%eax # Clear LDT
21116@@ -544,8 +626,11 @@ setup_once:
21117 * relocation. Manually set base address in stack canary
21118 * segment descriptor.
21119 */
21120- movl $gdt_page,%eax
21121+ movl $cpu_gdt_table,%eax
21122 movl $stack_canary,%ecx
21123+#ifdef CONFIG_SMP
21124+ addl $__per_cpu_load,%ecx
21125+#endif
21126 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
21127 shrl $16, %ecx
21128 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
21129@@ -576,7 +661,7 @@ ENDPROC(early_idt_handlers)
21130 /* This is global to keep gas from relaxing the jumps */
21131 ENTRY(early_idt_handler)
21132 cld
21133- cmpl $2,%ss:early_recursion_flag
21134+ cmpl $1,%ss:early_recursion_flag
21135 je hlt_loop
21136 incl %ss:early_recursion_flag
21137
21138@@ -614,8 +699,8 @@ ENTRY(early_idt_handler)
21139 pushl (20+6*4)(%esp) /* trapno */
21140 pushl $fault_msg
21141 call printk
21142-#endif
21143 call dump_stack
21144+#endif
21145 hlt_loop:
21146 hlt
21147 jmp hlt_loop
21148@@ -634,8 +719,11 @@ ENDPROC(early_idt_handler)
21149 /* This is the default interrupt "handler" :-) */
21150 ALIGN
21151 ignore_int:
21152- cld
21153 #ifdef CONFIG_PRINTK
21154+ cmpl $2,%ss:early_recursion_flag
21155+ je hlt_loop
21156+ incl %ss:early_recursion_flag
21157+ cld
21158 pushl %eax
21159 pushl %ecx
21160 pushl %edx
21161@@ -644,9 +732,6 @@ ignore_int:
21162 movl $(__KERNEL_DS),%eax
21163 movl %eax,%ds
21164 movl %eax,%es
21165- cmpl $2,early_recursion_flag
21166- je hlt_loop
21167- incl early_recursion_flag
21168 pushl 16(%esp)
21169 pushl 24(%esp)
21170 pushl 32(%esp)
21171@@ -680,29 +765,43 @@ ENTRY(setup_once_ref)
21172 /*
21173 * BSS section
21174 */
21175-__PAGE_ALIGNED_BSS
21176- .align PAGE_SIZE
21177 #ifdef CONFIG_X86_PAE
21178+.section .initial_pg_pmd,"a",@progbits
21179 initial_pg_pmd:
21180 .fill 1024*KPMDS,4,0
21181 #else
21182+.section .initial_page_table,"a",@progbits
21183 ENTRY(initial_page_table)
21184 .fill 1024,4,0
21185 #endif
21186+.section .initial_pg_fixmap,"a",@progbits
21187 initial_pg_fixmap:
21188 .fill 1024,4,0
21189+.section .empty_zero_page,"a",@progbits
21190 ENTRY(empty_zero_page)
21191 .fill 4096,1,0
21192+.section .swapper_pg_dir,"a",@progbits
21193 ENTRY(swapper_pg_dir)
21194+#ifdef CONFIG_X86_PAE
21195+ .fill 4,8,0
21196+#else
21197 .fill 1024,4,0
21198+#endif
21199+
21200+/*
21201+ * The IDT has to be page-aligned to simplify the Pentium
21202+ * F0 0F bug workaround.. We have a special link segment
21203+ * for this.
21204+ */
21205+.section .idt,"a",@progbits
21206+ENTRY(idt_table)
21207+ .fill 256,8,0
21208
21209 /*
21210 * This starts the data section.
21211 */
21212 #ifdef CONFIG_X86_PAE
21213-__PAGE_ALIGNED_DATA
21214- /* Page-aligned for the benefit of paravirt? */
21215- .align PAGE_SIZE
21216+.section .initial_page_table,"a",@progbits
21217 ENTRY(initial_page_table)
21218 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
21219 # if KPMDS == 3
21220@@ -721,12 +820,20 @@ ENTRY(initial_page_table)
21221 # error "Kernel PMDs should be 1, 2 or 3"
21222 # endif
21223 .align PAGE_SIZE /* needs to be page-sized too */
21224+
21225+#ifdef CONFIG_PAX_PER_CPU_PGD
21226+ENTRY(cpu_pgd)
21227+ .rept NR_CPUS
21228+ .fill 4,8,0
21229+ .endr
21230+#endif
21231+
21232 #endif
21233
21234 .data
21235 .balign 4
21236 ENTRY(stack_start)
21237- .long init_thread_union+THREAD_SIZE
21238+ .long init_thread_union+THREAD_SIZE-8
21239
21240 __INITRODATA
21241 int_msg:
21242@@ -754,7 +861,7 @@ fault_msg:
21243 * segment size, and 32-bit linear address value:
21244 */
21245
21246- .data
21247+.section .rodata,"a",@progbits
21248 .globl boot_gdt_descr
21249 .globl idt_descr
21250
21251@@ -763,7 +870,7 @@ fault_msg:
21252 .word 0 # 32 bit align gdt_desc.address
21253 boot_gdt_descr:
21254 .word __BOOT_DS+7
21255- .long boot_gdt - __PAGE_OFFSET
21256+ .long pa(boot_gdt)
21257
21258 .word 0 # 32-bit align idt_desc.address
21259 idt_descr:
21260@@ -774,7 +881,7 @@ idt_descr:
21261 .word 0 # 32 bit align gdt_desc.address
21262 ENTRY(early_gdt_descr)
21263 .word GDT_ENTRIES*8-1
21264- .long gdt_page /* Overwritten for secondary CPUs */
21265+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
21266
21267 /*
21268 * The boot_gdt must mirror the equivalent in setup.S and is
21269@@ -783,5 +890,65 @@ ENTRY(early_gdt_descr)
21270 .align L1_CACHE_BYTES
21271 ENTRY(boot_gdt)
21272 .fill GDT_ENTRY_BOOT_CS,8,0
21273- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
21274- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
21275+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
21276+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
21277+
21278+ .align PAGE_SIZE_asm
21279+ENTRY(cpu_gdt_table)
21280+ .rept NR_CPUS
21281+ .quad 0x0000000000000000 /* NULL descriptor */
21282+ .quad 0x0000000000000000 /* 0x0b reserved */
21283+ .quad 0x0000000000000000 /* 0x13 reserved */
21284+ .quad 0x0000000000000000 /* 0x1b reserved */
21285+
21286+#ifdef CONFIG_PAX_KERNEXEC
21287+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
21288+#else
21289+ .quad 0x0000000000000000 /* 0x20 unused */
21290+#endif
21291+
21292+ .quad 0x0000000000000000 /* 0x28 unused */
21293+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
21294+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
21295+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
21296+ .quad 0x0000000000000000 /* 0x4b reserved */
21297+ .quad 0x0000000000000000 /* 0x53 reserved */
21298+ .quad 0x0000000000000000 /* 0x5b reserved */
21299+
21300+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
21301+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
21302+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
21303+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
21304+
21305+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
21306+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
21307+
21308+ /*
21309+ * Segments used for calling PnP BIOS have byte granularity.
21310+ * The code segments and data segments have fixed 64k limits,
21311+ * the transfer segment sizes are set at run time.
21312+ */
21313+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
21314+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
21315+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
21316+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
21317+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
21318+
21319+ /*
21320+ * The APM segments have byte granularity and their bases
21321+ * are set at run time. All have 64k limits.
21322+ */
21323+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
21324+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
21325+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
21326+
21327+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
21328+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
21329+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
21330+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
21331+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
21332+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
21333+
21334+ /* Be sure this is zeroed to avoid false validations in Xen */
21335+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
21336+ .endr
21337diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
21338index 980053c..74d3b44 100644
21339--- a/arch/x86/kernel/head_64.S
21340+++ b/arch/x86/kernel/head_64.S
21341@@ -20,6 +20,8 @@
21342 #include <asm/processor-flags.h>
21343 #include <asm/percpu.h>
21344 #include <asm/nops.h>
21345+#include <asm/cpufeature.h>
21346+#include <asm/alternative-asm.h>
21347
21348 #ifdef CONFIG_PARAVIRT
21349 #include <asm/asm-offsets.h>
21350@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
21351 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
21352 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
21353 L3_START_KERNEL = pud_index(__START_KERNEL_map)
21354+L4_VMALLOC_START = pgd_index(VMALLOC_START)
21355+L3_VMALLOC_START = pud_index(VMALLOC_START)
21356+L4_VMALLOC_END = pgd_index(VMALLOC_END)
21357+L3_VMALLOC_END = pud_index(VMALLOC_END)
21358+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
21359+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
21360
21361 .text
21362 __HEAD
21363@@ -88,35 +96,23 @@ startup_64:
21364 */
21365 addq %rbp, init_level4_pgt + 0(%rip)
21366 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
21367+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
21368+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
21369+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
21370 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
21371
21372 addq %rbp, level3_ident_pgt + 0(%rip)
21373+#ifndef CONFIG_XEN
21374+ addq %rbp, level3_ident_pgt + 8(%rip)
21375+#endif
21376
21377- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
21378- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
21379+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
21380+
21381+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
21382+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
21383
21384 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
21385-
21386- /* Add an Identity mapping if I am above 1G */
21387- leaq _text(%rip), %rdi
21388- andq $PMD_PAGE_MASK, %rdi
21389-
21390- movq %rdi, %rax
21391- shrq $PUD_SHIFT, %rax
21392- andq $(PTRS_PER_PUD - 1), %rax
21393- jz ident_complete
21394-
21395- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
21396- leaq level3_ident_pgt(%rip), %rbx
21397- movq %rdx, 0(%rbx, %rax, 8)
21398-
21399- movq %rdi, %rax
21400- shrq $PMD_SHIFT, %rax
21401- andq $(PTRS_PER_PMD - 1), %rax
21402- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
21403- leaq level2_spare_pgt(%rip), %rbx
21404- movq %rdx, 0(%rbx, %rax, 8)
21405-ident_complete:
21406+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
21407
21408 /*
21409 * Fixup the kernel text+data virtual addresses. Note that
21410@@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
21411 * after the boot processor executes this code.
21412 */
21413
21414- /* Enable PAE mode and PGE */
21415- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
21416+ /* Enable PAE mode and PSE/PGE */
21417+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
21418 movq %rax, %cr4
21419
21420 /* Setup early boot stage 4 level pagetables. */
21421@@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
21422 movl $MSR_EFER, %ecx
21423 rdmsr
21424 btsl $_EFER_SCE, %eax /* Enable System Call */
21425- btl $20,%edi /* No Execute supported? */
21426+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
21427 jnc 1f
21428 btsl $_EFER_NX, %eax
21429+ leaq init_level4_pgt(%rip), %rdi
21430+#ifndef CONFIG_EFI
21431+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
21432+#endif
21433+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
21434+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
21435+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
21436+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
21437 1: wrmsr /* Make changes effective */
21438
21439 /* Setup cr0 */
21440@@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
21441 * jump. In addition we need to ensure %cs is set so we make this
21442 * a far return.
21443 */
21444+ pax_set_fptr_mask
21445 movq initial_code(%rip),%rax
21446 pushq $0 # fake return address to stop unwinder
21447 pushq $__KERNEL_CS # set correct cs
21448@@ -284,7 +289,7 @@ ENDPROC(start_cpu0)
21449 bad_address:
21450 jmp bad_address
21451
21452- .section ".init.text","ax"
21453+ __INIT
21454 .globl early_idt_handlers
21455 early_idt_handlers:
21456 # 104(%rsp) %rflags
21457@@ -343,7 +348,7 @@ ENTRY(early_idt_handler)
21458 call dump_stack
21459 #ifdef CONFIG_KALLSYMS
21460 leaq early_idt_ripmsg(%rip),%rdi
21461- movq 40(%rsp),%rsi # %rip again
21462+ movq 88(%rsp),%rsi # %rip again
21463 call __print_symbol
21464 #endif
21465 #endif /* EARLY_PRINTK */
21466@@ -363,11 +368,15 @@ ENTRY(early_idt_handler)
21467 addq $16,%rsp # drop vector number and error code
21468 decl early_recursion_flag(%rip)
21469 INTERRUPT_RETURN
21470+ .previous
21471
21472+ __INITDATA
21473 .balign 4
21474 early_recursion_flag:
21475 .long 0
21476+ .previous
21477
21478+ .section .rodata,"a",@progbits
21479 #ifdef CONFIG_EARLY_PRINTK
21480 early_idt_msg:
21481 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
21482@@ -376,6 +385,7 @@ early_idt_ripmsg:
21483 #endif /* CONFIG_EARLY_PRINTK */
21484 .previous
21485
21486+ .section .rodata,"a",@progbits
21487 #define NEXT_PAGE(name) \
21488 .balign PAGE_SIZE; \
21489 ENTRY(name)
21490@@ -388,7 +398,6 @@ ENTRY(name)
21491 i = i + 1 ; \
21492 .endr
21493
21494- .data
21495 /*
21496 * This default setting generates an ident mapping at address 0x100000
21497 * and a mapping for the kernel that precisely maps virtual address
21498@@ -399,13 +408,41 @@ NEXT_PAGE(init_level4_pgt)
21499 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
21500 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
21501 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
21502+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
21503+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
21504+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
21505+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
21506+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
21507+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
21508 .org init_level4_pgt + L4_START_KERNEL*8, 0
21509 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
21510 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
21511
21512+#ifdef CONFIG_PAX_PER_CPU_PGD
21513+NEXT_PAGE(cpu_pgd)
21514+ .rept NR_CPUS
21515+ .fill 512,8,0
21516+ .endr
21517+#endif
21518+
21519 NEXT_PAGE(level3_ident_pgt)
21520 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
21521+#ifdef CONFIG_XEN
21522 .fill 511,8,0
21523+#else
21524+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
21525+ .fill 510,8,0
21526+#endif
21527+
21528+NEXT_PAGE(level3_vmalloc_start_pgt)
21529+ .fill 512,8,0
21530+
21531+NEXT_PAGE(level3_vmalloc_end_pgt)
21532+ .fill 512,8,0
21533+
21534+NEXT_PAGE(level3_vmemmap_pgt)
21535+ .fill L3_VMEMMAP_START,8,0
21536+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
21537
21538 NEXT_PAGE(level3_kernel_pgt)
21539 .fill L3_START_KERNEL,8,0
21540@@ -413,20 +450,23 @@ NEXT_PAGE(level3_kernel_pgt)
21541 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
21542 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
21543
21544+NEXT_PAGE(level2_vmemmap_pgt)
21545+ .fill 512,8,0
21546+
21547 NEXT_PAGE(level2_fixmap_pgt)
21548- .fill 506,8,0
21549- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
21550- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
21551- .fill 5,8,0
21552+ .fill 507,8,0
21553+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
21554+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
21555+ .fill 4,8,0
21556
21557-NEXT_PAGE(level1_fixmap_pgt)
21558+NEXT_PAGE(level1_vsyscall_pgt)
21559 .fill 512,8,0
21560
21561-NEXT_PAGE(level2_ident_pgt)
21562- /* Since I easily can, map the first 1G.
21563+ /* Since I easily can, map the first 2G.
21564 * Don't set NX because code runs from these pages.
21565 */
21566- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
21567+NEXT_PAGE(level2_ident_pgt)
21568+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
21569
21570 NEXT_PAGE(level2_kernel_pgt)
21571 /*
21572@@ -439,37 +479,59 @@ NEXT_PAGE(level2_kernel_pgt)
21573 * If you want to increase this then increase MODULES_VADDR
21574 * too.)
21575 */
21576- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
21577- KERNEL_IMAGE_SIZE/PMD_SIZE)
21578-
21579-NEXT_PAGE(level2_spare_pgt)
21580- .fill 512, 8, 0
21581+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
21582
21583 #undef PMDS
21584 #undef NEXT_PAGE
21585
21586- .data
21587+ .align PAGE_SIZE
21588+ENTRY(cpu_gdt_table)
21589+ .rept NR_CPUS
21590+ .quad 0x0000000000000000 /* NULL descriptor */
21591+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
21592+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
21593+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
21594+ .quad 0x00cffb000000ffff /* __USER32_CS */
21595+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
21596+ .quad 0x00affb000000ffff /* __USER_CS */
21597+
21598+#ifdef CONFIG_PAX_KERNEXEC
21599+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
21600+#else
21601+ .quad 0x0 /* unused */
21602+#endif
21603+
21604+ .quad 0,0 /* TSS */
21605+ .quad 0,0 /* LDT */
21606+ .quad 0,0,0 /* three TLS descriptors */
21607+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
21608+ /* asm/segment.h:GDT_ENTRIES must match this */
21609+
21610+ /* zero the remaining page */
21611+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
21612+ .endr
21613+
21614 .align 16
21615 .globl early_gdt_descr
21616 early_gdt_descr:
21617 .word GDT_ENTRIES*8-1
21618 early_gdt_descr_base:
21619- .quad INIT_PER_CPU_VAR(gdt_page)
21620+ .quad cpu_gdt_table
21621
21622 ENTRY(phys_base)
21623 /* This must match the first entry in level2_kernel_pgt */
21624 .quad 0x0000000000000000
21625
21626 #include "../../x86/xen/xen-head.S"
21627-
21628- .section .bss, "aw", @nobits
21629+
21630+ .section .rodata,"a",@progbits
21631 .align L1_CACHE_BYTES
21632 ENTRY(idt_table)
21633- .skip IDT_ENTRIES * 16
21634+ .fill 512,8,0
21635
21636 .align L1_CACHE_BYTES
21637 ENTRY(nmi_idt_table)
21638- .skip IDT_ENTRIES * 16
21639+ .fill 512,8,0
21640
21641 __PAGE_ALIGNED_BSS
21642 .align PAGE_SIZE
21643diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
21644index 9c3bd4a..e1d9b35 100644
21645--- a/arch/x86/kernel/i386_ksyms_32.c
21646+++ b/arch/x86/kernel/i386_ksyms_32.c
21647@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
21648 EXPORT_SYMBOL(cmpxchg8b_emu);
21649 #endif
21650
21651+EXPORT_SYMBOL_GPL(cpu_gdt_table);
21652+
21653 /* Networking helper routines. */
21654 EXPORT_SYMBOL(csum_partial_copy_generic);
21655+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
21656+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
21657
21658 EXPORT_SYMBOL(__get_user_1);
21659 EXPORT_SYMBOL(__get_user_2);
21660@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
21661
21662 EXPORT_SYMBOL(csum_partial);
21663 EXPORT_SYMBOL(empty_zero_page);
21664+
21665+#ifdef CONFIG_PAX_KERNEXEC
21666+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
21667+#endif
21668diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
21669index 245a71d..89d9ce4 100644
21670--- a/arch/x86/kernel/i387.c
21671+++ b/arch/x86/kernel/i387.c
21672@@ -55,7 +55,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
21673 static inline bool interrupted_user_mode(void)
21674 {
21675 struct pt_regs *regs = get_irq_regs();
21676- return regs && user_mode_vm(regs);
21677+ return regs && user_mode(regs);
21678 }
21679
21680 /*
21681diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
21682index 9a5c460..b332a4b 100644
21683--- a/arch/x86/kernel/i8259.c
21684+++ b/arch/x86/kernel/i8259.c
21685@@ -209,7 +209,7 @@ spurious_8259A_irq:
21686 "spurious 8259A interrupt: IRQ%d.\n", irq);
21687 spurious_irq_mask |= irqmask;
21688 }
21689- atomic_inc(&irq_err_count);
21690+ atomic_inc_unchecked(&irq_err_count);
21691 /*
21692 * Theoretically we do not have to handle this IRQ,
21693 * but in Linux this does not cause problems and is
21694@@ -333,14 +333,16 @@ static void init_8259A(int auto_eoi)
21695 /* (slave's support for AEOI in flat mode is to be investigated) */
21696 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
21697
21698+ pax_open_kernel();
21699 if (auto_eoi)
21700 /*
21701 * In AEOI mode we just have to mask the interrupt
21702 * when acking.
21703 */
21704- i8259A_chip.irq_mask_ack = disable_8259A_irq;
21705+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
21706 else
21707- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
21708+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
21709+ pax_close_kernel();
21710
21711 udelay(100); /* wait for 8259A to initialize */
21712
21713diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
21714index a979b5b..1d6db75 100644
21715--- a/arch/x86/kernel/io_delay.c
21716+++ b/arch/x86/kernel/io_delay.c
21717@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
21718 * Quirk table for systems that misbehave (lock up, etc.) if port
21719 * 0x80 is used:
21720 */
21721-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
21722+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
21723 {
21724 .callback = dmi_io_delay_0xed_port,
21725 .ident = "Compaq Presario V6000",
21726diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
21727index 8c96897..be66bfa 100644
21728--- a/arch/x86/kernel/ioport.c
21729+++ b/arch/x86/kernel/ioport.c
21730@@ -6,6 +6,7 @@
21731 #include <linux/sched.h>
21732 #include <linux/kernel.h>
21733 #include <linux/capability.h>
21734+#include <linux/security.h>
21735 #include <linux/errno.h>
21736 #include <linux/types.h>
21737 #include <linux/ioport.h>
21738@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
21739
21740 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
21741 return -EINVAL;
21742+#ifdef CONFIG_GRKERNSEC_IO
21743+ if (turn_on && grsec_disable_privio) {
21744+ gr_handle_ioperm();
21745+ return -EPERM;
21746+ }
21747+#endif
21748 if (turn_on && !capable(CAP_SYS_RAWIO))
21749 return -EPERM;
21750
21751@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
21752 * because the ->io_bitmap_max value must match the bitmap
21753 * contents:
21754 */
21755- tss = &per_cpu(init_tss, get_cpu());
21756+ tss = init_tss + get_cpu();
21757
21758 if (turn_on)
21759 bitmap_clear(t->io_bitmap_ptr, from, num);
21760@@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
21761 return -EINVAL;
21762 /* Trying to gain more privileges? */
21763 if (level > old) {
21764+#ifdef CONFIG_GRKERNSEC_IO
21765+ if (grsec_disable_privio) {
21766+ gr_handle_iopl();
21767+ return -EPERM;
21768+ }
21769+#endif
21770 if (!capable(CAP_SYS_RAWIO))
21771 return -EPERM;
21772 }
21773diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
21774index e4595f1..ee3bfb8 100644
21775--- a/arch/x86/kernel/irq.c
21776+++ b/arch/x86/kernel/irq.c
21777@@ -18,7 +18,7 @@
21778 #include <asm/mce.h>
21779 #include <asm/hw_irq.h>
21780
21781-atomic_t irq_err_count;
21782+atomic_unchecked_t irq_err_count;
21783
21784 /* Function pointer for generic interrupt vector handling */
21785 void (*x86_platform_ipi_callback)(void) = NULL;
21786@@ -122,9 +122,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
21787 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
21788 seq_printf(p, " Machine check polls\n");
21789 #endif
21790- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
21791+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
21792 #if defined(CONFIG_X86_IO_APIC)
21793- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
21794+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
21795 #endif
21796 return 0;
21797 }
21798@@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
21799
21800 u64 arch_irq_stat(void)
21801 {
21802- u64 sum = atomic_read(&irq_err_count);
21803+ u64 sum = atomic_read_unchecked(&irq_err_count);
21804
21805 #ifdef CONFIG_X86_IO_APIC
21806- sum += atomic_read(&irq_mis_count);
21807+ sum += atomic_read_unchecked(&irq_mis_count);
21808 #endif
21809 return sum;
21810 }
21811diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
21812index 344faf8..355f60d 100644
21813--- a/arch/x86/kernel/irq_32.c
21814+++ b/arch/x86/kernel/irq_32.c
21815@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
21816 __asm__ __volatile__("andl %%esp,%0" :
21817 "=r" (sp) : "0" (THREAD_SIZE - 1));
21818
21819- return sp < (sizeof(struct thread_info) + STACK_WARN);
21820+ return sp < STACK_WARN;
21821 }
21822
21823 static void print_stack_overflow(void)
21824@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
21825 * per-CPU IRQ handling contexts (thread information and stack)
21826 */
21827 union irq_ctx {
21828- struct thread_info tinfo;
21829- u32 stack[THREAD_SIZE/sizeof(u32)];
21830+ unsigned long previous_esp;
21831+ u32 stack[THREAD_SIZE/sizeof(u32)];
21832 } __attribute__((aligned(THREAD_SIZE)));
21833
21834 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
21835@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
21836 static inline int
21837 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21838 {
21839- union irq_ctx *curctx, *irqctx;
21840+ union irq_ctx *irqctx;
21841 u32 *isp, arg1, arg2;
21842
21843- curctx = (union irq_ctx *) current_thread_info();
21844 irqctx = __this_cpu_read(hardirq_ctx);
21845
21846 /*
21847@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21848 * handler) we can't do that and just have to keep using the
21849 * current stack (which is the irq stack already after all)
21850 */
21851- if (unlikely(curctx == irqctx))
21852+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
21853 return 0;
21854
21855 /* build the stack frame on the IRQ stack */
21856- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
21857- irqctx->tinfo.task = curctx->tinfo.task;
21858- irqctx->tinfo.previous_esp = current_stack_pointer;
21859+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
21860+ irqctx->previous_esp = current_stack_pointer;
21861
21862- /* Copy the preempt_count so that the [soft]irq checks work. */
21863- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
21864+#ifdef CONFIG_PAX_MEMORY_UDEREF
21865+ __set_fs(MAKE_MM_SEG(0));
21866+#endif
21867
21868 if (unlikely(overflow))
21869 call_on_stack(print_stack_overflow, isp);
21870@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21871 : "0" (irq), "1" (desc), "2" (isp),
21872 "D" (desc->handle_irq)
21873 : "memory", "cc", "ecx");
21874+
21875+#ifdef CONFIG_PAX_MEMORY_UDEREF
21876+ __set_fs(current_thread_info()->addr_limit);
21877+#endif
21878+
21879 return 1;
21880 }
21881
21882@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21883 */
21884 void __cpuinit irq_ctx_init(int cpu)
21885 {
21886- union irq_ctx *irqctx;
21887-
21888 if (per_cpu(hardirq_ctx, cpu))
21889 return;
21890
21891- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
21892- THREADINFO_GFP,
21893- THREAD_SIZE_ORDER));
21894- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
21895- irqctx->tinfo.cpu = cpu;
21896- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
21897- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
21898-
21899- per_cpu(hardirq_ctx, cpu) = irqctx;
21900-
21901- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
21902- THREADINFO_GFP,
21903- THREAD_SIZE_ORDER));
21904- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
21905- irqctx->tinfo.cpu = cpu;
21906- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
21907-
21908- per_cpu(softirq_ctx, cpu) = irqctx;
21909+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
21910+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
21911+
21912+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
21913+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
21914
21915 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
21916 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
21917@@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
21918 asmlinkage void do_softirq(void)
21919 {
21920 unsigned long flags;
21921- struct thread_info *curctx;
21922 union irq_ctx *irqctx;
21923 u32 *isp;
21924
21925@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
21926 local_irq_save(flags);
21927
21928 if (local_softirq_pending()) {
21929- curctx = current_thread_info();
21930 irqctx = __this_cpu_read(softirq_ctx);
21931- irqctx->tinfo.task = curctx->task;
21932- irqctx->tinfo.previous_esp = current_stack_pointer;
21933+ irqctx->previous_esp = current_stack_pointer;
21934
21935 /* build the stack frame on the softirq stack */
21936- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
21937+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
21938+
21939+#ifdef CONFIG_PAX_MEMORY_UDEREF
21940+ __set_fs(MAKE_MM_SEG(0));
21941+#endif
21942
21943 call_on_stack(__do_softirq, isp);
21944+
21945+#ifdef CONFIG_PAX_MEMORY_UDEREF
21946+ __set_fs(current_thread_info()->addr_limit);
21947+#endif
21948+
21949 /*
21950 * Shouldn't happen, we returned above if in_interrupt():
21951 */
21952@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
21953 if (unlikely(!desc))
21954 return false;
21955
21956- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
21957+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
21958 if (unlikely(overflow))
21959 print_stack_overflow();
21960 desc->handle_irq(irq, desc);
21961diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
21962index d04d3ec..ea4b374 100644
21963--- a/arch/x86/kernel/irq_64.c
21964+++ b/arch/x86/kernel/irq_64.c
21965@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
21966 u64 estack_top, estack_bottom;
21967 u64 curbase = (u64)task_stack_page(current);
21968
21969- if (user_mode_vm(regs))
21970+ if (user_mode(regs))
21971 return;
21972
21973 if (regs->sp >= curbase + sizeof(struct thread_info) +
21974diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
21975index dc1404b..bbc43e7 100644
21976--- a/arch/x86/kernel/kdebugfs.c
21977+++ b/arch/x86/kernel/kdebugfs.c
21978@@ -27,7 +27,7 @@ struct setup_data_node {
21979 u32 len;
21980 };
21981
21982-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
21983+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
21984 size_t count, loff_t *ppos)
21985 {
21986 struct setup_data_node *node = file->private_data;
21987diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
21988index 836f832..a8bda67 100644
21989--- a/arch/x86/kernel/kgdb.c
21990+++ b/arch/x86/kernel/kgdb.c
21991@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
21992 #ifdef CONFIG_X86_32
21993 switch (regno) {
21994 case GDB_SS:
21995- if (!user_mode_vm(regs))
21996+ if (!user_mode(regs))
21997 *(unsigned long *)mem = __KERNEL_DS;
21998 break;
21999 case GDB_SP:
22000- if (!user_mode_vm(regs))
22001+ if (!user_mode(regs))
22002 *(unsigned long *)mem = kernel_stack_pointer(regs);
22003 break;
22004 case GDB_GS:
22005@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
22006 bp->attr.bp_addr = breakinfo[breakno].addr;
22007 bp->attr.bp_len = breakinfo[breakno].len;
22008 bp->attr.bp_type = breakinfo[breakno].type;
22009- info->address = breakinfo[breakno].addr;
22010+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
22011+ info->address = ktla_ktva(breakinfo[breakno].addr);
22012+ else
22013+ info->address = breakinfo[breakno].addr;
22014 info->len = breakinfo[breakno].len;
22015 info->type = breakinfo[breakno].type;
22016 val = arch_install_hw_breakpoint(bp);
22017@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
22018 case 'k':
22019 /* clear the trace bit */
22020 linux_regs->flags &= ~X86_EFLAGS_TF;
22021- atomic_set(&kgdb_cpu_doing_single_step, -1);
22022+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
22023
22024 /* set the trace bit if we're stepping */
22025 if (remcomInBuffer[0] == 's') {
22026 linux_regs->flags |= X86_EFLAGS_TF;
22027- atomic_set(&kgdb_cpu_doing_single_step,
22028+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
22029 raw_smp_processor_id());
22030 }
22031
22032@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
22033
22034 switch (cmd) {
22035 case DIE_DEBUG:
22036- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
22037+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
22038 if (user_mode(regs))
22039 return single_step_cont(regs, args);
22040 break;
22041@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
22042 #endif /* CONFIG_DEBUG_RODATA */
22043
22044 bpt->type = BP_BREAKPOINT;
22045- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
22046+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
22047 BREAK_INSTR_SIZE);
22048 if (err)
22049 return err;
22050- err = probe_kernel_write((char *)bpt->bpt_addr,
22051+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
22052 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
22053 #ifdef CONFIG_DEBUG_RODATA
22054 if (!err)
22055@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
22056 return -EBUSY;
22057 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
22058 BREAK_INSTR_SIZE);
22059- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
22060+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
22061 if (err)
22062 return err;
22063 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
22064@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
22065 if (mutex_is_locked(&text_mutex))
22066 goto knl_write;
22067 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
22068- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
22069+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
22070 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
22071 goto knl_write;
22072 return err;
22073 knl_write:
22074 #endif /* CONFIG_DEBUG_RODATA */
22075- return probe_kernel_write((char *)bpt->bpt_addr,
22076+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
22077 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
22078 }
22079
22080diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
22081index c5e410e..ed5a7f0 100644
22082--- a/arch/x86/kernel/kprobes-opt.c
22083+++ b/arch/x86/kernel/kprobes-opt.c
22084@@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
22085 * Verify if the address gap is in 2GB range, because this uses
22086 * a relative jump.
22087 */
22088- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
22089+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
22090 if (abs(rel) > 0x7fffffff)
22091 return -ERANGE;
22092
22093@@ -353,16 +353,16 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
22094 op->optinsn.size = ret;
22095
22096 /* Copy arch-dep-instance from template */
22097- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
22098+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
22099
22100 /* Set probe information */
22101 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
22102
22103 /* Set probe function call */
22104- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
22105+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
22106
22107 /* Set returning jmp instruction at the tail of out-of-line buffer */
22108- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
22109+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
22110 (u8 *)op->kp.addr + op->optinsn.size);
22111
22112 flush_icache_range((unsigned long) buf,
22113@@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
22114 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
22115
22116 /* Backup instructions which will be replaced by jump address */
22117- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
22118+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
22119 RELATIVE_ADDR_SIZE);
22120
22121 insn_buf[0] = RELATIVEJUMP_OPCODE;
22122@@ -483,7 +483,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
22123 /* This kprobe is really able to run optimized path. */
22124 op = container_of(p, struct optimized_kprobe, kp);
22125 /* Detour through copied instructions */
22126- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
22127+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
22128 if (!reenter)
22129 reset_current_kprobe();
22130 preempt_enable_no_resched();
22131diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
22132index 57916c0..9e0b9d0 100644
22133--- a/arch/x86/kernel/kprobes.c
22134+++ b/arch/x86/kernel/kprobes.c
22135@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
22136 s32 raddr;
22137 } __attribute__((packed)) *insn;
22138
22139- insn = (struct __arch_relative_insn *)from;
22140+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
22141+
22142+ pax_open_kernel();
22143 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
22144 insn->op = op;
22145+ pax_close_kernel();
22146 }
22147
22148 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
22149@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
22150 kprobe_opcode_t opcode;
22151 kprobe_opcode_t *orig_opcodes = opcodes;
22152
22153- if (search_exception_tables((unsigned long)opcodes))
22154+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
22155 return 0; /* Page fault may occur on this address. */
22156
22157 retry:
22158@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
22159 * for the first byte, we can recover the original instruction
22160 * from it and kp->opcode.
22161 */
22162- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
22163+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
22164 buf[0] = kp->opcode;
22165- return (unsigned long)buf;
22166+ return ktva_ktla((unsigned long)buf);
22167 }
22168
22169 /*
22170@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
22171 /* Another subsystem puts a breakpoint, failed to recover */
22172 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
22173 return 0;
22174+ pax_open_kernel();
22175 memcpy(dest, insn.kaddr, insn.length);
22176+ pax_close_kernel();
22177
22178 #ifdef CONFIG_X86_64
22179 if (insn_rip_relative(&insn)) {
22180@@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
22181 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
22182 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
22183 disp = (u8 *) dest + insn_offset_displacement(&insn);
22184+ pax_open_kernel();
22185 *(s32 *) disp = (s32) newdisp;
22186+ pax_close_kernel();
22187 }
22188 #endif
22189 return insn.length;
22190@@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
22191 * nor set current_kprobe, because it doesn't use single
22192 * stepping.
22193 */
22194- regs->ip = (unsigned long)p->ainsn.insn;
22195+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
22196 preempt_enable_no_resched();
22197 return;
22198 }
22199@@ -502,9 +509,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
22200 regs->flags &= ~X86_EFLAGS_IF;
22201 /* single step inline if the instruction is an int3 */
22202 if (p->opcode == BREAKPOINT_INSTRUCTION)
22203- regs->ip = (unsigned long)p->addr;
22204+ regs->ip = ktla_ktva((unsigned long)p->addr);
22205 else
22206- regs->ip = (unsigned long)p->ainsn.insn;
22207+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
22208 }
22209
22210 /*
22211@@ -600,7 +607,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
22212 setup_singlestep(p, regs, kcb, 0);
22213 return 1;
22214 }
22215- } else if (*addr != BREAKPOINT_INSTRUCTION) {
22216+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
22217 /*
22218 * The breakpoint instruction was removed right
22219 * after we hit it. Another cpu has removed
22220@@ -651,6 +658,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
22221 " movq %rax, 152(%rsp)\n"
22222 RESTORE_REGS_STRING
22223 " popfq\n"
22224+#ifdef KERNEXEC_PLUGIN
22225+ " btsq $63,(%rsp)\n"
22226+#endif
22227 #else
22228 " pushf\n"
22229 SAVE_REGS_STRING
22230@@ -788,7 +798,7 @@ static void __kprobes
22231 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
22232 {
22233 unsigned long *tos = stack_addr(regs);
22234- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
22235+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
22236 unsigned long orig_ip = (unsigned long)p->addr;
22237 kprobe_opcode_t *insn = p->ainsn.insn;
22238
22239@@ -970,7 +980,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
22240 struct die_args *args = data;
22241 int ret = NOTIFY_DONE;
22242
22243- if (args->regs && user_mode_vm(args->regs))
22244+ if (args->regs && user_mode(args->regs))
22245 return ret;
22246
22247 switch (val) {
22248diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
22249index 9c2bd8b..bb1131c 100644
22250--- a/arch/x86/kernel/kvm.c
22251+++ b/arch/x86/kernel/kvm.c
22252@@ -452,7 +452,7 @@ static int __cpuinit kvm_cpu_notify(struct notifier_block *self,
22253 return NOTIFY_OK;
22254 }
22255
22256-static struct notifier_block __cpuinitdata kvm_cpu_notifier = {
22257+static struct notifier_block kvm_cpu_notifier = {
22258 .notifier_call = kvm_cpu_notify,
22259 };
22260 #endif
22261diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
22262index ebc9873..1b9724b 100644
22263--- a/arch/x86/kernel/ldt.c
22264+++ b/arch/x86/kernel/ldt.c
22265@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
22266 if (reload) {
22267 #ifdef CONFIG_SMP
22268 preempt_disable();
22269- load_LDT(pc);
22270+ load_LDT_nolock(pc);
22271 if (!cpumask_equal(mm_cpumask(current->mm),
22272 cpumask_of(smp_processor_id())))
22273 smp_call_function(flush_ldt, current->mm, 1);
22274 preempt_enable();
22275 #else
22276- load_LDT(pc);
22277+ load_LDT_nolock(pc);
22278 #endif
22279 }
22280 if (oldsize) {
22281@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
22282 return err;
22283
22284 for (i = 0; i < old->size; i++)
22285- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
22286+ write_ldt_entry(new->ldt, i, old->ldt + i);
22287 return 0;
22288 }
22289
22290@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
22291 retval = copy_ldt(&mm->context, &old_mm->context);
22292 mutex_unlock(&old_mm->context.lock);
22293 }
22294+
22295+ if (tsk == current) {
22296+ mm->context.vdso = 0;
22297+
22298+#ifdef CONFIG_X86_32
22299+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
22300+ mm->context.user_cs_base = 0UL;
22301+ mm->context.user_cs_limit = ~0UL;
22302+
22303+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
22304+ cpus_clear(mm->context.cpu_user_cs_mask);
22305+#endif
22306+
22307+#endif
22308+#endif
22309+
22310+ }
22311+
22312 return retval;
22313 }
22314
22315@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
22316 }
22317 }
22318
22319+#ifdef CONFIG_PAX_SEGMEXEC
22320+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
22321+ error = -EINVAL;
22322+ goto out_unlock;
22323+ }
22324+#endif
22325+
22326 fill_ldt(&ldt, &ldt_info);
22327 if (oldmode)
22328 ldt.avl = 0;
22329diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
22330index 5b19e4d..6476a76 100644
22331--- a/arch/x86/kernel/machine_kexec_32.c
22332+++ b/arch/x86/kernel/machine_kexec_32.c
22333@@ -26,7 +26,7 @@
22334 #include <asm/cacheflush.h>
22335 #include <asm/debugreg.h>
22336
22337-static void set_idt(void *newidt, __u16 limit)
22338+static void set_idt(struct desc_struct *newidt, __u16 limit)
22339 {
22340 struct desc_ptr curidt;
22341
22342@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
22343 }
22344
22345
22346-static void set_gdt(void *newgdt, __u16 limit)
22347+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
22348 {
22349 struct desc_ptr curgdt;
22350
22351@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
22352 }
22353
22354 control_page = page_address(image->control_code_page);
22355- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
22356+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
22357
22358 relocate_kernel_ptr = control_page;
22359 page_list[PA_CONTROL_PAGE] = __pa(control_page);
22360diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
22361index 3a04b22..1d2eb09 100644
22362--- a/arch/x86/kernel/microcode_core.c
22363+++ b/arch/x86/kernel/microcode_core.c
22364@@ -512,7 +512,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
22365 return NOTIFY_OK;
22366 }
22367
22368-static struct notifier_block __refdata mc_cpu_notifier = {
22369+static struct notifier_block mc_cpu_notifier = {
22370 .notifier_call = mc_cpu_callback,
22371 };
22372
22373diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
22374index 3544aed..01ddc1c 100644
22375--- a/arch/x86/kernel/microcode_intel.c
22376+++ b/arch/x86/kernel/microcode_intel.c
22377@@ -431,13 +431,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
22378
22379 static int get_ucode_user(void *to, const void *from, size_t n)
22380 {
22381- return copy_from_user(to, from, n);
22382+ return copy_from_user(to, (const void __force_user *)from, n);
22383 }
22384
22385 static enum ucode_state
22386 request_microcode_user(int cpu, const void __user *buf, size_t size)
22387 {
22388- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
22389+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
22390 }
22391
22392 static void microcode_fini_cpu(int cpu)
22393diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
22394index 216a4d7..228255a 100644
22395--- a/arch/x86/kernel/module.c
22396+++ b/arch/x86/kernel/module.c
22397@@ -43,15 +43,60 @@ do { \
22398 } while (0)
22399 #endif
22400
22401-void *module_alloc(unsigned long size)
22402+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
22403 {
22404- if (PAGE_ALIGN(size) > MODULES_LEN)
22405+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
22406 return NULL;
22407 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
22408- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
22409+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
22410 -1, __builtin_return_address(0));
22411 }
22412
22413+void *module_alloc(unsigned long size)
22414+{
22415+
22416+#ifdef CONFIG_PAX_KERNEXEC
22417+ return __module_alloc(size, PAGE_KERNEL);
22418+#else
22419+ return __module_alloc(size, PAGE_KERNEL_EXEC);
22420+#endif
22421+
22422+}
22423+
22424+#ifdef CONFIG_PAX_KERNEXEC
22425+#ifdef CONFIG_X86_32
22426+void *module_alloc_exec(unsigned long size)
22427+{
22428+ struct vm_struct *area;
22429+
22430+ if (size == 0)
22431+ return NULL;
22432+
22433+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
22434+ return area ? area->addr : NULL;
22435+}
22436+EXPORT_SYMBOL(module_alloc_exec);
22437+
22438+void module_free_exec(struct module *mod, void *module_region)
22439+{
22440+ vunmap(module_region);
22441+}
22442+EXPORT_SYMBOL(module_free_exec);
22443+#else
22444+void module_free_exec(struct module *mod, void *module_region)
22445+{
22446+ module_free(mod, module_region);
22447+}
22448+EXPORT_SYMBOL(module_free_exec);
22449+
22450+void *module_alloc_exec(unsigned long size)
22451+{
22452+ return __module_alloc(size, PAGE_KERNEL_RX);
22453+}
22454+EXPORT_SYMBOL(module_alloc_exec);
22455+#endif
22456+#endif
22457+
22458 #ifdef CONFIG_X86_32
22459 int apply_relocate(Elf32_Shdr *sechdrs,
22460 const char *strtab,
22461@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
22462 unsigned int i;
22463 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
22464 Elf32_Sym *sym;
22465- uint32_t *location;
22466+ uint32_t *plocation, location;
22467
22468 DEBUGP("Applying relocate section %u to %u\n",
22469 relsec, sechdrs[relsec].sh_info);
22470 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
22471 /* This is where to make the change */
22472- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
22473- + rel[i].r_offset;
22474+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
22475+ location = (uint32_t)plocation;
22476+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
22477+ plocation = ktla_ktva((void *)plocation);
22478 /* This is the symbol it is referring to. Note that all
22479 undefined symbols have been resolved. */
22480 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
22481@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
22482 switch (ELF32_R_TYPE(rel[i].r_info)) {
22483 case R_386_32:
22484 /* We add the value into the location given */
22485- *location += sym->st_value;
22486+ pax_open_kernel();
22487+ *plocation += sym->st_value;
22488+ pax_close_kernel();
22489 break;
22490 case R_386_PC32:
22491 /* Add the value, subtract its position */
22492- *location += sym->st_value - (uint32_t)location;
22493+ pax_open_kernel();
22494+ *plocation += sym->st_value - location;
22495+ pax_close_kernel();
22496 break;
22497 default:
22498 pr_err("%s: Unknown relocation: %u\n",
22499@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
22500 case R_X86_64_NONE:
22501 break;
22502 case R_X86_64_64:
22503+ pax_open_kernel();
22504 *(u64 *)loc = val;
22505+ pax_close_kernel();
22506 break;
22507 case R_X86_64_32:
22508+ pax_open_kernel();
22509 *(u32 *)loc = val;
22510+ pax_close_kernel();
22511 if (val != *(u32 *)loc)
22512 goto overflow;
22513 break;
22514 case R_X86_64_32S:
22515+ pax_open_kernel();
22516 *(s32 *)loc = val;
22517+ pax_close_kernel();
22518 if ((s64)val != *(s32 *)loc)
22519 goto overflow;
22520 break;
22521 case R_X86_64_PC32:
22522 val -= (u64)loc;
22523+ pax_open_kernel();
22524 *(u32 *)loc = val;
22525+ pax_close_kernel();
22526+
22527 #if 0
22528 if ((s64)val != *(s32 *)loc)
22529 goto overflow;
22530diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
22531index 4929502..686c291 100644
22532--- a/arch/x86/kernel/msr.c
22533+++ b/arch/x86/kernel/msr.c
22534@@ -234,7 +234,7 @@ static int __cpuinit msr_class_cpu_callback(struct notifier_block *nfb,
22535 return notifier_from_errno(err);
22536 }
22537
22538-static struct notifier_block __refdata msr_class_cpu_notifier = {
22539+static struct notifier_block msr_class_cpu_notifier = {
22540 .notifier_call = msr_class_cpu_callback,
22541 };
22542
22543diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
22544index f84f5c5..f404e81 100644
22545--- a/arch/x86/kernel/nmi.c
22546+++ b/arch/x86/kernel/nmi.c
22547@@ -105,7 +105,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
22548 return handled;
22549 }
22550
22551-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
22552+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
22553 {
22554 struct nmi_desc *desc = nmi_to_desc(type);
22555 unsigned long flags;
22556@@ -129,9 +129,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
22557 * event confuses some handlers (kdump uses this flag)
22558 */
22559 if (action->flags & NMI_FLAG_FIRST)
22560- list_add_rcu(&action->list, &desc->head);
22561+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
22562 else
22563- list_add_tail_rcu(&action->list, &desc->head);
22564+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
22565
22566 spin_unlock_irqrestore(&desc->lock, flags);
22567 return 0;
22568@@ -154,7 +154,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
22569 if (!strcmp(n->name, name)) {
22570 WARN(in_nmi(),
22571 "Trying to free NMI (%s) from NMI context!\n", n->name);
22572- list_del_rcu(&n->list);
22573+ pax_list_del_rcu((struct list_head *)&n->list);
22574 break;
22575 }
22576 }
22577@@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
22578 dotraplinkage notrace __kprobes void
22579 do_nmi(struct pt_regs *regs, long error_code)
22580 {
22581+
22582+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
22583+ if (!user_mode(regs)) {
22584+ unsigned long cs = regs->cs & 0xFFFF;
22585+ unsigned long ip = ktva_ktla(regs->ip);
22586+
22587+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
22588+ regs->ip = ip;
22589+ }
22590+#endif
22591+
22592 nmi_nesting_preprocess(regs);
22593
22594 nmi_enter();
22595diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
22596index 6d9582e..f746287 100644
22597--- a/arch/x86/kernel/nmi_selftest.c
22598+++ b/arch/x86/kernel/nmi_selftest.c
22599@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
22600 {
22601 /* trap all the unknown NMIs we may generate */
22602 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
22603- __initdata);
22604+ __initconst);
22605 }
22606
22607 static void __init cleanup_nmi_testsuite(void)
22608@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
22609 unsigned long timeout;
22610
22611 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
22612- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
22613+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
22614 nmi_fail = FAILURE;
22615 return;
22616 }
22617diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
22618index 676b8c7..870ba04 100644
22619--- a/arch/x86/kernel/paravirt-spinlocks.c
22620+++ b/arch/x86/kernel/paravirt-spinlocks.c
22621@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
22622 arch_spin_lock(lock);
22623 }
22624
22625-struct pv_lock_ops pv_lock_ops = {
22626+struct pv_lock_ops pv_lock_ops __read_only = {
22627 #ifdef CONFIG_SMP
22628 .spin_is_locked = __ticket_spin_is_locked,
22629 .spin_is_contended = __ticket_spin_is_contended,
22630diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
22631index 8bfb335..c1463c6 100644
22632--- a/arch/x86/kernel/paravirt.c
22633+++ b/arch/x86/kernel/paravirt.c
22634@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
22635 {
22636 return x;
22637 }
22638+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
22639+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
22640+#endif
22641
22642 void __init default_banner(void)
22643 {
22644@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
22645 if (opfunc == NULL)
22646 /* If there's no function, patch it with a ud2a (BUG) */
22647 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
22648- else if (opfunc == _paravirt_nop)
22649+ else if (opfunc == (void *)_paravirt_nop)
22650 /* If the operation is a nop, then nop the callsite */
22651 ret = paravirt_patch_nop();
22652
22653 /* identity functions just return their single argument */
22654- else if (opfunc == _paravirt_ident_32)
22655+ else if (opfunc == (void *)_paravirt_ident_32)
22656 ret = paravirt_patch_ident_32(insnbuf, len);
22657- else if (opfunc == _paravirt_ident_64)
22658+ else if (opfunc == (void *)_paravirt_ident_64)
22659 ret = paravirt_patch_ident_64(insnbuf, len);
22660+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
22661+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
22662+ ret = paravirt_patch_ident_64(insnbuf, len);
22663+#endif
22664
22665 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
22666 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
22667@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
22668 if (insn_len > len || start == NULL)
22669 insn_len = len;
22670 else
22671- memcpy(insnbuf, start, insn_len);
22672+ memcpy(insnbuf, ktla_ktva(start), insn_len);
22673
22674 return insn_len;
22675 }
22676@@ -304,7 +311,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
22677 return this_cpu_read(paravirt_lazy_mode);
22678 }
22679
22680-struct pv_info pv_info = {
22681+struct pv_info pv_info __read_only = {
22682 .name = "bare hardware",
22683 .paravirt_enabled = 0,
22684 .kernel_rpl = 0,
22685@@ -315,16 +322,16 @@ struct pv_info pv_info = {
22686 #endif
22687 };
22688
22689-struct pv_init_ops pv_init_ops = {
22690+struct pv_init_ops pv_init_ops __read_only = {
22691 .patch = native_patch,
22692 };
22693
22694-struct pv_time_ops pv_time_ops = {
22695+struct pv_time_ops pv_time_ops __read_only = {
22696 .sched_clock = native_sched_clock,
22697 .steal_clock = native_steal_clock,
22698 };
22699
22700-struct pv_irq_ops pv_irq_ops = {
22701+struct pv_irq_ops pv_irq_ops __read_only = {
22702 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
22703 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
22704 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
22705@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
22706 #endif
22707 };
22708
22709-struct pv_cpu_ops pv_cpu_ops = {
22710+struct pv_cpu_ops pv_cpu_ops __read_only = {
22711 .cpuid = native_cpuid,
22712 .get_debugreg = native_get_debugreg,
22713 .set_debugreg = native_set_debugreg,
22714@@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
22715 .end_context_switch = paravirt_nop,
22716 };
22717
22718-struct pv_apic_ops pv_apic_ops = {
22719+struct pv_apic_ops pv_apic_ops __read_only= {
22720 #ifdef CONFIG_X86_LOCAL_APIC
22721 .startup_ipi_hook = paravirt_nop,
22722 #endif
22723 };
22724
22725-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
22726+#ifdef CONFIG_X86_32
22727+#ifdef CONFIG_X86_PAE
22728+/* 64-bit pagetable entries */
22729+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
22730+#else
22731 /* 32-bit pagetable entries */
22732 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
22733+#endif
22734 #else
22735 /* 64-bit pagetable entries */
22736 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
22737 #endif
22738
22739-struct pv_mmu_ops pv_mmu_ops = {
22740+struct pv_mmu_ops pv_mmu_ops __read_only = {
22741
22742 .read_cr2 = native_read_cr2,
22743 .write_cr2 = native_write_cr2,
22744@@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
22745 .make_pud = PTE_IDENT,
22746
22747 .set_pgd = native_set_pgd,
22748+ .set_pgd_batched = native_set_pgd_batched,
22749 #endif
22750 #endif /* PAGETABLE_LEVELS >= 3 */
22751
22752@@ -479,6 +492,12 @@ struct pv_mmu_ops pv_mmu_ops = {
22753 },
22754
22755 .set_fixmap = native_set_fixmap,
22756+
22757+#ifdef CONFIG_PAX_KERNEXEC
22758+ .pax_open_kernel = native_pax_open_kernel,
22759+ .pax_close_kernel = native_pax_close_kernel,
22760+#endif
22761+
22762 };
22763
22764 EXPORT_SYMBOL_GPL(pv_time_ops);
22765diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
22766index 35ccf75..7a15747 100644
22767--- a/arch/x86/kernel/pci-iommu_table.c
22768+++ b/arch/x86/kernel/pci-iommu_table.c
22769@@ -2,7 +2,7 @@
22770 #include <asm/iommu_table.h>
22771 #include <linux/string.h>
22772 #include <linux/kallsyms.h>
22773-
22774+#include <linux/sched.h>
22775
22776 #define DEBUG 1
22777
22778diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
22779index 6c483ba..d10ce2f 100644
22780--- a/arch/x86/kernel/pci-swiotlb.c
22781+++ b/arch/x86/kernel/pci-swiotlb.c
22782@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
22783 void *vaddr, dma_addr_t dma_addr,
22784 struct dma_attrs *attrs)
22785 {
22786- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
22787+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
22788 }
22789
22790 static struct dma_map_ops swiotlb_dma_ops = {
22791diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
22792index 2ed787f..f70c9f6 100644
22793--- a/arch/x86/kernel/process.c
22794+++ b/arch/x86/kernel/process.c
22795@@ -36,7 +36,8 @@
22796 * section. Since TSS's are completely CPU-local, we want them
22797 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
22798 */
22799-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
22800+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
22801+EXPORT_SYMBOL(init_tss);
22802
22803 #ifdef CONFIG_X86_64
22804 static DEFINE_PER_CPU(unsigned char, is_idle);
22805@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
22806 task_xstate_cachep =
22807 kmem_cache_create("task_xstate", xstate_size,
22808 __alignof__(union thread_xstate),
22809- SLAB_PANIC | SLAB_NOTRACK, NULL);
22810+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
22811 }
22812
22813 /*
22814@@ -105,7 +106,7 @@ void exit_thread(void)
22815 unsigned long *bp = t->io_bitmap_ptr;
22816
22817 if (bp) {
22818- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
22819+ struct tss_struct *tss = init_tss + get_cpu();
22820
22821 t->io_bitmap_ptr = NULL;
22822 clear_thread_flag(TIF_IO_BITMAP);
22823@@ -136,7 +137,7 @@ void show_regs_common(void)
22824 board = dmi_get_system_info(DMI_BOARD_NAME);
22825
22826 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
22827- current->pid, current->comm, print_tainted(),
22828+ task_pid_nr(current), current->comm, print_tainted(),
22829 init_utsname()->release,
22830 (int)strcspn(init_utsname()->version, " "),
22831 init_utsname()->version,
22832@@ -149,6 +150,9 @@ void flush_thread(void)
22833 {
22834 struct task_struct *tsk = current;
22835
22836+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
22837+ loadsegment(gs, 0);
22838+#endif
22839 flush_ptrace_hw_breakpoint(tsk);
22840 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
22841 drop_init_fpu(tsk);
22842@@ -301,7 +305,7 @@ static void __exit_idle(void)
22843 void exit_idle(void)
22844 {
22845 /* idle loop has pid 0 */
22846- if (current->pid)
22847+ if (task_pid_nr(current))
22848 return;
22849 __exit_idle();
22850 }
22851@@ -404,7 +408,7 @@ bool set_pm_idle_to_default(void)
22852
22853 return ret;
22854 }
22855-void stop_this_cpu(void *dummy)
22856+__noreturn void stop_this_cpu(void *dummy)
22857 {
22858 local_irq_disable();
22859 /*
22860@@ -632,16 +636,37 @@ static int __init idle_setup(char *str)
22861 }
22862 early_param("idle", idle_setup);
22863
22864-unsigned long arch_align_stack(unsigned long sp)
22865+#ifdef CONFIG_PAX_RANDKSTACK
22866+void pax_randomize_kstack(struct pt_regs *regs)
22867 {
22868- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
22869- sp -= get_random_int() % 8192;
22870- return sp & ~0xf;
22871-}
22872+ struct thread_struct *thread = &current->thread;
22873+ unsigned long time;
22874
22875-unsigned long arch_randomize_brk(struct mm_struct *mm)
22876-{
22877- unsigned long range_end = mm->brk + 0x02000000;
22878- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
22879-}
22880+ if (!randomize_va_space)
22881+ return;
22882+
22883+ if (v8086_mode(regs))
22884+ return;
22885
22886+ rdtscl(time);
22887+
22888+ /* P4 seems to return a 0 LSB, ignore it */
22889+#ifdef CONFIG_MPENTIUM4
22890+ time &= 0x3EUL;
22891+ time <<= 2;
22892+#elif defined(CONFIG_X86_64)
22893+ time &= 0xFUL;
22894+ time <<= 4;
22895+#else
22896+ time &= 0x1FUL;
22897+ time <<= 3;
22898+#endif
22899+
22900+ thread->sp0 ^= time;
22901+ load_sp0(init_tss + smp_processor_id(), thread);
22902+
22903+#ifdef CONFIG_X86_64
22904+ this_cpu_write(kernel_stack, thread->sp0);
22905+#endif
22906+}
22907+#endif
22908diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
22909index b5a8905..d9cacac 100644
22910--- a/arch/x86/kernel/process_32.c
22911+++ b/arch/x86/kernel/process_32.c
22912@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
22913 unsigned long thread_saved_pc(struct task_struct *tsk)
22914 {
22915 return ((unsigned long *)tsk->thread.sp)[3];
22916+//XXX return tsk->thread.eip;
22917 }
22918
22919 void __show_regs(struct pt_regs *regs, int all)
22920@@ -74,21 +75,20 @@ void __show_regs(struct pt_regs *regs, int all)
22921 unsigned long sp;
22922 unsigned short ss, gs;
22923
22924- if (user_mode_vm(regs)) {
22925+ if (user_mode(regs)) {
22926 sp = regs->sp;
22927 ss = regs->ss & 0xffff;
22928- gs = get_user_gs(regs);
22929 } else {
22930 sp = kernel_stack_pointer(regs);
22931 savesegment(ss, ss);
22932- savesegment(gs, gs);
22933 }
22934+ gs = get_user_gs(regs);
22935
22936 show_regs_common();
22937
22938 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
22939 (u16)regs->cs, regs->ip, regs->flags,
22940- smp_processor_id());
22941+ raw_smp_processor_id());
22942 print_symbol("EIP is at %s\n", regs->ip);
22943
22944 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
22945@@ -130,20 +130,21 @@ void release_thread(struct task_struct *dead_task)
22946 int copy_thread(unsigned long clone_flags, unsigned long sp,
22947 unsigned long arg, struct task_struct *p)
22948 {
22949- struct pt_regs *childregs = task_pt_regs(p);
22950+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
22951 struct task_struct *tsk;
22952 int err;
22953
22954 p->thread.sp = (unsigned long) childregs;
22955 p->thread.sp0 = (unsigned long) (childregs+1);
22956+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
22957
22958 if (unlikely(p->flags & PF_KTHREAD)) {
22959 /* kernel thread */
22960 memset(childregs, 0, sizeof(struct pt_regs));
22961 p->thread.ip = (unsigned long) ret_from_kernel_thread;
22962- task_user_gs(p) = __KERNEL_STACK_CANARY;
22963- childregs->ds = __USER_DS;
22964- childregs->es = __USER_DS;
22965+ savesegment(gs, childregs->gs);
22966+ childregs->ds = __KERNEL_DS;
22967+ childregs->es = __KERNEL_DS;
22968 childregs->fs = __KERNEL_PERCPU;
22969 childregs->bx = sp; /* function */
22970 childregs->bp = arg;
22971@@ -250,7 +251,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22972 struct thread_struct *prev = &prev_p->thread,
22973 *next = &next_p->thread;
22974 int cpu = smp_processor_id();
22975- struct tss_struct *tss = &per_cpu(init_tss, cpu);
22976+ struct tss_struct *tss = init_tss + cpu;
22977 fpu_switch_t fpu;
22978
22979 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
22980@@ -274,6 +275,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22981 */
22982 lazy_save_gs(prev->gs);
22983
22984+#ifdef CONFIG_PAX_MEMORY_UDEREF
22985+ __set_fs(task_thread_info(next_p)->addr_limit);
22986+#endif
22987+
22988 /*
22989 * Load the per-thread Thread-Local Storage descriptor.
22990 */
22991@@ -304,6 +309,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22992 */
22993 arch_end_context_switch(next_p);
22994
22995+ this_cpu_write(current_task, next_p);
22996+ this_cpu_write(current_tinfo, &next_p->tinfo);
22997+
22998 /*
22999 * Restore %gs if needed (which is common)
23000 */
23001@@ -312,8 +320,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
23002
23003 switch_fpu_finish(next_p, fpu);
23004
23005- this_cpu_write(current_task, next_p);
23006-
23007 return prev_p;
23008 }
23009
23010@@ -343,4 +349,3 @@ unsigned long get_wchan(struct task_struct *p)
23011 } while (count++ < 16);
23012 return 0;
23013 }
23014-
23015diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
23016index 6e68a61..955a9a5 100644
23017--- a/arch/x86/kernel/process_64.c
23018+++ b/arch/x86/kernel/process_64.c
23019@@ -152,10 +152,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
23020 struct pt_regs *childregs;
23021 struct task_struct *me = current;
23022
23023- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
23024+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
23025 childregs = task_pt_regs(p);
23026 p->thread.sp = (unsigned long) childregs;
23027 p->thread.usersp = me->thread.usersp;
23028+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
23029 set_tsk_thread_flag(p, TIF_FORK);
23030 p->fpu_counter = 0;
23031 p->thread.io_bitmap_ptr = NULL;
23032@@ -274,7 +275,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
23033 struct thread_struct *prev = &prev_p->thread;
23034 struct thread_struct *next = &next_p->thread;
23035 int cpu = smp_processor_id();
23036- struct tss_struct *tss = &per_cpu(init_tss, cpu);
23037+ struct tss_struct *tss = init_tss + cpu;
23038 unsigned fsindex, gsindex;
23039 fpu_switch_t fpu;
23040
23041@@ -356,10 +357,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
23042 prev->usersp = this_cpu_read(old_rsp);
23043 this_cpu_write(old_rsp, next->usersp);
23044 this_cpu_write(current_task, next_p);
23045+ this_cpu_write(current_tinfo, &next_p->tinfo);
23046
23047- this_cpu_write(kernel_stack,
23048- (unsigned long)task_stack_page(next_p) +
23049- THREAD_SIZE - KERNEL_STACK_OFFSET);
23050+ this_cpu_write(kernel_stack, next->sp0);
23051
23052 /*
23053 * Now maybe reload the debug registers and handle I/O bitmaps
23054@@ -428,12 +428,11 @@ unsigned long get_wchan(struct task_struct *p)
23055 if (!p || p == current || p->state == TASK_RUNNING)
23056 return 0;
23057 stack = (unsigned long)task_stack_page(p);
23058- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
23059+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
23060 return 0;
23061 fp = *(u64 *)(p->thread.sp);
23062 do {
23063- if (fp < (unsigned long)stack ||
23064- fp >= (unsigned long)stack+THREAD_SIZE)
23065+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
23066 return 0;
23067 ip = *(u64 *)(fp+8);
23068 if (!in_sched_functions(ip))
23069diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
23070index b629bbe..0fa615a 100644
23071--- a/arch/x86/kernel/ptrace.c
23072+++ b/arch/x86/kernel/ptrace.c
23073@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
23074 {
23075 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
23076 unsigned long sp = (unsigned long)&regs->sp;
23077- struct thread_info *tinfo;
23078
23079- if (context == (sp & ~(THREAD_SIZE - 1)))
23080+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
23081 return sp;
23082
23083- tinfo = (struct thread_info *)context;
23084- if (tinfo->previous_esp)
23085- return tinfo->previous_esp;
23086+ sp = *(unsigned long *)context;
23087+ if (sp)
23088+ return sp;
23089
23090 return (unsigned long)regs;
23091 }
23092@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
23093 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
23094 {
23095 int i;
23096- int dr7 = 0;
23097+ unsigned long dr7 = 0;
23098 struct arch_hw_breakpoint *info;
23099
23100 for (i = 0; i < HBP_NUM; i++) {
23101@@ -856,7 +855,7 @@ long arch_ptrace(struct task_struct *child, long request,
23102 unsigned long addr, unsigned long data)
23103 {
23104 int ret;
23105- unsigned long __user *datap = (unsigned long __user *)data;
23106+ unsigned long __user *datap = (__force unsigned long __user *)data;
23107
23108 switch (request) {
23109 /* read the word at location addr in the USER area. */
23110@@ -941,14 +940,14 @@ long arch_ptrace(struct task_struct *child, long request,
23111 if ((int) addr < 0)
23112 return -EIO;
23113 ret = do_get_thread_area(child, addr,
23114- (struct user_desc __user *)data);
23115+ (__force struct user_desc __user *) data);
23116 break;
23117
23118 case PTRACE_SET_THREAD_AREA:
23119 if ((int) addr < 0)
23120 return -EIO;
23121 ret = do_set_thread_area(child, addr,
23122- (struct user_desc __user *)data, 0);
23123+ (__force struct user_desc __user *) data, 0);
23124 break;
23125 #endif
23126
23127@@ -1326,7 +1325,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
23128
23129 #ifdef CONFIG_X86_64
23130
23131-static struct user_regset x86_64_regsets[] __read_mostly = {
23132+static user_regset_no_const x86_64_regsets[] __read_only = {
23133 [REGSET_GENERAL] = {
23134 .core_note_type = NT_PRSTATUS,
23135 .n = sizeof(struct user_regs_struct) / sizeof(long),
23136@@ -1367,7 +1366,7 @@ static const struct user_regset_view user_x86_64_view = {
23137 #endif /* CONFIG_X86_64 */
23138
23139 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
23140-static struct user_regset x86_32_regsets[] __read_mostly = {
23141+static user_regset_no_const x86_32_regsets[] __read_only = {
23142 [REGSET_GENERAL] = {
23143 .core_note_type = NT_PRSTATUS,
23144 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
23145@@ -1420,7 +1419,7 @@ static const struct user_regset_view user_x86_32_view = {
23146 */
23147 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
23148
23149-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
23150+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
23151 {
23152 #ifdef CONFIG_X86_64
23153 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
23154@@ -1455,7 +1454,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
23155 memset(info, 0, sizeof(*info));
23156 info->si_signo = SIGTRAP;
23157 info->si_code = si_code;
23158- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
23159+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
23160 }
23161
23162 void user_single_step_siginfo(struct task_struct *tsk,
23163@@ -1484,6 +1483,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
23164 # define IS_IA32 0
23165 #endif
23166
23167+#ifdef CONFIG_GRKERNSEC_SETXID
23168+extern void gr_delayed_cred_worker(void);
23169+#endif
23170+
23171 /*
23172 * We must return the syscall number to actually look up in the table.
23173 * This can be -1L to skip running any syscall at all.
23174@@ -1494,6 +1497,11 @@ long syscall_trace_enter(struct pt_regs *regs)
23175
23176 user_exit();
23177
23178+#ifdef CONFIG_GRKERNSEC_SETXID
23179+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
23180+ gr_delayed_cred_worker();
23181+#endif
23182+
23183 /*
23184 * If we stepped into a sysenter/syscall insn, it trapped in
23185 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
23186@@ -1549,6 +1557,11 @@ void syscall_trace_leave(struct pt_regs *regs)
23187 */
23188 user_exit();
23189
23190+#ifdef CONFIG_GRKERNSEC_SETXID
23191+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
23192+ gr_delayed_cred_worker();
23193+#endif
23194+
23195 audit_syscall_exit(regs);
23196
23197 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
23198diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
23199index 2cb9470..ff1fd80 100644
23200--- a/arch/x86/kernel/pvclock.c
23201+++ b/arch/x86/kernel/pvclock.c
23202@@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
23203 return pv_tsc_khz;
23204 }
23205
23206-static atomic64_t last_value = ATOMIC64_INIT(0);
23207+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
23208
23209 void pvclock_resume(void)
23210 {
23211- atomic64_set(&last_value, 0);
23212+ atomic64_set_unchecked(&last_value, 0);
23213 }
23214
23215 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
23216@@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
23217 * updating at the same time, and one of them could be slightly behind,
23218 * making the assumption that last_value always go forward fail to hold.
23219 */
23220- last = atomic64_read(&last_value);
23221+ last = atomic64_read_unchecked(&last_value);
23222 do {
23223 if (ret < last)
23224 return last;
23225- last = atomic64_cmpxchg(&last_value, last, ret);
23226+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
23227 } while (unlikely(last != ret));
23228
23229 return ret;
23230diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
23231index 76fa1e9..abf09ea 100644
23232--- a/arch/x86/kernel/reboot.c
23233+++ b/arch/x86/kernel/reboot.c
23234@@ -36,7 +36,7 @@ void (*pm_power_off)(void);
23235 EXPORT_SYMBOL(pm_power_off);
23236
23237 static const struct desc_ptr no_idt = {};
23238-static int reboot_mode;
23239+static unsigned short reboot_mode;
23240 enum reboot_type reboot_type = BOOT_ACPI;
23241 int reboot_force;
23242
23243@@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
23244
23245 void __noreturn machine_real_restart(unsigned int type)
23246 {
23247+
23248+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
23249+ struct desc_struct *gdt;
23250+#endif
23251+
23252 local_irq_disable();
23253
23254 /*
23255@@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
23256
23257 /* Jump to the identity-mapped low memory code */
23258 #ifdef CONFIG_X86_32
23259- asm volatile("jmpl *%0" : :
23260+
23261+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23262+ gdt = get_cpu_gdt_table(smp_processor_id());
23263+ pax_open_kernel();
23264+#ifdef CONFIG_PAX_MEMORY_UDEREF
23265+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
23266+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
23267+ loadsegment(ds, __KERNEL_DS);
23268+ loadsegment(es, __KERNEL_DS);
23269+ loadsegment(ss, __KERNEL_DS);
23270+#endif
23271+#ifdef CONFIG_PAX_KERNEXEC
23272+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
23273+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
23274+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
23275+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
23276+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
23277+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
23278+#endif
23279+ pax_close_kernel();
23280+#endif
23281+
23282+ asm volatile("ljmpl *%0" : :
23283 "rm" (real_mode_header->machine_real_restart_asm),
23284 "a" (type));
23285 #else
23286@@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
23287 * try to force a triple fault and then cycle between hitting the keyboard
23288 * controller and doing that
23289 */
23290-static void native_machine_emergency_restart(void)
23291+static void __noreturn native_machine_emergency_restart(void)
23292 {
23293 int i;
23294 int attempt = 0;
23295@@ -654,13 +681,13 @@ void native_machine_shutdown(void)
23296 #endif
23297 }
23298
23299-static void __machine_emergency_restart(int emergency)
23300+static void __noreturn __machine_emergency_restart(int emergency)
23301 {
23302 reboot_emergency = emergency;
23303 machine_ops.emergency_restart();
23304 }
23305
23306-static void native_machine_restart(char *__unused)
23307+static void __noreturn native_machine_restart(char *__unused)
23308 {
23309 pr_notice("machine restart\n");
23310
23311@@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
23312 __machine_emergency_restart(0);
23313 }
23314
23315-static void native_machine_halt(void)
23316+static void __noreturn native_machine_halt(void)
23317 {
23318 /* Stop other cpus and apics */
23319 machine_shutdown();
23320@@ -679,7 +706,7 @@ static void native_machine_halt(void)
23321 stop_this_cpu(NULL);
23322 }
23323
23324-static void native_machine_power_off(void)
23325+static void __noreturn native_machine_power_off(void)
23326 {
23327 if (pm_power_off) {
23328 if (!reboot_force)
23329@@ -688,9 +715,10 @@ static void native_machine_power_off(void)
23330 }
23331 /* A fallback in case there is no PM info available */
23332 tboot_shutdown(TB_SHUTDOWN_HALT);
23333+ unreachable();
23334 }
23335
23336-struct machine_ops machine_ops = {
23337+struct machine_ops machine_ops __read_only = {
23338 .power_off = native_machine_power_off,
23339 .shutdown = native_machine_shutdown,
23340 .emergency_restart = native_machine_emergency_restart,
23341diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
23342index 7a6f3b3..bed145d7 100644
23343--- a/arch/x86/kernel/relocate_kernel_64.S
23344+++ b/arch/x86/kernel/relocate_kernel_64.S
23345@@ -11,6 +11,7 @@
23346 #include <asm/kexec.h>
23347 #include <asm/processor-flags.h>
23348 #include <asm/pgtable_types.h>
23349+#include <asm/alternative-asm.h>
23350
23351 /*
23352 * Must be relocatable PIC code callable as a C function
23353@@ -160,13 +161,14 @@ identity_mapped:
23354 xorq %rbp, %rbp
23355 xorq %r8, %r8
23356 xorq %r9, %r9
23357- xorq %r10, %r9
23358+ xorq %r10, %r10
23359 xorq %r11, %r11
23360 xorq %r12, %r12
23361 xorq %r13, %r13
23362 xorq %r14, %r14
23363 xorq %r15, %r15
23364
23365+ pax_force_retaddr 0, 1
23366 ret
23367
23368 1:
23369diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
23370index 8b24289..d37b58b 100644
23371--- a/arch/x86/kernel/setup.c
23372+++ b/arch/x86/kernel/setup.c
23373@@ -437,7 +437,7 @@ static void __init parse_setup_data(void)
23374
23375 switch (data->type) {
23376 case SETUP_E820_EXT:
23377- parse_e820_ext(data);
23378+ parse_e820_ext((struct setup_data __force_kernel *)data);
23379 break;
23380 case SETUP_DTB:
23381 add_dtb(pa_data);
23382@@ -706,7 +706,7 @@ static void __init trim_bios_range(void)
23383 * area (640->1Mb) as ram even though it is not.
23384 * take them out.
23385 */
23386- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
23387+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
23388
23389 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
23390 }
23391@@ -830,14 +830,14 @@ void __init setup_arch(char **cmdline_p)
23392
23393 if (!boot_params.hdr.root_flags)
23394 root_mountflags &= ~MS_RDONLY;
23395- init_mm.start_code = (unsigned long) _text;
23396- init_mm.end_code = (unsigned long) _etext;
23397+ init_mm.start_code = ktla_ktva((unsigned long) _text);
23398+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
23399 init_mm.end_data = (unsigned long) _edata;
23400 init_mm.brk = _brk_end;
23401
23402- code_resource.start = virt_to_phys(_text);
23403- code_resource.end = virt_to_phys(_etext)-1;
23404- data_resource.start = virt_to_phys(_etext);
23405+ code_resource.start = virt_to_phys(ktla_ktva(_text));
23406+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
23407+ data_resource.start = virt_to_phys(_sdata);
23408 data_resource.end = virt_to_phys(_edata)-1;
23409 bss_resource.start = virt_to_phys(&__bss_start);
23410 bss_resource.end = virt_to_phys(&__bss_stop)-1;
23411diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
23412index 5cdff03..80fa283 100644
23413--- a/arch/x86/kernel/setup_percpu.c
23414+++ b/arch/x86/kernel/setup_percpu.c
23415@@ -21,19 +21,17 @@
23416 #include <asm/cpu.h>
23417 #include <asm/stackprotector.h>
23418
23419-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
23420+#ifdef CONFIG_SMP
23421+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
23422 EXPORT_PER_CPU_SYMBOL(cpu_number);
23423+#endif
23424
23425-#ifdef CONFIG_X86_64
23426 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
23427-#else
23428-#define BOOT_PERCPU_OFFSET 0
23429-#endif
23430
23431 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
23432 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
23433
23434-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
23435+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
23436 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
23437 };
23438 EXPORT_SYMBOL(__per_cpu_offset);
23439@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
23440 {
23441 #ifdef CONFIG_NEED_MULTIPLE_NODES
23442 pg_data_t *last = NULL;
23443- unsigned int cpu;
23444+ int cpu;
23445
23446 for_each_possible_cpu(cpu) {
23447 int node = early_cpu_to_node(cpu);
23448@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
23449 {
23450 #ifdef CONFIG_X86_32
23451 struct desc_struct gdt;
23452+ unsigned long base = per_cpu_offset(cpu);
23453
23454- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
23455- 0x2 | DESCTYPE_S, 0x8);
23456- gdt.s = 1;
23457+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
23458+ 0x83 | DESCTYPE_S, 0xC);
23459 write_gdt_entry(get_cpu_gdt_table(cpu),
23460 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
23461 #endif
23462@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
23463 /* alrighty, percpu areas up and running */
23464 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
23465 for_each_possible_cpu(cpu) {
23466+#ifdef CONFIG_CC_STACKPROTECTOR
23467+#ifdef CONFIG_X86_32
23468+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
23469+#endif
23470+#endif
23471 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
23472 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
23473 per_cpu(cpu_number, cpu) = cpu;
23474@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
23475 */
23476 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
23477 #endif
23478+#ifdef CONFIG_CC_STACKPROTECTOR
23479+#ifdef CONFIG_X86_32
23480+ if (!cpu)
23481+ per_cpu(stack_canary.canary, cpu) = canary;
23482+#endif
23483+#endif
23484 /*
23485 * Up to this point, the boot CPU has been using .init.data
23486 * area. Reload any changed state for the boot CPU.
23487diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
23488index d6bf1f3..3ffce5a 100644
23489--- a/arch/x86/kernel/signal.c
23490+++ b/arch/x86/kernel/signal.c
23491@@ -196,7 +196,7 @@ static unsigned long align_sigframe(unsigned long sp)
23492 * Align the stack pointer according to the i386 ABI,
23493 * i.e. so that on function entry ((sp + 4) & 15) == 0.
23494 */
23495- sp = ((sp + 4) & -16ul) - 4;
23496+ sp = ((sp - 12) & -16ul) - 4;
23497 #else /* !CONFIG_X86_32 */
23498 sp = round_down(sp, 16) - 8;
23499 #endif
23500@@ -304,9 +304,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
23501 }
23502
23503 if (current->mm->context.vdso)
23504- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
23505+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
23506 else
23507- restorer = &frame->retcode;
23508+ restorer = (void __user *)&frame->retcode;
23509 if (ka->sa.sa_flags & SA_RESTORER)
23510 restorer = ka->sa.sa_restorer;
23511
23512@@ -320,7 +320,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
23513 * reasons and because gdb uses it as a signature to notice
23514 * signal handler stack frames.
23515 */
23516- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
23517+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
23518
23519 if (err)
23520 return -EFAULT;
23521@@ -367,7 +367,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
23522 err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
23523
23524 /* Set up to return from userspace. */
23525- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
23526+ if (current->mm->context.vdso)
23527+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
23528+ else
23529+ restorer = (void __user *)&frame->retcode;
23530 if (ka->sa.sa_flags & SA_RESTORER)
23531 restorer = ka->sa.sa_restorer;
23532 put_user_ex(restorer, &frame->pretcode);
23533@@ -379,7 +382,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
23534 * reasons and because gdb uses it as a signature to notice
23535 * signal handler stack frames.
23536 */
23537- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
23538+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
23539 } put_user_catch(err);
23540
23541 err |= copy_siginfo_to_user(&frame->info, info);
23542diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
23543index 48d2b7d..90d328a 100644
23544--- a/arch/x86/kernel/smp.c
23545+++ b/arch/x86/kernel/smp.c
23546@@ -285,7 +285,7 @@ static int __init nonmi_ipi_setup(char *str)
23547
23548 __setup("nonmi_ipi", nonmi_ipi_setup);
23549
23550-struct smp_ops smp_ops = {
23551+struct smp_ops smp_ops __read_only = {
23552 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
23553 .smp_prepare_cpus = native_smp_prepare_cpus,
23554 .smp_cpus_done = native_smp_cpus_done,
23555diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
23556index ed0fe38..87fc692 100644
23557--- a/arch/x86/kernel/smpboot.c
23558+++ b/arch/x86/kernel/smpboot.c
23559@@ -748,6 +748,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
23560 idle->thread.sp = (unsigned long) (((struct pt_regs *)
23561 (THREAD_SIZE + task_stack_page(idle))) - 1);
23562 per_cpu(current_task, cpu) = idle;
23563+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
23564
23565 #ifdef CONFIG_X86_32
23566 /* Stack for startup_32 can be just as for start_secondary onwards */
23567@@ -755,11 +756,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
23568 #else
23569 clear_tsk_thread_flag(idle, TIF_FORK);
23570 initial_gs = per_cpu_offset(cpu);
23571- per_cpu(kernel_stack, cpu) =
23572- (unsigned long)task_stack_page(idle) -
23573- KERNEL_STACK_OFFSET + THREAD_SIZE;
23574+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
23575 #endif
23576+
23577+ pax_open_kernel();
23578 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
23579+ pax_close_kernel();
23580+
23581 initial_code = (unsigned long)start_secondary;
23582 stack_start = idle->thread.sp;
23583
23584@@ -908,6 +911,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
23585 /* the FPU context is blank, nobody can own it */
23586 __cpu_disable_lazy_restore(cpu);
23587
23588+#ifdef CONFIG_PAX_PER_CPU_PGD
23589+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
23590+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
23591+ KERNEL_PGD_PTRS);
23592+#endif
23593+
23594+ /* the FPU context is blank, nobody can own it */
23595+ __cpu_disable_lazy_restore(cpu);
23596+
23597 err = do_boot_cpu(apicid, cpu, tidle);
23598 if (err) {
23599 pr_debug("do_boot_cpu failed %d\n", err);
23600diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
23601index 9b4d51d..5d28b58 100644
23602--- a/arch/x86/kernel/step.c
23603+++ b/arch/x86/kernel/step.c
23604@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
23605 struct desc_struct *desc;
23606 unsigned long base;
23607
23608- seg &= ~7UL;
23609+ seg >>= 3;
23610
23611 mutex_lock(&child->mm->context.lock);
23612- if (unlikely((seg >> 3) >= child->mm->context.size))
23613+ if (unlikely(seg >= child->mm->context.size))
23614 addr = -1L; /* bogus selector, access would fault */
23615 else {
23616 desc = child->mm->context.ldt + seg;
23617@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
23618 addr += base;
23619 }
23620 mutex_unlock(&child->mm->context.lock);
23621- }
23622+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
23623+ addr = ktla_ktva(addr);
23624
23625 return addr;
23626 }
23627@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
23628 unsigned char opcode[15];
23629 unsigned long addr = convert_ip_to_linear(child, regs);
23630
23631+ if (addr == -EINVAL)
23632+ return 0;
23633+
23634 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
23635 for (i = 0; i < copied; i++) {
23636 switch (opcode[i]) {
23637diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
23638new file mode 100644
23639index 0000000..207bec6
23640--- /dev/null
23641+++ b/arch/x86/kernel/sys_i386_32.c
23642@@ -0,0 +1,250 @@
23643+/*
23644+ * This file contains various random system calls that
23645+ * have a non-standard calling sequence on the Linux/i386
23646+ * platform.
23647+ */
23648+
23649+#include <linux/errno.h>
23650+#include <linux/sched.h>
23651+#include <linux/mm.h>
23652+#include <linux/fs.h>
23653+#include <linux/smp.h>
23654+#include <linux/sem.h>
23655+#include <linux/msg.h>
23656+#include <linux/shm.h>
23657+#include <linux/stat.h>
23658+#include <linux/syscalls.h>
23659+#include <linux/mman.h>
23660+#include <linux/file.h>
23661+#include <linux/utsname.h>
23662+#include <linux/ipc.h>
23663+
23664+#include <linux/uaccess.h>
23665+#include <linux/unistd.h>
23666+
23667+#include <asm/syscalls.h>
23668+
23669+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
23670+{
23671+ unsigned long pax_task_size = TASK_SIZE;
23672+
23673+#ifdef CONFIG_PAX_SEGMEXEC
23674+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
23675+ pax_task_size = SEGMEXEC_TASK_SIZE;
23676+#endif
23677+
23678+ if (flags & MAP_FIXED)
23679+ if (len > pax_task_size || addr > pax_task_size - len)
23680+ return -EINVAL;
23681+
23682+ return 0;
23683+}
23684+
23685+unsigned long
23686+arch_get_unmapped_area(struct file *filp, unsigned long addr,
23687+ unsigned long len, unsigned long pgoff, unsigned long flags)
23688+{
23689+ struct mm_struct *mm = current->mm;
23690+ struct vm_area_struct *vma;
23691+ unsigned long start_addr, pax_task_size = TASK_SIZE;
23692+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
23693+
23694+#ifdef CONFIG_PAX_SEGMEXEC
23695+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
23696+ pax_task_size = SEGMEXEC_TASK_SIZE;
23697+#endif
23698+
23699+ pax_task_size -= PAGE_SIZE;
23700+
23701+ if (len > pax_task_size)
23702+ return -ENOMEM;
23703+
23704+ if (flags & MAP_FIXED)
23705+ return addr;
23706+
23707+#ifdef CONFIG_PAX_RANDMMAP
23708+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23709+#endif
23710+
23711+ if (addr) {
23712+ addr = PAGE_ALIGN(addr);
23713+ if (pax_task_size - len >= addr) {
23714+ vma = find_vma(mm, addr);
23715+ if (check_heap_stack_gap(vma, addr, len, offset))
23716+ return addr;
23717+ }
23718+ }
23719+ if (len > mm->cached_hole_size) {
23720+ start_addr = addr = mm->free_area_cache;
23721+ } else {
23722+ start_addr = addr = mm->mmap_base;
23723+ mm->cached_hole_size = 0;
23724+ }
23725+
23726+#ifdef CONFIG_PAX_PAGEEXEC
23727+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
23728+ start_addr = 0x00110000UL;
23729+
23730+#ifdef CONFIG_PAX_RANDMMAP
23731+ if (mm->pax_flags & MF_PAX_RANDMMAP)
23732+ start_addr += mm->delta_mmap & 0x03FFF000UL;
23733+#endif
23734+
23735+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
23736+ start_addr = addr = mm->mmap_base;
23737+ else
23738+ addr = start_addr;
23739+ }
23740+#endif
23741+
23742+full_search:
23743+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
23744+ /* At this point: (!vma || addr < vma->vm_end). */
23745+ if (pax_task_size - len < addr) {
23746+ /*
23747+ * Start a new search - just in case we missed
23748+ * some holes.
23749+ */
23750+ if (start_addr != mm->mmap_base) {
23751+ start_addr = addr = mm->mmap_base;
23752+ mm->cached_hole_size = 0;
23753+ goto full_search;
23754+ }
23755+ return -ENOMEM;
23756+ }
23757+ if (check_heap_stack_gap(vma, addr, len, offset))
23758+ break;
23759+ if (addr + mm->cached_hole_size < vma->vm_start)
23760+ mm->cached_hole_size = vma->vm_start - addr;
23761+ addr = vma->vm_end;
23762+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
23763+ start_addr = addr = mm->mmap_base;
23764+ mm->cached_hole_size = 0;
23765+ goto full_search;
23766+ }
23767+ }
23768+
23769+ /*
23770+ * Remember the place where we stopped the search:
23771+ */
23772+ mm->free_area_cache = addr + len;
23773+ return addr;
23774+}
23775+
23776+unsigned long
23777+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
23778+ const unsigned long len, const unsigned long pgoff,
23779+ const unsigned long flags)
23780+{
23781+ struct vm_area_struct *vma;
23782+ struct mm_struct *mm = current->mm;
23783+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
23784+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
23785+
23786+#ifdef CONFIG_PAX_SEGMEXEC
23787+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
23788+ pax_task_size = SEGMEXEC_TASK_SIZE;
23789+#endif
23790+
23791+ pax_task_size -= PAGE_SIZE;
23792+
23793+ /* requested length too big for entire address space */
23794+ if (len > pax_task_size)
23795+ return -ENOMEM;
23796+
23797+ if (flags & MAP_FIXED)
23798+ return addr;
23799+
23800+#ifdef CONFIG_PAX_PAGEEXEC
23801+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
23802+ goto bottomup;
23803+#endif
23804+
23805+#ifdef CONFIG_PAX_RANDMMAP
23806+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23807+#endif
23808+
23809+ /* requesting a specific address */
23810+ if (addr) {
23811+ addr = PAGE_ALIGN(addr);
23812+ if (pax_task_size - len >= addr) {
23813+ vma = find_vma(mm, addr);
23814+ if (check_heap_stack_gap(vma, addr, len, offset))
23815+ return addr;
23816+ }
23817+ }
23818+
23819+ /* check if free_area_cache is useful for us */
23820+ if (len <= mm->cached_hole_size) {
23821+ mm->cached_hole_size = 0;
23822+ mm->free_area_cache = mm->mmap_base;
23823+ }
23824+
23825+ /* either no address requested or can't fit in requested address hole */
23826+ addr = mm->free_area_cache;
23827+
23828+ /* make sure it can fit in the remaining address space */
23829+ if (addr > len) {
23830+ vma = find_vma(mm, addr-len);
23831+ if (check_heap_stack_gap(vma, addr - len, len, offset))
23832+ /* remember the address as a hint for next time */
23833+ return (mm->free_area_cache = addr-len);
23834+ }
23835+
23836+ if (mm->mmap_base < len)
23837+ goto bottomup;
23838+
23839+ addr = mm->mmap_base-len;
23840+
23841+ do {
23842+ /*
23843+ * Lookup failure means no vma is above this address,
23844+ * else if new region fits below vma->vm_start,
23845+ * return with success:
23846+ */
23847+ vma = find_vma(mm, addr);
23848+ if (check_heap_stack_gap(vma, addr, len, offset))
23849+ /* remember the address as a hint for next time */
23850+ return (mm->free_area_cache = addr);
23851+
23852+ /* remember the largest hole we saw so far */
23853+ if (addr + mm->cached_hole_size < vma->vm_start)
23854+ mm->cached_hole_size = vma->vm_start - addr;
23855+
23856+ /* try just below the current vma->vm_start */
23857+ addr = skip_heap_stack_gap(vma, len, offset);
23858+ } while (!IS_ERR_VALUE(addr));
23859+
23860+bottomup:
23861+ /*
23862+ * A failed mmap() very likely causes application failure,
23863+ * so fall back to the bottom-up function here. This scenario
23864+ * can happen with large stack limits and large mmap()
23865+ * allocations.
23866+ */
23867+
23868+#ifdef CONFIG_PAX_SEGMEXEC
23869+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
23870+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
23871+ else
23872+#endif
23873+
23874+ mm->mmap_base = TASK_UNMAPPED_BASE;
23875+
23876+#ifdef CONFIG_PAX_RANDMMAP
23877+ if (mm->pax_flags & MF_PAX_RANDMMAP)
23878+ mm->mmap_base += mm->delta_mmap;
23879+#endif
23880+
23881+ mm->free_area_cache = mm->mmap_base;
23882+ mm->cached_hole_size = ~0UL;
23883+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
23884+ /*
23885+ * Restore the topdown base:
23886+ */
23887+ mm->mmap_base = base;
23888+ mm->free_area_cache = base;
23889+ mm->cached_hole_size = ~0UL;
23890+
23891+ return addr;
23892+}
23893diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
23894index 97ef74b..57a1882 100644
23895--- a/arch/x86/kernel/sys_x86_64.c
23896+++ b/arch/x86/kernel/sys_x86_64.c
23897@@ -81,8 +81,8 @@ out:
23898 return error;
23899 }
23900
23901-static void find_start_end(unsigned long flags, unsigned long *begin,
23902- unsigned long *end)
23903+static void find_start_end(struct mm_struct *mm, unsigned long flags,
23904+ unsigned long *begin, unsigned long *end)
23905 {
23906 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
23907 unsigned long new_begin;
23908@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
23909 *begin = new_begin;
23910 }
23911 } else {
23912- *begin = TASK_UNMAPPED_BASE;
23913+ *begin = mm->mmap_base;
23914 *end = TASK_SIZE;
23915 }
23916 }
23917@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
23918 struct vm_area_struct *vma;
23919 struct vm_unmapped_area_info info;
23920 unsigned long begin, end;
23921+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
23922
23923 if (flags & MAP_FIXED)
23924 return addr;
23925
23926- find_start_end(flags, &begin, &end);
23927+ find_start_end(mm, flags, &begin, &end);
23928
23929 if (len > end)
23930 return -ENOMEM;
23931
23932+#ifdef CONFIG_PAX_RANDMMAP
23933+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23934+#endif
23935+
23936 if (addr) {
23937 addr = PAGE_ALIGN(addr);
23938 vma = find_vma(mm, addr);
23939- if (end - len >= addr &&
23940- (!vma || addr + len <= vma->vm_start))
23941+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
23942 return addr;
23943 }
23944
23945@@ -161,6 +165,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
23946 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
23947 goto bottomup;
23948
23949+#ifdef CONFIG_PAX_RANDMMAP
23950+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23951+#endif
23952+
23953 /* requesting a specific address */
23954 if (addr) {
23955 addr = PAGE_ALIGN(addr);
23956diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
23957index f84fe00..f41d9f1 100644
23958--- a/arch/x86/kernel/tboot.c
23959+++ b/arch/x86/kernel/tboot.c
23960@@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
23961
23962 void tboot_shutdown(u32 shutdown_type)
23963 {
23964- void (*shutdown)(void);
23965+ void (* __noreturn shutdown)(void);
23966
23967 if (!tboot_enabled())
23968 return;
23969@@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
23970
23971 switch_to_tboot_pt();
23972
23973- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
23974+ shutdown = (void *)tboot->shutdown_entry;
23975 shutdown();
23976
23977 /* should not reach here */
23978@@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
23979 return 0;
23980 }
23981
23982-static atomic_t ap_wfs_count;
23983+static atomic_unchecked_t ap_wfs_count;
23984
23985 static int tboot_wait_for_aps(int num_aps)
23986 {
23987@@ -324,16 +324,16 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
23988 {
23989 switch (action) {
23990 case CPU_DYING:
23991- atomic_inc(&ap_wfs_count);
23992+ atomic_inc_unchecked(&ap_wfs_count);
23993 if (num_online_cpus() == 1)
23994- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
23995+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
23996 return NOTIFY_BAD;
23997 break;
23998 }
23999 return NOTIFY_OK;
24000 }
24001
24002-static struct notifier_block tboot_cpu_notifier __cpuinitdata =
24003+static struct notifier_block tboot_cpu_notifier =
24004 {
24005 .notifier_call = tboot_cpu_callback,
24006 };
24007@@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
24008
24009 tboot_create_trampoline();
24010
24011- atomic_set(&ap_wfs_count, 0);
24012+ atomic_set_unchecked(&ap_wfs_count, 0);
24013 register_hotcpu_notifier(&tboot_cpu_notifier);
24014
24015 acpi_os_set_prepare_sleep(&tboot_sleep);
24016diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
24017index 24d3c91..d06b473 100644
24018--- a/arch/x86/kernel/time.c
24019+++ b/arch/x86/kernel/time.c
24020@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
24021 {
24022 unsigned long pc = instruction_pointer(regs);
24023
24024- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
24025+ if (!user_mode(regs) && in_lock_functions(pc)) {
24026 #ifdef CONFIG_FRAME_POINTER
24027- return *(unsigned long *)(regs->bp + sizeof(long));
24028+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
24029 #else
24030 unsigned long *sp =
24031 (unsigned long *)kernel_stack_pointer(regs);
24032@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
24033 * or above a saved flags. Eflags has bits 22-31 zero,
24034 * kernel addresses don't.
24035 */
24036+
24037+#ifdef CONFIG_PAX_KERNEXEC
24038+ return ktla_ktva(sp[0]);
24039+#else
24040 if (sp[0] >> 22)
24041 return sp[0];
24042 if (sp[1] >> 22)
24043 return sp[1];
24044 #endif
24045+
24046+#endif
24047 }
24048 return pc;
24049 }
24050diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
24051index 9d9d2f9..cad418a 100644
24052--- a/arch/x86/kernel/tls.c
24053+++ b/arch/x86/kernel/tls.c
24054@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
24055 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
24056 return -EINVAL;
24057
24058+#ifdef CONFIG_PAX_SEGMEXEC
24059+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
24060+ return -EINVAL;
24061+#endif
24062+
24063 set_tls_desc(p, idx, &info, 1);
24064
24065 return 0;
24066@@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
24067
24068 if (kbuf)
24069 info = kbuf;
24070- else if (__copy_from_user(infobuf, ubuf, count))
24071+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
24072 return -EFAULT;
24073 else
24074 info = infobuf;
24075diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
24076index ecffca1..95c4d13 100644
24077--- a/arch/x86/kernel/traps.c
24078+++ b/arch/x86/kernel/traps.c
24079@@ -68,12 +68,6 @@
24080 #include <asm/setup.h>
24081
24082 asmlinkage int system_call(void);
24083-
24084-/*
24085- * The IDT has to be page-aligned to simplify the Pentium
24086- * F0 0F bug workaround.
24087- */
24088-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
24089 #endif
24090
24091 DECLARE_BITMAP(used_vectors, NR_VECTORS);
24092@@ -106,11 +100,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
24093 }
24094
24095 static int __kprobes
24096-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
24097+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
24098 struct pt_regs *regs, long error_code)
24099 {
24100 #ifdef CONFIG_X86_32
24101- if (regs->flags & X86_VM_MASK) {
24102+ if (v8086_mode(regs)) {
24103 /*
24104 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
24105 * On nmi (interrupt 2), do_trap should not be called.
24106@@ -123,12 +117,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
24107 return -1;
24108 }
24109 #endif
24110- if (!user_mode(regs)) {
24111+ if (!user_mode_novm(regs)) {
24112 if (!fixup_exception(regs)) {
24113 tsk->thread.error_code = error_code;
24114 tsk->thread.trap_nr = trapnr;
24115+
24116+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24117+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
24118+ str = "PAX: suspicious stack segment fault";
24119+#endif
24120+
24121 die(str, regs, error_code);
24122 }
24123+
24124+#ifdef CONFIG_PAX_REFCOUNT
24125+ if (trapnr == 4)
24126+ pax_report_refcount_overflow(regs);
24127+#endif
24128+
24129 return 0;
24130 }
24131
24132@@ -136,7 +142,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
24133 }
24134
24135 static void __kprobes
24136-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
24137+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
24138 long error_code, siginfo_t *info)
24139 {
24140 struct task_struct *tsk = current;
24141@@ -160,7 +166,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
24142 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
24143 printk_ratelimit()) {
24144 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
24145- tsk->comm, tsk->pid, str,
24146+ tsk->comm, task_pid_nr(tsk), str,
24147 regs->ip, regs->sp, error_code);
24148 print_vma_addr(" in ", regs->ip);
24149 pr_cont("\n");
24150@@ -266,7 +272,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
24151 conditional_sti(regs);
24152
24153 #ifdef CONFIG_X86_32
24154- if (regs->flags & X86_VM_MASK) {
24155+ if (v8086_mode(regs)) {
24156 local_irq_enable();
24157 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
24158 goto exit;
24159@@ -274,18 +280,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
24160 #endif
24161
24162 tsk = current;
24163- if (!user_mode(regs)) {
24164+ if (!user_mode_novm(regs)) {
24165 if (fixup_exception(regs))
24166 goto exit;
24167
24168 tsk->thread.error_code = error_code;
24169 tsk->thread.trap_nr = X86_TRAP_GP;
24170 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
24171- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
24172+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
24173+
24174+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24175+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
24176+ die("PAX: suspicious general protection fault", regs, error_code);
24177+ else
24178+#endif
24179+
24180 die("general protection fault", regs, error_code);
24181+ }
24182 goto exit;
24183 }
24184
24185+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
24186+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
24187+ struct mm_struct *mm = tsk->mm;
24188+ unsigned long limit;
24189+
24190+ down_write(&mm->mmap_sem);
24191+ limit = mm->context.user_cs_limit;
24192+ if (limit < TASK_SIZE) {
24193+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
24194+ up_write(&mm->mmap_sem);
24195+ return;
24196+ }
24197+ up_write(&mm->mmap_sem);
24198+ }
24199+#endif
24200+
24201 tsk->thread.error_code = error_code;
24202 tsk->thread.trap_nr = X86_TRAP_GP;
24203
24204@@ -440,7 +470,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
24205 /* It's safe to allow irq's after DR6 has been saved */
24206 preempt_conditional_sti(regs);
24207
24208- if (regs->flags & X86_VM_MASK) {
24209+ if (v8086_mode(regs)) {
24210 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
24211 X86_TRAP_DB);
24212 preempt_conditional_cli(regs);
24213@@ -455,7 +485,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
24214 * We already checked v86 mode above, so we can check for kernel mode
24215 * by just checking the CPL of CS.
24216 */
24217- if ((dr6 & DR_STEP) && !user_mode(regs)) {
24218+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
24219 tsk->thread.debugreg6 &= ~DR_STEP;
24220 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
24221 regs->flags &= ~X86_EFLAGS_TF;
24222@@ -487,7 +517,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
24223 return;
24224 conditional_sti(regs);
24225
24226- if (!user_mode_vm(regs))
24227+ if (!user_mode(regs))
24228 {
24229 if (!fixup_exception(regs)) {
24230 task->thread.error_code = error_code;
24231diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
24232index c71025b..b117501 100644
24233--- a/arch/x86/kernel/uprobes.c
24234+++ b/arch/x86/kernel/uprobes.c
24235@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
24236 int ret = NOTIFY_DONE;
24237
24238 /* We are only interested in userspace traps */
24239- if (regs && !user_mode_vm(regs))
24240+ if (regs && !user_mode(regs))
24241 return NOTIFY_DONE;
24242
24243 switch (val) {
24244diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
24245index b9242ba..50c5edd 100644
24246--- a/arch/x86/kernel/verify_cpu.S
24247+++ b/arch/x86/kernel/verify_cpu.S
24248@@ -20,6 +20,7 @@
24249 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
24250 * arch/x86/kernel/trampoline_64.S: secondary processor verification
24251 * arch/x86/kernel/head_32.S: processor startup
24252+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
24253 *
24254 * verify_cpu, returns the status of longmode and SSE in register %eax.
24255 * 0: Success 1: Failure
24256diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
24257index 1dfe69c..a3df6f6 100644
24258--- a/arch/x86/kernel/vm86_32.c
24259+++ b/arch/x86/kernel/vm86_32.c
24260@@ -43,6 +43,7 @@
24261 #include <linux/ptrace.h>
24262 #include <linux/audit.h>
24263 #include <linux/stddef.h>
24264+#include <linux/grsecurity.h>
24265
24266 #include <asm/uaccess.h>
24267 #include <asm/io.h>
24268@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
24269 do_exit(SIGSEGV);
24270 }
24271
24272- tss = &per_cpu(init_tss, get_cpu());
24273+ tss = init_tss + get_cpu();
24274 current->thread.sp0 = current->thread.saved_sp0;
24275 current->thread.sysenter_cs = __KERNEL_CS;
24276 load_sp0(tss, &current->thread);
24277@@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
24278 struct task_struct *tsk;
24279 int tmp, ret = -EPERM;
24280
24281+#ifdef CONFIG_GRKERNSEC_VM86
24282+ if (!capable(CAP_SYS_RAWIO)) {
24283+ gr_handle_vm86();
24284+ goto out;
24285+ }
24286+#endif
24287+
24288 tsk = current;
24289 if (tsk->thread.saved_sp0)
24290 goto out;
24291@@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
24292 int tmp, ret;
24293 struct vm86plus_struct __user *v86;
24294
24295+#ifdef CONFIG_GRKERNSEC_VM86
24296+ if (!capable(CAP_SYS_RAWIO)) {
24297+ gr_handle_vm86();
24298+ ret = -EPERM;
24299+ goto out;
24300+ }
24301+#endif
24302+
24303 tsk = current;
24304 switch (cmd) {
24305 case VM86_REQUEST_IRQ:
24306@@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
24307 tsk->thread.saved_fs = info->regs32->fs;
24308 tsk->thread.saved_gs = get_user_gs(info->regs32);
24309
24310- tss = &per_cpu(init_tss, get_cpu());
24311+ tss = init_tss + get_cpu();
24312 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
24313 if (cpu_has_sep)
24314 tsk->thread.sysenter_cs = 0;
24315@@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
24316 goto cannot_handle;
24317 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
24318 goto cannot_handle;
24319- intr_ptr = (unsigned long __user *) (i << 2);
24320+ intr_ptr = (__force unsigned long __user *) (i << 2);
24321 if (get_user(segoffs, intr_ptr))
24322 goto cannot_handle;
24323 if ((segoffs >> 16) == BIOSSEG)
24324diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
24325index 22a1530..8fbaaad 100644
24326--- a/arch/x86/kernel/vmlinux.lds.S
24327+++ b/arch/x86/kernel/vmlinux.lds.S
24328@@ -26,6 +26,13 @@
24329 #include <asm/page_types.h>
24330 #include <asm/cache.h>
24331 #include <asm/boot.h>
24332+#include <asm/segment.h>
24333+
24334+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24335+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
24336+#else
24337+#define __KERNEL_TEXT_OFFSET 0
24338+#endif
24339
24340 #undef i386 /* in case the preprocessor is a 32bit one */
24341
24342@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
24343
24344 PHDRS {
24345 text PT_LOAD FLAGS(5); /* R_E */
24346+#ifdef CONFIG_X86_32
24347+ module PT_LOAD FLAGS(5); /* R_E */
24348+#endif
24349+#ifdef CONFIG_XEN
24350+ rodata PT_LOAD FLAGS(5); /* R_E */
24351+#else
24352+ rodata PT_LOAD FLAGS(4); /* R__ */
24353+#endif
24354 data PT_LOAD FLAGS(6); /* RW_ */
24355-#ifdef CONFIG_X86_64
24356+ init.begin PT_LOAD FLAGS(6); /* RW_ */
24357 #ifdef CONFIG_SMP
24358 percpu PT_LOAD FLAGS(6); /* RW_ */
24359 #endif
24360+ text.init PT_LOAD FLAGS(5); /* R_E */
24361+ text.exit PT_LOAD FLAGS(5); /* R_E */
24362 init PT_LOAD FLAGS(7); /* RWE */
24363-#endif
24364 note PT_NOTE FLAGS(0); /* ___ */
24365 }
24366
24367 SECTIONS
24368 {
24369 #ifdef CONFIG_X86_32
24370- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
24371- phys_startup_32 = startup_32 - LOAD_OFFSET;
24372+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
24373 #else
24374- . = __START_KERNEL;
24375- phys_startup_64 = startup_64 - LOAD_OFFSET;
24376+ . = __START_KERNEL;
24377 #endif
24378
24379 /* Text and read-only data */
24380- .text : AT(ADDR(.text) - LOAD_OFFSET) {
24381- _text = .;
24382+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
24383 /* bootstrapping code */
24384+#ifdef CONFIG_X86_32
24385+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
24386+#else
24387+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
24388+#endif
24389+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
24390+ _text = .;
24391 HEAD_TEXT
24392 #ifdef CONFIG_X86_32
24393 . = ALIGN(PAGE_SIZE);
24394@@ -108,13 +128,48 @@ SECTIONS
24395 IRQENTRY_TEXT
24396 *(.fixup)
24397 *(.gnu.warning)
24398- /* End of text section */
24399- _etext = .;
24400 } :text = 0x9090
24401
24402- NOTES :text :note
24403+ . += __KERNEL_TEXT_OFFSET;
24404
24405- EXCEPTION_TABLE(16) :text = 0x9090
24406+#ifdef CONFIG_X86_32
24407+ . = ALIGN(PAGE_SIZE);
24408+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
24409+
24410+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
24411+ MODULES_EXEC_VADDR = .;
24412+ BYTE(0)
24413+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
24414+ . = ALIGN(HPAGE_SIZE) - 1;
24415+ MODULES_EXEC_END = .;
24416+#endif
24417+
24418+ } :module
24419+#endif
24420+
24421+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
24422+ /* End of text section */
24423+ BYTE(0)
24424+ _etext = . - __KERNEL_TEXT_OFFSET;
24425+ }
24426+
24427+#ifdef CONFIG_X86_32
24428+ . = ALIGN(PAGE_SIZE);
24429+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
24430+ *(.idt)
24431+ . = ALIGN(PAGE_SIZE);
24432+ *(.empty_zero_page)
24433+ *(.initial_pg_fixmap)
24434+ *(.initial_pg_pmd)
24435+ *(.initial_page_table)
24436+ *(.swapper_pg_dir)
24437+ } :rodata
24438+#endif
24439+
24440+ . = ALIGN(PAGE_SIZE);
24441+ NOTES :rodata :note
24442+
24443+ EXCEPTION_TABLE(16) :rodata
24444
24445 #if defined(CONFIG_DEBUG_RODATA)
24446 /* .text should occupy whole number of pages */
24447@@ -126,16 +181,20 @@ SECTIONS
24448
24449 /* Data */
24450 .data : AT(ADDR(.data) - LOAD_OFFSET) {
24451+
24452+#ifdef CONFIG_PAX_KERNEXEC
24453+ . = ALIGN(HPAGE_SIZE);
24454+#else
24455+ . = ALIGN(PAGE_SIZE);
24456+#endif
24457+
24458 /* Start of data section */
24459 _sdata = .;
24460
24461 /* init_task */
24462 INIT_TASK_DATA(THREAD_SIZE)
24463
24464-#ifdef CONFIG_X86_32
24465- /* 32 bit has nosave before _edata */
24466 NOSAVE_DATA
24467-#endif
24468
24469 PAGE_ALIGNED_DATA(PAGE_SIZE)
24470
24471@@ -176,12 +235,19 @@ SECTIONS
24472 #endif /* CONFIG_X86_64 */
24473
24474 /* Init code and data - will be freed after init */
24475- . = ALIGN(PAGE_SIZE);
24476 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
24477+ BYTE(0)
24478+
24479+#ifdef CONFIG_PAX_KERNEXEC
24480+ . = ALIGN(HPAGE_SIZE);
24481+#else
24482+ . = ALIGN(PAGE_SIZE);
24483+#endif
24484+
24485 __init_begin = .; /* paired with __init_end */
24486- }
24487+ } :init.begin
24488
24489-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
24490+#ifdef CONFIG_SMP
24491 /*
24492 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
24493 * output PHDR, so the next output section - .init.text - should
24494@@ -190,12 +256,27 @@ SECTIONS
24495 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
24496 #endif
24497
24498- INIT_TEXT_SECTION(PAGE_SIZE)
24499-#ifdef CONFIG_X86_64
24500- :init
24501-#endif
24502+ . = ALIGN(PAGE_SIZE);
24503+ init_begin = .;
24504+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
24505+ VMLINUX_SYMBOL(_sinittext) = .;
24506+ INIT_TEXT
24507+ VMLINUX_SYMBOL(_einittext) = .;
24508+ . = ALIGN(PAGE_SIZE);
24509+ } :text.init
24510
24511- INIT_DATA_SECTION(16)
24512+ /*
24513+ * .exit.text is discard at runtime, not link time, to deal with
24514+ * references from .altinstructions and .eh_frame
24515+ */
24516+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
24517+ EXIT_TEXT
24518+ . = ALIGN(16);
24519+ } :text.exit
24520+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
24521+
24522+ . = ALIGN(PAGE_SIZE);
24523+ INIT_DATA_SECTION(16) :init
24524
24525 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
24526 __x86_cpu_dev_start = .;
24527@@ -257,19 +338,12 @@ SECTIONS
24528 }
24529
24530 . = ALIGN(8);
24531- /*
24532- * .exit.text is discard at runtime, not link time, to deal with
24533- * references from .altinstructions and .eh_frame
24534- */
24535- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
24536- EXIT_TEXT
24537- }
24538
24539 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
24540 EXIT_DATA
24541 }
24542
24543-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
24544+#ifndef CONFIG_SMP
24545 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
24546 #endif
24547
24548@@ -288,16 +362,10 @@ SECTIONS
24549 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
24550 __smp_locks = .;
24551 *(.smp_locks)
24552- . = ALIGN(PAGE_SIZE);
24553 __smp_locks_end = .;
24554+ . = ALIGN(PAGE_SIZE);
24555 }
24556
24557-#ifdef CONFIG_X86_64
24558- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
24559- NOSAVE_DATA
24560- }
24561-#endif
24562-
24563 /* BSS */
24564 . = ALIGN(PAGE_SIZE);
24565 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
24566@@ -313,6 +381,7 @@ SECTIONS
24567 __brk_base = .;
24568 . += 64 * 1024; /* 64k alignment slop space */
24569 *(.brk_reservation) /* areas brk users have reserved */
24570+ . = ALIGN(HPAGE_SIZE);
24571 __brk_limit = .;
24572 }
24573
24574@@ -339,13 +408,12 @@ SECTIONS
24575 * for the boot processor.
24576 */
24577 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
24578-INIT_PER_CPU(gdt_page);
24579 INIT_PER_CPU(irq_stack_union);
24580
24581 /*
24582 * Build-time check on the image size:
24583 */
24584-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
24585+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
24586 "kernel image bigger than KERNEL_IMAGE_SIZE");
24587
24588 #ifdef CONFIG_SMP
24589diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
24590index 9a907a6..f83f921 100644
24591--- a/arch/x86/kernel/vsyscall_64.c
24592+++ b/arch/x86/kernel/vsyscall_64.c
24593@@ -56,15 +56,13 @@
24594 DEFINE_VVAR(int, vgetcpu_mode);
24595 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
24596
24597-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
24598+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
24599
24600 static int __init vsyscall_setup(char *str)
24601 {
24602 if (str) {
24603 if (!strcmp("emulate", str))
24604 vsyscall_mode = EMULATE;
24605- else if (!strcmp("native", str))
24606- vsyscall_mode = NATIVE;
24607 else if (!strcmp("none", str))
24608 vsyscall_mode = NONE;
24609 else
24610@@ -323,8 +321,7 @@ do_ret:
24611 return true;
24612
24613 sigsegv:
24614- force_sig(SIGSEGV, current);
24615- return true;
24616+ do_group_exit(SIGKILL);
24617 }
24618
24619 /*
24620@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
24621 extern char __vvar_page;
24622 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
24623
24624- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
24625- vsyscall_mode == NATIVE
24626- ? PAGE_KERNEL_VSYSCALL
24627- : PAGE_KERNEL_VVAR);
24628+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
24629 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
24630 (unsigned long)VSYSCALL_START);
24631
24632diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
24633index 1330dd1..d220b99 100644
24634--- a/arch/x86/kernel/x8664_ksyms_64.c
24635+++ b/arch/x86/kernel/x8664_ksyms_64.c
24636@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
24637 EXPORT_SYMBOL(copy_user_generic_unrolled);
24638 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
24639 EXPORT_SYMBOL(__copy_user_nocache);
24640-EXPORT_SYMBOL(_copy_from_user);
24641-EXPORT_SYMBOL(_copy_to_user);
24642
24643 EXPORT_SYMBOL(copy_page);
24644 EXPORT_SYMBOL(clear_page);
24645diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
24646index 7a3d075..6cb373d 100644
24647--- a/arch/x86/kernel/x86_init.c
24648+++ b/arch/x86/kernel/x86_init.c
24649@@ -88,7 +88,7 @@ struct x86_init_ops x86_init __initdata = {
24650 },
24651 };
24652
24653-struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
24654+struct x86_cpuinit_ops x86_cpuinit __cpuinitconst = {
24655 .early_percpu_clock_init = x86_init_noop,
24656 .setup_percpu_clockev = setup_secondary_APIC_clock,
24657 };
24658@@ -96,7 +96,7 @@ struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
24659 static void default_nmi_init(void) { };
24660 static int default_i8042_detect(void) { return 1; };
24661
24662-struct x86_platform_ops x86_platform = {
24663+struct x86_platform_ops x86_platform __read_only = {
24664 .calibrate_tsc = native_calibrate_tsc,
24665 .get_wallclock = mach_get_cmos_time,
24666 .set_wallclock = mach_set_rtc_mmss,
24667@@ -110,14 +110,14 @@ struct x86_platform_ops x86_platform = {
24668 };
24669
24670 EXPORT_SYMBOL_GPL(x86_platform);
24671-struct x86_msi_ops x86_msi = {
24672+struct x86_msi_ops x86_msi __read_only = {
24673 .setup_msi_irqs = native_setup_msi_irqs,
24674 .teardown_msi_irq = native_teardown_msi_irq,
24675 .teardown_msi_irqs = default_teardown_msi_irqs,
24676 .restore_msi_irqs = default_restore_msi_irqs,
24677 };
24678
24679-struct x86_io_apic_ops x86_io_apic_ops = {
24680+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
24681 .init = native_io_apic_init_mappings,
24682 .read = native_io_apic_read,
24683 .write = native_io_apic_write,
24684diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
24685index ada87a3..afea76d 100644
24686--- a/arch/x86/kernel/xsave.c
24687+++ b/arch/x86/kernel/xsave.c
24688@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
24689 {
24690 int err;
24691
24692+ buf = (struct xsave_struct __user *)____m(buf);
24693 if (use_xsave())
24694 err = xsave_user(buf);
24695 else if (use_fxsr())
24696@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
24697 */
24698 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
24699 {
24700+ buf = (void __user *)____m(buf);
24701 if (use_xsave()) {
24702 if ((unsigned long)buf % 64 || fx_only) {
24703 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
24704diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
24705index a20ecb5..d0e2194 100644
24706--- a/arch/x86/kvm/cpuid.c
24707+++ b/arch/x86/kvm/cpuid.c
24708@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
24709 struct kvm_cpuid2 *cpuid,
24710 struct kvm_cpuid_entry2 __user *entries)
24711 {
24712- int r;
24713+ int r, i;
24714
24715 r = -E2BIG;
24716 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
24717 goto out;
24718 r = -EFAULT;
24719- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
24720- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
24721+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
24722 goto out;
24723+ for (i = 0; i < cpuid->nent; ++i) {
24724+ struct kvm_cpuid_entry2 cpuid_entry;
24725+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
24726+ goto out;
24727+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
24728+ }
24729 vcpu->arch.cpuid_nent = cpuid->nent;
24730 kvm_apic_set_version(vcpu);
24731 kvm_x86_ops->cpuid_update(vcpu);
24732@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
24733 struct kvm_cpuid2 *cpuid,
24734 struct kvm_cpuid_entry2 __user *entries)
24735 {
24736- int r;
24737+ int r, i;
24738
24739 r = -E2BIG;
24740 if (cpuid->nent < vcpu->arch.cpuid_nent)
24741 goto out;
24742 r = -EFAULT;
24743- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
24744- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
24745+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
24746 goto out;
24747+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
24748+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
24749+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
24750+ goto out;
24751+ }
24752 return 0;
24753
24754 out:
24755diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
24756index a27e763..54bfe43 100644
24757--- a/arch/x86/kvm/emulate.c
24758+++ b/arch/x86/kvm/emulate.c
24759@@ -292,6 +292,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
24760
24761 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
24762 do { \
24763+ unsigned long _tmp; \
24764 __asm__ __volatile__ ( \
24765 _PRE_EFLAGS("0", "4", "2") \
24766 _op _suffix " %"_x"3,%1; " \
24767@@ -306,8 +307,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
24768 /* Raw emulation: instruction has two explicit operands. */
24769 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
24770 do { \
24771- unsigned long _tmp; \
24772- \
24773 switch ((ctxt)->dst.bytes) { \
24774 case 2: \
24775 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
24776@@ -323,7 +322,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
24777
24778 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
24779 do { \
24780- unsigned long _tmp; \
24781 switch ((ctxt)->dst.bytes) { \
24782 case 1: \
24783 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
24784diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
24785index 9392f52..0e56d77 100644
24786--- a/arch/x86/kvm/lapic.c
24787+++ b/arch/x86/kvm/lapic.c
24788@@ -55,7 +55,7 @@
24789 #define APIC_BUS_CYCLE_NS 1
24790
24791 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
24792-#define apic_debug(fmt, arg...)
24793+#define apic_debug(fmt, arg...) do {} while (0)
24794
24795 #define APIC_LVT_NUM 6
24796 /* 14 is the version for Xeon and Pentium 8.4.8*/
24797diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
24798index 891eb6d..e027900 100644
24799--- a/arch/x86/kvm/paging_tmpl.h
24800+++ b/arch/x86/kvm/paging_tmpl.h
24801@@ -208,7 +208,7 @@ retry_walk:
24802 if (unlikely(kvm_is_error_hva(host_addr)))
24803 goto error;
24804
24805- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
24806+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
24807 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
24808 goto error;
24809 walker->ptep_user[walker->level - 1] = ptep_user;
24810diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
24811index d29d3cd..ec9d522 100644
24812--- a/arch/x86/kvm/svm.c
24813+++ b/arch/x86/kvm/svm.c
24814@@ -3507,7 +3507,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
24815 int cpu = raw_smp_processor_id();
24816
24817 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
24818+
24819+ pax_open_kernel();
24820 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
24821+ pax_close_kernel();
24822+
24823 load_TR_desc();
24824 }
24825
24826@@ -3881,6 +3885,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
24827 #endif
24828 #endif
24829
24830+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
24831+ __set_fs(current_thread_info()->addr_limit);
24832+#endif
24833+
24834 reload_tss(vcpu);
24835
24836 local_irq_disable();
24837diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
24838index 9120ae1..238abc0 100644
24839--- a/arch/x86/kvm/vmx.c
24840+++ b/arch/x86/kvm/vmx.c
24841@@ -1370,7 +1370,11 @@ static void reload_tss(void)
24842 struct desc_struct *descs;
24843
24844 descs = (void *)gdt->address;
24845+
24846+ pax_open_kernel();
24847 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
24848+ pax_close_kernel();
24849+
24850 load_TR_desc();
24851 }
24852
24853@@ -1594,6 +1598,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
24854 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
24855 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
24856
24857+#ifdef CONFIG_PAX_PER_CPU_PGD
24858+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
24859+#endif
24860+
24861 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
24862 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
24863 vmx->loaded_vmcs->cpu = cpu;
24864@@ -2738,8 +2746,11 @@ static __init int hardware_setup(void)
24865 if (!cpu_has_vmx_flexpriority())
24866 flexpriority_enabled = 0;
24867
24868- if (!cpu_has_vmx_tpr_shadow())
24869- kvm_x86_ops->update_cr8_intercept = NULL;
24870+ if (!cpu_has_vmx_tpr_shadow()) {
24871+ pax_open_kernel();
24872+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
24873+ pax_close_kernel();
24874+ }
24875
24876 if (enable_ept && !cpu_has_vmx_ept_2m_page())
24877 kvm_disable_largepages();
24878@@ -3782,7 +3793,10 @@ static void vmx_set_constant_host_state(void)
24879
24880 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
24881 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
24882+
24883+#ifndef CONFIG_PAX_PER_CPU_PGD
24884 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
24885+#endif
24886
24887 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
24888 #ifdef CONFIG_X86_64
24889@@ -3803,7 +3817,7 @@ static void vmx_set_constant_host_state(void)
24890 native_store_idt(&dt);
24891 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
24892
24893- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
24894+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
24895
24896 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
24897 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
24898@@ -6355,6 +6369,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24899 "jmp 2f \n\t"
24900 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
24901 "2: "
24902+
24903+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24904+ "ljmp %[cs],$3f\n\t"
24905+ "3: "
24906+#endif
24907+
24908 /* Save guest registers, load host registers, keep flags */
24909 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
24910 "pop %0 \n\t"
24911@@ -6407,6 +6427,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24912 #endif
24913 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
24914 [wordsize]"i"(sizeof(ulong))
24915+
24916+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24917+ ,[cs]"i"(__KERNEL_CS)
24918+#endif
24919+
24920 : "cc", "memory"
24921 #ifdef CONFIG_X86_64
24922 , "rax", "rbx", "rdi", "rsi"
24923@@ -6420,7 +6445,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24924 if (debugctlmsr)
24925 update_debugctlmsr(debugctlmsr);
24926
24927-#ifndef CONFIG_X86_64
24928+#ifdef CONFIG_X86_32
24929 /*
24930 * The sysexit path does not restore ds/es, so we must set them to
24931 * a reasonable value ourselves.
24932@@ -6429,8 +6454,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24933 * may be executed in interrupt context, which saves and restore segments
24934 * around it, nullifying its effect.
24935 */
24936- loadsegment(ds, __USER_DS);
24937- loadsegment(es, __USER_DS);
24938+ loadsegment(ds, __KERNEL_DS);
24939+ loadsegment(es, __KERNEL_DS);
24940+ loadsegment(ss, __KERNEL_DS);
24941+
24942+#ifdef CONFIG_PAX_KERNEXEC
24943+ loadsegment(fs, __KERNEL_PERCPU);
24944+#endif
24945+
24946+#ifdef CONFIG_PAX_MEMORY_UDEREF
24947+ __set_fs(current_thread_info()->addr_limit);
24948+#endif
24949+
24950 #endif
24951
24952 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
24953diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
24954index c243b81..b692af3 100644
24955--- a/arch/x86/kvm/x86.c
24956+++ b/arch/x86/kvm/x86.c
24957@@ -1408,10 +1408,9 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
24958 unsigned long flags, this_tsc_khz;
24959 struct kvm_vcpu_arch *vcpu = &v->arch;
24960 struct kvm_arch *ka = &v->kvm->arch;
24961- void *shared_kaddr;
24962 s64 kernel_ns, max_kernel_ns;
24963 u64 tsc_timestamp, host_tsc;
24964- struct pvclock_vcpu_time_info *guest_hv_clock;
24965+ struct pvclock_vcpu_time_info guest_hv_clock;
24966 u8 pvclock_flags;
24967 bool use_master_clock;
24968
24969@@ -1465,7 +1464,7 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
24970
24971 local_irq_restore(flags);
24972
24973- if (!vcpu->time_page)
24974+ if (!vcpu->pv_time_enabled)
24975 return 0;
24976
24977 /*
24978@@ -1527,12 +1526,12 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
24979 */
24980 vcpu->hv_clock.version += 2;
24981
24982- shared_kaddr = kmap_atomic(vcpu->time_page);
24983-
24984- guest_hv_clock = shared_kaddr + vcpu->time_offset;
24985+ if (unlikely(kvm_read_guest_cached(v->kvm, &vcpu->pv_time,
24986+ &guest_hv_clock, sizeof(guest_hv_clock))))
24987+ return 0;
24988
24989 /* retain PVCLOCK_GUEST_STOPPED if set in guest copy */
24990- pvclock_flags = (guest_hv_clock->flags & PVCLOCK_GUEST_STOPPED);
24991+ pvclock_flags = (guest_hv_clock.flags & PVCLOCK_GUEST_STOPPED);
24992
24993 if (vcpu->pvclock_set_guest_stopped_request) {
24994 pvclock_flags |= PVCLOCK_GUEST_STOPPED;
24995@@ -1545,12 +1544,9 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
24996
24997 vcpu->hv_clock.flags = pvclock_flags;
24998
24999- memcpy(shared_kaddr + vcpu->time_offset, &vcpu->hv_clock,
25000- sizeof(vcpu->hv_clock));
25001-
25002- kunmap_atomic(shared_kaddr);
25003-
25004- mark_page_dirty(v->kvm, vcpu->time >> PAGE_SHIFT);
25005+ kvm_write_guest_cached(v->kvm, &vcpu->pv_time,
25006+ &vcpu->hv_clock,
25007+ sizeof(vcpu->hv_clock));
25008 return 0;
25009 }
25010
25011@@ -1692,8 +1688,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
25012 {
25013 struct kvm *kvm = vcpu->kvm;
25014 int lm = is_long_mode(vcpu);
25015- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
25016- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
25017+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
25018+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
25019 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
25020 : kvm->arch.xen_hvm_config.blob_size_32;
25021 u32 page_num = data & ~PAGE_MASK;
25022@@ -1839,10 +1835,7 @@ static int kvm_pv_enable_async_pf(struct kvm_vcpu *vcpu, u64 data)
25023
25024 static void kvmclock_reset(struct kvm_vcpu *vcpu)
25025 {
25026- if (vcpu->arch.time_page) {
25027- kvm_release_page_dirty(vcpu->arch.time_page);
25028- vcpu->arch.time_page = NULL;
25029- }
25030+ vcpu->arch.pv_time_enabled = false;
25031 }
25032
25033 static void accumulate_steal_time(struct kvm_vcpu *vcpu)
25034@@ -1948,6 +1941,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
25035 break;
25036 case MSR_KVM_SYSTEM_TIME_NEW:
25037 case MSR_KVM_SYSTEM_TIME: {
25038+ u64 gpa_offset;
25039 kvmclock_reset(vcpu);
25040
25041 vcpu->arch.time = data;
25042@@ -1957,14 +1951,17 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
25043 if (!(data & 1))
25044 break;
25045
25046- /* ...but clean it before doing the actual write */
25047- vcpu->arch.time_offset = data & ~(PAGE_MASK | 1);
25048+ gpa_offset = data & ~(PAGE_MASK | 1);
25049
25050- vcpu->arch.time_page =
25051- gfn_to_page(vcpu->kvm, data >> PAGE_SHIFT);
25052+ /* Check that the address is 32-byte aligned. */
25053+ if (gpa_offset & (sizeof(struct pvclock_vcpu_time_info) - 1))
25054+ break;
25055
25056- if (is_error_page(vcpu->arch.time_page))
25057- vcpu->arch.time_page = NULL;
25058+ if (kvm_gfn_to_hva_cache_init(vcpu->kvm,
25059+ &vcpu->arch.pv_time, data & ~1ULL))
25060+ vcpu->arch.pv_time_enabled = false;
25061+ else
25062+ vcpu->arch.pv_time_enabled = true;
25063
25064 break;
25065 }
25066@@ -2571,6 +2568,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
25067 if (n < msr_list.nmsrs)
25068 goto out;
25069 r = -EFAULT;
25070+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
25071+ goto out;
25072 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
25073 num_msrs_to_save * sizeof(u32)))
25074 goto out;
25075@@ -2700,7 +2699,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
25076 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
25077 struct kvm_interrupt *irq)
25078 {
25079- if (irq->irq < 0 || irq->irq >= KVM_NR_INTERRUPTS)
25080+ if (irq->irq >= KVM_NR_INTERRUPTS)
25081 return -EINVAL;
25082 if (irqchip_in_kernel(vcpu->kvm))
25083 return -ENXIO;
25084@@ -2967,7 +2966,7 @@ static int kvm_vcpu_ioctl_x86_set_xcrs(struct kvm_vcpu *vcpu,
25085 */
25086 static int kvm_set_guest_paused(struct kvm_vcpu *vcpu)
25087 {
25088- if (!vcpu->arch.time_page)
25089+ if (!vcpu->arch.pv_time_enabled)
25090 return -EINVAL;
25091 vcpu->arch.pvclock_set_guest_stopped_request = true;
25092 kvm_make_request(KVM_REQ_CLOCK_UPDATE, vcpu);
25093@@ -5213,7 +5212,7 @@ static struct notifier_block pvclock_gtod_notifier = {
25094 };
25095 #endif
25096
25097-int kvm_arch_init(void *opaque)
25098+int kvm_arch_init(const void *opaque)
25099 {
25100 int r;
25101 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
25102@@ -6661,6 +6660,7 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
25103 goto fail_free_wbinvd_dirty_mask;
25104
25105 vcpu->arch.ia32_tsc_adjust_msr = 0x0;
25106+ vcpu->arch.pv_time_enabled = false;
25107 kvm_async_pf_hash_reset(vcpu);
25108 kvm_pmu_init(vcpu);
25109
25110diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
25111index 20a4fd4..d806083 100644
25112--- a/arch/x86/lguest/boot.c
25113+++ b/arch/x86/lguest/boot.c
25114@@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
25115 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
25116 * Launcher to reboot us.
25117 */
25118-static void lguest_restart(char *reason)
25119+static __noreturn void lguest_restart(char *reason)
25120 {
25121 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
25122+ BUG();
25123 }
25124
25125 /*G:050
25126diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
25127index 00933d5..3a64af9 100644
25128--- a/arch/x86/lib/atomic64_386_32.S
25129+++ b/arch/x86/lib/atomic64_386_32.S
25130@@ -48,6 +48,10 @@ BEGIN(read)
25131 movl (v), %eax
25132 movl 4(v), %edx
25133 RET_ENDP
25134+BEGIN(read_unchecked)
25135+ movl (v), %eax
25136+ movl 4(v), %edx
25137+RET_ENDP
25138 #undef v
25139
25140 #define v %esi
25141@@ -55,6 +59,10 @@ BEGIN(set)
25142 movl %ebx, (v)
25143 movl %ecx, 4(v)
25144 RET_ENDP
25145+BEGIN(set_unchecked)
25146+ movl %ebx, (v)
25147+ movl %ecx, 4(v)
25148+RET_ENDP
25149 #undef v
25150
25151 #define v %esi
25152@@ -70,6 +78,20 @@ RET_ENDP
25153 BEGIN(add)
25154 addl %eax, (v)
25155 adcl %edx, 4(v)
25156+
25157+#ifdef CONFIG_PAX_REFCOUNT
25158+ jno 0f
25159+ subl %eax, (v)
25160+ sbbl %edx, 4(v)
25161+ int $4
25162+0:
25163+ _ASM_EXTABLE(0b, 0b)
25164+#endif
25165+
25166+RET_ENDP
25167+BEGIN(add_unchecked)
25168+ addl %eax, (v)
25169+ adcl %edx, 4(v)
25170 RET_ENDP
25171 #undef v
25172
25173@@ -77,6 +99,24 @@ RET_ENDP
25174 BEGIN(add_return)
25175 addl (v), %eax
25176 adcl 4(v), %edx
25177+
25178+#ifdef CONFIG_PAX_REFCOUNT
25179+ into
25180+1234:
25181+ _ASM_EXTABLE(1234b, 2f)
25182+#endif
25183+
25184+ movl %eax, (v)
25185+ movl %edx, 4(v)
25186+
25187+#ifdef CONFIG_PAX_REFCOUNT
25188+2:
25189+#endif
25190+
25191+RET_ENDP
25192+BEGIN(add_return_unchecked)
25193+ addl (v), %eax
25194+ adcl 4(v), %edx
25195 movl %eax, (v)
25196 movl %edx, 4(v)
25197 RET_ENDP
25198@@ -86,6 +126,20 @@ RET_ENDP
25199 BEGIN(sub)
25200 subl %eax, (v)
25201 sbbl %edx, 4(v)
25202+
25203+#ifdef CONFIG_PAX_REFCOUNT
25204+ jno 0f
25205+ addl %eax, (v)
25206+ adcl %edx, 4(v)
25207+ int $4
25208+0:
25209+ _ASM_EXTABLE(0b, 0b)
25210+#endif
25211+
25212+RET_ENDP
25213+BEGIN(sub_unchecked)
25214+ subl %eax, (v)
25215+ sbbl %edx, 4(v)
25216 RET_ENDP
25217 #undef v
25218
25219@@ -96,6 +150,27 @@ BEGIN(sub_return)
25220 sbbl $0, %edx
25221 addl (v), %eax
25222 adcl 4(v), %edx
25223+
25224+#ifdef CONFIG_PAX_REFCOUNT
25225+ into
25226+1234:
25227+ _ASM_EXTABLE(1234b, 2f)
25228+#endif
25229+
25230+ movl %eax, (v)
25231+ movl %edx, 4(v)
25232+
25233+#ifdef CONFIG_PAX_REFCOUNT
25234+2:
25235+#endif
25236+
25237+RET_ENDP
25238+BEGIN(sub_return_unchecked)
25239+ negl %edx
25240+ negl %eax
25241+ sbbl $0, %edx
25242+ addl (v), %eax
25243+ adcl 4(v), %edx
25244 movl %eax, (v)
25245 movl %edx, 4(v)
25246 RET_ENDP
25247@@ -105,6 +180,20 @@ RET_ENDP
25248 BEGIN(inc)
25249 addl $1, (v)
25250 adcl $0, 4(v)
25251+
25252+#ifdef CONFIG_PAX_REFCOUNT
25253+ jno 0f
25254+ subl $1, (v)
25255+ sbbl $0, 4(v)
25256+ int $4
25257+0:
25258+ _ASM_EXTABLE(0b, 0b)
25259+#endif
25260+
25261+RET_ENDP
25262+BEGIN(inc_unchecked)
25263+ addl $1, (v)
25264+ adcl $0, 4(v)
25265 RET_ENDP
25266 #undef v
25267
25268@@ -114,6 +203,26 @@ BEGIN(inc_return)
25269 movl 4(v), %edx
25270 addl $1, %eax
25271 adcl $0, %edx
25272+
25273+#ifdef CONFIG_PAX_REFCOUNT
25274+ into
25275+1234:
25276+ _ASM_EXTABLE(1234b, 2f)
25277+#endif
25278+
25279+ movl %eax, (v)
25280+ movl %edx, 4(v)
25281+
25282+#ifdef CONFIG_PAX_REFCOUNT
25283+2:
25284+#endif
25285+
25286+RET_ENDP
25287+BEGIN(inc_return_unchecked)
25288+ movl (v), %eax
25289+ movl 4(v), %edx
25290+ addl $1, %eax
25291+ adcl $0, %edx
25292 movl %eax, (v)
25293 movl %edx, 4(v)
25294 RET_ENDP
25295@@ -123,6 +232,20 @@ RET_ENDP
25296 BEGIN(dec)
25297 subl $1, (v)
25298 sbbl $0, 4(v)
25299+
25300+#ifdef CONFIG_PAX_REFCOUNT
25301+ jno 0f
25302+ addl $1, (v)
25303+ adcl $0, 4(v)
25304+ int $4
25305+0:
25306+ _ASM_EXTABLE(0b, 0b)
25307+#endif
25308+
25309+RET_ENDP
25310+BEGIN(dec_unchecked)
25311+ subl $1, (v)
25312+ sbbl $0, 4(v)
25313 RET_ENDP
25314 #undef v
25315
25316@@ -132,6 +255,26 @@ BEGIN(dec_return)
25317 movl 4(v), %edx
25318 subl $1, %eax
25319 sbbl $0, %edx
25320+
25321+#ifdef CONFIG_PAX_REFCOUNT
25322+ into
25323+1234:
25324+ _ASM_EXTABLE(1234b, 2f)
25325+#endif
25326+
25327+ movl %eax, (v)
25328+ movl %edx, 4(v)
25329+
25330+#ifdef CONFIG_PAX_REFCOUNT
25331+2:
25332+#endif
25333+
25334+RET_ENDP
25335+BEGIN(dec_return_unchecked)
25336+ movl (v), %eax
25337+ movl 4(v), %edx
25338+ subl $1, %eax
25339+ sbbl $0, %edx
25340 movl %eax, (v)
25341 movl %edx, 4(v)
25342 RET_ENDP
25343@@ -143,6 +286,13 @@ BEGIN(add_unless)
25344 adcl %edx, %edi
25345 addl (v), %eax
25346 adcl 4(v), %edx
25347+
25348+#ifdef CONFIG_PAX_REFCOUNT
25349+ into
25350+1234:
25351+ _ASM_EXTABLE(1234b, 2f)
25352+#endif
25353+
25354 cmpl %eax, %ecx
25355 je 3f
25356 1:
25357@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
25358 1:
25359 addl $1, %eax
25360 adcl $0, %edx
25361+
25362+#ifdef CONFIG_PAX_REFCOUNT
25363+ into
25364+1234:
25365+ _ASM_EXTABLE(1234b, 2f)
25366+#endif
25367+
25368 movl %eax, (v)
25369 movl %edx, 4(v)
25370 movl $1, %eax
25371@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
25372 movl 4(v), %edx
25373 subl $1, %eax
25374 sbbl $0, %edx
25375+
25376+#ifdef CONFIG_PAX_REFCOUNT
25377+ into
25378+1234:
25379+ _ASM_EXTABLE(1234b, 1f)
25380+#endif
25381+
25382 js 1f
25383 movl %eax, (v)
25384 movl %edx, 4(v)
25385diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
25386index f5cc9eb..51fa319 100644
25387--- a/arch/x86/lib/atomic64_cx8_32.S
25388+++ b/arch/x86/lib/atomic64_cx8_32.S
25389@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
25390 CFI_STARTPROC
25391
25392 read64 %ecx
25393+ pax_force_retaddr
25394 ret
25395 CFI_ENDPROC
25396 ENDPROC(atomic64_read_cx8)
25397
25398+ENTRY(atomic64_read_unchecked_cx8)
25399+ CFI_STARTPROC
25400+
25401+ read64 %ecx
25402+ pax_force_retaddr
25403+ ret
25404+ CFI_ENDPROC
25405+ENDPROC(atomic64_read_unchecked_cx8)
25406+
25407 ENTRY(atomic64_set_cx8)
25408 CFI_STARTPROC
25409
25410@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
25411 cmpxchg8b (%esi)
25412 jne 1b
25413
25414+ pax_force_retaddr
25415 ret
25416 CFI_ENDPROC
25417 ENDPROC(atomic64_set_cx8)
25418
25419+ENTRY(atomic64_set_unchecked_cx8)
25420+ CFI_STARTPROC
25421+
25422+1:
25423+/* we don't need LOCK_PREFIX since aligned 64-bit writes
25424+ * are atomic on 586 and newer */
25425+ cmpxchg8b (%esi)
25426+ jne 1b
25427+
25428+ pax_force_retaddr
25429+ ret
25430+ CFI_ENDPROC
25431+ENDPROC(atomic64_set_unchecked_cx8)
25432+
25433 ENTRY(atomic64_xchg_cx8)
25434 CFI_STARTPROC
25435
25436@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
25437 cmpxchg8b (%esi)
25438 jne 1b
25439
25440+ pax_force_retaddr
25441 ret
25442 CFI_ENDPROC
25443 ENDPROC(atomic64_xchg_cx8)
25444
25445-.macro addsub_return func ins insc
25446-ENTRY(atomic64_\func\()_return_cx8)
25447+.macro addsub_return func ins insc unchecked=""
25448+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
25449 CFI_STARTPROC
25450 SAVE ebp
25451 SAVE ebx
25452@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
25453 movl %edx, %ecx
25454 \ins\()l %esi, %ebx
25455 \insc\()l %edi, %ecx
25456+
25457+.ifb \unchecked
25458+#ifdef CONFIG_PAX_REFCOUNT
25459+ into
25460+2:
25461+ _ASM_EXTABLE(2b, 3f)
25462+#endif
25463+.endif
25464+
25465 LOCK_PREFIX
25466 cmpxchg8b (%ebp)
25467 jne 1b
25468-
25469-10:
25470 movl %ebx, %eax
25471 movl %ecx, %edx
25472+
25473+.ifb \unchecked
25474+#ifdef CONFIG_PAX_REFCOUNT
25475+3:
25476+#endif
25477+.endif
25478+
25479 RESTORE edi
25480 RESTORE esi
25481 RESTORE ebx
25482 RESTORE ebp
25483+ pax_force_retaddr
25484 ret
25485 CFI_ENDPROC
25486-ENDPROC(atomic64_\func\()_return_cx8)
25487+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
25488 .endm
25489
25490 addsub_return add add adc
25491 addsub_return sub sub sbb
25492+addsub_return add add adc _unchecked
25493+addsub_return sub sub sbb _unchecked
25494
25495-.macro incdec_return func ins insc
25496-ENTRY(atomic64_\func\()_return_cx8)
25497+.macro incdec_return func ins insc unchecked=""
25498+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
25499 CFI_STARTPROC
25500 SAVE ebx
25501
25502@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
25503 movl %edx, %ecx
25504 \ins\()l $1, %ebx
25505 \insc\()l $0, %ecx
25506+
25507+.ifb \unchecked
25508+#ifdef CONFIG_PAX_REFCOUNT
25509+ into
25510+2:
25511+ _ASM_EXTABLE(2b, 3f)
25512+#endif
25513+.endif
25514+
25515 LOCK_PREFIX
25516 cmpxchg8b (%esi)
25517 jne 1b
25518
25519-10:
25520 movl %ebx, %eax
25521 movl %ecx, %edx
25522+
25523+.ifb \unchecked
25524+#ifdef CONFIG_PAX_REFCOUNT
25525+3:
25526+#endif
25527+.endif
25528+
25529 RESTORE ebx
25530+ pax_force_retaddr
25531 ret
25532 CFI_ENDPROC
25533-ENDPROC(atomic64_\func\()_return_cx8)
25534+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
25535 .endm
25536
25537 incdec_return inc add adc
25538 incdec_return dec sub sbb
25539+incdec_return inc add adc _unchecked
25540+incdec_return dec sub sbb _unchecked
25541
25542 ENTRY(atomic64_dec_if_positive_cx8)
25543 CFI_STARTPROC
25544@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
25545 movl %edx, %ecx
25546 subl $1, %ebx
25547 sbb $0, %ecx
25548+
25549+#ifdef CONFIG_PAX_REFCOUNT
25550+ into
25551+1234:
25552+ _ASM_EXTABLE(1234b, 2f)
25553+#endif
25554+
25555 js 2f
25556 LOCK_PREFIX
25557 cmpxchg8b (%esi)
25558@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
25559 movl %ebx, %eax
25560 movl %ecx, %edx
25561 RESTORE ebx
25562+ pax_force_retaddr
25563 ret
25564 CFI_ENDPROC
25565 ENDPROC(atomic64_dec_if_positive_cx8)
25566@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
25567 movl %edx, %ecx
25568 addl %ebp, %ebx
25569 adcl %edi, %ecx
25570+
25571+#ifdef CONFIG_PAX_REFCOUNT
25572+ into
25573+1234:
25574+ _ASM_EXTABLE(1234b, 3f)
25575+#endif
25576+
25577 LOCK_PREFIX
25578 cmpxchg8b (%esi)
25579 jne 1b
25580@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
25581 CFI_ADJUST_CFA_OFFSET -8
25582 RESTORE ebx
25583 RESTORE ebp
25584+ pax_force_retaddr
25585 ret
25586 4:
25587 cmpl %edx, 4(%esp)
25588@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
25589 xorl %ecx, %ecx
25590 addl $1, %ebx
25591 adcl %edx, %ecx
25592+
25593+#ifdef CONFIG_PAX_REFCOUNT
25594+ into
25595+1234:
25596+ _ASM_EXTABLE(1234b, 3f)
25597+#endif
25598+
25599 LOCK_PREFIX
25600 cmpxchg8b (%esi)
25601 jne 1b
25602@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
25603 movl $1, %eax
25604 3:
25605 RESTORE ebx
25606+ pax_force_retaddr
25607 ret
25608 CFI_ENDPROC
25609 ENDPROC(atomic64_inc_not_zero_cx8)
25610diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
25611index 2af5df3..62b1a5a 100644
25612--- a/arch/x86/lib/checksum_32.S
25613+++ b/arch/x86/lib/checksum_32.S
25614@@ -29,7 +29,8 @@
25615 #include <asm/dwarf2.h>
25616 #include <asm/errno.h>
25617 #include <asm/asm.h>
25618-
25619+#include <asm/segment.h>
25620+
25621 /*
25622 * computes a partial checksum, e.g. for TCP/UDP fragments
25623 */
25624@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
25625
25626 #define ARGBASE 16
25627 #define FP 12
25628-
25629-ENTRY(csum_partial_copy_generic)
25630+
25631+ENTRY(csum_partial_copy_generic_to_user)
25632 CFI_STARTPROC
25633+
25634+#ifdef CONFIG_PAX_MEMORY_UDEREF
25635+ pushl_cfi %gs
25636+ popl_cfi %es
25637+ jmp csum_partial_copy_generic
25638+#endif
25639+
25640+ENTRY(csum_partial_copy_generic_from_user)
25641+
25642+#ifdef CONFIG_PAX_MEMORY_UDEREF
25643+ pushl_cfi %gs
25644+ popl_cfi %ds
25645+#endif
25646+
25647+ENTRY(csum_partial_copy_generic)
25648 subl $4,%esp
25649 CFI_ADJUST_CFA_OFFSET 4
25650 pushl_cfi %edi
25651@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
25652 jmp 4f
25653 SRC(1: movw (%esi), %bx )
25654 addl $2, %esi
25655-DST( movw %bx, (%edi) )
25656+DST( movw %bx, %es:(%edi) )
25657 addl $2, %edi
25658 addw %bx, %ax
25659 adcl $0, %eax
25660@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
25661 SRC(1: movl (%esi), %ebx )
25662 SRC( movl 4(%esi), %edx )
25663 adcl %ebx, %eax
25664-DST( movl %ebx, (%edi) )
25665+DST( movl %ebx, %es:(%edi) )
25666 adcl %edx, %eax
25667-DST( movl %edx, 4(%edi) )
25668+DST( movl %edx, %es:4(%edi) )
25669
25670 SRC( movl 8(%esi), %ebx )
25671 SRC( movl 12(%esi), %edx )
25672 adcl %ebx, %eax
25673-DST( movl %ebx, 8(%edi) )
25674+DST( movl %ebx, %es:8(%edi) )
25675 adcl %edx, %eax
25676-DST( movl %edx, 12(%edi) )
25677+DST( movl %edx, %es:12(%edi) )
25678
25679 SRC( movl 16(%esi), %ebx )
25680 SRC( movl 20(%esi), %edx )
25681 adcl %ebx, %eax
25682-DST( movl %ebx, 16(%edi) )
25683+DST( movl %ebx, %es:16(%edi) )
25684 adcl %edx, %eax
25685-DST( movl %edx, 20(%edi) )
25686+DST( movl %edx, %es:20(%edi) )
25687
25688 SRC( movl 24(%esi), %ebx )
25689 SRC( movl 28(%esi), %edx )
25690 adcl %ebx, %eax
25691-DST( movl %ebx, 24(%edi) )
25692+DST( movl %ebx, %es:24(%edi) )
25693 adcl %edx, %eax
25694-DST( movl %edx, 28(%edi) )
25695+DST( movl %edx, %es:28(%edi) )
25696
25697 lea 32(%esi), %esi
25698 lea 32(%edi), %edi
25699@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
25700 shrl $2, %edx # This clears CF
25701 SRC(3: movl (%esi), %ebx )
25702 adcl %ebx, %eax
25703-DST( movl %ebx, (%edi) )
25704+DST( movl %ebx, %es:(%edi) )
25705 lea 4(%esi), %esi
25706 lea 4(%edi), %edi
25707 dec %edx
25708@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
25709 jb 5f
25710 SRC( movw (%esi), %cx )
25711 leal 2(%esi), %esi
25712-DST( movw %cx, (%edi) )
25713+DST( movw %cx, %es:(%edi) )
25714 leal 2(%edi), %edi
25715 je 6f
25716 shll $16,%ecx
25717 SRC(5: movb (%esi), %cl )
25718-DST( movb %cl, (%edi) )
25719+DST( movb %cl, %es:(%edi) )
25720 6: addl %ecx, %eax
25721 adcl $0, %eax
25722 7:
25723@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
25724
25725 6001:
25726 movl ARGBASE+20(%esp), %ebx # src_err_ptr
25727- movl $-EFAULT, (%ebx)
25728+ movl $-EFAULT, %ss:(%ebx)
25729
25730 # zero the complete destination - computing the rest
25731 # is too much work
25732@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
25733
25734 6002:
25735 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
25736- movl $-EFAULT,(%ebx)
25737+ movl $-EFAULT,%ss:(%ebx)
25738 jmp 5000b
25739
25740 .previous
25741
25742+ pushl_cfi %ss
25743+ popl_cfi %ds
25744+ pushl_cfi %ss
25745+ popl_cfi %es
25746 popl_cfi %ebx
25747 CFI_RESTORE ebx
25748 popl_cfi %esi
25749@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
25750 popl_cfi %ecx # equivalent to addl $4,%esp
25751 ret
25752 CFI_ENDPROC
25753-ENDPROC(csum_partial_copy_generic)
25754+ENDPROC(csum_partial_copy_generic_to_user)
25755
25756 #else
25757
25758 /* Version for PentiumII/PPro */
25759
25760 #define ROUND1(x) \
25761+ nop; nop; nop; \
25762 SRC(movl x(%esi), %ebx ) ; \
25763 addl %ebx, %eax ; \
25764- DST(movl %ebx, x(%edi) ) ;
25765+ DST(movl %ebx, %es:x(%edi)) ;
25766
25767 #define ROUND(x) \
25768+ nop; nop; nop; \
25769 SRC(movl x(%esi), %ebx ) ; \
25770 adcl %ebx, %eax ; \
25771- DST(movl %ebx, x(%edi) ) ;
25772+ DST(movl %ebx, %es:x(%edi)) ;
25773
25774 #define ARGBASE 12
25775-
25776-ENTRY(csum_partial_copy_generic)
25777+
25778+ENTRY(csum_partial_copy_generic_to_user)
25779 CFI_STARTPROC
25780+
25781+#ifdef CONFIG_PAX_MEMORY_UDEREF
25782+ pushl_cfi %gs
25783+ popl_cfi %es
25784+ jmp csum_partial_copy_generic
25785+#endif
25786+
25787+ENTRY(csum_partial_copy_generic_from_user)
25788+
25789+#ifdef CONFIG_PAX_MEMORY_UDEREF
25790+ pushl_cfi %gs
25791+ popl_cfi %ds
25792+#endif
25793+
25794+ENTRY(csum_partial_copy_generic)
25795 pushl_cfi %ebx
25796 CFI_REL_OFFSET ebx, 0
25797 pushl_cfi %edi
25798@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
25799 subl %ebx, %edi
25800 lea -1(%esi),%edx
25801 andl $-32,%edx
25802- lea 3f(%ebx,%ebx), %ebx
25803+ lea 3f(%ebx,%ebx,2), %ebx
25804 testl %esi, %esi
25805 jmp *%ebx
25806 1: addl $64,%esi
25807@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
25808 jb 5f
25809 SRC( movw (%esi), %dx )
25810 leal 2(%esi), %esi
25811-DST( movw %dx, (%edi) )
25812+DST( movw %dx, %es:(%edi) )
25813 leal 2(%edi), %edi
25814 je 6f
25815 shll $16,%edx
25816 5:
25817 SRC( movb (%esi), %dl )
25818-DST( movb %dl, (%edi) )
25819+DST( movb %dl, %es:(%edi) )
25820 6: addl %edx, %eax
25821 adcl $0, %eax
25822 7:
25823 .section .fixup, "ax"
25824 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
25825- movl $-EFAULT, (%ebx)
25826+ movl $-EFAULT, %ss:(%ebx)
25827 # zero the complete destination (computing the rest is too much work)
25828 movl ARGBASE+8(%esp),%edi # dst
25829 movl ARGBASE+12(%esp),%ecx # len
25830@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
25831 rep; stosb
25832 jmp 7b
25833 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
25834- movl $-EFAULT, (%ebx)
25835+ movl $-EFAULT, %ss:(%ebx)
25836 jmp 7b
25837 .previous
25838
25839+#ifdef CONFIG_PAX_MEMORY_UDEREF
25840+ pushl_cfi %ss
25841+ popl_cfi %ds
25842+ pushl_cfi %ss
25843+ popl_cfi %es
25844+#endif
25845+
25846 popl_cfi %esi
25847 CFI_RESTORE esi
25848 popl_cfi %edi
25849@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
25850 CFI_RESTORE ebx
25851 ret
25852 CFI_ENDPROC
25853-ENDPROC(csum_partial_copy_generic)
25854+ENDPROC(csum_partial_copy_generic_to_user)
25855
25856 #undef ROUND
25857 #undef ROUND1
25858diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
25859index f2145cf..cea889d 100644
25860--- a/arch/x86/lib/clear_page_64.S
25861+++ b/arch/x86/lib/clear_page_64.S
25862@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
25863 movl $4096/8,%ecx
25864 xorl %eax,%eax
25865 rep stosq
25866+ pax_force_retaddr
25867 ret
25868 CFI_ENDPROC
25869 ENDPROC(clear_page_c)
25870@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
25871 movl $4096,%ecx
25872 xorl %eax,%eax
25873 rep stosb
25874+ pax_force_retaddr
25875 ret
25876 CFI_ENDPROC
25877 ENDPROC(clear_page_c_e)
25878@@ -43,6 +45,7 @@ ENTRY(clear_page)
25879 leaq 64(%rdi),%rdi
25880 jnz .Lloop
25881 nop
25882+ pax_force_retaddr
25883 ret
25884 CFI_ENDPROC
25885 .Lclear_page_end:
25886@@ -58,7 +61,7 @@ ENDPROC(clear_page)
25887
25888 #include <asm/cpufeature.h>
25889
25890- .section .altinstr_replacement,"ax"
25891+ .section .altinstr_replacement,"a"
25892 1: .byte 0xeb /* jmp <disp8> */
25893 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
25894 2: .byte 0xeb /* jmp <disp8> */
25895diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
25896index 1e572c5..2a162cd 100644
25897--- a/arch/x86/lib/cmpxchg16b_emu.S
25898+++ b/arch/x86/lib/cmpxchg16b_emu.S
25899@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
25900
25901 popf
25902 mov $1, %al
25903+ pax_force_retaddr
25904 ret
25905
25906 not_same:
25907 popf
25908 xor %al,%al
25909+ pax_force_retaddr
25910 ret
25911
25912 CFI_ENDPROC
25913diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
25914index 176cca6..1166c50 100644
25915--- a/arch/x86/lib/copy_page_64.S
25916+++ b/arch/x86/lib/copy_page_64.S
25917@@ -9,6 +9,7 @@ copy_page_rep:
25918 CFI_STARTPROC
25919 movl $4096/8, %ecx
25920 rep movsq
25921+ pax_force_retaddr
25922 ret
25923 CFI_ENDPROC
25924 ENDPROC(copy_page_rep)
25925@@ -20,12 +21,14 @@ ENDPROC(copy_page_rep)
25926
25927 ENTRY(copy_page)
25928 CFI_STARTPROC
25929- subq $2*8, %rsp
25930- CFI_ADJUST_CFA_OFFSET 2*8
25931+ subq $3*8, %rsp
25932+ CFI_ADJUST_CFA_OFFSET 3*8
25933 movq %rbx, (%rsp)
25934 CFI_REL_OFFSET rbx, 0
25935 movq %r12, 1*8(%rsp)
25936 CFI_REL_OFFSET r12, 1*8
25937+ movq %r13, 2*8(%rsp)
25938+ CFI_REL_OFFSET r13, 2*8
25939
25940 movl $(4096/64)-5, %ecx
25941 .p2align 4
25942@@ -36,7 +39,7 @@ ENTRY(copy_page)
25943 movq 0x8*2(%rsi), %rdx
25944 movq 0x8*3(%rsi), %r8
25945 movq 0x8*4(%rsi), %r9
25946- movq 0x8*5(%rsi), %r10
25947+ movq 0x8*5(%rsi), %r13
25948 movq 0x8*6(%rsi), %r11
25949 movq 0x8*7(%rsi), %r12
25950
25951@@ -47,7 +50,7 @@ ENTRY(copy_page)
25952 movq %rdx, 0x8*2(%rdi)
25953 movq %r8, 0x8*3(%rdi)
25954 movq %r9, 0x8*4(%rdi)
25955- movq %r10, 0x8*5(%rdi)
25956+ movq %r13, 0x8*5(%rdi)
25957 movq %r11, 0x8*6(%rdi)
25958 movq %r12, 0x8*7(%rdi)
25959
25960@@ -66,7 +69,7 @@ ENTRY(copy_page)
25961 movq 0x8*2(%rsi), %rdx
25962 movq 0x8*3(%rsi), %r8
25963 movq 0x8*4(%rsi), %r9
25964- movq 0x8*5(%rsi), %r10
25965+ movq 0x8*5(%rsi), %r13
25966 movq 0x8*6(%rsi), %r11
25967 movq 0x8*7(%rsi), %r12
25968
25969@@ -75,7 +78,7 @@ ENTRY(copy_page)
25970 movq %rdx, 0x8*2(%rdi)
25971 movq %r8, 0x8*3(%rdi)
25972 movq %r9, 0x8*4(%rdi)
25973- movq %r10, 0x8*5(%rdi)
25974+ movq %r13, 0x8*5(%rdi)
25975 movq %r11, 0x8*6(%rdi)
25976 movq %r12, 0x8*7(%rdi)
25977
25978@@ -87,8 +90,11 @@ ENTRY(copy_page)
25979 CFI_RESTORE rbx
25980 movq 1*8(%rsp), %r12
25981 CFI_RESTORE r12
25982- addq $2*8, %rsp
25983- CFI_ADJUST_CFA_OFFSET -2*8
25984+ movq 2*8(%rsp), %r13
25985+ CFI_RESTORE r13
25986+ addq $3*8, %rsp
25987+ CFI_ADJUST_CFA_OFFSET -3*8
25988+ pax_force_retaddr
25989 ret
25990 .Lcopy_page_end:
25991 CFI_ENDPROC
25992@@ -99,7 +105,7 @@ ENDPROC(copy_page)
25993
25994 #include <asm/cpufeature.h>
25995
25996- .section .altinstr_replacement,"ax"
25997+ .section .altinstr_replacement,"a"
25998 1: .byte 0xeb /* jmp <disp8> */
25999 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
26000 2:
26001diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
26002index a30ca15..d25fab6 100644
26003--- a/arch/x86/lib/copy_user_64.S
26004+++ b/arch/x86/lib/copy_user_64.S
26005@@ -18,6 +18,7 @@
26006 #include <asm/alternative-asm.h>
26007 #include <asm/asm.h>
26008 #include <asm/smap.h>
26009+#include <asm/pgtable.h>
26010
26011 /*
26012 * By placing feature2 after feature1 in altinstructions section, we logically
26013@@ -31,7 +32,7 @@
26014 .byte 0xe9 /* 32bit jump */
26015 .long \orig-1f /* by default jump to orig */
26016 1:
26017- .section .altinstr_replacement,"ax"
26018+ .section .altinstr_replacement,"a"
26019 2: .byte 0xe9 /* near jump with 32bit immediate */
26020 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
26021 3: .byte 0xe9 /* near jump with 32bit immediate */
26022@@ -70,47 +71,20 @@
26023 #endif
26024 .endm
26025
26026-/* Standard copy_to_user with segment limit checking */
26027-ENTRY(_copy_to_user)
26028- CFI_STARTPROC
26029- GET_THREAD_INFO(%rax)
26030- movq %rdi,%rcx
26031- addq %rdx,%rcx
26032- jc bad_to_user
26033- cmpq TI_addr_limit(%rax),%rcx
26034- ja bad_to_user
26035- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
26036- copy_user_generic_unrolled,copy_user_generic_string, \
26037- copy_user_enhanced_fast_string
26038- CFI_ENDPROC
26039-ENDPROC(_copy_to_user)
26040-
26041-/* Standard copy_from_user with segment limit checking */
26042-ENTRY(_copy_from_user)
26043- CFI_STARTPROC
26044- GET_THREAD_INFO(%rax)
26045- movq %rsi,%rcx
26046- addq %rdx,%rcx
26047- jc bad_from_user
26048- cmpq TI_addr_limit(%rax),%rcx
26049- ja bad_from_user
26050- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
26051- copy_user_generic_unrolled,copy_user_generic_string, \
26052- copy_user_enhanced_fast_string
26053- CFI_ENDPROC
26054-ENDPROC(_copy_from_user)
26055-
26056 .section .fixup,"ax"
26057 /* must zero dest */
26058 ENTRY(bad_from_user)
26059 bad_from_user:
26060 CFI_STARTPROC
26061+ testl %edx,%edx
26062+ js bad_to_user
26063 movl %edx,%ecx
26064 xorl %eax,%eax
26065 rep
26066 stosb
26067 bad_to_user:
26068 movl %edx,%eax
26069+ pax_force_retaddr
26070 ret
26071 CFI_ENDPROC
26072 ENDPROC(bad_from_user)
26073@@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
26074 jz 17f
26075 1: movq (%rsi),%r8
26076 2: movq 1*8(%rsi),%r9
26077-3: movq 2*8(%rsi),%r10
26078+3: movq 2*8(%rsi),%rax
26079 4: movq 3*8(%rsi),%r11
26080 5: movq %r8,(%rdi)
26081 6: movq %r9,1*8(%rdi)
26082-7: movq %r10,2*8(%rdi)
26083+7: movq %rax,2*8(%rdi)
26084 8: movq %r11,3*8(%rdi)
26085 9: movq 4*8(%rsi),%r8
26086 10: movq 5*8(%rsi),%r9
26087-11: movq 6*8(%rsi),%r10
26088+11: movq 6*8(%rsi),%rax
26089 12: movq 7*8(%rsi),%r11
26090 13: movq %r8,4*8(%rdi)
26091 14: movq %r9,5*8(%rdi)
26092-15: movq %r10,6*8(%rdi)
26093+15: movq %rax,6*8(%rdi)
26094 16: movq %r11,7*8(%rdi)
26095 leaq 64(%rsi),%rsi
26096 leaq 64(%rdi),%rdi
26097@@ -180,6 +154,7 @@ ENTRY(copy_user_generic_unrolled)
26098 jnz 21b
26099 23: xor %eax,%eax
26100 ASM_CLAC
26101+ pax_force_retaddr
26102 ret
26103
26104 .section .fixup,"ax"
26105@@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
26106 movsb
26107 4: xorl %eax,%eax
26108 ASM_CLAC
26109+ pax_force_retaddr
26110 ret
26111
26112 .section .fixup,"ax"
26113@@ -286,6 +262,7 @@ ENTRY(copy_user_enhanced_fast_string)
26114 movsb
26115 2: xorl %eax,%eax
26116 ASM_CLAC
26117+ pax_force_retaddr
26118 ret
26119
26120 .section .fixup,"ax"
26121diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
26122index 6a4f43c..f5f9e26 100644
26123--- a/arch/x86/lib/copy_user_nocache_64.S
26124+++ b/arch/x86/lib/copy_user_nocache_64.S
26125@@ -8,6 +8,7 @@
26126
26127 #include <linux/linkage.h>
26128 #include <asm/dwarf2.h>
26129+#include <asm/alternative-asm.h>
26130
26131 #define FIX_ALIGNMENT 1
26132
26133@@ -16,6 +17,7 @@
26134 #include <asm/thread_info.h>
26135 #include <asm/asm.h>
26136 #include <asm/smap.h>
26137+#include <asm/pgtable.h>
26138
26139 .macro ALIGN_DESTINATION
26140 #ifdef FIX_ALIGNMENT
26141@@ -49,6 +51,15 @@
26142 */
26143 ENTRY(__copy_user_nocache)
26144 CFI_STARTPROC
26145+
26146+#ifdef CONFIG_PAX_MEMORY_UDEREF
26147+ mov $PAX_USER_SHADOW_BASE,%rcx
26148+ cmp %rcx,%rsi
26149+ jae 1f
26150+ add %rcx,%rsi
26151+1:
26152+#endif
26153+
26154 ASM_STAC
26155 cmpl $8,%edx
26156 jb 20f /* less then 8 bytes, go to byte copy loop */
26157@@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
26158 jz 17f
26159 1: movq (%rsi),%r8
26160 2: movq 1*8(%rsi),%r9
26161-3: movq 2*8(%rsi),%r10
26162+3: movq 2*8(%rsi),%rax
26163 4: movq 3*8(%rsi),%r11
26164 5: movnti %r8,(%rdi)
26165 6: movnti %r9,1*8(%rdi)
26166-7: movnti %r10,2*8(%rdi)
26167+7: movnti %rax,2*8(%rdi)
26168 8: movnti %r11,3*8(%rdi)
26169 9: movq 4*8(%rsi),%r8
26170 10: movq 5*8(%rsi),%r9
26171-11: movq 6*8(%rsi),%r10
26172+11: movq 6*8(%rsi),%rax
26173 12: movq 7*8(%rsi),%r11
26174 13: movnti %r8,4*8(%rdi)
26175 14: movnti %r9,5*8(%rdi)
26176-15: movnti %r10,6*8(%rdi)
26177+15: movnti %rax,6*8(%rdi)
26178 16: movnti %r11,7*8(%rdi)
26179 leaq 64(%rsi),%rsi
26180 leaq 64(%rdi),%rdi
26181@@ -99,6 +110,7 @@ ENTRY(__copy_user_nocache)
26182 23: xorl %eax,%eax
26183 ASM_CLAC
26184 sfence
26185+ pax_force_retaddr
26186 ret
26187
26188 .section .fixup,"ax"
26189diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
26190index 2419d5f..953ee51 100644
26191--- a/arch/x86/lib/csum-copy_64.S
26192+++ b/arch/x86/lib/csum-copy_64.S
26193@@ -9,6 +9,7 @@
26194 #include <asm/dwarf2.h>
26195 #include <asm/errno.h>
26196 #include <asm/asm.h>
26197+#include <asm/alternative-asm.h>
26198
26199 /*
26200 * Checksum copy with exception handling.
26201@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
26202 CFI_RESTORE rbp
26203 addq $7*8, %rsp
26204 CFI_ADJUST_CFA_OFFSET -7*8
26205+ pax_force_retaddr 0, 1
26206 ret
26207 CFI_RESTORE_STATE
26208
26209diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
26210index 25b7ae8..169fafc 100644
26211--- a/arch/x86/lib/csum-wrappers_64.c
26212+++ b/arch/x86/lib/csum-wrappers_64.c
26213@@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
26214 len -= 2;
26215 }
26216 }
26217- isum = csum_partial_copy_generic((__force const void *)src,
26218+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
26219 dst, len, isum, errp, NULL);
26220 if (unlikely(*errp))
26221 goto out_err;
26222@@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
26223 }
26224
26225 *errp = 0;
26226- return csum_partial_copy_generic(src, (void __force *)dst,
26227+ return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
26228 len, isum, NULL, errp);
26229 }
26230 EXPORT_SYMBOL(csum_partial_copy_to_user);
26231diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
26232index 156b9c8..b144132 100644
26233--- a/arch/x86/lib/getuser.S
26234+++ b/arch/x86/lib/getuser.S
26235@@ -34,17 +34,40 @@
26236 #include <asm/thread_info.h>
26237 #include <asm/asm.h>
26238 #include <asm/smap.h>
26239+#include <asm/segment.h>
26240+#include <asm/pgtable.h>
26241+#include <asm/alternative-asm.h>
26242+
26243+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
26244+#define __copyuser_seg gs;
26245+#else
26246+#define __copyuser_seg
26247+#endif
26248
26249 .text
26250 ENTRY(__get_user_1)
26251 CFI_STARTPROC
26252+
26253+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26254 GET_THREAD_INFO(%_ASM_DX)
26255 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
26256 jae bad_get_user
26257 ASM_STAC
26258-1: movzb (%_ASM_AX),%edx
26259+
26260+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26261+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
26262+ cmp %_ASM_DX,%_ASM_AX
26263+ jae 1234f
26264+ add %_ASM_DX,%_ASM_AX
26265+1234:
26266+#endif
26267+
26268+#endif
26269+
26270+1: __copyuser_seg movzb (%_ASM_AX),%edx
26271 xor %eax,%eax
26272 ASM_CLAC
26273+ pax_force_retaddr
26274 ret
26275 CFI_ENDPROC
26276 ENDPROC(__get_user_1)
26277@@ -52,14 +75,28 @@ ENDPROC(__get_user_1)
26278 ENTRY(__get_user_2)
26279 CFI_STARTPROC
26280 add $1,%_ASM_AX
26281+
26282+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26283 jc bad_get_user
26284 GET_THREAD_INFO(%_ASM_DX)
26285 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
26286 jae bad_get_user
26287 ASM_STAC
26288-2: movzwl -1(%_ASM_AX),%edx
26289+
26290+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26291+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
26292+ cmp %_ASM_DX,%_ASM_AX
26293+ jae 1234f
26294+ add %_ASM_DX,%_ASM_AX
26295+1234:
26296+#endif
26297+
26298+#endif
26299+
26300+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
26301 xor %eax,%eax
26302 ASM_CLAC
26303+ pax_force_retaddr
26304 ret
26305 CFI_ENDPROC
26306 ENDPROC(__get_user_2)
26307@@ -67,14 +104,28 @@ ENDPROC(__get_user_2)
26308 ENTRY(__get_user_4)
26309 CFI_STARTPROC
26310 add $3,%_ASM_AX
26311+
26312+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26313 jc bad_get_user
26314 GET_THREAD_INFO(%_ASM_DX)
26315 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
26316 jae bad_get_user
26317 ASM_STAC
26318-3: mov -3(%_ASM_AX),%edx
26319+
26320+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26321+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
26322+ cmp %_ASM_DX,%_ASM_AX
26323+ jae 1234f
26324+ add %_ASM_DX,%_ASM_AX
26325+1234:
26326+#endif
26327+
26328+#endif
26329+
26330+3: __copyuser_seg mov -3(%_ASM_AX),%edx
26331 xor %eax,%eax
26332 ASM_CLAC
26333+ pax_force_retaddr
26334 ret
26335 CFI_ENDPROC
26336 ENDPROC(__get_user_4)
26337@@ -87,10 +138,20 @@ ENTRY(__get_user_8)
26338 GET_THREAD_INFO(%_ASM_DX)
26339 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
26340 jae bad_get_user
26341+
26342+#ifdef CONFIG_PAX_MEMORY_UDEREF
26343+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
26344+ cmp %_ASM_DX,%_ASM_AX
26345+ jae 1234f
26346+ add %_ASM_DX,%_ASM_AX
26347+1234:
26348+#endif
26349+
26350 ASM_STAC
26351 4: movq -7(%_ASM_AX),%_ASM_DX
26352 xor %eax,%eax
26353 ASM_CLAC
26354+ pax_force_retaddr
26355 ret
26356 CFI_ENDPROC
26357 ENDPROC(__get_user_8)
26358@@ -101,6 +162,7 @@ bad_get_user:
26359 xor %edx,%edx
26360 mov $(-EFAULT),%_ASM_AX
26361 ASM_CLAC
26362+ pax_force_retaddr
26363 ret
26364 CFI_ENDPROC
26365 END(bad_get_user)
26366diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
26367index 54fcffe..7be149e 100644
26368--- a/arch/x86/lib/insn.c
26369+++ b/arch/x86/lib/insn.c
26370@@ -20,8 +20,10 @@
26371
26372 #ifdef __KERNEL__
26373 #include <linux/string.h>
26374+#include <asm/pgtable_types.h>
26375 #else
26376 #include <string.h>
26377+#define ktla_ktva(addr) addr
26378 #endif
26379 #include <asm/inat.h>
26380 #include <asm/insn.h>
26381@@ -53,8 +55,8 @@
26382 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
26383 {
26384 memset(insn, 0, sizeof(*insn));
26385- insn->kaddr = kaddr;
26386- insn->next_byte = kaddr;
26387+ insn->kaddr = ktla_ktva(kaddr);
26388+ insn->next_byte = ktla_ktva(kaddr);
26389 insn->x86_64 = x86_64 ? 1 : 0;
26390 insn->opnd_bytes = 4;
26391 if (x86_64)
26392diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
26393index 05a95e7..326f2fa 100644
26394--- a/arch/x86/lib/iomap_copy_64.S
26395+++ b/arch/x86/lib/iomap_copy_64.S
26396@@ -17,6 +17,7 @@
26397
26398 #include <linux/linkage.h>
26399 #include <asm/dwarf2.h>
26400+#include <asm/alternative-asm.h>
26401
26402 /*
26403 * override generic version in lib/iomap_copy.c
26404@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
26405 CFI_STARTPROC
26406 movl %edx,%ecx
26407 rep movsd
26408+ pax_force_retaddr
26409 ret
26410 CFI_ENDPROC
26411 ENDPROC(__iowrite32_copy)
26412diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
26413index 1c273be..da9cc0e 100644
26414--- a/arch/x86/lib/memcpy_64.S
26415+++ b/arch/x86/lib/memcpy_64.S
26416@@ -33,6 +33,7 @@
26417 rep movsq
26418 movl %edx, %ecx
26419 rep movsb
26420+ pax_force_retaddr
26421 ret
26422 .Lmemcpy_e:
26423 .previous
26424@@ -49,6 +50,7 @@
26425 movq %rdi, %rax
26426 movq %rdx, %rcx
26427 rep movsb
26428+ pax_force_retaddr
26429 ret
26430 .Lmemcpy_e_e:
26431 .previous
26432@@ -76,13 +78,13 @@ ENTRY(memcpy)
26433 */
26434 movq 0*8(%rsi), %r8
26435 movq 1*8(%rsi), %r9
26436- movq 2*8(%rsi), %r10
26437+ movq 2*8(%rsi), %rcx
26438 movq 3*8(%rsi), %r11
26439 leaq 4*8(%rsi), %rsi
26440
26441 movq %r8, 0*8(%rdi)
26442 movq %r9, 1*8(%rdi)
26443- movq %r10, 2*8(%rdi)
26444+ movq %rcx, 2*8(%rdi)
26445 movq %r11, 3*8(%rdi)
26446 leaq 4*8(%rdi), %rdi
26447 jae .Lcopy_forward_loop
26448@@ -105,12 +107,12 @@ ENTRY(memcpy)
26449 subq $0x20, %rdx
26450 movq -1*8(%rsi), %r8
26451 movq -2*8(%rsi), %r9
26452- movq -3*8(%rsi), %r10
26453+ movq -3*8(%rsi), %rcx
26454 movq -4*8(%rsi), %r11
26455 leaq -4*8(%rsi), %rsi
26456 movq %r8, -1*8(%rdi)
26457 movq %r9, -2*8(%rdi)
26458- movq %r10, -3*8(%rdi)
26459+ movq %rcx, -3*8(%rdi)
26460 movq %r11, -4*8(%rdi)
26461 leaq -4*8(%rdi), %rdi
26462 jae .Lcopy_backward_loop
26463@@ -130,12 +132,13 @@ ENTRY(memcpy)
26464 */
26465 movq 0*8(%rsi), %r8
26466 movq 1*8(%rsi), %r9
26467- movq -2*8(%rsi, %rdx), %r10
26468+ movq -2*8(%rsi, %rdx), %rcx
26469 movq -1*8(%rsi, %rdx), %r11
26470 movq %r8, 0*8(%rdi)
26471 movq %r9, 1*8(%rdi)
26472- movq %r10, -2*8(%rdi, %rdx)
26473+ movq %rcx, -2*8(%rdi, %rdx)
26474 movq %r11, -1*8(%rdi, %rdx)
26475+ pax_force_retaddr
26476 retq
26477 .p2align 4
26478 .Lless_16bytes:
26479@@ -148,6 +151,7 @@ ENTRY(memcpy)
26480 movq -1*8(%rsi, %rdx), %r9
26481 movq %r8, 0*8(%rdi)
26482 movq %r9, -1*8(%rdi, %rdx)
26483+ pax_force_retaddr
26484 retq
26485 .p2align 4
26486 .Lless_8bytes:
26487@@ -161,6 +165,7 @@ ENTRY(memcpy)
26488 movl -4(%rsi, %rdx), %r8d
26489 movl %ecx, (%rdi)
26490 movl %r8d, -4(%rdi, %rdx)
26491+ pax_force_retaddr
26492 retq
26493 .p2align 4
26494 .Lless_3bytes:
26495@@ -179,6 +184,7 @@ ENTRY(memcpy)
26496 movb %cl, (%rdi)
26497
26498 .Lend:
26499+ pax_force_retaddr
26500 retq
26501 CFI_ENDPROC
26502 ENDPROC(memcpy)
26503diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
26504index ee16461..c39c199 100644
26505--- a/arch/x86/lib/memmove_64.S
26506+++ b/arch/x86/lib/memmove_64.S
26507@@ -61,13 +61,13 @@ ENTRY(memmove)
26508 5:
26509 sub $0x20, %rdx
26510 movq 0*8(%rsi), %r11
26511- movq 1*8(%rsi), %r10
26512+ movq 1*8(%rsi), %rcx
26513 movq 2*8(%rsi), %r9
26514 movq 3*8(%rsi), %r8
26515 leaq 4*8(%rsi), %rsi
26516
26517 movq %r11, 0*8(%rdi)
26518- movq %r10, 1*8(%rdi)
26519+ movq %rcx, 1*8(%rdi)
26520 movq %r9, 2*8(%rdi)
26521 movq %r8, 3*8(%rdi)
26522 leaq 4*8(%rdi), %rdi
26523@@ -81,10 +81,10 @@ ENTRY(memmove)
26524 4:
26525 movq %rdx, %rcx
26526 movq -8(%rsi, %rdx), %r11
26527- lea -8(%rdi, %rdx), %r10
26528+ lea -8(%rdi, %rdx), %r9
26529 shrq $3, %rcx
26530 rep movsq
26531- movq %r11, (%r10)
26532+ movq %r11, (%r9)
26533 jmp 13f
26534 .Lmemmove_end_forward:
26535
26536@@ -95,14 +95,14 @@ ENTRY(memmove)
26537 7:
26538 movq %rdx, %rcx
26539 movq (%rsi), %r11
26540- movq %rdi, %r10
26541+ movq %rdi, %r9
26542 leaq -8(%rsi, %rdx), %rsi
26543 leaq -8(%rdi, %rdx), %rdi
26544 shrq $3, %rcx
26545 std
26546 rep movsq
26547 cld
26548- movq %r11, (%r10)
26549+ movq %r11, (%r9)
26550 jmp 13f
26551
26552 /*
26553@@ -127,13 +127,13 @@ ENTRY(memmove)
26554 8:
26555 subq $0x20, %rdx
26556 movq -1*8(%rsi), %r11
26557- movq -2*8(%rsi), %r10
26558+ movq -2*8(%rsi), %rcx
26559 movq -3*8(%rsi), %r9
26560 movq -4*8(%rsi), %r8
26561 leaq -4*8(%rsi), %rsi
26562
26563 movq %r11, -1*8(%rdi)
26564- movq %r10, -2*8(%rdi)
26565+ movq %rcx, -2*8(%rdi)
26566 movq %r9, -3*8(%rdi)
26567 movq %r8, -4*8(%rdi)
26568 leaq -4*8(%rdi), %rdi
26569@@ -151,11 +151,11 @@ ENTRY(memmove)
26570 * Move data from 16 bytes to 31 bytes.
26571 */
26572 movq 0*8(%rsi), %r11
26573- movq 1*8(%rsi), %r10
26574+ movq 1*8(%rsi), %rcx
26575 movq -2*8(%rsi, %rdx), %r9
26576 movq -1*8(%rsi, %rdx), %r8
26577 movq %r11, 0*8(%rdi)
26578- movq %r10, 1*8(%rdi)
26579+ movq %rcx, 1*8(%rdi)
26580 movq %r9, -2*8(%rdi, %rdx)
26581 movq %r8, -1*8(%rdi, %rdx)
26582 jmp 13f
26583@@ -167,9 +167,9 @@ ENTRY(memmove)
26584 * Move data from 8 bytes to 15 bytes.
26585 */
26586 movq 0*8(%rsi), %r11
26587- movq -1*8(%rsi, %rdx), %r10
26588+ movq -1*8(%rsi, %rdx), %r9
26589 movq %r11, 0*8(%rdi)
26590- movq %r10, -1*8(%rdi, %rdx)
26591+ movq %r9, -1*8(%rdi, %rdx)
26592 jmp 13f
26593 10:
26594 cmpq $4, %rdx
26595@@ -178,9 +178,9 @@ ENTRY(memmove)
26596 * Move data from 4 bytes to 7 bytes.
26597 */
26598 movl (%rsi), %r11d
26599- movl -4(%rsi, %rdx), %r10d
26600+ movl -4(%rsi, %rdx), %r9d
26601 movl %r11d, (%rdi)
26602- movl %r10d, -4(%rdi, %rdx)
26603+ movl %r9d, -4(%rdi, %rdx)
26604 jmp 13f
26605 11:
26606 cmp $2, %rdx
26607@@ -189,9 +189,9 @@ ENTRY(memmove)
26608 * Move data from 2 bytes to 3 bytes.
26609 */
26610 movw (%rsi), %r11w
26611- movw -2(%rsi, %rdx), %r10w
26612+ movw -2(%rsi, %rdx), %r9w
26613 movw %r11w, (%rdi)
26614- movw %r10w, -2(%rdi, %rdx)
26615+ movw %r9w, -2(%rdi, %rdx)
26616 jmp 13f
26617 12:
26618 cmp $1, %rdx
26619@@ -202,6 +202,7 @@ ENTRY(memmove)
26620 movb (%rsi), %r11b
26621 movb %r11b, (%rdi)
26622 13:
26623+ pax_force_retaddr
26624 retq
26625 CFI_ENDPROC
26626
26627@@ -210,6 +211,7 @@ ENTRY(memmove)
26628 /* Forward moving data. */
26629 movq %rdx, %rcx
26630 rep movsb
26631+ pax_force_retaddr
26632 retq
26633 .Lmemmove_end_forward_efs:
26634 .previous
26635diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
26636index 2dcb380..963660a 100644
26637--- a/arch/x86/lib/memset_64.S
26638+++ b/arch/x86/lib/memset_64.S
26639@@ -30,6 +30,7 @@
26640 movl %edx,%ecx
26641 rep stosb
26642 movq %r9,%rax
26643+ pax_force_retaddr
26644 ret
26645 .Lmemset_e:
26646 .previous
26647@@ -52,6 +53,7 @@
26648 movq %rdx,%rcx
26649 rep stosb
26650 movq %r9,%rax
26651+ pax_force_retaddr
26652 ret
26653 .Lmemset_e_e:
26654 .previous
26655@@ -59,7 +61,7 @@
26656 ENTRY(memset)
26657 ENTRY(__memset)
26658 CFI_STARTPROC
26659- movq %rdi,%r10
26660+ movq %rdi,%r11
26661
26662 /* expand byte value */
26663 movzbl %sil,%ecx
26664@@ -117,7 +119,8 @@ ENTRY(__memset)
26665 jnz .Lloop_1
26666
26667 .Lende:
26668- movq %r10,%rax
26669+ movq %r11,%rax
26670+ pax_force_retaddr
26671 ret
26672
26673 CFI_RESTORE_STATE
26674diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
26675index c9f2d9b..e7fd2c0 100644
26676--- a/arch/x86/lib/mmx_32.c
26677+++ b/arch/x86/lib/mmx_32.c
26678@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
26679 {
26680 void *p;
26681 int i;
26682+ unsigned long cr0;
26683
26684 if (unlikely(in_interrupt()))
26685 return __memcpy(to, from, len);
26686@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
26687 kernel_fpu_begin();
26688
26689 __asm__ __volatile__ (
26690- "1: prefetch (%0)\n" /* This set is 28 bytes */
26691- " prefetch 64(%0)\n"
26692- " prefetch 128(%0)\n"
26693- " prefetch 192(%0)\n"
26694- " prefetch 256(%0)\n"
26695+ "1: prefetch (%1)\n" /* This set is 28 bytes */
26696+ " prefetch 64(%1)\n"
26697+ " prefetch 128(%1)\n"
26698+ " prefetch 192(%1)\n"
26699+ " prefetch 256(%1)\n"
26700 "2: \n"
26701 ".section .fixup, \"ax\"\n"
26702- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26703+ "3: \n"
26704+
26705+#ifdef CONFIG_PAX_KERNEXEC
26706+ " movl %%cr0, %0\n"
26707+ " movl %0, %%eax\n"
26708+ " andl $0xFFFEFFFF, %%eax\n"
26709+ " movl %%eax, %%cr0\n"
26710+#endif
26711+
26712+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26713+
26714+#ifdef CONFIG_PAX_KERNEXEC
26715+ " movl %0, %%cr0\n"
26716+#endif
26717+
26718 " jmp 2b\n"
26719 ".previous\n"
26720 _ASM_EXTABLE(1b, 3b)
26721- : : "r" (from));
26722+ : "=&r" (cr0) : "r" (from) : "ax");
26723
26724 for ( ; i > 5; i--) {
26725 __asm__ __volatile__ (
26726- "1: prefetch 320(%0)\n"
26727- "2: movq (%0), %%mm0\n"
26728- " movq 8(%0), %%mm1\n"
26729- " movq 16(%0), %%mm2\n"
26730- " movq 24(%0), %%mm3\n"
26731- " movq %%mm0, (%1)\n"
26732- " movq %%mm1, 8(%1)\n"
26733- " movq %%mm2, 16(%1)\n"
26734- " movq %%mm3, 24(%1)\n"
26735- " movq 32(%0), %%mm0\n"
26736- " movq 40(%0), %%mm1\n"
26737- " movq 48(%0), %%mm2\n"
26738- " movq 56(%0), %%mm3\n"
26739- " movq %%mm0, 32(%1)\n"
26740- " movq %%mm1, 40(%1)\n"
26741- " movq %%mm2, 48(%1)\n"
26742- " movq %%mm3, 56(%1)\n"
26743+ "1: prefetch 320(%1)\n"
26744+ "2: movq (%1), %%mm0\n"
26745+ " movq 8(%1), %%mm1\n"
26746+ " movq 16(%1), %%mm2\n"
26747+ " movq 24(%1), %%mm3\n"
26748+ " movq %%mm0, (%2)\n"
26749+ " movq %%mm1, 8(%2)\n"
26750+ " movq %%mm2, 16(%2)\n"
26751+ " movq %%mm3, 24(%2)\n"
26752+ " movq 32(%1), %%mm0\n"
26753+ " movq 40(%1), %%mm1\n"
26754+ " movq 48(%1), %%mm2\n"
26755+ " movq 56(%1), %%mm3\n"
26756+ " movq %%mm0, 32(%2)\n"
26757+ " movq %%mm1, 40(%2)\n"
26758+ " movq %%mm2, 48(%2)\n"
26759+ " movq %%mm3, 56(%2)\n"
26760 ".section .fixup, \"ax\"\n"
26761- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26762+ "3:\n"
26763+
26764+#ifdef CONFIG_PAX_KERNEXEC
26765+ " movl %%cr0, %0\n"
26766+ " movl %0, %%eax\n"
26767+ " andl $0xFFFEFFFF, %%eax\n"
26768+ " movl %%eax, %%cr0\n"
26769+#endif
26770+
26771+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26772+
26773+#ifdef CONFIG_PAX_KERNEXEC
26774+ " movl %0, %%cr0\n"
26775+#endif
26776+
26777 " jmp 2b\n"
26778 ".previous\n"
26779 _ASM_EXTABLE(1b, 3b)
26780- : : "r" (from), "r" (to) : "memory");
26781+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
26782
26783 from += 64;
26784 to += 64;
26785@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
26786 static void fast_copy_page(void *to, void *from)
26787 {
26788 int i;
26789+ unsigned long cr0;
26790
26791 kernel_fpu_begin();
26792
26793@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
26794 * but that is for later. -AV
26795 */
26796 __asm__ __volatile__(
26797- "1: prefetch (%0)\n"
26798- " prefetch 64(%0)\n"
26799- " prefetch 128(%0)\n"
26800- " prefetch 192(%0)\n"
26801- " prefetch 256(%0)\n"
26802+ "1: prefetch (%1)\n"
26803+ " prefetch 64(%1)\n"
26804+ " prefetch 128(%1)\n"
26805+ " prefetch 192(%1)\n"
26806+ " prefetch 256(%1)\n"
26807 "2: \n"
26808 ".section .fixup, \"ax\"\n"
26809- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26810+ "3: \n"
26811+
26812+#ifdef CONFIG_PAX_KERNEXEC
26813+ " movl %%cr0, %0\n"
26814+ " movl %0, %%eax\n"
26815+ " andl $0xFFFEFFFF, %%eax\n"
26816+ " movl %%eax, %%cr0\n"
26817+#endif
26818+
26819+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26820+
26821+#ifdef CONFIG_PAX_KERNEXEC
26822+ " movl %0, %%cr0\n"
26823+#endif
26824+
26825 " jmp 2b\n"
26826 ".previous\n"
26827- _ASM_EXTABLE(1b, 3b) : : "r" (from));
26828+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
26829
26830 for (i = 0; i < (4096-320)/64; i++) {
26831 __asm__ __volatile__ (
26832- "1: prefetch 320(%0)\n"
26833- "2: movq (%0), %%mm0\n"
26834- " movntq %%mm0, (%1)\n"
26835- " movq 8(%0), %%mm1\n"
26836- " movntq %%mm1, 8(%1)\n"
26837- " movq 16(%0), %%mm2\n"
26838- " movntq %%mm2, 16(%1)\n"
26839- " movq 24(%0), %%mm3\n"
26840- " movntq %%mm3, 24(%1)\n"
26841- " movq 32(%0), %%mm4\n"
26842- " movntq %%mm4, 32(%1)\n"
26843- " movq 40(%0), %%mm5\n"
26844- " movntq %%mm5, 40(%1)\n"
26845- " movq 48(%0), %%mm6\n"
26846- " movntq %%mm6, 48(%1)\n"
26847- " movq 56(%0), %%mm7\n"
26848- " movntq %%mm7, 56(%1)\n"
26849+ "1: prefetch 320(%1)\n"
26850+ "2: movq (%1), %%mm0\n"
26851+ " movntq %%mm0, (%2)\n"
26852+ " movq 8(%1), %%mm1\n"
26853+ " movntq %%mm1, 8(%2)\n"
26854+ " movq 16(%1), %%mm2\n"
26855+ " movntq %%mm2, 16(%2)\n"
26856+ " movq 24(%1), %%mm3\n"
26857+ " movntq %%mm3, 24(%2)\n"
26858+ " movq 32(%1), %%mm4\n"
26859+ " movntq %%mm4, 32(%2)\n"
26860+ " movq 40(%1), %%mm5\n"
26861+ " movntq %%mm5, 40(%2)\n"
26862+ " movq 48(%1), %%mm6\n"
26863+ " movntq %%mm6, 48(%2)\n"
26864+ " movq 56(%1), %%mm7\n"
26865+ " movntq %%mm7, 56(%2)\n"
26866 ".section .fixup, \"ax\"\n"
26867- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26868+ "3:\n"
26869+
26870+#ifdef CONFIG_PAX_KERNEXEC
26871+ " movl %%cr0, %0\n"
26872+ " movl %0, %%eax\n"
26873+ " andl $0xFFFEFFFF, %%eax\n"
26874+ " movl %%eax, %%cr0\n"
26875+#endif
26876+
26877+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26878+
26879+#ifdef CONFIG_PAX_KERNEXEC
26880+ " movl %0, %%cr0\n"
26881+#endif
26882+
26883 " jmp 2b\n"
26884 ".previous\n"
26885- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
26886+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
26887
26888 from += 64;
26889 to += 64;
26890@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
26891 static void fast_copy_page(void *to, void *from)
26892 {
26893 int i;
26894+ unsigned long cr0;
26895
26896 kernel_fpu_begin();
26897
26898 __asm__ __volatile__ (
26899- "1: prefetch (%0)\n"
26900- " prefetch 64(%0)\n"
26901- " prefetch 128(%0)\n"
26902- " prefetch 192(%0)\n"
26903- " prefetch 256(%0)\n"
26904+ "1: prefetch (%1)\n"
26905+ " prefetch 64(%1)\n"
26906+ " prefetch 128(%1)\n"
26907+ " prefetch 192(%1)\n"
26908+ " prefetch 256(%1)\n"
26909 "2: \n"
26910 ".section .fixup, \"ax\"\n"
26911- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26912+ "3: \n"
26913+
26914+#ifdef CONFIG_PAX_KERNEXEC
26915+ " movl %%cr0, %0\n"
26916+ " movl %0, %%eax\n"
26917+ " andl $0xFFFEFFFF, %%eax\n"
26918+ " movl %%eax, %%cr0\n"
26919+#endif
26920+
26921+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26922+
26923+#ifdef CONFIG_PAX_KERNEXEC
26924+ " movl %0, %%cr0\n"
26925+#endif
26926+
26927 " jmp 2b\n"
26928 ".previous\n"
26929- _ASM_EXTABLE(1b, 3b) : : "r" (from));
26930+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
26931
26932 for (i = 0; i < 4096/64; i++) {
26933 __asm__ __volatile__ (
26934- "1: prefetch 320(%0)\n"
26935- "2: movq (%0), %%mm0\n"
26936- " movq 8(%0), %%mm1\n"
26937- " movq 16(%0), %%mm2\n"
26938- " movq 24(%0), %%mm3\n"
26939- " movq %%mm0, (%1)\n"
26940- " movq %%mm1, 8(%1)\n"
26941- " movq %%mm2, 16(%1)\n"
26942- " movq %%mm3, 24(%1)\n"
26943- " movq 32(%0), %%mm0\n"
26944- " movq 40(%0), %%mm1\n"
26945- " movq 48(%0), %%mm2\n"
26946- " movq 56(%0), %%mm3\n"
26947- " movq %%mm0, 32(%1)\n"
26948- " movq %%mm1, 40(%1)\n"
26949- " movq %%mm2, 48(%1)\n"
26950- " movq %%mm3, 56(%1)\n"
26951+ "1: prefetch 320(%1)\n"
26952+ "2: movq (%1), %%mm0\n"
26953+ " movq 8(%1), %%mm1\n"
26954+ " movq 16(%1), %%mm2\n"
26955+ " movq 24(%1), %%mm3\n"
26956+ " movq %%mm0, (%2)\n"
26957+ " movq %%mm1, 8(%2)\n"
26958+ " movq %%mm2, 16(%2)\n"
26959+ " movq %%mm3, 24(%2)\n"
26960+ " movq 32(%1), %%mm0\n"
26961+ " movq 40(%1), %%mm1\n"
26962+ " movq 48(%1), %%mm2\n"
26963+ " movq 56(%1), %%mm3\n"
26964+ " movq %%mm0, 32(%2)\n"
26965+ " movq %%mm1, 40(%2)\n"
26966+ " movq %%mm2, 48(%2)\n"
26967+ " movq %%mm3, 56(%2)\n"
26968 ".section .fixup, \"ax\"\n"
26969- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26970+ "3:\n"
26971+
26972+#ifdef CONFIG_PAX_KERNEXEC
26973+ " movl %%cr0, %0\n"
26974+ " movl %0, %%eax\n"
26975+ " andl $0xFFFEFFFF, %%eax\n"
26976+ " movl %%eax, %%cr0\n"
26977+#endif
26978+
26979+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26980+
26981+#ifdef CONFIG_PAX_KERNEXEC
26982+ " movl %0, %%cr0\n"
26983+#endif
26984+
26985 " jmp 2b\n"
26986 ".previous\n"
26987 _ASM_EXTABLE(1b, 3b)
26988- : : "r" (from), "r" (to) : "memory");
26989+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
26990
26991 from += 64;
26992 to += 64;
26993diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
26994index f6d13ee..aca5f0b 100644
26995--- a/arch/x86/lib/msr-reg.S
26996+++ b/arch/x86/lib/msr-reg.S
26997@@ -3,6 +3,7 @@
26998 #include <asm/dwarf2.h>
26999 #include <asm/asm.h>
27000 #include <asm/msr.h>
27001+#include <asm/alternative-asm.h>
27002
27003 #ifdef CONFIG_X86_64
27004 /*
27005@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
27006 CFI_STARTPROC
27007 pushq_cfi %rbx
27008 pushq_cfi %rbp
27009- movq %rdi, %r10 /* Save pointer */
27010+ movq %rdi, %r9 /* Save pointer */
27011 xorl %r11d, %r11d /* Return value */
27012 movl (%rdi), %eax
27013 movl 4(%rdi), %ecx
27014@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
27015 movl 28(%rdi), %edi
27016 CFI_REMEMBER_STATE
27017 1: \op
27018-2: movl %eax, (%r10)
27019+2: movl %eax, (%r9)
27020 movl %r11d, %eax /* Return value */
27021- movl %ecx, 4(%r10)
27022- movl %edx, 8(%r10)
27023- movl %ebx, 12(%r10)
27024- movl %ebp, 20(%r10)
27025- movl %esi, 24(%r10)
27026- movl %edi, 28(%r10)
27027+ movl %ecx, 4(%r9)
27028+ movl %edx, 8(%r9)
27029+ movl %ebx, 12(%r9)
27030+ movl %ebp, 20(%r9)
27031+ movl %esi, 24(%r9)
27032+ movl %edi, 28(%r9)
27033 popq_cfi %rbp
27034 popq_cfi %rbx
27035+ pax_force_retaddr
27036 ret
27037 3:
27038 CFI_RESTORE_STATE
27039diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
27040index fc6ba17..04471c5 100644
27041--- a/arch/x86/lib/putuser.S
27042+++ b/arch/x86/lib/putuser.S
27043@@ -16,7 +16,9 @@
27044 #include <asm/errno.h>
27045 #include <asm/asm.h>
27046 #include <asm/smap.h>
27047-
27048+#include <asm/segment.h>
27049+#include <asm/pgtable.h>
27050+#include <asm/alternative-asm.h>
27051
27052 /*
27053 * __put_user_X
27054@@ -30,57 +32,125 @@
27055 * as they get called from within inline assembly.
27056 */
27057
27058-#define ENTER CFI_STARTPROC ; \
27059- GET_THREAD_INFO(%_ASM_BX)
27060-#define EXIT ASM_CLAC ; \
27061- ret ; \
27062+#define ENTER CFI_STARTPROC
27063+#define EXIT ASM_CLAC ; \
27064+ pax_force_retaddr ; \
27065+ ret ; \
27066 CFI_ENDPROC
27067
27068+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27069+#define _DEST %_ASM_CX,%_ASM_BX
27070+#else
27071+#define _DEST %_ASM_CX
27072+#endif
27073+
27074+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
27075+#define __copyuser_seg gs;
27076+#else
27077+#define __copyuser_seg
27078+#endif
27079+
27080 .text
27081 ENTRY(__put_user_1)
27082 ENTER
27083+
27084+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
27085+ GET_THREAD_INFO(%_ASM_BX)
27086 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
27087 jae bad_put_user
27088 ASM_STAC
27089-1: movb %al,(%_ASM_CX)
27090+
27091+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27092+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
27093+ cmp %_ASM_BX,%_ASM_CX
27094+ jb 1234f
27095+ xor %ebx,%ebx
27096+1234:
27097+#endif
27098+
27099+#endif
27100+
27101+1: __copyuser_seg movb %al,(_DEST)
27102 xor %eax,%eax
27103 EXIT
27104 ENDPROC(__put_user_1)
27105
27106 ENTRY(__put_user_2)
27107 ENTER
27108+
27109+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
27110+ GET_THREAD_INFO(%_ASM_BX)
27111 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
27112 sub $1,%_ASM_BX
27113 cmp %_ASM_BX,%_ASM_CX
27114 jae bad_put_user
27115 ASM_STAC
27116-2: movw %ax,(%_ASM_CX)
27117+
27118+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27119+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
27120+ cmp %_ASM_BX,%_ASM_CX
27121+ jb 1234f
27122+ xor %ebx,%ebx
27123+1234:
27124+#endif
27125+
27126+#endif
27127+
27128+2: __copyuser_seg movw %ax,(_DEST)
27129 xor %eax,%eax
27130 EXIT
27131 ENDPROC(__put_user_2)
27132
27133 ENTRY(__put_user_4)
27134 ENTER
27135+
27136+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
27137+ GET_THREAD_INFO(%_ASM_BX)
27138 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
27139 sub $3,%_ASM_BX
27140 cmp %_ASM_BX,%_ASM_CX
27141 jae bad_put_user
27142 ASM_STAC
27143-3: movl %eax,(%_ASM_CX)
27144+
27145+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27146+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
27147+ cmp %_ASM_BX,%_ASM_CX
27148+ jb 1234f
27149+ xor %ebx,%ebx
27150+1234:
27151+#endif
27152+
27153+#endif
27154+
27155+3: __copyuser_seg movl %eax,(_DEST)
27156 xor %eax,%eax
27157 EXIT
27158 ENDPROC(__put_user_4)
27159
27160 ENTRY(__put_user_8)
27161 ENTER
27162+
27163+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
27164+ GET_THREAD_INFO(%_ASM_BX)
27165 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
27166 sub $7,%_ASM_BX
27167 cmp %_ASM_BX,%_ASM_CX
27168 jae bad_put_user
27169 ASM_STAC
27170-4: mov %_ASM_AX,(%_ASM_CX)
27171+
27172+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27173+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
27174+ cmp %_ASM_BX,%_ASM_CX
27175+ jb 1234f
27176+ xor %ebx,%ebx
27177+1234:
27178+#endif
27179+
27180+#endif
27181+
27182+4: __copyuser_seg mov %_ASM_AX,(_DEST)
27183 #ifdef CONFIG_X86_32
27184-5: movl %edx,4(%_ASM_CX)
27185+5: __copyuser_seg movl %edx,4(_DEST)
27186 #endif
27187 xor %eax,%eax
27188 EXIT
27189diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
27190index 1cad221..de671ee 100644
27191--- a/arch/x86/lib/rwlock.S
27192+++ b/arch/x86/lib/rwlock.S
27193@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
27194 FRAME
27195 0: LOCK_PREFIX
27196 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
27197+
27198+#ifdef CONFIG_PAX_REFCOUNT
27199+ jno 1234f
27200+ LOCK_PREFIX
27201+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
27202+ int $4
27203+1234:
27204+ _ASM_EXTABLE(1234b, 1234b)
27205+#endif
27206+
27207 1: rep; nop
27208 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
27209 jne 1b
27210 LOCK_PREFIX
27211 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
27212+
27213+#ifdef CONFIG_PAX_REFCOUNT
27214+ jno 1234f
27215+ LOCK_PREFIX
27216+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
27217+ int $4
27218+1234:
27219+ _ASM_EXTABLE(1234b, 1234b)
27220+#endif
27221+
27222 jnz 0b
27223 ENDFRAME
27224+ pax_force_retaddr
27225 ret
27226 CFI_ENDPROC
27227 END(__write_lock_failed)
27228@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
27229 FRAME
27230 0: LOCK_PREFIX
27231 READ_LOCK_SIZE(inc) (%__lock_ptr)
27232+
27233+#ifdef CONFIG_PAX_REFCOUNT
27234+ jno 1234f
27235+ LOCK_PREFIX
27236+ READ_LOCK_SIZE(dec) (%__lock_ptr)
27237+ int $4
27238+1234:
27239+ _ASM_EXTABLE(1234b, 1234b)
27240+#endif
27241+
27242 1: rep; nop
27243 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
27244 js 1b
27245 LOCK_PREFIX
27246 READ_LOCK_SIZE(dec) (%__lock_ptr)
27247+
27248+#ifdef CONFIG_PAX_REFCOUNT
27249+ jno 1234f
27250+ LOCK_PREFIX
27251+ READ_LOCK_SIZE(inc) (%__lock_ptr)
27252+ int $4
27253+1234:
27254+ _ASM_EXTABLE(1234b, 1234b)
27255+#endif
27256+
27257 js 0b
27258 ENDFRAME
27259+ pax_force_retaddr
27260 ret
27261 CFI_ENDPROC
27262 END(__read_lock_failed)
27263diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
27264index 5dff5f0..cadebf4 100644
27265--- a/arch/x86/lib/rwsem.S
27266+++ b/arch/x86/lib/rwsem.S
27267@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
27268 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
27269 CFI_RESTORE __ASM_REG(dx)
27270 restore_common_regs
27271+ pax_force_retaddr
27272 ret
27273 CFI_ENDPROC
27274 ENDPROC(call_rwsem_down_read_failed)
27275@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
27276 movq %rax,%rdi
27277 call rwsem_down_write_failed
27278 restore_common_regs
27279+ pax_force_retaddr
27280 ret
27281 CFI_ENDPROC
27282 ENDPROC(call_rwsem_down_write_failed)
27283@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
27284 movq %rax,%rdi
27285 call rwsem_wake
27286 restore_common_regs
27287-1: ret
27288+1: pax_force_retaddr
27289+ ret
27290 CFI_ENDPROC
27291 ENDPROC(call_rwsem_wake)
27292
27293@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
27294 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
27295 CFI_RESTORE __ASM_REG(dx)
27296 restore_common_regs
27297+ pax_force_retaddr
27298 ret
27299 CFI_ENDPROC
27300 ENDPROC(call_rwsem_downgrade_wake)
27301diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
27302index a63efd6..ccecad8 100644
27303--- a/arch/x86/lib/thunk_64.S
27304+++ b/arch/x86/lib/thunk_64.S
27305@@ -8,6 +8,7 @@
27306 #include <linux/linkage.h>
27307 #include <asm/dwarf2.h>
27308 #include <asm/calling.h>
27309+#include <asm/alternative-asm.h>
27310
27311 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
27312 .macro THUNK name, func, put_ret_addr_in_rdi=0
27313@@ -41,5 +42,6 @@
27314 SAVE_ARGS
27315 restore:
27316 RESTORE_ARGS
27317+ pax_force_retaddr
27318 ret
27319 CFI_ENDPROC
27320diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
27321index f0312d7..9c39d63 100644
27322--- a/arch/x86/lib/usercopy_32.c
27323+++ b/arch/x86/lib/usercopy_32.c
27324@@ -42,11 +42,13 @@ do { \
27325 int __d0; \
27326 might_fault(); \
27327 __asm__ __volatile__( \
27328+ __COPYUSER_SET_ES \
27329 ASM_STAC "\n" \
27330 "0: rep; stosl\n" \
27331 " movl %2,%0\n" \
27332 "1: rep; stosb\n" \
27333 "2: " ASM_CLAC "\n" \
27334+ __COPYUSER_RESTORE_ES \
27335 ".section .fixup,\"ax\"\n" \
27336 "3: lea 0(%2,%0,4),%0\n" \
27337 " jmp 2b\n" \
27338@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
27339
27340 #ifdef CONFIG_X86_INTEL_USERCOPY
27341 static unsigned long
27342-__copy_user_intel(void __user *to, const void *from, unsigned long size)
27343+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
27344 {
27345 int d0, d1;
27346 __asm__ __volatile__(
27347@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
27348 " .align 2,0x90\n"
27349 "3: movl 0(%4), %%eax\n"
27350 "4: movl 4(%4), %%edx\n"
27351- "5: movl %%eax, 0(%3)\n"
27352- "6: movl %%edx, 4(%3)\n"
27353+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
27354+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
27355 "7: movl 8(%4), %%eax\n"
27356 "8: movl 12(%4),%%edx\n"
27357- "9: movl %%eax, 8(%3)\n"
27358- "10: movl %%edx, 12(%3)\n"
27359+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
27360+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
27361 "11: movl 16(%4), %%eax\n"
27362 "12: movl 20(%4), %%edx\n"
27363- "13: movl %%eax, 16(%3)\n"
27364- "14: movl %%edx, 20(%3)\n"
27365+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
27366+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
27367 "15: movl 24(%4), %%eax\n"
27368 "16: movl 28(%4), %%edx\n"
27369- "17: movl %%eax, 24(%3)\n"
27370- "18: movl %%edx, 28(%3)\n"
27371+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
27372+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
27373 "19: movl 32(%4), %%eax\n"
27374 "20: movl 36(%4), %%edx\n"
27375- "21: movl %%eax, 32(%3)\n"
27376- "22: movl %%edx, 36(%3)\n"
27377+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
27378+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
27379 "23: movl 40(%4), %%eax\n"
27380 "24: movl 44(%4), %%edx\n"
27381- "25: movl %%eax, 40(%3)\n"
27382- "26: movl %%edx, 44(%3)\n"
27383+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
27384+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
27385 "27: movl 48(%4), %%eax\n"
27386 "28: movl 52(%4), %%edx\n"
27387- "29: movl %%eax, 48(%3)\n"
27388- "30: movl %%edx, 52(%3)\n"
27389+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
27390+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
27391 "31: movl 56(%4), %%eax\n"
27392 "32: movl 60(%4), %%edx\n"
27393- "33: movl %%eax, 56(%3)\n"
27394- "34: movl %%edx, 60(%3)\n"
27395+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
27396+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
27397 " addl $-64, %0\n"
27398 " addl $64, %4\n"
27399 " addl $64, %3\n"
27400@@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
27401 " shrl $2, %0\n"
27402 " andl $3, %%eax\n"
27403 " cld\n"
27404+ __COPYUSER_SET_ES
27405 "99: rep; movsl\n"
27406 "36: movl %%eax, %0\n"
27407 "37: rep; movsb\n"
27408 "100:\n"
27409+ __COPYUSER_RESTORE_ES
27410 ".section .fixup,\"ax\"\n"
27411 "101: lea 0(%%eax,%0,4),%0\n"
27412 " jmp 100b\n"
27413@@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
27414 }
27415
27416 static unsigned long
27417+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
27418+{
27419+ int d0, d1;
27420+ __asm__ __volatile__(
27421+ " .align 2,0x90\n"
27422+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
27423+ " cmpl $67, %0\n"
27424+ " jbe 3f\n"
27425+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
27426+ " .align 2,0x90\n"
27427+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
27428+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
27429+ "5: movl %%eax, 0(%3)\n"
27430+ "6: movl %%edx, 4(%3)\n"
27431+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
27432+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
27433+ "9: movl %%eax, 8(%3)\n"
27434+ "10: movl %%edx, 12(%3)\n"
27435+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
27436+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
27437+ "13: movl %%eax, 16(%3)\n"
27438+ "14: movl %%edx, 20(%3)\n"
27439+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
27440+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
27441+ "17: movl %%eax, 24(%3)\n"
27442+ "18: movl %%edx, 28(%3)\n"
27443+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
27444+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
27445+ "21: movl %%eax, 32(%3)\n"
27446+ "22: movl %%edx, 36(%3)\n"
27447+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
27448+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
27449+ "25: movl %%eax, 40(%3)\n"
27450+ "26: movl %%edx, 44(%3)\n"
27451+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
27452+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
27453+ "29: movl %%eax, 48(%3)\n"
27454+ "30: movl %%edx, 52(%3)\n"
27455+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
27456+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
27457+ "33: movl %%eax, 56(%3)\n"
27458+ "34: movl %%edx, 60(%3)\n"
27459+ " addl $-64, %0\n"
27460+ " addl $64, %4\n"
27461+ " addl $64, %3\n"
27462+ " cmpl $63, %0\n"
27463+ " ja 1b\n"
27464+ "35: movl %0, %%eax\n"
27465+ " shrl $2, %0\n"
27466+ " andl $3, %%eax\n"
27467+ " cld\n"
27468+ "99: rep; "__copyuser_seg" movsl\n"
27469+ "36: movl %%eax, %0\n"
27470+ "37: rep; "__copyuser_seg" movsb\n"
27471+ "100:\n"
27472+ ".section .fixup,\"ax\"\n"
27473+ "101: lea 0(%%eax,%0,4),%0\n"
27474+ " jmp 100b\n"
27475+ ".previous\n"
27476+ _ASM_EXTABLE(1b,100b)
27477+ _ASM_EXTABLE(2b,100b)
27478+ _ASM_EXTABLE(3b,100b)
27479+ _ASM_EXTABLE(4b,100b)
27480+ _ASM_EXTABLE(5b,100b)
27481+ _ASM_EXTABLE(6b,100b)
27482+ _ASM_EXTABLE(7b,100b)
27483+ _ASM_EXTABLE(8b,100b)
27484+ _ASM_EXTABLE(9b,100b)
27485+ _ASM_EXTABLE(10b,100b)
27486+ _ASM_EXTABLE(11b,100b)
27487+ _ASM_EXTABLE(12b,100b)
27488+ _ASM_EXTABLE(13b,100b)
27489+ _ASM_EXTABLE(14b,100b)
27490+ _ASM_EXTABLE(15b,100b)
27491+ _ASM_EXTABLE(16b,100b)
27492+ _ASM_EXTABLE(17b,100b)
27493+ _ASM_EXTABLE(18b,100b)
27494+ _ASM_EXTABLE(19b,100b)
27495+ _ASM_EXTABLE(20b,100b)
27496+ _ASM_EXTABLE(21b,100b)
27497+ _ASM_EXTABLE(22b,100b)
27498+ _ASM_EXTABLE(23b,100b)
27499+ _ASM_EXTABLE(24b,100b)
27500+ _ASM_EXTABLE(25b,100b)
27501+ _ASM_EXTABLE(26b,100b)
27502+ _ASM_EXTABLE(27b,100b)
27503+ _ASM_EXTABLE(28b,100b)
27504+ _ASM_EXTABLE(29b,100b)
27505+ _ASM_EXTABLE(30b,100b)
27506+ _ASM_EXTABLE(31b,100b)
27507+ _ASM_EXTABLE(32b,100b)
27508+ _ASM_EXTABLE(33b,100b)
27509+ _ASM_EXTABLE(34b,100b)
27510+ _ASM_EXTABLE(35b,100b)
27511+ _ASM_EXTABLE(36b,100b)
27512+ _ASM_EXTABLE(37b,100b)
27513+ _ASM_EXTABLE(99b,101b)
27514+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
27515+ : "1"(to), "2"(from), "0"(size)
27516+ : "eax", "edx", "memory");
27517+ return size;
27518+}
27519+
27520+static unsigned long __size_overflow(3)
27521 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
27522 {
27523 int d0, d1;
27524 __asm__ __volatile__(
27525 " .align 2,0x90\n"
27526- "0: movl 32(%4), %%eax\n"
27527+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
27528 " cmpl $67, %0\n"
27529 " jbe 2f\n"
27530- "1: movl 64(%4), %%eax\n"
27531+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
27532 " .align 2,0x90\n"
27533- "2: movl 0(%4), %%eax\n"
27534- "21: movl 4(%4), %%edx\n"
27535+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
27536+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
27537 " movl %%eax, 0(%3)\n"
27538 " movl %%edx, 4(%3)\n"
27539- "3: movl 8(%4), %%eax\n"
27540- "31: movl 12(%4),%%edx\n"
27541+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
27542+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
27543 " movl %%eax, 8(%3)\n"
27544 " movl %%edx, 12(%3)\n"
27545- "4: movl 16(%4), %%eax\n"
27546- "41: movl 20(%4), %%edx\n"
27547+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
27548+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
27549 " movl %%eax, 16(%3)\n"
27550 " movl %%edx, 20(%3)\n"
27551- "10: movl 24(%4), %%eax\n"
27552- "51: movl 28(%4), %%edx\n"
27553+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
27554+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
27555 " movl %%eax, 24(%3)\n"
27556 " movl %%edx, 28(%3)\n"
27557- "11: movl 32(%4), %%eax\n"
27558- "61: movl 36(%4), %%edx\n"
27559+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
27560+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
27561 " movl %%eax, 32(%3)\n"
27562 " movl %%edx, 36(%3)\n"
27563- "12: movl 40(%4), %%eax\n"
27564- "71: movl 44(%4), %%edx\n"
27565+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
27566+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
27567 " movl %%eax, 40(%3)\n"
27568 " movl %%edx, 44(%3)\n"
27569- "13: movl 48(%4), %%eax\n"
27570- "81: movl 52(%4), %%edx\n"
27571+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
27572+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
27573 " movl %%eax, 48(%3)\n"
27574 " movl %%edx, 52(%3)\n"
27575- "14: movl 56(%4), %%eax\n"
27576- "91: movl 60(%4), %%edx\n"
27577+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
27578+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
27579 " movl %%eax, 56(%3)\n"
27580 " movl %%edx, 60(%3)\n"
27581 " addl $-64, %0\n"
27582@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
27583 " shrl $2, %0\n"
27584 " andl $3, %%eax\n"
27585 " cld\n"
27586- "6: rep; movsl\n"
27587+ "6: rep; "__copyuser_seg" movsl\n"
27588 " movl %%eax,%0\n"
27589- "7: rep; movsb\n"
27590+ "7: rep; "__copyuser_seg" movsb\n"
27591 "8:\n"
27592 ".section .fixup,\"ax\"\n"
27593 "9: lea 0(%%eax,%0,4),%0\n"
27594@@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
27595 * hyoshiok@miraclelinux.com
27596 */
27597
27598-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
27599+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
27600 const void __user *from, unsigned long size)
27601 {
27602 int d0, d1;
27603
27604 __asm__ __volatile__(
27605 " .align 2,0x90\n"
27606- "0: movl 32(%4), %%eax\n"
27607+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
27608 " cmpl $67, %0\n"
27609 " jbe 2f\n"
27610- "1: movl 64(%4), %%eax\n"
27611+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
27612 " .align 2,0x90\n"
27613- "2: movl 0(%4), %%eax\n"
27614- "21: movl 4(%4), %%edx\n"
27615+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
27616+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
27617 " movnti %%eax, 0(%3)\n"
27618 " movnti %%edx, 4(%3)\n"
27619- "3: movl 8(%4), %%eax\n"
27620- "31: movl 12(%4),%%edx\n"
27621+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
27622+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
27623 " movnti %%eax, 8(%3)\n"
27624 " movnti %%edx, 12(%3)\n"
27625- "4: movl 16(%4), %%eax\n"
27626- "41: movl 20(%4), %%edx\n"
27627+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
27628+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
27629 " movnti %%eax, 16(%3)\n"
27630 " movnti %%edx, 20(%3)\n"
27631- "10: movl 24(%4), %%eax\n"
27632- "51: movl 28(%4), %%edx\n"
27633+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
27634+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
27635 " movnti %%eax, 24(%3)\n"
27636 " movnti %%edx, 28(%3)\n"
27637- "11: movl 32(%4), %%eax\n"
27638- "61: movl 36(%4), %%edx\n"
27639+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
27640+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
27641 " movnti %%eax, 32(%3)\n"
27642 " movnti %%edx, 36(%3)\n"
27643- "12: movl 40(%4), %%eax\n"
27644- "71: movl 44(%4), %%edx\n"
27645+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
27646+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
27647 " movnti %%eax, 40(%3)\n"
27648 " movnti %%edx, 44(%3)\n"
27649- "13: movl 48(%4), %%eax\n"
27650- "81: movl 52(%4), %%edx\n"
27651+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
27652+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
27653 " movnti %%eax, 48(%3)\n"
27654 " movnti %%edx, 52(%3)\n"
27655- "14: movl 56(%4), %%eax\n"
27656- "91: movl 60(%4), %%edx\n"
27657+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
27658+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
27659 " movnti %%eax, 56(%3)\n"
27660 " movnti %%edx, 60(%3)\n"
27661 " addl $-64, %0\n"
27662@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
27663 " shrl $2, %0\n"
27664 " andl $3, %%eax\n"
27665 " cld\n"
27666- "6: rep; movsl\n"
27667+ "6: rep; "__copyuser_seg" movsl\n"
27668 " movl %%eax,%0\n"
27669- "7: rep; movsb\n"
27670+ "7: rep; "__copyuser_seg" movsb\n"
27671 "8:\n"
27672 ".section .fixup,\"ax\"\n"
27673 "9: lea 0(%%eax,%0,4),%0\n"
27674@@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
27675 return size;
27676 }
27677
27678-static unsigned long __copy_user_intel_nocache(void *to,
27679+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
27680 const void __user *from, unsigned long size)
27681 {
27682 int d0, d1;
27683
27684 __asm__ __volatile__(
27685 " .align 2,0x90\n"
27686- "0: movl 32(%4), %%eax\n"
27687+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
27688 " cmpl $67, %0\n"
27689 " jbe 2f\n"
27690- "1: movl 64(%4), %%eax\n"
27691+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
27692 " .align 2,0x90\n"
27693- "2: movl 0(%4), %%eax\n"
27694- "21: movl 4(%4), %%edx\n"
27695+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
27696+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
27697 " movnti %%eax, 0(%3)\n"
27698 " movnti %%edx, 4(%3)\n"
27699- "3: movl 8(%4), %%eax\n"
27700- "31: movl 12(%4),%%edx\n"
27701+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
27702+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
27703 " movnti %%eax, 8(%3)\n"
27704 " movnti %%edx, 12(%3)\n"
27705- "4: movl 16(%4), %%eax\n"
27706- "41: movl 20(%4), %%edx\n"
27707+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
27708+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
27709 " movnti %%eax, 16(%3)\n"
27710 " movnti %%edx, 20(%3)\n"
27711- "10: movl 24(%4), %%eax\n"
27712- "51: movl 28(%4), %%edx\n"
27713+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
27714+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
27715 " movnti %%eax, 24(%3)\n"
27716 " movnti %%edx, 28(%3)\n"
27717- "11: movl 32(%4), %%eax\n"
27718- "61: movl 36(%4), %%edx\n"
27719+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
27720+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
27721 " movnti %%eax, 32(%3)\n"
27722 " movnti %%edx, 36(%3)\n"
27723- "12: movl 40(%4), %%eax\n"
27724- "71: movl 44(%4), %%edx\n"
27725+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
27726+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
27727 " movnti %%eax, 40(%3)\n"
27728 " movnti %%edx, 44(%3)\n"
27729- "13: movl 48(%4), %%eax\n"
27730- "81: movl 52(%4), %%edx\n"
27731+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
27732+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
27733 " movnti %%eax, 48(%3)\n"
27734 " movnti %%edx, 52(%3)\n"
27735- "14: movl 56(%4), %%eax\n"
27736- "91: movl 60(%4), %%edx\n"
27737+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
27738+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
27739 " movnti %%eax, 56(%3)\n"
27740 " movnti %%edx, 60(%3)\n"
27741 " addl $-64, %0\n"
27742@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
27743 " shrl $2, %0\n"
27744 " andl $3, %%eax\n"
27745 " cld\n"
27746- "6: rep; movsl\n"
27747+ "6: rep; "__copyuser_seg" movsl\n"
27748 " movl %%eax,%0\n"
27749- "7: rep; movsb\n"
27750+ "7: rep; "__copyuser_seg" movsb\n"
27751 "8:\n"
27752 ".section .fixup,\"ax\"\n"
27753 "9: lea 0(%%eax,%0,4),%0\n"
27754@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
27755 */
27756 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
27757 unsigned long size);
27758-unsigned long __copy_user_intel(void __user *to, const void *from,
27759+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
27760+ unsigned long size);
27761+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
27762 unsigned long size);
27763 unsigned long __copy_user_zeroing_intel_nocache(void *to,
27764 const void __user *from, unsigned long size);
27765 #endif /* CONFIG_X86_INTEL_USERCOPY */
27766
27767 /* Generic arbitrary sized copy. */
27768-#define __copy_user(to, from, size) \
27769+#define __copy_user(to, from, size, prefix, set, restore) \
27770 do { \
27771 int __d0, __d1, __d2; \
27772 __asm__ __volatile__( \
27773+ set \
27774 " cmp $7,%0\n" \
27775 " jbe 1f\n" \
27776 " movl %1,%0\n" \
27777 " negl %0\n" \
27778 " andl $7,%0\n" \
27779 " subl %0,%3\n" \
27780- "4: rep; movsb\n" \
27781+ "4: rep; "prefix"movsb\n" \
27782 " movl %3,%0\n" \
27783 " shrl $2,%0\n" \
27784 " andl $3,%3\n" \
27785 " .align 2,0x90\n" \
27786- "0: rep; movsl\n" \
27787+ "0: rep; "prefix"movsl\n" \
27788 " movl %3,%0\n" \
27789- "1: rep; movsb\n" \
27790+ "1: rep; "prefix"movsb\n" \
27791 "2:\n" \
27792+ restore \
27793 ".section .fixup,\"ax\"\n" \
27794 "5: addl %3,%0\n" \
27795 " jmp 2b\n" \
27796@@ -538,14 +650,14 @@ do { \
27797 " negl %0\n" \
27798 " andl $7,%0\n" \
27799 " subl %0,%3\n" \
27800- "4: rep; movsb\n" \
27801+ "4: rep; "__copyuser_seg"movsb\n" \
27802 " movl %3,%0\n" \
27803 " shrl $2,%0\n" \
27804 " andl $3,%3\n" \
27805 " .align 2,0x90\n" \
27806- "0: rep; movsl\n" \
27807+ "0: rep; "__copyuser_seg"movsl\n" \
27808 " movl %3,%0\n" \
27809- "1: rep; movsb\n" \
27810+ "1: rep; "__copyuser_seg"movsb\n" \
27811 "2:\n" \
27812 ".section .fixup,\"ax\"\n" \
27813 "5: addl %3,%0\n" \
27814@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
27815 {
27816 stac();
27817 if (movsl_is_ok(to, from, n))
27818- __copy_user(to, from, n);
27819+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
27820 else
27821- n = __copy_user_intel(to, from, n);
27822+ n = __generic_copy_to_user_intel(to, from, n);
27823 clac();
27824 return n;
27825 }
27826@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
27827 {
27828 stac();
27829 if (movsl_is_ok(to, from, n))
27830- __copy_user(to, from, n);
27831+ __copy_user(to, from, n, __copyuser_seg, "", "");
27832 else
27833- n = __copy_user_intel((void __user *)to,
27834- (const void *)from, n);
27835+ n = __generic_copy_from_user_intel(to, from, n);
27836 clac();
27837 return n;
27838 }
27839@@ -632,66 +743,51 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
27840 if (n > 64 && cpu_has_xmm2)
27841 n = __copy_user_intel_nocache(to, from, n);
27842 else
27843- __copy_user(to, from, n);
27844+ __copy_user(to, from, n, __copyuser_seg, "", "");
27845 #else
27846- __copy_user(to, from, n);
27847+ __copy_user(to, from, n, __copyuser_seg, "", "");
27848 #endif
27849 clac();
27850 return n;
27851 }
27852 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
27853
27854-/**
27855- * copy_to_user: - Copy a block of data into user space.
27856- * @to: Destination address, in user space.
27857- * @from: Source address, in kernel space.
27858- * @n: Number of bytes to copy.
27859- *
27860- * Context: User context only. This function may sleep.
27861- *
27862- * Copy data from kernel space to user space.
27863- *
27864- * Returns number of bytes that could not be copied.
27865- * On success, this will be zero.
27866- */
27867-unsigned long
27868-copy_to_user(void __user *to, const void *from, unsigned long n)
27869-{
27870- if (access_ok(VERIFY_WRITE, to, n))
27871- n = __copy_to_user(to, from, n);
27872- return n;
27873-}
27874-EXPORT_SYMBOL(copy_to_user);
27875-
27876-/**
27877- * copy_from_user: - Copy a block of data from user space.
27878- * @to: Destination address, in kernel space.
27879- * @from: Source address, in user space.
27880- * @n: Number of bytes to copy.
27881- *
27882- * Context: User context only. This function may sleep.
27883- *
27884- * Copy data from user space to kernel space.
27885- *
27886- * Returns number of bytes that could not be copied.
27887- * On success, this will be zero.
27888- *
27889- * If some data could not be copied, this function will pad the copied
27890- * data to the requested size using zero bytes.
27891- */
27892-unsigned long
27893-_copy_from_user(void *to, const void __user *from, unsigned long n)
27894-{
27895- if (access_ok(VERIFY_READ, from, n))
27896- n = __copy_from_user(to, from, n);
27897- else
27898- memset(to, 0, n);
27899- return n;
27900-}
27901-EXPORT_SYMBOL(_copy_from_user);
27902-
27903 void copy_from_user_overflow(void)
27904 {
27905 WARN(1, "Buffer overflow detected!\n");
27906 }
27907 EXPORT_SYMBOL(copy_from_user_overflow);
27908+
27909+void copy_to_user_overflow(void)
27910+{
27911+ WARN(1, "Buffer overflow detected!\n");
27912+}
27913+EXPORT_SYMBOL(copy_to_user_overflow);
27914+
27915+#ifdef CONFIG_PAX_MEMORY_UDEREF
27916+void __set_fs(mm_segment_t x)
27917+{
27918+ switch (x.seg) {
27919+ case 0:
27920+ loadsegment(gs, 0);
27921+ break;
27922+ case TASK_SIZE_MAX:
27923+ loadsegment(gs, __USER_DS);
27924+ break;
27925+ case -1UL:
27926+ loadsegment(gs, __KERNEL_DS);
27927+ break;
27928+ default:
27929+ BUG();
27930+ }
27931+ return;
27932+}
27933+EXPORT_SYMBOL(__set_fs);
27934+
27935+void set_fs(mm_segment_t x)
27936+{
27937+ current_thread_info()->addr_limit = x;
27938+ __set_fs(x);
27939+}
27940+EXPORT_SYMBOL(set_fs);
27941+#endif
27942diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
27943index 906fea3..ee8a097 100644
27944--- a/arch/x86/lib/usercopy_64.c
27945+++ b/arch/x86/lib/usercopy_64.c
27946@@ -39,7 +39,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
27947 _ASM_EXTABLE(0b,3b)
27948 _ASM_EXTABLE(1b,2b)
27949 : [size8] "=&c"(size), [dst] "=&D" (__d0)
27950- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
27951+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
27952 [zero] "r" (0UL), [eight] "r" (8UL));
27953 clac();
27954 return size;
27955@@ -54,12 +54,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
27956 }
27957 EXPORT_SYMBOL(clear_user);
27958
27959-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
27960+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
27961 {
27962- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
27963- return copy_user_generic((__force void *)to, (__force void *)from, len);
27964- }
27965- return len;
27966+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
27967+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
27968+ return len;
27969 }
27970 EXPORT_SYMBOL(copy_in_user);
27971
27972@@ -69,7 +68,7 @@ EXPORT_SYMBOL(copy_in_user);
27973 * it is not necessary to optimize tail handling.
27974 */
27975 unsigned long
27976-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
27977+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
27978 {
27979 char c;
27980 unsigned zero_len;
27981@@ -87,3 +86,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
27982 clac();
27983 return len;
27984 }
27985+
27986+void copy_from_user_overflow(void)
27987+{
27988+ WARN(1, "Buffer overflow detected!\n");
27989+}
27990+EXPORT_SYMBOL(copy_from_user_overflow);
27991+
27992+void copy_to_user_overflow(void)
27993+{
27994+ WARN(1, "Buffer overflow detected!\n");
27995+}
27996+EXPORT_SYMBOL(copy_to_user_overflow);
27997diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
27998index 903ec1e..c4166b2 100644
27999--- a/arch/x86/mm/extable.c
28000+++ b/arch/x86/mm/extable.c
28001@@ -6,12 +6,24 @@
28002 static inline unsigned long
28003 ex_insn_addr(const struct exception_table_entry *x)
28004 {
28005- return (unsigned long)&x->insn + x->insn;
28006+ unsigned long reloc = 0;
28007+
28008+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28009+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
28010+#endif
28011+
28012+ return (unsigned long)&x->insn + x->insn + reloc;
28013 }
28014 static inline unsigned long
28015 ex_fixup_addr(const struct exception_table_entry *x)
28016 {
28017- return (unsigned long)&x->fixup + x->fixup;
28018+ unsigned long reloc = 0;
28019+
28020+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28021+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
28022+#endif
28023+
28024+ return (unsigned long)&x->fixup + x->fixup + reloc;
28025 }
28026
28027 int fixup_exception(struct pt_regs *regs)
28028@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
28029 unsigned long new_ip;
28030
28031 #ifdef CONFIG_PNPBIOS
28032- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
28033+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
28034 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
28035 extern u32 pnp_bios_is_utter_crap;
28036 pnp_bios_is_utter_crap = 1;
28037@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
28038 i += 4;
28039 p->fixup -= i;
28040 i += 4;
28041+
28042+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28043+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
28044+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
28045+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
28046+#endif
28047+
28048 }
28049 }
28050
28051diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
28052index 4f7d793..165a8be 100644
28053--- a/arch/x86/mm/fault.c
28054+++ b/arch/x86/mm/fault.c
28055@@ -13,12 +13,19 @@
28056 #include <linux/perf_event.h> /* perf_sw_event */
28057 #include <linux/hugetlb.h> /* hstate_index_to_shift */
28058 #include <linux/prefetch.h> /* prefetchw */
28059+#include <linux/unistd.h>
28060+#include <linux/compiler.h>
28061
28062 #include <asm/traps.h> /* dotraplinkage, ... */
28063 #include <asm/pgalloc.h> /* pgd_*(), ... */
28064 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
28065 #include <asm/fixmap.h> /* VSYSCALL_START */
28066 #include <asm/context_tracking.h> /* exception_enter(), ... */
28067+#include <asm/tlbflush.h>
28068+
28069+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28070+#include <asm/stacktrace.h>
28071+#endif
28072
28073 /*
28074 * Page fault error code bits:
28075@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
28076 int ret = 0;
28077
28078 /* kprobe_running() needs smp_processor_id() */
28079- if (kprobes_built_in() && !user_mode_vm(regs)) {
28080+ if (kprobes_built_in() && !user_mode(regs)) {
28081 preempt_disable();
28082 if (kprobe_running() && kprobe_fault_handler(regs, 14))
28083 ret = 1;
28084@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
28085 return !instr_lo || (instr_lo>>1) == 1;
28086 case 0x00:
28087 /* Prefetch instruction is 0x0F0D or 0x0F18 */
28088- if (probe_kernel_address(instr, opcode))
28089+ if (user_mode(regs)) {
28090+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
28091+ return 0;
28092+ } else if (probe_kernel_address(instr, opcode))
28093 return 0;
28094
28095 *prefetch = (instr_lo == 0xF) &&
28096@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
28097 while (instr < max_instr) {
28098 unsigned char opcode;
28099
28100- if (probe_kernel_address(instr, opcode))
28101+ if (user_mode(regs)) {
28102+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
28103+ break;
28104+ } else if (probe_kernel_address(instr, opcode))
28105 break;
28106
28107 instr++;
28108@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
28109 force_sig_info(si_signo, &info, tsk);
28110 }
28111
28112+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
28113+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
28114+#endif
28115+
28116+#ifdef CONFIG_PAX_EMUTRAMP
28117+static int pax_handle_fetch_fault(struct pt_regs *regs);
28118+#endif
28119+
28120+#ifdef CONFIG_PAX_PAGEEXEC
28121+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
28122+{
28123+ pgd_t *pgd;
28124+ pud_t *pud;
28125+ pmd_t *pmd;
28126+
28127+ pgd = pgd_offset(mm, address);
28128+ if (!pgd_present(*pgd))
28129+ return NULL;
28130+ pud = pud_offset(pgd, address);
28131+ if (!pud_present(*pud))
28132+ return NULL;
28133+ pmd = pmd_offset(pud, address);
28134+ if (!pmd_present(*pmd))
28135+ return NULL;
28136+ return pmd;
28137+}
28138+#endif
28139+
28140 DEFINE_SPINLOCK(pgd_lock);
28141 LIST_HEAD(pgd_list);
28142
28143@@ -232,10 +273,22 @@ void vmalloc_sync_all(void)
28144 for (address = VMALLOC_START & PMD_MASK;
28145 address >= TASK_SIZE && address < FIXADDR_TOP;
28146 address += PMD_SIZE) {
28147+
28148+#ifdef CONFIG_PAX_PER_CPU_PGD
28149+ unsigned long cpu;
28150+#else
28151 struct page *page;
28152+#endif
28153
28154 spin_lock(&pgd_lock);
28155+
28156+#ifdef CONFIG_PAX_PER_CPU_PGD
28157+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
28158+ pgd_t *pgd = get_cpu_pgd(cpu);
28159+ pmd_t *ret;
28160+#else
28161 list_for_each_entry(page, &pgd_list, lru) {
28162+ pgd_t *pgd;
28163 spinlock_t *pgt_lock;
28164 pmd_t *ret;
28165
28166@@ -243,8 +296,14 @@ void vmalloc_sync_all(void)
28167 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
28168
28169 spin_lock(pgt_lock);
28170- ret = vmalloc_sync_one(page_address(page), address);
28171+ pgd = page_address(page);
28172+#endif
28173+
28174+ ret = vmalloc_sync_one(pgd, address);
28175+
28176+#ifndef CONFIG_PAX_PER_CPU_PGD
28177 spin_unlock(pgt_lock);
28178+#endif
28179
28180 if (!ret)
28181 break;
28182@@ -278,6 +337,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
28183 * an interrupt in the middle of a task switch..
28184 */
28185 pgd_paddr = read_cr3();
28186+
28187+#ifdef CONFIG_PAX_PER_CPU_PGD
28188+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
28189+#endif
28190+
28191 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
28192 if (!pmd_k)
28193 return -1;
28194@@ -373,7 +437,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
28195 * happen within a race in page table update. In the later
28196 * case just flush:
28197 */
28198+
28199+#ifdef CONFIG_PAX_PER_CPU_PGD
28200+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
28201+ pgd = pgd_offset_cpu(smp_processor_id(), address);
28202+#else
28203 pgd = pgd_offset(current->active_mm, address);
28204+#endif
28205+
28206 pgd_ref = pgd_offset_k(address);
28207 if (pgd_none(*pgd_ref))
28208 return -1;
28209@@ -543,7 +614,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
28210 static int is_errata100(struct pt_regs *regs, unsigned long address)
28211 {
28212 #ifdef CONFIG_X86_64
28213- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
28214+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
28215 return 1;
28216 #endif
28217 return 0;
28218@@ -570,7 +641,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
28219 }
28220
28221 static const char nx_warning[] = KERN_CRIT
28222-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
28223+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
28224
28225 static void
28226 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
28227@@ -579,15 +650,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
28228 if (!oops_may_print())
28229 return;
28230
28231- if (error_code & PF_INSTR) {
28232+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
28233 unsigned int level;
28234
28235 pte_t *pte = lookup_address(address, &level);
28236
28237 if (pte && pte_present(*pte) && !pte_exec(*pte))
28238- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
28239+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
28240 }
28241
28242+#ifdef CONFIG_PAX_KERNEXEC
28243+ if (init_mm.start_code <= address && address < init_mm.end_code) {
28244+ if (current->signal->curr_ip)
28245+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
28246+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
28247+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
28248+ else
28249+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
28250+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
28251+ }
28252+#endif
28253+
28254 printk(KERN_ALERT "BUG: unable to handle kernel ");
28255 if (address < PAGE_SIZE)
28256 printk(KERN_CONT "NULL pointer dereference");
28257@@ -750,6 +833,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
28258 return;
28259 }
28260 #endif
28261+
28262+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
28263+ if (pax_is_fetch_fault(regs, error_code, address)) {
28264+
28265+#ifdef CONFIG_PAX_EMUTRAMP
28266+ switch (pax_handle_fetch_fault(regs)) {
28267+ case 2:
28268+ return;
28269+ }
28270+#endif
28271+
28272+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
28273+ do_group_exit(SIGKILL);
28274+ }
28275+#endif
28276+
28277 /* Kernel addresses are always protection faults: */
28278 if (address >= TASK_SIZE)
28279 error_code |= PF_PROT;
28280@@ -835,7 +934,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
28281 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
28282 printk(KERN_ERR
28283 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
28284- tsk->comm, tsk->pid, address);
28285+ tsk->comm, task_pid_nr(tsk), address);
28286 code = BUS_MCEERR_AR;
28287 }
28288 #endif
28289@@ -898,6 +997,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
28290 return 1;
28291 }
28292
28293+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
28294+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
28295+{
28296+ pte_t *pte;
28297+ pmd_t *pmd;
28298+ spinlock_t *ptl;
28299+ unsigned char pte_mask;
28300+
28301+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
28302+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
28303+ return 0;
28304+
28305+ /* PaX: it's our fault, let's handle it if we can */
28306+
28307+ /* PaX: take a look at read faults before acquiring any locks */
28308+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
28309+ /* instruction fetch attempt from a protected page in user mode */
28310+ up_read(&mm->mmap_sem);
28311+
28312+#ifdef CONFIG_PAX_EMUTRAMP
28313+ switch (pax_handle_fetch_fault(regs)) {
28314+ case 2:
28315+ return 1;
28316+ }
28317+#endif
28318+
28319+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
28320+ do_group_exit(SIGKILL);
28321+ }
28322+
28323+ pmd = pax_get_pmd(mm, address);
28324+ if (unlikely(!pmd))
28325+ return 0;
28326+
28327+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
28328+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
28329+ pte_unmap_unlock(pte, ptl);
28330+ return 0;
28331+ }
28332+
28333+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
28334+ /* write attempt to a protected page in user mode */
28335+ pte_unmap_unlock(pte, ptl);
28336+ return 0;
28337+ }
28338+
28339+#ifdef CONFIG_SMP
28340+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
28341+#else
28342+ if (likely(address > get_limit(regs->cs)))
28343+#endif
28344+ {
28345+ set_pte(pte, pte_mkread(*pte));
28346+ __flush_tlb_one(address);
28347+ pte_unmap_unlock(pte, ptl);
28348+ up_read(&mm->mmap_sem);
28349+ return 1;
28350+ }
28351+
28352+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
28353+
28354+ /*
28355+ * PaX: fill DTLB with user rights and retry
28356+ */
28357+ __asm__ __volatile__ (
28358+ "orb %2,(%1)\n"
28359+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
28360+/*
28361+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
28362+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
28363+ * page fault when examined during a TLB load attempt. this is true not only
28364+ * for PTEs holding a non-present entry but also present entries that will
28365+ * raise a page fault (such as those set up by PaX, or the copy-on-write
28366+ * mechanism). in effect it means that we do *not* need to flush the TLBs
28367+ * for our target pages since their PTEs are simply not in the TLBs at all.
28368+
28369+ * the best thing in omitting it is that we gain around 15-20% speed in the
28370+ * fast path of the page fault handler and can get rid of tracing since we
28371+ * can no longer flush unintended entries.
28372+ */
28373+ "invlpg (%0)\n"
28374+#endif
28375+ __copyuser_seg"testb $0,(%0)\n"
28376+ "xorb %3,(%1)\n"
28377+ :
28378+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
28379+ : "memory", "cc");
28380+ pte_unmap_unlock(pte, ptl);
28381+ up_read(&mm->mmap_sem);
28382+ return 1;
28383+}
28384+#endif
28385+
28386 /*
28387 * Handle a spurious fault caused by a stale TLB entry.
28388 *
28389@@ -970,6 +1162,9 @@ int show_unhandled_signals = 1;
28390 static inline int
28391 access_error(unsigned long error_code, struct vm_area_struct *vma)
28392 {
28393+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
28394+ return 1;
28395+
28396 if (error_code & PF_WRITE) {
28397 /* write, present and write, not present: */
28398 if (unlikely(!(vma->vm_flags & VM_WRITE)))
28399@@ -998,7 +1193,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
28400 if (error_code & PF_USER)
28401 return false;
28402
28403- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
28404+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
28405 return false;
28406
28407 return true;
28408@@ -1014,18 +1209,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
28409 {
28410 struct vm_area_struct *vma;
28411 struct task_struct *tsk;
28412- unsigned long address;
28413 struct mm_struct *mm;
28414 int fault;
28415 int write = error_code & PF_WRITE;
28416 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
28417 (write ? FAULT_FLAG_WRITE : 0);
28418
28419- tsk = current;
28420- mm = tsk->mm;
28421-
28422 /* Get the faulting address: */
28423- address = read_cr2();
28424+ unsigned long address = read_cr2();
28425+
28426+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28427+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
28428+ if (!search_exception_tables(regs->ip)) {
28429+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
28430+ bad_area_nosemaphore(regs, error_code, address);
28431+ return;
28432+ }
28433+ if (address < PAX_USER_SHADOW_BASE) {
28434+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
28435+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
28436+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
28437+ } else
28438+ address -= PAX_USER_SHADOW_BASE;
28439+ }
28440+#endif
28441+
28442+ tsk = current;
28443+ mm = tsk->mm;
28444
28445 /*
28446 * Detect and handle instructions that would cause a page fault for
28447@@ -1086,7 +1296,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
28448 * User-mode registers count as a user access even for any
28449 * potential system fault or CPU buglet:
28450 */
28451- if (user_mode_vm(regs)) {
28452+ if (user_mode(regs)) {
28453 local_irq_enable();
28454 error_code |= PF_USER;
28455 } else {
28456@@ -1148,6 +1358,11 @@ retry:
28457 might_sleep();
28458 }
28459
28460+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
28461+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
28462+ return;
28463+#endif
28464+
28465 vma = find_vma(mm, address);
28466 if (unlikely(!vma)) {
28467 bad_area(regs, error_code, address);
28468@@ -1159,18 +1374,24 @@ retry:
28469 bad_area(regs, error_code, address);
28470 return;
28471 }
28472- if (error_code & PF_USER) {
28473- /*
28474- * Accessing the stack below %sp is always a bug.
28475- * The large cushion allows instructions like enter
28476- * and pusha to work. ("enter $65535, $31" pushes
28477- * 32 pointers and then decrements %sp by 65535.)
28478- */
28479- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
28480- bad_area(regs, error_code, address);
28481- return;
28482- }
28483+ /*
28484+ * Accessing the stack below %sp is always a bug.
28485+ * The large cushion allows instructions like enter
28486+ * and pusha to work. ("enter $65535, $31" pushes
28487+ * 32 pointers and then decrements %sp by 65535.)
28488+ */
28489+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
28490+ bad_area(regs, error_code, address);
28491+ return;
28492 }
28493+
28494+#ifdef CONFIG_PAX_SEGMEXEC
28495+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
28496+ bad_area(regs, error_code, address);
28497+ return;
28498+ }
28499+#endif
28500+
28501 if (unlikely(expand_stack(vma, address))) {
28502 bad_area(regs, error_code, address);
28503 return;
28504@@ -1234,3 +1455,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
28505 __do_page_fault(regs, error_code);
28506 exception_exit(regs);
28507 }
28508+
28509+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
28510+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
28511+{
28512+ struct mm_struct *mm = current->mm;
28513+ unsigned long ip = regs->ip;
28514+
28515+ if (v8086_mode(regs))
28516+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
28517+
28518+#ifdef CONFIG_PAX_PAGEEXEC
28519+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
28520+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
28521+ return true;
28522+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
28523+ return true;
28524+ return false;
28525+ }
28526+#endif
28527+
28528+#ifdef CONFIG_PAX_SEGMEXEC
28529+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
28530+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
28531+ return true;
28532+ return false;
28533+ }
28534+#endif
28535+
28536+ return false;
28537+}
28538+#endif
28539+
28540+#ifdef CONFIG_PAX_EMUTRAMP
28541+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
28542+{
28543+ int err;
28544+
28545+ do { /* PaX: libffi trampoline emulation */
28546+ unsigned char mov, jmp;
28547+ unsigned int addr1, addr2;
28548+
28549+#ifdef CONFIG_X86_64
28550+ if ((regs->ip + 9) >> 32)
28551+ break;
28552+#endif
28553+
28554+ err = get_user(mov, (unsigned char __user *)regs->ip);
28555+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
28556+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
28557+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
28558+
28559+ if (err)
28560+ break;
28561+
28562+ if (mov == 0xB8 && jmp == 0xE9) {
28563+ regs->ax = addr1;
28564+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
28565+ return 2;
28566+ }
28567+ } while (0);
28568+
28569+ do { /* PaX: gcc trampoline emulation #1 */
28570+ unsigned char mov1, mov2;
28571+ unsigned short jmp;
28572+ unsigned int addr1, addr2;
28573+
28574+#ifdef CONFIG_X86_64
28575+ if ((regs->ip + 11) >> 32)
28576+ break;
28577+#endif
28578+
28579+ err = get_user(mov1, (unsigned char __user *)regs->ip);
28580+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
28581+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
28582+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
28583+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
28584+
28585+ if (err)
28586+ break;
28587+
28588+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
28589+ regs->cx = addr1;
28590+ regs->ax = addr2;
28591+ regs->ip = addr2;
28592+ return 2;
28593+ }
28594+ } while (0);
28595+
28596+ do { /* PaX: gcc trampoline emulation #2 */
28597+ unsigned char mov, jmp;
28598+ unsigned int addr1, addr2;
28599+
28600+#ifdef CONFIG_X86_64
28601+ if ((regs->ip + 9) >> 32)
28602+ break;
28603+#endif
28604+
28605+ err = get_user(mov, (unsigned char __user *)regs->ip);
28606+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
28607+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
28608+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
28609+
28610+ if (err)
28611+ break;
28612+
28613+ if (mov == 0xB9 && jmp == 0xE9) {
28614+ regs->cx = addr1;
28615+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
28616+ return 2;
28617+ }
28618+ } while (0);
28619+
28620+ return 1; /* PaX in action */
28621+}
28622+
28623+#ifdef CONFIG_X86_64
28624+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
28625+{
28626+ int err;
28627+
28628+ do { /* PaX: libffi trampoline emulation */
28629+ unsigned short mov1, mov2, jmp1;
28630+ unsigned char stcclc, jmp2;
28631+ unsigned long addr1, addr2;
28632+
28633+ err = get_user(mov1, (unsigned short __user *)regs->ip);
28634+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
28635+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
28636+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
28637+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
28638+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
28639+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
28640+
28641+ if (err)
28642+ break;
28643+
28644+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
28645+ regs->r11 = addr1;
28646+ regs->r10 = addr2;
28647+ if (stcclc == 0xF8)
28648+ regs->flags &= ~X86_EFLAGS_CF;
28649+ else
28650+ regs->flags |= X86_EFLAGS_CF;
28651+ regs->ip = addr1;
28652+ return 2;
28653+ }
28654+ } while (0);
28655+
28656+ do { /* PaX: gcc trampoline emulation #1 */
28657+ unsigned short mov1, mov2, jmp1;
28658+ unsigned char jmp2;
28659+ unsigned int addr1;
28660+ unsigned long addr2;
28661+
28662+ err = get_user(mov1, (unsigned short __user *)regs->ip);
28663+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
28664+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
28665+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
28666+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
28667+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
28668+
28669+ if (err)
28670+ break;
28671+
28672+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
28673+ regs->r11 = addr1;
28674+ regs->r10 = addr2;
28675+ regs->ip = addr1;
28676+ return 2;
28677+ }
28678+ } while (0);
28679+
28680+ do { /* PaX: gcc trampoline emulation #2 */
28681+ unsigned short mov1, mov2, jmp1;
28682+ unsigned char jmp2;
28683+ unsigned long addr1, addr2;
28684+
28685+ err = get_user(mov1, (unsigned short __user *)regs->ip);
28686+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
28687+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
28688+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
28689+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
28690+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
28691+
28692+ if (err)
28693+ break;
28694+
28695+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
28696+ regs->r11 = addr1;
28697+ regs->r10 = addr2;
28698+ regs->ip = addr1;
28699+ return 2;
28700+ }
28701+ } while (0);
28702+
28703+ return 1; /* PaX in action */
28704+}
28705+#endif
28706+
28707+/*
28708+ * PaX: decide what to do with offenders (regs->ip = fault address)
28709+ *
28710+ * returns 1 when task should be killed
28711+ * 2 when gcc trampoline was detected
28712+ */
28713+static int pax_handle_fetch_fault(struct pt_regs *regs)
28714+{
28715+ if (v8086_mode(regs))
28716+ return 1;
28717+
28718+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
28719+ return 1;
28720+
28721+#ifdef CONFIG_X86_32
28722+ return pax_handle_fetch_fault_32(regs);
28723+#else
28724+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
28725+ return pax_handle_fetch_fault_32(regs);
28726+ else
28727+ return pax_handle_fetch_fault_64(regs);
28728+#endif
28729+}
28730+#endif
28731+
28732+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
28733+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
28734+{
28735+ long i;
28736+
28737+ printk(KERN_ERR "PAX: bytes at PC: ");
28738+ for (i = 0; i < 20; i++) {
28739+ unsigned char c;
28740+ if (get_user(c, (unsigned char __force_user *)pc+i))
28741+ printk(KERN_CONT "?? ");
28742+ else
28743+ printk(KERN_CONT "%02x ", c);
28744+ }
28745+ printk("\n");
28746+
28747+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
28748+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
28749+ unsigned long c;
28750+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
28751+#ifdef CONFIG_X86_32
28752+ printk(KERN_CONT "???????? ");
28753+#else
28754+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
28755+ printk(KERN_CONT "???????? ???????? ");
28756+ else
28757+ printk(KERN_CONT "???????????????? ");
28758+#endif
28759+ } else {
28760+#ifdef CONFIG_X86_64
28761+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
28762+ printk(KERN_CONT "%08x ", (unsigned int)c);
28763+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
28764+ } else
28765+#endif
28766+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
28767+ }
28768+ }
28769+ printk("\n");
28770+}
28771+#endif
28772+
28773+/**
28774+ * probe_kernel_write(): safely attempt to write to a location
28775+ * @dst: address to write to
28776+ * @src: pointer to the data that shall be written
28777+ * @size: size of the data chunk
28778+ *
28779+ * Safely write to address @dst from the buffer at @src. If a kernel fault
28780+ * happens, handle that and return -EFAULT.
28781+ */
28782+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
28783+{
28784+ long ret;
28785+ mm_segment_t old_fs = get_fs();
28786+
28787+ set_fs(KERNEL_DS);
28788+ pagefault_disable();
28789+ pax_open_kernel();
28790+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
28791+ pax_close_kernel();
28792+ pagefault_enable();
28793+ set_fs(old_fs);
28794+
28795+ return ret ? -EFAULT : 0;
28796+}
28797diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
28798index dd74e46..7d26398 100644
28799--- a/arch/x86/mm/gup.c
28800+++ b/arch/x86/mm/gup.c
28801@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
28802 addr = start;
28803 len = (unsigned long) nr_pages << PAGE_SHIFT;
28804 end = start + len;
28805- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
28806+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
28807 (void __user *)start, len)))
28808 return 0;
28809
28810diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
28811index 6f31ee5..8ee4164 100644
28812--- a/arch/x86/mm/highmem_32.c
28813+++ b/arch/x86/mm/highmem_32.c
28814@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
28815 idx = type + KM_TYPE_NR*smp_processor_id();
28816 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
28817 BUG_ON(!pte_none(*(kmap_pte-idx)));
28818+
28819+ pax_open_kernel();
28820 set_pte(kmap_pte-idx, mk_pte(page, prot));
28821+ pax_close_kernel();
28822+
28823 arch_flush_lazy_mmu_mode();
28824
28825 return (void *)vaddr;
28826diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
28827index ae1aa71..56316db 100644
28828--- a/arch/x86/mm/hugetlbpage.c
28829+++ b/arch/x86/mm/hugetlbpage.c
28830@@ -279,6 +279,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
28831 info.flags = 0;
28832 info.length = len;
28833 info.low_limit = TASK_UNMAPPED_BASE;
28834+
28835+#ifdef CONFIG_PAX_RANDMMAP
28836+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
28837+ info.low_limit += current->mm->delta_mmap;
28838+#endif
28839+
28840 info.high_limit = TASK_SIZE;
28841 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
28842 info.align_offset = 0;
28843@@ -311,6 +317,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
28844 VM_BUG_ON(addr != -ENOMEM);
28845 info.flags = 0;
28846 info.low_limit = TASK_UNMAPPED_BASE;
28847+
28848+#ifdef CONFIG_PAX_RANDMMAP
28849+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
28850+ info.low_limit += current->mm->delta_mmap;
28851+#endif
28852+
28853 info.high_limit = TASK_SIZE;
28854 addr = vm_unmapped_area(&info);
28855 }
28856@@ -325,10 +337,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
28857 struct hstate *h = hstate_file(file);
28858 struct mm_struct *mm = current->mm;
28859 struct vm_area_struct *vma;
28860+ unsigned long pax_task_size = TASK_SIZE;
28861+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
28862
28863 if (len & ~huge_page_mask(h))
28864 return -EINVAL;
28865- if (len > TASK_SIZE)
28866+
28867+#ifdef CONFIG_PAX_SEGMEXEC
28868+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28869+ pax_task_size = SEGMEXEC_TASK_SIZE;
28870+#endif
28871+
28872+ pax_task_size -= PAGE_SIZE;
28873+
28874+ if (len > pax_task_size)
28875 return -ENOMEM;
28876
28877 if (flags & MAP_FIXED) {
28878@@ -337,11 +359,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
28879 return addr;
28880 }
28881
28882+#ifdef CONFIG_PAX_RANDMMAP
28883+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
28884+#endif
28885+
28886 if (addr) {
28887 addr = ALIGN(addr, huge_page_size(h));
28888 vma = find_vma(mm, addr);
28889- if (TASK_SIZE - len >= addr &&
28890- (!vma || addr + len <= vma->vm_start))
28891+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
28892 return addr;
28893 }
28894 if (mm->get_unmapped_area == arch_get_unmapped_area)
28895diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
28896index d7aea41..0fc945b 100644
28897--- a/arch/x86/mm/init.c
28898+++ b/arch/x86/mm/init.c
28899@@ -4,6 +4,7 @@
28900 #include <linux/swap.h>
28901 #include <linux/memblock.h>
28902 #include <linux/bootmem.h> /* for max_low_pfn */
28903+#include <linux/tboot.h>
28904
28905 #include <asm/cacheflush.h>
28906 #include <asm/e820.h>
28907@@ -16,6 +17,8 @@
28908 #include <asm/tlb.h>
28909 #include <asm/proto.h>
28910 #include <asm/dma.h> /* for MAX_DMA_PFN */
28911+#include <asm/desc.h>
28912+#include <asm/bios_ebda.h>
28913
28914 unsigned long __initdata pgt_buf_start;
28915 unsigned long __meminitdata pgt_buf_end;
28916@@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
28917 {
28918 int i;
28919 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
28920- unsigned long start = 0, good_end;
28921+ unsigned long start = 0x100000, good_end;
28922 phys_addr_t base;
28923
28924 for (i = 0; i < nr_range; i++) {
28925@@ -321,10 +324,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
28926 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
28927 * mmio resources as well as potential bios/acpi data regions.
28928 */
28929+
28930+#ifdef CONFIG_GRKERNSEC_KMEM
28931+static unsigned int ebda_start __read_only;
28932+static unsigned int ebda_end __read_only;
28933+#endif
28934+
28935 int devmem_is_allowed(unsigned long pagenr)
28936 {
28937- if (pagenr < 256)
28938+#ifdef CONFIG_GRKERNSEC_KMEM
28939+ /* allow BDA */
28940+ if (!pagenr)
28941 return 1;
28942+ /* allow EBDA */
28943+ if (pagenr >= ebda_start && pagenr < ebda_end)
28944+ return 1;
28945+ /* if tboot is in use, allow access to its hardcoded serial log range */
28946+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
28947+ return 1;
28948+#else
28949+ if (!pagenr)
28950+ return 1;
28951+#ifdef CONFIG_VM86
28952+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
28953+ return 1;
28954+#endif
28955+#endif
28956+
28957+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
28958+ return 1;
28959+#ifdef CONFIG_GRKERNSEC_KMEM
28960+ /* throw out everything else below 1MB */
28961+ if (pagenr <= 256)
28962+ return 0;
28963+#endif
28964 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
28965 return 0;
28966 if (!page_is_ram(pagenr))
28967@@ -381,8 +414,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
28968 #endif
28969 }
28970
28971+#ifdef CONFIG_GRKERNSEC_KMEM
28972+static inline void gr_init_ebda(void)
28973+{
28974+ unsigned int ebda_addr;
28975+ unsigned int ebda_size = 0;
28976+
28977+ ebda_addr = get_bios_ebda();
28978+ if (ebda_addr) {
28979+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
28980+ ebda_size <<= 10;
28981+ }
28982+ if (ebda_addr && ebda_size) {
28983+ ebda_start = ebda_addr >> PAGE_SHIFT;
28984+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
28985+ } else {
28986+ ebda_start = 0x9f000 >> PAGE_SHIFT;
28987+ ebda_end = 0xa0000 >> PAGE_SHIFT;
28988+ }
28989+}
28990+#else
28991+static inline void gr_init_ebda(void) { }
28992+#endif
28993+
28994 void free_initmem(void)
28995 {
28996+#ifdef CONFIG_PAX_KERNEXEC
28997+#ifdef CONFIG_X86_32
28998+ /* PaX: limit KERNEL_CS to actual size */
28999+ unsigned long addr, limit;
29000+ struct desc_struct d;
29001+ int cpu;
29002+#else
29003+ pgd_t *pgd;
29004+ pud_t *pud;
29005+ pmd_t *pmd;
29006+ unsigned long addr, end;
29007+#endif
29008+#endif
29009+
29010+ gr_init_ebda();
29011+
29012+#ifdef CONFIG_PAX_KERNEXEC
29013+#ifdef CONFIG_X86_32
29014+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
29015+ limit = (limit - 1UL) >> PAGE_SHIFT;
29016+
29017+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
29018+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
29019+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
29020+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
29021+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
29022+ }
29023+
29024+ /* PaX: make KERNEL_CS read-only */
29025+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
29026+ if (!paravirt_enabled())
29027+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
29028+/*
29029+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
29030+ pgd = pgd_offset_k(addr);
29031+ pud = pud_offset(pgd, addr);
29032+ pmd = pmd_offset(pud, addr);
29033+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
29034+ }
29035+*/
29036+#ifdef CONFIG_X86_PAE
29037+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
29038+/*
29039+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
29040+ pgd = pgd_offset_k(addr);
29041+ pud = pud_offset(pgd, addr);
29042+ pmd = pmd_offset(pud, addr);
29043+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
29044+ }
29045+*/
29046+#endif
29047+
29048+#ifdef CONFIG_MODULES
29049+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
29050+#endif
29051+
29052+#else
29053+ /* PaX: make kernel code/rodata read-only, rest non-executable */
29054+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
29055+ pgd = pgd_offset_k(addr);
29056+ pud = pud_offset(pgd, addr);
29057+ pmd = pmd_offset(pud, addr);
29058+ if (!pmd_present(*pmd))
29059+ continue;
29060+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
29061+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
29062+ else
29063+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
29064+ }
29065+
29066+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
29067+ end = addr + KERNEL_IMAGE_SIZE;
29068+ for (; addr < end; addr += PMD_SIZE) {
29069+ pgd = pgd_offset_k(addr);
29070+ pud = pud_offset(pgd, addr);
29071+ pmd = pmd_offset(pud, addr);
29072+ if (!pmd_present(*pmd))
29073+ continue;
29074+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
29075+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
29076+ }
29077+#endif
29078+
29079+ flush_tlb_all();
29080+#endif
29081+
29082 free_init_pages("unused kernel memory",
29083 (unsigned long)(&__init_begin),
29084 (unsigned long)(&__init_end));
29085diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
29086index 745d66b..56bf568 100644
29087--- a/arch/x86/mm/init_32.c
29088+++ b/arch/x86/mm/init_32.c
29089@@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
29090 }
29091
29092 /*
29093- * Creates a middle page table and puts a pointer to it in the
29094- * given global directory entry. This only returns the gd entry
29095- * in non-PAE compilation mode, since the middle layer is folded.
29096- */
29097-static pmd_t * __init one_md_table_init(pgd_t *pgd)
29098-{
29099- pud_t *pud;
29100- pmd_t *pmd_table;
29101-
29102-#ifdef CONFIG_X86_PAE
29103- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
29104- if (after_bootmem)
29105- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
29106- else
29107- pmd_table = (pmd_t *)alloc_low_page();
29108- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
29109- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
29110- pud = pud_offset(pgd, 0);
29111- BUG_ON(pmd_table != pmd_offset(pud, 0));
29112-
29113- return pmd_table;
29114- }
29115-#endif
29116- pud = pud_offset(pgd, 0);
29117- pmd_table = pmd_offset(pud, 0);
29118-
29119- return pmd_table;
29120-}
29121-
29122-/*
29123 * Create a page table and place a pointer to it in a middle page
29124 * directory entry:
29125 */
29126@@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
29127 page_table = (pte_t *)alloc_low_page();
29128
29129 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
29130+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
29131+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
29132+#else
29133 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
29134+#endif
29135 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
29136 }
29137
29138 return pte_offset_kernel(pmd, 0);
29139 }
29140
29141+static pmd_t * __init one_md_table_init(pgd_t *pgd)
29142+{
29143+ pud_t *pud;
29144+ pmd_t *pmd_table;
29145+
29146+ pud = pud_offset(pgd, 0);
29147+ pmd_table = pmd_offset(pud, 0);
29148+
29149+ return pmd_table;
29150+}
29151+
29152 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
29153 {
29154 int pgd_idx = pgd_index(vaddr);
29155@@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
29156 int pgd_idx, pmd_idx;
29157 unsigned long vaddr;
29158 pgd_t *pgd;
29159+ pud_t *pud;
29160 pmd_t *pmd;
29161 pte_t *pte = NULL;
29162
29163@@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
29164 pgd = pgd_base + pgd_idx;
29165
29166 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
29167- pmd = one_md_table_init(pgd);
29168- pmd = pmd + pmd_index(vaddr);
29169+ pud = pud_offset(pgd, vaddr);
29170+ pmd = pmd_offset(pud, vaddr);
29171+
29172+#ifdef CONFIG_X86_PAE
29173+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
29174+#endif
29175+
29176 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
29177 pmd++, pmd_idx++) {
29178 pte = page_table_kmap_check(one_page_table_init(pmd),
29179@@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
29180 }
29181 }
29182
29183-static inline int is_kernel_text(unsigned long addr)
29184+static inline int is_kernel_text(unsigned long start, unsigned long end)
29185 {
29186- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
29187- return 1;
29188- return 0;
29189+ if ((start > ktla_ktva((unsigned long)_etext) ||
29190+ end <= ktla_ktva((unsigned long)_stext)) &&
29191+ (start > ktla_ktva((unsigned long)_einittext) ||
29192+ end <= ktla_ktva((unsigned long)_sinittext)) &&
29193+
29194+#ifdef CONFIG_ACPI_SLEEP
29195+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
29196+#endif
29197+
29198+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
29199+ return 0;
29200+ return 1;
29201 }
29202
29203 /*
29204@@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
29205 unsigned long last_map_addr = end;
29206 unsigned long start_pfn, end_pfn;
29207 pgd_t *pgd_base = swapper_pg_dir;
29208- int pgd_idx, pmd_idx, pte_ofs;
29209+ unsigned int pgd_idx, pmd_idx, pte_ofs;
29210 unsigned long pfn;
29211 pgd_t *pgd;
29212+ pud_t *pud;
29213 pmd_t *pmd;
29214 pte_t *pte;
29215 unsigned pages_2m, pages_4k;
29216@@ -280,8 +281,13 @@ repeat:
29217 pfn = start_pfn;
29218 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
29219 pgd = pgd_base + pgd_idx;
29220- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
29221- pmd = one_md_table_init(pgd);
29222+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
29223+ pud = pud_offset(pgd, 0);
29224+ pmd = pmd_offset(pud, 0);
29225+
29226+#ifdef CONFIG_X86_PAE
29227+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
29228+#endif
29229
29230 if (pfn >= end_pfn)
29231 continue;
29232@@ -293,14 +299,13 @@ repeat:
29233 #endif
29234 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
29235 pmd++, pmd_idx++) {
29236- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
29237+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
29238
29239 /*
29240 * Map with big pages if possible, otherwise
29241 * create normal page tables:
29242 */
29243 if (use_pse) {
29244- unsigned int addr2;
29245 pgprot_t prot = PAGE_KERNEL_LARGE;
29246 /*
29247 * first pass will use the same initial
29248@@ -310,11 +315,7 @@ repeat:
29249 __pgprot(PTE_IDENT_ATTR |
29250 _PAGE_PSE);
29251
29252- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
29253- PAGE_OFFSET + PAGE_SIZE-1;
29254-
29255- if (is_kernel_text(addr) ||
29256- is_kernel_text(addr2))
29257+ if (is_kernel_text(address, address + PMD_SIZE))
29258 prot = PAGE_KERNEL_LARGE_EXEC;
29259
29260 pages_2m++;
29261@@ -331,7 +332,7 @@ repeat:
29262 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
29263 pte += pte_ofs;
29264 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
29265- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
29266+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
29267 pgprot_t prot = PAGE_KERNEL;
29268 /*
29269 * first pass will use the same initial
29270@@ -339,7 +340,7 @@ repeat:
29271 */
29272 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
29273
29274- if (is_kernel_text(addr))
29275+ if (is_kernel_text(address, address + PAGE_SIZE))
29276 prot = PAGE_KERNEL_EXEC;
29277
29278 pages_4k++;
29279@@ -465,7 +466,7 @@ void __init native_pagetable_init(void)
29280
29281 pud = pud_offset(pgd, va);
29282 pmd = pmd_offset(pud, va);
29283- if (!pmd_present(*pmd))
29284+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
29285 break;
29286
29287 pte = pte_offset_kernel(pmd, va);
29288@@ -514,12 +515,10 @@ void __init early_ioremap_page_table_range_init(void)
29289
29290 static void __init pagetable_init(void)
29291 {
29292- pgd_t *pgd_base = swapper_pg_dir;
29293-
29294- permanent_kmaps_init(pgd_base);
29295+ permanent_kmaps_init(swapper_pg_dir);
29296 }
29297
29298-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
29299+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
29300 EXPORT_SYMBOL_GPL(__supported_pte_mask);
29301
29302 /* user-defined highmem size */
29303@@ -728,6 +727,12 @@ void __init mem_init(void)
29304
29305 pci_iommu_alloc();
29306
29307+#ifdef CONFIG_PAX_PER_CPU_PGD
29308+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
29309+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
29310+ KERNEL_PGD_PTRS);
29311+#endif
29312+
29313 #ifdef CONFIG_FLATMEM
29314 BUG_ON(!mem_map);
29315 #endif
29316@@ -754,7 +759,7 @@ void __init mem_init(void)
29317 reservedpages++;
29318
29319 codesize = (unsigned long) &_etext - (unsigned long) &_text;
29320- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
29321+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
29322 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
29323
29324 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
29325@@ -795,10 +800,10 @@ void __init mem_init(void)
29326 ((unsigned long)&__init_end -
29327 (unsigned long)&__init_begin) >> 10,
29328
29329- (unsigned long)&_etext, (unsigned long)&_edata,
29330- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
29331+ (unsigned long)&_sdata, (unsigned long)&_edata,
29332+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
29333
29334- (unsigned long)&_text, (unsigned long)&_etext,
29335+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
29336 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
29337
29338 /*
29339@@ -876,6 +881,7 @@ void set_kernel_text_rw(void)
29340 if (!kernel_set_to_readonly)
29341 return;
29342
29343+ start = ktla_ktva(start);
29344 pr_debug("Set kernel text: %lx - %lx for read write\n",
29345 start, start+size);
29346
29347@@ -890,6 +896,7 @@ void set_kernel_text_ro(void)
29348 if (!kernel_set_to_readonly)
29349 return;
29350
29351+ start = ktla_ktva(start);
29352 pr_debug("Set kernel text: %lx - %lx for read only\n",
29353 start, start+size);
29354
29355@@ -918,6 +925,7 @@ void mark_rodata_ro(void)
29356 unsigned long start = PFN_ALIGN(_text);
29357 unsigned long size = PFN_ALIGN(_etext) - start;
29358
29359+ start = ktla_ktva(start);
29360 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
29361 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
29362 size >> 10);
29363diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
29364index 75c9a6a..498d677 100644
29365--- a/arch/x86/mm/init_64.c
29366+++ b/arch/x86/mm/init_64.c
29367@@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
29368 * around without checking the pgd every time.
29369 */
29370
29371-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
29372+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
29373 EXPORT_SYMBOL_GPL(__supported_pte_mask);
29374
29375 int force_personality32;
29376@@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
29377
29378 for (address = start; address <= end; address += PGDIR_SIZE) {
29379 const pgd_t *pgd_ref = pgd_offset_k(address);
29380+
29381+#ifdef CONFIG_PAX_PER_CPU_PGD
29382+ unsigned long cpu;
29383+#else
29384 struct page *page;
29385+#endif
29386
29387 if (pgd_none(*pgd_ref))
29388 continue;
29389
29390 spin_lock(&pgd_lock);
29391+
29392+#ifdef CONFIG_PAX_PER_CPU_PGD
29393+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
29394+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
29395+#else
29396 list_for_each_entry(page, &pgd_list, lru) {
29397 pgd_t *pgd;
29398 spinlock_t *pgt_lock;
29399@@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
29400 /* the pgt_lock only for Xen */
29401 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
29402 spin_lock(pgt_lock);
29403+#endif
29404
29405 if (pgd_none(*pgd))
29406 set_pgd(pgd, *pgd_ref);
29407@@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
29408 BUG_ON(pgd_page_vaddr(*pgd)
29409 != pgd_page_vaddr(*pgd_ref));
29410
29411+#ifndef CONFIG_PAX_PER_CPU_PGD
29412 spin_unlock(pgt_lock);
29413+#endif
29414+
29415 }
29416 spin_unlock(&pgd_lock);
29417 }
29418@@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
29419 {
29420 if (pgd_none(*pgd)) {
29421 pud_t *pud = (pud_t *)spp_getpage();
29422- pgd_populate(&init_mm, pgd, pud);
29423+ pgd_populate_kernel(&init_mm, pgd, pud);
29424 if (pud != pud_offset(pgd, 0))
29425 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
29426 pud, pud_offset(pgd, 0));
29427@@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
29428 {
29429 if (pud_none(*pud)) {
29430 pmd_t *pmd = (pmd_t *) spp_getpage();
29431- pud_populate(&init_mm, pud, pmd);
29432+ pud_populate_kernel(&init_mm, pud, pmd);
29433 if (pmd != pmd_offset(pud, 0))
29434 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
29435 pmd, pmd_offset(pud, 0));
29436@@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
29437 pmd = fill_pmd(pud, vaddr);
29438 pte = fill_pte(pmd, vaddr);
29439
29440+ pax_open_kernel();
29441 set_pte(pte, new_pte);
29442+ pax_close_kernel();
29443
29444 /*
29445 * It's enough to flush this one mapping.
29446@@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
29447 pgd = pgd_offset_k((unsigned long)__va(phys));
29448 if (pgd_none(*pgd)) {
29449 pud = (pud_t *) spp_getpage();
29450- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
29451- _PAGE_USER));
29452+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
29453 }
29454 pud = pud_offset(pgd, (unsigned long)__va(phys));
29455 if (pud_none(*pud)) {
29456 pmd = (pmd_t *) spp_getpage();
29457- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
29458- _PAGE_USER));
29459+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
29460 }
29461 pmd = pmd_offset(pud, phys);
29462 BUG_ON(!pmd_none(*pmd));
29463@@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
29464 if (pfn >= pgt_buf_top)
29465 panic("alloc_low_page: ran out of memory");
29466
29467- adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
29468+ adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
29469 clear_page(adr);
29470 *phys = pfn * PAGE_SIZE;
29471 return adr;
29472@@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
29473
29474 phys = __pa(virt);
29475 left = phys & (PAGE_SIZE - 1);
29476- adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
29477+ adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
29478 adr = (void *)(((unsigned long)adr) | left);
29479
29480 return adr;
29481@@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
29482 unmap_low_page(pmd);
29483
29484 spin_lock(&init_mm.page_table_lock);
29485- pud_populate(&init_mm, pud, __va(pmd_phys));
29486+ pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
29487 spin_unlock(&init_mm.page_table_lock);
29488 }
29489 __flush_tlb_all();
29490@@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
29491 unmap_low_page(pud);
29492
29493 spin_lock(&init_mm.page_table_lock);
29494- pgd_populate(&init_mm, pgd, __va(pud_phys));
29495+ pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
29496 spin_unlock(&init_mm.page_table_lock);
29497 pgd_changed = true;
29498 }
29499@@ -693,6 +707,12 @@ void __init mem_init(void)
29500
29501 pci_iommu_alloc();
29502
29503+#ifdef CONFIG_PAX_PER_CPU_PGD
29504+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
29505+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
29506+ KERNEL_PGD_PTRS);
29507+#endif
29508+
29509 /* clear_bss() already clear the empty_zero_page */
29510
29511 reservedpages = 0;
29512@@ -856,8 +876,8 @@ int kern_addr_valid(unsigned long addr)
29513 static struct vm_area_struct gate_vma = {
29514 .vm_start = VSYSCALL_START,
29515 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
29516- .vm_page_prot = PAGE_READONLY_EXEC,
29517- .vm_flags = VM_READ | VM_EXEC
29518+ .vm_page_prot = PAGE_READONLY,
29519+ .vm_flags = VM_READ
29520 };
29521
29522 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
29523@@ -891,7 +911,7 @@ int in_gate_area_no_mm(unsigned long addr)
29524
29525 const char *arch_vma_name(struct vm_area_struct *vma)
29526 {
29527- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
29528+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
29529 return "[vdso]";
29530 if (vma == &gate_vma)
29531 return "[vsyscall]";
29532diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
29533index 7b179b4..6bd17777 100644
29534--- a/arch/x86/mm/iomap_32.c
29535+++ b/arch/x86/mm/iomap_32.c
29536@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
29537 type = kmap_atomic_idx_push();
29538 idx = type + KM_TYPE_NR * smp_processor_id();
29539 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
29540+
29541+ pax_open_kernel();
29542 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
29543+ pax_close_kernel();
29544+
29545 arch_flush_lazy_mmu_mode();
29546
29547 return (void *)vaddr;
29548diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
29549index 78fe3f1..73b95e2 100644
29550--- a/arch/x86/mm/ioremap.c
29551+++ b/arch/x86/mm/ioremap.c
29552@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
29553 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
29554 int is_ram = page_is_ram(pfn);
29555
29556- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
29557+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
29558 return NULL;
29559 WARN_ON_ONCE(is_ram);
29560 }
29561@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
29562 *
29563 * Caller must ensure there is only one unmapping for the same pointer.
29564 */
29565-void iounmap(volatile void __iomem *addr)
29566+void iounmap(const volatile void __iomem *addr)
29567 {
29568 struct vm_struct *p, *o;
29569
29570@@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
29571
29572 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
29573 if (page_is_ram(start >> PAGE_SHIFT))
29574+#ifdef CONFIG_HIGHMEM
29575+ if ((start >> PAGE_SHIFT) < max_low_pfn)
29576+#endif
29577 return __va(phys);
29578
29579 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
29580@@ -327,6 +330,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
29581 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
29582 {
29583 if (page_is_ram(phys >> PAGE_SHIFT))
29584+#ifdef CONFIG_HIGHMEM
29585+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
29586+#endif
29587 return;
29588
29589 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
29590@@ -344,7 +350,7 @@ static int __init early_ioremap_debug_setup(char *str)
29591 early_param("early_ioremap_debug", early_ioremap_debug_setup);
29592
29593 static __initdata int after_paging_init;
29594-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
29595+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
29596
29597 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
29598 {
29599@@ -381,8 +387,7 @@ void __init early_ioremap_init(void)
29600 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
29601
29602 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
29603- memset(bm_pte, 0, sizeof(bm_pte));
29604- pmd_populate_kernel(&init_mm, pmd, bm_pte);
29605+ pmd_populate_user(&init_mm, pmd, bm_pte);
29606
29607 /*
29608 * The boot-ioremap range spans multiple pmds, for which
29609diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
29610index d87dd6d..bf3fa66 100644
29611--- a/arch/x86/mm/kmemcheck/kmemcheck.c
29612+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
29613@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
29614 * memory (e.g. tracked pages)? For now, we need this to avoid
29615 * invoking kmemcheck for PnP BIOS calls.
29616 */
29617- if (regs->flags & X86_VM_MASK)
29618+ if (v8086_mode(regs))
29619 return false;
29620- if (regs->cs != __KERNEL_CS)
29621+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
29622 return false;
29623
29624 pte = kmemcheck_pte_lookup(address);
29625diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
29626index 845df68..1d8d29f 100644
29627--- a/arch/x86/mm/mmap.c
29628+++ b/arch/x86/mm/mmap.c
29629@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
29630 * Leave an at least ~128 MB hole with possible stack randomization.
29631 */
29632 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
29633-#define MAX_GAP (TASK_SIZE/6*5)
29634+#define MAX_GAP (pax_task_size/6*5)
29635
29636 static int mmap_is_legacy(void)
29637 {
29638@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
29639 return rnd << PAGE_SHIFT;
29640 }
29641
29642-static unsigned long mmap_base(void)
29643+static unsigned long mmap_base(struct mm_struct *mm)
29644 {
29645 unsigned long gap = rlimit(RLIMIT_STACK);
29646+ unsigned long pax_task_size = TASK_SIZE;
29647+
29648+#ifdef CONFIG_PAX_SEGMEXEC
29649+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
29650+ pax_task_size = SEGMEXEC_TASK_SIZE;
29651+#endif
29652
29653 if (gap < MIN_GAP)
29654 gap = MIN_GAP;
29655 else if (gap > MAX_GAP)
29656 gap = MAX_GAP;
29657
29658- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
29659+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
29660 }
29661
29662 /*
29663 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
29664 * does, but not when emulating X86_32
29665 */
29666-static unsigned long mmap_legacy_base(void)
29667+static unsigned long mmap_legacy_base(struct mm_struct *mm)
29668 {
29669- if (mmap_is_ia32())
29670+ if (mmap_is_ia32()) {
29671+
29672+#ifdef CONFIG_PAX_SEGMEXEC
29673+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
29674+ return SEGMEXEC_TASK_UNMAPPED_BASE;
29675+ else
29676+#endif
29677+
29678 return TASK_UNMAPPED_BASE;
29679- else
29680+ } else
29681 return TASK_UNMAPPED_BASE + mmap_rnd();
29682 }
29683
29684@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
29685 void arch_pick_mmap_layout(struct mm_struct *mm)
29686 {
29687 if (mmap_is_legacy()) {
29688- mm->mmap_base = mmap_legacy_base();
29689+ mm->mmap_base = mmap_legacy_base(mm);
29690+
29691+#ifdef CONFIG_PAX_RANDMMAP
29692+ if (mm->pax_flags & MF_PAX_RANDMMAP)
29693+ mm->mmap_base += mm->delta_mmap;
29694+#endif
29695+
29696 mm->get_unmapped_area = arch_get_unmapped_area;
29697 mm->unmap_area = arch_unmap_area;
29698 } else {
29699- mm->mmap_base = mmap_base();
29700+ mm->mmap_base = mmap_base(mm);
29701+
29702+#ifdef CONFIG_PAX_RANDMMAP
29703+ if (mm->pax_flags & MF_PAX_RANDMMAP)
29704+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
29705+#endif
29706+
29707 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
29708 mm->unmap_area = arch_unmap_area_topdown;
29709 }
29710diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
29711index dc0b727..f612039 100644
29712--- a/arch/x86/mm/mmio-mod.c
29713+++ b/arch/x86/mm/mmio-mod.c
29714@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
29715 break;
29716 default:
29717 {
29718- unsigned char *ip = (unsigned char *)instptr;
29719+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
29720 my_trace->opcode = MMIO_UNKNOWN_OP;
29721 my_trace->width = 0;
29722 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
29723@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
29724 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
29725 void __iomem *addr)
29726 {
29727- static atomic_t next_id;
29728+ static atomic_unchecked_t next_id;
29729 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
29730 /* These are page-unaligned. */
29731 struct mmiotrace_map map = {
29732@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
29733 .private = trace
29734 },
29735 .phys = offset,
29736- .id = atomic_inc_return(&next_id)
29737+ .id = atomic_inc_return_unchecked(&next_id)
29738 };
29739 map.map_id = trace->id;
29740
29741@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
29742 ioremap_trace_core(offset, size, addr);
29743 }
29744
29745-static void iounmap_trace_core(volatile void __iomem *addr)
29746+static void iounmap_trace_core(const volatile void __iomem *addr)
29747 {
29748 struct mmiotrace_map map = {
29749 .phys = 0,
29750@@ -328,7 +328,7 @@ not_enabled:
29751 }
29752 }
29753
29754-void mmiotrace_iounmap(volatile void __iomem *addr)
29755+void mmiotrace_iounmap(const volatile void __iomem *addr)
29756 {
29757 might_sleep();
29758 if (is_enabled()) /* recheck and proper locking in *_core() */
29759diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
29760index 8504f36..5fc68f2 100644
29761--- a/arch/x86/mm/numa.c
29762+++ b/arch/x86/mm/numa.c
29763@@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
29764 return true;
29765 }
29766
29767-static int __init numa_register_memblks(struct numa_meminfo *mi)
29768+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
29769 {
29770 unsigned long uninitialized_var(pfn_align);
29771 int i, nid;
29772diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
29773index b008656..773eac2 100644
29774--- a/arch/x86/mm/pageattr-test.c
29775+++ b/arch/x86/mm/pageattr-test.c
29776@@ -36,7 +36,7 @@ enum {
29777
29778 static int pte_testbit(pte_t pte)
29779 {
29780- return pte_flags(pte) & _PAGE_UNUSED1;
29781+ return pte_flags(pte) & _PAGE_CPA_TEST;
29782 }
29783
29784 struct split_state {
29785diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
29786index a718e0d..77419bc 100644
29787--- a/arch/x86/mm/pageattr.c
29788+++ b/arch/x86/mm/pageattr.c
29789@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
29790 */
29791 #ifdef CONFIG_PCI_BIOS
29792 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
29793- pgprot_val(forbidden) |= _PAGE_NX;
29794+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
29795 #endif
29796
29797 /*
29798@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
29799 * Does not cover __inittext since that is gone later on. On
29800 * 64bit we do not enforce !NX on the low mapping
29801 */
29802- if (within(address, (unsigned long)_text, (unsigned long)_etext))
29803- pgprot_val(forbidden) |= _PAGE_NX;
29804+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
29805+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
29806
29807+#ifdef CONFIG_DEBUG_RODATA
29808 /*
29809 * The .rodata section needs to be read-only. Using the pfn
29810 * catches all aliases.
29811@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
29812 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
29813 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
29814 pgprot_val(forbidden) |= _PAGE_RW;
29815+#endif
29816
29817 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
29818 /*
29819@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
29820 }
29821 #endif
29822
29823+#ifdef CONFIG_PAX_KERNEXEC
29824+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
29825+ pgprot_val(forbidden) |= _PAGE_RW;
29826+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
29827+ }
29828+#endif
29829+
29830 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
29831
29832 return prot;
29833@@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
29834 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
29835 {
29836 /* change init_mm */
29837+ pax_open_kernel();
29838 set_pte_atomic(kpte, pte);
29839+
29840 #ifdef CONFIG_X86_32
29841 if (!SHARED_KERNEL_PMD) {
29842+
29843+#ifdef CONFIG_PAX_PER_CPU_PGD
29844+ unsigned long cpu;
29845+#else
29846 struct page *page;
29847+#endif
29848
29849+#ifdef CONFIG_PAX_PER_CPU_PGD
29850+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
29851+ pgd_t *pgd = get_cpu_pgd(cpu);
29852+#else
29853 list_for_each_entry(page, &pgd_list, lru) {
29854- pgd_t *pgd;
29855+ pgd_t *pgd = (pgd_t *)page_address(page);
29856+#endif
29857+
29858 pud_t *pud;
29859 pmd_t *pmd;
29860
29861- pgd = (pgd_t *)page_address(page) + pgd_index(address);
29862+ pgd += pgd_index(address);
29863 pud = pud_offset(pgd, address);
29864 pmd = pmd_offset(pud, address);
29865 set_pte_atomic((pte_t *)pmd, pte);
29866 }
29867 }
29868 #endif
29869+ pax_close_kernel();
29870 }
29871
29872 static int
29873diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
29874index 0eb572e..92f5c1e 100644
29875--- a/arch/x86/mm/pat.c
29876+++ b/arch/x86/mm/pat.c
29877@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
29878
29879 if (!entry) {
29880 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
29881- current->comm, current->pid, start, end - 1);
29882+ current->comm, task_pid_nr(current), start, end - 1);
29883 return -EINVAL;
29884 }
29885
29886@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29887
29888 while (cursor < to) {
29889 if (!devmem_is_allowed(pfn)) {
29890- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
29891- current->comm, from, to - 1);
29892+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
29893+ current->comm, from, to - 1, cursor);
29894 return 0;
29895 }
29896 cursor += PAGE_SIZE;
29897@@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
29898 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
29899 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
29900 "for [mem %#010Lx-%#010Lx]\n",
29901- current->comm, current->pid,
29902+ current->comm, task_pid_nr(current),
29903 cattr_name(flags),
29904 base, (unsigned long long)(base + size-1));
29905 return -EINVAL;
29906@@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
29907 flags = lookup_memtype(paddr);
29908 if (want_flags != flags) {
29909 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
29910- current->comm, current->pid,
29911+ current->comm, task_pid_nr(current),
29912 cattr_name(want_flags),
29913 (unsigned long long)paddr,
29914 (unsigned long long)(paddr + size - 1),
29915@@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
29916 free_memtype(paddr, paddr + size);
29917 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
29918 " for [mem %#010Lx-%#010Lx], got %s\n",
29919- current->comm, current->pid,
29920+ current->comm, task_pid_nr(current),
29921 cattr_name(want_flags),
29922 (unsigned long long)paddr,
29923 (unsigned long long)(paddr + size - 1),
29924diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
29925index 9f0614d..92ae64a 100644
29926--- a/arch/x86/mm/pf_in.c
29927+++ b/arch/x86/mm/pf_in.c
29928@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
29929 int i;
29930 enum reason_type rv = OTHERS;
29931
29932- p = (unsigned char *)ins_addr;
29933+ p = (unsigned char *)ktla_ktva(ins_addr);
29934 p += skip_prefix(p, &prf);
29935 p += get_opcode(p, &opcode);
29936
29937@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
29938 struct prefix_bits prf;
29939 int i;
29940
29941- p = (unsigned char *)ins_addr;
29942+ p = (unsigned char *)ktla_ktva(ins_addr);
29943 p += skip_prefix(p, &prf);
29944 p += get_opcode(p, &opcode);
29945
29946@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
29947 struct prefix_bits prf;
29948 int i;
29949
29950- p = (unsigned char *)ins_addr;
29951+ p = (unsigned char *)ktla_ktva(ins_addr);
29952 p += skip_prefix(p, &prf);
29953 p += get_opcode(p, &opcode);
29954
29955@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
29956 struct prefix_bits prf;
29957 int i;
29958
29959- p = (unsigned char *)ins_addr;
29960+ p = (unsigned char *)ktla_ktva(ins_addr);
29961 p += skip_prefix(p, &prf);
29962 p += get_opcode(p, &opcode);
29963 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
29964@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
29965 struct prefix_bits prf;
29966 int i;
29967
29968- p = (unsigned char *)ins_addr;
29969+ p = (unsigned char *)ktla_ktva(ins_addr);
29970 p += skip_prefix(p, &prf);
29971 p += get_opcode(p, &opcode);
29972 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
29973diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
29974index 395b3b4a..213e72b 100644
29975--- a/arch/x86/mm/pgtable.c
29976+++ b/arch/x86/mm/pgtable.c
29977@@ -91,10 +91,64 @@ static inline void pgd_list_del(pgd_t *pgd)
29978 list_del(&page->lru);
29979 }
29980
29981-#define UNSHARED_PTRS_PER_PGD \
29982- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
29983+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29984+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
29985
29986+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
29987+{
29988+ unsigned int count = USER_PGD_PTRS;
29989
29990+ while (count--)
29991+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
29992+}
29993+#endif
29994+
29995+#ifdef CONFIG_PAX_PER_CPU_PGD
29996+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
29997+{
29998+ unsigned int count = USER_PGD_PTRS;
29999+
30000+ while (count--) {
30001+ pgd_t pgd;
30002+
30003+#ifdef CONFIG_X86_64
30004+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
30005+#else
30006+ pgd = *src++;
30007+#endif
30008+
30009+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30010+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
30011+#endif
30012+
30013+ *dst++ = pgd;
30014+ }
30015+
30016+}
30017+#endif
30018+
30019+#ifdef CONFIG_X86_64
30020+#define pxd_t pud_t
30021+#define pyd_t pgd_t
30022+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
30023+#define pxd_free(mm, pud) pud_free((mm), (pud))
30024+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
30025+#define pyd_offset(mm, address) pgd_offset((mm), (address))
30026+#define PYD_SIZE PGDIR_SIZE
30027+#else
30028+#define pxd_t pmd_t
30029+#define pyd_t pud_t
30030+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
30031+#define pxd_free(mm, pud) pmd_free((mm), (pud))
30032+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
30033+#define pyd_offset(mm, address) pud_offset((mm), (address))
30034+#define PYD_SIZE PUD_SIZE
30035+#endif
30036+
30037+#ifdef CONFIG_PAX_PER_CPU_PGD
30038+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
30039+static inline void pgd_dtor(pgd_t *pgd) {}
30040+#else
30041 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
30042 {
30043 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
30044@@ -135,6 +189,7 @@ static void pgd_dtor(pgd_t *pgd)
30045 pgd_list_del(pgd);
30046 spin_unlock(&pgd_lock);
30047 }
30048+#endif
30049
30050 /*
30051 * List of all pgd's needed for non-PAE so it can invalidate entries
30052@@ -147,7 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
30053 * -- nyc
30054 */
30055
30056-#ifdef CONFIG_X86_PAE
30057+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
30058 /*
30059 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
30060 * updating the top-level pagetable entries to guarantee the
30061@@ -159,7 +214,7 @@ static void pgd_dtor(pgd_t *pgd)
30062 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
30063 * and initialize the kernel pmds here.
30064 */
30065-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
30066+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
30067
30068 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
30069 {
30070@@ -177,36 +232,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
30071 */
30072 flush_tlb_mm(mm);
30073 }
30074+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
30075+#define PREALLOCATED_PXDS USER_PGD_PTRS
30076 #else /* !CONFIG_X86_PAE */
30077
30078 /* No need to prepopulate any pagetable entries in non-PAE modes. */
30079-#define PREALLOCATED_PMDS 0
30080+#define PREALLOCATED_PXDS 0
30081
30082 #endif /* CONFIG_X86_PAE */
30083
30084-static void free_pmds(pmd_t *pmds[])
30085+static void free_pxds(pxd_t *pxds[])
30086 {
30087 int i;
30088
30089- for(i = 0; i < PREALLOCATED_PMDS; i++)
30090- if (pmds[i])
30091- free_page((unsigned long)pmds[i]);
30092+ for(i = 0; i < PREALLOCATED_PXDS; i++)
30093+ if (pxds[i])
30094+ free_page((unsigned long)pxds[i]);
30095 }
30096
30097-static int preallocate_pmds(pmd_t *pmds[])
30098+static int preallocate_pxds(pxd_t *pxds[])
30099 {
30100 int i;
30101 bool failed = false;
30102
30103- for(i = 0; i < PREALLOCATED_PMDS; i++) {
30104- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
30105- if (pmd == NULL)
30106+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
30107+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
30108+ if (pxd == NULL)
30109 failed = true;
30110- pmds[i] = pmd;
30111+ pxds[i] = pxd;
30112 }
30113
30114 if (failed) {
30115- free_pmds(pmds);
30116+ free_pxds(pxds);
30117 return -ENOMEM;
30118 }
30119
30120@@ -219,51 +276,55 @@ static int preallocate_pmds(pmd_t *pmds[])
30121 * preallocate which never got a corresponding vma will need to be
30122 * freed manually.
30123 */
30124-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
30125+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
30126 {
30127 int i;
30128
30129- for(i = 0; i < PREALLOCATED_PMDS; i++) {
30130+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
30131 pgd_t pgd = pgdp[i];
30132
30133 if (pgd_val(pgd) != 0) {
30134- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
30135+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
30136
30137- pgdp[i] = native_make_pgd(0);
30138+ set_pgd(pgdp + i, native_make_pgd(0));
30139
30140- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
30141- pmd_free(mm, pmd);
30142+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
30143+ pxd_free(mm, pxd);
30144 }
30145 }
30146 }
30147
30148-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
30149+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
30150 {
30151- pud_t *pud;
30152+ pyd_t *pyd;
30153 unsigned long addr;
30154 int i;
30155
30156- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
30157+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
30158 return;
30159
30160- pud = pud_offset(pgd, 0);
30161+#ifdef CONFIG_X86_64
30162+ pyd = pyd_offset(mm, 0L);
30163+#else
30164+ pyd = pyd_offset(pgd, 0L);
30165+#endif
30166
30167- for (addr = i = 0; i < PREALLOCATED_PMDS;
30168- i++, pud++, addr += PUD_SIZE) {
30169- pmd_t *pmd = pmds[i];
30170+ for (addr = i = 0; i < PREALLOCATED_PXDS;
30171+ i++, pyd++, addr += PYD_SIZE) {
30172+ pxd_t *pxd = pxds[i];
30173
30174 if (i >= KERNEL_PGD_BOUNDARY)
30175- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
30176- sizeof(pmd_t) * PTRS_PER_PMD);
30177+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
30178+ sizeof(pxd_t) * PTRS_PER_PMD);
30179
30180- pud_populate(mm, pud, pmd);
30181+ pyd_populate(mm, pyd, pxd);
30182 }
30183 }
30184
30185 pgd_t *pgd_alloc(struct mm_struct *mm)
30186 {
30187 pgd_t *pgd;
30188- pmd_t *pmds[PREALLOCATED_PMDS];
30189+ pxd_t *pxds[PREALLOCATED_PXDS];
30190
30191 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
30192
30193@@ -272,11 +333,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
30194
30195 mm->pgd = pgd;
30196
30197- if (preallocate_pmds(pmds) != 0)
30198+ if (preallocate_pxds(pxds) != 0)
30199 goto out_free_pgd;
30200
30201 if (paravirt_pgd_alloc(mm) != 0)
30202- goto out_free_pmds;
30203+ goto out_free_pxds;
30204
30205 /*
30206 * Make sure that pre-populating the pmds is atomic with
30207@@ -286,14 +347,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
30208 spin_lock(&pgd_lock);
30209
30210 pgd_ctor(mm, pgd);
30211- pgd_prepopulate_pmd(mm, pgd, pmds);
30212+ pgd_prepopulate_pxd(mm, pgd, pxds);
30213
30214 spin_unlock(&pgd_lock);
30215
30216 return pgd;
30217
30218-out_free_pmds:
30219- free_pmds(pmds);
30220+out_free_pxds:
30221+ free_pxds(pxds);
30222 out_free_pgd:
30223 free_page((unsigned long)pgd);
30224 out:
30225@@ -302,7 +363,7 @@ out:
30226
30227 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
30228 {
30229- pgd_mop_up_pmds(mm, pgd);
30230+ pgd_mop_up_pxds(mm, pgd);
30231 pgd_dtor(pgd);
30232 paravirt_pgd_free(mm, pgd);
30233 free_page((unsigned long)pgd);
30234diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
30235index a69bcb8..19068ab 100644
30236--- a/arch/x86/mm/pgtable_32.c
30237+++ b/arch/x86/mm/pgtable_32.c
30238@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
30239 return;
30240 }
30241 pte = pte_offset_kernel(pmd, vaddr);
30242+
30243+ pax_open_kernel();
30244 if (pte_val(pteval))
30245 set_pte_at(&init_mm, vaddr, pte, pteval);
30246 else
30247 pte_clear(&init_mm, vaddr, pte);
30248+ pax_close_kernel();
30249
30250 /*
30251 * It's enough to flush this one mapping.
30252diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
30253index d2e2735..5c6586f 100644
30254--- a/arch/x86/mm/physaddr.c
30255+++ b/arch/x86/mm/physaddr.c
30256@@ -8,7 +8,7 @@
30257
30258 #ifdef CONFIG_X86_64
30259
30260-unsigned long __phys_addr(unsigned long x)
30261+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
30262 {
30263 if (x >= __START_KERNEL_map) {
30264 x -= __START_KERNEL_map;
30265@@ -45,7 +45,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
30266 #else
30267
30268 #ifdef CONFIG_DEBUG_VIRTUAL
30269-unsigned long __phys_addr(unsigned long x)
30270+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
30271 {
30272 /* VMALLOC_* aren't constants */
30273 VIRTUAL_BUG_ON(x < PAGE_OFFSET);
30274diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
30275index 410531d..0f16030 100644
30276--- a/arch/x86/mm/setup_nx.c
30277+++ b/arch/x86/mm/setup_nx.c
30278@@ -5,8 +5,10 @@
30279 #include <asm/pgtable.h>
30280 #include <asm/proto.h>
30281
30282+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
30283 static int disable_nx __cpuinitdata;
30284
30285+#ifndef CONFIG_PAX_PAGEEXEC
30286 /*
30287 * noexec = on|off
30288 *
30289@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
30290 return 0;
30291 }
30292 early_param("noexec", noexec_setup);
30293+#endif
30294+
30295+#endif
30296
30297 void __cpuinit x86_configure_nx(void)
30298 {
30299+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
30300 if (cpu_has_nx && !disable_nx)
30301 __supported_pte_mask |= _PAGE_NX;
30302 else
30303+#endif
30304 __supported_pte_mask &= ~_PAGE_NX;
30305 }
30306
30307diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
30308index 13a6b29..c2fff23 100644
30309--- a/arch/x86/mm/tlb.c
30310+++ b/arch/x86/mm/tlb.c
30311@@ -48,7 +48,11 @@ void leave_mm(int cpu)
30312 BUG();
30313 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
30314 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
30315+
30316+#ifndef CONFIG_PAX_PER_CPU_PGD
30317 load_cr3(swapper_pg_dir);
30318+#endif
30319+
30320 }
30321 }
30322 EXPORT_SYMBOL_GPL(leave_mm);
30323diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
30324index 877b9a1..a8ecf42 100644
30325--- a/arch/x86/net/bpf_jit.S
30326+++ b/arch/x86/net/bpf_jit.S
30327@@ -9,6 +9,7 @@
30328 */
30329 #include <linux/linkage.h>
30330 #include <asm/dwarf2.h>
30331+#include <asm/alternative-asm.h>
30332
30333 /*
30334 * Calling convention :
30335@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
30336 jle bpf_slow_path_word
30337 mov (SKBDATA,%rsi),%eax
30338 bswap %eax /* ntohl() */
30339+ pax_force_retaddr
30340 ret
30341
30342 sk_load_half:
30343@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
30344 jle bpf_slow_path_half
30345 movzwl (SKBDATA,%rsi),%eax
30346 rol $8,%ax # ntohs()
30347+ pax_force_retaddr
30348 ret
30349
30350 sk_load_byte:
30351@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
30352 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
30353 jle bpf_slow_path_byte
30354 movzbl (SKBDATA,%rsi),%eax
30355+ pax_force_retaddr
30356 ret
30357
30358 /**
30359@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
30360 movzbl (SKBDATA,%rsi),%ebx
30361 and $15,%bl
30362 shl $2,%bl
30363+ pax_force_retaddr
30364 ret
30365
30366 /* rsi contains offset and can be scratched */
30367@@ -109,6 +114,7 @@ bpf_slow_path_word:
30368 js bpf_error
30369 mov -12(%rbp),%eax
30370 bswap %eax
30371+ pax_force_retaddr
30372 ret
30373
30374 bpf_slow_path_half:
30375@@ -117,12 +123,14 @@ bpf_slow_path_half:
30376 mov -12(%rbp),%ax
30377 rol $8,%ax
30378 movzwl %ax,%eax
30379+ pax_force_retaddr
30380 ret
30381
30382 bpf_slow_path_byte:
30383 bpf_slow_path_common(1)
30384 js bpf_error
30385 movzbl -12(%rbp),%eax
30386+ pax_force_retaddr
30387 ret
30388
30389 bpf_slow_path_byte_msh:
30390@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
30391 and $15,%al
30392 shl $2,%al
30393 xchg %eax,%ebx
30394+ pax_force_retaddr
30395 ret
30396
30397 #define sk_negative_common(SIZE) \
30398@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
30399 sk_negative_common(4)
30400 mov (%rax), %eax
30401 bswap %eax
30402+ pax_force_retaddr
30403 ret
30404
30405 bpf_slow_path_half_neg:
30406@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
30407 mov (%rax),%ax
30408 rol $8,%ax
30409 movzwl %ax,%eax
30410+ pax_force_retaddr
30411 ret
30412
30413 bpf_slow_path_byte_neg:
30414@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
30415 .globl sk_load_byte_negative_offset
30416 sk_negative_common(1)
30417 movzbl (%rax), %eax
30418+ pax_force_retaddr
30419 ret
30420
30421 bpf_slow_path_byte_msh_neg:
30422@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
30423 and $15,%al
30424 shl $2,%al
30425 xchg %eax,%ebx
30426+ pax_force_retaddr
30427 ret
30428
30429 bpf_error:
30430@@ -197,4 +210,5 @@ bpf_error:
30431 xor %eax,%eax
30432 mov -8(%rbp),%rbx
30433 leaveq
30434+ pax_force_retaddr
30435 ret
30436diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
30437index d11a470..3f9adff3 100644
30438--- a/arch/x86/net/bpf_jit_comp.c
30439+++ b/arch/x86/net/bpf_jit_comp.c
30440@@ -12,6 +12,7 @@
30441 #include <linux/netdevice.h>
30442 #include <linux/filter.h>
30443 #include <linux/if_vlan.h>
30444+#include <linux/random.h>
30445
30446 /*
30447 * Conventions :
30448@@ -49,13 +50,87 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
30449 return ptr + len;
30450 }
30451
30452+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
30453+#define MAX_INSTR_CODE_SIZE 96
30454+#else
30455+#define MAX_INSTR_CODE_SIZE 64
30456+#endif
30457+
30458 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
30459
30460 #define EMIT1(b1) EMIT(b1, 1)
30461 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
30462 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
30463 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
30464+
30465+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
30466+/* original constant will appear in ecx */
30467+#define DILUTE_CONST_SEQUENCE(_off, _key) \
30468+do { \
30469+ /* mov ecx, randkey */ \
30470+ EMIT1(0xb9); \
30471+ EMIT(_key, 4); \
30472+ /* xor ecx, randkey ^ off */ \
30473+ EMIT2(0x81, 0xf1); \
30474+ EMIT((_key) ^ (_off), 4); \
30475+} while (0)
30476+
30477+#define EMIT1_off32(b1, _off) \
30478+do { \
30479+ switch (b1) { \
30480+ case 0x05: /* add eax, imm32 */ \
30481+ case 0x2d: /* sub eax, imm32 */ \
30482+ case 0x25: /* and eax, imm32 */ \
30483+ case 0x0d: /* or eax, imm32 */ \
30484+ case 0xb8: /* mov eax, imm32 */ \
30485+ case 0x3d: /* cmp eax, imm32 */ \
30486+ case 0xa9: /* test eax, imm32 */ \
30487+ DILUTE_CONST_SEQUENCE(_off, randkey); \
30488+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
30489+ break; \
30490+ case 0xbb: /* mov ebx, imm32 */ \
30491+ DILUTE_CONST_SEQUENCE(_off, randkey); \
30492+ /* mov ebx, ecx */ \
30493+ EMIT2(0x89, 0xcb); \
30494+ break; \
30495+ case 0xbe: /* mov esi, imm32 */ \
30496+ DILUTE_CONST_SEQUENCE(_off, randkey); \
30497+ /* mov esi, ecx */ \
30498+ EMIT2(0x89, 0xce); \
30499+ break; \
30500+ case 0xe9: /* jmp rel imm32 */ \
30501+ EMIT1(b1); \
30502+ EMIT(_off, 4); \
30503+ /* prevent fall-through, we're not called if off = 0 */ \
30504+ EMIT(0xcccccccc, 4); \
30505+ EMIT(0xcccccccc, 4); \
30506+ break; \
30507+ default: \
30508+ EMIT1(b1); \
30509+ EMIT(_off, 4); \
30510+ } \
30511+} while (0)
30512+
30513+#define EMIT2_off32(b1, b2, _off) \
30514+do { \
30515+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
30516+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
30517+ EMIT(randkey, 4); \
30518+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
30519+ EMIT((_off) - randkey, 4); \
30520+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
30521+ DILUTE_CONST_SEQUENCE(_off, randkey); \
30522+ /* imul eax, ecx */ \
30523+ EMIT3(0x0f, 0xaf, 0xc1); \
30524+ } else { \
30525+ EMIT2(b1, b2); \
30526+ EMIT(_off, 4); \
30527+ } \
30528+} while (0)
30529+#else
30530 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
30531+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
30532+#endif
30533
30534 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
30535 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
30536@@ -90,6 +165,24 @@ do { \
30537 #define X86_JBE 0x76
30538 #define X86_JA 0x77
30539
30540+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
30541+#define APPEND_FLOW_VERIFY() \
30542+do { \
30543+ /* mov ecx, randkey */ \
30544+ EMIT1(0xb9); \
30545+ EMIT(randkey, 4); \
30546+ /* cmp ecx, randkey */ \
30547+ EMIT2(0x81, 0xf9); \
30548+ EMIT(randkey, 4); \
30549+ /* jz after 8 int 3s */ \
30550+ EMIT2(0x74, 0x08); \
30551+ EMIT(0xcccccccc, 4); \
30552+ EMIT(0xcccccccc, 4); \
30553+} while (0)
30554+#else
30555+#define APPEND_FLOW_VERIFY() do { } while (0)
30556+#endif
30557+
30558 #define EMIT_COND_JMP(op, offset) \
30559 do { \
30560 if (is_near(offset)) \
30561@@ -97,6 +190,7 @@ do { \
30562 else { \
30563 EMIT2(0x0f, op + 0x10); \
30564 EMIT(offset, 4); /* jxx .+off32 */ \
30565+ APPEND_FLOW_VERIFY(); \
30566 } \
30567 } while (0)
30568
30569@@ -121,12 +215,17 @@ static inline void bpf_flush_icache(void *start, void *end)
30570 set_fs(old_fs);
30571 }
30572
30573+struct bpf_jit_work {
30574+ struct work_struct work;
30575+ void *image;
30576+};
30577+
30578 #define CHOOSE_LOAD_FUNC(K, func) \
30579 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
30580
30581 void bpf_jit_compile(struct sk_filter *fp)
30582 {
30583- u8 temp[64];
30584+ u8 temp[MAX_INSTR_CODE_SIZE];
30585 u8 *prog;
30586 unsigned int proglen, oldproglen = 0;
30587 int ilen, i;
30588@@ -139,6 +238,9 @@ void bpf_jit_compile(struct sk_filter *fp)
30589 unsigned int *addrs;
30590 const struct sock_filter *filter = fp->insns;
30591 int flen = fp->len;
30592+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
30593+ unsigned int randkey;
30594+#endif
30595
30596 if (!bpf_jit_enable)
30597 return;
30598@@ -147,11 +249,19 @@ void bpf_jit_compile(struct sk_filter *fp)
30599 if (addrs == NULL)
30600 return;
30601
30602+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
30603+ if (!fp->work)
30604+ goto out;
30605+
30606+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
30607+ randkey = get_random_int();
30608+#endif
30609+
30610 /* Before first pass, make a rough estimation of addrs[]
30611- * each bpf instruction is translated to less than 64 bytes
30612+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
30613 */
30614 for (proglen = 0, i = 0; i < flen; i++) {
30615- proglen += 64;
30616+ proglen += MAX_INSTR_CODE_SIZE;
30617 addrs[i] = proglen;
30618 }
30619 cleanup_addr = proglen; /* epilogue address */
30620@@ -261,10 +371,8 @@ void bpf_jit_compile(struct sk_filter *fp)
30621 case BPF_S_ALU_MUL_K: /* A *= K */
30622 if (is_imm8(K))
30623 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
30624- else {
30625- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
30626- EMIT(K, 4);
30627- }
30628+ else
30629+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
30630 break;
30631 case BPF_S_ALU_DIV_X: /* A /= X; */
30632 seen |= SEEN_XREG;
30633@@ -304,13 +412,23 @@ void bpf_jit_compile(struct sk_filter *fp)
30634 break;
30635 case BPF_S_ALU_MOD_K: /* A %= K; */
30636 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
30637+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
30638+ DILUTE_CONST_SEQUENCE(K, randkey);
30639+#else
30640 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
30641+#endif
30642 EMIT2(0xf7, 0xf1); /* div %ecx */
30643 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
30644 break;
30645 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
30646+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
30647+ DILUTE_CONST_SEQUENCE(K, randkey);
30648+ // imul rax, rcx
30649+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
30650+#else
30651 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
30652 EMIT(K, 4);
30653+#endif
30654 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
30655 break;
30656 case BPF_S_ALU_AND_X:
30657@@ -564,8 +682,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
30658 if (is_imm8(K)) {
30659 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
30660 } else {
30661- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
30662- EMIT(K, 4);
30663+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
30664 }
30665 } else {
30666 EMIT2(0x89,0xde); /* mov %ebx,%esi */
30667@@ -648,17 +765,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
30668 break;
30669 default:
30670 /* hmm, too complex filter, give up with jit compiler */
30671- goto out;
30672+ goto error;
30673 }
30674 ilen = prog - temp;
30675 if (image) {
30676 if (unlikely(proglen + ilen > oldproglen)) {
30677 pr_err("bpb_jit_compile fatal error\n");
30678- kfree(addrs);
30679- module_free(NULL, image);
30680- return;
30681+ module_free_exec(NULL, image);
30682+ goto error;
30683 }
30684+ pax_open_kernel();
30685 memcpy(image + proglen, temp, ilen);
30686+ pax_close_kernel();
30687 }
30688 proglen += ilen;
30689 addrs[i] = proglen;
30690@@ -679,11 +797,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
30691 break;
30692 }
30693 if (proglen == oldproglen) {
30694- image = module_alloc(max_t(unsigned int,
30695- proglen,
30696- sizeof(struct work_struct)));
30697+ image = module_alloc_exec(proglen);
30698 if (!image)
30699- goto out;
30700+ goto error;
30701 }
30702 oldproglen = proglen;
30703 }
30704@@ -699,7 +815,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
30705 bpf_flush_icache(image, image + proglen);
30706
30707 fp->bpf_func = (void *)image;
30708- }
30709+ } else
30710+error:
30711+ kfree(fp->work);
30712+
30713 out:
30714 kfree(addrs);
30715 return;
30716@@ -707,18 +826,20 @@ out:
30717
30718 static void jit_free_defer(struct work_struct *arg)
30719 {
30720- module_free(NULL, arg);
30721+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
30722+ kfree(arg);
30723 }
30724
30725 /* run from softirq, we must use a work_struct to call
30726- * module_free() from process context
30727+ * module_free_exec() from process context
30728 */
30729 void bpf_jit_free(struct sk_filter *fp)
30730 {
30731 if (fp->bpf_func != sk_run_filter) {
30732- struct work_struct *work = (struct work_struct *)fp->bpf_func;
30733+ struct work_struct *work = &fp->work->work;
30734
30735 INIT_WORK(work, jit_free_defer);
30736+ fp->work->image = fp->bpf_func;
30737 schedule_work(work);
30738 }
30739 }
30740diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
30741index d6aa6e8..266395a 100644
30742--- a/arch/x86/oprofile/backtrace.c
30743+++ b/arch/x86/oprofile/backtrace.c
30744@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
30745 struct stack_frame_ia32 *fp;
30746 unsigned long bytes;
30747
30748- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
30749+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
30750 if (bytes != sizeof(bufhead))
30751 return NULL;
30752
30753- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
30754+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
30755
30756 oprofile_add_trace(bufhead[0].return_address);
30757
30758@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
30759 struct stack_frame bufhead[2];
30760 unsigned long bytes;
30761
30762- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
30763+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
30764 if (bytes != sizeof(bufhead))
30765 return NULL;
30766
30767@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
30768 {
30769 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
30770
30771- if (!user_mode_vm(regs)) {
30772+ if (!user_mode(regs)) {
30773 unsigned long stack = kernel_stack_pointer(regs);
30774 if (depth)
30775 dump_trace(NULL, regs, (unsigned long *)stack, 0,
30776diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
30777index 48768df..ba9143c 100644
30778--- a/arch/x86/oprofile/nmi_int.c
30779+++ b/arch/x86/oprofile/nmi_int.c
30780@@ -23,6 +23,7 @@
30781 #include <asm/nmi.h>
30782 #include <asm/msr.h>
30783 #include <asm/apic.h>
30784+#include <asm/pgtable.h>
30785
30786 #include "op_counter.h"
30787 #include "op_x86_model.h"
30788@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
30789 if (ret)
30790 return ret;
30791
30792- if (!model->num_virt_counters)
30793- model->num_virt_counters = model->num_counters;
30794+ if (!model->num_virt_counters) {
30795+ pax_open_kernel();
30796+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
30797+ pax_close_kernel();
30798+ }
30799
30800 mux_init(ops);
30801
30802diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
30803index b2b9443..be58856 100644
30804--- a/arch/x86/oprofile/op_model_amd.c
30805+++ b/arch/x86/oprofile/op_model_amd.c
30806@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
30807 num_counters = AMD64_NUM_COUNTERS;
30808 }
30809
30810- op_amd_spec.num_counters = num_counters;
30811- op_amd_spec.num_controls = num_counters;
30812- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
30813+ pax_open_kernel();
30814+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
30815+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
30816+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
30817+ pax_close_kernel();
30818
30819 return 0;
30820 }
30821diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
30822index d90528e..0127e2b 100644
30823--- a/arch/x86/oprofile/op_model_ppro.c
30824+++ b/arch/x86/oprofile/op_model_ppro.c
30825@@ -19,6 +19,7 @@
30826 #include <asm/msr.h>
30827 #include <asm/apic.h>
30828 #include <asm/nmi.h>
30829+#include <asm/pgtable.h>
30830
30831 #include "op_x86_model.h"
30832 #include "op_counter.h"
30833@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
30834
30835 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
30836
30837- op_arch_perfmon_spec.num_counters = num_counters;
30838- op_arch_perfmon_spec.num_controls = num_counters;
30839+ pax_open_kernel();
30840+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
30841+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
30842+ pax_close_kernel();
30843 }
30844
30845 static int arch_perfmon_init(struct oprofile_operations *ignore)
30846diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
30847index 71e8a67..6a313bb 100644
30848--- a/arch/x86/oprofile/op_x86_model.h
30849+++ b/arch/x86/oprofile/op_x86_model.h
30850@@ -52,7 +52,7 @@ struct op_x86_model_spec {
30851 void (*switch_ctrl)(struct op_x86_model_spec const *model,
30852 struct op_msrs const * const msrs);
30853 #endif
30854-};
30855+} __do_const;
30856
30857 struct op_counter_config;
30858
30859diff --git a/arch/x86/pci/amd_bus.c b/arch/x86/pci/amd_bus.c
30860index e9e6ed5..e47ae67 100644
30861--- a/arch/x86/pci/amd_bus.c
30862+++ b/arch/x86/pci/amd_bus.c
30863@@ -337,7 +337,7 @@ static int __cpuinit amd_cpu_notify(struct notifier_block *self,
30864 return NOTIFY_OK;
30865 }
30866
30867-static struct notifier_block __cpuinitdata amd_cpu_notifier = {
30868+static struct notifier_block amd_cpu_notifier = {
30869 .notifier_call = amd_cpu_notify,
30870 };
30871
30872diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
30873index 372e9b8..e775a6c 100644
30874--- a/arch/x86/pci/irq.c
30875+++ b/arch/x86/pci/irq.c
30876@@ -50,7 +50,7 @@ struct irq_router {
30877 struct irq_router_handler {
30878 u16 vendor;
30879 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
30880-};
30881+} __do_const;
30882
30883 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
30884 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
30885@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
30886 return 0;
30887 }
30888
30889-static __initdata struct irq_router_handler pirq_routers[] = {
30890+static __initconst const struct irq_router_handler pirq_routers[] = {
30891 { PCI_VENDOR_ID_INTEL, intel_router_probe },
30892 { PCI_VENDOR_ID_AL, ali_router_probe },
30893 { PCI_VENDOR_ID_ITE, ite_router_probe },
30894@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
30895 static void __init pirq_find_router(struct irq_router *r)
30896 {
30897 struct irq_routing_table *rt = pirq_table;
30898- struct irq_router_handler *h;
30899+ const struct irq_router_handler *h;
30900
30901 #ifdef CONFIG_PCI_BIOS
30902 if (!rt->signature) {
30903@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
30904 return 0;
30905 }
30906
30907-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
30908+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
30909 {
30910 .callback = fix_broken_hp_bios_irq9,
30911 .ident = "HP Pavilion N5400 Series Laptop",
30912diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
30913index 6eb18c4..20d83de 100644
30914--- a/arch/x86/pci/mrst.c
30915+++ b/arch/x86/pci/mrst.c
30916@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
30917 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
30918 pci_mmcfg_late_init();
30919 pcibios_enable_irq = mrst_pci_irq_enable;
30920- pci_root_ops = pci_mrst_ops;
30921+ pax_open_kernel();
30922+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
30923+ pax_close_kernel();
30924 pci_soc_mode = 1;
30925 /* Continue with standard init */
30926 return 1;
30927diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
30928index c77b24a..c979855 100644
30929--- a/arch/x86/pci/pcbios.c
30930+++ b/arch/x86/pci/pcbios.c
30931@@ -79,7 +79,7 @@ union bios32 {
30932 static struct {
30933 unsigned long address;
30934 unsigned short segment;
30935-} bios32_indirect = { 0, __KERNEL_CS };
30936+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
30937
30938 /*
30939 * Returns the entry point for the given service, NULL on error
30940@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
30941 unsigned long length; /* %ecx */
30942 unsigned long entry; /* %edx */
30943 unsigned long flags;
30944+ struct desc_struct d, *gdt;
30945
30946 local_irq_save(flags);
30947- __asm__("lcall *(%%edi); cld"
30948+
30949+ gdt = get_cpu_gdt_table(smp_processor_id());
30950+
30951+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
30952+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
30953+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
30954+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
30955+
30956+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
30957 : "=a" (return_code),
30958 "=b" (address),
30959 "=c" (length),
30960 "=d" (entry)
30961 : "0" (service),
30962 "1" (0),
30963- "D" (&bios32_indirect));
30964+ "D" (&bios32_indirect),
30965+ "r"(__PCIBIOS_DS)
30966+ : "memory");
30967+
30968+ pax_open_kernel();
30969+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
30970+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
30971+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
30972+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
30973+ pax_close_kernel();
30974+
30975 local_irq_restore(flags);
30976
30977 switch (return_code) {
30978- case 0:
30979- return address + entry;
30980- case 0x80: /* Not present */
30981- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
30982- return 0;
30983- default: /* Shouldn't happen */
30984- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
30985- service, return_code);
30986+ case 0: {
30987+ int cpu;
30988+ unsigned char flags;
30989+
30990+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
30991+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
30992+ printk(KERN_WARNING "bios32_service: not valid\n");
30993 return 0;
30994+ }
30995+ address = address + PAGE_OFFSET;
30996+ length += 16UL; /* some BIOSs underreport this... */
30997+ flags = 4;
30998+ if (length >= 64*1024*1024) {
30999+ length >>= PAGE_SHIFT;
31000+ flags |= 8;
31001+ }
31002+
31003+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
31004+ gdt = get_cpu_gdt_table(cpu);
31005+ pack_descriptor(&d, address, length, 0x9b, flags);
31006+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
31007+ pack_descriptor(&d, address, length, 0x93, flags);
31008+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
31009+ }
31010+ return entry;
31011+ }
31012+ case 0x80: /* Not present */
31013+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
31014+ return 0;
31015+ default: /* Shouldn't happen */
31016+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
31017+ service, return_code);
31018+ return 0;
31019 }
31020 }
31021
31022 static struct {
31023 unsigned long address;
31024 unsigned short segment;
31025-} pci_indirect = { 0, __KERNEL_CS };
31026+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
31027
31028-static int pci_bios_present;
31029+static int pci_bios_present __read_only;
31030
31031 static int check_pcibios(void)
31032 {
31033@@ -131,11 +174,13 @@ static int check_pcibios(void)
31034 unsigned long flags, pcibios_entry;
31035
31036 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
31037- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
31038+ pci_indirect.address = pcibios_entry;
31039
31040 local_irq_save(flags);
31041- __asm__(
31042- "lcall *(%%edi); cld\n\t"
31043+ __asm__("movw %w6, %%ds\n\t"
31044+ "lcall *%%ss:(%%edi); cld\n\t"
31045+ "push %%ss\n\t"
31046+ "pop %%ds\n\t"
31047 "jc 1f\n\t"
31048 "xor %%ah, %%ah\n"
31049 "1:"
31050@@ -144,7 +189,8 @@ static int check_pcibios(void)
31051 "=b" (ebx),
31052 "=c" (ecx)
31053 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
31054- "D" (&pci_indirect)
31055+ "D" (&pci_indirect),
31056+ "r" (__PCIBIOS_DS)
31057 : "memory");
31058 local_irq_restore(flags);
31059
31060@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
31061
31062 switch (len) {
31063 case 1:
31064- __asm__("lcall *(%%esi); cld\n\t"
31065+ __asm__("movw %w6, %%ds\n\t"
31066+ "lcall *%%ss:(%%esi); cld\n\t"
31067+ "push %%ss\n\t"
31068+ "pop %%ds\n\t"
31069 "jc 1f\n\t"
31070 "xor %%ah, %%ah\n"
31071 "1:"
31072@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
31073 : "1" (PCIBIOS_READ_CONFIG_BYTE),
31074 "b" (bx),
31075 "D" ((long)reg),
31076- "S" (&pci_indirect));
31077+ "S" (&pci_indirect),
31078+ "r" (__PCIBIOS_DS));
31079 /*
31080 * Zero-extend the result beyond 8 bits, do not trust the
31081 * BIOS having done it:
31082@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
31083 *value &= 0xff;
31084 break;
31085 case 2:
31086- __asm__("lcall *(%%esi); cld\n\t"
31087+ __asm__("movw %w6, %%ds\n\t"
31088+ "lcall *%%ss:(%%esi); cld\n\t"
31089+ "push %%ss\n\t"
31090+ "pop %%ds\n\t"
31091 "jc 1f\n\t"
31092 "xor %%ah, %%ah\n"
31093 "1:"
31094@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
31095 : "1" (PCIBIOS_READ_CONFIG_WORD),
31096 "b" (bx),
31097 "D" ((long)reg),
31098- "S" (&pci_indirect));
31099+ "S" (&pci_indirect),
31100+ "r" (__PCIBIOS_DS));
31101 /*
31102 * Zero-extend the result beyond 16 bits, do not trust the
31103 * BIOS having done it:
31104@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
31105 *value &= 0xffff;
31106 break;
31107 case 4:
31108- __asm__("lcall *(%%esi); cld\n\t"
31109+ __asm__("movw %w6, %%ds\n\t"
31110+ "lcall *%%ss:(%%esi); cld\n\t"
31111+ "push %%ss\n\t"
31112+ "pop %%ds\n\t"
31113 "jc 1f\n\t"
31114 "xor %%ah, %%ah\n"
31115 "1:"
31116@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
31117 : "1" (PCIBIOS_READ_CONFIG_DWORD),
31118 "b" (bx),
31119 "D" ((long)reg),
31120- "S" (&pci_indirect));
31121+ "S" (&pci_indirect),
31122+ "r" (__PCIBIOS_DS));
31123 break;
31124 }
31125
31126@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
31127
31128 switch (len) {
31129 case 1:
31130- __asm__("lcall *(%%esi); cld\n\t"
31131+ __asm__("movw %w6, %%ds\n\t"
31132+ "lcall *%%ss:(%%esi); cld\n\t"
31133+ "push %%ss\n\t"
31134+ "pop %%ds\n\t"
31135 "jc 1f\n\t"
31136 "xor %%ah, %%ah\n"
31137 "1:"
31138@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
31139 "c" (value),
31140 "b" (bx),
31141 "D" ((long)reg),
31142- "S" (&pci_indirect));
31143+ "S" (&pci_indirect),
31144+ "r" (__PCIBIOS_DS));
31145 break;
31146 case 2:
31147- __asm__("lcall *(%%esi); cld\n\t"
31148+ __asm__("movw %w6, %%ds\n\t"
31149+ "lcall *%%ss:(%%esi); cld\n\t"
31150+ "push %%ss\n\t"
31151+ "pop %%ds\n\t"
31152 "jc 1f\n\t"
31153 "xor %%ah, %%ah\n"
31154 "1:"
31155@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
31156 "c" (value),
31157 "b" (bx),
31158 "D" ((long)reg),
31159- "S" (&pci_indirect));
31160+ "S" (&pci_indirect),
31161+ "r" (__PCIBIOS_DS));
31162 break;
31163 case 4:
31164- __asm__("lcall *(%%esi); cld\n\t"
31165+ __asm__("movw %w6, %%ds\n\t"
31166+ "lcall *%%ss:(%%esi); cld\n\t"
31167+ "push %%ss\n\t"
31168+ "pop %%ds\n\t"
31169 "jc 1f\n\t"
31170 "xor %%ah, %%ah\n"
31171 "1:"
31172@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
31173 "c" (value),
31174 "b" (bx),
31175 "D" ((long)reg),
31176- "S" (&pci_indirect));
31177+ "S" (&pci_indirect),
31178+ "r" (__PCIBIOS_DS));
31179 break;
31180 }
31181
31182@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
31183
31184 DBG("PCI: Fetching IRQ routing table... ");
31185 __asm__("push %%es\n\t"
31186+ "movw %w8, %%ds\n\t"
31187 "push %%ds\n\t"
31188 "pop %%es\n\t"
31189- "lcall *(%%esi); cld\n\t"
31190+ "lcall *%%ss:(%%esi); cld\n\t"
31191 "pop %%es\n\t"
31192+ "push %%ss\n\t"
31193+ "pop %%ds\n"
31194 "jc 1f\n\t"
31195 "xor %%ah, %%ah\n"
31196 "1:"
31197@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
31198 "1" (0),
31199 "D" ((long) &opt),
31200 "S" (&pci_indirect),
31201- "m" (opt)
31202+ "m" (opt),
31203+ "r" (__PCIBIOS_DS)
31204 : "memory");
31205 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
31206 if (ret & 0xff00)
31207@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
31208 {
31209 int ret;
31210
31211- __asm__("lcall *(%%esi); cld\n\t"
31212+ __asm__("movw %w5, %%ds\n\t"
31213+ "lcall *%%ss:(%%esi); cld\n\t"
31214+ "push %%ss\n\t"
31215+ "pop %%ds\n"
31216 "jc 1f\n\t"
31217 "xor %%ah, %%ah\n"
31218 "1:"
31219@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
31220 : "0" (PCIBIOS_SET_PCI_HW_INT),
31221 "b" ((dev->bus->number << 8) | dev->devfn),
31222 "c" ((irq << 8) | (pin + 10)),
31223- "S" (&pci_indirect));
31224+ "S" (&pci_indirect),
31225+ "r" (__PCIBIOS_DS));
31226 return !(ret & 0xff00);
31227 }
31228 EXPORT_SYMBOL(pcibios_set_irq_routing);
31229diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
31230index 40e4469..1ab536e 100644
31231--- a/arch/x86/platform/efi/efi_32.c
31232+++ b/arch/x86/platform/efi/efi_32.c
31233@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
31234 {
31235 struct desc_ptr gdt_descr;
31236
31237+#ifdef CONFIG_PAX_KERNEXEC
31238+ struct desc_struct d;
31239+#endif
31240+
31241 local_irq_save(efi_rt_eflags);
31242
31243 load_cr3(initial_page_table);
31244 __flush_tlb_all();
31245
31246+#ifdef CONFIG_PAX_KERNEXEC
31247+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
31248+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
31249+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
31250+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
31251+#endif
31252+
31253 gdt_descr.address = __pa(get_cpu_gdt_table(0));
31254 gdt_descr.size = GDT_SIZE - 1;
31255 load_gdt(&gdt_descr);
31256@@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
31257 {
31258 struct desc_ptr gdt_descr;
31259
31260+#ifdef CONFIG_PAX_KERNEXEC
31261+ struct desc_struct d;
31262+
31263+ memset(&d, 0, sizeof d);
31264+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
31265+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
31266+#endif
31267+
31268 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
31269 gdt_descr.size = GDT_SIZE - 1;
31270 load_gdt(&gdt_descr);
31271diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
31272index fbe66e6..eae5e38 100644
31273--- a/arch/x86/platform/efi/efi_stub_32.S
31274+++ b/arch/x86/platform/efi/efi_stub_32.S
31275@@ -6,7 +6,9 @@
31276 */
31277
31278 #include <linux/linkage.h>
31279+#include <linux/init.h>
31280 #include <asm/page_types.h>
31281+#include <asm/segment.h>
31282
31283 /*
31284 * efi_call_phys(void *, ...) is a function with variable parameters.
31285@@ -20,7 +22,7 @@
31286 * service functions will comply with gcc calling convention, too.
31287 */
31288
31289-.text
31290+__INIT
31291 ENTRY(efi_call_phys)
31292 /*
31293 * 0. The function can only be called in Linux kernel. So CS has been
31294@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
31295 * The mapping of lower virtual memory has been created in prelog and
31296 * epilog.
31297 */
31298- movl $1f, %edx
31299- subl $__PAGE_OFFSET, %edx
31300- jmp *%edx
31301+#ifdef CONFIG_PAX_KERNEXEC
31302+ movl $(__KERNEXEC_EFI_DS), %edx
31303+ mov %edx, %ds
31304+ mov %edx, %es
31305+ mov %edx, %ss
31306+ addl $2f,(1f)
31307+ ljmp *(1f)
31308+
31309+__INITDATA
31310+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
31311+.previous
31312+
31313+2:
31314+ subl $2b,(1b)
31315+#else
31316+ jmp 1f-__PAGE_OFFSET
31317 1:
31318+#endif
31319
31320 /*
31321 * 2. Now on the top of stack is the return
31322@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
31323 * parameter 2, ..., param n. To make things easy, we save the return
31324 * address of efi_call_phys in a global variable.
31325 */
31326- popl %edx
31327- movl %edx, saved_return_addr
31328- /* get the function pointer into ECX*/
31329- popl %ecx
31330- movl %ecx, efi_rt_function_ptr
31331- movl $2f, %edx
31332- subl $__PAGE_OFFSET, %edx
31333- pushl %edx
31334+ popl (saved_return_addr)
31335+ popl (efi_rt_function_ptr)
31336
31337 /*
31338 * 3. Clear PG bit in %CR0.
31339@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
31340 /*
31341 * 5. Call the physical function.
31342 */
31343- jmp *%ecx
31344+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
31345
31346-2:
31347 /*
31348 * 6. After EFI runtime service returns, control will return to
31349 * following instruction. We'd better readjust stack pointer first.
31350@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
31351 movl %cr0, %edx
31352 orl $0x80000000, %edx
31353 movl %edx, %cr0
31354- jmp 1f
31355-1:
31356+
31357 /*
31358 * 8. Now restore the virtual mode from flat mode by
31359 * adding EIP with PAGE_OFFSET.
31360 */
31361- movl $1f, %edx
31362- jmp *%edx
31363+#ifdef CONFIG_PAX_KERNEXEC
31364+ movl $(__KERNEL_DS), %edx
31365+ mov %edx, %ds
31366+ mov %edx, %es
31367+ mov %edx, %ss
31368+ ljmp $(__KERNEL_CS),$1f
31369+#else
31370+ jmp 1f+__PAGE_OFFSET
31371+#endif
31372 1:
31373
31374 /*
31375 * 9. Balance the stack. And because EAX contain the return value,
31376 * we'd better not clobber it.
31377 */
31378- leal efi_rt_function_ptr, %edx
31379- movl (%edx), %ecx
31380- pushl %ecx
31381+ pushl (efi_rt_function_ptr)
31382
31383 /*
31384- * 10. Push the saved return address onto the stack and return.
31385+ * 10. Return to the saved return address.
31386 */
31387- leal saved_return_addr, %edx
31388- movl (%edx), %ecx
31389- pushl %ecx
31390- ret
31391+ jmpl *(saved_return_addr)
31392 ENDPROC(efi_call_phys)
31393 .previous
31394
31395-.data
31396+__INITDATA
31397 saved_return_addr:
31398 .long 0
31399 efi_rt_function_ptr:
31400diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
31401index 4c07cca..2c8427d 100644
31402--- a/arch/x86/platform/efi/efi_stub_64.S
31403+++ b/arch/x86/platform/efi/efi_stub_64.S
31404@@ -7,6 +7,7 @@
31405 */
31406
31407 #include <linux/linkage.h>
31408+#include <asm/alternative-asm.h>
31409
31410 #define SAVE_XMM \
31411 mov %rsp, %rax; \
31412@@ -40,6 +41,7 @@ ENTRY(efi_call0)
31413 call *%rdi
31414 addq $32, %rsp
31415 RESTORE_XMM
31416+ pax_force_retaddr 0, 1
31417 ret
31418 ENDPROC(efi_call0)
31419
31420@@ -50,6 +52,7 @@ ENTRY(efi_call1)
31421 call *%rdi
31422 addq $32, %rsp
31423 RESTORE_XMM
31424+ pax_force_retaddr 0, 1
31425 ret
31426 ENDPROC(efi_call1)
31427
31428@@ -60,6 +63,7 @@ ENTRY(efi_call2)
31429 call *%rdi
31430 addq $32, %rsp
31431 RESTORE_XMM
31432+ pax_force_retaddr 0, 1
31433 ret
31434 ENDPROC(efi_call2)
31435
31436@@ -71,6 +75,7 @@ ENTRY(efi_call3)
31437 call *%rdi
31438 addq $32, %rsp
31439 RESTORE_XMM
31440+ pax_force_retaddr 0, 1
31441 ret
31442 ENDPROC(efi_call3)
31443
31444@@ -83,6 +88,7 @@ ENTRY(efi_call4)
31445 call *%rdi
31446 addq $32, %rsp
31447 RESTORE_XMM
31448+ pax_force_retaddr 0, 1
31449 ret
31450 ENDPROC(efi_call4)
31451
31452@@ -96,6 +102,7 @@ ENTRY(efi_call5)
31453 call *%rdi
31454 addq $48, %rsp
31455 RESTORE_XMM
31456+ pax_force_retaddr 0, 1
31457 ret
31458 ENDPROC(efi_call5)
31459
31460@@ -112,5 +119,6 @@ ENTRY(efi_call6)
31461 call *%rdi
31462 addq $48, %rsp
31463 RESTORE_XMM
31464+ pax_force_retaddr 0, 1
31465 ret
31466 ENDPROC(efi_call6)
31467diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
31468index e31bcd8..f12dc46 100644
31469--- a/arch/x86/platform/mrst/mrst.c
31470+++ b/arch/x86/platform/mrst/mrst.c
31471@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
31472 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
31473 int sfi_mrtc_num;
31474
31475-static void mrst_power_off(void)
31476+static __noreturn void mrst_power_off(void)
31477 {
31478+ BUG();
31479 }
31480
31481-static void mrst_reboot(void)
31482+static __noreturn void mrst_reboot(void)
31483 {
31484 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
31485+ BUG();
31486 }
31487
31488 /* parse all the mtimer info to a static mtimer array */
31489diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
31490index d6ee929..3637cb5 100644
31491--- a/arch/x86/platform/olpc/olpc_dt.c
31492+++ b/arch/x86/platform/olpc/olpc_dt.c
31493@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
31494 return res;
31495 }
31496
31497-static struct of_pdt_ops prom_olpc_ops __initdata = {
31498+static struct of_pdt_ops prom_olpc_ops __initconst = {
31499 .nextprop = olpc_dt_nextprop,
31500 .getproplen = olpc_dt_getproplen,
31501 .getproperty = olpc_dt_getproperty,
31502diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
31503index 3c68768..07e82b8 100644
31504--- a/arch/x86/power/cpu.c
31505+++ b/arch/x86/power/cpu.c
31506@@ -134,7 +134,7 @@ static void do_fpu_end(void)
31507 static void fix_processor_context(void)
31508 {
31509 int cpu = smp_processor_id();
31510- struct tss_struct *t = &per_cpu(init_tss, cpu);
31511+ struct tss_struct *t = init_tss + cpu;
31512
31513 set_tss_desc(cpu, t); /*
31514 * This just modifies memory; should not be
31515@@ -144,8 +144,6 @@ static void fix_processor_context(void)
31516 */
31517
31518 #ifdef CONFIG_X86_64
31519- get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
31520-
31521 syscall_init(); /* This sets MSR_*STAR and related */
31522 #endif
31523 load_TR_desc(); /* This does ltr */
31524diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
31525index cbca565..bae7133 100644
31526--- a/arch/x86/realmode/init.c
31527+++ b/arch/x86/realmode/init.c
31528@@ -62,7 +62,13 @@ void __init setup_real_mode(void)
31529 __va(real_mode_header->trampoline_header);
31530
31531 #ifdef CONFIG_X86_32
31532- trampoline_header->start = __pa(startup_32_smp);
31533+ trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
31534+
31535+#ifdef CONFIG_PAX_KERNEXEC
31536+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
31537+#endif
31538+
31539+ trampoline_header->boot_cs = __BOOT_CS;
31540 trampoline_header->gdt_limit = __BOOT_DS + 7;
31541 trampoline_header->gdt_base = __pa(boot_gdt);
31542 #else
31543diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
31544index 8869287..d577672 100644
31545--- a/arch/x86/realmode/rm/Makefile
31546+++ b/arch/x86/realmode/rm/Makefile
31547@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
31548 $(call cc-option, -fno-unit-at-a-time)) \
31549 $(call cc-option, -fno-stack-protector) \
31550 $(call cc-option, -mpreferred-stack-boundary=2)
31551+ifdef CONSTIFY_PLUGIN
31552+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
31553+endif
31554 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
31555 GCOV_PROFILE := n
31556diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
31557index a28221d..93c40f1 100644
31558--- a/arch/x86/realmode/rm/header.S
31559+++ b/arch/x86/realmode/rm/header.S
31560@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
31561 #endif
31562 /* APM/BIOS reboot */
31563 .long pa_machine_real_restart_asm
31564-#ifdef CONFIG_X86_64
31565+#ifdef CONFIG_X86_32
31566+ .long __KERNEL_CS
31567+#else
31568 .long __KERNEL32_CS
31569 #endif
31570 END(real_mode_header)
31571diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
31572index c1b2791..f9e31c7 100644
31573--- a/arch/x86/realmode/rm/trampoline_32.S
31574+++ b/arch/x86/realmode/rm/trampoline_32.S
31575@@ -25,6 +25,12 @@
31576 #include <asm/page_types.h>
31577 #include "realmode.h"
31578
31579+#ifdef CONFIG_PAX_KERNEXEC
31580+#define ta(X) (X)
31581+#else
31582+#define ta(X) (pa_ ## X)
31583+#endif
31584+
31585 .text
31586 .code16
31587
31588@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
31589
31590 cli # We should be safe anyway
31591
31592- movl tr_start, %eax # where we need to go
31593-
31594 movl $0xA5A5A5A5, trampoline_status
31595 # write marker for master knows we're running
31596
31597@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
31598 movw $1, %dx # protected mode (PE) bit
31599 lmsw %dx # into protected mode
31600
31601- ljmpl $__BOOT_CS, $pa_startup_32
31602+ ljmpl *(trampoline_header)
31603
31604 .section ".text32","ax"
31605 .code32
31606@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
31607 .balign 8
31608 GLOBAL(trampoline_header)
31609 tr_start: .space 4
31610- tr_gdt_pad: .space 2
31611+ tr_boot_cs: .space 2
31612 tr_gdt: .space 6
31613 END(trampoline_header)
31614
31615diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
31616index bb360dc..3e5945f 100644
31617--- a/arch/x86/realmode/rm/trampoline_64.S
31618+++ b/arch/x86/realmode/rm/trampoline_64.S
31619@@ -107,7 +107,7 @@ ENTRY(startup_32)
31620 wrmsr
31621
31622 # Enable paging and in turn activate Long Mode
31623- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
31624+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
31625 movl %eax, %cr0
31626
31627 /*
31628diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
31629index 79d67bd..c7e1b90 100644
31630--- a/arch/x86/tools/relocs.c
31631+++ b/arch/x86/tools/relocs.c
31632@@ -12,10 +12,13 @@
31633 #include <regex.h>
31634 #include <tools/le_byteshift.h>
31635
31636+#include "../../../include/generated/autoconf.h"
31637+
31638 static void die(char *fmt, ...);
31639
31640 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
31641 static Elf32_Ehdr ehdr;
31642+static Elf32_Phdr *phdr;
31643 static unsigned long reloc_count, reloc_idx;
31644 static unsigned long *relocs;
31645 static unsigned long reloc16_count, reloc16_idx;
31646@@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
31647 }
31648 }
31649
31650+static void read_phdrs(FILE *fp)
31651+{
31652+ unsigned int i;
31653+
31654+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
31655+ if (!phdr) {
31656+ die("Unable to allocate %d program headers\n",
31657+ ehdr.e_phnum);
31658+ }
31659+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
31660+ die("Seek to %d failed: %s\n",
31661+ ehdr.e_phoff, strerror(errno));
31662+ }
31663+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
31664+ die("Cannot read ELF program headers: %s\n",
31665+ strerror(errno));
31666+ }
31667+ for(i = 0; i < ehdr.e_phnum; i++) {
31668+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
31669+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
31670+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
31671+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
31672+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
31673+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
31674+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
31675+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
31676+ }
31677+
31678+}
31679+
31680 static void read_shdrs(FILE *fp)
31681 {
31682- int i;
31683+ unsigned int i;
31684 Elf32_Shdr shdr;
31685
31686 secs = calloc(ehdr.e_shnum, sizeof(struct section));
31687@@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
31688
31689 static void read_strtabs(FILE *fp)
31690 {
31691- int i;
31692+ unsigned int i;
31693 for (i = 0; i < ehdr.e_shnum; i++) {
31694 struct section *sec = &secs[i];
31695 if (sec->shdr.sh_type != SHT_STRTAB) {
31696@@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
31697
31698 static void read_symtabs(FILE *fp)
31699 {
31700- int i,j;
31701+ unsigned int i,j;
31702 for (i = 0; i < ehdr.e_shnum; i++) {
31703 struct section *sec = &secs[i];
31704 if (sec->shdr.sh_type != SHT_SYMTAB) {
31705@@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
31706 }
31707
31708
31709-static void read_relocs(FILE *fp)
31710+static void read_relocs(FILE *fp, int use_real_mode)
31711 {
31712- int i,j;
31713+ unsigned int i,j;
31714+ uint32_t base;
31715+
31716 for (i = 0; i < ehdr.e_shnum; i++) {
31717 struct section *sec = &secs[i];
31718 if (sec->shdr.sh_type != SHT_REL) {
31719@@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
31720 die("Cannot read symbol table: %s\n",
31721 strerror(errno));
31722 }
31723+ base = 0;
31724+
31725+#ifdef CONFIG_X86_32
31726+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
31727+ if (phdr[j].p_type != PT_LOAD )
31728+ continue;
31729+ 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)
31730+ continue;
31731+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
31732+ break;
31733+ }
31734+#endif
31735+
31736 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
31737 Elf32_Rel *rel = &sec->reltab[j];
31738- rel->r_offset = elf32_to_cpu(rel->r_offset);
31739+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
31740 rel->r_info = elf32_to_cpu(rel->r_info);
31741 }
31742 }
31743@@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
31744
31745 static void print_absolute_symbols(void)
31746 {
31747- int i;
31748+ unsigned int i;
31749 printf("Absolute symbols\n");
31750 printf(" Num: Value Size Type Bind Visibility Name\n");
31751 for (i = 0; i < ehdr.e_shnum; i++) {
31752 struct section *sec = &secs[i];
31753 char *sym_strtab;
31754- int j;
31755+ unsigned int j;
31756
31757 if (sec->shdr.sh_type != SHT_SYMTAB) {
31758 continue;
31759@@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
31760
31761 static void print_absolute_relocs(void)
31762 {
31763- int i, printed = 0;
31764+ unsigned int i, printed = 0;
31765
31766 for (i = 0; i < ehdr.e_shnum; i++) {
31767 struct section *sec = &secs[i];
31768 struct section *sec_applies, *sec_symtab;
31769 char *sym_strtab;
31770 Elf32_Sym *sh_symtab;
31771- int j;
31772+ unsigned int j;
31773 if (sec->shdr.sh_type != SHT_REL) {
31774 continue;
31775 }
31776@@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
31777 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
31778 int use_real_mode)
31779 {
31780- int i;
31781+ unsigned int i;
31782 /* Walk through the relocations */
31783 for (i = 0; i < ehdr.e_shnum; i++) {
31784 char *sym_strtab;
31785 Elf32_Sym *sh_symtab;
31786 struct section *sec_applies, *sec_symtab;
31787- int j;
31788+ unsigned int j;
31789 struct section *sec = &secs[i];
31790
31791 if (sec->shdr.sh_type != SHT_REL) {
31792@@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
31793 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
31794 r_type = ELF32_R_TYPE(rel->r_info);
31795
31796+ if (!use_real_mode) {
31797+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
31798+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
31799+ continue;
31800+
31801+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
31802+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
31803+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
31804+ continue;
31805+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
31806+ continue;
31807+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
31808+ continue;
31809+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
31810+ continue;
31811+#endif
31812+ }
31813+
31814 shn_abs = sym->st_shndx == SHN_ABS;
31815
31816 switch (r_type) {
31817@@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
31818
31819 static void emit_relocs(int as_text, int use_real_mode)
31820 {
31821- int i;
31822+ unsigned int i;
31823 /* Count how many relocations I have and allocate space for them. */
31824 reloc_count = 0;
31825 walk_relocs(count_reloc, use_real_mode);
31826@@ -808,10 +874,11 @@ int main(int argc, char **argv)
31827 fname, strerror(errno));
31828 }
31829 read_ehdr(fp);
31830+ read_phdrs(fp);
31831 read_shdrs(fp);
31832 read_strtabs(fp);
31833 read_symtabs(fp);
31834- read_relocs(fp);
31835+ read_relocs(fp, use_real_mode);
31836 if (show_absolute_syms) {
31837 print_absolute_symbols();
31838 goto out;
31839diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
31840index fd14be1..e3c79c0 100644
31841--- a/arch/x86/vdso/Makefile
31842+++ b/arch/x86/vdso/Makefile
31843@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
31844 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
31845 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
31846
31847-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
31848+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
31849 GCOV_PROFILE := n
31850
31851 #
31852diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
31853index 0faad64..39ef157 100644
31854--- a/arch/x86/vdso/vdso32-setup.c
31855+++ b/arch/x86/vdso/vdso32-setup.c
31856@@ -25,6 +25,7 @@
31857 #include <asm/tlbflush.h>
31858 #include <asm/vdso.h>
31859 #include <asm/proto.h>
31860+#include <asm/mman.h>
31861
31862 enum {
31863 VDSO_DISABLED = 0,
31864@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
31865 void enable_sep_cpu(void)
31866 {
31867 int cpu = get_cpu();
31868- struct tss_struct *tss = &per_cpu(init_tss, cpu);
31869+ struct tss_struct *tss = init_tss + cpu;
31870
31871 if (!boot_cpu_has(X86_FEATURE_SEP)) {
31872 put_cpu();
31873@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
31874 gate_vma.vm_start = FIXADDR_USER_START;
31875 gate_vma.vm_end = FIXADDR_USER_END;
31876 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
31877- gate_vma.vm_page_prot = __P101;
31878+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
31879
31880 return 0;
31881 }
31882@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
31883 if (compat)
31884 addr = VDSO_HIGH_BASE;
31885 else {
31886- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
31887+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
31888 if (IS_ERR_VALUE(addr)) {
31889 ret = addr;
31890 goto up_fail;
31891 }
31892 }
31893
31894- current->mm->context.vdso = (void *)addr;
31895+ current->mm->context.vdso = addr;
31896
31897 if (compat_uses_vma || !compat) {
31898 /*
31899@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
31900 }
31901
31902 current_thread_info()->sysenter_return =
31903- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
31904+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
31905
31906 up_fail:
31907 if (ret)
31908- current->mm->context.vdso = NULL;
31909+ current->mm->context.vdso = 0;
31910
31911 up_write(&mm->mmap_sem);
31912
31913@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
31914
31915 const char *arch_vma_name(struct vm_area_struct *vma)
31916 {
31917- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
31918+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
31919 return "[vdso]";
31920+
31921+#ifdef CONFIG_PAX_SEGMEXEC
31922+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
31923+ return "[vdso]";
31924+#endif
31925+
31926 return NULL;
31927 }
31928
31929@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
31930 * Check to see if the corresponding task was created in compat vdso
31931 * mode.
31932 */
31933- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
31934+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
31935 return &gate_vma;
31936 return NULL;
31937 }
31938diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
31939index 431e875..cbb23f3 100644
31940--- a/arch/x86/vdso/vma.c
31941+++ b/arch/x86/vdso/vma.c
31942@@ -16,8 +16,6 @@
31943 #include <asm/vdso.h>
31944 #include <asm/page.h>
31945
31946-unsigned int __read_mostly vdso_enabled = 1;
31947-
31948 extern char vdso_start[], vdso_end[];
31949 extern unsigned short vdso_sync_cpuid;
31950
31951@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
31952 * unaligned here as a result of stack start randomization.
31953 */
31954 addr = PAGE_ALIGN(addr);
31955- addr = align_vdso_addr(addr);
31956
31957 return addr;
31958 }
31959@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
31960 unsigned size)
31961 {
31962 struct mm_struct *mm = current->mm;
31963- unsigned long addr;
31964+ unsigned long addr = 0;
31965 int ret;
31966
31967- if (!vdso_enabled)
31968- return 0;
31969-
31970 down_write(&mm->mmap_sem);
31971+
31972+#ifdef CONFIG_PAX_RANDMMAP
31973+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
31974+#endif
31975+
31976 addr = vdso_addr(mm->start_stack, size);
31977+ addr = align_vdso_addr(addr);
31978 addr = get_unmapped_area(NULL, addr, size, 0, 0);
31979 if (IS_ERR_VALUE(addr)) {
31980 ret = addr;
31981 goto up_fail;
31982 }
31983
31984- current->mm->context.vdso = (void *)addr;
31985+ mm->context.vdso = addr;
31986
31987 ret = install_special_mapping(mm, addr, size,
31988 VM_READ|VM_EXEC|
31989 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
31990 pages);
31991- if (ret) {
31992- current->mm->context.vdso = NULL;
31993- goto up_fail;
31994- }
31995+ if (ret)
31996+ mm->context.vdso = 0;
31997
31998 up_fail:
31999 up_write(&mm->mmap_sem);
32000@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
32001 vdsox32_size);
32002 }
32003 #endif
32004-
32005-static __init int vdso_setup(char *s)
32006-{
32007- vdso_enabled = simple_strtoul(s, NULL, 0);
32008- return 0;
32009-}
32010-__setup("vdso=", vdso_setup);
32011diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
32012index 2262003..3ee61cf 100644
32013--- a/arch/x86/xen/enlighten.c
32014+++ b/arch/x86/xen/enlighten.c
32015@@ -100,8 +100,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
32016
32017 struct shared_info xen_dummy_shared_info;
32018
32019-void *xen_initial_gdt;
32020-
32021 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
32022 __read_mostly int xen_have_vector_callback;
32023 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
32024@@ -496,8 +494,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
32025 {
32026 unsigned long va = dtr->address;
32027 unsigned int size = dtr->size + 1;
32028- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
32029- unsigned long frames[pages];
32030+ unsigned long frames[65536 / PAGE_SIZE];
32031 int f;
32032
32033 /*
32034@@ -545,8 +542,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
32035 {
32036 unsigned long va = dtr->address;
32037 unsigned int size = dtr->size + 1;
32038- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
32039- unsigned long frames[pages];
32040+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
32041 int f;
32042
32043 /*
32044@@ -554,7 +550,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
32045 * 8-byte entries, or 16 4k pages..
32046 */
32047
32048- BUG_ON(size > 65536);
32049+ BUG_ON(size > GDT_SIZE);
32050 BUG_ON(va & ~PAGE_MASK);
32051
32052 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
32053@@ -939,7 +935,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
32054 return 0;
32055 }
32056
32057-static void set_xen_basic_apic_ops(void)
32058+static void __init set_xen_basic_apic_ops(void)
32059 {
32060 apic->read = xen_apic_read;
32061 apic->write = xen_apic_write;
32062@@ -1245,30 +1241,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
32063 #endif
32064 };
32065
32066-static void xen_reboot(int reason)
32067+static __noreturn void xen_reboot(int reason)
32068 {
32069 struct sched_shutdown r = { .reason = reason };
32070
32071- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
32072- BUG();
32073+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
32074+ BUG();
32075 }
32076
32077-static void xen_restart(char *msg)
32078+static __noreturn void xen_restart(char *msg)
32079 {
32080 xen_reboot(SHUTDOWN_reboot);
32081 }
32082
32083-static void xen_emergency_restart(void)
32084+static __noreturn void xen_emergency_restart(void)
32085 {
32086 xen_reboot(SHUTDOWN_reboot);
32087 }
32088
32089-static void xen_machine_halt(void)
32090+static __noreturn void xen_machine_halt(void)
32091 {
32092 xen_reboot(SHUTDOWN_poweroff);
32093 }
32094
32095-static void xen_machine_power_off(void)
32096+static __noreturn void xen_machine_power_off(void)
32097 {
32098 if (pm_power_off)
32099 pm_power_off();
32100@@ -1370,7 +1366,17 @@ asmlinkage void __init xen_start_kernel(void)
32101 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
32102
32103 /* Work out if we support NX */
32104- x86_configure_nx();
32105+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32106+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
32107+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
32108+ unsigned l, h;
32109+
32110+ __supported_pte_mask |= _PAGE_NX;
32111+ rdmsr(MSR_EFER, l, h);
32112+ l |= EFER_NX;
32113+ wrmsr(MSR_EFER, l, h);
32114+ }
32115+#endif
32116
32117 xen_setup_features();
32118
32119@@ -1401,13 +1407,6 @@ asmlinkage void __init xen_start_kernel(void)
32120
32121 machine_ops = xen_machine_ops;
32122
32123- /*
32124- * The only reliable way to retain the initial address of the
32125- * percpu gdt_page is to remember it here, so we can go and
32126- * mark it RW later, when the initial percpu area is freed.
32127- */
32128- xen_initial_gdt = &per_cpu(gdt_page, 0);
32129-
32130 xen_smp_init();
32131
32132 #ifdef CONFIG_ACPI_NUMA
32133@@ -1598,7 +1597,7 @@ static int __cpuinit xen_hvm_cpu_notify(struct notifier_block *self,
32134 return NOTIFY_OK;
32135 }
32136
32137-static struct notifier_block xen_hvm_cpu_notifier __cpuinitdata = {
32138+static struct notifier_block xen_hvm_cpu_notifier = {
32139 .notifier_call = xen_hvm_cpu_notify,
32140 };
32141
32142diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
32143index cab96b6..8c629ba 100644
32144--- a/arch/x86/xen/mmu.c
32145+++ b/arch/x86/xen/mmu.c
32146@@ -1739,14 +1739,18 @@ static void *m2v(phys_addr_t maddr)
32147 }
32148
32149 /* Set the page permissions on an identity-mapped pages */
32150-static void set_page_prot(void *addr, pgprot_t prot)
32151+static void set_page_prot_flags(void *addr, pgprot_t prot, unsigned long flags)
32152 {
32153 unsigned long pfn = __pa(addr) >> PAGE_SHIFT;
32154 pte_t pte = pfn_pte(pfn, prot);
32155
32156- if (HYPERVISOR_update_va_mapping((unsigned long)addr, pte, 0))
32157+ if (HYPERVISOR_update_va_mapping((unsigned long)addr, pte, flags))
32158 BUG();
32159 }
32160+static void set_page_prot(void *addr, pgprot_t prot)
32161+{
32162+ return set_page_prot_flags(addr, prot, UVMF_NONE);
32163+}
32164 #ifdef CONFIG_X86_32
32165 static void __init xen_map_identity_early(pmd_t *pmd, unsigned long max_pfn)
32166 {
32167@@ -1830,12 +1834,12 @@ static void __init check_pt_base(unsigned long *pt_base, unsigned long *pt_end,
32168 unsigned long addr)
32169 {
32170 if (*pt_base == PFN_DOWN(__pa(addr))) {
32171- set_page_prot((void *)addr, PAGE_KERNEL);
32172+ set_page_prot_flags((void *)addr, PAGE_KERNEL, UVMF_INVLPG);
32173 clear_page((void *)addr);
32174 (*pt_base)++;
32175 }
32176 if (*pt_end == PFN_DOWN(__pa(addr))) {
32177- set_page_prot((void *)addr, PAGE_KERNEL);
32178+ set_page_prot_flags((void *)addr, PAGE_KERNEL, UVMF_INVLPG);
32179 clear_page((void *)addr);
32180 (*pt_end)--;
32181 }
32182@@ -1881,6 +1885,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
32183 /* L3_k[510] -> level2_kernel_pgt
32184 * L3_i[511] -> level2_fixmap_pgt */
32185 convert_pfn_mfn(level3_kernel_pgt);
32186+ convert_pfn_mfn(level3_vmalloc_start_pgt);
32187+ convert_pfn_mfn(level3_vmalloc_end_pgt);
32188+ convert_pfn_mfn(level3_vmemmap_pgt);
32189
32190 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
32191 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
32192@@ -1910,8 +1917,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
32193 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
32194 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
32195 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
32196+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
32197+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
32198+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
32199 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
32200 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
32201+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
32202 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
32203 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
32204
32205@@ -2097,6 +2108,7 @@ static void __init xen_post_allocator_init(void)
32206 pv_mmu_ops.set_pud = xen_set_pud;
32207 #if PAGETABLE_LEVELS == 4
32208 pv_mmu_ops.set_pgd = xen_set_pgd;
32209+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
32210 #endif
32211
32212 /* This will work as long as patching hasn't happened yet
32213@@ -2178,6 +2190,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
32214 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
32215 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
32216 .set_pgd = xen_set_pgd_hyper,
32217+ .set_pgd_batched = xen_set_pgd_hyper,
32218
32219 .alloc_pud = xen_alloc_pmd_init,
32220 .release_pud = xen_release_pmd_init,
32221diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
32222index 34bc4ce..c34aa24 100644
32223--- a/arch/x86/xen/smp.c
32224+++ b/arch/x86/xen/smp.c
32225@@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
32226 {
32227 BUG_ON(smp_processor_id() != 0);
32228 native_smp_prepare_boot_cpu();
32229-
32230- /* We've switched to the "real" per-cpu gdt, so make sure the
32231- old memory can be recycled */
32232- make_lowmem_page_readwrite(xen_initial_gdt);
32233-
32234 xen_filter_cpu_maps();
32235 xen_setup_vcpu_info_placement();
32236 }
32237@@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
32238 gdt = get_cpu_gdt_table(cpu);
32239
32240 ctxt->flags = VGCF_IN_KERNEL;
32241- ctxt->user_regs.ds = __USER_DS;
32242- ctxt->user_regs.es = __USER_DS;
32243+ ctxt->user_regs.ds = __KERNEL_DS;
32244+ ctxt->user_regs.es = __KERNEL_DS;
32245 ctxt->user_regs.ss = __KERNEL_DS;
32246 #ifdef CONFIG_X86_32
32247 ctxt->user_regs.fs = __KERNEL_PERCPU;
32248- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
32249+ savesegment(gs, ctxt->user_regs.gs);
32250 #else
32251 ctxt->gs_base_kernel = per_cpu_offset(cpu);
32252 #endif
32253@@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
32254 int rc;
32255
32256 per_cpu(current_task, cpu) = idle;
32257+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
32258 #ifdef CONFIG_X86_32
32259 irq_ctx_init(cpu);
32260 #else
32261 clear_tsk_thread_flag(idle, TIF_FORK);
32262- per_cpu(kernel_stack, cpu) =
32263- (unsigned long)task_stack_page(idle) -
32264- KERNEL_STACK_OFFSET + THREAD_SIZE;
32265+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
32266 #endif
32267 xen_setup_runstate_info(cpu);
32268 xen_setup_timer(cpu);
32269@@ -630,7 +624,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
32270
32271 void __init xen_smp_init(void)
32272 {
32273- smp_ops = xen_smp_ops;
32274+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
32275 xen_fill_possible_map();
32276 xen_init_spinlocks();
32277 }
32278diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
32279index 33ca6e4..0ded929 100644
32280--- a/arch/x86/xen/xen-asm_32.S
32281+++ b/arch/x86/xen/xen-asm_32.S
32282@@ -84,14 +84,14 @@ ENTRY(xen_iret)
32283 ESP_OFFSET=4 # bytes pushed onto stack
32284
32285 /*
32286- * Store vcpu_info pointer for easy access. Do it this way to
32287- * avoid having to reload %fs
32288+ * Store vcpu_info pointer for easy access.
32289 */
32290 #ifdef CONFIG_SMP
32291- GET_THREAD_INFO(%eax)
32292- movl %ss:TI_cpu(%eax), %eax
32293- movl %ss:__per_cpu_offset(,%eax,4), %eax
32294- mov %ss:xen_vcpu(%eax), %eax
32295+ push %fs
32296+ mov $(__KERNEL_PERCPU), %eax
32297+ mov %eax, %fs
32298+ mov PER_CPU_VAR(xen_vcpu), %eax
32299+ pop %fs
32300 #else
32301 movl %ss:xen_vcpu, %eax
32302 #endif
32303diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
32304index 7faed58..ba4427c 100644
32305--- a/arch/x86/xen/xen-head.S
32306+++ b/arch/x86/xen/xen-head.S
32307@@ -19,6 +19,17 @@ ENTRY(startup_xen)
32308 #ifdef CONFIG_X86_32
32309 mov %esi,xen_start_info
32310 mov $init_thread_union+THREAD_SIZE,%esp
32311+#ifdef CONFIG_SMP
32312+ movl $cpu_gdt_table,%edi
32313+ movl $__per_cpu_load,%eax
32314+ movw %ax,__KERNEL_PERCPU + 2(%edi)
32315+ rorl $16,%eax
32316+ movb %al,__KERNEL_PERCPU + 4(%edi)
32317+ movb %ah,__KERNEL_PERCPU + 7(%edi)
32318+ movl $__per_cpu_end - 1,%eax
32319+ subl $__per_cpu_start,%eax
32320+ movw %ax,__KERNEL_PERCPU + 0(%edi)
32321+#endif
32322 #else
32323 mov %rsi,xen_start_info
32324 mov $init_thread_union+THREAD_SIZE,%rsp
32325diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
32326index a95b417..b6dbd0b 100644
32327--- a/arch/x86/xen/xen-ops.h
32328+++ b/arch/x86/xen/xen-ops.h
32329@@ -10,8 +10,6 @@
32330 extern const char xen_hypervisor_callback[];
32331 extern const char xen_failsafe_callback[];
32332
32333-extern void *xen_initial_gdt;
32334-
32335 struct trap_info;
32336 void xen_copy_trap_info(struct trap_info *traps);
32337
32338diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
32339index 525bd3d..ef888b1 100644
32340--- a/arch/xtensa/variants/dc232b/include/variant/core.h
32341+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
32342@@ -119,9 +119,9 @@
32343 ----------------------------------------------------------------------*/
32344
32345 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
32346-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
32347 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
32348 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
32349+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
32350
32351 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
32352 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
32353diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
32354index 2f33760..835e50a 100644
32355--- a/arch/xtensa/variants/fsf/include/variant/core.h
32356+++ b/arch/xtensa/variants/fsf/include/variant/core.h
32357@@ -11,6 +11,7 @@
32358 #ifndef _XTENSA_CORE_H
32359 #define _XTENSA_CORE_H
32360
32361+#include <linux/const.h>
32362
32363 /****************************************************************************
32364 Parameters Useful for Any Code, USER or PRIVILEGED
32365@@ -112,9 +113,9 @@
32366 ----------------------------------------------------------------------*/
32367
32368 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
32369-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
32370 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
32371 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
32372+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
32373
32374 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
32375 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
32376diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
32377index af00795..2bb8105 100644
32378--- a/arch/xtensa/variants/s6000/include/variant/core.h
32379+++ b/arch/xtensa/variants/s6000/include/variant/core.h
32380@@ -11,6 +11,7 @@
32381 #ifndef _XTENSA_CORE_CONFIGURATION_H
32382 #define _XTENSA_CORE_CONFIGURATION_H
32383
32384+#include <linux/const.h>
32385
32386 /****************************************************************************
32387 Parameters Useful for Any Code, USER or PRIVILEGED
32388@@ -118,9 +119,9 @@
32389 ----------------------------------------------------------------------*/
32390
32391 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
32392-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
32393 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
32394 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
32395+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
32396
32397 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
32398 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
32399diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
32400index 58916af..eb9dbcf6 100644
32401--- a/block/blk-iopoll.c
32402+++ b/block/blk-iopoll.c
32403@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
32404 }
32405 EXPORT_SYMBOL(blk_iopoll_complete);
32406
32407-static void blk_iopoll_softirq(struct softirq_action *h)
32408+static void blk_iopoll_softirq(void)
32409 {
32410 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
32411 int rearm = 0, budget = blk_iopoll_budget;
32412@@ -209,7 +209,7 @@ static int __cpuinit blk_iopoll_cpu_notify(struct notifier_block *self,
32413 return NOTIFY_OK;
32414 }
32415
32416-static struct notifier_block __cpuinitdata blk_iopoll_cpu_notifier = {
32417+static struct notifier_block blk_iopoll_cpu_notifier = {
32418 .notifier_call = blk_iopoll_cpu_notify,
32419 };
32420
32421diff --git a/block/blk-map.c b/block/blk-map.c
32422index 623e1cd..ca1e109 100644
32423--- a/block/blk-map.c
32424+++ b/block/blk-map.c
32425@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
32426 if (!len || !kbuf)
32427 return -EINVAL;
32428
32429- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
32430+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
32431 if (do_copy)
32432 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
32433 else
32434diff --git a/block/blk-softirq.c b/block/blk-softirq.c
32435index 467c8de..f3628c5 100644
32436--- a/block/blk-softirq.c
32437+++ b/block/blk-softirq.c
32438@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
32439 * Softirq action handler - move entries to local list and loop over them
32440 * while passing them to the queue registered handler.
32441 */
32442-static void blk_done_softirq(struct softirq_action *h)
32443+static void blk_done_softirq(void)
32444 {
32445 struct list_head *cpu_list, local_list;
32446
32447@@ -98,7 +98,7 @@ static int __cpuinit blk_cpu_notify(struct notifier_block *self,
32448 return NOTIFY_OK;
32449 }
32450
32451-static struct notifier_block __cpuinitdata blk_cpu_notifier = {
32452+static struct notifier_block blk_cpu_notifier = {
32453 .notifier_call = blk_cpu_notify,
32454 };
32455
32456diff --git a/block/bsg.c b/block/bsg.c
32457index ff64ae3..593560c 100644
32458--- a/block/bsg.c
32459+++ b/block/bsg.c
32460@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
32461 struct sg_io_v4 *hdr, struct bsg_device *bd,
32462 fmode_t has_write_perm)
32463 {
32464+ unsigned char tmpcmd[sizeof(rq->__cmd)];
32465+ unsigned char *cmdptr;
32466+
32467 if (hdr->request_len > BLK_MAX_CDB) {
32468 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
32469 if (!rq->cmd)
32470 return -ENOMEM;
32471- }
32472+ cmdptr = rq->cmd;
32473+ } else
32474+ cmdptr = tmpcmd;
32475
32476- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
32477+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
32478 hdr->request_len))
32479 return -EFAULT;
32480
32481+ if (cmdptr != rq->cmd)
32482+ memcpy(rq->cmd, cmdptr, hdr->request_len);
32483+
32484 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
32485 if (blk_verify_command(rq->cmd, has_write_perm))
32486 return -EPERM;
32487diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
32488index 7c668c8..db3521c 100644
32489--- a/block/compat_ioctl.c
32490+++ b/block/compat_ioctl.c
32491@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
32492 err |= __get_user(f->spec1, &uf->spec1);
32493 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
32494 err |= __get_user(name, &uf->name);
32495- f->name = compat_ptr(name);
32496+ f->name = (void __force_kernel *)compat_ptr(name);
32497 if (err) {
32498 err = -EFAULT;
32499 goto out;
32500diff --git a/block/partitions/efi.c b/block/partitions/efi.c
32501index b62fb88..bdab4c4 100644
32502--- a/block/partitions/efi.c
32503+++ b/block/partitions/efi.c
32504@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
32505 if (!gpt)
32506 return NULL;
32507
32508+ if (!le32_to_cpu(gpt->num_partition_entries))
32509+ return NULL;
32510+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
32511+ if (!pte)
32512+ return NULL;
32513+
32514 count = le32_to_cpu(gpt->num_partition_entries) *
32515 le32_to_cpu(gpt->sizeof_partition_entry);
32516- if (!count)
32517- return NULL;
32518- pte = kzalloc(count, GFP_KERNEL);
32519- if (!pte)
32520- return NULL;
32521-
32522 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
32523 (u8 *) pte,
32524 count) < count) {
32525diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
32526index 9a87daa..fb17486 100644
32527--- a/block/scsi_ioctl.c
32528+++ b/block/scsi_ioctl.c
32529@@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
32530 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
32531 struct sg_io_hdr *hdr, fmode_t mode)
32532 {
32533- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
32534+ unsigned char tmpcmd[sizeof(rq->__cmd)];
32535+ unsigned char *cmdptr;
32536+
32537+ if (rq->cmd != rq->__cmd)
32538+ cmdptr = rq->cmd;
32539+ else
32540+ cmdptr = tmpcmd;
32541+
32542+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
32543 return -EFAULT;
32544+
32545+ if (cmdptr != rq->cmd)
32546+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
32547+
32548 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
32549 return -EPERM;
32550
32551@@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
32552 int err;
32553 unsigned int in_len, out_len, bytes, opcode, cmdlen;
32554 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
32555+ unsigned char tmpcmd[sizeof(rq->__cmd)];
32556+ unsigned char *cmdptr;
32557
32558 if (!sic)
32559 return -EINVAL;
32560@@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
32561 */
32562 err = -EFAULT;
32563 rq->cmd_len = cmdlen;
32564- if (copy_from_user(rq->cmd, sic->data, cmdlen))
32565+
32566+ if (rq->cmd != rq->__cmd)
32567+ cmdptr = rq->cmd;
32568+ else
32569+ cmdptr = tmpcmd;
32570+
32571+ if (copy_from_user(cmdptr, sic->data, cmdlen))
32572 goto error;
32573
32574+ if (rq->cmd != cmdptr)
32575+ memcpy(rq->cmd, cmdptr, cmdlen);
32576+
32577 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
32578 goto error;
32579
32580diff --git a/crypto/cryptd.c b/crypto/cryptd.c
32581index 7bdd61b..afec999 100644
32582--- a/crypto/cryptd.c
32583+++ b/crypto/cryptd.c
32584@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
32585
32586 struct cryptd_blkcipher_request_ctx {
32587 crypto_completion_t complete;
32588-};
32589+} __no_const;
32590
32591 struct cryptd_hash_ctx {
32592 struct crypto_shash *child;
32593@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
32594
32595 struct cryptd_aead_request_ctx {
32596 crypto_completion_t complete;
32597-};
32598+} __no_const;
32599
32600 static void cryptd_queue_worker(struct work_struct *work);
32601
32602diff --git a/crypto/crypto_user.c b/crypto/crypto_user.c
32603index f6d9baf..dfd511f 100644
32604--- a/crypto/crypto_user.c
32605+++ b/crypto/crypto_user.c
32606@@ -30,6 +30,8 @@
32607
32608 #include "internal.h"
32609
32610+#define null_terminated(x) (strnlen(x, sizeof(x)) < sizeof(x))
32611+
32612 static DEFINE_MUTEX(crypto_cfg_mutex);
32613
32614 /* The crypto netlink socket */
32615@@ -196,7 +198,10 @@ static int crypto_report(struct sk_buff *in_skb, struct nlmsghdr *in_nlh,
32616 struct crypto_dump_info info;
32617 int err;
32618
32619- if (!p->cru_driver_name)
32620+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
32621+ return -EINVAL;
32622+
32623+ if (!p->cru_driver_name[0])
32624 return -EINVAL;
32625
32626 alg = crypto_alg_match(p, 1);
32627@@ -260,6 +265,9 @@ static int crypto_update_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
32628 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
32629 LIST_HEAD(list);
32630
32631+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
32632+ return -EINVAL;
32633+
32634 if (priority && !strlen(p->cru_driver_name))
32635 return -EINVAL;
32636
32637@@ -287,6 +295,9 @@ static int crypto_del_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
32638 struct crypto_alg *alg;
32639 struct crypto_user_alg *p = nlmsg_data(nlh);
32640
32641+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
32642+ return -EINVAL;
32643+
32644 alg = crypto_alg_match(p, 1);
32645 if (!alg)
32646 return -ENOENT;
32647@@ -368,6 +379,9 @@ static int crypto_add_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
32648 struct crypto_user_alg *p = nlmsg_data(nlh);
32649 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
32650
32651+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
32652+ return -EINVAL;
32653+
32654 if (strlen(p->cru_driver_name))
32655 exact = 1;
32656
32657diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
32658index f220d64..d359ad6 100644
32659--- a/drivers/acpi/apei/apei-internal.h
32660+++ b/drivers/acpi/apei/apei-internal.h
32661@@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
32662 struct apei_exec_ins_type {
32663 u32 flags;
32664 apei_exec_ins_func_t run;
32665-};
32666+} __do_const;
32667
32668 struct apei_exec_context {
32669 u32 ip;
32670diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
32671index e6defd8..c26a225 100644
32672--- a/drivers/acpi/apei/cper.c
32673+++ b/drivers/acpi/apei/cper.c
32674@@ -38,12 +38,12 @@
32675 */
32676 u64 cper_next_record_id(void)
32677 {
32678- static atomic64_t seq;
32679+ static atomic64_unchecked_t seq;
32680
32681- if (!atomic64_read(&seq))
32682- atomic64_set(&seq, ((u64)get_seconds()) << 32);
32683+ if (!atomic64_read_unchecked(&seq))
32684+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
32685
32686- return atomic64_inc_return(&seq);
32687+ return atomic64_inc_return_unchecked(&seq);
32688 }
32689 EXPORT_SYMBOL_GPL(cper_next_record_id);
32690
32691diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
32692index be60399..778b33e8 100644
32693--- a/drivers/acpi/bgrt.c
32694+++ b/drivers/acpi/bgrt.c
32695@@ -87,8 +87,10 @@ static int __init bgrt_init(void)
32696 return -ENODEV;
32697
32698 sysfs_bin_attr_init(&image_attr);
32699- image_attr.private = bgrt_image;
32700- image_attr.size = bgrt_image_size;
32701+ pax_open_kernel();
32702+ *(void **)&image_attr.private = bgrt_image;
32703+ *(size_t *)&image_attr.size = bgrt_image_size;
32704+ pax_close_kernel();
32705
32706 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
32707 if (!bgrt_kobj)
32708diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
32709index cb96296..b81293b 100644
32710--- a/drivers/acpi/blacklist.c
32711+++ b/drivers/acpi/blacklist.c
32712@@ -52,7 +52,7 @@ struct acpi_blacklist_item {
32713 u32 is_critical_error;
32714 };
32715
32716-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
32717+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
32718
32719 /*
32720 * POLICY: If *anything* doesn't work, put it on the blacklist.
32721@@ -193,7 +193,7 @@ static int __init dmi_disable_osi_win7(const struct dmi_system_id *d)
32722 return 0;
32723 }
32724
32725-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
32726+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
32727 {
32728 .callback = dmi_disable_osi_vista,
32729 .ident = "Fujitsu Siemens",
32730diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
32731index 7586544..636a2f0 100644
32732--- a/drivers/acpi/ec_sys.c
32733+++ b/drivers/acpi/ec_sys.c
32734@@ -12,6 +12,7 @@
32735 #include <linux/acpi.h>
32736 #include <linux/debugfs.h>
32737 #include <linux/module.h>
32738+#include <linux/uaccess.h>
32739 #include "internal.h"
32740
32741 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
32742@@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
32743 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
32744 */
32745 unsigned int size = EC_SPACE_SIZE;
32746- u8 *data = (u8 *) buf;
32747+ u8 data;
32748 loff_t init_off = *off;
32749 int err = 0;
32750
32751@@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
32752 size = count;
32753
32754 while (size) {
32755- err = ec_read(*off, &data[*off - init_off]);
32756+ err = ec_read(*off, &data);
32757 if (err)
32758 return err;
32759+ if (put_user(data, &buf[*off - init_off]))
32760+ return -EFAULT;
32761 *off += 1;
32762 size--;
32763 }
32764@@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
32765
32766 unsigned int size = count;
32767 loff_t init_off = *off;
32768- u8 *data = (u8 *) buf;
32769 int err = 0;
32770
32771 if (*off >= EC_SPACE_SIZE)
32772@@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
32773 }
32774
32775 while (size) {
32776- u8 byte_write = data[*off - init_off];
32777+ u8 byte_write;
32778+ if (get_user(byte_write, &buf[*off - init_off]))
32779+ return -EFAULT;
32780 err = ec_write(*off, byte_write);
32781 if (err)
32782 return err;
32783diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
32784index e83311b..142b5cc 100644
32785--- a/drivers/acpi/processor_driver.c
32786+++ b/drivers/acpi/processor_driver.c
32787@@ -558,7 +558,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
32788 return 0;
32789 #endif
32790
32791- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
32792+ BUG_ON(pr->id >= nr_cpu_ids);
32793
32794 /*
32795 * Buggy BIOS check
32796diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
32797index ed9a1cc..f4a354c 100644
32798--- a/drivers/acpi/processor_idle.c
32799+++ b/drivers/acpi/processor_idle.c
32800@@ -1005,7 +1005,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
32801 {
32802 int i, count = CPUIDLE_DRIVER_STATE_START;
32803 struct acpi_processor_cx *cx;
32804- struct cpuidle_state *state;
32805+ cpuidle_state_no_const *state;
32806 struct cpuidle_driver *drv = &acpi_idle_driver;
32807
32808 if (!pr->flags.power_setup_done)
32809diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
32810index ea61ca9..3fdd70d 100644
32811--- a/drivers/acpi/sysfs.c
32812+++ b/drivers/acpi/sysfs.c
32813@@ -420,11 +420,11 @@ static u32 num_counters;
32814 static struct attribute **all_attrs;
32815 static u32 acpi_gpe_count;
32816
32817-static struct attribute_group interrupt_stats_attr_group = {
32818+static attribute_group_no_const interrupt_stats_attr_group = {
32819 .name = "interrupts",
32820 };
32821
32822-static struct kobj_attribute *counter_attrs;
32823+static kobj_attribute_no_const *counter_attrs;
32824
32825 static void delete_gpe_attr_array(void)
32826 {
32827diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
32828index 6cd7805..07facb3 100644
32829--- a/drivers/ata/libahci.c
32830+++ b/drivers/ata/libahci.c
32831@@ -1230,7 +1230,7 @@ int ahci_kick_engine(struct ata_port *ap)
32832 }
32833 EXPORT_SYMBOL_GPL(ahci_kick_engine);
32834
32835-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
32836+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
32837 struct ata_taskfile *tf, int is_cmd, u16 flags,
32838 unsigned long timeout_msec)
32839 {
32840diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
32841index 501c209..5f28b4d 100644
32842--- a/drivers/ata/libata-core.c
32843+++ b/drivers/ata/libata-core.c
32844@@ -4784,7 +4784,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
32845 struct ata_port *ap;
32846 unsigned int tag;
32847
32848- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32849+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32850 ap = qc->ap;
32851
32852 qc->flags = 0;
32853@@ -4800,7 +4800,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
32854 struct ata_port *ap;
32855 struct ata_link *link;
32856
32857- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32858+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32859 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
32860 ap = qc->ap;
32861 link = qc->dev->link;
32862@@ -5896,6 +5896,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
32863 return;
32864
32865 spin_lock(&lock);
32866+ pax_open_kernel();
32867
32868 for (cur = ops->inherits; cur; cur = cur->inherits) {
32869 void **inherit = (void **)cur;
32870@@ -5909,8 +5910,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
32871 if (IS_ERR(*pp))
32872 *pp = NULL;
32873
32874- ops->inherits = NULL;
32875+ *(struct ata_port_operations **)&ops->inherits = NULL;
32876
32877+ pax_close_kernel();
32878 spin_unlock(&lock);
32879 }
32880
32881diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
32882index 405022d..fb70e53 100644
32883--- a/drivers/ata/pata_arasan_cf.c
32884+++ b/drivers/ata/pata_arasan_cf.c
32885@@ -864,7 +864,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
32886 /* Handle platform specific quirks */
32887 if (pdata->quirk) {
32888 if (pdata->quirk & CF_BROKEN_PIO) {
32889- ap->ops->set_piomode = NULL;
32890+ pax_open_kernel();
32891+ *(void **)&ap->ops->set_piomode = NULL;
32892+ pax_close_kernel();
32893 ap->pio_mask = 0;
32894 }
32895 if (pdata->quirk & CF_BROKEN_MWDMA)
32896diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
32897index f9b983a..887b9d8 100644
32898--- a/drivers/atm/adummy.c
32899+++ b/drivers/atm/adummy.c
32900@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
32901 vcc->pop(vcc, skb);
32902 else
32903 dev_kfree_skb_any(skb);
32904- atomic_inc(&vcc->stats->tx);
32905+ atomic_inc_unchecked(&vcc->stats->tx);
32906
32907 return 0;
32908 }
32909diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
32910index 77a7480..05cde58 100644
32911--- a/drivers/atm/ambassador.c
32912+++ b/drivers/atm/ambassador.c
32913@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
32914 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
32915
32916 // VC layer stats
32917- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32918+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32919
32920 // free the descriptor
32921 kfree (tx_descr);
32922@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
32923 dump_skb ("<<<", vc, skb);
32924
32925 // VC layer stats
32926- atomic_inc(&atm_vcc->stats->rx);
32927+ atomic_inc_unchecked(&atm_vcc->stats->rx);
32928 __net_timestamp(skb);
32929 // end of our responsibility
32930 atm_vcc->push (atm_vcc, skb);
32931@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
32932 } else {
32933 PRINTK (KERN_INFO, "dropped over-size frame");
32934 // should we count this?
32935- atomic_inc(&atm_vcc->stats->rx_drop);
32936+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32937 }
32938
32939 } else {
32940@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
32941 }
32942
32943 if (check_area (skb->data, skb->len)) {
32944- atomic_inc(&atm_vcc->stats->tx_err);
32945+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
32946 return -ENOMEM; // ?
32947 }
32948
32949diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
32950index b22d71c..d6e1049 100644
32951--- a/drivers/atm/atmtcp.c
32952+++ b/drivers/atm/atmtcp.c
32953@@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
32954 if (vcc->pop) vcc->pop(vcc,skb);
32955 else dev_kfree_skb(skb);
32956 if (dev_data) return 0;
32957- atomic_inc(&vcc->stats->tx_err);
32958+ atomic_inc_unchecked(&vcc->stats->tx_err);
32959 return -ENOLINK;
32960 }
32961 size = skb->len+sizeof(struct atmtcp_hdr);
32962@@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
32963 if (!new_skb) {
32964 if (vcc->pop) vcc->pop(vcc,skb);
32965 else dev_kfree_skb(skb);
32966- atomic_inc(&vcc->stats->tx_err);
32967+ atomic_inc_unchecked(&vcc->stats->tx_err);
32968 return -ENOBUFS;
32969 }
32970 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
32971@@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
32972 if (vcc->pop) vcc->pop(vcc,skb);
32973 else dev_kfree_skb(skb);
32974 out_vcc->push(out_vcc,new_skb);
32975- atomic_inc(&vcc->stats->tx);
32976- atomic_inc(&out_vcc->stats->rx);
32977+ atomic_inc_unchecked(&vcc->stats->tx);
32978+ atomic_inc_unchecked(&out_vcc->stats->rx);
32979 return 0;
32980 }
32981
32982@@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
32983 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
32984 read_unlock(&vcc_sklist_lock);
32985 if (!out_vcc) {
32986- atomic_inc(&vcc->stats->tx_err);
32987+ atomic_inc_unchecked(&vcc->stats->tx_err);
32988 goto done;
32989 }
32990 skb_pull(skb,sizeof(struct atmtcp_hdr));
32991@@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
32992 __net_timestamp(new_skb);
32993 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
32994 out_vcc->push(out_vcc,new_skb);
32995- atomic_inc(&vcc->stats->tx);
32996- atomic_inc(&out_vcc->stats->rx);
32997+ atomic_inc_unchecked(&vcc->stats->tx);
32998+ atomic_inc_unchecked(&out_vcc->stats->rx);
32999 done:
33000 if (vcc->pop) vcc->pop(vcc,skb);
33001 else dev_kfree_skb(skb);
33002diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
33003index c1eb6fa..4c71be9 100644
33004--- a/drivers/atm/eni.c
33005+++ b/drivers/atm/eni.c
33006@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
33007 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
33008 vcc->dev->number);
33009 length = 0;
33010- atomic_inc(&vcc->stats->rx_err);
33011+ atomic_inc_unchecked(&vcc->stats->rx_err);
33012 }
33013 else {
33014 length = ATM_CELL_SIZE-1; /* no HEC */
33015@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
33016 size);
33017 }
33018 eff = length = 0;
33019- atomic_inc(&vcc->stats->rx_err);
33020+ atomic_inc_unchecked(&vcc->stats->rx_err);
33021 }
33022 else {
33023 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
33024@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
33025 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
33026 vcc->dev->number,vcc->vci,length,size << 2,descr);
33027 length = eff = 0;
33028- atomic_inc(&vcc->stats->rx_err);
33029+ atomic_inc_unchecked(&vcc->stats->rx_err);
33030 }
33031 }
33032 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
33033@@ -767,7 +767,7 @@ rx_dequeued++;
33034 vcc->push(vcc,skb);
33035 pushed++;
33036 }
33037- atomic_inc(&vcc->stats->rx);
33038+ atomic_inc_unchecked(&vcc->stats->rx);
33039 }
33040 wake_up(&eni_dev->rx_wait);
33041 }
33042@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
33043 PCI_DMA_TODEVICE);
33044 if (vcc->pop) vcc->pop(vcc,skb);
33045 else dev_kfree_skb_irq(skb);
33046- atomic_inc(&vcc->stats->tx);
33047+ atomic_inc_unchecked(&vcc->stats->tx);
33048 wake_up(&eni_dev->tx_wait);
33049 dma_complete++;
33050 }
33051diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
33052index b41c948..a002b17 100644
33053--- a/drivers/atm/firestream.c
33054+++ b/drivers/atm/firestream.c
33055@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
33056 }
33057 }
33058
33059- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
33060+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
33061
33062 fs_dprintk (FS_DEBUG_TXMEM, "i");
33063 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
33064@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
33065 #endif
33066 skb_put (skb, qe->p1 & 0xffff);
33067 ATM_SKB(skb)->vcc = atm_vcc;
33068- atomic_inc(&atm_vcc->stats->rx);
33069+ atomic_inc_unchecked(&atm_vcc->stats->rx);
33070 __net_timestamp(skb);
33071 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
33072 atm_vcc->push (atm_vcc, skb);
33073@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
33074 kfree (pe);
33075 }
33076 if (atm_vcc)
33077- atomic_inc(&atm_vcc->stats->rx_drop);
33078+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
33079 break;
33080 case 0x1f: /* Reassembly abort: no buffers. */
33081 /* Silently increment error counter. */
33082 if (atm_vcc)
33083- atomic_inc(&atm_vcc->stats->rx_drop);
33084+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
33085 break;
33086 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
33087 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
33088diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
33089index 204814e..cede831 100644
33090--- a/drivers/atm/fore200e.c
33091+++ b/drivers/atm/fore200e.c
33092@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
33093 #endif
33094 /* check error condition */
33095 if (*entry->status & STATUS_ERROR)
33096- atomic_inc(&vcc->stats->tx_err);
33097+ atomic_inc_unchecked(&vcc->stats->tx_err);
33098 else
33099- atomic_inc(&vcc->stats->tx);
33100+ atomic_inc_unchecked(&vcc->stats->tx);
33101 }
33102 }
33103
33104@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
33105 if (skb == NULL) {
33106 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
33107
33108- atomic_inc(&vcc->stats->rx_drop);
33109+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33110 return -ENOMEM;
33111 }
33112
33113@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
33114
33115 dev_kfree_skb_any(skb);
33116
33117- atomic_inc(&vcc->stats->rx_drop);
33118+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33119 return -ENOMEM;
33120 }
33121
33122 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
33123
33124 vcc->push(vcc, skb);
33125- atomic_inc(&vcc->stats->rx);
33126+ atomic_inc_unchecked(&vcc->stats->rx);
33127
33128 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
33129
33130@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
33131 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
33132 fore200e->atm_dev->number,
33133 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
33134- atomic_inc(&vcc->stats->rx_err);
33135+ atomic_inc_unchecked(&vcc->stats->rx_err);
33136 }
33137 }
33138
33139@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
33140 goto retry_here;
33141 }
33142
33143- atomic_inc(&vcc->stats->tx_err);
33144+ atomic_inc_unchecked(&vcc->stats->tx_err);
33145
33146 fore200e->tx_sat++;
33147 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
33148diff --git a/drivers/atm/he.c b/drivers/atm/he.c
33149index 72b6960..cf9167a 100644
33150--- a/drivers/atm/he.c
33151+++ b/drivers/atm/he.c
33152@@ -1699,7 +1699,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
33153
33154 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
33155 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
33156- atomic_inc(&vcc->stats->rx_drop);
33157+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33158 goto return_host_buffers;
33159 }
33160
33161@@ -1726,7 +1726,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
33162 RBRQ_LEN_ERR(he_dev->rbrq_head)
33163 ? "LEN_ERR" : "",
33164 vcc->vpi, vcc->vci);
33165- atomic_inc(&vcc->stats->rx_err);
33166+ atomic_inc_unchecked(&vcc->stats->rx_err);
33167 goto return_host_buffers;
33168 }
33169
33170@@ -1778,7 +1778,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
33171 vcc->push(vcc, skb);
33172 spin_lock(&he_dev->global_lock);
33173
33174- atomic_inc(&vcc->stats->rx);
33175+ atomic_inc_unchecked(&vcc->stats->rx);
33176
33177 return_host_buffers:
33178 ++pdus_assembled;
33179@@ -2104,7 +2104,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
33180 tpd->vcc->pop(tpd->vcc, tpd->skb);
33181 else
33182 dev_kfree_skb_any(tpd->skb);
33183- atomic_inc(&tpd->vcc->stats->tx_err);
33184+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
33185 }
33186 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
33187 return;
33188@@ -2516,7 +2516,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
33189 vcc->pop(vcc, skb);
33190 else
33191 dev_kfree_skb_any(skb);
33192- atomic_inc(&vcc->stats->tx_err);
33193+ atomic_inc_unchecked(&vcc->stats->tx_err);
33194 return -EINVAL;
33195 }
33196
33197@@ -2527,7 +2527,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
33198 vcc->pop(vcc, skb);
33199 else
33200 dev_kfree_skb_any(skb);
33201- atomic_inc(&vcc->stats->tx_err);
33202+ atomic_inc_unchecked(&vcc->stats->tx_err);
33203 return -EINVAL;
33204 }
33205 #endif
33206@@ -2539,7 +2539,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
33207 vcc->pop(vcc, skb);
33208 else
33209 dev_kfree_skb_any(skb);
33210- atomic_inc(&vcc->stats->tx_err);
33211+ atomic_inc_unchecked(&vcc->stats->tx_err);
33212 spin_unlock_irqrestore(&he_dev->global_lock, flags);
33213 return -ENOMEM;
33214 }
33215@@ -2581,7 +2581,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
33216 vcc->pop(vcc, skb);
33217 else
33218 dev_kfree_skb_any(skb);
33219- atomic_inc(&vcc->stats->tx_err);
33220+ atomic_inc_unchecked(&vcc->stats->tx_err);
33221 spin_unlock_irqrestore(&he_dev->global_lock, flags);
33222 return -ENOMEM;
33223 }
33224@@ -2612,7 +2612,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
33225 __enqueue_tpd(he_dev, tpd, cid);
33226 spin_unlock_irqrestore(&he_dev->global_lock, flags);
33227
33228- atomic_inc(&vcc->stats->tx);
33229+ atomic_inc_unchecked(&vcc->stats->tx);
33230
33231 return 0;
33232 }
33233diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
33234index 1dc0519..1aadaf7 100644
33235--- a/drivers/atm/horizon.c
33236+++ b/drivers/atm/horizon.c
33237@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
33238 {
33239 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
33240 // VC layer stats
33241- atomic_inc(&vcc->stats->rx);
33242+ atomic_inc_unchecked(&vcc->stats->rx);
33243 __net_timestamp(skb);
33244 // end of our responsibility
33245 vcc->push (vcc, skb);
33246@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
33247 dev->tx_iovec = NULL;
33248
33249 // VC layer stats
33250- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
33251+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
33252
33253 // free the skb
33254 hrz_kfree_skb (skb);
33255diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
33256index 272f009..a18ba55 100644
33257--- a/drivers/atm/idt77252.c
33258+++ b/drivers/atm/idt77252.c
33259@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
33260 else
33261 dev_kfree_skb(skb);
33262
33263- atomic_inc(&vcc->stats->tx);
33264+ atomic_inc_unchecked(&vcc->stats->tx);
33265 }
33266
33267 atomic_dec(&scq->used);
33268@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
33269 if ((sb = dev_alloc_skb(64)) == NULL) {
33270 printk("%s: Can't allocate buffers for aal0.\n",
33271 card->name);
33272- atomic_add(i, &vcc->stats->rx_drop);
33273+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
33274 break;
33275 }
33276 if (!atm_charge(vcc, sb->truesize)) {
33277 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
33278 card->name);
33279- atomic_add(i - 1, &vcc->stats->rx_drop);
33280+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
33281 dev_kfree_skb(sb);
33282 break;
33283 }
33284@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
33285 ATM_SKB(sb)->vcc = vcc;
33286 __net_timestamp(sb);
33287 vcc->push(vcc, sb);
33288- atomic_inc(&vcc->stats->rx);
33289+ atomic_inc_unchecked(&vcc->stats->rx);
33290
33291 cell += ATM_CELL_PAYLOAD;
33292 }
33293@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
33294 "(CDC: %08x)\n",
33295 card->name, len, rpp->len, readl(SAR_REG_CDC));
33296 recycle_rx_pool_skb(card, rpp);
33297- atomic_inc(&vcc->stats->rx_err);
33298+ atomic_inc_unchecked(&vcc->stats->rx_err);
33299 return;
33300 }
33301 if (stat & SAR_RSQE_CRC) {
33302 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
33303 recycle_rx_pool_skb(card, rpp);
33304- atomic_inc(&vcc->stats->rx_err);
33305+ atomic_inc_unchecked(&vcc->stats->rx_err);
33306 return;
33307 }
33308 if (skb_queue_len(&rpp->queue) > 1) {
33309@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
33310 RXPRINTK("%s: Can't alloc RX skb.\n",
33311 card->name);
33312 recycle_rx_pool_skb(card, rpp);
33313- atomic_inc(&vcc->stats->rx_err);
33314+ atomic_inc_unchecked(&vcc->stats->rx_err);
33315 return;
33316 }
33317 if (!atm_charge(vcc, skb->truesize)) {
33318@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
33319 __net_timestamp(skb);
33320
33321 vcc->push(vcc, skb);
33322- atomic_inc(&vcc->stats->rx);
33323+ atomic_inc_unchecked(&vcc->stats->rx);
33324
33325 return;
33326 }
33327@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
33328 __net_timestamp(skb);
33329
33330 vcc->push(vcc, skb);
33331- atomic_inc(&vcc->stats->rx);
33332+ atomic_inc_unchecked(&vcc->stats->rx);
33333
33334 if (skb->truesize > SAR_FB_SIZE_3)
33335 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
33336@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
33337 if (vcc->qos.aal != ATM_AAL0) {
33338 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
33339 card->name, vpi, vci);
33340- atomic_inc(&vcc->stats->rx_drop);
33341+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33342 goto drop;
33343 }
33344
33345 if ((sb = dev_alloc_skb(64)) == NULL) {
33346 printk("%s: Can't allocate buffers for AAL0.\n",
33347 card->name);
33348- atomic_inc(&vcc->stats->rx_err);
33349+ atomic_inc_unchecked(&vcc->stats->rx_err);
33350 goto drop;
33351 }
33352
33353@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
33354 ATM_SKB(sb)->vcc = vcc;
33355 __net_timestamp(sb);
33356 vcc->push(vcc, sb);
33357- atomic_inc(&vcc->stats->rx);
33358+ atomic_inc_unchecked(&vcc->stats->rx);
33359
33360 drop:
33361 skb_pull(queue, 64);
33362@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
33363
33364 if (vc == NULL) {
33365 printk("%s: NULL connection in send().\n", card->name);
33366- atomic_inc(&vcc->stats->tx_err);
33367+ atomic_inc_unchecked(&vcc->stats->tx_err);
33368 dev_kfree_skb(skb);
33369 return -EINVAL;
33370 }
33371 if (!test_bit(VCF_TX, &vc->flags)) {
33372 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
33373- atomic_inc(&vcc->stats->tx_err);
33374+ atomic_inc_unchecked(&vcc->stats->tx_err);
33375 dev_kfree_skb(skb);
33376 return -EINVAL;
33377 }
33378@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
33379 break;
33380 default:
33381 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
33382- atomic_inc(&vcc->stats->tx_err);
33383+ atomic_inc_unchecked(&vcc->stats->tx_err);
33384 dev_kfree_skb(skb);
33385 return -EINVAL;
33386 }
33387
33388 if (skb_shinfo(skb)->nr_frags != 0) {
33389 printk("%s: No scatter-gather yet.\n", card->name);
33390- atomic_inc(&vcc->stats->tx_err);
33391+ atomic_inc_unchecked(&vcc->stats->tx_err);
33392 dev_kfree_skb(skb);
33393 return -EINVAL;
33394 }
33395@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
33396
33397 err = queue_skb(card, vc, skb, oam);
33398 if (err) {
33399- atomic_inc(&vcc->stats->tx_err);
33400+ atomic_inc_unchecked(&vcc->stats->tx_err);
33401 dev_kfree_skb(skb);
33402 return err;
33403 }
33404@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
33405 skb = dev_alloc_skb(64);
33406 if (!skb) {
33407 printk("%s: Out of memory in send_oam().\n", card->name);
33408- atomic_inc(&vcc->stats->tx_err);
33409+ atomic_inc_unchecked(&vcc->stats->tx_err);
33410 return -ENOMEM;
33411 }
33412 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
33413diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
33414index 4217f29..88f547a 100644
33415--- a/drivers/atm/iphase.c
33416+++ b/drivers/atm/iphase.c
33417@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
33418 status = (u_short) (buf_desc_ptr->desc_mode);
33419 if (status & (RX_CER | RX_PTE | RX_OFL))
33420 {
33421- atomic_inc(&vcc->stats->rx_err);
33422+ atomic_inc_unchecked(&vcc->stats->rx_err);
33423 IF_ERR(printk("IA: bad packet, dropping it");)
33424 if (status & RX_CER) {
33425 IF_ERR(printk(" cause: packet CRC error\n");)
33426@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
33427 len = dma_addr - buf_addr;
33428 if (len > iadev->rx_buf_sz) {
33429 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
33430- atomic_inc(&vcc->stats->rx_err);
33431+ atomic_inc_unchecked(&vcc->stats->rx_err);
33432 goto out_free_desc;
33433 }
33434
33435@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
33436 ia_vcc = INPH_IA_VCC(vcc);
33437 if (ia_vcc == NULL)
33438 {
33439- atomic_inc(&vcc->stats->rx_err);
33440+ atomic_inc_unchecked(&vcc->stats->rx_err);
33441 atm_return(vcc, skb->truesize);
33442 dev_kfree_skb_any(skb);
33443 goto INCR_DLE;
33444@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
33445 if ((length > iadev->rx_buf_sz) || (length >
33446 (skb->len - sizeof(struct cpcs_trailer))))
33447 {
33448- atomic_inc(&vcc->stats->rx_err);
33449+ atomic_inc_unchecked(&vcc->stats->rx_err);
33450 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
33451 length, skb->len);)
33452 atm_return(vcc, skb->truesize);
33453@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
33454
33455 IF_RX(printk("rx_dle_intr: skb push");)
33456 vcc->push(vcc,skb);
33457- atomic_inc(&vcc->stats->rx);
33458+ atomic_inc_unchecked(&vcc->stats->rx);
33459 iadev->rx_pkt_cnt++;
33460 }
33461 INCR_DLE:
33462@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
33463 {
33464 struct k_sonet_stats *stats;
33465 stats = &PRIV(_ia_dev[board])->sonet_stats;
33466- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
33467- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
33468- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
33469- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
33470- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
33471- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
33472- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
33473- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
33474- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
33475+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
33476+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
33477+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
33478+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
33479+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
33480+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
33481+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
33482+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
33483+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
33484 }
33485 ia_cmds.status = 0;
33486 break;
33487@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
33488 if ((desc == 0) || (desc > iadev->num_tx_desc))
33489 {
33490 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
33491- atomic_inc(&vcc->stats->tx);
33492+ atomic_inc_unchecked(&vcc->stats->tx);
33493 if (vcc->pop)
33494 vcc->pop(vcc, skb);
33495 else
33496@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
33497 ATM_DESC(skb) = vcc->vci;
33498 skb_queue_tail(&iadev->tx_dma_q, skb);
33499
33500- atomic_inc(&vcc->stats->tx);
33501+ atomic_inc_unchecked(&vcc->stats->tx);
33502 iadev->tx_pkt_cnt++;
33503 /* Increment transaction counter */
33504 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
33505
33506 #if 0
33507 /* add flow control logic */
33508- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
33509+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
33510 if (iavcc->vc_desc_cnt > 10) {
33511 vcc->tx_quota = vcc->tx_quota * 3 / 4;
33512 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
33513diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
33514index fa7d701..1e404c7 100644
33515--- a/drivers/atm/lanai.c
33516+++ b/drivers/atm/lanai.c
33517@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
33518 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
33519 lanai_endtx(lanai, lvcc);
33520 lanai_free_skb(lvcc->tx.atmvcc, skb);
33521- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
33522+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
33523 }
33524
33525 /* Try to fill the buffer - don't call unless there is backlog */
33526@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
33527 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
33528 __net_timestamp(skb);
33529 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
33530- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
33531+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
33532 out:
33533 lvcc->rx.buf.ptr = end;
33534 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
33535@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
33536 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
33537 "vcc %d\n", lanai->number, (unsigned int) s, vci);
33538 lanai->stats.service_rxnotaal5++;
33539- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
33540+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
33541 return 0;
33542 }
33543 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
33544@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
33545 int bytes;
33546 read_unlock(&vcc_sklist_lock);
33547 DPRINTK("got trashed rx pdu on vci %d\n", vci);
33548- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
33549+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
33550 lvcc->stats.x.aal5.service_trash++;
33551 bytes = (SERVICE_GET_END(s) * 16) -
33552 (((unsigned long) lvcc->rx.buf.ptr) -
33553@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
33554 }
33555 if (s & SERVICE_STREAM) {
33556 read_unlock(&vcc_sklist_lock);
33557- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
33558+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
33559 lvcc->stats.x.aal5.service_stream++;
33560 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
33561 "PDU on VCI %d!\n", lanai->number, vci);
33562@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
33563 return 0;
33564 }
33565 DPRINTK("got rx crc error on vci %d\n", vci);
33566- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
33567+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
33568 lvcc->stats.x.aal5.service_rxcrc++;
33569 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
33570 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
33571diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
33572index ed1d2b7..8cffc1f 100644
33573--- a/drivers/atm/nicstar.c
33574+++ b/drivers/atm/nicstar.c
33575@@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
33576 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
33577 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
33578 card->index);
33579- atomic_inc(&vcc->stats->tx_err);
33580+ atomic_inc_unchecked(&vcc->stats->tx_err);
33581 dev_kfree_skb_any(skb);
33582 return -EINVAL;
33583 }
33584@@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
33585 if (!vc->tx) {
33586 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
33587 card->index);
33588- atomic_inc(&vcc->stats->tx_err);
33589+ atomic_inc_unchecked(&vcc->stats->tx_err);
33590 dev_kfree_skb_any(skb);
33591 return -EINVAL;
33592 }
33593@@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
33594 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
33595 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
33596 card->index);
33597- atomic_inc(&vcc->stats->tx_err);
33598+ atomic_inc_unchecked(&vcc->stats->tx_err);
33599 dev_kfree_skb_any(skb);
33600 return -EINVAL;
33601 }
33602
33603 if (skb_shinfo(skb)->nr_frags != 0) {
33604 printk("nicstar%d: No scatter-gather yet.\n", card->index);
33605- atomic_inc(&vcc->stats->tx_err);
33606+ atomic_inc_unchecked(&vcc->stats->tx_err);
33607 dev_kfree_skb_any(skb);
33608 return -EINVAL;
33609 }
33610@@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
33611 }
33612
33613 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
33614- atomic_inc(&vcc->stats->tx_err);
33615+ atomic_inc_unchecked(&vcc->stats->tx_err);
33616 dev_kfree_skb_any(skb);
33617 return -EIO;
33618 }
33619- atomic_inc(&vcc->stats->tx);
33620+ atomic_inc_unchecked(&vcc->stats->tx);
33621
33622 return 0;
33623 }
33624@@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33625 printk
33626 ("nicstar%d: Can't allocate buffers for aal0.\n",
33627 card->index);
33628- atomic_add(i, &vcc->stats->rx_drop);
33629+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
33630 break;
33631 }
33632 if (!atm_charge(vcc, sb->truesize)) {
33633 RXPRINTK
33634 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
33635 card->index);
33636- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
33637+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
33638 dev_kfree_skb_any(sb);
33639 break;
33640 }
33641@@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33642 ATM_SKB(sb)->vcc = vcc;
33643 __net_timestamp(sb);
33644 vcc->push(vcc, sb);
33645- atomic_inc(&vcc->stats->rx);
33646+ atomic_inc_unchecked(&vcc->stats->rx);
33647 cell += ATM_CELL_PAYLOAD;
33648 }
33649
33650@@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33651 if (iovb == NULL) {
33652 printk("nicstar%d: Out of iovec buffers.\n",
33653 card->index);
33654- atomic_inc(&vcc->stats->rx_drop);
33655+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33656 recycle_rx_buf(card, skb);
33657 return;
33658 }
33659@@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33660 small or large buffer itself. */
33661 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
33662 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
33663- atomic_inc(&vcc->stats->rx_err);
33664+ atomic_inc_unchecked(&vcc->stats->rx_err);
33665 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
33666 NS_MAX_IOVECS);
33667 NS_PRV_IOVCNT(iovb) = 0;
33668@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33669 ("nicstar%d: Expected a small buffer, and this is not one.\n",
33670 card->index);
33671 which_list(card, skb);
33672- atomic_inc(&vcc->stats->rx_err);
33673+ atomic_inc_unchecked(&vcc->stats->rx_err);
33674 recycle_rx_buf(card, skb);
33675 vc->rx_iov = NULL;
33676 recycle_iov_buf(card, iovb);
33677@@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33678 ("nicstar%d: Expected a large buffer, and this is not one.\n",
33679 card->index);
33680 which_list(card, skb);
33681- atomic_inc(&vcc->stats->rx_err);
33682+ atomic_inc_unchecked(&vcc->stats->rx_err);
33683 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
33684 NS_PRV_IOVCNT(iovb));
33685 vc->rx_iov = NULL;
33686@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33687 printk(" - PDU size mismatch.\n");
33688 else
33689 printk(".\n");
33690- atomic_inc(&vcc->stats->rx_err);
33691+ atomic_inc_unchecked(&vcc->stats->rx_err);
33692 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
33693 NS_PRV_IOVCNT(iovb));
33694 vc->rx_iov = NULL;
33695@@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33696 /* skb points to a small buffer */
33697 if (!atm_charge(vcc, skb->truesize)) {
33698 push_rxbufs(card, skb);
33699- atomic_inc(&vcc->stats->rx_drop);
33700+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33701 } else {
33702 skb_put(skb, len);
33703 dequeue_sm_buf(card, skb);
33704@@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33705 ATM_SKB(skb)->vcc = vcc;
33706 __net_timestamp(skb);
33707 vcc->push(vcc, skb);
33708- atomic_inc(&vcc->stats->rx);
33709+ atomic_inc_unchecked(&vcc->stats->rx);
33710 }
33711 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
33712 struct sk_buff *sb;
33713@@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33714 if (len <= NS_SMBUFSIZE) {
33715 if (!atm_charge(vcc, sb->truesize)) {
33716 push_rxbufs(card, sb);
33717- atomic_inc(&vcc->stats->rx_drop);
33718+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33719 } else {
33720 skb_put(sb, len);
33721 dequeue_sm_buf(card, sb);
33722@@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33723 ATM_SKB(sb)->vcc = vcc;
33724 __net_timestamp(sb);
33725 vcc->push(vcc, sb);
33726- atomic_inc(&vcc->stats->rx);
33727+ atomic_inc_unchecked(&vcc->stats->rx);
33728 }
33729
33730 push_rxbufs(card, skb);
33731@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33732
33733 if (!atm_charge(vcc, skb->truesize)) {
33734 push_rxbufs(card, skb);
33735- atomic_inc(&vcc->stats->rx_drop);
33736+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33737 } else {
33738 dequeue_lg_buf(card, skb);
33739 #ifdef NS_USE_DESTRUCTORS
33740@@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33741 ATM_SKB(skb)->vcc = vcc;
33742 __net_timestamp(skb);
33743 vcc->push(vcc, skb);
33744- atomic_inc(&vcc->stats->rx);
33745+ atomic_inc_unchecked(&vcc->stats->rx);
33746 }
33747
33748 push_rxbufs(card, sb);
33749@@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33750 printk
33751 ("nicstar%d: Out of huge buffers.\n",
33752 card->index);
33753- atomic_inc(&vcc->stats->rx_drop);
33754+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33755 recycle_iovec_rx_bufs(card,
33756 (struct iovec *)
33757 iovb->data,
33758@@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33759 card->hbpool.count++;
33760 } else
33761 dev_kfree_skb_any(hb);
33762- atomic_inc(&vcc->stats->rx_drop);
33763+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33764 } else {
33765 /* Copy the small buffer to the huge buffer */
33766 sb = (struct sk_buff *)iov->iov_base;
33767@@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33768 #endif /* NS_USE_DESTRUCTORS */
33769 __net_timestamp(hb);
33770 vcc->push(vcc, hb);
33771- atomic_inc(&vcc->stats->rx);
33772+ atomic_inc_unchecked(&vcc->stats->rx);
33773 }
33774 }
33775
33776diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
33777index 0474a89..06ea4a1 100644
33778--- a/drivers/atm/solos-pci.c
33779+++ b/drivers/atm/solos-pci.c
33780@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
33781 }
33782 atm_charge(vcc, skb->truesize);
33783 vcc->push(vcc, skb);
33784- atomic_inc(&vcc->stats->rx);
33785+ atomic_inc_unchecked(&vcc->stats->rx);
33786 break;
33787
33788 case PKT_STATUS:
33789@@ -1117,7 +1117,7 @@ static uint32_t fpga_tx(struct solos_card *card)
33790 vcc = SKB_CB(oldskb)->vcc;
33791
33792 if (vcc) {
33793- atomic_inc(&vcc->stats->tx);
33794+ atomic_inc_unchecked(&vcc->stats->tx);
33795 solos_pop(vcc, oldskb);
33796 } else {
33797 dev_kfree_skb_irq(oldskb);
33798diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
33799index 0215934..ce9f5b1 100644
33800--- a/drivers/atm/suni.c
33801+++ b/drivers/atm/suni.c
33802@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
33803
33804
33805 #define ADD_LIMITED(s,v) \
33806- atomic_add((v),&stats->s); \
33807- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
33808+ atomic_add_unchecked((v),&stats->s); \
33809+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
33810
33811
33812 static void suni_hz(unsigned long from_timer)
33813diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
33814index 5120a96..e2572bd 100644
33815--- a/drivers/atm/uPD98402.c
33816+++ b/drivers/atm/uPD98402.c
33817@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
33818 struct sonet_stats tmp;
33819 int error = 0;
33820
33821- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
33822+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
33823 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
33824 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
33825 if (zero && !error) {
33826@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
33827
33828
33829 #define ADD_LIMITED(s,v) \
33830- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
33831- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
33832- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
33833+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
33834+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
33835+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
33836
33837
33838 static void stat_event(struct atm_dev *dev)
33839@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
33840 if (reason & uPD98402_INT_PFM) stat_event(dev);
33841 if (reason & uPD98402_INT_PCO) {
33842 (void) GET(PCOCR); /* clear interrupt cause */
33843- atomic_add(GET(HECCT),
33844+ atomic_add_unchecked(GET(HECCT),
33845 &PRIV(dev)->sonet_stats.uncorr_hcs);
33846 }
33847 if ((reason & uPD98402_INT_RFO) &&
33848@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
33849 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
33850 uPD98402_INT_LOS),PIMR); /* enable them */
33851 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
33852- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
33853- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
33854- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
33855+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
33856+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
33857+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
33858 return 0;
33859 }
33860
33861diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
33862index 969c3c2..9b72956 100644
33863--- a/drivers/atm/zatm.c
33864+++ b/drivers/atm/zatm.c
33865@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
33866 }
33867 if (!size) {
33868 dev_kfree_skb_irq(skb);
33869- if (vcc) atomic_inc(&vcc->stats->rx_err);
33870+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
33871 continue;
33872 }
33873 if (!atm_charge(vcc,skb->truesize)) {
33874@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
33875 skb->len = size;
33876 ATM_SKB(skb)->vcc = vcc;
33877 vcc->push(vcc,skb);
33878- atomic_inc(&vcc->stats->rx);
33879+ atomic_inc_unchecked(&vcc->stats->rx);
33880 }
33881 zout(pos & 0xffff,MTA(mbx));
33882 #if 0 /* probably a stupid idea */
33883@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
33884 skb_queue_head(&zatm_vcc->backlog,skb);
33885 break;
33886 }
33887- atomic_inc(&vcc->stats->tx);
33888+ atomic_inc_unchecked(&vcc->stats->tx);
33889 wake_up(&zatm_vcc->tx_wait);
33890 }
33891
33892diff --git a/drivers/base/bus.c b/drivers/base/bus.c
33893index 6856303..0602d70 100644
33894--- a/drivers/base/bus.c
33895+++ b/drivers/base/bus.c
33896@@ -1163,7 +1163,7 @@ int subsys_interface_register(struct subsys_interface *sif)
33897 return -EINVAL;
33898
33899 mutex_lock(&subsys->p->mutex);
33900- list_add_tail(&sif->node, &subsys->p->interfaces);
33901+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
33902 if (sif->add_dev) {
33903 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
33904 while ((dev = subsys_dev_iter_next(&iter)))
33905@@ -1188,7 +1188,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
33906 subsys = sif->subsys;
33907
33908 mutex_lock(&subsys->p->mutex);
33909- list_del_init(&sif->node);
33910+ pax_list_del_init((struct list_head *)&sif->node);
33911 if (sif->remove_dev) {
33912 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
33913 while ((dev = subsys_dev_iter_next(&iter)))
33914diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
33915index 17cf7ca..7e553e1 100644
33916--- a/drivers/base/devtmpfs.c
33917+++ b/drivers/base/devtmpfs.c
33918@@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
33919 if (!thread)
33920 return 0;
33921
33922- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
33923+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
33924 if (err)
33925 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
33926 else
33927diff --git a/drivers/base/node.c b/drivers/base/node.c
33928index fac124a..66bd4ab 100644
33929--- a/drivers/base/node.c
33930+++ b/drivers/base/node.c
33931@@ -625,7 +625,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
33932 struct node_attr {
33933 struct device_attribute attr;
33934 enum node_states state;
33935-};
33936+} __do_const;
33937
33938 static ssize_t show_node_state(struct device *dev,
33939 struct device_attribute *attr, char *buf)
33940diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
33941index acc3a8d..981c236 100644
33942--- a/drivers/base/power/domain.c
33943+++ b/drivers/base/power/domain.c
33944@@ -1851,7 +1851,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
33945 {
33946 struct cpuidle_driver *cpuidle_drv;
33947 struct gpd_cpu_data *cpu_data;
33948- struct cpuidle_state *idle_state;
33949+ cpuidle_state_no_const *idle_state;
33950 int ret = 0;
33951
33952 if (IS_ERR_OR_NULL(genpd) || state < 0)
33953@@ -1919,7 +1919,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
33954 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
33955 {
33956 struct gpd_cpu_data *cpu_data;
33957- struct cpuidle_state *idle_state;
33958+ cpuidle_state_no_const *idle_state;
33959 int ret = 0;
33960
33961 if (IS_ERR_OR_NULL(genpd))
33962diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
33963index e6ee5e8..98ad7fc 100644
33964--- a/drivers/base/power/wakeup.c
33965+++ b/drivers/base/power/wakeup.c
33966@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
33967 * They need to be modified together atomically, so it's better to use one
33968 * atomic variable to hold them both.
33969 */
33970-static atomic_t combined_event_count = ATOMIC_INIT(0);
33971+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
33972
33973 #define IN_PROGRESS_BITS (sizeof(int) * 4)
33974 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
33975
33976 static void split_counters(unsigned int *cnt, unsigned int *inpr)
33977 {
33978- unsigned int comb = atomic_read(&combined_event_count);
33979+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
33980
33981 *cnt = (comb >> IN_PROGRESS_BITS);
33982 *inpr = comb & MAX_IN_PROGRESS;
33983@@ -389,7 +389,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
33984 ws->start_prevent_time = ws->last_time;
33985
33986 /* Increment the counter of events in progress. */
33987- cec = atomic_inc_return(&combined_event_count);
33988+ cec = atomic_inc_return_unchecked(&combined_event_count);
33989
33990 trace_wakeup_source_activate(ws->name, cec);
33991 }
33992@@ -515,7 +515,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
33993 * Increment the counter of registered wakeup events and decrement the
33994 * couter of wakeup events in progress simultaneously.
33995 */
33996- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
33997+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
33998 trace_wakeup_source_deactivate(ws->name, cec);
33999
34000 split_counters(&cnt, &inpr);
34001diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
34002index e8d11b6..7b1b36f 100644
34003--- a/drivers/base/syscore.c
34004+++ b/drivers/base/syscore.c
34005@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
34006 void register_syscore_ops(struct syscore_ops *ops)
34007 {
34008 mutex_lock(&syscore_ops_lock);
34009- list_add_tail(&ops->node, &syscore_ops_list);
34010+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
34011 mutex_unlock(&syscore_ops_lock);
34012 }
34013 EXPORT_SYMBOL_GPL(register_syscore_ops);
34014@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
34015 void unregister_syscore_ops(struct syscore_ops *ops)
34016 {
34017 mutex_lock(&syscore_ops_lock);
34018- list_del(&ops->node);
34019+ pax_list_del((struct list_head *)&ops->node);
34020 mutex_unlock(&syscore_ops_lock);
34021 }
34022 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
34023diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
34024index ade58bc..867143d 100644
34025--- a/drivers/block/cciss.c
34026+++ b/drivers/block/cciss.c
34027@@ -1196,6 +1196,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
34028 int err;
34029 u32 cp;
34030
34031+ memset(&arg64, 0, sizeof(arg64));
34032+
34033 err = 0;
34034 err |=
34035 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
34036@@ -3005,7 +3007,7 @@ static void start_io(ctlr_info_t *h)
34037 while (!list_empty(&h->reqQ)) {
34038 c = list_entry(h->reqQ.next, CommandList_struct, list);
34039 /* can't do anything if fifo is full */
34040- if ((h->access.fifo_full(h))) {
34041+ if ((h->access->fifo_full(h))) {
34042 dev_warn(&h->pdev->dev, "fifo full\n");
34043 break;
34044 }
34045@@ -3015,7 +3017,7 @@ static void start_io(ctlr_info_t *h)
34046 h->Qdepth--;
34047
34048 /* Tell the controller execute command */
34049- h->access.submit_command(h, c);
34050+ h->access->submit_command(h, c);
34051
34052 /* Put job onto the completed Q */
34053 addQ(&h->cmpQ, c);
34054@@ -3441,17 +3443,17 @@ startio:
34055
34056 static inline unsigned long get_next_completion(ctlr_info_t *h)
34057 {
34058- return h->access.command_completed(h);
34059+ return h->access->command_completed(h);
34060 }
34061
34062 static inline int interrupt_pending(ctlr_info_t *h)
34063 {
34064- return h->access.intr_pending(h);
34065+ return h->access->intr_pending(h);
34066 }
34067
34068 static inline long interrupt_not_for_us(ctlr_info_t *h)
34069 {
34070- return ((h->access.intr_pending(h) == 0) ||
34071+ return ((h->access->intr_pending(h) == 0) ||
34072 (h->interrupts_enabled == 0));
34073 }
34074
34075@@ -3484,7 +3486,7 @@ static inline u32 next_command(ctlr_info_t *h)
34076 u32 a;
34077
34078 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
34079- return h->access.command_completed(h);
34080+ return h->access->command_completed(h);
34081
34082 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
34083 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
34084@@ -4041,7 +4043,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
34085 trans_support & CFGTBL_Trans_use_short_tags);
34086
34087 /* Change the access methods to the performant access methods */
34088- h->access = SA5_performant_access;
34089+ h->access = &SA5_performant_access;
34090 h->transMethod = CFGTBL_Trans_Performant;
34091
34092 return;
34093@@ -4310,7 +4312,7 @@ static int cciss_pci_init(ctlr_info_t *h)
34094 if (prod_index < 0)
34095 return -ENODEV;
34096 h->product_name = products[prod_index].product_name;
34097- h->access = *(products[prod_index].access);
34098+ h->access = products[prod_index].access;
34099
34100 if (cciss_board_disabled(h)) {
34101 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
34102@@ -5032,7 +5034,7 @@ reinit_after_soft_reset:
34103 }
34104
34105 /* make sure the board interrupts are off */
34106- h->access.set_intr_mask(h, CCISS_INTR_OFF);
34107+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
34108 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
34109 if (rc)
34110 goto clean2;
34111@@ -5082,7 +5084,7 @@ reinit_after_soft_reset:
34112 * fake ones to scoop up any residual completions.
34113 */
34114 spin_lock_irqsave(&h->lock, flags);
34115- h->access.set_intr_mask(h, CCISS_INTR_OFF);
34116+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
34117 spin_unlock_irqrestore(&h->lock, flags);
34118 free_irq(h->intr[h->intr_mode], h);
34119 rc = cciss_request_irq(h, cciss_msix_discard_completions,
34120@@ -5102,9 +5104,9 @@ reinit_after_soft_reset:
34121 dev_info(&h->pdev->dev, "Board READY.\n");
34122 dev_info(&h->pdev->dev,
34123 "Waiting for stale completions to drain.\n");
34124- h->access.set_intr_mask(h, CCISS_INTR_ON);
34125+ h->access->set_intr_mask(h, CCISS_INTR_ON);
34126 msleep(10000);
34127- h->access.set_intr_mask(h, CCISS_INTR_OFF);
34128+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
34129
34130 rc = controller_reset_failed(h->cfgtable);
34131 if (rc)
34132@@ -5127,7 +5129,7 @@ reinit_after_soft_reset:
34133 cciss_scsi_setup(h);
34134
34135 /* Turn the interrupts on so we can service requests */
34136- h->access.set_intr_mask(h, CCISS_INTR_ON);
34137+ h->access->set_intr_mask(h, CCISS_INTR_ON);
34138
34139 /* Get the firmware version */
34140 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
34141@@ -5199,7 +5201,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
34142 kfree(flush_buf);
34143 if (return_code != IO_OK)
34144 dev_warn(&h->pdev->dev, "Error flushing cache\n");
34145- h->access.set_intr_mask(h, CCISS_INTR_OFF);
34146+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
34147 free_irq(h->intr[h->intr_mode], h);
34148 }
34149
34150diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
34151index 7fda30e..eb5dfe0 100644
34152--- a/drivers/block/cciss.h
34153+++ b/drivers/block/cciss.h
34154@@ -101,7 +101,7 @@ struct ctlr_info
34155 /* information about each logical volume */
34156 drive_info_struct *drv[CISS_MAX_LUN];
34157
34158- struct access_method access;
34159+ struct access_method *access;
34160
34161 /* queue and queue Info */
34162 struct list_head reqQ;
34163diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
34164index 3f08713..56a586a 100644
34165--- a/drivers/block/cpqarray.c
34166+++ b/drivers/block/cpqarray.c
34167@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
34168 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
34169 goto Enomem4;
34170 }
34171- hba[i]->access.set_intr_mask(hba[i], 0);
34172+ hba[i]->access->set_intr_mask(hba[i], 0);
34173 if (request_irq(hba[i]->intr, do_ida_intr,
34174 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
34175 {
34176@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
34177 add_timer(&hba[i]->timer);
34178
34179 /* Enable IRQ now that spinlock and rate limit timer are set up */
34180- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
34181+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
34182
34183 for(j=0; j<NWD; j++) {
34184 struct gendisk *disk = ida_gendisk[i][j];
34185@@ -694,7 +694,7 @@ DBGINFO(
34186 for(i=0; i<NR_PRODUCTS; i++) {
34187 if (board_id == products[i].board_id) {
34188 c->product_name = products[i].product_name;
34189- c->access = *(products[i].access);
34190+ c->access = products[i].access;
34191 break;
34192 }
34193 }
34194@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
34195 hba[ctlr]->intr = intr;
34196 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
34197 hba[ctlr]->product_name = products[j].product_name;
34198- hba[ctlr]->access = *(products[j].access);
34199+ hba[ctlr]->access = products[j].access;
34200 hba[ctlr]->ctlr = ctlr;
34201 hba[ctlr]->board_id = board_id;
34202 hba[ctlr]->pci_dev = NULL; /* not PCI */
34203@@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
34204
34205 while((c = h->reqQ) != NULL) {
34206 /* Can't do anything if we're busy */
34207- if (h->access.fifo_full(h) == 0)
34208+ if (h->access->fifo_full(h) == 0)
34209 return;
34210
34211 /* Get the first entry from the request Q */
34212@@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
34213 h->Qdepth--;
34214
34215 /* Tell the controller to do our bidding */
34216- h->access.submit_command(h, c);
34217+ h->access->submit_command(h, c);
34218
34219 /* Get onto the completion Q */
34220 addQ(&h->cmpQ, c);
34221@@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
34222 unsigned long flags;
34223 __u32 a,a1;
34224
34225- istat = h->access.intr_pending(h);
34226+ istat = h->access->intr_pending(h);
34227 /* Is this interrupt for us? */
34228 if (istat == 0)
34229 return IRQ_NONE;
34230@@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
34231 */
34232 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
34233 if (istat & FIFO_NOT_EMPTY) {
34234- while((a = h->access.command_completed(h))) {
34235+ while((a = h->access->command_completed(h))) {
34236 a1 = a; a &= ~3;
34237 if ((c = h->cmpQ) == NULL)
34238 {
34239@@ -1449,11 +1449,11 @@ static int sendcmd(
34240 /*
34241 * Disable interrupt
34242 */
34243- info_p->access.set_intr_mask(info_p, 0);
34244+ info_p->access->set_intr_mask(info_p, 0);
34245 /* Make sure there is room in the command FIFO */
34246 /* Actually it should be completely empty at this time. */
34247 for (i = 200000; i > 0; i--) {
34248- temp = info_p->access.fifo_full(info_p);
34249+ temp = info_p->access->fifo_full(info_p);
34250 if (temp != 0) {
34251 break;
34252 }
34253@@ -1466,7 +1466,7 @@ DBG(
34254 /*
34255 * Send the cmd
34256 */
34257- info_p->access.submit_command(info_p, c);
34258+ info_p->access->submit_command(info_p, c);
34259 complete = pollcomplete(ctlr);
34260
34261 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
34262@@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
34263 * we check the new geometry. Then turn interrupts back on when
34264 * we're done.
34265 */
34266- host->access.set_intr_mask(host, 0);
34267+ host->access->set_intr_mask(host, 0);
34268 getgeometry(ctlr);
34269- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
34270+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
34271
34272 for(i=0; i<NWD; i++) {
34273 struct gendisk *disk = ida_gendisk[ctlr][i];
34274@@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
34275 /* Wait (up to 2 seconds) for a command to complete */
34276
34277 for (i = 200000; i > 0; i--) {
34278- done = hba[ctlr]->access.command_completed(hba[ctlr]);
34279+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
34280 if (done == 0) {
34281 udelay(10); /* a short fixed delay */
34282 } else
34283diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
34284index be73e9d..7fbf140 100644
34285--- a/drivers/block/cpqarray.h
34286+++ b/drivers/block/cpqarray.h
34287@@ -99,7 +99,7 @@ struct ctlr_info {
34288 drv_info_t drv[NWD];
34289 struct proc_dir_entry *proc;
34290
34291- struct access_method access;
34292+ struct access_method *access;
34293
34294 cmdlist_t *reqQ;
34295 cmdlist_t *cmpQ;
34296diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
34297index 6b51afa..17e1191 100644
34298--- a/drivers/block/drbd/drbd_int.h
34299+++ b/drivers/block/drbd/drbd_int.h
34300@@ -582,7 +582,7 @@ struct drbd_epoch {
34301 struct drbd_tconn *tconn;
34302 struct list_head list;
34303 unsigned int barrier_nr;
34304- atomic_t epoch_size; /* increased on every request added. */
34305+ atomic_unchecked_t epoch_size; /* increased on every request added. */
34306 atomic_t active; /* increased on every req. added, and dec on every finished. */
34307 unsigned long flags;
34308 };
34309@@ -1011,7 +1011,7 @@ struct drbd_conf {
34310 int al_tr_cycle;
34311 int al_tr_pos; /* position of the next transaction in the journal */
34312 wait_queue_head_t seq_wait;
34313- atomic_t packet_seq;
34314+ atomic_unchecked_t packet_seq;
34315 unsigned int peer_seq;
34316 spinlock_t peer_seq_lock;
34317 unsigned int minor;
34318@@ -1527,7 +1527,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
34319 char __user *uoptval;
34320 int err;
34321
34322- uoptval = (char __user __force *)optval;
34323+ uoptval = (char __force_user *)optval;
34324
34325 set_fs(KERNEL_DS);
34326 if (level == SOL_SOCKET)
34327diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
34328index 8c13eeb..217adee 100644
34329--- a/drivers/block/drbd/drbd_main.c
34330+++ b/drivers/block/drbd/drbd_main.c
34331@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
34332 p->sector = sector;
34333 p->block_id = block_id;
34334 p->blksize = blksize;
34335- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
34336+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
34337 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
34338 }
34339
34340@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
34341 return -EIO;
34342 p->sector = cpu_to_be64(req->i.sector);
34343 p->block_id = (unsigned long)req;
34344- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
34345+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
34346 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
34347 if (mdev->state.conn >= C_SYNC_SOURCE &&
34348 mdev->state.conn <= C_PAUSED_SYNC_T)
34349@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
34350 {
34351 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
34352
34353- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
34354- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
34355+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
34356+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
34357 kfree(tconn->current_epoch);
34358
34359 idr_destroy(&tconn->volumes);
34360diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
34361index a9eccfc..f5efe87 100644
34362--- a/drivers/block/drbd/drbd_receiver.c
34363+++ b/drivers/block/drbd/drbd_receiver.c
34364@@ -833,7 +833,7 @@ int drbd_connected(struct drbd_conf *mdev)
34365 {
34366 int err;
34367
34368- atomic_set(&mdev->packet_seq, 0);
34369+ atomic_set_unchecked(&mdev->packet_seq, 0);
34370 mdev->peer_seq = 0;
34371
34372 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
34373@@ -1191,7 +1191,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
34374 do {
34375 next_epoch = NULL;
34376
34377- epoch_size = atomic_read(&epoch->epoch_size);
34378+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
34379
34380 switch (ev & ~EV_CLEANUP) {
34381 case EV_PUT:
34382@@ -1231,7 +1231,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
34383 rv = FE_DESTROYED;
34384 } else {
34385 epoch->flags = 0;
34386- atomic_set(&epoch->epoch_size, 0);
34387+ atomic_set_unchecked(&epoch->epoch_size, 0);
34388 /* atomic_set(&epoch->active, 0); is already zero */
34389 if (rv == FE_STILL_LIVE)
34390 rv = FE_RECYCLED;
34391@@ -1449,7 +1449,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
34392 conn_wait_active_ee_empty(tconn);
34393 drbd_flush(tconn);
34394
34395- if (atomic_read(&tconn->current_epoch->epoch_size)) {
34396+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
34397 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
34398 if (epoch)
34399 break;
34400@@ -1462,11 +1462,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
34401 }
34402
34403 epoch->flags = 0;
34404- atomic_set(&epoch->epoch_size, 0);
34405+ atomic_set_unchecked(&epoch->epoch_size, 0);
34406 atomic_set(&epoch->active, 0);
34407
34408 spin_lock(&tconn->epoch_lock);
34409- if (atomic_read(&tconn->current_epoch->epoch_size)) {
34410+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
34411 list_add(&epoch->list, &tconn->current_epoch->list);
34412 tconn->current_epoch = epoch;
34413 tconn->epochs++;
34414@@ -2170,7 +2170,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
34415
34416 err = wait_for_and_update_peer_seq(mdev, peer_seq);
34417 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
34418- atomic_inc(&tconn->current_epoch->epoch_size);
34419+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
34420 err2 = drbd_drain_block(mdev, pi->size);
34421 if (!err)
34422 err = err2;
34423@@ -2204,7 +2204,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
34424
34425 spin_lock(&tconn->epoch_lock);
34426 peer_req->epoch = tconn->current_epoch;
34427- atomic_inc(&peer_req->epoch->epoch_size);
34428+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
34429 atomic_inc(&peer_req->epoch->active);
34430 spin_unlock(&tconn->epoch_lock);
34431
34432@@ -4346,7 +4346,7 @@ struct data_cmd {
34433 int expect_payload;
34434 size_t pkt_size;
34435 int (*fn)(struct drbd_tconn *, struct packet_info *);
34436-};
34437+} __do_const;
34438
34439 static struct data_cmd drbd_cmd_handler[] = {
34440 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
34441@@ -4466,7 +4466,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
34442 if (!list_empty(&tconn->current_epoch->list))
34443 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
34444 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
34445- atomic_set(&tconn->current_epoch->epoch_size, 0);
34446+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
34447 tconn->send.seen_any_write_yet = false;
34448
34449 conn_info(tconn, "Connection closed\n");
34450@@ -5222,7 +5222,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
34451 struct asender_cmd {
34452 size_t pkt_size;
34453 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
34454-};
34455+} __do_const;
34456
34457 static struct asender_cmd asender_tbl[] = {
34458 [P_PING] = { 0, got_Ping },
34459diff --git a/drivers/block/loop.c b/drivers/block/loop.c
34460index f74f2c0..bb668af 100644
34461--- a/drivers/block/loop.c
34462+++ b/drivers/block/loop.c
34463@@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
34464 mm_segment_t old_fs = get_fs();
34465
34466 set_fs(get_ds());
34467- bw = file->f_op->write(file, buf, len, &pos);
34468+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
34469 set_fs(old_fs);
34470 if (likely(bw == len))
34471 return 0;
34472diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
34473index d620b44..587561e 100644
34474--- a/drivers/cdrom/cdrom.c
34475+++ b/drivers/cdrom/cdrom.c
34476@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
34477 ENSURE(reset, CDC_RESET);
34478 ENSURE(generic_packet, CDC_GENERIC_PACKET);
34479 cdi->mc_flags = 0;
34480- cdo->n_minors = 0;
34481 cdi->options = CDO_USE_FFLAGS;
34482
34483 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
34484@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
34485 else
34486 cdi->cdda_method = CDDA_OLD;
34487
34488- if (!cdo->generic_packet)
34489- cdo->generic_packet = cdrom_dummy_generic_packet;
34490+ if (!cdo->generic_packet) {
34491+ pax_open_kernel();
34492+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
34493+ pax_close_kernel();
34494+ }
34495
34496 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
34497 mutex_lock(&cdrom_mutex);
34498@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
34499 if (cdi->exit)
34500 cdi->exit(cdi);
34501
34502- cdi->ops->n_minors--;
34503 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
34504 }
34505
34506diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
34507index d59cdcb..11afddf 100644
34508--- a/drivers/cdrom/gdrom.c
34509+++ b/drivers/cdrom/gdrom.c
34510@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
34511 .audio_ioctl = gdrom_audio_ioctl,
34512 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
34513 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
34514- .n_minors = 1,
34515 };
34516
34517 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
34518diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
34519index 72bedad..8181ce1 100644
34520--- a/drivers/char/Kconfig
34521+++ b/drivers/char/Kconfig
34522@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
34523
34524 config DEVKMEM
34525 bool "/dev/kmem virtual device support"
34526- default y
34527+ default n
34528+ depends on !GRKERNSEC_KMEM
34529 help
34530 Say Y here if you want to support the /dev/kmem device. The
34531 /dev/kmem device is rarely used, but can be used for certain
34532@@ -581,6 +582,7 @@ config DEVPORT
34533 bool
34534 depends on !M68K
34535 depends on ISA || PCI
34536+ depends on !GRKERNSEC_KMEM
34537 default y
34538
34539 source "drivers/s390/char/Kconfig"
34540diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
34541index 2e04433..22afc64 100644
34542--- a/drivers/char/agp/frontend.c
34543+++ b/drivers/char/agp/frontend.c
34544@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
34545 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
34546 return -EFAULT;
34547
34548- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
34549+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
34550 return -EFAULT;
34551
34552 client = agp_find_client_by_pid(reserve.pid);
34553diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
34554index 21cb980..f15107c 100644
34555--- a/drivers/char/genrtc.c
34556+++ b/drivers/char/genrtc.c
34557@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
34558 switch (cmd) {
34559
34560 case RTC_PLL_GET:
34561+ memset(&pll, 0, sizeof(pll));
34562 if (get_rtc_pll(&pll))
34563 return -EINVAL;
34564 else
34565diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
34566index fe6d4be..89f32100 100644
34567--- a/drivers/char/hpet.c
34568+++ b/drivers/char/hpet.c
34569@@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
34570 }
34571
34572 static int
34573-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
34574+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
34575 struct hpet_info *info)
34576 {
34577 struct hpet_timer __iomem *timer;
34578diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
34579index 053201b0..8335cce 100644
34580--- a/drivers/char/ipmi/ipmi_msghandler.c
34581+++ b/drivers/char/ipmi/ipmi_msghandler.c
34582@@ -420,7 +420,7 @@ struct ipmi_smi {
34583 struct proc_dir_entry *proc_dir;
34584 char proc_dir_name[10];
34585
34586- atomic_t stats[IPMI_NUM_STATS];
34587+ atomic_unchecked_t stats[IPMI_NUM_STATS];
34588
34589 /*
34590 * run_to_completion duplicate of smb_info, smi_info
34591@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
34592
34593
34594 #define ipmi_inc_stat(intf, stat) \
34595- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
34596+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
34597 #define ipmi_get_stat(intf, stat) \
34598- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
34599+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
34600
34601 static int is_lan_addr(struct ipmi_addr *addr)
34602 {
34603@@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
34604 INIT_LIST_HEAD(&intf->cmd_rcvrs);
34605 init_waitqueue_head(&intf->waitq);
34606 for (i = 0; i < IPMI_NUM_STATS; i++)
34607- atomic_set(&intf->stats[i], 0);
34608+ atomic_set_unchecked(&intf->stats[i], 0);
34609
34610 intf->proc_dir = NULL;
34611
34612diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
34613index 1c7fdcd..4899100 100644
34614--- a/drivers/char/ipmi/ipmi_si_intf.c
34615+++ b/drivers/char/ipmi/ipmi_si_intf.c
34616@@ -275,7 +275,7 @@ struct smi_info {
34617 unsigned char slave_addr;
34618
34619 /* Counters and things for the proc filesystem. */
34620- atomic_t stats[SI_NUM_STATS];
34621+ atomic_unchecked_t stats[SI_NUM_STATS];
34622
34623 struct task_struct *thread;
34624
34625@@ -284,9 +284,9 @@ struct smi_info {
34626 };
34627
34628 #define smi_inc_stat(smi, stat) \
34629- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
34630+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
34631 #define smi_get_stat(smi, stat) \
34632- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
34633+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
34634
34635 #define SI_MAX_PARMS 4
34636
34637@@ -3225,7 +3225,7 @@ static int try_smi_init(struct smi_info *new_smi)
34638 atomic_set(&new_smi->req_events, 0);
34639 new_smi->run_to_completion = 0;
34640 for (i = 0; i < SI_NUM_STATS; i++)
34641- atomic_set(&new_smi->stats[i], 0);
34642+ atomic_set_unchecked(&new_smi->stats[i], 0);
34643
34644 new_smi->interrupt_disabled = 1;
34645 atomic_set(&new_smi->stop_operation, 0);
34646diff --git a/drivers/char/mem.c b/drivers/char/mem.c
34647index c6fa3bc..4ca3e42 100644
34648--- a/drivers/char/mem.c
34649+++ b/drivers/char/mem.c
34650@@ -18,6 +18,7 @@
34651 #include <linux/raw.h>
34652 #include <linux/tty.h>
34653 #include <linux/capability.h>
34654+#include <linux/security.h>
34655 #include <linux/ptrace.h>
34656 #include <linux/device.h>
34657 #include <linux/highmem.h>
34658@@ -37,6 +38,10 @@
34659
34660 #define DEVPORT_MINOR 4
34661
34662+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
34663+extern const struct file_operations grsec_fops;
34664+#endif
34665+
34666 static inline unsigned long size_inside_page(unsigned long start,
34667 unsigned long size)
34668 {
34669@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34670
34671 while (cursor < to) {
34672 if (!devmem_is_allowed(pfn)) {
34673+#ifdef CONFIG_GRKERNSEC_KMEM
34674+ gr_handle_mem_readwrite(from, to);
34675+#else
34676 printk(KERN_INFO
34677 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
34678 current->comm, from, to);
34679+#endif
34680 return 0;
34681 }
34682 cursor += PAGE_SIZE;
34683@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34684 }
34685 return 1;
34686 }
34687+#elif defined(CONFIG_GRKERNSEC_KMEM)
34688+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34689+{
34690+ return 0;
34691+}
34692 #else
34693 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34694 {
34695@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
34696
34697 while (count > 0) {
34698 unsigned long remaining;
34699+ char *temp;
34700
34701 sz = size_inside_page(p, count);
34702
34703@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
34704 if (!ptr)
34705 return -EFAULT;
34706
34707- remaining = copy_to_user(buf, ptr, sz);
34708+#ifdef CONFIG_PAX_USERCOPY
34709+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
34710+ if (!temp) {
34711+ unxlate_dev_mem_ptr(p, ptr);
34712+ return -ENOMEM;
34713+ }
34714+ memcpy(temp, ptr, sz);
34715+#else
34716+ temp = ptr;
34717+#endif
34718+
34719+ remaining = copy_to_user(buf, temp, sz);
34720+
34721+#ifdef CONFIG_PAX_USERCOPY
34722+ kfree(temp);
34723+#endif
34724+
34725 unxlate_dev_mem_ptr(p, ptr);
34726 if (remaining)
34727 return -EFAULT;
34728@@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
34729 size_t count, loff_t *ppos)
34730 {
34731 unsigned long p = *ppos;
34732- ssize_t low_count, read, sz;
34733+ ssize_t low_count, read, sz, err = 0;
34734 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
34735- int err = 0;
34736
34737 read = 0;
34738 if (p < (unsigned long) high_memory) {
34739@@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
34740 }
34741 #endif
34742 while (low_count > 0) {
34743+ char *temp;
34744+
34745 sz = size_inside_page(p, low_count);
34746
34747 /*
34748@@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
34749 */
34750 kbuf = xlate_dev_kmem_ptr((char *)p);
34751
34752- if (copy_to_user(buf, kbuf, sz))
34753+#ifdef CONFIG_PAX_USERCOPY
34754+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
34755+ if (!temp)
34756+ return -ENOMEM;
34757+ memcpy(temp, kbuf, sz);
34758+#else
34759+ temp = kbuf;
34760+#endif
34761+
34762+ err = copy_to_user(buf, temp, sz);
34763+
34764+#ifdef CONFIG_PAX_USERCOPY
34765+ kfree(temp);
34766+#endif
34767+
34768+ if (err)
34769 return -EFAULT;
34770 buf += sz;
34771 p += sz;
34772@@ -833,6 +880,9 @@ static const struct memdev {
34773 #ifdef CONFIG_CRASH_DUMP
34774 [12] = { "oldmem", 0, &oldmem_fops, NULL },
34775 #endif
34776+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
34777+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
34778+#endif
34779 };
34780
34781 static int memory_open(struct inode *inode, struct file *filp)
34782diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
34783index 9df78e2..01ba9ae 100644
34784--- a/drivers/char/nvram.c
34785+++ b/drivers/char/nvram.c
34786@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
34787
34788 spin_unlock_irq(&rtc_lock);
34789
34790- if (copy_to_user(buf, contents, tmp - contents))
34791+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
34792 return -EFAULT;
34793
34794 *ppos = i;
34795diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
34796index b66eaa0..2619d1b 100644
34797--- a/drivers/char/pcmcia/synclink_cs.c
34798+++ b/drivers/char/pcmcia/synclink_cs.c
34799@@ -2348,9 +2348,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
34800
34801 if (debug_level >= DEBUG_LEVEL_INFO)
34802 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
34803- __FILE__,__LINE__, info->device_name, port->count);
34804+ __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
34805
34806- WARN_ON(!port->count);
34807+ WARN_ON(!atomic_read(&port->count));
34808
34809 if (tty_port_close_start(port, tty, filp) == 0)
34810 goto cleanup;
34811@@ -2368,7 +2368,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
34812 cleanup:
34813 if (debug_level >= DEBUG_LEVEL_INFO)
34814 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
34815- tty->driver->name, port->count);
34816+ tty->driver->name, atomic_read(&port->count));
34817 }
34818
34819 /* Wait until the transmitter is empty.
34820@@ -2510,7 +2510,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
34821
34822 if (debug_level >= DEBUG_LEVEL_INFO)
34823 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
34824- __FILE__,__LINE__,tty->driver->name, port->count);
34825+ __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
34826
34827 /* If port is closing, signal caller to try again */
34828 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
34829@@ -2530,11 +2530,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
34830 goto cleanup;
34831 }
34832 spin_lock(&port->lock);
34833- port->count++;
34834+ atomic_inc(&port->count);
34835 spin_unlock(&port->lock);
34836 spin_unlock_irqrestore(&info->netlock, flags);
34837
34838- if (port->count == 1) {
34839+ if (atomic_read(&port->count) == 1) {
34840 /* 1st open on this device, init hardware */
34841 retval = startup(info, tty);
34842 if (retval < 0)
34843@@ -3889,7 +3889,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
34844 unsigned short new_crctype;
34845
34846 /* return error if TTY interface open */
34847- if (info->port.count)
34848+ if (atomic_read(&info->port.count))
34849 return -EBUSY;
34850
34851 switch (encoding)
34852@@ -3992,7 +3992,7 @@ static int hdlcdev_open(struct net_device *dev)
34853
34854 /* arbitrate between network and tty opens */
34855 spin_lock_irqsave(&info->netlock, flags);
34856- if (info->port.count != 0 || info->netcount != 0) {
34857+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
34858 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
34859 spin_unlock_irqrestore(&info->netlock, flags);
34860 return -EBUSY;
34861@@ -4081,7 +4081,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
34862 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
34863
34864 /* return error if TTY interface open */
34865- if (info->port.count)
34866+ if (atomic_read(&info->port.count))
34867 return -EBUSY;
34868
34869 if (cmd != SIOCWANDEV)
34870diff --git a/drivers/char/random.c b/drivers/char/random.c
34871index 57d4b15..253207b 100644
34872--- a/drivers/char/random.c
34873+++ b/drivers/char/random.c
34874@@ -272,8 +272,13 @@
34875 /*
34876 * Configuration information
34877 */
34878+#ifdef CONFIG_GRKERNSEC_RANDNET
34879+#define INPUT_POOL_WORDS 512
34880+#define OUTPUT_POOL_WORDS 128
34881+#else
34882 #define INPUT_POOL_WORDS 128
34883 #define OUTPUT_POOL_WORDS 32
34884+#endif
34885 #define SEC_XFER_SIZE 512
34886 #define EXTRACT_SIZE 10
34887
34888@@ -313,10 +318,17 @@ static struct poolinfo {
34889 int poolwords;
34890 int tap1, tap2, tap3, tap4, tap5;
34891 } poolinfo_table[] = {
34892+#ifdef CONFIG_GRKERNSEC_RANDNET
34893+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
34894+ { 512, 411, 308, 208, 104, 1 },
34895+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
34896+ { 128, 103, 76, 51, 25, 1 },
34897+#else
34898 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
34899 { 128, 103, 76, 51, 25, 1 },
34900 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
34901 { 32, 26, 20, 14, 7, 1 },
34902+#endif
34903 #if 0
34904 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
34905 { 2048, 1638, 1231, 819, 411, 1 },
34906@@ -524,8 +536,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
34907 input_rotate += i ? 7 : 14;
34908 }
34909
34910- ACCESS_ONCE(r->input_rotate) = input_rotate;
34911- ACCESS_ONCE(r->add_ptr) = i;
34912+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
34913+ ACCESS_ONCE_RW(r->add_ptr) = i;
34914 smp_wmb();
34915
34916 if (out)
34917@@ -1024,7 +1036,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
34918
34919 extract_buf(r, tmp);
34920 i = min_t(int, nbytes, EXTRACT_SIZE);
34921- if (copy_to_user(buf, tmp, i)) {
34922+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
34923 ret = -EFAULT;
34924 break;
34925 }
34926@@ -1360,7 +1372,7 @@ EXPORT_SYMBOL(generate_random_uuid);
34927 #include <linux/sysctl.h>
34928
34929 static int min_read_thresh = 8, min_write_thresh;
34930-static int max_read_thresh = INPUT_POOL_WORDS * 32;
34931+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
34932 static int max_write_thresh = INPUT_POOL_WORDS * 32;
34933 static char sysctl_bootid[16];
34934
34935@@ -1376,7 +1388,7 @@ static char sysctl_bootid[16];
34936 static int proc_do_uuid(ctl_table *table, int write,
34937 void __user *buffer, size_t *lenp, loff_t *ppos)
34938 {
34939- ctl_table fake_table;
34940+ ctl_table_no_const fake_table;
34941 unsigned char buf[64], tmp_uuid[16], *uuid;
34942
34943 uuid = table->data;
34944diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
34945index d780295..b29f3a8 100644
34946--- a/drivers/char/sonypi.c
34947+++ b/drivers/char/sonypi.c
34948@@ -54,6 +54,7 @@
34949
34950 #include <asm/uaccess.h>
34951 #include <asm/io.h>
34952+#include <asm/local.h>
34953
34954 #include <linux/sonypi.h>
34955
34956@@ -490,7 +491,7 @@ static struct sonypi_device {
34957 spinlock_t fifo_lock;
34958 wait_queue_head_t fifo_proc_list;
34959 struct fasync_struct *fifo_async;
34960- int open_count;
34961+ local_t open_count;
34962 int model;
34963 struct input_dev *input_jog_dev;
34964 struct input_dev *input_key_dev;
34965@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
34966 static int sonypi_misc_release(struct inode *inode, struct file *file)
34967 {
34968 mutex_lock(&sonypi_device.lock);
34969- sonypi_device.open_count--;
34970+ local_dec(&sonypi_device.open_count);
34971 mutex_unlock(&sonypi_device.lock);
34972 return 0;
34973 }
34974@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
34975 {
34976 mutex_lock(&sonypi_device.lock);
34977 /* Flush input queue on first open */
34978- if (!sonypi_device.open_count)
34979+ if (!local_read(&sonypi_device.open_count))
34980 kfifo_reset(&sonypi_device.fifo);
34981- sonypi_device.open_count++;
34982+ local_inc(&sonypi_device.open_count);
34983 mutex_unlock(&sonypi_device.lock);
34984
34985 return 0;
34986diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
34987index 93211df..c7805f7 100644
34988--- a/drivers/char/tpm/tpm.c
34989+++ b/drivers/char/tpm/tpm.c
34990@@ -410,7 +410,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
34991 chip->vendor.req_complete_val)
34992 goto out_recv;
34993
34994- if ((status == chip->vendor.req_canceled)) {
34995+ if (status == chip->vendor.req_canceled) {
34996 dev_err(chip->dev, "Operation Canceled\n");
34997 rc = -ECANCELED;
34998 goto out;
34999diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
35000index 56051d0..11cf3b7 100644
35001--- a/drivers/char/tpm/tpm_acpi.c
35002+++ b/drivers/char/tpm/tpm_acpi.c
35003@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
35004 virt = acpi_os_map_memory(start, len);
35005 if (!virt) {
35006 kfree(log->bios_event_log);
35007+ log->bios_event_log = NULL;
35008 printk("%s: ERROR - Unable to map memory\n", __func__);
35009 return -EIO;
35010 }
35011
35012- memcpy_fromio(log->bios_event_log, virt, len);
35013+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
35014
35015 acpi_os_unmap_memory(virt, len);
35016 return 0;
35017diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
35018index 84ddc55..1d32f1e 100644
35019--- a/drivers/char/tpm/tpm_eventlog.c
35020+++ b/drivers/char/tpm/tpm_eventlog.c
35021@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
35022 event = addr;
35023
35024 if ((event->event_type == 0 && event->event_size == 0) ||
35025- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
35026+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
35027 return NULL;
35028
35029 return addr;
35030@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
35031 return NULL;
35032
35033 if ((event->event_type == 0 && event->event_size == 0) ||
35034- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
35035+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
35036 return NULL;
35037
35038 (*pos)++;
35039@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
35040 int i;
35041
35042 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
35043- seq_putc(m, data[i]);
35044+ if (!seq_putc(m, data[i]))
35045+ return -EFAULT;
35046
35047 return 0;
35048 }
35049diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
35050index a4b7aa0..2faa0bc 100644
35051--- a/drivers/char/virtio_console.c
35052+++ b/drivers/char/virtio_console.c
35053@@ -685,7 +685,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
35054 if (to_user) {
35055 ssize_t ret;
35056
35057- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
35058+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
35059 if (ret)
35060 return -EFAULT;
35061 } else {
35062@@ -784,7 +784,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
35063 if (!port_has_data(port) && !port->host_connected)
35064 return 0;
35065
35066- return fill_readbuf(port, ubuf, count, true);
35067+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
35068 }
35069
35070 static int wait_port_writable(struct port *port, bool nonblock)
35071diff --git a/drivers/clocksource/arm_generic.c b/drivers/clocksource/arm_generic.c
35072index 8ae1a61..9c00613 100644
35073--- a/drivers/clocksource/arm_generic.c
35074+++ b/drivers/clocksource/arm_generic.c
35075@@ -181,7 +181,7 @@ static int __cpuinit arch_timer_cpu_notify(struct notifier_block *self,
35076 return NOTIFY_OK;
35077 }
35078
35079-static struct notifier_block __cpuinitdata arch_timer_cpu_nb = {
35080+static struct notifier_block arch_timer_cpu_nb = {
35081 .notifier_call = arch_timer_cpu_notify,
35082 };
35083
35084diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
35085index 7b0d49d..134fac9 100644
35086--- a/drivers/cpufreq/acpi-cpufreq.c
35087+++ b/drivers/cpufreq/acpi-cpufreq.c
35088@@ -172,7 +172,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
35089 return sprintf(buf, "%u\n", boost_enabled);
35090 }
35091
35092-static struct global_attr global_boost = __ATTR(boost, 0644,
35093+static global_attr_no_const global_boost = __ATTR(boost, 0644,
35094 show_global_boost,
35095 store_global_boost);
35096
35097@@ -712,8 +712,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
35098 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
35099 per_cpu(acfreq_data, cpu) = data;
35100
35101- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
35102- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
35103+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
35104+ pax_open_kernel();
35105+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
35106+ pax_close_kernel();
35107+ }
35108
35109 result = acpi_processor_register_performance(data->acpi_data, cpu);
35110 if (result)
35111@@ -835,7 +838,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
35112 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
35113 break;
35114 case ACPI_ADR_SPACE_FIXED_HARDWARE:
35115- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
35116+ pax_open_kernel();
35117+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
35118+ pax_close_kernel();
35119 policy->cur = get_cur_freq_on_cpu(cpu);
35120 break;
35121 default:
35122@@ -846,8 +851,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
35123 acpi_processor_notify_smm(THIS_MODULE);
35124
35125 /* Check for APERF/MPERF support in hardware */
35126- if (boot_cpu_has(X86_FEATURE_APERFMPERF))
35127- acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
35128+ if (boot_cpu_has(X86_FEATURE_APERFMPERF)) {
35129+ pax_open_kernel();
35130+ *(void **)&acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
35131+ pax_close_kernel();
35132+ }
35133
35134 pr_debug("CPU%u - ACPI performance management activated.\n", cpu);
35135 for (i = 0; i < perf->state_count; i++)
35136diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
35137index 1f93dbd..305cef1 100644
35138--- a/drivers/cpufreq/cpufreq.c
35139+++ b/drivers/cpufreq/cpufreq.c
35140@@ -1843,7 +1843,7 @@ static int __cpuinit cpufreq_cpu_callback(struct notifier_block *nfb,
35141 return NOTIFY_OK;
35142 }
35143
35144-static struct notifier_block __refdata cpufreq_cpu_notifier = {
35145+static struct notifier_block cpufreq_cpu_notifier = {
35146 .notifier_call = cpufreq_cpu_callback,
35147 };
35148
35149@@ -1875,8 +1875,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
35150
35151 pr_debug("trying to register driver %s\n", driver_data->name);
35152
35153- if (driver_data->setpolicy)
35154- driver_data->flags |= CPUFREQ_CONST_LOOPS;
35155+ if (driver_data->setpolicy) {
35156+ pax_open_kernel();
35157+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
35158+ pax_close_kernel();
35159+ }
35160
35161 spin_lock_irqsave(&cpufreq_driver_lock, flags);
35162 if (cpufreq_driver) {
35163diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
35164index 6c5f1d3..c7e2f35e 100644
35165--- a/drivers/cpufreq/cpufreq_governor.c
35166+++ b/drivers/cpufreq/cpufreq_governor.c
35167@@ -243,7 +243,7 @@ int cpufreq_governor_dbs(struct dbs_data *dbs_data,
35168 * governor, thus we are bound to jiffes/HZ
35169 */
35170 if (dbs_data->governor == GOV_CONSERVATIVE) {
35171- struct cs_ops *ops = dbs_data->gov_ops;
35172+ const struct cs_ops *ops = dbs_data->gov_ops;
35173
35174 cpufreq_register_notifier(ops->notifier_block,
35175 CPUFREQ_TRANSITION_NOTIFIER);
35176@@ -251,7 +251,7 @@ int cpufreq_governor_dbs(struct dbs_data *dbs_data,
35177 dbs_data->min_sampling_rate = MIN_SAMPLING_RATE_RATIO *
35178 jiffies_to_usecs(10);
35179 } else {
35180- struct od_ops *ops = dbs_data->gov_ops;
35181+ const struct od_ops *ops = dbs_data->gov_ops;
35182
35183 od_tuners->io_is_busy = ops->io_busy();
35184 }
35185@@ -268,7 +268,7 @@ second_time:
35186 cs_dbs_info->enable = 1;
35187 cs_dbs_info->requested_freq = policy->cur;
35188 } else {
35189- struct od_ops *ops = dbs_data->gov_ops;
35190+ const struct od_ops *ops = dbs_data->gov_ops;
35191 od_dbs_info->rate_mult = 1;
35192 od_dbs_info->sample_type = OD_NORMAL_SAMPLE;
35193 ops->powersave_bias_init_cpu(cpu);
35194@@ -289,7 +289,7 @@ second_time:
35195 mutex_destroy(&cpu_cdbs->timer_mutex);
35196 dbs_data->enable--;
35197 if (!dbs_data->enable) {
35198- struct cs_ops *ops = dbs_data->gov_ops;
35199+ const struct cs_ops *ops = dbs_data->gov_ops;
35200
35201 sysfs_remove_group(cpufreq_global_kobject,
35202 dbs_data->attr_group);
35203diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
35204index f661654..6c8e638 100644
35205--- a/drivers/cpufreq/cpufreq_governor.h
35206+++ b/drivers/cpufreq/cpufreq_governor.h
35207@@ -142,7 +142,7 @@ struct dbs_data {
35208 void (*gov_check_cpu)(int cpu, unsigned int load);
35209
35210 /* Governor specific ops, see below */
35211- void *gov_ops;
35212+ const void *gov_ops;
35213 };
35214
35215 /* Governor specific ops, will be passed to dbs_data->gov_ops */
35216diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
35217index 9d7732b..0b1a793 100644
35218--- a/drivers/cpufreq/cpufreq_stats.c
35219+++ b/drivers/cpufreq/cpufreq_stats.c
35220@@ -340,7 +340,7 @@ static int __cpuinit cpufreq_stat_cpu_callback(struct notifier_block *nfb,
35221 }
35222
35223 /* priority=1 so this will get called before cpufreq_remove_dev */
35224-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
35225+static struct notifier_block cpufreq_stat_cpu_notifier = {
35226 .notifier_call = cpufreq_stat_cpu_callback,
35227 .priority = 1,
35228 };
35229diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
35230index 827629c9..0bc6a03 100644
35231--- a/drivers/cpufreq/p4-clockmod.c
35232+++ b/drivers/cpufreq/p4-clockmod.c
35233@@ -167,10 +167,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
35234 case 0x0F: /* Core Duo */
35235 case 0x16: /* Celeron Core */
35236 case 0x1C: /* Atom */
35237- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
35238+ pax_open_kernel();
35239+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
35240+ pax_close_kernel();
35241 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
35242 case 0x0D: /* Pentium M (Dothan) */
35243- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
35244+ pax_open_kernel();
35245+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
35246+ pax_close_kernel();
35247 /* fall through */
35248 case 0x09: /* Pentium M (Banias) */
35249 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
35250@@ -182,7 +186,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
35251
35252 /* on P-4s, the TSC runs with constant frequency independent whether
35253 * throttling is active or not. */
35254- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
35255+ pax_open_kernel();
35256+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
35257+ pax_close_kernel();
35258
35259 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
35260 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
35261diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
35262index 3a953d5..f5993f6 100644
35263--- a/drivers/cpufreq/speedstep-centrino.c
35264+++ b/drivers/cpufreq/speedstep-centrino.c
35265@@ -353,8 +353,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
35266 !cpu_has(cpu, X86_FEATURE_EST))
35267 return -ENODEV;
35268
35269- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
35270- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
35271+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
35272+ pax_open_kernel();
35273+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
35274+ pax_close_kernel();
35275+ }
35276
35277 if (policy->cpu != 0)
35278 return -ENODEV;
35279diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
35280index e1f6860..f8de20b 100644
35281--- a/drivers/cpuidle/cpuidle.c
35282+++ b/drivers/cpuidle/cpuidle.c
35283@@ -279,7 +279,7 @@ static int poll_idle(struct cpuidle_device *dev,
35284
35285 static void poll_idle_init(struct cpuidle_driver *drv)
35286 {
35287- struct cpuidle_state *state = &drv->states[0];
35288+ cpuidle_state_no_const *state = &drv->states[0];
35289
35290 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
35291 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
35292diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
35293index ea2f8e7..70ac501 100644
35294--- a/drivers/cpuidle/governor.c
35295+++ b/drivers/cpuidle/governor.c
35296@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
35297 mutex_lock(&cpuidle_lock);
35298 if (__cpuidle_find_governor(gov->name) == NULL) {
35299 ret = 0;
35300- list_add_tail(&gov->governor_list, &cpuidle_governors);
35301+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
35302 if (!cpuidle_curr_governor ||
35303 cpuidle_curr_governor->rating < gov->rating)
35304 cpuidle_switch_governor(gov);
35305@@ -135,7 +135,7 @@ void cpuidle_unregister_governor(struct cpuidle_governor *gov)
35306 new_gov = cpuidle_replace_governor(gov->rating);
35307 cpuidle_switch_governor(new_gov);
35308 }
35309- list_del(&gov->governor_list);
35310+ pax_list_del((struct list_head *)&gov->governor_list);
35311 mutex_unlock(&cpuidle_lock);
35312 }
35313
35314diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
35315index 428754a..8bdf9cc 100644
35316--- a/drivers/cpuidle/sysfs.c
35317+++ b/drivers/cpuidle/sysfs.c
35318@@ -131,7 +131,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
35319 NULL
35320 };
35321
35322-static struct attribute_group cpuidle_attr_group = {
35323+static attribute_group_no_const cpuidle_attr_group = {
35324 .attrs = cpuidle_default_attrs,
35325 .name = "cpuidle",
35326 };
35327diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
35328index 3b36797..289c16a 100644
35329--- a/drivers/devfreq/devfreq.c
35330+++ b/drivers/devfreq/devfreq.c
35331@@ -588,7 +588,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
35332 goto err_out;
35333 }
35334
35335- list_add(&governor->node, &devfreq_governor_list);
35336+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
35337
35338 list_for_each_entry(devfreq, &devfreq_list, node) {
35339 int ret = 0;
35340@@ -676,7 +676,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
35341 }
35342 }
35343
35344- list_del(&governor->node);
35345+ pax_list_del((struct list_head *)&governor->node);
35346 err_out:
35347 mutex_unlock(&devfreq_list_lock);
35348
35349diff --git a/drivers/dma/sh/shdma.c b/drivers/dma/sh/shdma.c
35350index b70709b..1d8d02a 100644
35351--- a/drivers/dma/sh/shdma.c
35352+++ b/drivers/dma/sh/shdma.c
35353@@ -476,7 +476,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
35354 return ret;
35355 }
35356
35357-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
35358+static struct notifier_block sh_dmae_nmi_notifier = {
35359 .notifier_call = sh_dmae_nmi_handler,
35360
35361 /* Run before NMI debug handler and KGDB */
35362diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
35363index 0ca1ca7..6e6f454 100644
35364--- a/drivers/edac/edac_mc_sysfs.c
35365+++ b/drivers/edac/edac_mc_sysfs.c
35366@@ -148,7 +148,7 @@ static const char *edac_caps[] = {
35367 struct dev_ch_attribute {
35368 struct device_attribute attr;
35369 int channel;
35370-};
35371+} __do_const;
35372
35373 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
35374 struct dev_ch_attribute dev_attr_legacy_##_name = \
35375diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
35376index 0056c4d..23b54d9 100644
35377--- a/drivers/edac/edac_pci_sysfs.c
35378+++ b/drivers/edac/edac_pci_sysfs.c
35379@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
35380 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
35381 static int edac_pci_poll_msec = 1000; /* one second workq period */
35382
35383-static atomic_t pci_parity_count = ATOMIC_INIT(0);
35384-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
35385+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
35386+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
35387
35388 static struct kobject *edac_pci_top_main_kobj;
35389 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
35390@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
35391 void *value;
35392 ssize_t(*show) (void *, char *);
35393 ssize_t(*store) (void *, const char *, size_t);
35394-};
35395+} __do_const;
35396
35397 /* Set of show/store abstract level functions for PCI Parity object */
35398 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
35399@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
35400 edac_printk(KERN_CRIT, EDAC_PCI,
35401 "Signaled System Error on %s\n",
35402 pci_name(dev));
35403- atomic_inc(&pci_nonparity_count);
35404+ atomic_inc_unchecked(&pci_nonparity_count);
35405 }
35406
35407 if (status & (PCI_STATUS_PARITY)) {
35408@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
35409 "Master Data Parity Error on %s\n",
35410 pci_name(dev));
35411
35412- atomic_inc(&pci_parity_count);
35413+ atomic_inc_unchecked(&pci_parity_count);
35414 }
35415
35416 if (status & (PCI_STATUS_DETECTED_PARITY)) {
35417@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
35418 "Detected Parity Error on %s\n",
35419 pci_name(dev));
35420
35421- atomic_inc(&pci_parity_count);
35422+ atomic_inc_unchecked(&pci_parity_count);
35423 }
35424 }
35425
35426@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
35427 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
35428 "Signaled System Error on %s\n",
35429 pci_name(dev));
35430- atomic_inc(&pci_nonparity_count);
35431+ atomic_inc_unchecked(&pci_nonparity_count);
35432 }
35433
35434 if (status & (PCI_STATUS_PARITY)) {
35435@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
35436 "Master Data Parity Error on "
35437 "%s\n", pci_name(dev));
35438
35439- atomic_inc(&pci_parity_count);
35440+ atomic_inc_unchecked(&pci_parity_count);
35441 }
35442
35443 if (status & (PCI_STATUS_DETECTED_PARITY)) {
35444@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
35445 "Detected Parity Error on %s\n",
35446 pci_name(dev));
35447
35448- atomic_inc(&pci_parity_count);
35449+ atomic_inc_unchecked(&pci_parity_count);
35450 }
35451 }
35452 }
35453@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
35454 if (!check_pci_errors)
35455 return;
35456
35457- before_count = atomic_read(&pci_parity_count);
35458+ before_count = atomic_read_unchecked(&pci_parity_count);
35459
35460 /* scan all PCI devices looking for a Parity Error on devices and
35461 * bridges.
35462@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
35463 /* Only if operator has selected panic on PCI Error */
35464 if (edac_pci_get_panic_on_pe()) {
35465 /* If the count is different 'after' from 'before' */
35466- if (before_count != atomic_read(&pci_parity_count))
35467+ if (before_count != atomic_read_unchecked(&pci_parity_count))
35468 panic("EDAC: PCI Parity Error");
35469 }
35470 }
35471diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
35472index 6796799..99e8377 100644
35473--- a/drivers/edac/mce_amd.h
35474+++ b/drivers/edac/mce_amd.h
35475@@ -78,7 +78,7 @@ extern const char * const ii_msgs[];
35476 struct amd_decoder_ops {
35477 bool (*mc0_mce)(u16, u8);
35478 bool (*mc1_mce)(u16, u8);
35479-};
35480+} __no_const;
35481
35482 void amd_report_gart_errors(bool);
35483 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
35484diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
35485index 57ea7f4..789e3c3 100644
35486--- a/drivers/firewire/core-card.c
35487+++ b/drivers/firewire/core-card.c
35488@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
35489
35490 void fw_core_remove_card(struct fw_card *card)
35491 {
35492- struct fw_card_driver dummy_driver = dummy_driver_template;
35493+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
35494
35495 card->driver->update_phy_reg(card, 4,
35496 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
35497diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
35498index f8d2287..5aaf4db 100644
35499--- a/drivers/firewire/core-cdev.c
35500+++ b/drivers/firewire/core-cdev.c
35501@@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
35502 int ret;
35503
35504 if ((request->channels == 0 && request->bandwidth == 0) ||
35505- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
35506- request->bandwidth < 0)
35507+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
35508 return -EINVAL;
35509
35510 r = kmalloc(sizeof(*r), GFP_KERNEL);
35511diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
35512index af3e8aa..eb2f227 100644
35513--- a/drivers/firewire/core-device.c
35514+++ b/drivers/firewire/core-device.c
35515@@ -232,7 +232,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
35516 struct config_rom_attribute {
35517 struct device_attribute attr;
35518 u32 key;
35519-};
35520+} __do_const;
35521
35522 static ssize_t show_immediate(struct device *dev,
35523 struct device_attribute *dattr, char *buf)
35524diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
35525index 28a94c7..58da63a 100644
35526--- a/drivers/firewire/core-transaction.c
35527+++ b/drivers/firewire/core-transaction.c
35528@@ -38,6 +38,7 @@
35529 #include <linux/timer.h>
35530 #include <linux/types.h>
35531 #include <linux/workqueue.h>
35532+#include <linux/sched.h>
35533
35534 #include <asm/byteorder.h>
35535
35536diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
35537index 515a42c..5ecf3ba 100644
35538--- a/drivers/firewire/core.h
35539+++ b/drivers/firewire/core.h
35540@@ -111,6 +111,7 @@ struct fw_card_driver {
35541
35542 int (*stop_iso)(struct fw_iso_context *ctx);
35543 };
35544+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
35545
35546 void fw_card_initialize(struct fw_card *card,
35547 const struct fw_card_driver *driver, struct device *device);
35548diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
35549index 94a58a0..f5eba42 100644
35550--- a/drivers/firmware/dmi-id.c
35551+++ b/drivers/firmware/dmi-id.c
35552@@ -16,7 +16,7 @@
35553 struct dmi_device_attribute{
35554 struct device_attribute dev_attr;
35555 int field;
35556-};
35557+} __do_const;
35558 #define to_dmi_dev_attr(_dev_attr) \
35559 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
35560
35561diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
35562index 4cd392d..4b629e1 100644
35563--- a/drivers/firmware/dmi_scan.c
35564+++ b/drivers/firmware/dmi_scan.c
35565@@ -490,11 +490,6 @@ void __init dmi_scan_machine(void)
35566 }
35567 }
35568 else {
35569- /*
35570- * no iounmap() for that ioremap(); it would be a no-op, but
35571- * it's so early in setup that sucker gets confused into doing
35572- * what it shouldn't if we actually call it.
35573- */
35574 p = dmi_ioremap(0xF0000, 0x10000);
35575 if (p == NULL)
35576 goto error;
35577@@ -769,7 +764,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
35578 if (buf == NULL)
35579 return -1;
35580
35581- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
35582+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
35583
35584 iounmap(buf);
35585 return 0;
35586diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
35587index b07cb37..2a51037 100644
35588--- a/drivers/firmware/efivars.c
35589+++ b/drivers/firmware/efivars.c
35590@@ -138,7 +138,7 @@ struct efivar_attribute {
35591 };
35592
35593 static struct efivars __efivars;
35594-static struct efivar_operations ops;
35595+static efivar_operations_no_const ops __read_only;
35596
35597 #define PSTORE_EFI_ATTRIBUTES \
35598 (EFI_VARIABLE_NON_VOLATILE | \
35599@@ -1834,7 +1834,7 @@ efivar_create_sysfs_entry(struct efivars *efivars,
35600 static int
35601 create_efivars_bin_attributes(struct efivars *efivars)
35602 {
35603- struct bin_attribute *attr;
35604+ bin_attribute_no_const *attr;
35605 int error;
35606
35607 /* new_var */
35608diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
35609index 2a90ba6..07f3733 100644
35610--- a/drivers/firmware/google/memconsole.c
35611+++ b/drivers/firmware/google/memconsole.c
35612@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
35613 if (!found_memconsole())
35614 return -ENODEV;
35615
35616- memconsole_bin_attr.size = memconsole_length;
35617+ pax_open_kernel();
35618+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
35619+ pax_close_kernel();
35620
35621 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
35622
35623diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
35624index 6f2306d..af9476a 100644
35625--- a/drivers/gpio/gpio-ich.c
35626+++ b/drivers/gpio/gpio-ich.c
35627@@ -69,7 +69,7 @@ struct ichx_desc {
35628 /* Some chipsets have quirks, let these use their own request/get */
35629 int (*request)(struct gpio_chip *chip, unsigned offset);
35630 int (*get)(struct gpio_chip *chip, unsigned offset);
35631-};
35632+} __do_const;
35633
35634 static struct {
35635 spinlock_t lock;
35636diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
35637index 9902732..64b62dd 100644
35638--- a/drivers/gpio/gpio-vr41xx.c
35639+++ b/drivers/gpio/gpio-vr41xx.c
35640@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
35641 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
35642 maskl, pendl, maskh, pendh);
35643
35644- atomic_inc(&irq_err_count);
35645+ atomic_inc_unchecked(&irq_err_count);
35646
35647 return -EINVAL;
35648 }
35649diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
35650index 7b2d378..cc947ea 100644
35651--- a/drivers/gpu/drm/drm_crtc_helper.c
35652+++ b/drivers/gpu/drm/drm_crtc_helper.c
35653@@ -319,7 +319,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
35654 struct drm_crtc *tmp;
35655 int crtc_mask = 1;
35656
35657- WARN(!crtc, "checking null crtc?\n");
35658+ BUG_ON(!crtc);
35659
35660 dev = crtc->dev;
35661
35662diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
35663index be174ca..7f38143 100644
35664--- a/drivers/gpu/drm/drm_drv.c
35665+++ b/drivers/gpu/drm/drm_drv.c
35666@@ -307,7 +307,7 @@ module_exit(drm_core_exit);
35667 /**
35668 * Copy and IOCTL return string to user space
35669 */
35670-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
35671+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
35672 {
35673 int len;
35674
35675@@ -377,7 +377,7 @@ long drm_ioctl(struct file *filp,
35676 struct drm_file *file_priv = filp->private_data;
35677 struct drm_device *dev;
35678 struct drm_ioctl_desc *ioctl;
35679- drm_ioctl_t *func;
35680+ drm_ioctl_no_const_t func;
35681 unsigned int nr = DRM_IOCTL_NR(cmd);
35682 int retcode = -EINVAL;
35683 char stack_kdata[128];
35684@@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
35685 return -ENODEV;
35686
35687 atomic_inc(&dev->ioctl_count);
35688- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
35689+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
35690 ++file_priv->ioctl_count;
35691
35692 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
35693diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
35694index 32d7775..c8be5e1 100644
35695--- a/drivers/gpu/drm/drm_fops.c
35696+++ b/drivers/gpu/drm/drm_fops.c
35697@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
35698 }
35699
35700 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
35701- atomic_set(&dev->counts[i], 0);
35702+ atomic_set_unchecked(&dev->counts[i], 0);
35703
35704 dev->sigdata.lock = NULL;
35705
35706@@ -135,7 +135,7 @@ int drm_open(struct inode *inode, struct file *filp)
35707 if (drm_device_is_unplugged(dev))
35708 return -ENODEV;
35709
35710- if (!dev->open_count++)
35711+ if (local_inc_return(&dev->open_count) == 1)
35712 need_setup = 1;
35713 mutex_lock(&dev->struct_mutex);
35714 old_imapping = inode->i_mapping;
35715@@ -151,7 +151,7 @@ int drm_open(struct inode *inode, struct file *filp)
35716 retcode = drm_open_helper(inode, filp, dev);
35717 if (retcode)
35718 goto err_undo;
35719- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
35720+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
35721 if (need_setup) {
35722 retcode = drm_setup(dev);
35723 if (retcode)
35724@@ -166,7 +166,7 @@ err_undo:
35725 iput(container_of(dev->dev_mapping, struct inode, i_data));
35726 dev->dev_mapping = old_mapping;
35727 mutex_unlock(&dev->struct_mutex);
35728- dev->open_count--;
35729+ local_dec(&dev->open_count);
35730 return retcode;
35731 }
35732 EXPORT_SYMBOL(drm_open);
35733@@ -440,7 +440,7 @@ int drm_release(struct inode *inode, struct file *filp)
35734
35735 mutex_lock(&drm_global_mutex);
35736
35737- DRM_DEBUG("open_count = %d\n", dev->open_count);
35738+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
35739
35740 if (dev->driver->preclose)
35741 dev->driver->preclose(dev, file_priv);
35742@@ -449,10 +449,10 @@ int drm_release(struct inode *inode, struct file *filp)
35743 * Begin inline drm_release
35744 */
35745
35746- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
35747+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
35748 task_pid_nr(current),
35749 (long)old_encode_dev(file_priv->minor->device),
35750- dev->open_count);
35751+ local_read(&dev->open_count));
35752
35753 /* Release any auth tokens that might point to this file_priv,
35754 (do that under the drm_global_mutex) */
35755@@ -549,8 +549,8 @@ int drm_release(struct inode *inode, struct file *filp)
35756 * End inline drm_release
35757 */
35758
35759- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
35760- if (!--dev->open_count) {
35761+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
35762+ if (local_dec_and_test(&dev->open_count)) {
35763 if (atomic_read(&dev->ioctl_count)) {
35764 DRM_ERROR("Device busy: %d\n",
35765 atomic_read(&dev->ioctl_count));
35766diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
35767index f731116..629842c 100644
35768--- a/drivers/gpu/drm/drm_global.c
35769+++ b/drivers/gpu/drm/drm_global.c
35770@@ -36,7 +36,7 @@
35771 struct drm_global_item {
35772 struct mutex mutex;
35773 void *object;
35774- int refcount;
35775+ atomic_t refcount;
35776 };
35777
35778 static struct drm_global_item glob[DRM_GLOBAL_NUM];
35779@@ -49,7 +49,7 @@ void drm_global_init(void)
35780 struct drm_global_item *item = &glob[i];
35781 mutex_init(&item->mutex);
35782 item->object = NULL;
35783- item->refcount = 0;
35784+ atomic_set(&item->refcount, 0);
35785 }
35786 }
35787
35788@@ -59,7 +59,7 @@ void drm_global_release(void)
35789 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
35790 struct drm_global_item *item = &glob[i];
35791 BUG_ON(item->object != NULL);
35792- BUG_ON(item->refcount != 0);
35793+ BUG_ON(atomic_read(&item->refcount) != 0);
35794 }
35795 }
35796
35797@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
35798 void *object;
35799
35800 mutex_lock(&item->mutex);
35801- if (item->refcount == 0) {
35802+ if (atomic_read(&item->refcount) == 0) {
35803 item->object = kzalloc(ref->size, GFP_KERNEL);
35804 if (unlikely(item->object == NULL)) {
35805 ret = -ENOMEM;
35806@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
35807 goto out_err;
35808
35809 }
35810- ++item->refcount;
35811+ atomic_inc(&item->refcount);
35812 ref->object = item->object;
35813 object = item->object;
35814 mutex_unlock(&item->mutex);
35815@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
35816 struct drm_global_item *item = &glob[ref->global_type];
35817
35818 mutex_lock(&item->mutex);
35819- BUG_ON(item->refcount == 0);
35820+ BUG_ON(atomic_read(&item->refcount) == 0);
35821 BUG_ON(ref->object != item->object);
35822- if (--item->refcount == 0) {
35823+ if (atomic_dec_and_test(&item->refcount)) {
35824 ref->release(ref);
35825 item->object = NULL;
35826 }
35827diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
35828index d4b20ce..77a8d41 100644
35829--- a/drivers/gpu/drm/drm_info.c
35830+++ b/drivers/gpu/drm/drm_info.c
35831@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
35832 struct drm_local_map *map;
35833 struct drm_map_list *r_list;
35834
35835- /* Hardcoded from _DRM_FRAME_BUFFER,
35836- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
35837- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
35838- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
35839+ static const char * const types[] = {
35840+ [_DRM_FRAME_BUFFER] = "FB",
35841+ [_DRM_REGISTERS] = "REG",
35842+ [_DRM_SHM] = "SHM",
35843+ [_DRM_AGP] = "AGP",
35844+ [_DRM_SCATTER_GATHER] = "SG",
35845+ [_DRM_CONSISTENT] = "PCI",
35846+ [_DRM_GEM] = "GEM" };
35847 const char *type;
35848 int i;
35849
35850@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
35851 map = r_list->map;
35852 if (!map)
35853 continue;
35854- if (map->type < 0 || map->type > 5)
35855+ if (map->type >= ARRAY_SIZE(types))
35856 type = "??";
35857 else
35858 type = types[map->type];
35859@@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
35860 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
35861 vma->vm_flags & VM_LOCKED ? 'l' : '-',
35862 vma->vm_flags & VM_IO ? 'i' : '-',
35863+#ifdef CONFIG_GRKERNSEC_HIDESYM
35864+ 0);
35865+#else
35866 vma->vm_pgoff);
35867+#endif
35868
35869 #if defined(__i386__)
35870 pgprot = pgprot_val(vma->vm_page_prot);
35871diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
35872index 2f4c434..dd12cd2 100644
35873--- a/drivers/gpu/drm/drm_ioc32.c
35874+++ b/drivers/gpu/drm/drm_ioc32.c
35875@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
35876 request = compat_alloc_user_space(nbytes);
35877 if (!access_ok(VERIFY_WRITE, request, nbytes))
35878 return -EFAULT;
35879- list = (struct drm_buf_desc *) (request + 1);
35880+ list = (struct drm_buf_desc __user *) (request + 1);
35881
35882 if (__put_user(count, &request->count)
35883 || __put_user(list, &request->list))
35884@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
35885 request = compat_alloc_user_space(nbytes);
35886 if (!access_ok(VERIFY_WRITE, request, nbytes))
35887 return -EFAULT;
35888- list = (struct drm_buf_pub *) (request + 1);
35889+ list = (struct drm_buf_pub __user *) (request + 1);
35890
35891 if (__put_user(count, &request->count)
35892 || __put_user(list, &request->list))
35893@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
35894 return 0;
35895 }
35896
35897-drm_ioctl_compat_t *drm_compat_ioctls[] = {
35898+drm_ioctl_compat_t drm_compat_ioctls[] = {
35899 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
35900 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
35901 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
35902@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
35903 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35904 {
35905 unsigned int nr = DRM_IOCTL_NR(cmd);
35906- drm_ioctl_compat_t *fn;
35907 int ret;
35908
35909 /* Assume that ioctls without an explicit compat routine will just
35910@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35911 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
35912 return drm_ioctl(filp, cmd, arg);
35913
35914- fn = drm_compat_ioctls[nr];
35915-
35916- if (fn != NULL)
35917- ret = (*fn) (filp, cmd, arg);
35918+ if (drm_compat_ioctls[nr] != NULL)
35919+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
35920 else
35921 ret = drm_ioctl(filp, cmd, arg);
35922
35923diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
35924index e77bd8b..1571b85 100644
35925--- a/drivers/gpu/drm/drm_ioctl.c
35926+++ b/drivers/gpu/drm/drm_ioctl.c
35927@@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
35928 stats->data[i].value =
35929 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
35930 else
35931- stats->data[i].value = atomic_read(&dev->counts[i]);
35932+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
35933 stats->data[i].type = dev->types[i];
35934 }
35935
35936diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
35937index d752c96..fe08455 100644
35938--- a/drivers/gpu/drm/drm_lock.c
35939+++ b/drivers/gpu/drm/drm_lock.c
35940@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
35941 if (drm_lock_take(&master->lock, lock->context)) {
35942 master->lock.file_priv = file_priv;
35943 master->lock.lock_time = jiffies;
35944- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
35945+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
35946 break; /* Got lock */
35947 }
35948
35949@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
35950 return -EINVAL;
35951 }
35952
35953- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
35954+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
35955
35956 if (drm_lock_free(&master->lock, lock->context)) {
35957 /* FIXME: Should really bail out here. */
35958diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
35959index 200e104..59facda 100644
35960--- a/drivers/gpu/drm/drm_stub.c
35961+++ b/drivers/gpu/drm/drm_stub.c
35962@@ -516,7 +516,7 @@ void drm_unplug_dev(struct drm_device *dev)
35963
35964 drm_device_set_unplugged(dev);
35965
35966- if (dev->open_count == 0) {
35967+ if (local_read(&dev->open_count) == 0) {
35968 drm_put_dev(dev);
35969 }
35970 mutex_unlock(&drm_global_mutex);
35971diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
35972index 004ecdf..db1f6e0 100644
35973--- a/drivers/gpu/drm/i810/i810_dma.c
35974+++ b/drivers/gpu/drm/i810/i810_dma.c
35975@@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
35976 dma->buflist[vertex->idx],
35977 vertex->discard, vertex->used);
35978
35979- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
35980- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
35981+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
35982+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
35983 sarea_priv->last_enqueue = dev_priv->counter - 1;
35984 sarea_priv->last_dispatch = (int)hw_status[5];
35985
35986@@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
35987 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
35988 mc->last_render);
35989
35990- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
35991- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
35992+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
35993+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
35994 sarea_priv->last_enqueue = dev_priv->counter - 1;
35995 sarea_priv->last_dispatch = (int)hw_status[5];
35996
35997diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
35998index 6e0acad..93c8289 100644
35999--- a/drivers/gpu/drm/i810/i810_drv.h
36000+++ b/drivers/gpu/drm/i810/i810_drv.h
36001@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
36002 int page_flipping;
36003
36004 wait_queue_head_t irq_queue;
36005- atomic_t irq_received;
36006- atomic_t irq_emitted;
36007+ atomic_unchecked_t irq_received;
36008+ atomic_unchecked_t irq_emitted;
36009
36010 int front_offset;
36011 } drm_i810_private_t;
36012diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
36013index 261efc8e..27af8a5 100644
36014--- a/drivers/gpu/drm/i915/i915_debugfs.c
36015+++ b/drivers/gpu/drm/i915/i915_debugfs.c
36016@@ -496,7 +496,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
36017 I915_READ(GTIMR));
36018 }
36019 seq_printf(m, "Interrupts received: %d\n",
36020- atomic_read(&dev_priv->irq_received));
36021+ atomic_read_unchecked(&dev_priv->irq_received));
36022 for_each_ring(ring, dev_priv, i) {
36023 if (IS_GEN6(dev) || IS_GEN7(dev)) {
36024 seq_printf(m,
36025diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
36026index 99daa89..84ebd44 100644
36027--- a/drivers/gpu/drm/i915/i915_dma.c
36028+++ b/drivers/gpu/drm/i915/i915_dma.c
36029@@ -1253,7 +1253,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
36030 bool can_switch;
36031
36032 spin_lock(&dev->count_lock);
36033- can_switch = (dev->open_count == 0);
36034+ can_switch = (local_read(&dev->open_count) == 0);
36035 spin_unlock(&dev->count_lock);
36036 return can_switch;
36037 }
36038diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
36039index 7339a4b..445aaba 100644
36040--- a/drivers/gpu/drm/i915/i915_drv.h
36041+++ b/drivers/gpu/drm/i915/i915_drv.h
36042@@ -656,7 +656,7 @@ typedef struct drm_i915_private {
36043 drm_dma_handle_t *status_page_dmah;
36044 struct resource mch_res;
36045
36046- atomic_t irq_received;
36047+ atomic_unchecked_t irq_received;
36048
36049 /* protects the irq masks */
36050 spinlock_t irq_lock;
36051@@ -1102,7 +1102,7 @@ struct drm_i915_gem_object {
36052 * will be page flipped away on the next vblank. When it
36053 * reaches 0, dev_priv->pending_flip_queue will be woken up.
36054 */
36055- atomic_t pending_flip;
36056+ atomic_unchecked_t pending_flip;
36057 };
36058 #define to_gem_object(obj) (&((struct drm_i915_gem_object *)(obj))->base)
36059
36060@@ -1633,7 +1633,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
36061 struct drm_i915_private *dev_priv, unsigned port);
36062 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
36063 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
36064-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
36065+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
36066 {
36067 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
36068 }
36069diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
36070index ba8805a..39d5330 100644
36071--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
36072+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
36073@@ -672,7 +672,7 @@ i915_gem_execbuffer_move_to_gpu(struct intel_ring_buffer *ring,
36074 i915_gem_clflush_object(obj);
36075
36076 if (obj->base.pending_write_domain)
36077- flips |= atomic_read(&obj->pending_flip);
36078+ flips |= atomic_read_unchecked(&obj->pending_flip);
36079
36080 flush_domains |= obj->base.write_domain;
36081 }
36082@@ -703,9 +703,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
36083
36084 static int
36085 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
36086- int count)
36087+ unsigned int count)
36088 {
36089- int i;
36090+ unsigned int i;
36091 int relocs_total = 0;
36092 int relocs_max = INT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
36093
36094@@ -1202,7 +1202,7 @@ i915_gem_execbuffer2(struct drm_device *dev, void *data,
36095 return -ENOMEM;
36096 }
36097 ret = copy_from_user(exec2_list,
36098- (struct drm_i915_relocation_entry __user *)
36099+ (struct drm_i915_gem_exec_object2 __user *)
36100 (uintptr_t) args->buffers_ptr,
36101 sizeof(*exec2_list) * args->buffer_count);
36102 if (ret != 0) {
36103diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
36104index 3c59584..500f2e9 100644
36105--- a/drivers/gpu/drm/i915/i915_ioc32.c
36106+++ b/drivers/gpu/drm/i915/i915_ioc32.c
36107@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
36108 (unsigned long)request);
36109 }
36110
36111-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
36112+static drm_ioctl_compat_t i915_compat_ioctls[] = {
36113 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
36114 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
36115 [DRM_I915_GETPARAM] = compat_i915_getparam,
36116@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
36117 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
36118 {
36119 unsigned int nr = DRM_IOCTL_NR(cmd);
36120- drm_ioctl_compat_t *fn = NULL;
36121 int ret;
36122
36123 if (nr < DRM_COMMAND_BASE)
36124 return drm_compat_ioctl(filp, cmd, arg);
36125
36126- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
36127- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
36128-
36129- if (fn != NULL)
36130+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
36131+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
36132 ret = (*fn) (filp, cmd, arg);
36133- else
36134+ } else
36135 ret = drm_ioctl(filp, cmd, arg);
36136
36137 return ret;
36138diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
36139index fe84338..a863190 100644
36140--- a/drivers/gpu/drm/i915/i915_irq.c
36141+++ b/drivers/gpu/drm/i915/i915_irq.c
36142@@ -535,7 +535,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
36143 u32 pipe_stats[I915_MAX_PIPES];
36144 bool blc_event;
36145
36146- atomic_inc(&dev_priv->irq_received);
36147+ atomic_inc_unchecked(&dev_priv->irq_received);
36148
36149 while (true) {
36150 iir = I915_READ(VLV_IIR);
36151@@ -688,7 +688,7 @@ static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
36152 irqreturn_t ret = IRQ_NONE;
36153 int i;
36154
36155- atomic_inc(&dev_priv->irq_received);
36156+ atomic_inc_unchecked(&dev_priv->irq_received);
36157
36158 /* disable master interrupt before clearing iir */
36159 de_ier = I915_READ(DEIER);
36160@@ -760,7 +760,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
36161 int ret = IRQ_NONE;
36162 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
36163
36164- atomic_inc(&dev_priv->irq_received);
36165+ atomic_inc_unchecked(&dev_priv->irq_received);
36166
36167 /* disable master interrupt before clearing iir */
36168 de_ier = I915_READ(DEIER);
36169@@ -1787,7 +1787,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
36170 {
36171 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
36172
36173- atomic_set(&dev_priv->irq_received, 0);
36174+ atomic_set_unchecked(&dev_priv->irq_received, 0);
36175
36176 I915_WRITE(HWSTAM, 0xeffe);
36177
36178@@ -1813,7 +1813,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
36179 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
36180 int pipe;
36181
36182- atomic_set(&dev_priv->irq_received, 0);
36183+ atomic_set_unchecked(&dev_priv->irq_received, 0);
36184
36185 /* VLV magic */
36186 I915_WRITE(VLV_IMR, 0);
36187@@ -2108,7 +2108,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
36188 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
36189 int pipe;
36190
36191- atomic_set(&dev_priv->irq_received, 0);
36192+ atomic_set_unchecked(&dev_priv->irq_received, 0);
36193
36194 for_each_pipe(pipe)
36195 I915_WRITE(PIPESTAT(pipe), 0);
36196@@ -2159,7 +2159,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
36197 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
36198 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
36199
36200- atomic_inc(&dev_priv->irq_received);
36201+ atomic_inc_unchecked(&dev_priv->irq_received);
36202
36203 iir = I915_READ16(IIR);
36204 if (iir == 0)
36205@@ -2244,7 +2244,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
36206 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
36207 int pipe;
36208
36209- atomic_set(&dev_priv->irq_received, 0);
36210+ atomic_set_unchecked(&dev_priv->irq_received, 0);
36211
36212 if (I915_HAS_HOTPLUG(dev)) {
36213 I915_WRITE(PORT_HOTPLUG_EN, 0);
36214@@ -2339,7 +2339,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
36215 };
36216 int pipe, ret = IRQ_NONE;
36217
36218- atomic_inc(&dev_priv->irq_received);
36219+ atomic_inc_unchecked(&dev_priv->irq_received);
36220
36221 iir = I915_READ(IIR);
36222 do {
36223@@ -2465,7 +2465,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
36224 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
36225 int pipe;
36226
36227- atomic_set(&dev_priv->irq_received, 0);
36228+ atomic_set_unchecked(&dev_priv->irq_received, 0);
36229
36230 I915_WRITE(PORT_HOTPLUG_EN, 0);
36231 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
36232@@ -2572,7 +2572,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
36233 int irq_received;
36234 int ret = IRQ_NONE, pipe;
36235
36236- atomic_inc(&dev_priv->irq_received);
36237+ atomic_inc_unchecked(&dev_priv->irq_received);
36238
36239 iir = I915_READ(IIR);
36240
36241diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
36242index d3f834a..0ad1b37 100644
36243--- a/drivers/gpu/drm/i915/intel_display.c
36244+++ b/drivers/gpu/drm/i915/intel_display.c
36245@@ -2255,7 +2255,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
36246
36247 wait_event(dev_priv->pending_flip_queue,
36248 atomic_read(&dev_priv->mm.wedged) ||
36249- atomic_read(&obj->pending_flip) == 0);
36250+ atomic_read_unchecked(&obj->pending_flip) == 0);
36251
36252 /* Big Hammer, we also need to ensure that any pending
36253 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
36254@@ -7122,8 +7122,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
36255
36256 obj = work->old_fb_obj;
36257
36258- atomic_clear_mask(1 << intel_crtc->plane,
36259- &obj->pending_flip.counter);
36260+ atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
36261 wake_up(&dev_priv->pending_flip_queue);
36262
36263 queue_work(dev_priv->wq, &work->work);
36264@@ -7486,7 +7485,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
36265 /* Block clients from rendering to the new back buffer until
36266 * the flip occurs and the object is no longer visible.
36267 */
36268- atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
36269+ atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
36270 atomic_inc(&intel_crtc->unpin_work_count);
36271
36272 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
36273@@ -7504,7 +7503,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
36274 cleanup_pending:
36275 atomic_dec(&intel_crtc->unpin_work_count);
36276 crtc->fb = old_fb;
36277- atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
36278+ atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
36279 drm_gem_object_unreference(&work->old_fb_obj->base);
36280 drm_gem_object_unreference(&obj->base);
36281 mutex_unlock(&dev->struct_mutex);
36282@@ -8846,13 +8845,13 @@ struct intel_quirk {
36283 int subsystem_vendor;
36284 int subsystem_device;
36285 void (*hook)(struct drm_device *dev);
36286-};
36287+} __do_const;
36288
36289 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
36290 struct intel_dmi_quirk {
36291 void (*hook)(struct drm_device *dev);
36292 const struct dmi_system_id (*dmi_id_list)[];
36293-};
36294+} __do_const;
36295
36296 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
36297 {
36298@@ -8860,18 +8859,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
36299 return 1;
36300 }
36301
36302+static const struct dmi_system_id intel_dmi_quirks_table[] = {
36303+ {
36304+ .callback = intel_dmi_reverse_brightness,
36305+ .ident = "NCR Corporation",
36306+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
36307+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
36308+ },
36309+ },
36310+ { } /* terminating entry */
36311+};
36312+
36313 static const struct intel_dmi_quirk intel_dmi_quirks[] = {
36314 {
36315- .dmi_id_list = &(const struct dmi_system_id[]) {
36316- {
36317- .callback = intel_dmi_reverse_brightness,
36318- .ident = "NCR Corporation",
36319- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
36320- DMI_MATCH(DMI_PRODUCT_NAME, ""),
36321- },
36322- },
36323- { } /* terminating entry */
36324- },
36325+ .dmi_id_list = &intel_dmi_quirks_table,
36326 .hook = quirk_invert_brightness,
36327 },
36328 };
36329diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
36330index 54558a0..2d97005 100644
36331--- a/drivers/gpu/drm/mga/mga_drv.h
36332+++ b/drivers/gpu/drm/mga/mga_drv.h
36333@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
36334 u32 clear_cmd;
36335 u32 maccess;
36336
36337- atomic_t vbl_received; /**< Number of vblanks received. */
36338+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
36339 wait_queue_head_t fence_queue;
36340- atomic_t last_fence_retired;
36341+ atomic_unchecked_t last_fence_retired;
36342 u32 next_fence_to_post;
36343
36344 unsigned int fb_cpp;
36345diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
36346index 709e90d..89a1c0d 100644
36347--- a/drivers/gpu/drm/mga/mga_ioc32.c
36348+++ b/drivers/gpu/drm/mga/mga_ioc32.c
36349@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
36350 return 0;
36351 }
36352
36353-drm_ioctl_compat_t *mga_compat_ioctls[] = {
36354+drm_ioctl_compat_t mga_compat_ioctls[] = {
36355 [DRM_MGA_INIT] = compat_mga_init,
36356 [DRM_MGA_GETPARAM] = compat_mga_getparam,
36357 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
36358@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
36359 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
36360 {
36361 unsigned int nr = DRM_IOCTL_NR(cmd);
36362- drm_ioctl_compat_t *fn = NULL;
36363 int ret;
36364
36365 if (nr < DRM_COMMAND_BASE)
36366 return drm_compat_ioctl(filp, cmd, arg);
36367
36368- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
36369- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
36370-
36371- if (fn != NULL)
36372+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
36373+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
36374 ret = (*fn) (filp, cmd, arg);
36375- else
36376+ } else
36377 ret = drm_ioctl(filp, cmd, arg);
36378
36379 return ret;
36380diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
36381index 598c281..60d590e 100644
36382--- a/drivers/gpu/drm/mga/mga_irq.c
36383+++ b/drivers/gpu/drm/mga/mga_irq.c
36384@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
36385 if (crtc != 0)
36386 return 0;
36387
36388- return atomic_read(&dev_priv->vbl_received);
36389+ return atomic_read_unchecked(&dev_priv->vbl_received);
36390 }
36391
36392
36393@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
36394 /* VBLANK interrupt */
36395 if (status & MGA_VLINEPEN) {
36396 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
36397- atomic_inc(&dev_priv->vbl_received);
36398+ atomic_inc_unchecked(&dev_priv->vbl_received);
36399 drm_handle_vblank(dev, 0);
36400 handled = 1;
36401 }
36402@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
36403 if ((prim_start & ~0x03) != (prim_end & ~0x03))
36404 MGA_WRITE(MGA_PRIMEND, prim_end);
36405
36406- atomic_inc(&dev_priv->last_fence_retired);
36407+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
36408 DRM_WAKEUP(&dev_priv->fence_queue);
36409 handled = 1;
36410 }
36411@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
36412 * using fences.
36413 */
36414 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
36415- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
36416+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
36417 - *sequence) <= (1 << 23)));
36418
36419 *sequence = cur_fence;
36420diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
36421index 865eddf..62c4cc3 100644
36422--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
36423+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
36424@@ -1015,7 +1015,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
36425 struct bit_table {
36426 const char id;
36427 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
36428-};
36429+} __no_const;
36430
36431 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
36432
36433diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
36434index aa89eb9..d45d38b 100644
36435--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
36436+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
36437@@ -80,7 +80,7 @@ struct nouveau_drm {
36438 struct drm_global_reference mem_global_ref;
36439 struct ttm_bo_global_ref bo_global_ref;
36440 struct ttm_bo_device bdev;
36441- atomic_t validate_sequence;
36442+ atomic_unchecked_t validate_sequence;
36443 int (*move)(struct nouveau_channel *,
36444 struct ttm_buffer_object *,
36445 struct ttm_mem_reg *, struct ttm_mem_reg *);
36446diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.h b/drivers/gpu/drm/nouveau/nouveau_fence.h
36447index cdb83ac..27f0a16 100644
36448--- a/drivers/gpu/drm/nouveau/nouveau_fence.h
36449+++ b/drivers/gpu/drm/nouveau/nouveau_fence.h
36450@@ -43,7 +43,7 @@ struct nouveau_fence_priv {
36451 int (*sync)(struct nouveau_fence *, struct nouveau_channel *,
36452 struct nouveau_channel *);
36453 u32 (*read)(struct nouveau_channel *);
36454-};
36455+} __no_const;
36456
36457 #define nouveau_fence(drm) ((struct nouveau_fence_priv *)(drm)->fence)
36458
36459diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
36460index 8bf695c..9fbc90a 100644
36461--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
36462+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
36463@@ -321,7 +321,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
36464 int trycnt = 0;
36465 int ret, i;
36466
36467- sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
36468+ sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
36469 retry:
36470 if (++trycnt > 100000) {
36471 NV_ERROR(drm, "%s failed and gave up.\n", __func__);
36472diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
36473index 08214bc..9208577 100644
36474--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
36475+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
36476@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
36477 unsigned long arg)
36478 {
36479 unsigned int nr = DRM_IOCTL_NR(cmd);
36480- drm_ioctl_compat_t *fn = NULL;
36481+ drm_ioctl_compat_t fn = NULL;
36482 int ret;
36483
36484 if (nr < DRM_COMMAND_BASE)
36485diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
36486index 25d3495..d81aaf6 100644
36487--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
36488+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
36489@@ -62,7 +62,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
36490 bool can_switch;
36491
36492 spin_lock(&dev->count_lock);
36493- can_switch = (dev->open_count == 0);
36494+ can_switch = (local_read(&dev->open_count) == 0);
36495 spin_unlock(&dev->count_lock);
36496 return can_switch;
36497 }
36498diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
36499index d4660cf..70dbe65 100644
36500--- a/drivers/gpu/drm/r128/r128_cce.c
36501+++ b/drivers/gpu/drm/r128/r128_cce.c
36502@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
36503
36504 /* GH: Simple idle check.
36505 */
36506- atomic_set(&dev_priv->idle_count, 0);
36507+ atomic_set_unchecked(&dev_priv->idle_count, 0);
36508
36509 /* We don't support anything other than bus-mastering ring mode,
36510 * but the ring can be in either AGP or PCI space for the ring
36511diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
36512index 930c71b..499aded 100644
36513--- a/drivers/gpu/drm/r128/r128_drv.h
36514+++ b/drivers/gpu/drm/r128/r128_drv.h
36515@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
36516 int is_pci;
36517 unsigned long cce_buffers_offset;
36518
36519- atomic_t idle_count;
36520+ atomic_unchecked_t idle_count;
36521
36522 int page_flipping;
36523 int current_page;
36524 u32 crtc_offset;
36525 u32 crtc_offset_cntl;
36526
36527- atomic_t vbl_received;
36528+ atomic_unchecked_t vbl_received;
36529
36530 u32 color_fmt;
36531 unsigned int front_offset;
36532diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
36533index a954c54..9cc595c 100644
36534--- a/drivers/gpu/drm/r128/r128_ioc32.c
36535+++ b/drivers/gpu/drm/r128/r128_ioc32.c
36536@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
36537 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
36538 }
36539
36540-drm_ioctl_compat_t *r128_compat_ioctls[] = {
36541+drm_ioctl_compat_t r128_compat_ioctls[] = {
36542 [DRM_R128_INIT] = compat_r128_init,
36543 [DRM_R128_DEPTH] = compat_r128_depth,
36544 [DRM_R128_STIPPLE] = compat_r128_stipple,
36545@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
36546 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
36547 {
36548 unsigned int nr = DRM_IOCTL_NR(cmd);
36549- drm_ioctl_compat_t *fn = NULL;
36550 int ret;
36551
36552 if (nr < DRM_COMMAND_BASE)
36553 return drm_compat_ioctl(filp, cmd, arg);
36554
36555- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
36556- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
36557-
36558- if (fn != NULL)
36559+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
36560+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
36561 ret = (*fn) (filp, cmd, arg);
36562- else
36563+ } else
36564 ret = drm_ioctl(filp, cmd, arg);
36565
36566 return ret;
36567diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
36568index 2ea4f09..d391371 100644
36569--- a/drivers/gpu/drm/r128/r128_irq.c
36570+++ b/drivers/gpu/drm/r128/r128_irq.c
36571@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
36572 if (crtc != 0)
36573 return 0;
36574
36575- return atomic_read(&dev_priv->vbl_received);
36576+ return atomic_read_unchecked(&dev_priv->vbl_received);
36577 }
36578
36579 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
36580@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
36581 /* VBLANK interrupt */
36582 if (status & R128_CRTC_VBLANK_INT) {
36583 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
36584- atomic_inc(&dev_priv->vbl_received);
36585+ atomic_inc_unchecked(&dev_priv->vbl_received);
36586 drm_handle_vblank(dev, 0);
36587 return IRQ_HANDLED;
36588 }
36589diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
36590index 19bb7e6..de7e2a2 100644
36591--- a/drivers/gpu/drm/r128/r128_state.c
36592+++ b/drivers/gpu/drm/r128/r128_state.c
36593@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
36594
36595 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
36596 {
36597- if (atomic_read(&dev_priv->idle_count) == 0)
36598+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
36599 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
36600 else
36601- atomic_set(&dev_priv->idle_count, 0);
36602+ atomic_set_unchecked(&dev_priv->idle_count, 0);
36603 }
36604
36605 #endif
36606diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
36607index 5a82b6b..9e69c73 100644
36608--- a/drivers/gpu/drm/radeon/mkregtable.c
36609+++ b/drivers/gpu/drm/radeon/mkregtable.c
36610@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
36611 regex_t mask_rex;
36612 regmatch_t match[4];
36613 char buf[1024];
36614- size_t end;
36615+ long end;
36616 int len;
36617 int done = 0;
36618 int r;
36619 unsigned o;
36620 struct offset *offset;
36621 char last_reg_s[10];
36622- int last_reg;
36623+ unsigned long last_reg;
36624
36625 if (regcomp
36626 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
36627diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
36628index 0d6562b..a154330 100644
36629--- a/drivers/gpu/drm/radeon/radeon_device.c
36630+++ b/drivers/gpu/drm/radeon/radeon_device.c
36631@@ -969,7 +969,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
36632 bool can_switch;
36633
36634 spin_lock(&dev->count_lock);
36635- can_switch = (dev->open_count == 0);
36636+ can_switch = (local_read(&dev->open_count) == 0);
36637 spin_unlock(&dev->count_lock);
36638 return can_switch;
36639 }
36640diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
36641index e7fdf16..f4f6490 100644
36642--- a/drivers/gpu/drm/radeon/radeon_drv.h
36643+++ b/drivers/gpu/drm/radeon/radeon_drv.h
36644@@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
36645
36646 /* SW interrupt */
36647 wait_queue_head_t swi_queue;
36648- atomic_t swi_emitted;
36649+ atomic_unchecked_t swi_emitted;
36650 int vblank_crtc;
36651 uint32_t irq_enable_reg;
36652 uint32_t r500_disp_irq_reg;
36653diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
36654index c180df8..5fd8186 100644
36655--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
36656+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
36657@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
36658 request = compat_alloc_user_space(sizeof(*request));
36659 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
36660 || __put_user(req32.param, &request->param)
36661- || __put_user((void __user *)(unsigned long)req32.value,
36662+ || __put_user((unsigned long)req32.value,
36663 &request->value))
36664 return -EFAULT;
36665
36666@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
36667 #define compat_radeon_cp_setparam NULL
36668 #endif /* X86_64 || IA64 */
36669
36670-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
36671+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
36672 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
36673 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
36674 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
36675@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
36676 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
36677 {
36678 unsigned int nr = DRM_IOCTL_NR(cmd);
36679- drm_ioctl_compat_t *fn = NULL;
36680 int ret;
36681
36682 if (nr < DRM_COMMAND_BASE)
36683 return drm_compat_ioctl(filp, cmd, arg);
36684
36685- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
36686- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
36687-
36688- if (fn != NULL)
36689+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
36690+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
36691 ret = (*fn) (filp, cmd, arg);
36692- else
36693+ } else
36694 ret = drm_ioctl(filp, cmd, arg);
36695
36696 return ret;
36697diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
36698index e771033..a0bc6b3 100644
36699--- a/drivers/gpu/drm/radeon/radeon_irq.c
36700+++ b/drivers/gpu/drm/radeon/radeon_irq.c
36701@@ -224,8 +224,8 @@ static int radeon_emit_irq(struct drm_device * dev)
36702 unsigned int ret;
36703 RING_LOCALS;
36704
36705- atomic_inc(&dev_priv->swi_emitted);
36706- ret = atomic_read(&dev_priv->swi_emitted);
36707+ atomic_inc_unchecked(&dev_priv->swi_emitted);
36708+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
36709
36710 BEGIN_RING(4);
36711 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
36712@@ -351,7 +351,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
36713 drm_radeon_private_t *dev_priv =
36714 (drm_radeon_private_t *) dev->dev_private;
36715
36716- atomic_set(&dev_priv->swi_emitted, 0);
36717+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
36718 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
36719
36720 dev->max_vblank_count = 0x001fffff;
36721diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
36722index 8e9057b..af6dacb 100644
36723--- a/drivers/gpu/drm/radeon/radeon_state.c
36724+++ b/drivers/gpu/drm/radeon/radeon_state.c
36725@@ -2166,7 +2166,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
36726 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
36727 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
36728
36729- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
36730+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
36731 sarea_priv->nbox * sizeof(depth_boxes[0])))
36732 return -EFAULT;
36733
36734@@ -3029,7 +3029,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
36735 {
36736 drm_radeon_private_t *dev_priv = dev->dev_private;
36737 drm_radeon_getparam_t *param = data;
36738- int value;
36739+ int value = 0;
36740
36741 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
36742
36743diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
36744index 93f760e..8088227 100644
36745--- a/drivers/gpu/drm/radeon/radeon_ttm.c
36746+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
36747@@ -782,7 +782,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
36748 man->size = size >> PAGE_SHIFT;
36749 }
36750
36751-static struct vm_operations_struct radeon_ttm_vm_ops;
36752+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
36753 static const struct vm_operations_struct *ttm_vm_ops = NULL;
36754
36755 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
36756@@ -823,8 +823,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
36757 }
36758 if (unlikely(ttm_vm_ops == NULL)) {
36759 ttm_vm_ops = vma->vm_ops;
36760+ pax_open_kernel();
36761 radeon_ttm_vm_ops = *ttm_vm_ops;
36762 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
36763+ pax_close_kernel();
36764 }
36765 vma->vm_ops = &radeon_ttm_vm_ops;
36766 return 0;
36767@@ -862,28 +864,33 @@ static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
36768 sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
36769 else
36770 sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
36771- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36772- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
36773- radeon_mem_types_list[i].driver_features = 0;
36774+ pax_open_kernel();
36775+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36776+ *(void **)&radeon_mem_types_list[i].show = &radeon_mm_dump_table;
36777+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
36778 if (i == 0)
36779- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
36780+ *(void **)&radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
36781 else
36782- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
36783-
36784+ *(void **)&radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
36785+ pax_close_kernel();
36786 }
36787 /* Add ttm page pool to debugfs */
36788 sprintf(radeon_mem_types_names[i], "ttm_page_pool");
36789- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36790- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
36791- radeon_mem_types_list[i].driver_features = 0;
36792- radeon_mem_types_list[i++].data = NULL;
36793+ pax_open_kernel();
36794+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36795+ *(void **)&radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
36796+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
36797+ *(void **)&radeon_mem_types_list[i++].data = NULL;
36798+ pax_close_kernel();
36799 #ifdef CONFIG_SWIOTLB
36800 if (swiotlb_nr_tbl()) {
36801 sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
36802- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36803- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
36804- radeon_mem_types_list[i].driver_features = 0;
36805- radeon_mem_types_list[i++].data = NULL;
36806+ pax_open_kernel();
36807+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36808+ *(void **)&radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
36809+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
36810+ *(void **)&radeon_mem_types_list[i++].data = NULL;
36811+ pax_close_kernel();
36812 }
36813 #endif
36814 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
36815diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
36816index 5706d2a..17aedaa 100644
36817--- a/drivers/gpu/drm/radeon/rs690.c
36818+++ b/drivers/gpu/drm/radeon/rs690.c
36819@@ -304,9 +304,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
36820 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
36821 rdev->pm.sideport_bandwidth.full)
36822 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
36823- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
36824+ read_delay_latency.full = dfixed_const(800 * 1000);
36825 read_delay_latency.full = dfixed_div(read_delay_latency,
36826 rdev->pm.igp_sideport_mclk);
36827+ a.full = dfixed_const(370);
36828+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
36829 } else {
36830 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
36831 rdev->pm.k8_bandwidth.full)
36832diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
36833index bd2a3b4..122d9ad 100644
36834--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
36835+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
36836@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
36837 static int ttm_pool_mm_shrink(struct shrinker *shrink,
36838 struct shrink_control *sc)
36839 {
36840- static atomic_t start_pool = ATOMIC_INIT(0);
36841+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
36842 unsigned i;
36843- unsigned pool_offset = atomic_add_return(1, &start_pool);
36844+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
36845 struct ttm_page_pool *pool;
36846 int shrink_pages = sc->nr_to_scan;
36847
36848diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
36849index 1eb060c..188b1fc 100644
36850--- a/drivers/gpu/drm/udl/udl_fb.c
36851+++ b/drivers/gpu/drm/udl/udl_fb.c
36852@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
36853 fb_deferred_io_cleanup(info);
36854 kfree(info->fbdefio);
36855 info->fbdefio = NULL;
36856- info->fbops->fb_mmap = udl_fb_mmap;
36857 }
36858
36859 pr_warn("released /dev/fb%d user=%d count=%d\n",
36860diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
36861index 893a650..6190d3b 100644
36862--- a/drivers/gpu/drm/via/via_drv.h
36863+++ b/drivers/gpu/drm/via/via_drv.h
36864@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
36865 typedef uint32_t maskarray_t[5];
36866
36867 typedef struct drm_via_irq {
36868- atomic_t irq_received;
36869+ atomic_unchecked_t irq_received;
36870 uint32_t pending_mask;
36871 uint32_t enable_mask;
36872 wait_queue_head_t irq_queue;
36873@@ -75,7 +75,7 @@ typedef struct drm_via_private {
36874 struct timeval last_vblank;
36875 int last_vblank_valid;
36876 unsigned usec_per_vblank;
36877- atomic_t vbl_received;
36878+ atomic_unchecked_t vbl_received;
36879 drm_via_state_t hc_state;
36880 char pci_buf[VIA_PCI_BUF_SIZE];
36881 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
36882diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
36883index ac98964..5dbf512 100644
36884--- a/drivers/gpu/drm/via/via_irq.c
36885+++ b/drivers/gpu/drm/via/via_irq.c
36886@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
36887 if (crtc != 0)
36888 return 0;
36889
36890- return atomic_read(&dev_priv->vbl_received);
36891+ return atomic_read_unchecked(&dev_priv->vbl_received);
36892 }
36893
36894 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36895@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36896
36897 status = VIA_READ(VIA_REG_INTERRUPT);
36898 if (status & VIA_IRQ_VBLANK_PENDING) {
36899- atomic_inc(&dev_priv->vbl_received);
36900- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
36901+ atomic_inc_unchecked(&dev_priv->vbl_received);
36902+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
36903 do_gettimeofday(&cur_vblank);
36904 if (dev_priv->last_vblank_valid) {
36905 dev_priv->usec_per_vblank =
36906@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36907 dev_priv->last_vblank = cur_vblank;
36908 dev_priv->last_vblank_valid = 1;
36909 }
36910- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
36911+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
36912 DRM_DEBUG("US per vblank is: %u\n",
36913 dev_priv->usec_per_vblank);
36914 }
36915@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36916
36917 for (i = 0; i < dev_priv->num_irqs; ++i) {
36918 if (status & cur_irq->pending_mask) {
36919- atomic_inc(&cur_irq->irq_received);
36920+ atomic_inc_unchecked(&cur_irq->irq_received);
36921 DRM_WAKEUP(&cur_irq->irq_queue);
36922 handled = 1;
36923 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
36924@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
36925 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
36926 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
36927 masks[irq][4]));
36928- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
36929+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
36930 } else {
36931 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
36932 (((cur_irq_sequence =
36933- atomic_read(&cur_irq->irq_received)) -
36934+ atomic_read_unchecked(&cur_irq->irq_received)) -
36935 *sequence) <= (1 << 23)));
36936 }
36937 *sequence = cur_irq_sequence;
36938@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
36939 }
36940
36941 for (i = 0; i < dev_priv->num_irqs; ++i) {
36942- atomic_set(&cur_irq->irq_received, 0);
36943+ atomic_set_unchecked(&cur_irq->irq_received, 0);
36944 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
36945 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
36946 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
36947@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
36948 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
36949 case VIA_IRQ_RELATIVE:
36950 irqwait->request.sequence +=
36951- atomic_read(&cur_irq->irq_received);
36952+ atomic_read_unchecked(&cur_irq->irq_received);
36953 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
36954 case VIA_IRQ_ABSOLUTE:
36955 break;
36956diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
36957index 13aeda7..4a952d1 100644
36958--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
36959+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
36960@@ -290,7 +290,7 @@ struct vmw_private {
36961 * Fencing and IRQs.
36962 */
36963
36964- atomic_t marker_seq;
36965+ atomic_unchecked_t marker_seq;
36966 wait_queue_head_t fence_queue;
36967 wait_queue_head_t fifo_queue;
36968 int fence_queue_waiters; /* Protected by hw_mutex */
36969diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
36970index 3eb1486..0a47ee9 100644
36971--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
36972+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
36973@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
36974 (unsigned int) min,
36975 (unsigned int) fifo->capabilities);
36976
36977- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
36978+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
36979 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
36980 vmw_marker_queue_init(&fifo->marker_queue);
36981 return vmw_fifo_send_fence(dev_priv, &dummy);
36982@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
36983 if (reserveable)
36984 iowrite32(bytes, fifo_mem +
36985 SVGA_FIFO_RESERVED);
36986- return fifo_mem + (next_cmd >> 2);
36987+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
36988 } else {
36989 need_bounce = true;
36990 }
36991@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
36992
36993 fm = vmw_fifo_reserve(dev_priv, bytes);
36994 if (unlikely(fm == NULL)) {
36995- *seqno = atomic_read(&dev_priv->marker_seq);
36996+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
36997 ret = -ENOMEM;
36998 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
36999 false, 3*HZ);
37000@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
37001 }
37002
37003 do {
37004- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
37005+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
37006 } while (*seqno == 0);
37007
37008 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
37009diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
37010index 4640adb..e1384ed 100644
37011--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
37012+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
37013@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
37014 * emitted. Then the fence is stale and signaled.
37015 */
37016
37017- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
37018+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
37019 > VMW_FENCE_WRAP);
37020
37021 return ret;
37022@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
37023
37024 if (fifo_idle)
37025 down_read(&fifo_state->rwsem);
37026- signal_seq = atomic_read(&dev_priv->marker_seq);
37027+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
37028 ret = 0;
37029
37030 for (;;) {
37031diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
37032index 8a8725c..afed796 100644
37033--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
37034+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
37035@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
37036 while (!vmw_lag_lt(queue, us)) {
37037 spin_lock(&queue->lock);
37038 if (list_empty(&queue->head))
37039- seqno = atomic_read(&dev_priv->marker_seq);
37040+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
37041 else {
37042 marker = list_first_entry(&queue->head,
37043 struct vmw_marker, head);
37044diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
37045index ceb3040..6160c5c 100644
37046--- a/drivers/hid/hid-core.c
37047+++ b/drivers/hid/hid-core.c
37048@@ -2242,7 +2242,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
37049
37050 int hid_add_device(struct hid_device *hdev)
37051 {
37052- static atomic_t id = ATOMIC_INIT(0);
37053+ static atomic_unchecked_t id = ATOMIC_INIT(0);
37054 int ret;
37055
37056 if (WARN_ON(hdev->status & HID_STAT_ADDED))
37057@@ -2276,7 +2276,7 @@ int hid_add_device(struct hid_device *hdev)
37058 /* XXX hack, any other cleaner solution after the driver core
37059 * is converted to allow more than 20 bytes as the device name? */
37060 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
37061- hdev->vendor, hdev->product, atomic_inc_return(&id));
37062+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
37063
37064 hid_debug_register(hdev, dev_name(&hdev->dev));
37065 ret = device_add(&hdev->dev);
37066diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
37067index eec3291..8ed706b 100644
37068--- a/drivers/hid/hid-wiimote-debug.c
37069+++ b/drivers/hid/hid-wiimote-debug.c
37070@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
37071 else if (size == 0)
37072 return -EIO;
37073
37074- if (copy_to_user(u, buf, size))
37075+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
37076 return -EFAULT;
37077
37078 *off += size;
37079diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
37080index 773a2f2..7ce08bc 100644
37081--- a/drivers/hv/channel.c
37082+++ b/drivers/hv/channel.c
37083@@ -394,8 +394,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
37084 int ret = 0;
37085 int t;
37086
37087- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
37088- atomic_inc(&vmbus_connection.next_gpadl_handle);
37089+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
37090+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
37091
37092 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
37093 if (ret)
37094diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
37095index 3648f8f..30ef30d 100644
37096--- a/drivers/hv/hv.c
37097+++ b/drivers/hv/hv.c
37098@@ -111,7 +111,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
37099 u64 output_address = (output) ? virt_to_phys(output) : 0;
37100 u32 output_address_hi = output_address >> 32;
37101 u32 output_address_lo = output_address & 0xFFFFFFFF;
37102- void *hypercall_page = hv_context.hypercall_page;
37103+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
37104
37105 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
37106 "=a"(hv_status_lo) : "d" (control_hi),
37107diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
37108index d8d1fad..b91caf7 100644
37109--- a/drivers/hv/hyperv_vmbus.h
37110+++ b/drivers/hv/hyperv_vmbus.h
37111@@ -594,7 +594,7 @@ enum vmbus_connect_state {
37112 struct vmbus_connection {
37113 enum vmbus_connect_state conn_state;
37114
37115- atomic_t next_gpadl_handle;
37116+ atomic_unchecked_t next_gpadl_handle;
37117
37118 /*
37119 * Represents channel interrupts. Each bit position represents a
37120diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
37121index 8e1a9ec..4687821 100644
37122--- a/drivers/hv/vmbus_drv.c
37123+++ b/drivers/hv/vmbus_drv.c
37124@@ -629,10 +629,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
37125 {
37126 int ret = 0;
37127
37128- static atomic_t device_num = ATOMIC_INIT(0);
37129+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
37130
37131 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
37132- atomic_inc_return(&device_num));
37133+ atomic_inc_return_unchecked(&device_num));
37134
37135 child_device_obj->device.bus = &hv_bus;
37136 child_device_obj->device.parent = &hv_acpi_dev->dev;
37137diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
37138index 1672e2a..4a6297c 100644
37139--- a/drivers/hwmon/acpi_power_meter.c
37140+++ b/drivers/hwmon/acpi_power_meter.c
37141@@ -117,7 +117,7 @@ struct sensor_template {
37142 struct device_attribute *devattr,
37143 const char *buf, size_t count);
37144 int index;
37145-};
37146+} __do_const;
37147
37148 /* Averaging interval */
37149 static int update_avg_interval(struct acpi_power_meter_resource *resource)
37150@@ -629,7 +629,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
37151 struct sensor_template *attrs)
37152 {
37153 struct device *dev = &resource->acpi_dev->dev;
37154- struct sensor_device_attribute *sensors =
37155+ sensor_device_attribute_no_const *sensors =
37156 &resource->sensors[resource->num_sensors];
37157 int res = 0;
37158
37159diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
37160index b41baff..4953e4d 100644
37161--- a/drivers/hwmon/applesmc.c
37162+++ b/drivers/hwmon/applesmc.c
37163@@ -1084,7 +1084,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
37164 {
37165 struct applesmc_node_group *grp;
37166 struct applesmc_dev_attr *node;
37167- struct attribute *attr;
37168+ attribute_no_const *attr;
37169 int ret, i;
37170
37171 for (grp = groups; grp->format; grp++) {
37172diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
37173index 56dbcfb..9874bf1 100644
37174--- a/drivers/hwmon/asus_atk0110.c
37175+++ b/drivers/hwmon/asus_atk0110.c
37176@@ -152,10 +152,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
37177 struct atk_sensor_data {
37178 struct list_head list;
37179 struct atk_data *data;
37180- struct device_attribute label_attr;
37181- struct device_attribute input_attr;
37182- struct device_attribute limit1_attr;
37183- struct device_attribute limit2_attr;
37184+ device_attribute_no_const label_attr;
37185+ device_attribute_no_const input_attr;
37186+ device_attribute_no_const limit1_attr;
37187+ device_attribute_no_const limit2_attr;
37188 char label_attr_name[ATTR_NAME_SIZE];
37189 char input_attr_name[ATTR_NAME_SIZE];
37190 char limit1_attr_name[ATTR_NAME_SIZE];
37191@@ -275,7 +275,7 @@ static ssize_t atk_name_show(struct device *dev,
37192 static struct device_attribute atk_name_attr =
37193 __ATTR(name, 0444, atk_name_show, NULL);
37194
37195-static void atk_init_attribute(struct device_attribute *attr, char *name,
37196+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
37197 sysfs_show_func show)
37198 {
37199 sysfs_attr_init(&attr->attr);
37200diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
37201index d64923d..72591e8 100644
37202--- a/drivers/hwmon/coretemp.c
37203+++ b/drivers/hwmon/coretemp.c
37204@@ -790,7 +790,7 @@ static int __cpuinit coretemp_cpu_callback(struct notifier_block *nfb,
37205 return NOTIFY_OK;
37206 }
37207
37208-static struct notifier_block coretemp_cpu_notifier __refdata = {
37209+static struct notifier_block coretemp_cpu_notifier = {
37210 .notifier_call = coretemp_cpu_callback,
37211 };
37212
37213diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
37214index a14f634..2916ee2 100644
37215--- a/drivers/hwmon/ibmaem.c
37216+++ b/drivers/hwmon/ibmaem.c
37217@@ -925,7 +925,7 @@ static int aem_register_sensors(struct aem_data *data,
37218 struct aem_rw_sensor_template *rw)
37219 {
37220 struct device *dev = &data->pdev->dev;
37221- struct sensor_device_attribute *sensors = data->sensors;
37222+ sensor_device_attribute_no_const *sensors = data->sensors;
37223 int err;
37224
37225 /* Set up read-only sensors */
37226diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
37227index 7d19b1b..8fdaaac 100644
37228--- a/drivers/hwmon/pmbus/pmbus_core.c
37229+++ b/drivers/hwmon/pmbus/pmbus_core.c
37230@@ -811,7 +811,7 @@ static ssize_t pmbus_show_label(struct device *dev,
37231
37232 #define PMBUS_ADD_ATTR(data, _name, _idx, _mode, _type, _show, _set) \
37233 do { \
37234- struct sensor_device_attribute *a \
37235+ sensor_device_attribute_no_const *a \
37236 = &data->_type##s[data->num_##_type##s].attribute; \
37237 BUG_ON(data->num_attributes >= data->max_attributes); \
37238 sysfs_attr_init(&a->dev_attr.attr); \
37239diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
37240index 8047fed..1e956f0 100644
37241--- a/drivers/hwmon/sht15.c
37242+++ b/drivers/hwmon/sht15.c
37243@@ -169,7 +169,7 @@ struct sht15_data {
37244 int supply_uV;
37245 bool supply_uV_valid;
37246 struct work_struct update_supply_work;
37247- atomic_t interrupt_handled;
37248+ atomic_unchecked_t interrupt_handled;
37249 };
37250
37251 /**
37252@@ -512,13 +512,13 @@ static int sht15_measurement(struct sht15_data *data,
37253 return ret;
37254
37255 gpio_direction_input(data->pdata->gpio_data);
37256- atomic_set(&data->interrupt_handled, 0);
37257+ atomic_set_unchecked(&data->interrupt_handled, 0);
37258
37259 enable_irq(gpio_to_irq(data->pdata->gpio_data));
37260 if (gpio_get_value(data->pdata->gpio_data) == 0) {
37261 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
37262 /* Only relevant if the interrupt hasn't occurred. */
37263- if (!atomic_read(&data->interrupt_handled))
37264+ if (!atomic_read_unchecked(&data->interrupt_handled))
37265 schedule_work(&data->read_work);
37266 }
37267 ret = wait_event_timeout(data->wait_queue,
37268@@ -785,7 +785,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
37269
37270 /* First disable the interrupt */
37271 disable_irq_nosync(irq);
37272- atomic_inc(&data->interrupt_handled);
37273+ atomic_inc_unchecked(&data->interrupt_handled);
37274 /* Then schedule a reading work struct */
37275 if (data->state != SHT15_READING_NOTHING)
37276 schedule_work(&data->read_work);
37277@@ -807,11 +807,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
37278 * If not, then start the interrupt again - care here as could
37279 * have gone low in meantime so verify it hasn't!
37280 */
37281- atomic_set(&data->interrupt_handled, 0);
37282+ atomic_set_unchecked(&data->interrupt_handled, 0);
37283 enable_irq(gpio_to_irq(data->pdata->gpio_data));
37284 /* If still not occurred or another handler was scheduled */
37285 if (gpio_get_value(data->pdata->gpio_data)
37286- || atomic_read(&data->interrupt_handled))
37287+ || atomic_read_unchecked(&data->interrupt_handled))
37288 return;
37289 }
37290
37291diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
37292index 76f157b..9c0db1b 100644
37293--- a/drivers/hwmon/via-cputemp.c
37294+++ b/drivers/hwmon/via-cputemp.c
37295@@ -296,7 +296,7 @@ static int __cpuinit via_cputemp_cpu_callback(struct notifier_block *nfb,
37296 return NOTIFY_OK;
37297 }
37298
37299-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
37300+static struct notifier_block via_cputemp_cpu_notifier = {
37301 .notifier_call = via_cputemp_cpu_callback,
37302 };
37303
37304diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
37305index 378fcb5..5e91fa8 100644
37306--- a/drivers/i2c/busses/i2c-amd756-s4882.c
37307+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
37308@@ -43,7 +43,7 @@
37309 extern struct i2c_adapter amd756_smbus;
37310
37311 static struct i2c_adapter *s4882_adapter;
37312-static struct i2c_algorithm *s4882_algo;
37313+static i2c_algorithm_no_const *s4882_algo;
37314
37315 /* Wrapper access functions for multiplexed SMBus */
37316 static DEFINE_MUTEX(amd756_lock);
37317diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
37318index 29015eb..af2d8e9 100644
37319--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
37320+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
37321@@ -41,7 +41,7 @@
37322 extern struct i2c_adapter *nforce2_smbus;
37323
37324 static struct i2c_adapter *s4985_adapter;
37325-static struct i2c_algorithm *s4985_algo;
37326+static i2c_algorithm_no_const *s4985_algo;
37327
37328 /* Wrapper access functions for multiplexed SMBus */
37329 static DEFINE_MUTEX(nforce2_lock);
37330diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
37331index 8126824..55a2798 100644
37332--- a/drivers/ide/ide-cd.c
37333+++ b/drivers/ide/ide-cd.c
37334@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
37335 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
37336 if ((unsigned long)buf & alignment
37337 || blk_rq_bytes(rq) & q->dma_pad_mask
37338- || object_is_on_stack(buf))
37339+ || object_starts_on_stack(buf))
37340 drive->dma = 0;
37341 }
37342 }
37343diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
37344index 8848f16..f8e6dd8 100644
37345--- a/drivers/iio/industrialio-core.c
37346+++ b/drivers/iio/industrialio-core.c
37347@@ -506,7 +506,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
37348 }
37349
37350 static
37351-int __iio_device_attr_init(struct device_attribute *dev_attr,
37352+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
37353 const char *postfix,
37354 struct iio_chan_spec const *chan,
37355 ssize_t (*readfunc)(struct device *dev,
37356diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
37357index 394fea2..c833880 100644
37358--- a/drivers/infiniband/core/cm.c
37359+++ b/drivers/infiniband/core/cm.c
37360@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
37361
37362 struct cm_counter_group {
37363 struct kobject obj;
37364- atomic_long_t counter[CM_ATTR_COUNT];
37365+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
37366 };
37367
37368 struct cm_counter_attribute {
37369@@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
37370 struct ib_mad_send_buf *msg = NULL;
37371 int ret;
37372
37373- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37374+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37375 counter[CM_REQ_COUNTER]);
37376
37377 /* Quick state check to discard duplicate REQs. */
37378@@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
37379 if (!cm_id_priv)
37380 return;
37381
37382- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37383+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37384 counter[CM_REP_COUNTER]);
37385 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
37386 if (ret)
37387@@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
37388 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
37389 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
37390 spin_unlock_irq(&cm_id_priv->lock);
37391- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37392+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37393 counter[CM_RTU_COUNTER]);
37394 goto out;
37395 }
37396@@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
37397 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
37398 dreq_msg->local_comm_id);
37399 if (!cm_id_priv) {
37400- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37401+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37402 counter[CM_DREQ_COUNTER]);
37403 cm_issue_drep(work->port, work->mad_recv_wc);
37404 return -EINVAL;
37405@@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
37406 case IB_CM_MRA_REP_RCVD:
37407 break;
37408 case IB_CM_TIMEWAIT:
37409- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37410+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37411 counter[CM_DREQ_COUNTER]);
37412 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
37413 goto unlock;
37414@@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
37415 cm_free_msg(msg);
37416 goto deref;
37417 case IB_CM_DREQ_RCVD:
37418- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37419+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37420 counter[CM_DREQ_COUNTER]);
37421 goto unlock;
37422 default:
37423@@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
37424 ib_modify_mad(cm_id_priv->av.port->mad_agent,
37425 cm_id_priv->msg, timeout)) {
37426 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
37427- atomic_long_inc(&work->port->
37428+ atomic_long_inc_unchecked(&work->port->
37429 counter_group[CM_RECV_DUPLICATES].
37430 counter[CM_MRA_COUNTER]);
37431 goto out;
37432@@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
37433 break;
37434 case IB_CM_MRA_REQ_RCVD:
37435 case IB_CM_MRA_REP_RCVD:
37436- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37437+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37438 counter[CM_MRA_COUNTER]);
37439 /* fall through */
37440 default:
37441@@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
37442 case IB_CM_LAP_IDLE:
37443 break;
37444 case IB_CM_MRA_LAP_SENT:
37445- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37446+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37447 counter[CM_LAP_COUNTER]);
37448 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
37449 goto unlock;
37450@@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
37451 cm_free_msg(msg);
37452 goto deref;
37453 case IB_CM_LAP_RCVD:
37454- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37455+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37456 counter[CM_LAP_COUNTER]);
37457 goto unlock;
37458 default:
37459@@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
37460 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
37461 if (cur_cm_id_priv) {
37462 spin_unlock_irq(&cm.lock);
37463- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37464+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37465 counter[CM_SIDR_REQ_COUNTER]);
37466 goto out; /* Duplicate message. */
37467 }
37468@@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
37469 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
37470 msg->retries = 1;
37471
37472- atomic_long_add(1 + msg->retries,
37473+ atomic_long_add_unchecked(1 + msg->retries,
37474 &port->counter_group[CM_XMIT].counter[attr_index]);
37475 if (msg->retries)
37476- atomic_long_add(msg->retries,
37477+ atomic_long_add_unchecked(msg->retries,
37478 &port->counter_group[CM_XMIT_RETRIES].
37479 counter[attr_index]);
37480
37481@@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
37482 }
37483
37484 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
37485- atomic_long_inc(&port->counter_group[CM_RECV].
37486+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
37487 counter[attr_id - CM_ATTR_ID_OFFSET]);
37488
37489 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
37490@@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
37491 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
37492
37493 return sprintf(buf, "%ld\n",
37494- atomic_long_read(&group->counter[cm_attr->index]));
37495+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
37496 }
37497
37498 static const struct sysfs_ops cm_counter_ops = {
37499diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
37500index 176c8f9..2627b62 100644
37501--- a/drivers/infiniband/core/fmr_pool.c
37502+++ b/drivers/infiniband/core/fmr_pool.c
37503@@ -98,8 +98,8 @@ struct ib_fmr_pool {
37504
37505 struct task_struct *thread;
37506
37507- atomic_t req_ser;
37508- atomic_t flush_ser;
37509+ atomic_unchecked_t req_ser;
37510+ atomic_unchecked_t flush_ser;
37511
37512 wait_queue_head_t force_wait;
37513 };
37514@@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
37515 struct ib_fmr_pool *pool = pool_ptr;
37516
37517 do {
37518- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
37519+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
37520 ib_fmr_batch_release(pool);
37521
37522- atomic_inc(&pool->flush_ser);
37523+ atomic_inc_unchecked(&pool->flush_ser);
37524 wake_up_interruptible(&pool->force_wait);
37525
37526 if (pool->flush_function)
37527@@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
37528 }
37529
37530 set_current_state(TASK_INTERRUPTIBLE);
37531- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
37532+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
37533 !kthread_should_stop())
37534 schedule();
37535 __set_current_state(TASK_RUNNING);
37536@@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
37537 pool->dirty_watermark = params->dirty_watermark;
37538 pool->dirty_len = 0;
37539 spin_lock_init(&pool->pool_lock);
37540- atomic_set(&pool->req_ser, 0);
37541- atomic_set(&pool->flush_ser, 0);
37542+ atomic_set_unchecked(&pool->req_ser, 0);
37543+ atomic_set_unchecked(&pool->flush_ser, 0);
37544 init_waitqueue_head(&pool->force_wait);
37545
37546 pool->thread = kthread_run(ib_fmr_cleanup_thread,
37547@@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
37548 }
37549 spin_unlock_irq(&pool->pool_lock);
37550
37551- serial = atomic_inc_return(&pool->req_ser);
37552+ serial = atomic_inc_return_unchecked(&pool->req_ser);
37553 wake_up_process(pool->thread);
37554
37555 if (wait_event_interruptible(pool->force_wait,
37556- atomic_read(&pool->flush_ser) - serial >= 0))
37557+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
37558 return -EINTR;
37559
37560 return 0;
37561@@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
37562 } else {
37563 list_add_tail(&fmr->list, &pool->dirty_list);
37564 if (++pool->dirty_len >= pool->dirty_watermark) {
37565- atomic_inc(&pool->req_ser);
37566+ atomic_inc_unchecked(&pool->req_ser);
37567 wake_up_process(pool->thread);
37568 }
37569 }
37570diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
37571index afd8179..598063f 100644
37572--- a/drivers/infiniband/hw/cxgb4/mem.c
37573+++ b/drivers/infiniband/hw/cxgb4/mem.c
37574@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
37575 int err;
37576 struct fw_ri_tpte tpt;
37577 u32 stag_idx;
37578- static atomic_t key;
37579+ static atomic_unchecked_t key;
37580
37581 if (c4iw_fatal_error(rdev))
37582 return -EIO;
37583@@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
37584 if (rdev->stats.stag.cur > rdev->stats.stag.max)
37585 rdev->stats.stag.max = rdev->stats.stag.cur;
37586 mutex_unlock(&rdev->stats.lock);
37587- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
37588+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
37589 }
37590 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
37591 __func__, stag_state, type, pdid, stag_idx);
37592diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
37593index 79b3dbc..96e5fcc 100644
37594--- a/drivers/infiniband/hw/ipath/ipath_rc.c
37595+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
37596@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
37597 struct ib_atomic_eth *ateth;
37598 struct ipath_ack_entry *e;
37599 u64 vaddr;
37600- atomic64_t *maddr;
37601+ atomic64_unchecked_t *maddr;
37602 u64 sdata;
37603 u32 rkey;
37604 u8 next;
37605@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
37606 IB_ACCESS_REMOTE_ATOMIC)))
37607 goto nack_acc_unlck;
37608 /* Perform atomic OP and save result. */
37609- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
37610+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
37611 sdata = be64_to_cpu(ateth->swap_data);
37612 e = &qp->s_ack_queue[qp->r_head_ack_queue];
37613 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
37614- (u64) atomic64_add_return(sdata, maddr) - sdata :
37615+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
37616 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
37617 be64_to_cpu(ateth->compare_data),
37618 sdata);
37619diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
37620index 1f95bba..9530f87 100644
37621--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
37622+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
37623@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
37624 unsigned long flags;
37625 struct ib_wc wc;
37626 u64 sdata;
37627- atomic64_t *maddr;
37628+ atomic64_unchecked_t *maddr;
37629 enum ib_wc_status send_status;
37630
37631 /*
37632@@ -382,11 +382,11 @@ again:
37633 IB_ACCESS_REMOTE_ATOMIC)))
37634 goto acc_err;
37635 /* Perform atomic OP and save result. */
37636- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
37637+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
37638 sdata = wqe->wr.wr.atomic.compare_add;
37639 *(u64 *) sqp->s_sge.sge.vaddr =
37640 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
37641- (u64) atomic64_add_return(sdata, maddr) - sdata :
37642+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
37643 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
37644 sdata, wqe->wr.wr.atomic.swap);
37645 goto send_comp;
37646diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
37647index 9d3e5c1..d9afe4a 100644
37648--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
37649+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
37650@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
37651 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
37652 }
37653
37654-int mthca_QUERY_FW(struct mthca_dev *dev)
37655+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
37656 {
37657 struct mthca_mailbox *mailbox;
37658 u32 *outbox;
37659diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
37660index ed9a989..e0c5871 100644
37661--- a/drivers/infiniband/hw/mthca/mthca_mr.c
37662+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
37663@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
37664 return key;
37665 }
37666
37667-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
37668+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
37669 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
37670 {
37671 struct mthca_mailbox *mailbox;
37672diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
37673index 5b152a3..c1f3e83 100644
37674--- a/drivers/infiniband/hw/nes/nes.c
37675+++ b/drivers/infiniband/hw/nes/nes.c
37676@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
37677 LIST_HEAD(nes_adapter_list);
37678 static LIST_HEAD(nes_dev_list);
37679
37680-atomic_t qps_destroyed;
37681+atomic_unchecked_t qps_destroyed;
37682
37683 static unsigned int ee_flsh_adapter;
37684 static unsigned int sysfs_nonidx_addr;
37685@@ -267,7 +267,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
37686 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
37687 struct nes_adapter *nesadapter = nesdev->nesadapter;
37688
37689- atomic_inc(&qps_destroyed);
37690+ atomic_inc_unchecked(&qps_destroyed);
37691
37692 /* Free the control structures */
37693
37694diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
37695index 33cc589..3bd6538 100644
37696--- a/drivers/infiniband/hw/nes/nes.h
37697+++ b/drivers/infiniband/hw/nes/nes.h
37698@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
37699 extern unsigned int wqm_quanta;
37700 extern struct list_head nes_adapter_list;
37701
37702-extern atomic_t cm_connects;
37703-extern atomic_t cm_accepts;
37704-extern atomic_t cm_disconnects;
37705-extern atomic_t cm_closes;
37706-extern atomic_t cm_connecteds;
37707-extern atomic_t cm_connect_reqs;
37708-extern atomic_t cm_rejects;
37709-extern atomic_t mod_qp_timouts;
37710-extern atomic_t qps_created;
37711-extern atomic_t qps_destroyed;
37712-extern atomic_t sw_qps_destroyed;
37713+extern atomic_unchecked_t cm_connects;
37714+extern atomic_unchecked_t cm_accepts;
37715+extern atomic_unchecked_t cm_disconnects;
37716+extern atomic_unchecked_t cm_closes;
37717+extern atomic_unchecked_t cm_connecteds;
37718+extern atomic_unchecked_t cm_connect_reqs;
37719+extern atomic_unchecked_t cm_rejects;
37720+extern atomic_unchecked_t mod_qp_timouts;
37721+extern atomic_unchecked_t qps_created;
37722+extern atomic_unchecked_t qps_destroyed;
37723+extern atomic_unchecked_t sw_qps_destroyed;
37724 extern u32 mh_detected;
37725 extern u32 mh_pauses_sent;
37726 extern u32 cm_packets_sent;
37727@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
37728 extern u32 cm_packets_received;
37729 extern u32 cm_packets_dropped;
37730 extern u32 cm_packets_retrans;
37731-extern atomic_t cm_listens_created;
37732-extern atomic_t cm_listens_destroyed;
37733+extern atomic_unchecked_t cm_listens_created;
37734+extern atomic_unchecked_t cm_listens_destroyed;
37735 extern u32 cm_backlog_drops;
37736-extern atomic_t cm_loopbacks;
37737-extern atomic_t cm_nodes_created;
37738-extern atomic_t cm_nodes_destroyed;
37739-extern atomic_t cm_accel_dropped_pkts;
37740-extern atomic_t cm_resets_recvd;
37741-extern atomic_t pau_qps_created;
37742-extern atomic_t pau_qps_destroyed;
37743+extern atomic_unchecked_t cm_loopbacks;
37744+extern atomic_unchecked_t cm_nodes_created;
37745+extern atomic_unchecked_t cm_nodes_destroyed;
37746+extern atomic_unchecked_t cm_accel_dropped_pkts;
37747+extern atomic_unchecked_t cm_resets_recvd;
37748+extern atomic_unchecked_t pau_qps_created;
37749+extern atomic_unchecked_t pau_qps_destroyed;
37750
37751 extern u32 int_mod_timer_init;
37752 extern u32 int_mod_cq_depth_256;
37753diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
37754index 22ea67e..dcbe3bc 100644
37755--- a/drivers/infiniband/hw/nes/nes_cm.c
37756+++ b/drivers/infiniband/hw/nes/nes_cm.c
37757@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
37758 u32 cm_packets_retrans;
37759 u32 cm_packets_created;
37760 u32 cm_packets_received;
37761-atomic_t cm_listens_created;
37762-atomic_t cm_listens_destroyed;
37763+atomic_unchecked_t cm_listens_created;
37764+atomic_unchecked_t cm_listens_destroyed;
37765 u32 cm_backlog_drops;
37766-atomic_t cm_loopbacks;
37767-atomic_t cm_nodes_created;
37768-atomic_t cm_nodes_destroyed;
37769-atomic_t cm_accel_dropped_pkts;
37770-atomic_t cm_resets_recvd;
37771+atomic_unchecked_t cm_loopbacks;
37772+atomic_unchecked_t cm_nodes_created;
37773+atomic_unchecked_t cm_nodes_destroyed;
37774+atomic_unchecked_t cm_accel_dropped_pkts;
37775+atomic_unchecked_t cm_resets_recvd;
37776
37777 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
37778 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
37779@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
37780
37781 static struct nes_cm_core *g_cm_core;
37782
37783-atomic_t cm_connects;
37784-atomic_t cm_accepts;
37785-atomic_t cm_disconnects;
37786-atomic_t cm_closes;
37787-atomic_t cm_connecteds;
37788-atomic_t cm_connect_reqs;
37789-atomic_t cm_rejects;
37790+atomic_unchecked_t cm_connects;
37791+atomic_unchecked_t cm_accepts;
37792+atomic_unchecked_t cm_disconnects;
37793+atomic_unchecked_t cm_closes;
37794+atomic_unchecked_t cm_connecteds;
37795+atomic_unchecked_t cm_connect_reqs;
37796+atomic_unchecked_t cm_rejects;
37797
37798 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
37799 {
37800@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
37801 kfree(listener);
37802 listener = NULL;
37803 ret = 0;
37804- atomic_inc(&cm_listens_destroyed);
37805+ atomic_inc_unchecked(&cm_listens_destroyed);
37806 } else {
37807 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
37808 }
37809@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
37810 cm_node->rem_mac);
37811
37812 add_hte_node(cm_core, cm_node);
37813- atomic_inc(&cm_nodes_created);
37814+ atomic_inc_unchecked(&cm_nodes_created);
37815
37816 return cm_node;
37817 }
37818@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
37819 }
37820
37821 atomic_dec(&cm_core->node_cnt);
37822- atomic_inc(&cm_nodes_destroyed);
37823+ atomic_inc_unchecked(&cm_nodes_destroyed);
37824 nesqp = cm_node->nesqp;
37825 if (nesqp) {
37826 nesqp->cm_node = NULL;
37827@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
37828
37829 static void drop_packet(struct sk_buff *skb)
37830 {
37831- atomic_inc(&cm_accel_dropped_pkts);
37832+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
37833 dev_kfree_skb_any(skb);
37834 }
37835
37836@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
37837 {
37838
37839 int reset = 0; /* whether to send reset in case of err.. */
37840- atomic_inc(&cm_resets_recvd);
37841+ atomic_inc_unchecked(&cm_resets_recvd);
37842 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
37843 " refcnt=%d\n", cm_node, cm_node->state,
37844 atomic_read(&cm_node->ref_count));
37845@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
37846 rem_ref_cm_node(cm_node->cm_core, cm_node);
37847 return NULL;
37848 }
37849- atomic_inc(&cm_loopbacks);
37850+ atomic_inc_unchecked(&cm_loopbacks);
37851 loopbackremotenode->loopbackpartner = cm_node;
37852 loopbackremotenode->tcp_cntxt.rcv_wscale =
37853 NES_CM_DEFAULT_RCV_WND_SCALE;
37854@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
37855 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
37856 else {
37857 rem_ref_cm_node(cm_core, cm_node);
37858- atomic_inc(&cm_accel_dropped_pkts);
37859+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
37860 dev_kfree_skb_any(skb);
37861 }
37862 break;
37863@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
37864
37865 if ((cm_id) && (cm_id->event_handler)) {
37866 if (issue_disconn) {
37867- atomic_inc(&cm_disconnects);
37868+ atomic_inc_unchecked(&cm_disconnects);
37869 cm_event.event = IW_CM_EVENT_DISCONNECT;
37870 cm_event.status = disconn_status;
37871 cm_event.local_addr = cm_id->local_addr;
37872@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
37873 }
37874
37875 if (issue_close) {
37876- atomic_inc(&cm_closes);
37877+ atomic_inc_unchecked(&cm_closes);
37878 nes_disconnect(nesqp, 1);
37879
37880 cm_id->provider_data = nesqp;
37881@@ -3033,7 +3033,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
37882
37883 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
37884 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
37885- atomic_inc(&cm_accepts);
37886+ atomic_inc_unchecked(&cm_accepts);
37887
37888 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
37889 netdev_refcnt_read(nesvnic->netdev));
37890@@ -3228,7 +3228,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
37891 struct nes_cm_core *cm_core;
37892 u8 *start_buff;
37893
37894- atomic_inc(&cm_rejects);
37895+ atomic_inc_unchecked(&cm_rejects);
37896 cm_node = (struct nes_cm_node *)cm_id->provider_data;
37897 loopback = cm_node->loopbackpartner;
37898 cm_core = cm_node->cm_core;
37899@@ -3288,7 +3288,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
37900 ntohl(cm_id->local_addr.sin_addr.s_addr),
37901 ntohs(cm_id->local_addr.sin_port));
37902
37903- atomic_inc(&cm_connects);
37904+ atomic_inc_unchecked(&cm_connects);
37905 nesqp->active_conn = 1;
37906
37907 /* cache the cm_id in the qp */
37908@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
37909 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
37910 return err;
37911 }
37912- atomic_inc(&cm_listens_created);
37913+ atomic_inc_unchecked(&cm_listens_created);
37914 }
37915
37916 cm_id->add_ref(cm_id);
37917@@ -3499,7 +3499,7 @@ static void cm_event_connected(struct nes_cm_event *event)
37918
37919 if (nesqp->destroyed)
37920 return;
37921- atomic_inc(&cm_connecteds);
37922+ atomic_inc_unchecked(&cm_connecteds);
37923 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
37924 " local port 0x%04X. jiffies = %lu.\n",
37925 nesqp->hwqp.qp_id,
37926@@ -3679,7 +3679,7 @@ static void cm_event_reset(struct nes_cm_event *event)
37927
37928 cm_id->add_ref(cm_id);
37929 ret = cm_id->event_handler(cm_id, &cm_event);
37930- atomic_inc(&cm_closes);
37931+ atomic_inc_unchecked(&cm_closes);
37932 cm_event.event = IW_CM_EVENT_CLOSE;
37933 cm_event.status = 0;
37934 cm_event.provider_data = cm_id->provider_data;
37935@@ -3715,7 +3715,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
37936 return;
37937 cm_id = cm_node->cm_id;
37938
37939- atomic_inc(&cm_connect_reqs);
37940+ atomic_inc_unchecked(&cm_connect_reqs);
37941 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
37942 cm_node, cm_id, jiffies);
37943
37944@@ -3755,7 +3755,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
37945 return;
37946 cm_id = cm_node->cm_id;
37947
37948- atomic_inc(&cm_connect_reqs);
37949+ atomic_inc_unchecked(&cm_connect_reqs);
37950 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
37951 cm_node, cm_id, jiffies);
37952
37953diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
37954index 4166452..fc952c3 100644
37955--- a/drivers/infiniband/hw/nes/nes_mgt.c
37956+++ b/drivers/infiniband/hw/nes/nes_mgt.c
37957@@ -40,8 +40,8 @@
37958 #include "nes.h"
37959 #include "nes_mgt.h"
37960
37961-atomic_t pau_qps_created;
37962-atomic_t pau_qps_destroyed;
37963+atomic_unchecked_t pau_qps_created;
37964+atomic_unchecked_t pau_qps_destroyed;
37965
37966 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
37967 {
37968@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
37969 {
37970 struct sk_buff *skb;
37971 unsigned long flags;
37972- atomic_inc(&pau_qps_destroyed);
37973+ atomic_inc_unchecked(&pau_qps_destroyed);
37974
37975 /* Free packets that have not yet been forwarded */
37976 /* Lock is acquired by skb_dequeue when removing the skb */
37977@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
37978 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
37979 skb_queue_head_init(&nesqp->pau_list);
37980 spin_lock_init(&nesqp->pau_lock);
37981- atomic_inc(&pau_qps_created);
37982+ atomic_inc_unchecked(&pau_qps_created);
37983 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
37984 }
37985
37986diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
37987index 9542e16..a008c40 100644
37988--- a/drivers/infiniband/hw/nes/nes_nic.c
37989+++ b/drivers/infiniband/hw/nes/nes_nic.c
37990@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
37991 target_stat_values[++index] = mh_detected;
37992 target_stat_values[++index] = mh_pauses_sent;
37993 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
37994- target_stat_values[++index] = atomic_read(&cm_connects);
37995- target_stat_values[++index] = atomic_read(&cm_accepts);
37996- target_stat_values[++index] = atomic_read(&cm_disconnects);
37997- target_stat_values[++index] = atomic_read(&cm_connecteds);
37998- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
37999- target_stat_values[++index] = atomic_read(&cm_rejects);
38000- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
38001- target_stat_values[++index] = atomic_read(&qps_created);
38002- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
38003- target_stat_values[++index] = atomic_read(&qps_destroyed);
38004- target_stat_values[++index] = atomic_read(&cm_closes);
38005+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
38006+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
38007+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
38008+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
38009+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
38010+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
38011+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
38012+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
38013+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
38014+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
38015+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
38016 target_stat_values[++index] = cm_packets_sent;
38017 target_stat_values[++index] = cm_packets_bounced;
38018 target_stat_values[++index] = cm_packets_created;
38019 target_stat_values[++index] = cm_packets_received;
38020 target_stat_values[++index] = cm_packets_dropped;
38021 target_stat_values[++index] = cm_packets_retrans;
38022- target_stat_values[++index] = atomic_read(&cm_listens_created);
38023- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
38024+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
38025+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
38026 target_stat_values[++index] = cm_backlog_drops;
38027- target_stat_values[++index] = atomic_read(&cm_loopbacks);
38028- target_stat_values[++index] = atomic_read(&cm_nodes_created);
38029- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
38030- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
38031- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
38032+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
38033+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
38034+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
38035+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
38036+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
38037 target_stat_values[++index] = nesadapter->free_4kpbl;
38038 target_stat_values[++index] = nesadapter->free_256pbl;
38039 target_stat_values[++index] = int_mod_timer_init;
38040 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
38041 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
38042 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
38043- target_stat_values[++index] = atomic_read(&pau_qps_created);
38044- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
38045+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
38046+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
38047 }
38048
38049 /**
38050diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
38051index 07e4fba..685f041 100644
38052--- a/drivers/infiniband/hw/nes/nes_verbs.c
38053+++ b/drivers/infiniband/hw/nes/nes_verbs.c
38054@@ -46,9 +46,9 @@
38055
38056 #include <rdma/ib_umem.h>
38057
38058-atomic_t mod_qp_timouts;
38059-atomic_t qps_created;
38060-atomic_t sw_qps_destroyed;
38061+atomic_unchecked_t mod_qp_timouts;
38062+atomic_unchecked_t qps_created;
38063+atomic_unchecked_t sw_qps_destroyed;
38064
38065 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
38066
38067@@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
38068 if (init_attr->create_flags)
38069 return ERR_PTR(-EINVAL);
38070
38071- atomic_inc(&qps_created);
38072+ atomic_inc_unchecked(&qps_created);
38073 switch (init_attr->qp_type) {
38074 case IB_QPT_RC:
38075 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
38076@@ -1462,7 +1462,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
38077 struct iw_cm_event cm_event;
38078 int ret = 0;
38079
38080- atomic_inc(&sw_qps_destroyed);
38081+ atomic_inc_unchecked(&sw_qps_destroyed);
38082 nesqp->destroyed = 1;
38083
38084 /* Blow away the connection if it exists. */
38085diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
38086index 4d11575..3e890e5 100644
38087--- a/drivers/infiniband/hw/qib/qib.h
38088+++ b/drivers/infiniband/hw/qib/qib.h
38089@@ -51,6 +51,7 @@
38090 #include <linux/completion.h>
38091 #include <linux/kref.h>
38092 #include <linux/sched.h>
38093+#include <linux/slab.h>
38094
38095 #include "qib_common.h"
38096 #include "qib_verbs.h"
38097diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
38098index da739d9..da1c7f4 100644
38099--- a/drivers/input/gameport/gameport.c
38100+++ b/drivers/input/gameport/gameport.c
38101@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
38102 */
38103 static void gameport_init_port(struct gameport *gameport)
38104 {
38105- static atomic_t gameport_no = ATOMIC_INIT(0);
38106+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
38107
38108 __module_get(THIS_MODULE);
38109
38110 mutex_init(&gameport->drv_mutex);
38111 device_initialize(&gameport->dev);
38112 dev_set_name(&gameport->dev, "gameport%lu",
38113- (unsigned long)atomic_inc_return(&gameport_no) - 1);
38114+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
38115 gameport->dev.bus = &gameport_bus;
38116 gameport->dev.release = gameport_release_port;
38117 if (gameport->parent)
38118diff --git a/drivers/input/input.c b/drivers/input/input.c
38119index c044699..174d71a 100644
38120--- a/drivers/input/input.c
38121+++ b/drivers/input/input.c
38122@@ -2019,7 +2019,7 @@ static void devm_input_device_unregister(struct device *dev, void *res)
38123 */
38124 int input_register_device(struct input_dev *dev)
38125 {
38126- static atomic_t input_no = ATOMIC_INIT(0);
38127+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
38128 struct input_devres *devres = NULL;
38129 struct input_handler *handler;
38130 unsigned int packet_size;
38131@@ -2074,7 +2074,7 @@ int input_register_device(struct input_dev *dev)
38132 dev->setkeycode = input_default_setkeycode;
38133
38134 dev_set_name(&dev->dev, "input%ld",
38135- (unsigned long) atomic_inc_return(&input_no) - 1);
38136+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
38137
38138 error = device_add(&dev->dev);
38139 if (error)
38140diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
38141index 04c69af..5f92d00 100644
38142--- a/drivers/input/joystick/sidewinder.c
38143+++ b/drivers/input/joystick/sidewinder.c
38144@@ -30,6 +30,7 @@
38145 #include <linux/kernel.h>
38146 #include <linux/module.h>
38147 #include <linux/slab.h>
38148+#include <linux/sched.h>
38149 #include <linux/init.h>
38150 #include <linux/input.h>
38151 #include <linux/gameport.h>
38152diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
38153index d6cbfe9..6225402 100644
38154--- a/drivers/input/joystick/xpad.c
38155+++ b/drivers/input/joystick/xpad.c
38156@@ -735,7 +735,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
38157
38158 static int xpad_led_probe(struct usb_xpad *xpad)
38159 {
38160- static atomic_t led_seq = ATOMIC_INIT(0);
38161+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
38162 long led_no;
38163 struct xpad_led *led;
38164 struct led_classdev *led_cdev;
38165@@ -748,7 +748,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
38166 if (!led)
38167 return -ENOMEM;
38168
38169- led_no = (long)atomic_inc_return(&led_seq) - 1;
38170+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
38171
38172 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
38173 led->xpad = xpad;
38174diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
38175index fe1df23..5b710f3 100644
38176--- a/drivers/input/mouse/psmouse.h
38177+++ b/drivers/input/mouse/psmouse.h
38178@@ -115,7 +115,7 @@ struct psmouse_attribute {
38179 ssize_t (*set)(struct psmouse *psmouse, void *data,
38180 const char *buf, size_t count);
38181 bool protect;
38182-};
38183+} __do_const;
38184 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
38185
38186 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
38187diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
38188index 4c842c3..590b0bf 100644
38189--- a/drivers/input/mousedev.c
38190+++ b/drivers/input/mousedev.c
38191@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
38192
38193 spin_unlock_irq(&client->packet_lock);
38194
38195- if (copy_to_user(buffer, data, count))
38196+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
38197 return -EFAULT;
38198
38199 return count;
38200diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
38201index 25fc597..558bf3b 100644
38202--- a/drivers/input/serio/serio.c
38203+++ b/drivers/input/serio/serio.c
38204@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
38205 */
38206 static void serio_init_port(struct serio *serio)
38207 {
38208- static atomic_t serio_no = ATOMIC_INIT(0);
38209+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
38210
38211 __module_get(THIS_MODULE);
38212
38213@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
38214 mutex_init(&serio->drv_mutex);
38215 device_initialize(&serio->dev);
38216 dev_set_name(&serio->dev, "serio%ld",
38217- (long)atomic_inc_return(&serio_no) - 1);
38218+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
38219 serio->dev.bus = &serio_bus;
38220 serio->dev.release = serio_release_port;
38221 serio->dev.groups = serio_device_attr_groups;
38222diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
38223index ddbdaca..be18a78 100644
38224--- a/drivers/iommu/iommu.c
38225+++ b/drivers/iommu/iommu.c
38226@@ -554,7 +554,7 @@ static struct notifier_block iommu_bus_nb = {
38227 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
38228 {
38229 bus_register_notifier(bus, &iommu_bus_nb);
38230- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
38231+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
38232 }
38233
38234 /**
38235diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
38236index 89562a8..218999b 100644
38237--- a/drivers/isdn/capi/capi.c
38238+++ b/drivers/isdn/capi/capi.c
38239@@ -81,8 +81,8 @@ struct capiminor {
38240
38241 struct capi20_appl *ap;
38242 u32 ncci;
38243- atomic_t datahandle;
38244- atomic_t msgid;
38245+ atomic_unchecked_t datahandle;
38246+ atomic_unchecked_t msgid;
38247
38248 struct tty_port port;
38249 int ttyinstop;
38250@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
38251 capimsg_setu16(s, 2, mp->ap->applid);
38252 capimsg_setu8 (s, 4, CAPI_DATA_B3);
38253 capimsg_setu8 (s, 5, CAPI_RESP);
38254- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
38255+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
38256 capimsg_setu32(s, 8, mp->ncci);
38257 capimsg_setu16(s, 12, datahandle);
38258 }
38259@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
38260 mp->outbytes -= len;
38261 spin_unlock_bh(&mp->outlock);
38262
38263- datahandle = atomic_inc_return(&mp->datahandle);
38264+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
38265 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
38266 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
38267 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
38268 capimsg_setu16(skb->data, 2, mp->ap->applid);
38269 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
38270 capimsg_setu8 (skb->data, 5, CAPI_REQ);
38271- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
38272+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
38273 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
38274 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
38275 capimsg_setu16(skb->data, 16, len); /* Data length */
38276diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
38277index 67abf3f..076b3a6 100644
38278--- a/drivers/isdn/gigaset/interface.c
38279+++ b/drivers/isdn/gigaset/interface.c
38280@@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
38281 }
38282 tty->driver_data = cs;
38283
38284- ++cs->port.count;
38285+ atomic_inc(&cs->port.count);
38286
38287- if (cs->port.count == 1) {
38288+ if (atomic_read(&cs->port.count) == 1) {
38289 tty_port_tty_set(&cs->port, tty);
38290 tty->low_latency = 1;
38291 }
38292@@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
38293
38294 if (!cs->connected)
38295 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
38296- else if (!cs->port.count)
38297+ else if (!atomic_read(&cs->port.count))
38298 dev_warn(cs->dev, "%s: device not opened\n", __func__);
38299- else if (!--cs->port.count)
38300+ else if (!atomic_dec_return(&cs->port.count))
38301 tty_port_tty_set(&cs->port, NULL);
38302
38303 mutex_unlock(&cs->mutex);
38304diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
38305index 821f7ac..28d4030 100644
38306--- a/drivers/isdn/hardware/avm/b1.c
38307+++ b/drivers/isdn/hardware/avm/b1.c
38308@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
38309 }
38310 if (left) {
38311 if (t4file->user) {
38312- if (copy_from_user(buf, dp, left))
38313+ if (left > sizeof buf || copy_from_user(buf, dp, left))
38314 return -EFAULT;
38315 } else {
38316 memcpy(buf, dp, left);
38317@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
38318 }
38319 if (left) {
38320 if (config->user) {
38321- if (copy_from_user(buf, dp, left))
38322+ if (left > sizeof buf || copy_from_user(buf, dp, left))
38323 return -EFAULT;
38324 } else {
38325 memcpy(buf, dp, left);
38326diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
38327index e09dc8a..15e2efb 100644
38328--- a/drivers/isdn/i4l/isdn_tty.c
38329+++ b/drivers/isdn/i4l/isdn_tty.c
38330@@ -1513,9 +1513,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
38331
38332 #ifdef ISDN_DEBUG_MODEM_OPEN
38333 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
38334- port->count);
38335+ atomic_read(&port->count));
38336 #endif
38337- port->count++;
38338+ atomic_inc(&port->count);
38339 port->tty = tty;
38340 /*
38341 * Start up serial port
38342@@ -1559,7 +1559,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
38343 #endif
38344 return;
38345 }
38346- if ((tty->count == 1) && (port->count != 1)) {
38347+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
38348 /*
38349 * Uh, oh. tty->count is 1, which means that the tty
38350 * structure will be freed. Info->count should always
38351@@ -1568,15 +1568,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
38352 * serial port won't be shutdown.
38353 */
38354 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
38355- "info->count is %d\n", port->count);
38356- port->count = 1;
38357+ "info->count is %d\n", atomic_read(&port->count));
38358+ atomic_set(&port->count, 1);
38359 }
38360- if (--port->count < 0) {
38361+ if (atomic_dec_return(&port->count) < 0) {
38362 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
38363- info->line, port->count);
38364- port->count = 0;
38365+ info->line, atomic_read(&port->count));
38366+ atomic_set(&port->count, 0);
38367 }
38368- if (port->count) {
38369+ if (atomic_read(&port->count)) {
38370 #ifdef ISDN_DEBUG_MODEM_OPEN
38371 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
38372 #endif
38373@@ -1630,7 +1630,7 @@ isdn_tty_hangup(struct tty_struct *tty)
38374 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
38375 return;
38376 isdn_tty_shutdown(info);
38377- port->count = 0;
38378+ atomic_set(&port->count, 0);
38379 port->flags &= ~ASYNC_NORMAL_ACTIVE;
38380 port->tty = NULL;
38381 wake_up_interruptible(&port->open_wait);
38382@@ -1975,7 +1975,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
38383 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
38384 modem_info *info = &dev->mdm.info[i];
38385
38386- if (info->port.count == 0)
38387+ if (atomic_read(&info->port.count) == 0)
38388 continue;
38389 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
38390 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
38391diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
38392index e74df7c..03a03ba 100644
38393--- a/drivers/isdn/icn/icn.c
38394+++ b/drivers/isdn/icn/icn.c
38395@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
38396 if (count > len)
38397 count = len;
38398 if (user) {
38399- if (copy_from_user(msg, buf, count))
38400+ if (count > sizeof msg || copy_from_user(msg, buf, count))
38401 return -EFAULT;
38402 } else
38403 memcpy(msg, buf, count);
38404diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
38405index 6a8405d..0bd1c7e 100644
38406--- a/drivers/leds/leds-clevo-mail.c
38407+++ b/drivers/leds/leds-clevo-mail.c
38408@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
38409 * detected as working, but in reality it is not) as low as
38410 * possible.
38411 */
38412-static struct dmi_system_id __initdata clevo_mail_led_dmi_table[] = {
38413+static const struct dmi_system_id __initconst clevo_mail_led_dmi_table[] = {
38414 {
38415 .callback = clevo_mail_led_dmi_callback,
38416 .ident = "Clevo D410J",
38417diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
38418index ec9b287..65c9bf4 100644
38419--- a/drivers/leds/leds-ss4200.c
38420+++ b/drivers/leds/leds-ss4200.c
38421@@ -92,7 +92,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
38422 * detected as working, but in reality it is not) as low as
38423 * possible.
38424 */
38425-static struct dmi_system_id __initdata nas_led_whitelist[] = {
38426+static const struct dmi_system_id __initconst nas_led_whitelist[] = {
38427 {
38428 .callback = ss4200_led_dmi_callback,
38429 .ident = "Intel SS4200-E",
38430diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
38431index a5ebc00..982886f 100644
38432--- a/drivers/lguest/core.c
38433+++ b/drivers/lguest/core.c
38434@@ -92,9 +92,17 @@ static __init int map_switcher(void)
38435 * it's worked so far. The end address needs +1 because __get_vm_area
38436 * allocates an extra guard page, so we need space for that.
38437 */
38438+
38439+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
38440+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
38441+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
38442+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
38443+#else
38444 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
38445 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
38446 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
38447+#endif
38448+
38449 if (!switcher_vma) {
38450 err = -ENOMEM;
38451 printk("lguest: could not map switcher pages high\n");
38452@@ -119,7 +127,7 @@ static __init int map_switcher(void)
38453 * Now the Switcher is mapped at the right address, we can't fail!
38454 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
38455 */
38456- memcpy(switcher_vma->addr, start_switcher_text,
38457+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
38458 end_switcher_text - start_switcher_text);
38459
38460 printk(KERN_INFO "lguest: mapped switcher at %p\n",
38461diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
38462index 3b62be16..e33134a 100644
38463--- a/drivers/lguest/page_tables.c
38464+++ b/drivers/lguest/page_tables.c
38465@@ -532,7 +532,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
38466 /*:*/
38467
38468 #ifdef CONFIG_X86_PAE
38469-static void release_pmd(pmd_t *spmd)
38470+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
38471 {
38472 /* If the entry's not present, there's nothing to release. */
38473 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
38474diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
38475index 4af12e1..0e89afe 100644
38476--- a/drivers/lguest/x86/core.c
38477+++ b/drivers/lguest/x86/core.c
38478@@ -59,7 +59,7 @@ static struct {
38479 /* Offset from where switcher.S was compiled to where we've copied it */
38480 static unsigned long switcher_offset(void)
38481 {
38482- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
38483+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
38484 }
38485
38486 /* This cpu's struct lguest_pages. */
38487@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
38488 * These copies are pretty cheap, so we do them unconditionally: */
38489 /* Save the current Host top-level page directory.
38490 */
38491+
38492+#ifdef CONFIG_PAX_PER_CPU_PGD
38493+ pages->state.host_cr3 = read_cr3();
38494+#else
38495 pages->state.host_cr3 = __pa(current->mm->pgd);
38496+#endif
38497+
38498 /*
38499 * Set up the Guest's page tables to see this CPU's pages (and no
38500 * other CPU's pages).
38501@@ -476,7 +482,7 @@ void __init lguest_arch_host_init(void)
38502 * compiled-in switcher code and the high-mapped copy we just made.
38503 */
38504 for (i = 0; i < IDT_ENTRIES; i++)
38505- default_idt_entries[i] += switcher_offset();
38506+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
38507
38508 /*
38509 * Set up the Switcher's per-cpu areas.
38510@@ -559,7 +565,7 @@ void __init lguest_arch_host_init(void)
38511 * it will be undisturbed when we switch. To change %cs and jump we
38512 * need this structure to feed to Intel's "lcall" instruction.
38513 */
38514- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
38515+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
38516 lguest_entry.segment = LGUEST_CS;
38517
38518 /*
38519diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
38520index 40634b0..4f5855e 100644
38521--- a/drivers/lguest/x86/switcher_32.S
38522+++ b/drivers/lguest/x86/switcher_32.S
38523@@ -87,6 +87,7 @@
38524 #include <asm/page.h>
38525 #include <asm/segment.h>
38526 #include <asm/lguest.h>
38527+#include <asm/processor-flags.h>
38528
38529 // We mark the start of the code to copy
38530 // It's placed in .text tho it's never run here
38531@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
38532 // Changes type when we load it: damn Intel!
38533 // For after we switch over our page tables
38534 // That entry will be read-only: we'd crash.
38535+
38536+#ifdef CONFIG_PAX_KERNEXEC
38537+ mov %cr0, %edx
38538+ xor $X86_CR0_WP, %edx
38539+ mov %edx, %cr0
38540+#endif
38541+
38542 movl $(GDT_ENTRY_TSS*8), %edx
38543 ltr %dx
38544
38545@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
38546 // Let's clear it again for our return.
38547 // The GDT descriptor of the Host
38548 // Points to the table after two "size" bytes
38549- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
38550+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
38551 // Clear "used" from type field (byte 5, bit 2)
38552- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
38553+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
38554+
38555+#ifdef CONFIG_PAX_KERNEXEC
38556+ mov %cr0, %eax
38557+ xor $X86_CR0_WP, %eax
38558+ mov %eax, %cr0
38559+#endif
38560
38561 // Once our page table's switched, the Guest is live!
38562 // The Host fades as we run this final step.
38563@@ -295,13 +309,12 @@ deliver_to_host:
38564 // I consulted gcc, and it gave
38565 // These instructions, which I gladly credit:
38566 leal (%edx,%ebx,8), %eax
38567- movzwl (%eax),%edx
38568- movl 4(%eax), %eax
38569- xorw %ax, %ax
38570- orl %eax, %edx
38571+ movl 4(%eax), %edx
38572+ movw (%eax), %dx
38573 // Now the address of the handler's in %edx
38574 // We call it now: its "iret" drops us home.
38575- jmp *%edx
38576+ ljmp $__KERNEL_CS, $1f
38577+1: jmp *%edx
38578
38579 // Every interrupt can come to us here
38580 // But we must truly tell each apart.
38581diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
38582index 7155945..4bcc562 100644
38583--- a/drivers/md/bitmap.c
38584+++ b/drivers/md/bitmap.c
38585@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
38586 chunk_kb ? "KB" : "B");
38587 if (bitmap->storage.file) {
38588 seq_printf(seq, ", file: ");
38589- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
38590+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
38591 }
38592
38593 seq_printf(seq, "\n");
38594diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
38595index eee353d..74504c4 100644
38596--- a/drivers/md/dm-ioctl.c
38597+++ b/drivers/md/dm-ioctl.c
38598@@ -1632,7 +1632,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
38599 cmd == DM_LIST_VERSIONS_CMD)
38600 return 0;
38601
38602- if ((cmd == DM_DEV_CREATE_CMD)) {
38603+ if (cmd == DM_DEV_CREATE_CMD) {
38604 if (!*param->name) {
38605 DMWARN("name not supplied when creating device");
38606 return -EINVAL;
38607diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
38608index 7f24190..0e18099 100644
38609--- a/drivers/md/dm-raid1.c
38610+++ b/drivers/md/dm-raid1.c
38611@@ -40,7 +40,7 @@ enum dm_raid1_error {
38612
38613 struct mirror {
38614 struct mirror_set *ms;
38615- atomic_t error_count;
38616+ atomic_unchecked_t error_count;
38617 unsigned long error_type;
38618 struct dm_dev *dev;
38619 sector_t offset;
38620@@ -183,7 +183,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
38621 struct mirror *m;
38622
38623 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
38624- if (!atomic_read(&m->error_count))
38625+ if (!atomic_read_unchecked(&m->error_count))
38626 return m;
38627
38628 return NULL;
38629@@ -215,7 +215,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
38630 * simple way to tell if a device has encountered
38631 * errors.
38632 */
38633- atomic_inc(&m->error_count);
38634+ atomic_inc_unchecked(&m->error_count);
38635
38636 if (test_and_set_bit(error_type, &m->error_type))
38637 return;
38638@@ -406,7 +406,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
38639 struct mirror *m = get_default_mirror(ms);
38640
38641 do {
38642- if (likely(!atomic_read(&m->error_count)))
38643+ if (likely(!atomic_read_unchecked(&m->error_count)))
38644 return m;
38645
38646 if (m-- == ms->mirror)
38647@@ -420,7 +420,7 @@ static int default_ok(struct mirror *m)
38648 {
38649 struct mirror *default_mirror = get_default_mirror(m->ms);
38650
38651- return !atomic_read(&default_mirror->error_count);
38652+ return !atomic_read_unchecked(&default_mirror->error_count);
38653 }
38654
38655 static int mirror_available(struct mirror_set *ms, struct bio *bio)
38656@@ -557,7 +557,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
38657 */
38658 if (likely(region_in_sync(ms, region, 1)))
38659 m = choose_mirror(ms, bio->bi_sector);
38660- else if (m && atomic_read(&m->error_count))
38661+ else if (m && atomic_read_unchecked(&m->error_count))
38662 m = NULL;
38663
38664 if (likely(m))
38665@@ -924,7 +924,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
38666 }
38667
38668 ms->mirror[mirror].ms = ms;
38669- atomic_set(&(ms->mirror[mirror].error_count), 0);
38670+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
38671 ms->mirror[mirror].error_type = 0;
38672 ms->mirror[mirror].offset = offset;
38673
38674@@ -1337,7 +1337,7 @@ static void mirror_resume(struct dm_target *ti)
38675 */
38676 static char device_status_char(struct mirror *m)
38677 {
38678- if (!atomic_read(&(m->error_count)))
38679+ if (!atomic_read_unchecked(&(m->error_count)))
38680 return 'A';
38681
38682 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
38683diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
38684index aaecefa..23b3026 100644
38685--- a/drivers/md/dm-stripe.c
38686+++ b/drivers/md/dm-stripe.c
38687@@ -20,7 +20,7 @@ struct stripe {
38688 struct dm_dev *dev;
38689 sector_t physical_start;
38690
38691- atomic_t error_count;
38692+ atomic_unchecked_t error_count;
38693 };
38694
38695 struct stripe_c {
38696@@ -184,7 +184,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
38697 kfree(sc);
38698 return r;
38699 }
38700- atomic_set(&(sc->stripe[i].error_count), 0);
38701+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
38702 }
38703
38704 ti->private = sc;
38705@@ -325,7 +325,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
38706 DMEMIT("%d ", sc->stripes);
38707 for (i = 0; i < sc->stripes; i++) {
38708 DMEMIT("%s ", sc->stripe[i].dev->name);
38709- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
38710+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
38711 'D' : 'A';
38712 }
38713 buffer[i] = '\0';
38714@@ -370,8 +370,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
38715 */
38716 for (i = 0; i < sc->stripes; i++)
38717 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
38718- atomic_inc(&(sc->stripe[i].error_count));
38719- if (atomic_read(&(sc->stripe[i].error_count)) <
38720+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
38721+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
38722 DM_IO_ERROR_THRESHOLD)
38723 schedule_work(&sc->trigger_event);
38724 }
38725diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
38726index daf25d0..d74f49f 100644
38727--- a/drivers/md/dm-table.c
38728+++ b/drivers/md/dm-table.c
38729@@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
38730 if (!dev_size)
38731 return 0;
38732
38733- if ((start >= dev_size) || (start + len > dev_size)) {
38734+ if ((start >= dev_size) || (len > dev_size - start)) {
38735 DMWARN("%s: %s too small for target: "
38736 "start=%llu, len=%llu, dev_size=%llu",
38737 dm_device_name(ti->table->md), bdevname(bdev, b),
38738diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
38739index 4d6e853..a234157 100644
38740--- a/drivers/md/dm-thin-metadata.c
38741+++ b/drivers/md/dm-thin-metadata.c
38742@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
38743 {
38744 pmd->info.tm = pmd->tm;
38745 pmd->info.levels = 2;
38746- pmd->info.value_type.context = pmd->data_sm;
38747+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
38748 pmd->info.value_type.size = sizeof(__le64);
38749 pmd->info.value_type.inc = data_block_inc;
38750 pmd->info.value_type.dec = data_block_dec;
38751@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
38752
38753 pmd->bl_info.tm = pmd->tm;
38754 pmd->bl_info.levels = 1;
38755- pmd->bl_info.value_type.context = pmd->data_sm;
38756+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
38757 pmd->bl_info.value_type.size = sizeof(__le64);
38758 pmd->bl_info.value_type.inc = data_block_inc;
38759 pmd->bl_info.value_type.dec = data_block_dec;
38760diff --git a/drivers/md/dm.c b/drivers/md/dm.c
38761index 0d8f086..f5a91d5 100644
38762--- a/drivers/md/dm.c
38763+++ b/drivers/md/dm.c
38764@@ -170,9 +170,9 @@ struct mapped_device {
38765 /*
38766 * Event handling.
38767 */
38768- atomic_t event_nr;
38769+ atomic_unchecked_t event_nr;
38770 wait_queue_head_t eventq;
38771- atomic_t uevent_seq;
38772+ atomic_unchecked_t uevent_seq;
38773 struct list_head uevent_list;
38774 spinlock_t uevent_lock; /* Protect access to uevent_list */
38775
38776@@ -1872,8 +1872,8 @@ static struct mapped_device *alloc_dev(int minor)
38777 rwlock_init(&md->map_lock);
38778 atomic_set(&md->holders, 1);
38779 atomic_set(&md->open_count, 0);
38780- atomic_set(&md->event_nr, 0);
38781- atomic_set(&md->uevent_seq, 0);
38782+ atomic_set_unchecked(&md->event_nr, 0);
38783+ atomic_set_unchecked(&md->uevent_seq, 0);
38784 INIT_LIST_HEAD(&md->uevent_list);
38785 spin_lock_init(&md->uevent_lock);
38786
38787@@ -2026,7 +2026,7 @@ static void event_callback(void *context)
38788
38789 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
38790
38791- atomic_inc(&md->event_nr);
38792+ atomic_inc_unchecked(&md->event_nr);
38793 wake_up(&md->eventq);
38794 }
38795
38796@@ -2683,18 +2683,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
38797
38798 uint32_t dm_next_uevent_seq(struct mapped_device *md)
38799 {
38800- return atomic_add_return(1, &md->uevent_seq);
38801+ return atomic_add_return_unchecked(1, &md->uevent_seq);
38802 }
38803
38804 uint32_t dm_get_event_nr(struct mapped_device *md)
38805 {
38806- return atomic_read(&md->event_nr);
38807+ return atomic_read_unchecked(&md->event_nr);
38808 }
38809
38810 int dm_wait_event(struct mapped_device *md, int event_nr)
38811 {
38812 return wait_event_interruptible(md->eventq,
38813- (event_nr != atomic_read(&md->event_nr)));
38814+ (event_nr != atomic_read_unchecked(&md->event_nr)));
38815 }
38816
38817 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
38818diff --git a/drivers/md/md.c b/drivers/md/md.c
38819index f363135..9b38815 100644
38820--- a/drivers/md/md.c
38821+++ b/drivers/md/md.c
38822@@ -240,10 +240,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
38823 * start build, activate spare
38824 */
38825 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
38826-static atomic_t md_event_count;
38827+static atomic_unchecked_t md_event_count;
38828 void md_new_event(struct mddev *mddev)
38829 {
38830- atomic_inc(&md_event_count);
38831+ atomic_inc_unchecked(&md_event_count);
38832 wake_up(&md_event_waiters);
38833 }
38834 EXPORT_SYMBOL_GPL(md_new_event);
38835@@ -253,7 +253,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
38836 */
38837 static void md_new_event_inintr(struct mddev *mddev)
38838 {
38839- atomic_inc(&md_event_count);
38840+ atomic_inc_unchecked(&md_event_count);
38841 wake_up(&md_event_waiters);
38842 }
38843
38844@@ -1507,7 +1507,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
38845 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
38846 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
38847 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
38848- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
38849+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
38850
38851 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
38852 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
38853@@ -1751,7 +1751,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
38854 else
38855 sb->resync_offset = cpu_to_le64(0);
38856
38857- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
38858+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
38859
38860 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
38861 sb->size = cpu_to_le64(mddev->dev_sectors);
38862@@ -2751,7 +2751,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
38863 static ssize_t
38864 errors_show(struct md_rdev *rdev, char *page)
38865 {
38866- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
38867+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
38868 }
38869
38870 static ssize_t
38871@@ -2760,7 +2760,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
38872 char *e;
38873 unsigned long n = simple_strtoul(buf, &e, 10);
38874 if (*buf && (*e == 0 || *e == '\n')) {
38875- atomic_set(&rdev->corrected_errors, n);
38876+ atomic_set_unchecked(&rdev->corrected_errors, n);
38877 return len;
38878 }
38879 return -EINVAL;
38880@@ -3210,8 +3210,8 @@ int md_rdev_init(struct md_rdev *rdev)
38881 rdev->sb_loaded = 0;
38882 rdev->bb_page = NULL;
38883 atomic_set(&rdev->nr_pending, 0);
38884- atomic_set(&rdev->read_errors, 0);
38885- atomic_set(&rdev->corrected_errors, 0);
38886+ atomic_set_unchecked(&rdev->read_errors, 0);
38887+ atomic_set_unchecked(&rdev->corrected_errors, 0);
38888
38889 INIT_LIST_HEAD(&rdev->same_set);
38890 init_waitqueue_head(&rdev->blocked_wait);
38891@@ -6987,7 +6987,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
38892
38893 spin_unlock(&pers_lock);
38894 seq_printf(seq, "\n");
38895- seq->poll_event = atomic_read(&md_event_count);
38896+ seq->poll_event = atomic_read_unchecked(&md_event_count);
38897 return 0;
38898 }
38899 if (v == (void*)2) {
38900@@ -7090,7 +7090,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
38901 return error;
38902
38903 seq = file->private_data;
38904- seq->poll_event = atomic_read(&md_event_count);
38905+ seq->poll_event = atomic_read_unchecked(&md_event_count);
38906 return error;
38907 }
38908
38909@@ -7104,7 +7104,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
38910 /* always allow read */
38911 mask = POLLIN | POLLRDNORM;
38912
38913- if (seq->poll_event != atomic_read(&md_event_count))
38914+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
38915 mask |= POLLERR | POLLPRI;
38916 return mask;
38917 }
38918@@ -7148,7 +7148,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
38919 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
38920 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
38921 (int)part_stat_read(&disk->part0, sectors[1]) -
38922- atomic_read(&disk->sync_io);
38923+ atomic_read_unchecked(&disk->sync_io);
38924 /* sync IO will cause sync_io to increase before the disk_stats
38925 * as sync_io is counted when a request starts, and
38926 * disk_stats is counted when it completes.
38927diff --git a/drivers/md/md.h b/drivers/md/md.h
38928index eca59c3..7c42285 100644
38929--- a/drivers/md/md.h
38930+++ b/drivers/md/md.h
38931@@ -94,13 +94,13 @@ struct md_rdev {
38932 * only maintained for arrays that
38933 * support hot removal
38934 */
38935- atomic_t read_errors; /* number of consecutive read errors that
38936+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
38937 * we have tried to ignore.
38938 */
38939 struct timespec last_read_error; /* monotonic time since our
38940 * last read error
38941 */
38942- atomic_t corrected_errors; /* number of corrected read errors,
38943+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
38944 * for reporting to userspace and storing
38945 * in superblock.
38946 */
38947@@ -434,7 +434,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
38948
38949 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
38950 {
38951- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
38952+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
38953 }
38954
38955 struct md_personality
38956diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
38957index 1cbfc6b..56e1dbb 100644
38958--- a/drivers/md/persistent-data/dm-space-map.h
38959+++ b/drivers/md/persistent-data/dm-space-map.h
38960@@ -60,6 +60,7 @@ struct dm_space_map {
38961 int (*root_size)(struct dm_space_map *sm, size_t *result);
38962 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
38963 };
38964+typedef struct dm_space_map __no_const dm_space_map_no_const;
38965
38966 /*----------------------------------------------------------------*/
38967
38968diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
38969index 75b1f89..00ba344 100644
38970--- a/drivers/md/raid1.c
38971+++ b/drivers/md/raid1.c
38972@@ -1819,7 +1819,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
38973 if (r1_sync_page_io(rdev, sect, s,
38974 bio->bi_io_vec[idx].bv_page,
38975 READ) != 0)
38976- atomic_add(s, &rdev->corrected_errors);
38977+ atomic_add_unchecked(s, &rdev->corrected_errors);
38978 }
38979 sectors -= s;
38980 sect += s;
38981@@ -2041,7 +2041,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
38982 test_bit(In_sync, &rdev->flags)) {
38983 if (r1_sync_page_io(rdev, sect, s,
38984 conf->tmppage, READ)) {
38985- atomic_add(s, &rdev->corrected_errors);
38986+ atomic_add_unchecked(s, &rdev->corrected_errors);
38987 printk(KERN_INFO
38988 "md/raid1:%s: read error corrected "
38989 "(%d sectors at %llu on %s)\n",
38990diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
38991index 8d925dc..11d674f 100644
38992--- a/drivers/md/raid10.c
38993+++ b/drivers/md/raid10.c
38994@@ -1878,7 +1878,7 @@ static void end_sync_read(struct bio *bio, int error)
38995 /* The write handler will notice the lack of
38996 * R10BIO_Uptodate and record any errors etc
38997 */
38998- atomic_add(r10_bio->sectors,
38999+ atomic_add_unchecked(r10_bio->sectors,
39000 &conf->mirrors[d].rdev->corrected_errors);
39001
39002 /* for reconstruct, we always reschedule after a read.
39003@@ -2227,7 +2227,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
39004 {
39005 struct timespec cur_time_mon;
39006 unsigned long hours_since_last;
39007- unsigned int read_errors = atomic_read(&rdev->read_errors);
39008+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
39009
39010 ktime_get_ts(&cur_time_mon);
39011
39012@@ -2249,9 +2249,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
39013 * overflowing the shift of read_errors by hours_since_last.
39014 */
39015 if (hours_since_last >= 8 * sizeof(read_errors))
39016- atomic_set(&rdev->read_errors, 0);
39017+ atomic_set_unchecked(&rdev->read_errors, 0);
39018 else
39019- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
39020+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
39021 }
39022
39023 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
39024@@ -2305,8 +2305,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
39025 return;
39026
39027 check_decay_read_errors(mddev, rdev);
39028- atomic_inc(&rdev->read_errors);
39029- if (atomic_read(&rdev->read_errors) > max_read_errors) {
39030+ atomic_inc_unchecked(&rdev->read_errors);
39031+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
39032 char b[BDEVNAME_SIZE];
39033 bdevname(rdev->bdev, b);
39034
39035@@ -2314,7 +2314,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
39036 "md/raid10:%s: %s: Raid device exceeded "
39037 "read_error threshold [cur %d:max %d]\n",
39038 mdname(mddev), b,
39039- atomic_read(&rdev->read_errors), max_read_errors);
39040+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
39041 printk(KERN_NOTICE
39042 "md/raid10:%s: %s: Failing raid device\n",
39043 mdname(mddev), b);
39044@@ -2469,7 +2469,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
39045 sect +
39046 choose_data_offset(r10_bio, rdev)),
39047 bdevname(rdev->bdev, b));
39048- atomic_add(s, &rdev->corrected_errors);
39049+ atomic_add_unchecked(s, &rdev->corrected_errors);
39050 }
39051
39052 rdev_dec_pending(rdev, mddev);
39053diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
39054index 94ce78e..df99e24 100644
39055--- a/drivers/md/raid5.c
39056+++ b/drivers/md/raid5.c
39057@@ -1800,21 +1800,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
39058 mdname(conf->mddev), STRIPE_SECTORS,
39059 (unsigned long long)s,
39060 bdevname(rdev->bdev, b));
39061- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
39062+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
39063 clear_bit(R5_ReadError, &sh->dev[i].flags);
39064 clear_bit(R5_ReWrite, &sh->dev[i].flags);
39065 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
39066 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
39067
39068- if (atomic_read(&rdev->read_errors))
39069- atomic_set(&rdev->read_errors, 0);
39070+ if (atomic_read_unchecked(&rdev->read_errors))
39071+ atomic_set_unchecked(&rdev->read_errors, 0);
39072 } else {
39073 const char *bdn = bdevname(rdev->bdev, b);
39074 int retry = 0;
39075 int set_bad = 0;
39076
39077 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
39078- atomic_inc(&rdev->read_errors);
39079+ atomic_inc_unchecked(&rdev->read_errors);
39080 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
39081 printk_ratelimited(
39082 KERN_WARNING
39083@@ -1842,7 +1842,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
39084 mdname(conf->mddev),
39085 (unsigned long long)s,
39086 bdn);
39087- } else if (atomic_read(&rdev->read_errors)
39088+ } else if (atomic_read_unchecked(&rdev->read_errors)
39089 > conf->max_nr_stripes)
39090 printk(KERN_WARNING
39091 "md/raid:%s: Too many read errors, failing device %s.\n",
39092diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
39093index d33101a..6b13069 100644
39094--- a/drivers/media/dvb-core/dvbdev.c
39095+++ b/drivers/media/dvb-core/dvbdev.c
39096@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
39097 const struct dvb_device *template, void *priv, int type)
39098 {
39099 struct dvb_device *dvbdev;
39100- struct file_operations *dvbdevfops;
39101+ file_operations_no_const *dvbdevfops;
39102 struct device *clsdev;
39103 int minor;
39104 int id;
39105diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
39106index 404f63a..4796533 100644
39107--- a/drivers/media/dvb-frontends/dib3000.h
39108+++ b/drivers/media/dvb-frontends/dib3000.h
39109@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
39110 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
39111 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
39112 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
39113-};
39114+} __no_const;
39115
39116 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
39117 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
39118diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
39119index bc78354..42c9459 100644
39120--- a/drivers/media/pci/cx88/cx88-video.c
39121+++ b/drivers/media/pci/cx88/cx88-video.c
39122@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
39123
39124 /* ------------------------------------------------------------------ */
39125
39126-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
39127-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
39128-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
39129+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
39130+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
39131+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
39132
39133 module_param_array(video_nr, int, NULL, 0444);
39134 module_param_array(vbi_nr, int, NULL, 0444);
39135diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
39136index 8e9a668..78d6310 100644
39137--- a/drivers/media/platform/omap/omap_vout.c
39138+++ b/drivers/media/platform/omap/omap_vout.c
39139@@ -63,7 +63,6 @@ enum omap_vout_channels {
39140 OMAP_VIDEO2,
39141 };
39142
39143-static struct videobuf_queue_ops video_vbq_ops;
39144 /* Variables configurable through module params*/
39145 static u32 video1_numbuffers = 3;
39146 static u32 video2_numbuffers = 3;
39147@@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
39148 {
39149 struct videobuf_queue *q;
39150 struct omap_vout_device *vout = NULL;
39151+ static struct videobuf_queue_ops video_vbq_ops = {
39152+ .buf_setup = omap_vout_buffer_setup,
39153+ .buf_prepare = omap_vout_buffer_prepare,
39154+ .buf_release = omap_vout_buffer_release,
39155+ .buf_queue = omap_vout_buffer_queue,
39156+ };
39157
39158 vout = video_drvdata(file);
39159 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
39160@@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
39161 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
39162
39163 q = &vout->vbq;
39164- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
39165- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
39166- video_vbq_ops.buf_release = omap_vout_buffer_release;
39167- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
39168 spin_lock_init(&vout->vbq_lock);
39169
39170 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
39171diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
39172index b671e20..34088b7 100644
39173--- a/drivers/media/platform/s5p-tv/mixer.h
39174+++ b/drivers/media/platform/s5p-tv/mixer.h
39175@@ -155,7 +155,7 @@ struct mxr_layer {
39176 /** layer index (unique identifier) */
39177 int idx;
39178 /** callbacks for layer methods */
39179- struct mxr_layer_ops ops;
39180+ struct mxr_layer_ops *ops;
39181 /** format array */
39182 const struct mxr_format **fmt_array;
39183 /** size of format array */
39184diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
39185index b93a21f..2535195 100644
39186--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
39187+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
39188@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
39189 {
39190 struct mxr_layer *layer;
39191 int ret;
39192- struct mxr_layer_ops ops = {
39193+ static struct mxr_layer_ops ops = {
39194 .release = mxr_graph_layer_release,
39195 .buffer_set = mxr_graph_buffer_set,
39196 .stream_set = mxr_graph_stream_set,
39197diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
39198index 3b1670a..595c939 100644
39199--- a/drivers/media/platform/s5p-tv/mixer_reg.c
39200+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
39201@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
39202 layer->update_buf = next;
39203 }
39204
39205- layer->ops.buffer_set(layer, layer->update_buf);
39206+ layer->ops->buffer_set(layer, layer->update_buf);
39207
39208 if (done && done != layer->shadow_buf)
39209 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
39210diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
39211index 1f3b743..e839271 100644
39212--- a/drivers/media/platform/s5p-tv/mixer_video.c
39213+++ b/drivers/media/platform/s5p-tv/mixer_video.c
39214@@ -208,7 +208,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
39215 layer->geo.src.height = layer->geo.src.full_height;
39216
39217 mxr_geometry_dump(mdev, &layer->geo);
39218- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
39219+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
39220 mxr_geometry_dump(mdev, &layer->geo);
39221 }
39222
39223@@ -226,7 +226,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
39224 layer->geo.dst.full_width = mbus_fmt.width;
39225 layer->geo.dst.full_height = mbus_fmt.height;
39226 layer->geo.dst.field = mbus_fmt.field;
39227- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
39228+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
39229
39230 mxr_geometry_dump(mdev, &layer->geo);
39231 }
39232@@ -332,7 +332,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
39233 /* set source size to highest accepted value */
39234 geo->src.full_width = max(geo->dst.full_width, pix->width);
39235 geo->src.full_height = max(geo->dst.full_height, pix->height);
39236- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
39237+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
39238 mxr_geometry_dump(mdev, &layer->geo);
39239 /* set cropping to total visible screen */
39240 geo->src.width = pix->width;
39241@@ -340,12 +340,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
39242 geo->src.x_offset = 0;
39243 geo->src.y_offset = 0;
39244 /* assure consistency of geometry */
39245- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
39246+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
39247 mxr_geometry_dump(mdev, &layer->geo);
39248 /* set full size to lowest possible value */
39249 geo->src.full_width = 0;
39250 geo->src.full_height = 0;
39251- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
39252+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
39253 mxr_geometry_dump(mdev, &layer->geo);
39254
39255 /* returning results */
39256@@ -472,7 +472,7 @@ static int mxr_s_selection(struct file *file, void *fh,
39257 target->width = s->r.width;
39258 target->height = s->r.height;
39259
39260- layer->ops.fix_geometry(layer, stage, s->flags);
39261+ layer->ops->fix_geometry(layer, stage, s->flags);
39262
39263 /* retrieve update selection rectangle */
39264 res.left = target->x_offset;
39265@@ -937,13 +937,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
39266 mxr_output_get(mdev);
39267
39268 mxr_layer_update_output(layer);
39269- layer->ops.format_set(layer);
39270+ layer->ops->format_set(layer);
39271 /* enabling layer in hardware */
39272 spin_lock_irqsave(&layer->enq_slock, flags);
39273 layer->state = MXR_LAYER_STREAMING;
39274 spin_unlock_irqrestore(&layer->enq_slock, flags);
39275
39276- layer->ops.stream_set(layer, MXR_ENABLE);
39277+ layer->ops->stream_set(layer, MXR_ENABLE);
39278 mxr_streamer_get(mdev);
39279
39280 return 0;
39281@@ -1013,7 +1013,7 @@ static int stop_streaming(struct vb2_queue *vq)
39282 spin_unlock_irqrestore(&layer->enq_slock, flags);
39283
39284 /* disabling layer in hardware */
39285- layer->ops.stream_set(layer, MXR_DISABLE);
39286+ layer->ops->stream_set(layer, MXR_DISABLE);
39287 /* remove one streamer */
39288 mxr_streamer_put(mdev);
39289 /* allow changes in output configuration */
39290@@ -1052,8 +1052,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
39291
39292 void mxr_layer_release(struct mxr_layer *layer)
39293 {
39294- if (layer->ops.release)
39295- layer->ops.release(layer);
39296+ if (layer->ops->release)
39297+ layer->ops->release(layer);
39298 }
39299
39300 void mxr_base_layer_release(struct mxr_layer *layer)
39301@@ -1079,7 +1079,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
39302
39303 layer->mdev = mdev;
39304 layer->idx = idx;
39305- layer->ops = *ops;
39306+ layer->ops = ops;
39307
39308 spin_lock_init(&layer->enq_slock);
39309 INIT_LIST_HEAD(&layer->enq_list);
39310diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
39311index 3d13a63..da31bf1 100644
39312--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
39313+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
39314@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
39315 {
39316 struct mxr_layer *layer;
39317 int ret;
39318- struct mxr_layer_ops ops = {
39319+ static struct mxr_layer_ops ops = {
39320 .release = mxr_vp_layer_release,
39321 .buffer_set = mxr_vp_buffer_set,
39322 .stream_set = mxr_vp_stream_set,
39323diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
39324index 643d80a..56bb96b 100644
39325--- a/drivers/media/radio/radio-cadet.c
39326+++ b/drivers/media/radio/radio-cadet.c
39327@@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
39328 unsigned char readbuf[RDS_BUFFER];
39329 int i = 0;
39330
39331+ if (count > RDS_BUFFER)
39332+ return -EFAULT;
39333 mutex_lock(&dev->lock);
39334 if (dev->rdsstat == 0)
39335 cadet_start_rds(dev);
39336@@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
39337 while (i < count && dev->rdsin != dev->rdsout)
39338 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
39339
39340- if (i && copy_to_user(data, readbuf, i))
39341+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
39342 i = -EFAULT;
39343 unlock:
39344 mutex_unlock(&dev->lock);
39345diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
39346index 3940bb0..fb3952a 100644
39347--- a/drivers/media/usb/dvb-usb/cxusb.c
39348+++ b/drivers/media/usb/dvb-usb/cxusb.c
39349@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
39350
39351 struct dib0700_adapter_state {
39352 int (*set_param_save) (struct dvb_frontend *);
39353-};
39354+} __no_const;
39355
39356 static int dib7070_set_param_override(struct dvb_frontend *fe)
39357 {
39358diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
39359index 9382895..ac8093c 100644
39360--- a/drivers/media/usb/dvb-usb/dw2102.c
39361+++ b/drivers/media/usb/dvb-usb/dw2102.c
39362@@ -95,7 +95,7 @@ struct su3000_state {
39363
39364 struct s6x0_state {
39365 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
39366-};
39367+} __no_const;
39368
39369 /* debug */
39370 static int dvb_usb_dw2102_debug;
39371diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
39372index aa6e7c7..4cd8061 100644
39373--- a/drivers/media/v4l2-core/v4l2-ioctl.c
39374+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
39375@@ -1923,7 +1923,8 @@ struct v4l2_ioctl_info {
39376 struct file *file, void *fh, void *p);
39377 } u;
39378 void (*debug)(const void *arg, bool write_only);
39379-};
39380+} __do_const;
39381+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
39382
39383 /* This control needs a priority check */
39384 #define INFO_FL_PRIO (1 << 0)
39385@@ -2108,7 +2109,7 @@ static long __video_do_ioctl(struct file *file,
39386 struct video_device *vfd = video_devdata(file);
39387 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
39388 bool write_only = false;
39389- struct v4l2_ioctl_info default_info;
39390+ v4l2_ioctl_info_no_const default_info;
39391 const struct v4l2_ioctl_info *info;
39392 void *fh = file->private_data;
39393 struct v4l2_fh *vfh = NULL;
39394diff --git a/drivers/memstick/host/r592.c b/drivers/memstick/host/r592.c
39395index 29b2172..a7c5b31 100644
39396--- a/drivers/memstick/host/r592.c
39397+++ b/drivers/memstick/host/r592.c
39398@@ -454,7 +454,7 @@ static int r592_transfer_fifo_pio(struct r592_device *dev)
39399 /* Executes one TPC (data is read/written from small or large fifo) */
39400 static void r592_execute_tpc(struct r592_device *dev)
39401 {
39402- bool is_write = dev->req->tpc >= MS_TPC_SET_RW_REG_ADRS;
39403+ bool is_write;
39404 int len, error;
39405 u32 status, reg;
39406
39407@@ -463,6 +463,7 @@ static void r592_execute_tpc(struct r592_device *dev)
39408 return;
39409 }
39410
39411+ is_write = dev->req->tpc >= MS_TPC_SET_RW_REG_ADRS;
39412 len = dev->req->long_data ?
39413 dev->req->sg.length : dev->req->data_len;
39414
39415diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
39416index fb69baa..3aeea2e 100644
39417--- a/drivers/message/fusion/mptbase.c
39418+++ b/drivers/message/fusion/mptbase.c
39419@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
39420 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
39421 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
39422
39423+#ifdef CONFIG_GRKERNSEC_HIDESYM
39424+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
39425+#else
39426 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
39427 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
39428+#endif
39429+
39430 /*
39431 * Rounding UP to nearest 4-kB boundary here...
39432 */
39433@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
39434 ioc->facts.GlobalCredits);
39435
39436 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
39437+#ifdef CONFIG_GRKERNSEC_HIDESYM
39438+ NULL, NULL);
39439+#else
39440 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
39441+#endif
39442 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
39443 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
39444 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
39445diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
39446index fa43c39..daeb158 100644
39447--- a/drivers/message/fusion/mptsas.c
39448+++ b/drivers/message/fusion/mptsas.c
39449@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
39450 return 0;
39451 }
39452
39453+static inline void
39454+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
39455+{
39456+ if (phy_info->port_details) {
39457+ phy_info->port_details->rphy = rphy;
39458+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
39459+ ioc->name, rphy));
39460+ }
39461+
39462+ if (rphy) {
39463+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
39464+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
39465+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
39466+ ioc->name, rphy, rphy->dev.release));
39467+ }
39468+}
39469+
39470 /* no mutex */
39471 static void
39472 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
39473@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
39474 return NULL;
39475 }
39476
39477-static inline void
39478-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
39479-{
39480- if (phy_info->port_details) {
39481- phy_info->port_details->rphy = rphy;
39482- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
39483- ioc->name, rphy));
39484- }
39485-
39486- if (rphy) {
39487- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
39488- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
39489- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
39490- ioc->name, rphy, rphy->dev.release));
39491- }
39492-}
39493-
39494 static inline struct sas_port *
39495 mptsas_get_port(struct mptsas_phyinfo *phy_info)
39496 {
39497diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
39498index 164afa7..b6b2e74 100644
39499--- a/drivers/message/fusion/mptscsih.c
39500+++ b/drivers/message/fusion/mptscsih.c
39501@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
39502
39503 h = shost_priv(SChost);
39504
39505- if (h) {
39506- if (h->info_kbuf == NULL)
39507- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
39508- return h->info_kbuf;
39509- h->info_kbuf[0] = '\0';
39510+ if (!h)
39511+ return NULL;
39512
39513- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
39514- h->info_kbuf[size-1] = '\0';
39515- }
39516+ if (h->info_kbuf == NULL)
39517+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
39518+ return h->info_kbuf;
39519+ h->info_kbuf[0] = '\0';
39520+
39521+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
39522+ h->info_kbuf[size-1] = '\0';
39523
39524 return h->info_kbuf;
39525 }
39526diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
39527index 8001aa6..b137580 100644
39528--- a/drivers/message/i2o/i2o_proc.c
39529+++ b/drivers/message/i2o/i2o_proc.c
39530@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
39531 "Array Controller Device"
39532 };
39533
39534-static char *chtostr(char *tmp, u8 *chars, int n)
39535-{
39536- tmp[0] = 0;
39537- return strncat(tmp, (char *)chars, n);
39538-}
39539-
39540 static int i2o_report_query_status(struct seq_file *seq, int block_status,
39541 char *group)
39542 {
39543@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
39544 } *result;
39545
39546 i2o_exec_execute_ddm_table ddm_table;
39547- char tmp[28 + 1];
39548
39549 result = kmalloc(sizeof(*result), GFP_KERNEL);
39550 if (!result)
39551@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
39552
39553 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
39554 seq_printf(seq, "%-#8x", ddm_table.module_id);
39555- seq_printf(seq, "%-29s",
39556- chtostr(tmp, ddm_table.module_name_version, 28));
39557+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
39558 seq_printf(seq, "%9d ", ddm_table.data_size);
39559 seq_printf(seq, "%8d", ddm_table.code_size);
39560
39561@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
39562
39563 i2o_driver_result_table *result;
39564 i2o_driver_store_table *dst;
39565- char tmp[28 + 1];
39566
39567 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
39568 if (result == NULL)
39569@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
39570
39571 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
39572 seq_printf(seq, "%-#8x", dst->module_id);
39573- seq_printf(seq, "%-29s",
39574- chtostr(tmp, dst->module_name_version, 28));
39575- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
39576+ seq_printf(seq, "%-.28s", dst->module_name_version);
39577+ seq_printf(seq, "%-.8s", dst->date);
39578 seq_printf(seq, "%8d ", dst->module_size);
39579 seq_printf(seq, "%8d ", dst->mpb_size);
39580 seq_printf(seq, "0x%04x", dst->module_flags);
39581@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
39582 // == (allow) 512d bytes (max)
39583 static u16 *work16 = (u16 *) work32;
39584 int token;
39585- char tmp[16 + 1];
39586
39587 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
39588
39589@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
39590 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
39591 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
39592 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
39593- seq_printf(seq, "Vendor info : %s\n",
39594- chtostr(tmp, (u8 *) (work32 + 2), 16));
39595- seq_printf(seq, "Product info : %s\n",
39596- chtostr(tmp, (u8 *) (work32 + 6), 16));
39597- seq_printf(seq, "Description : %s\n",
39598- chtostr(tmp, (u8 *) (work32 + 10), 16));
39599- seq_printf(seq, "Product rev. : %s\n",
39600- chtostr(tmp, (u8 *) (work32 + 14), 8));
39601+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
39602+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
39603+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
39604+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
39605
39606 seq_printf(seq, "Serial number : ");
39607 print_serial_number(seq, (u8 *) (work32 + 16),
39608@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
39609 u8 pad[256]; // allow up to 256 byte (max) serial number
39610 } result;
39611
39612- char tmp[24 + 1];
39613-
39614 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
39615
39616 if (token < 0) {
39617@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
39618 }
39619
39620 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
39621- seq_printf(seq, "Module name : %s\n",
39622- chtostr(tmp, result.module_name, 24));
39623- seq_printf(seq, "Module revision : %s\n",
39624- chtostr(tmp, result.module_rev, 8));
39625+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
39626+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
39627
39628 seq_printf(seq, "Serial number : ");
39629 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
39630@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
39631 u8 instance_number[4];
39632 } result;
39633
39634- char tmp[64 + 1];
39635-
39636 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
39637
39638 if (token < 0) {
39639@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
39640 return 0;
39641 }
39642
39643- seq_printf(seq, "Device name : %s\n",
39644- chtostr(tmp, result.device_name, 64));
39645- seq_printf(seq, "Service name : %s\n",
39646- chtostr(tmp, result.service_name, 64));
39647- seq_printf(seq, "Physical name : %s\n",
39648- chtostr(tmp, result.physical_location, 64));
39649- seq_printf(seq, "Instance number : %s\n",
39650- chtostr(tmp, result.instance_number, 4));
39651+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
39652+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
39653+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
39654+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
39655
39656 return 0;
39657 }
39658diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
39659index a8c08f3..155fe3d 100644
39660--- a/drivers/message/i2o/iop.c
39661+++ b/drivers/message/i2o/iop.c
39662@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
39663
39664 spin_lock_irqsave(&c->context_list_lock, flags);
39665
39666- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
39667- atomic_inc(&c->context_list_counter);
39668+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
39669+ atomic_inc_unchecked(&c->context_list_counter);
39670
39671- entry->context = atomic_read(&c->context_list_counter);
39672+ entry->context = atomic_read_unchecked(&c->context_list_counter);
39673
39674 list_add(&entry->list, &c->context_list);
39675
39676@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
39677
39678 #if BITS_PER_LONG == 64
39679 spin_lock_init(&c->context_list_lock);
39680- atomic_set(&c->context_list_counter, 0);
39681+ atomic_set_unchecked(&c->context_list_counter, 0);
39682 INIT_LIST_HEAD(&c->context_list);
39683 #endif
39684
39685diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
39686index 45ece11..8efa218 100644
39687--- a/drivers/mfd/janz-cmodio.c
39688+++ b/drivers/mfd/janz-cmodio.c
39689@@ -13,6 +13,7 @@
39690
39691 #include <linux/kernel.h>
39692 #include <linux/module.h>
39693+#include <linux/slab.h>
39694 #include <linux/init.h>
39695 #include <linux/pci.h>
39696 #include <linux/interrupt.h>
39697diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
39698index a5f9888..1c0ed56 100644
39699--- a/drivers/mfd/twl4030-irq.c
39700+++ b/drivers/mfd/twl4030-irq.c
39701@@ -35,6 +35,7 @@
39702 #include <linux/of.h>
39703 #include <linux/irqdomain.h>
39704 #include <linux/i2c/twl.h>
39705+#include <asm/pgtable.h>
39706
39707 #include "twl-core.h"
39708
39709@@ -728,10 +729,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
39710 * Install an irq handler for each of the SIH modules;
39711 * clone dummy irq_chip since PIH can't *do* anything
39712 */
39713- twl4030_irq_chip = dummy_irq_chip;
39714- twl4030_irq_chip.name = "twl4030";
39715+ pax_open_kernel();
39716+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
39717+ *(const char **)&twl4030_irq_chip.name = "twl4030";
39718
39719- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
39720+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
39721+ pax_close_kernel();
39722
39723 for (i = irq_base; i < irq_end; i++) {
39724 irq_set_chip_and_handler(i, &twl4030_irq_chip,
39725diff --git a/drivers/mfd/twl6030-irq.c b/drivers/mfd/twl6030-irq.c
39726index 277a8db..0e0b754 100644
39727--- a/drivers/mfd/twl6030-irq.c
39728+++ b/drivers/mfd/twl6030-irq.c
39729@@ -387,10 +387,12 @@ int twl6030_init_irq(struct device *dev, int irq_num)
39730 * install an irq handler for each of the modules;
39731 * clone dummy irq_chip since PIH can't *do* anything
39732 */
39733- twl6030_irq_chip = dummy_irq_chip;
39734- twl6030_irq_chip.name = "twl6030";
39735- twl6030_irq_chip.irq_set_type = NULL;
39736- twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
39737+ pax_open_kernel();
39738+ memcpy((void *)&twl6030_irq_chip, &dummy_irq_chip, sizeof twl6030_irq_chip);
39739+ *(const char **)&twl6030_irq_chip.name = "twl6030";
39740+ *(void **)&twl6030_irq_chip.irq_set_type = NULL;
39741+ *(void **)&twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
39742+ pax_close_kernel();
39743
39744 for (i = irq_base; i < irq_end; i++) {
39745 irq_set_chip_and_handler(i, &twl6030_irq_chip,
39746diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
39747index f428d86..274c368 100644
39748--- a/drivers/misc/c2port/core.c
39749+++ b/drivers/misc/c2port/core.c
39750@@ -924,7 +924,9 @@ struct c2port_device *c2port_device_register(char *name,
39751 mutex_init(&c2dev->mutex);
39752
39753 /* Create binary file */
39754- c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
39755+ pax_open_kernel();
39756+ *(size_t *)&c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
39757+ pax_close_kernel();
39758 ret = device_create_bin_file(c2dev->dev, &c2port_bin_attrs);
39759 if (unlikely(ret))
39760 goto error_device_create_bin_file;
39761diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
39762index 3aa9a96..59cf685 100644
39763--- a/drivers/misc/kgdbts.c
39764+++ b/drivers/misc/kgdbts.c
39765@@ -832,7 +832,7 @@ static void run_plant_and_detach_test(int is_early)
39766 char before[BREAK_INSTR_SIZE];
39767 char after[BREAK_INSTR_SIZE];
39768
39769- probe_kernel_read(before, (char *)kgdbts_break_test,
39770+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
39771 BREAK_INSTR_SIZE);
39772 init_simple_test();
39773 ts.tst = plant_and_detach_test;
39774@@ -840,7 +840,7 @@ static void run_plant_and_detach_test(int is_early)
39775 /* Activate test with initial breakpoint */
39776 if (!is_early)
39777 kgdb_breakpoint();
39778- probe_kernel_read(after, (char *)kgdbts_break_test,
39779+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
39780 BREAK_INSTR_SIZE);
39781 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
39782 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
39783diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
39784index 4a87e5c..76bdf5c 100644
39785--- a/drivers/misc/lis3lv02d/lis3lv02d.c
39786+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
39787@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
39788 * the lid is closed. This leads to interrupts as soon as a little move
39789 * is done.
39790 */
39791- atomic_inc(&lis3->count);
39792+ atomic_inc_unchecked(&lis3->count);
39793
39794 wake_up_interruptible(&lis3->misc_wait);
39795 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
39796@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
39797 if (lis3->pm_dev)
39798 pm_runtime_get_sync(lis3->pm_dev);
39799
39800- atomic_set(&lis3->count, 0);
39801+ atomic_set_unchecked(&lis3->count, 0);
39802 return 0;
39803 }
39804
39805@@ -617,7 +617,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
39806 add_wait_queue(&lis3->misc_wait, &wait);
39807 while (true) {
39808 set_current_state(TASK_INTERRUPTIBLE);
39809- data = atomic_xchg(&lis3->count, 0);
39810+ data = atomic_xchg_unchecked(&lis3->count, 0);
39811 if (data)
39812 break;
39813
39814@@ -658,7 +658,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
39815 struct lis3lv02d, miscdev);
39816
39817 poll_wait(file, &lis3->misc_wait, wait);
39818- if (atomic_read(&lis3->count))
39819+ if (atomic_read_unchecked(&lis3->count))
39820 return POLLIN | POLLRDNORM;
39821 return 0;
39822 }
39823diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
39824index c439c82..1f20f57 100644
39825--- a/drivers/misc/lis3lv02d/lis3lv02d.h
39826+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
39827@@ -297,7 +297,7 @@ struct lis3lv02d {
39828 struct input_polled_dev *idev; /* input device */
39829 struct platform_device *pdev; /* platform device */
39830 struct regulator_bulk_data regulators[2];
39831- atomic_t count; /* interrupt count after last read */
39832+ atomic_unchecked_t count; /* interrupt count after last read */
39833 union axis_conversion ac; /* hw -> logical axis */
39834 int mapped_btns[3];
39835
39836diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
39837index 2f30bad..c4c13d0 100644
39838--- a/drivers/misc/sgi-gru/gruhandles.c
39839+++ b/drivers/misc/sgi-gru/gruhandles.c
39840@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
39841 unsigned long nsec;
39842
39843 nsec = CLKS2NSEC(clks);
39844- atomic_long_inc(&mcs_op_statistics[op].count);
39845- atomic_long_add(nsec, &mcs_op_statistics[op].total);
39846+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
39847+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
39848 if (mcs_op_statistics[op].max < nsec)
39849 mcs_op_statistics[op].max = nsec;
39850 }
39851diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
39852index 950dbe9..eeef0f8 100644
39853--- a/drivers/misc/sgi-gru/gruprocfs.c
39854+++ b/drivers/misc/sgi-gru/gruprocfs.c
39855@@ -32,9 +32,9 @@
39856
39857 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
39858
39859-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
39860+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
39861 {
39862- unsigned long val = atomic_long_read(v);
39863+ unsigned long val = atomic_long_read_unchecked(v);
39864
39865 seq_printf(s, "%16lu %s\n", val, id);
39866 }
39867@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
39868
39869 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
39870 for (op = 0; op < mcsop_last; op++) {
39871- count = atomic_long_read(&mcs_op_statistics[op].count);
39872- total = atomic_long_read(&mcs_op_statistics[op].total);
39873+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
39874+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
39875 max = mcs_op_statistics[op].max;
39876 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
39877 count ? total / count : 0, max);
39878diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
39879index 5c3ce24..4915ccb 100644
39880--- a/drivers/misc/sgi-gru/grutables.h
39881+++ b/drivers/misc/sgi-gru/grutables.h
39882@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
39883 * GRU statistics.
39884 */
39885 struct gru_stats_s {
39886- atomic_long_t vdata_alloc;
39887- atomic_long_t vdata_free;
39888- atomic_long_t gts_alloc;
39889- atomic_long_t gts_free;
39890- atomic_long_t gms_alloc;
39891- atomic_long_t gms_free;
39892- atomic_long_t gts_double_allocate;
39893- atomic_long_t assign_context;
39894- atomic_long_t assign_context_failed;
39895- atomic_long_t free_context;
39896- atomic_long_t load_user_context;
39897- atomic_long_t load_kernel_context;
39898- atomic_long_t lock_kernel_context;
39899- atomic_long_t unlock_kernel_context;
39900- atomic_long_t steal_user_context;
39901- atomic_long_t steal_kernel_context;
39902- atomic_long_t steal_context_failed;
39903- atomic_long_t nopfn;
39904- atomic_long_t asid_new;
39905- atomic_long_t asid_next;
39906- atomic_long_t asid_wrap;
39907- atomic_long_t asid_reuse;
39908- atomic_long_t intr;
39909- atomic_long_t intr_cbr;
39910- atomic_long_t intr_tfh;
39911- atomic_long_t intr_spurious;
39912- atomic_long_t intr_mm_lock_failed;
39913- atomic_long_t call_os;
39914- atomic_long_t call_os_wait_queue;
39915- atomic_long_t user_flush_tlb;
39916- atomic_long_t user_unload_context;
39917- atomic_long_t user_exception;
39918- atomic_long_t set_context_option;
39919- atomic_long_t check_context_retarget_intr;
39920- atomic_long_t check_context_unload;
39921- atomic_long_t tlb_dropin;
39922- atomic_long_t tlb_preload_page;
39923- atomic_long_t tlb_dropin_fail_no_asid;
39924- atomic_long_t tlb_dropin_fail_upm;
39925- atomic_long_t tlb_dropin_fail_invalid;
39926- atomic_long_t tlb_dropin_fail_range_active;
39927- atomic_long_t tlb_dropin_fail_idle;
39928- atomic_long_t tlb_dropin_fail_fmm;
39929- atomic_long_t tlb_dropin_fail_no_exception;
39930- atomic_long_t tfh_stale_on_fault;
39931- atomic_long_t mmu_invalidate_range;
39932- atomic_long_t mmu_invalidate_page;
39933- atomic_long_t flush_tlb;
39934- atomic_long_t flush_tlb_gru;
39935- atomic_long_t flush_tlb_gru_tgh;
39936- atomic_long_t flush_tlb_gru_zero_asid;
39937+ atomic_long_unchecked_t vdata_alloc;
39938+ atomic_long_unchecked_t vdata_free;
39939+ atomic_long_unchecked_t gts_alloc;
39940+ atomic_long_unchecked_t gts_free;
39941+ atomic_long_unchecked_t gms_alloc;
39942+ atomic_long_unchecked_t gms_free;
39943+ atomic_long_unchecked_t gts_double_allocate;
39944+ atomic_long_unchecked_t assign_context;
39945+ atomic_long_unchecked_t assign_context_failed;
39946+ atomic_long_unchecked_t free_context;
39947+ atomic_long_unchecked_t load_user_context;
39948+ atomic_long_unchecked_t load_kernel_context;
39949+ atomic_long_unchecked_t lock_kernel_context;
39950+ atomic_long_unchecked_t unlock_kernel_context;
39951+ atomic_long_unchecked_t steal_user_context;
39952+ atomic_long_unchecked_t steal_kernel_context;
39953+ atomic_long_unchecked_t steal_context_failed;
39954+ atomic_long_unchecked_t nopfn;
39955+ atomic_long_unchecked_t asid_new;
39956+ atomic_long_unchecked_t asid_next;
39957+ atomic_long_unchecked_t asid_wrap;
39958+ atomic_long_unchecked_t asid_reuse;
39959+ atomic_long_unchecked_t intr;
39960+ atomic_long_unchecked_t intr_cbr;
39961+ atomic_long_unchecked_t intr_tfh;
39962+ atomic_long_unchecked_t intr_spurious;
39963+ atomic_long_unchecked_t intr_mm_lock_failed;
39964+ atomic_long_unchecked_t call_os;
39965+ atomic_long_unchecked_t call_os_wait_queue;
39966+ atomic_long_unchecked_t user_flush_tlb;
39967+ atomic_long_unchecked_t user_unload_context;
39968+ atomic_long_unchecked_t user_exception;
39969+ atomic_long_unchecked_t set_context_option;
39970+ atomic_long_unchecked_t check_context_retarget_intr;
39971+ atomic_long_unchecked_t check_context_unload;
39972+ atomic_long_unchecked_t tlb_dropin;
39973+ atomic_long_unchecked_t tlb_preload_page;
39974+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
39975+ atomic_long_unchecked_t tlb_dropin_fail_upm;
39976+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
39977+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
39978+ atomic_long_unchecked_t tlb_dropin_fail_idle;
39979+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
39980+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
39981+ atomic_long_unchecked_t tfh_stale_on_fault;
39982+ atomic_long_unchecked_t mmu_invalidate_range;
39983+ atomic_long_unchecked_t mmu_invalidate_page;
39984+ atomic_long_unchecked_t flush_tlb;
39985+ atomic_long_unchecked_t flush_tlb_gru;
39986+ atomic_long_unchecked_t flush_tlb_gru_tgh;
39987+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
39988
39989- atomic_long_t copy_gpa;
39990- atomic_long_t read_gpa;
39991+ atomic_long_unchecked_t copy_gpa;
39992+ atomic_long_unchecked_t read_gpa;
39993
39994- atomic_long_t mesq_receive;
39995- atomic_long_t mesq_receive_none;
39996- atomic_long_t mesq_send;
39997- atomic_long_t mesq_send_failed;
39998- atomic_long_t mesq_noop;
39999- atomic_long_t mesq_send_unexpected_error;
40000- atomic_long_t mesq_send_lb_overflow;
40001- atomic_long_t mesq_send_qlimit_reached;
40002- atomic_long_t mesq_send_amo_nacked;
40003- atomic_long_t mesq_send_put_nacked;
40004- atomic_long_t mesq_page_overflow;
40005- atomic_long_t mesq_qf_locked;
40006- atomic_long_t mesq_qf_noop_not_full;
40007- atomic_long_t mesq_qf_switch_head_failed;
40008- atomic_long_t mesq_qf_unexpected_error;
40009- atomic_long_t mesq_noop_unexpected_error;
40010- atomic_long_t mesq_noop_lb_overflow;
40011- atomic_long_t mesq_noop_qlimit_reached;
40012- atomic_long_t mesq_noop_amo_nacked;
40013- atomic_long_t mesq_noop_put_nacked;
40014- atomic_long_t mesq_noop_page_overflow;
40015+ atomic_long_unchecked_t mesq_receive;
40016+ atomic_long_unchecked_t mesq_receive_none;
40017+ atomic_long_unchecked_t mesq_send;
40018+ atomic_long_unchecked_t mesq_send_failed;
40019+ atomic_long_unchecked_t mesq_noop;
40020+ atomic_long_unchecked_t mesq_send_unexpected_error;
40021+ atomic_long_unchecked_t mesq_send_lb_overflow;
40022+ atomic_long_unchecked_t mesq_send_qlimit_reached;
40023+ atomic_long_unchecked_t mesq_send_amo_nacked;
40024+ atomic_long_unchecked_t mesq_send_put_nacked;
40025+ atomic_long_unchecked_t mesq_page_overflow;
40026+ atomic_long_unchecked_t mesq_qf_locked;
40027+ atomic_long_unchecked_t mesq_qf_noop_not_full;
40028+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
40029+ atomic_long_unchecked_t mesq_qf_unexpected_error;
40030+ atomic_long_unchecked_t mesq_noop_unexpected_error;
40031+ atomic_long_unchecked_t mesq_noop_lb_overflow;
40032+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
40033+ atomic_long_unchecked_t mesq_noop_amo_nacked;
40034+ atomic_long_unchecked_t mesq_noop_put_nacked;
40035+ atomic_long_unchecked_t mesq_noop_page_overflow;
40036
40037 };
40038
40039@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
40040 tghop_invalidate, mcsop_last};
40041
40042 struct mcs_op_statistic {
40043- atomic_long_t count;
40044- atomic_long_t total;
40045+ atomic_long_unchecked_t count;
40046+ atomic_long_unchecked_t total;
40047 unsigned long max;
40048 };
40049
40050@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
40051
40052 #define STAT(id) do { \
40053 if (gru_options & OPT_STATS) \
40054- atomic_long_inc(&gru_stats.id); \
40055+ atomic_long_inc_unchecked(&gru_stats.id); \
40056 } while (0)
40057
40058 #ifdef CONFIG_SGI_GRU_DEBUG
40059diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
40060index c862cd4..0d176fe 100644
40061--- a/drivers/misc/sgi-xp/xp.h
40062+++ b/drivers/misc/sgi-xp/xp.h
40063@@ -288,7 +288,7 @@ struct xpc_interface {
40064 xpc_notify_func, void *);
40065 void (*received) (short, int, void *);
40066 enum xp_retval (*partid_to_nasids) (short, void *);
40067-};
40068+} __no_const;
40069
40070 extern struct xpc_interface xpc_interface;
40071
40072diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
40073index b94d5f7..7f494c5 100644
40074--- a/drivers/misc/sgi-xp/xpc.h
40075+++ b/drivers/misc/sgi-xp/xpc.h
40076@@ -835,6 +835,7 @@ struct xpc_arch_operations {
40077 void (*received_payload) (struct xpc_channel *, void *);
40078 void (*notify_senders_of_disconnect) (struct xpc_channel *);
40079 };
40080+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
40081
40082 /* struct xpc_partition act_state values (for XPC HB) */
40083
40084@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
40085 /* found in xpc_main.c */
40086 extern struct device *xpc_part;
40087 extern struct device *xpc_chan;
40088-extern struct xpc_arch_operations xpc_arch_ops;
40089+extern xpc_arch_operations_no_const xpc_arch_ops;
40090 extern int xpc_disengage_timelimit;
40091 extern int xpc_disengage_timedout;
40092 extern int xpc_activate_IRQ_rcvd;
40093diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
40094index d971817..33bdca5 100644
40095--- a/drivers/misc/sgi-xp/xpc_main.c
40096+++ b/drivers/misc/sgi-xp/xpc_main.c
40097@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
40098 .notifier_call = xpc_system_die,
40099 };
40100
40101-struct xpc_arch_operations xpc_arch_ops;
40102+xpc_arch_operations_no_const xpc_arch_ops;
40103
40104 /*
40105 * Timer function to enforce the timelimit on the partition disengage.
40106@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
40107
40108 if (((die_args->trapnr == X86_TRAP_MF) ||
40109 (die_args->trapnr == X86_TRAP_XF)) &&
40110- !user_mode_vm(die_args->regs))
40111+ !user_mode(die_args->regs))
40112 xpc_die_deactivate();
40113
40114 break;
40115diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
40116index 6d8f701..35b6369 100644
40117--- a/drivers/mmc/core/mmc_ops.c
40118+++ b/drivers/mmc/core/mmc_ops.c
40119@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
40120 void *data_buf;
40121 int is_on_stack;
40122
40123- is_on_stack = object_is_on_stack(buf);
40124+ is_on_stack = object_starts_on_stack(buf);
40125 if (is_on_stack) {
40126 /*
40127 * dma onto stack is unsafe/nonportable, but callers to this
40128diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
40129index 53b8fd9..615b462 100644
40130--- a/drivers/mmc/host/dw_mmc.h
40131+++ b/drivers/mmc/host/dw_mmc.h
40132@@ -205,5 +205,5 @@ struct dw_mci_drv_data {
40133 int (*parse_dt)(struct dw_mci *host);
40134 int (*setup_bus)(struct dw_mci *host,
40135 struct device_node *slot_np, u8 bus_width);
40136-};
40137+} __do_const;
40138 #endif /* _DW_MMC_H_ */
40139diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
40140index 82a8de1..3c56ccb 100644
40141--- a/drivers/mmc/host/sdhci-s3c.c
40142+++ b/drivers/mmc/host/sdhci-s3c.c
40143@@ -721,9 +721,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
40144 * we can use overriding functions instead of default.
40145 */
40146 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
40147- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
40148- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
40149- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
40150+ pax_open_kernel();
40151+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
40152+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
40153+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
40154+ pax_close_kernel();
40155 }
40156
40157 /* It supports additional host capabilities if needed */
40158diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
40159index a4eb8b5..8c0628f 100644
40160--- a/drivers/mtd/devices/doc2000.c
40161+++ b/drivers/mtd/devices/doc2000.c
40162@@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
40163
40164 /* The ECC will not be calculated correctly if less than 512 is written */
40165 /* DBB-
40166- if (len != 0x200 && eccbuf)
40167+ if (len != 0x200)
40168 printk(KERN_WARNING
40169 "ECC needs a full sector write (adr: %lx size %lx)\n",
40170 (long) to, (long) len);
40171diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
40172index 0c8bb6b..6f35deb 100644
40173--- a/drivers/mtd/nand/denali.c
40174+++ b/drivers/mtd/nand/denali.c
40175@@ -24,6 +24,7 @@
40176 #include <linux/slab.h>
40177 #include <linux/mtd/mtd.h>
40178 #include <linux/module.h>
40179+#include <linux/slab.h>
40180
40181 #include "denali.h"
40182
40183diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
40184index 51b9d6a..52af9a7 100644
40185--- a/drivers/mtd/nftlmount.c
40186+++ b/drivers/mtd/nftlmount.c
40187@@ -24,6 +24,7 @@
40188 #include <asm/errno.h>
40189 #include <linux/delay.h>
40190 #include <linux/slab.h>
40191+#include <linux/sched.h>
40192 #include <linux/mtd/mtd.h>
40193 #include <linux/mtd/nand.h>
40194 #include <linux/mtd/nftl.h>
40195diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
40196index 8dd6ba5..419cc1d 100644
40197--- a/drivers/mtd/sm_ftl.c
40198+++ b/drivers/mtd/sm_ftl.c
40199@@ -56,7 +56,7 @@ ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
40200 #define SM_CIS_VENDOR_OFFSET 0x59
40201 struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
40202 {
40203- struct attribute_group *attr_group;
40204+ attribute_group_no_const *attr_group;
40205 struct attribute **attributes;
40206 struct sm_sysfs_attribute *vendor_attribute;
40207
40208diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
40209index 27cdf1f..8c37357 100644
40210--- a/drivers/net/bonding/bond_main.c
40211+++ b/drivers/net/bonding/bond_main.c
40212@@ -4859,7 +4859,7 @@ static unsigned int bond_get_num_tx_queues(void)
40213 return tx_queues;
40214 }
40215
40216-static struct rtnl_link_ops bond_link_ops __read_mostly = {
40217+static struct rtnl_link_ops bond_link_ops = {
40218 .kind = "bond",
40219 .priv_size = sizeof(struct bonding),
40220 .setup = bond_setup,
40221@@ -4975,8 +4975,8 @@ static void __exit bonding_exit(void)
40222
40223 bond_destroy_debugfs();
40224
40225- rtnl_link_unregister(&bond_link_ops);
40226 unregister_pernet_subsys(&bond_net_ops);
40227+ rtnl_link_unregister(&bond_link_ops);
40228
40229 #ifdef CONFIG_NET_POLL_CONTROLLER
40230 /*
40231diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
40232index 70dba5d..11a0919 100644
40233--- a/drivers/net/ethernet/8390/ax88796.c
40234+++ b/drivers/net/ethernet/8390/ax88796.c
40235@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
40236 if (ax->plat->reg_offsets)
40237 ei_local->reg_offset = ax->plat->reg_offsets;
40238 else {
40239+ resource_size_t _mem_size = mem_size;
40240+ do_div(_mem_size, 0x18);
40241 ei_local->reg_offset = ax->reg_offsets;
40242 for (ret = 0; ret < 0x18; ret++)
40243- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
40244+ ax->reg_offsets[ret] = _mem_size * ret;
40245 }
40246
40247 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
40248diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
40249index 0991534..8098e92 100644
40250--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
40251+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
40252@@ -1094,7 +1094,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
40253 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
40254 {
40255 /* RX_MODE controlling object */
40256- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
40257+ bnx2x_init_rx_mode_obj(bp);
40258
40259 /* multicast configuration controlling object */
40260 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
40261diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c
40262index 10bc093..a2fb42a 100644
40263--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c
40264+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c
40265@@ -2136,12 +2136,12 @@ static u8 bnx2x_dcbnl_get_cap(struct net_device *netdev, int capid, u8 *cap)
40266 break;
40267 default:
40268 BNX2X_ERR("Non valid capability ID\n");
40269- rval = -EINVAL;
40270+ rval = 1;
40271 break;
40272 }
40273 } else {
40274 DP(BNX2X_MSG_DCB, "DCB disabled\n");
40275- rval = -EINVAL;
40276+ rval = 1;
40277 }
40278
40279 DP(BNX2X_MSG_DCB, "capid %d:%x\n", capid, *cap);
40280@@ -2167,12 +2167,12 @@ static int bnx2x_dcbnl_get_numtcs(struct net_device *netdev, int tcid, u8 *num)
40281 break;
40282 default:
40283 BNX2X_ERR("Non valid TC-ID\n");
40284- rval = -EINVAL;
40285+ rval = 1;
40286 break;
40287 }
40288 } else {
40289 DP(BNX2X_MSG_DCB, "DCB disabled\n");
40290- rval = -EINVAL;
40291+ rval = 1;
40292 }
40293
40294 return rval;
40295@@ -2185,7 +2185,7 @@ static int bnx2x_dcbnl_set_numtcs(struct net_device *netdev, int tcid, u8 num)
40296 return -EINVAL;
40297 }
40298
40299-static u8 bnx2x_dcbnl_get_pfc_state(struct net_device *netdev)
40300+static u8 bnx2x_dcbnl_get_pfc_state(struct net_device *netdev)
40301 {
40302 struct bnx2x *bp = netdev_priv(netdev);
40303 DP(BNX2X_MSG_DCB, "state = %d\n", bp->dcbx_local_feat.pfc.enabled);
40304@@ -2387,12 +2387,12 @@ static u8 bnx2x_dcbnl_get_featcfg(struct net_device *netdev, int featid,
40305 break;
40306 default:
40307 BNX2X_ERR("Non valid featrue-ID\n");
40308- rval = -EINVAL;
40309+ rval = 1;
40310 break;
40311 }
40312 } else {
40313 DP(BNX2X_MSG_DCB, "DCB disabled\n");
40314- rval = -EINVAL;
40315+ rval = 1;
40316 }
40317
40318 return rval;
40319@@ -2428,12 +2428,12 @@ static u8 bnx2x_dcbnl_set_featcfg(struct net_device *netdev, int featid,
40320 break;
40321 default:
40322 BNX2X_ERR("Non valid featrue-ID\n");
40323- rval = -EINVAL;
40324+ rval = 1;
40325 break;
40326 }
40327 } else {
40328 DP(BNX2X_MSG_DCB, "dcbnl call not valid\n");
40329- rval = -EINVAL;
40330+ rval = 1;
40331 }
40332
40333 return rval;
40334diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
40335index 5523da3..4fcf274 100644
40336--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
40337+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
40338@@ -4767,7 +4767,7 @@ static void bnx2x_after_function_update(struct bnx2x *bp)
40339 q);
40340 }
40341
40342- if (!NO_FCOE(bp)) {
40343+ if (!NO_FCOE(bp) && CNIC_ENABLED(bp)) {
40344 fp = &bp->fp[FCOE_IDX(bp)];
40345 queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
40346
40347@@ -13047,6 +13047,7 @@ static int bnx2x_unregister_cnic(struct net_device *dev)
40348 RCU_INIT_POINTER(bp->cnic_ops, NULL);
40349 mutex_unlock(&bp->cnic_mutex);
40350 synchronize_rcu();
40351+ bp->cnic_enabled = false;
40352 kfree(bp->cnic_kwq);
40353 bp->cnic_kwq = NULL;
40354
40355diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
40356index 09b625e..15b16fe 100644
40357--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
40358+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
40359@@ -2375,15 +2375,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
40360 return rc;
40361 }
40362
40363-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
40364- struct bnx2x_rx_mode_obj *o)
40365+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
40366 {
40367 if (CHIP_IS_E1x(bp)) {
40368- o->wait_comp = bnx2x_empty_rx_mode_wait;
40369- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
40370+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
40371+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
40372 } else {
40373- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
40374- o->config_rx_mode = bnx2x_set_rx_mode_e2;
40375+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
40376+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
40377 }
40378 }
40379
40380diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
40381index adbd91b..58ec94a 100644
40382--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
40383+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
40384@@ -1293,8 +1293,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
40385
40386 /********************* RX MODE ****************/
40387
40388-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
40389- struct bnx2x_rx_mode_obj *o);
40390+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
40391
40392 /**
40393 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
40394diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
40395index d330e81..ce1fb9a 100644
40396--- a/drivers/net/ethernet/broadcom/tg3.h
40397+++ b/drivers/net/ethernet/broadcom/tg3.h
40398@@ -146,6 +146,7 @@
40399 #define CHIPREV_ID_5750_A0 0x4000
40400 #define CHIPREV_ID_5750_A1 0x4001
40401 #define CHIPREV_ID_5750_A3 0x4003
40402+#define CHIPREV_ID_5750_C1 0x4201
40403 #define CHIPREV_ID_5750_C2 0x4202
40404 #define CHIPREV_ID_5752_A0_HW 0x5000
40405 #define CHIPREV_ID_5752_A0 0x6000
40406diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
40407index 8cffcdf..aadf043 100644
40408--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
40409+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
40410@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
40411 */
40412 struct l2t_skb_cb {
40413 arp_failure_handler_func arp_failure_handler;
40414-};
40415+} __no_const;
40416
40417 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
40418
40419diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
40420index 4c83003..2a2a5b9 100644
40421--- a/drivers/net/ethernet/dec/tulip/de4x5.c
40422+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
40423@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
40424 for (i=0; i<ETH_ALEN; i++) {
40425 tmp.addr[i] = dev->dev_addr[i];
40426 }
40427- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
40428+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
40429 break;
40430
40431 case DE4X5_SET_HWADDR: /* Set the hardware address */
40432@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
40433 spin_lock_irqsave(&lp->lock, flags);
40434 memcpy(&statbuf, &lp->pktStats, ioc->len);
40435 spin_unlock_irqrestore(&lp->lock, flags);
40436- if (copy_to_user(ioc->data, &statbuf, ioc->len))
40437+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
40438 return -EFAULT;
40439 break;
40440 }
40441diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
40442index 4d6f3c5..449bc5c 100644
40443--- a/drivers/net/ethernet/emulex/benet/be_main.c
40444+++ b/drivers/net/ethernet/emulex/benet/be_main.c
40445@@ -455,7 +455,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
40446
40447 if (wrapped)
40448 newacc += 65536;
40449- ACCESS_ONCE(*acc) = newacc;
40450+ ACCESS_ONCE_RW(*acc) = newacc;
40451 }
40452
40453 void be_parse_stats(struct be_adapter *adapter)
40454@@ -759,8 +759,9 @@ static struct sk_buff *be_insert_vlan_in_pkt(struct be_adapter *adapter,
40455
40456 if (vlan_tx_tag_present(skb)) {
40457 vlan_tag = be_get_tx_vlan_tag(adapter, skb);
40458- __vlan_put_tag(skb, vlan_tag);
40459- skb->vlan_tci = 0;
40460+ skb = __vlan_put_tag(skb, vlan_tag);
40461+ if (skb)
40462+ skb->vlan_tci = 0;
40463 }
40464
40465 return skb;
40466diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
40467index 74d749e..eefb1bd 100644
40468--- a/drivers/net/ethernet/faraday/ftgmac100.c
40469+++ b/drivers/net/ethernet/faraday/ftgmac100.c
40470@@ -31,6 +31,8 @@
40471 #include <linux/netdevice.h>
40472 #include <linux/phy.h>
40473 #include <linux/platform_device.h>
40474+#include <linux/interrupt.h>
40475+#include <linux/irqreturn.h>
40476 #include <net/ip.h>
40477
40478 #include "ftgmac100.h"
40479diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
40480index b901a01..1ff32ee 100644
40481--- a/drivers/net/ethernet/faraday/ftmac100.c
40482+++ b/drivers/net/ethernet/faraday/ftmac100.c
40483@@ -31,6 +31,8 @@
40484 #include <linux/module.h>
40485 #include <linux/netdevice.h>
40486 #include <linux/platform_device.h>
40487+#include <linux/interrupt.h>
40488+#include <linux/irqreturn.h>
40489
40490 #include "ftmac100.h"
40491
40492diff --git a/drivers/net/ethernet/intel/e100.c b/drivers/net/ethernet/intel/e100.c
40493index a59f077..7925d77 100644
40494--- a/drivers/net/ethernet/intel/e100.c
40495+++ b/drivers/net/ethernet/intel/e100.c
40496@@ -870,7 +870,7 @@ err_unlock:
40497 }
40498
40499 static int e100_exec_cb(struct nic *nic, struct sk_buff *skb,
40500- void (*cb_prepare)(struct nic *, struct cb *, struct sk_buff *))
40501+ int (*cb_prepare)(struct nic *, struct cb *, struct sk_buff *))
40502 {
40503 struct cb *cb;
40504 unsigned long flags;
40505@@ -888,10 +888,13 @@ static int e100_exec_cb(struct nic *nic, struct sk_buff *skb,
40506 nic->cbs_avail--;
40507 cb->skb = skb;
40508
40509+ err = cb_prepare(nic, cb, skb);
40510+ if (err)
40511+ goto err_unlock;
40512+
40513 if (unlikely(!nic->cbs_avail))
40514 err = -ENOSPC;
40515
40516- cb_prepare(nic, cb, skb);
40517
40518 /* Order is important otherwise we'll be in a race with h/w:
40519 * set S-bit in current first, then clear S-bit in previous. */
40520@@ -1091,7 +1094,7 @@ static void e100_get_defaults(struct nic *nic)
40521 nic->mii.mdio_write = mdio_write;
40522 }
40523
40524-static void e100_configure(struct nic *nic, struct cb *cb, struct sk_buff *skb)
40525+static int e100_configure(struct nic *nic, struct cb *cb, struct sk_buff *skb)
40526 {
40527 struct config *config = &cb->u.config;
40528 u8 *c = (u8 *)config;
40529@@ -1181,6 +1184,7 @@ static void e100_configure(struct nic *nic, struct cb *cb, struct sk_buff *skb)
40530 netif_printk(nic, hw, KERN_DEBUG, nic->netdev,
40531 "[16-23]=%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
40532 c[16], c[17], c[18], c[19], c[20], c[21], c[22], c[23]);
40533+ return 0;
40534 }
40535
40536 /*************************************************************************
40537@@ -1331,7 +1335,7 @@ static const struct firmware *e100_request_firmware(struct nic *nic)
40538 return fw;
40539 }
40540
40541-static void e100_setup_ucode(struct nic *nic, struct cb *cb,
40542+static int e100_setup_ucode(struct nic *nic, struct cb *cb,
40543 struct sk_buff *skb)
40544 {
40545 const struct firmware *fw = (void *)skb;
40546@@ -1358,6 +1362,7 @@ static void e100_setup_ucode(struct nic *nic, struct cb *cb,
40547 cb->u.ucode[min_size] |= cpu_to_le32((BUNDLESMALL) ? 0xFFFF : 0xFF80);
40548
40549 cb->command = cpu_to_le16(cb_ucode | cb_el);
40550+ return 0;
40551 }
40552
40553 static inline int e100_load_ucode_wait(struct nic *nic)
40554@@ -1400,18 +1405,20 @@ static inline int e100_load_ucode_wait(struct nic *nic)
40555 return err;
40556 }
40557
40558-static void e100_setup_iaaddr(struct nic *nic, struct cb *cb,
40559+static int e100_setup_iaaddr(struct nic *nic, struct cb *cb,
40560 struct sk_buff *skb)
40561 {
40562 cb->command = cpu_to_le16(cb_iaaddr);
40563 memcpy(cb->u.iaaddr, nic->netdev->dev_addr, ETH_ALEN);
40564+ return 0;
40565 }
40566
40567-static void e100_dump(struct nic *nic, struct cb *cb, struct sk_buff *skb)
40568+static int e100_dump(struct nic *nic, struct cb *cb, struct sk_buff *skb)
40569 {
40570 cb->command = cpu_to_le16(cb_dump);
40571 cb->u.dump_buffer_addr = cpu_to_le32(nic->dma_addr +
40572 offsetof(struct mem, dump_buf));
40573+ return 0;
40574 }
40575
40576 static int e100_phy_check_without_mii(struct nic *nic)
40577@@ -1581,7 +1588,7 @@ static int e100_hw_init(struct nic *nic)
40578 return 0;
40579 }
40580
40581-static void e100_multi(struct nic *nic, struct cb *cb, struct sk_buff *skb)
40582+static int e100_multi(struct nic *nic, struct cb *cb, struct sk_buff *skb)
40583 {
40584 struct net_device *netdev = nic->netdev;
40585 struct netdev_hw_addr *ha;
40586@@ -1596,6 +1603,7 @@ static void e100_multi(struct nic *nic, struct cb *cb, struct sk_buff *skb)
40587 memcpy(&cb->u.multi.addr[i++ * ETH_ALEN], &ha->addr,
40588 ETH_ALEN);
40589 }
40590+ return 0;
40591 }
40592
40593 static void e100_set_multicast_list(struct net_device *netdev)
40594@@ -1756,11 +1764,18 @@ static void e100_watchdog(unsigned long data)
40595 round_jiffies(jiffies + E100_WATCHDOG_PERIOD));
40596 }
40597
40598-static void e100_xmit_prepare(struct nic *nic, struct cb *cb,
40599+static int e100_xmit_prepare(struct nic *nic, struct cb *cb,
40600 struct sk_buff *skb)
40601 {
40602+ dma_addr_t dma_addr;
40603 cb->command = nic->tx_command;
40604
40605+ dma_addr = pci_map_single(nic->pdev,
40606+ skb->data, skb->len, PCI_DMA_TODEVICE);
40607+ /* If we can't map the skb, have the upper layer try later */
40608+ if (pci_dma_mapping_error(nic->pdev, dma_addr))
40609+ return -ENOMEM;
40610+
40611 /*
40612 * Use the last 4 bytes of the SKB payload packet as the CRC, used for
40613 * testing, ie sending frames with bad CRC.
40614@@ -1777,11 +1792,10 @@ static void e100_xmit_prepare(struct nic *nic, struct cb *cb,
40615 cb->u.tcb.tcb_byte_count = 0;
40616 cb->u.tcb.threshold = nic->tx_threshold;
40617 cb->u.tcb.tbd_count = 1;
40618- cb->u.tcb.tbd.buf_addr = cpu_to_le32(pci_map_single(nic->pdev,
40619- skb->data, skb->len, PCI_DMA_TODEVICE));
40620- /* check for mapping failure? */
40621+ cb->u.tcb.tbd.buf_addr = cpu_to_le32(dma_addr);
40622 cb->u.tcb.tbd.size = cpu_to_le16(skb->len);
40623 skb_tx_timestamp(skb);
40624+ return 0;
40625 }
40626
40627 static netdev_tx_t e100_xmit_frame(struct sk_buff *skb,
40628diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
40629index bb9256a..56d8752 100644
40630--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
40631+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
40632@@ -806,7 +806,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
40633 }
40634
40635 /* update the base incval used to calculate frequency adjustment */
40636- ACCESS_ONCE(adapter->base_incval) = incval;
40637+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
40638 smp_mb();
40639
40640 /* need lock to prevent incorrect read while modifying cyclecounter */
40641diff --git a/drivers/net/ethernet/lantiq_etop.c b/drivers/net/ethernet/lantiq_etop.c
40642index c124e67..db9b897 100644
40643--- a/drivers/net/ethernet/lantiq_etop.c
40644+++ b/drivers/net/ethernet/lantiq_etop.c
40645@@ -769,7 +769,7 @@ ltq_etop_probe(struct platform_device *pdev)
40646 return 0;
40647
40648 err_free:
40649- kfree(dev);
40650+ free_netdev(dev);
40651 err_out:
40652 return err;
40653 }
40654diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
40655index fbe5363..266b4e3 100644
40656--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
40657+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
40658@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
40659 struct __vxge_hw_fifo *fifo;
40660 struct vxge_hw_fifo_config *config;
40661 u32 txdl_size, txdl_per_memblock;
40662- struct vxge_hw_mempool_cbs fifo_mp_callback;
40663+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
40664+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
40665+ };
40666+
40667 struct __vxge_hw_virtualpath *vpath;
40668
40669 if ((vp == NULL) || (attr == NULL)) {
40670@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
40671 goto exit;
40672 }
40673
40674- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
40675-
40676 fifo->mempool =
40677 __vxge_hw_mempool_create(vpath->hldev,
40678 fifo->config->memblock_size,
40679diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
40680index 2d849da..23bba3b 100644
40681--- a/drivers/net/ethernet/realtek/r8169.c
40682+++ b/drivers/net/ethernet/realtek/r8169.c
40683@@ -741,22 +741,22 @@ struct rtl8169_private {
40684 struct mdio_ops {
40685 void (*write)(struct rtl8169_private *, int, int);
40686 int (*read)(struct rtl8169_private *, int);
40687- } mdio_ops;
40688+ } __no_const mdio_ops;
40689
40690 struct pll_power_ops {
40691 void (*down)(struct rtl8169_private *);
40692 void (*up)(struct rtl8169_private *);
40693- } pll_power_ops;
40694+ } __no_const pll_power_ops;
40695
40696 struct jumbo_ops {
40697 void (*enable)(struct rtl8169_private *);
40698 void (*disable)(struct rtl8169_private *);
40699- } jumbo_ops;
40700+ } __no_const jumbo_ops;
40701
40702 struct csi_ops {
40703 void (*write)(struct rtl8169_private *, int, int);
40704 u32 (*read)(struct rtl8169_private *, int);
40705- } csi_ops;
40706+ } __no_const csi_ops;
40707
40708 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
40709 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
40710diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
40711index 3f93624..cf01144 100644
40712--- a/drivers/net/ethernet/sfc/ptp.c
40713+++ b/drivers/net/ethernet/sfc/ptp.c
40714@@ -553,7 +553,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
40715 (u32)((u64)ptp->start.dma_addr >> 32));
40716
40717 /* Clear flag that signals MC ready */
40718- ACCESS_ONCE(*start) = 0;
40719+ ACCESS_ONCE_RW(*start) = 0;
40720 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
40721 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
40722
40723diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
40724index 0c74a70..3bc6f68 100644
40725--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
40726+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
40727@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
40728
40729 writel(value, ioaddr + MMC_CNTRL);
40730
40731- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
40732- MMC_CNTRL, value);
40733+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
40734+// MMC_CNTRL, value);
40735 }
40736
40737 /* To mask all all interrupts.*/
40738diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
40739index e6fe0d8..2b7d752 100644
40740--- a/drivers/net/hyperv/hyperv_net.h
40741+++ b/drivers/net/hyperv/hyperv_net.h
40742@@ -101,7 +101,7 @@ struct rndis_device {
40743
40744 enum rndis_device_state state;
40745 bool link_state;
40746- atomic_t new_req_id;
40747+ atomic_unchecked_t new_req_id;
40748
40749 spinlock_t request_lock;
40750 struct list_head req_list;
40751diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
40752index 2b657d4..9903bc0 100644
40753--- a/drivers/net/hyperv/rndis_filter.c
40754+++ b/drivers/net/hyperv/rndis_filter.c
40755@@ -107,7 +107,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
40756 * template
40757 */
40758 set = &rndis_msg->msg.set_req;
40759- set->req_id = atomic_inc_return(&dev->new_req_id);
40760+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
40761
40762 /* Add to the request list */
40763 spin_lock_irqsave(&dev->request_lock, flags);
40764@@ -758,7 +758,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
40765
40766 /* Setup the rndis set */
40767 halt = &request->request_msg.msg.halt_req;
40768- halt->req_id = atomic_inc_return(&dev->new_req_id);
40769+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
40770
40771 /* Ignore return since this msg is optional. */
40772 rndis_filter_send_request(dev, request);
40773diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
40774index 1e9cb0b..7839125 100644
40775--- a/drivers/net/ieee802154/fakehard.c
40776+++ b/drivers/net/ieee802154/fakehard.c
40777@@ -386,7 +386,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
40778 phy->transmit_power = 0xbf;
40779
40780 dev->netdev_ops = &fake_ops;
40781- dev->ml_priv = &fake_mlme;
40782+ dev->ml_priv = (void *)&fake_mlme;
40783
40784 priv = netdev_priv(dev);
40785 priv->phy = phy;
40786diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
40787index e5cb723..1fc0461 100644
40788--- a/drivers/net/macvlan.c
40789+++ b/drivers/net/macvlan.c
40790@@ -852,13 +852,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
40791 int macvlan_link_register(struct rtnl_link_ops *ops)
40792 {
40793 /* common fields */
40794- ops->priv_size = sizeof(struct macvlan_dev);
40795- ops->validate = macvlan_validate;
40796- ops->maxtype = IFLA_MACVLAN_MAX;
40797- ops->policy = macvlan_policy;
40798- ops->changelink = macvlan_changelink;
40799- ops->get_size = macvlan_get_size;
40800- ops->fill_info = macvlan_fill_info;
40801+ pax_open_kernel();
40802+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
40803+ *(void **)&ops->validate = macvlan_validate;
40804+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
40805+ *(const void **)&ops->policy = macvlan_policy;
40806+ *(void **)&ops->changelink = macvlan_changelink;
40807+ *(void **)&ops->get_size = macvlan_get_size;
40808+ *(void **)&ops->fill_info = macvlan_fill_info;
40809+ pax_close_kernel();
40810
40811 return rtnl_link_register(ops);
40812 };
40813@@ -914,7 +916,7 @@ static int macvlan_device_event(struct notifier_block *unused,
40814 return NOTIFY_DONE;
40815 }
40816
40817-static struct notifier_block macvlan_notifier_block __read_mostly = {
40818+static struct notifier_block macvlan_notifier_block = {
40819 .notifier_call = macvlan_device_event,
40820 };
40821
40822diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
40823index 0f0f9ce..0ca5819 100644
40824--- a/drivers/net/macvtap.c
40825+++ b/drivers/net/macvtap.c
40826@@ -1100,7 +1100,7 @@ static int macvtap_device_event(struct notifier_block *unused,
40827 return NOTIFY_DONE;
40828 }
40829
40830-static struct notifier_block macvtap_notifier_block __read_mostly = {
40831+static struct notifier_block macvtap_notifier_block = {
40832 .notifier_call = macvtap_device_event,
40833 };
40834
40835diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
40836index daec9b0..6428fcb 100644
40837--- a/drivers/net/phy/mdio-bitbang.c
40838+++ b/drivers/net/phy/mdio-bitbang.c
40839@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
40840 struct mdiobb_ctrl *ctrl = bus->priv;
40841
40842 module_put(ctrl->ops->owner);
40843+ mdiobus_unregister(bus);
40844 mdiobus_free(bus);
40845 }
40846 EXPORT_SYMBOL(free_mdio_bitbang);
40847diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
40848index 508570e..f706dc7 100644
40849--- a/drivers/net/ppp/ppp_generic.c
40850+++ b/drivers/net/ppp/ppp_generic.c
40851@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40852 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
40853 struct ppp_stats stats;
40854 struct ppp_comp_stats cstats;
40855- char *vers;
40856
40857 switch (cmd) {
40858 case SIOCGPPPSTATS:
40859@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40860 break;
40861
40862 case SIOCGPPPVER:
40863- vers = PPP_VERSION;
40864- if (copy_to_user(addr, vers, strlen(vers) + 1))
40865+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
40866 break;
40867 err = 0;
40868 break;
40869diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
40870index 8efe47a..a8075c5 100644
40871--- a/drivers/net/team/team.c
40872+++ b/drivers/net/team/team.c
40873@@ -2603,7 +2603,7 @@ static int team_device_event(struct notifier_block *unused,
40874 return NOTIFY_DONE;
40875 }
40876
40877-static struct notifier_block team_notifier_block __read_mostly = {
40878+static struct notifier_block team_notifier_block = {
40879 .notifier_call = team_device_event,
40880 };
40881
40882diff --git a/drivers/net/tun.c b/drivers/net/tun.c
40883index cb95fe5..16909e2 100644
40884--- a/drivers/net/tun.c
40885+++ b/drivers/net/tun.c
40886@@ -1594,7 +1594,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
40887
40888 if (tun->flags & TUN_TAP_MQ &&
40889 (tun->numqueues + tun->numdisabled > 1))
40890- return err;
40891+ return -EBUSY;
40892 }
40893 else {
40894 char *name;
40895@@ -1838,7 +1838,7 @@ unlock:
40896 }
40897
40898 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
40899- unsigned long arg, int ifreq_len)
40900+ unsigned long arg, size_t ifreq_len)
40901 {
40902 struct tun_file *tfile = file->private_data;
40903 struct tun_struct *tun;
40904@@ -1850,6 +1850,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
40905 int vnet_hdr_sz;
40906 int ret;
40907
40908+ if (ifreq_len > sizeof ifr)
40909+ return -EFAULT;
40910+
40911 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
40912 if (copy_from_user(&ifr, argp, ifreq_len))
40913 return -EFAULT;
40914diff --git a/drivers/net/usb/cdc_mbim.c b/drivers/net/usb/cdc_mbim.c
40915index 16c8429..6bd9167 100644
40916--- a/drivers/net/usb/cdc_mbim.c
40917+++ b/drivers/net/usb/cdc_mbim.c
40918@@ -134,7 +134,7 @@ static struct sk_buff *cdc_mbim_tx_fixup(struct usbnet *dev, struct sk_buff *skb
40919 goto error;
40920
40921 if (skb) {
40922- if (skb->len <= sizeof(ETH_HLEN))
40923+ if (skb->len <= ETH_HLEN)
40924 goto error;
40925
40926 /* mapping VLANs to MBIM sessions:
40927diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
40928index cd8ccb2..cff5144 100644
40929--- a/drivers/net/usb/hso.c
40930+++ b/drivers/net/usb/hso.c
40931@@ -71,7 +71,7 @@
40932 #include <asm/byteorder.h>
40933 #include <linux/serial_core.h>
40934 #include <linux/serial.h>
40935-
40936+#include <asm/local.h>
40937
40938 #define MOD_AUTHOR "Option Wireless"
40939 #define MOD_DESCRIPTION "USB High Speed Option driver"
40940@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
40941 struct urb *urb;
40942
40943 urb = serial->rx_urb[0];
40944- if (serial->port.count > 0) {
40945+ if (atomic_read(&serial->port.count) > 0) {
40946 count = put_rxbuf_data(urb, serial);
40947 if (count == -1)
40948 return;
40949@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
40950 DUMP1(urb->transfer_buffer, urb->actual_length);
40951
40952 /* Anyone listening? */
40953- if (serial->port.count == 0)
40954+ if (atomic_read(&serial->port.count) == 0)
40955 return;
40956
40957 if (status == 0) {
40958@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
40959 tty_port_tty_set(&serial->port, tty);
40960
40961 /* check for port already opened, if not set the termios */
40962- serial->port.count++;
40963- if (serial->port.count == 1) {
40964+ if (atomic_inc_return(&serial->port.count) == 1) {
40965 serial->rx_state = RX_IDLE;
40966 /* Force default termio settings */
40967 _hso_serial_set_termios(tty, NULL);
40968@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
40969 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
40970 if (result) {
40971 hso_stop_serial_device(serial->parent);
40972- serial->port.count--;
40973+ atomic_dec(&serial->port.count);
40974 kref_put(&serial->parent->ref, hso_serial_ref_free);
40975 }
40976 } else {
40977@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
40978
40979 /* reset the rts and dtr */
40980 /* do the actual close */
40981- serial->port.count--;
40982+ atomic_dec(&serial->port.count);
40983
40984- if (serial->port.count <= 0) {
40985- serial->port.count = 0;
40986+ if (atomic_read(&serial->port.count) <= 0) {
40987+ atomic_set(&serial->port.count, 0);
40988 tty_port_tty_set(&serial->port, NULL);
40989 if (!usb_gone)
40990 hso_stop_serial_device(serial->parent);
40991@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
40992
40993 /* the actual setup */
40994 spin_lock_irqsave(&serial->serial_lock, flags);
40995- if (serial->port.count)
40996+ if (atomic_read(&serial->port.count))
40997 _hso_serial_set_termios(tty, old);
40998 else
40999 tty->termios = *old;
41000@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
41001 D1("Pending read interrupt on port %d\n", i);
41002 spin_lock(&serial->serial_lock);
41003 if (serial->rx_state == RX_IDLE &&
41004- serial->port.count > 0) {
41005+ atomic_read(&serial->port.count) > 0) {
41006 /* Setup and send a ctrl req read on
41007 * port i */
41008 if (!serial->rx_urb_filled[0]) {
41009@@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
41010 /* Start all serial ports */
41011 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
41012 if (serial_table[i] && (serial_table[i]->interface == iface)) {
41013- if (dev2ser(serial_table[i])->port.count) {
41014+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
41015 result =
41016 hso_start_serial_device(serial_table[i], GFP_NOIO);
41017 hso_kick_transmit(dev2ser(serial_table[i]));
41018diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
41019index 6993bfa..9053a34 100644
41020--- a/drivers/net/vxlan.c
41021+++ b/drivers/net/vxlan.c
41022@@ -1428,7 +1428,7 @@ nla_put_failure:
41023 return -EMSGSIZE;
41024 }
41025
41026-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
41027+static struct rtnl_link_ops vxlan_link_ops = {
41028 .kind = "vxlan",
41029 .maxtype = IFLA_VXLAN_MAX,
41030 .policy = vxlan_policy,
41031diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
41032index 77fa428..996b355 100644
41033--- a/drivers/net/wireless/at76c50x-usb.c
41034+++ b/drivers/net/wireless/at76c50x-usb.c
41035@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
41036 }
41037
41038 /* Convert timeout from the DFU status to jiffies */
41039-static inline unsigned long at76_get_timeout(struct dfu_status *s)
41040+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
41041 {
41042 return msecs_to_jiffies((s->poll_timeout[2] << 16)
41043 | (s->poll_timeout[1] << 8)
41044diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
41045index 8d78253..bebbb68 100644
41046--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
41047+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
41048@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
41049 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
41050 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
41051
41052- ACCESS_ONCE(ads->ds_link) = i->link;
41053- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
41054+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
41055+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
41056
41057 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
41058 ctl6 = SM(i->keytype, AR_EncrType);
41059@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
41060
41061 if ((i->is_first || i->is_last) &&
41062 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
41063- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
41064+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
41065 | set11nTries(i->rates, 1)
41066 | set11nTries(i->rates, 2)
41067 | set11nTries(i->rates, 3)
41068 | (i->dur_update ? AR_DurUpdateEna : 0)
41069 | SM(0, AR_BurstDur);
41070
41071- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
41072+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
41073 | set11nRate(i->rates, 1)
41074 | set11nRate(i->rates, 2)
41075 | set11nRate(i->rates, 3);
41076 } else {
41077- ACCESS_ONCE(ads->ds_ctl2) = 0;
41078- ACCESS_ONCE(ads->ds_ctl3) = 0;
41079+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
41080+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
41081 }
41082
41083 if (!i->is_first) {
41084- ACCESS_ONCE(ads->ds_ctl0) = 0;
41085- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
41086- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
41087+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
41088+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
41089+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
41090 return;
41091 }
41092
41093@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
41094 break;
41095 }
41096
41097- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
41098+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
41099 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
41100 | SM(i->txpower, AR_XmitPower)
41101 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
41102@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
41103 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
41104 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
41105
41106- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
41107- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
41108+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
41109+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
41110
41111 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
41112 return;
41113
41114- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
41115+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
41116 | set11nPktDurRTSCTS(i->rates, 1);
41117
41118- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
41119+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
41120 | set11nPktDurRTSCTS(i->rates, 3);
41121
41122- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
41123+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
41124 | set11nRateFlags(i->rates, 1)
41125 | set11nRateFlags(i->rates, 2)
41126 | set11nRateFlags(i->rates, 3)
41127diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
41128index 301bf72..3f5654f 100644
41129--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
41130+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
41131@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
41132 (i->qcu << AR_TxQcuNum_S) | desc_len;
41133
41134 checksum += val;
41135- ACCESS_ONCE(ads->info) = val;
41136+ ACCESS_ONCE_RW(ads->info) = val;
41137
41138 checksum += i->link;
41139- ACCESS_ONCE(ads->link) = i->link;
41140+ ACCESS_ONCE_RW(ads->link) = i->link;
41141
41142 checksum += i->buf_addr[0];
41143- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
41144+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
41145 checksum += i->buf_addr[1];
41146- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
41147+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
41148 checksum += i->buf_addr[2];
41149- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
41150+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
41151 checksum += i->buf_addr[3];
41152- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
41153+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
41154
41155 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
41156- ACCESS_ONCE(ads->ctl3) = val;
41157+ ACCESS_ONCE_RW(ads->ctl3) = val;
41158 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
41159- ACCESS_ONCE(ads->ctl5) = val;
41160+ ACCESS_ONCE_RW(ads->ctl5) = val;
41161 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
41162- ACCESS_ONCE(ads->ctl7) = val;
41163+ ACCESS_ONCE_RW(ads->ctl7) = val;
41164 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
41165- ACCESS_ONCE(ads->ctl9) = val;
41166+ ACCESS_ONCE_RW(ads->ctl9) = val;
41167
41168 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
41169- ACCESS_ONCE(ads->ctl10) = checksum;
41170+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
41171
41172 if (i->is_first || i->is_last) {
41173- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
41174+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
41175 | set11nTries(i->rates, 1)
41176 | set11nTries(i->rates, 2)
41177 | set11nTries(i->rates, 3)
41178 | (i->dur_update ? AR_DurUpdateEna : 0)
41179 | SM(0, AR_BurstDur);
41180
41181- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
41182+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
41183 | set11nRate(i->rates, 1)
41184 | set11nRate(i->rates, 2)
41185 | set11nRate(i->rates, 3);
41186 } else {
41187- ACCESS_ONCE(ads->ctl13) = 0;
41188- ACCESS_ONCE(ads->ctl14) = 0;
41189+ ACCESS_ONCE_RW(ads->ctl13) = 0;
41190+ ACCESS_ONCE_RW(ads->ctl14) = 0;
41191 }
41192
41193 ads->ctl20 = 0;
41194@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
41195
41196 ctl17 = SM(i->keytype, AR_EncrType);
41197 if (!i->is_first) {
41198- ACCESS_ONCE(ads->ctl11) = 0;
41199- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
41200- ACCESS_ONCE(ads->ctl15) = 0;
41201- ACCESS_ONCE(ads->ctl16) = 0;
41202- ACCESS_ONCE(ads->ctl17) = ctl17;
41203- ACCESS_ONCE(ads->ctl18) = 0;
41204- ACCESS_ONCE(ads->ctl19) = 0;
41205+ ACCESS_ONCE_RW(ads->ctl11) = 0;
41206+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
41207+ ACCESS_ONCE_RW(ads->ctl15) = 0;
41208+ ACCESS_ONCE_RW(ads->ctl16) = 0;
41209+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
41210+ ACCESS_ONCE_RW(ads->ctl18) = 0;
41211+ ACCESS_ONCE_RW(ads->ctl19) = 0;
41212 return;
41213 }
41214
41215- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
41216+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
41217 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
41218 | SM(i->txpower, AR_XmitPower)
41219 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
41220@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
41221 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
41222 ctl12 |= SM(val, AR_PAPRDChainMask);
41223
41224- ACCESS_ONCE(ads->ctl12) = ctl12;
41225- ACCESS_ONCE(ads->ctl17) = ctl17;
41226+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
41227+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
41228
41229- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
41230+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
41231 | set11nPktDurRTSCTS(i->rates, 1);
41232
41233- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
41234+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
41235 | set11nPktDurRTSCTS(i->rates, 3);
41236
41237- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
41238+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
41239 | set11nRateFlags(i->rates, 1)
41240 | set11nRateFlags(i->rates, 2)
41241 | set11nRateFlags(i->rates, 3)
41242 | SM(i->rtscts_rate, AR_RTSCTSRate);
41243
41244- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
41245+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
41246 }
41247
41248 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
41249diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
41250index 9d26fc5..60d9f14 100644
41251--- a/drivers/net/wireless/ath/ath9k/hw.h
41252+++ b/drivers/net/wireless/ath/ath9k/hw.h
41253@@ -658,7 +658,7 @@ struct ath_hw_private_ops {
41254
41255 /* ANI */
41256 void (*ani_cache_ini_regs)(struct ath_hw *ah);
41257-};
41258+} __no_const;
41259
41260 /**
41261 * struct ath_hw_ops - callbacks used by hardware code and driver code
41262@@ -688,7 +688,7 @@ struct ath_hw_ops {
41263 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
41264 struct ath_hw_antcomb_conf *antconf);
41265 void (*antctrl_shared_chain_lnadiv)(struct ath_hw *hw, bool enable);
41266-};
41267+} __no_const;
41268
41269 struct ath_nf_limits {
41270 s16 max;
41271diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
41272index 3726cd6..b655808 100644
41273--- a/drivers/net/wireless/iwlegacy/3945-mac.c
41274+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
41275@@ -3615,7 +3615,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
41276 */
41277 if (il3945_mod_params.disable_hw_scan) {
41278 D_INFO("Disabling hw_scan\n");
41279- il3945_mac_ops.hw_scan = NULL;
41280+ pax_open_kernel();
41281+ *(void **)&il3945_mac_ops.hw_scan = NULL;
41282+ pax_close_kernel();
41283 }
41284
41285 D_INFO("*** LOAD DRIVER ***\n");
41286diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
41287index 5b9533e..7733880 100644
41288--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
41289+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
41290@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
41291 {
41292 struct iwl_priv *priv = file->private_data;
41293 char buf[64];
41294- int buf_size;
41295+ size_t buf_size;
41296 u32 offset, len;
41297
41298 memset(buf, 0, sizeof(buf));
41299@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
41300 struct iwl_priv *priv = file->private_data;
41301
41302 char buf[8];
41303- int buf_size;
41304+ size_t buf_size;
41305 u32 reset_flag;
41306
41307 memset(buf, 0, sizeof(buf));
41308@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
41309 {
41310 struct iwl_priv *priv = file->private_data;
41311 char buf[8];
41312- int buf_size;
41313+ size_t buf_size;
41314 int ht40;
41315
41316 memset(buf, 0, sizeof(buf));
41317@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
41318 {
41319 struct iwl_priv *priv = file->private_data;
41320 char buf[8];
41321- int buf_size;
41322+ size_t buf_size;
41323 int value;
41324
41325 memset(buf, 0, sizeof(buf));
41326@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
41327 {
41328 struct iwl_priv *priv = file->private_data;
41329 char buf[8];
41330- int buf_size;
41331+ size_t buf_size;
41332 int clear;
41333
41334 memset(buf, 0, sizeof(buf));
41335@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
41336 {
41337 struct iwl_priv *priv = file->private_data;
41338 char buf[8];
41339- int buf_size;
41340+ size_t buf_size;
41341 int trace;
41342
41343 memset(buf, 0, sizeof(buf));
41344@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
41345 {
41346 struct iwl_priv *priv = file->private_data;
41347 char buf[8];
41348- int buf_size;
41349+ size_t buf_size;
41350 int missed;
41351
41352 memset(buf, 0, sizeof(buf));
41353@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
41354
41355 struct iwl_priv *priv = file->private_data;
41356 char buf[8];
41357- int buf_size;
41358+ size_t buf_size;
41359 int plcp;
41360
41361 memset(buf, 0, sizeof(buf));
41362@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
41363
41364 struct iwl_priv *priv = file->private_data;
41365 char buf[8];
41366- int buf_size;
41367+ size_t buf_size;
41368 int flush;
41369
41370 memset(buf, 0, sizeof(buf));
41371@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
41372
41373 struct iwl_priv *priv = file->private_data;
41374 char buf[8];
41375- int buf_size;
41376+ size_t buf_size;
41377 int rts;
41378
41379 if (!priv->cfg->ht_params)
41380@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
41381 {
41382 struct iwl_priv *priv = file->private_data;
41383 char buf[8];
41384- int buf_size;
41385+ size_t buf_size;
41386
41387 memset(buf, 0, sizeof(buf));
41388 buf_size = min(count, sizeof(buf) - 1);
41389@@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
41390 struct iwl_priv *priv = file->private_data;
41391 u32 event_log_flag;
41392 char buf[8];
41393- int buf_size;
41394+ size_t buf_size;
41395
41396 /* check that the interface is up */
41397 if (!iwl_is_ready(priv))
41398@@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
41399 struct iwl_priv *priv = file->private_data;
41400 char buf[8];
41401 u32 calib_disabled;
41402- int buf_size;
41403+ size_t buf_size;
41404
41405 memset(buf, 0, sizeof(buf));
41406 buf_size = min(count, sizeof(buf) - 1);
41407diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
41408index 35708b9..31f7754 100644
41409--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
41410+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
41411@@ -1100,7 +1100,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
41412 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
41413
41414 char buf[8];
41415- int buf_size;
41416+ size_t buf_size;
41417 u32 reset_flag;
41418
41419 memset(buf, 0, sizeof(buf));
41420@@ -1121,7 +1121,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
41421 {
41422 struct iwl_trans *trans = file->private_data;
41423 char buf[8];
41424- int buf_size;
41425+ size_t buf_size;
41426 int csr;
41427
41428 memset(buf, 0, sizeof(buf));
41429diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
41430index ff90855..e46d223 100644
41431--- a/drivers/net/wireless/mac80211_hwsim.c
41432+++ b/drivers/net/wireless/mac80211_hwsim.c
41433@@ -2062,25 +2062,19 @@ static int __init init_mac80211_hwsim(void)
41434
41435 if (channels > 1) {
41436 hwsim_if_comb.num_different_channels = channels;
41437- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
41438- mac80211_hwsim_ops.cancel_hw_scan =
41439- mac80211_hwsim_cancel_hw_scan;
41440- mac80211_hwsim_ops.sw_scan_start = NULL;
41441- mac80211_hwsim_ops.sw_scan_complete = NULL;
41442- mac80211_hwsim_ops.remain_on_channel =
41443- mac80211_hwsim_roc;
41444- mac80211_hwsim_ops.cancel_remain_on_channel =
41445- mac80211_hwsim_croc;
41446- mac80211_hwsim_ops.add_chanctx =
41447- mac80211_hwsim_add_chanctx;
41448- mac80211_hwsim_ops.remove_chanctx =
41449- mac80211_hwsim_remove_chanctx;
41450- mac80211_hwsim_ops.change_chanctx =
41451- mac80211_hwsim_change_chanctx;
41452- mac80211_hwsim_ops.assign_vif_chanctx =
41453- mac80211_hwsim_assign_vif_chanctx;
41454- mac80211_hwsim_ops.unassign_vif_chanctx =
41455- mac80211_hwsim_unassign_vif_chanctx;
41456+ pax_open_kernel();
41457+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
41458+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
41459+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
41460+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
41461+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
41462+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
41463+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
41464+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
41465+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
41466+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
41467+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
41468+ pax_close_kernel();
41469 }
41470
41471 spin_lock_init(&hwsim_radio_lock);
41472diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
41473index abe1d03..fb02c22 100644
41474--- a/drivers/net/wireless/rndis_wlan.c
41475+++ b/drivers/net/wireless/rndis_wlan.c
41476@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
41477
41478 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
41479
41480- if (rts_threshold < 0 || rts_threshold > 2347)
41481+ if (rts_threshold > 2347)
41482 rts_threshold = 2347;
41483
41484 tmp = cpu_to_le32(rts_threshold);
41485diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
41486index 0751b35..246ba3e 100644
41487--- a/drivers/net/wireless/rt2x00/rt2x00.h
41488+++ b/drivers/net/wireless/rt2x00/rt2x00.h
41489@@ -398,7 +398,7 @@ struct rt2x00_intf {
41490 * for hardware which doesn't support hardware
41491 * sequence counting.
41492 */
41493- atomic_t seqno;
41494+ atomic_unchecked_t seqno;
41495 };
41496
41497 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
41498diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
41499index e488b94..14b6a0c 100644
41500--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
41501+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
41502@@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
41503 * sequence counter given by mac80211.
41504 */
41505 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
41506- seqno = atomic_add_return(0x10, &intf->seqno);
41507+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
41508 else
41509- seqno = atomic_read(&intf->seqno);
41510+ seqno = atomic_read_unchecked(&intf->seqno);
41511
41512 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
41513 hdr->seq_ctrl |= cpu_to_le16(seqno);
41514diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
41515index e57ee48..541cf6c 100644
41516--- a/drivers/net/wireless/ti/wl1251/sdio.c
41517+++ b/drivers/net/wireless/ti/wl1251/sdio.c
41518@@ -269,13 +269,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
41519
41520 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
41521
41522- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
41523- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
41524+ pax_open_kernel();
41525+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
41526+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
41527+ pax_close_kernel();
41528
41529 wl1251_info("using dedicated interrupt line");
41530 } else {
41531- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
41532- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
41533+ pax_open_kernel();
41534+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
41535+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
41536+ pax_close_kernel();
41537
41538 wl1251_info("using SDIO interrupt");
41539 }
41540diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
41541index e5f5f8f..fdf15b7 100644
41542--- a/drivers/net/wireless/ti/wl12xx/main.c
41543+++ b/drivers/net/wireless/ti/wl12xx/main.c
41544@@ -644,7 +644,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
41545 sizeof(wl->conf.mem));
41546
41547 /* read data preparation is only needed by wl127x */
41548- wl->ops->prepare_read = wl127x_prepare_read;
41549+ pax_open_kernel();
41550+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
41551+ pax_close_kernel();
41552
41553 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
41554 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
41555@@ -665,7 +667,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
41556 sizeof(wl->conf.mem));
41557
41558 /* read data preparation is only needed by wl127x */
41559- wl->ops->prepare_read = wl127x_prepare_read;
41560+ pax_open_kernel();
41561+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
41562+ pax_close_kernel();
41563
41564 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
41565 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
41566diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
41567index 8d8c1f8..e754844 100644
41568--- a/drivers/net/wireless/ti/wl18xx/main.c
41569+++ b/drivers/net/wireless/ti/wl18xx/main.c
41570@@ -1489,8 +1489,10 @@ static int wl18xx_setup(struct wl1271 *wl)
41571 }
41572
41573 if (!checksum_param) {
41574- wl18xx_ops.set_rx_csum = NULL;
41575- wl18xx_ops.init_vif = NULL;
41576+ pax_open_kernel();
41577+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
41578+ *(void **)&wl18xx_ops.init_vif = NULL;
41579+ pax_close_kernel();
41580 }
41581
41582 /* Enable 11a Band only if we have 5G antennas */
41583diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
41584index ef2b171..bb513a6 100644
41585--- a/drivers/net/wireless/zd1211rw/zd_usb.c
41586+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
41587@@ -387,7 +387,7 @@ static inline void handle_regs_int(struct urb *urb)
41588 {
41589 struct zd_usb *usb = urb->context;
41590 struct zd_usb_interrupt *intr = &usb->intr;
41591- int len;
41592+ unsigned int len;
41593 u16 int_num;
41594
41595 ZD_ASSERT(in_interrupt());
41596diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
41597index d93b2b6..ae50401 100644
41598--- a/drivers/oprofile/buffer_sync.c
41599+++ b/drivers/oprofile/buffer_sync.c
41600@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
41601 if (cookie == NO_COOKIE)
41602 offset = pc;
41603 if (cookie == INVALID_COOKIE) {
41604- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
41605+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
41606 offset = pc;
41607 }
41608 if (cookie != last_cookie) {
41609@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
41610 /* add userspace sample */
41611
41612 if (!mm) {
41613- atomic_inc(&oprofile_stats.sample_lost_no_mm);
41614+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
41615 return 0;
41616 }
41617
41618 cookie = lookup_dcookie(mm, s->eip, &offset);
41619
41620 if (cookie == INVALID_COOKIE) {
41621- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
41622+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
41623 return 0;
41624 }
41625
41626@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
41627 /* ignore backtraces if failed to add a sample */
41628 if (state == sb_bt_start) {
41629 state = sb_bt_ignore;
41630- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
41631+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
41632 }
41633 }
41634 release_mm(mm);
41635diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
41636index c0cc4e7..44d4e54 100644
41637--- a/drivers/oprofile/event_buffer.c
41638+++ b/drivers/oprofile/event_buffer.c
41639@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
41640 }
41641
41642 if (buffer_pos == buffer_size) {
41643- atomic_inc(&oprofile_stats.event_lost_overflow);
41644+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
41645 return;
41646 }
41647
41648diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
41649index ed2c3ec..deda85a 100644
41650--- a/drivers/oprofile/oprof.c
41651+++ b/drivers/oprofile/oprof.c
41652@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
41653 if (oprofile_ops.switch_events())
41654 return;
41655
41656- atomic_inc(&oprofile_stats.multiplex_counter);
41657+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
41658 start_switch_worker();
41659 }
41660
41661diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
41662index 84a208d..d61b0a1 100644
41663--- a/drivers/oprofile/oprofile_files.c
41664+++ b/drivers/oprofile/oprofile_files.c
41665@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
41666
41667 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
41668
41669-static ssize_t timeout_read(struct file *file, char __user *buf,
41670+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
41671 size_t count, loff_t *offset)
41672 {
41673 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
41674diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
41675index 917d28e..d62d981 100644
41676--- a/drivers/oprofile/oprofile_stats.c
41677+++ b/drivers/oprofile/oprofile_stats.c
41678@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
41679 cpu_buf->sample_invalid_eip = 0;
41680 }
41681
41682- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
41683- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
41684- atomic_set(&oprofile_stats.event_lost_overflow, 0);
41685- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
41686- atomic_set(&oprofile_stats.multiplex_counter, 0);
41687+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
41688+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
41689+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
41690+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
41691+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
41692 }
41693
41694
41695diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
41696index 38b6fc0..b5cbfce 100644
41697--- a/drivers/oprofile/oprofile_stats.h
41698+++ b/drivers/oprofile/oprofile_stats.h
41699@@ -13,11 +13,11 @@
41700 #include <linux/atomic.h>
41701
41702 struct oprofile_stat_struct {
41703- atomic_t sample_lost_no_mm;
41704- atomic_t sample_lost_no_mapping;
41705- atomic_t bt_lost_no_mapping;
41706- atomic_t event_lost_overflow;
41707- atomic_t multiplex_counter;
41708+ atomic_unchecked_t sample_lost_no_mm;
41709+ atomic_unchecked_t sample_lost_no_mapping;
41710+ atomic_unchecked_t bt_lost_no_mapping;
41711+ atomic_unchecked_t event_lost_overflow;
41712+ atomic_unchecked_t multiplex_counter;
41713 };
41714
41715 extern struct oprofile_stat_struct oprofile_stats;
41716diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
41717index 849357c..b83c1e0 100644
41718--- a/drivers/oprofile/oprofilefs.c
41719+++ b/drivers/oprofile/oprofilefs.c
41720@@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
41721
41722
41723 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
41724- char const *name, atomic_t *val)
41725+ char const *name, atomic_unchecked_t *val)
41726 {
41727 return __oprofilefs_create_file(sb, root, name,
41728 &atomic_ro_fops, 0444, val);
41729diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
41730index 93404f7..4a313d8 100644
41731--- a/drivers/oprofile/timer_int.c
41732+++ b/drivers/oprofile/timer_int.c
41733@@ -93,7 +93,7 @@ static int __cpuinit oprofile_cpu_notify(struct notifier_block *self,
41734 return NOTIFY_OK;
41735 }
41736
41737-static struct notifier_block __refdata oprofile_cpu_notifier = {
41738+static struct notifier_block oprofile_cpu_notifier = {
41739 .notifier_call = oprofile_cpu_notify,
41740 };
41741
41742diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
41743index 3f56bc0..707d642 100644
41744--- a/drivers/parport/procfs.c
41745+++ b/drivers/parport/procfs.c
41746@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
41747
41748 *ppos += len;
41749
41750- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
41751+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
41752 }
41753
41754 #ifdef CONFIG_PARPORT_1284
41755@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
41756
41757 *ppos += len;
41758
41759- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
41760+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
41761 }
41762 #endif /* IEEE1284.3 support. */
41763
41764diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
41765index c35e8ad..fc33beb 100644
41766--- a/drivers/pci/hotplug/acpiphp_ibm.c
41767+++ b/drivers/pci/hotplug/acpiphp_ibm.c
41768@@ -464,7 +464,9 @@ static int __init ibm_acpiphp_init(void)
41769 goto init_cleanup;
41770 }
41771
41772- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
41773+ pax_open_kernel();
41774+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
41775+ pax_close_kernel();
41776 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
41777
41778 return retval;
41779diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
41780index a6a71c4..c91097b 100644
41781--- a/drivers/pci/hotplug/cpcihp_generic.c
41782+++ b/drivers/pci/hotplug/cpcihp_generic.c
41783@@ -73,7 +73,6 @@ static u16 port;
41784 static unsigned int enum_bit;
41785 static u8 enum_mask;
41786
41787-static struct cpci_hp_controller_ops generic_hpc_ops;
41788 static struct cpci_hp_controller generic_hpc;
41789
41790 static int __init validate_parameters(void)
41791@@ -139,6 +138,10 @@ static int query_enum(void)
41792 return ((value & enum_mask) == enum_mask);
41793 }
41794
41795+static struct cpci_hp_controller_ops generic_hpc_ops = {
41796+ .query_enum = query_enum,
41797+};
41798+
41799 static int __init cpcihp_generic_init(void)
41800 {
41801 int status;
41802@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
41803 pci_dev_put(dev);
41804
41805 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
41806- generic_hpc_ops.query_enum = query_enum;
41807 generic_hpc.ops = &generic_hpc_ops;
41808
41809 status = cpci_hp_register_controller(&generic_hpc);
41810diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
41811index 449b4bb..257e2e8 100644
41812--- a/drivers/pci/hotplug/cpcihp_zt5550.c
41813+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
41814@@ -59,7 +59,6 @@
41815 /* local variables */
41816 static bool debug;
41817 static bool poll;
41818-static struct cpci_hp_controller_ops zt5550_hpc_ops;
41819 static struct cpci_hp_controller zt5550_hpc;
41820
41821 /* Primary cPCI bus bridge device */
41822@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
41823 return 0;
41824 }
41825
41826+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
41827+ .query_enum = zt5550_hc_query_enum,
41828+};
41829+
41830 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
41831 {
41832 int status;
41833@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
41834 dbg("returned from zt5550_hc_config");
41835
41836 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
41837- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
41838 zt5550_hpc.ops = &zt5550_hpc_ops;
41839 if(!poll) {
41840 zt5550_hpc.irq = hc_dev->irq;
41841 zt5550_hpc.irq_flags = IRQF_SHARED;
41842 zt5550_hpc.dev_id = hc_dev;
41843
41844- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
41845- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
41846- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
41847+ pax_open_kernel();
41848+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
41849+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
41850+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
41851+ pax_open_kernel();
41852 } else {
41853 info("using ENUM# polling mode");
41854 }
41855diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
41856index 76ba8a1..20ca857 100644
41857--- a/drivers/pci/hotplug/cpqphp_nvram.c
41858+++ b/drivers/pci/hotplug/cpqphp_nvram.c
41859@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
41860
41861 void compaq_nvram_init (void __iomem *rom_start)
41862 {
41863+
41864+#ifndef CONFIG_PAX_KERNEXEC
41865 if (rom_start) {
41866 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
41867 }
41868+#endif
41869+
41870 dbg("int15 entry = %p\n", compaq_int15_entry_point);
41871
41872 /* initialize our int15 lock */
41873diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
41874index 202f4a9..8ee47d0 100644
41875--- a/drivers/pci/hotplug/pci_hotplug_core.c
41876+++ b/drivers/pci/hotplug/pci_hotplug_core.c
41877@@ -448,8 +448,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
41878 return -EINVAL;
41879 }
41880
41881- slot->ops->owner = owner;
41882- slot->ops->mod_name = mod_name;
41883+ pax_open_kernel();
41884+ *(struct module **)&slot->ops->owner = owner;
41885+ *(const char **)&slot->ops->mod_name = mod_name;
41886+ pax_close_kernel();
41887
41888 mutex_lock(&pci_hp_mutex);
41889 /*
41890diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
41891index 939bd1d..a1459c9 100644
41892--- a/drivers/pci/hotplug/pciehp_core.c
41893+++ b/drivers/pci/hotplug/pciehp_core.c
41894@@ -91,7 +91,7 @@ static int init_slot(struct controller *ctrl)
41895 struct slot *slot = ctrl->slot;
41896 struct hotplug_slot *hotplug = NULL;
41897 struct hotplug_slot_info *info = NULL;
41898- struct hotplug_slot_ops *ops = NULL;
41899+ hotplug_slot_ops_no_const *ops = NULL;
41900 char name[SLOT_NAME_SIZE];
41901 int retval = -ENOMEM;
41902
41903diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
41904index 9c6e9bb..2916736 100644
41905--- a/drivers/pci/pci-sysfs.c
41906+++ b/drivers/pci/pci-sysfs.c
41907@@ -1071,7 +1071,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
41908 {
41909 /* allocate attribute structure, piggyback attribute name */
41910 int name_len = write_combine ? 13 : 10;
41911- struct bin_attribute *res_attr;
41912+ bin_attribute_no_const *res_attr;
41913 int retval;
41914
41915 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
41916@@ -1256,7 +1256,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
41917 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
41918 {
41919 int retval;
41920- struct bin_attribute *attr;
41921+ bin_attribute_no_const *attr;
41922
41923 /* If the device has VPD, try to expose it in sysfs. */
41924 if (dev->vpd) {
41925@@ -1303,7 +1303,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
41926 {
41927 int retval;
41928 int rom_size = 0;
41929- struct bin_attribute *attr;
41930+ bin_attribute_no_const *attr;
41931
41932 if (!sysfs_initialized)
41933 return -EACCES;
41934diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
41935index e851829..a1a7196 100644
41936--- a/drivers/pci/pci.h
41937+++ b/drivers/pci/pci.h
41938@@ -98,7 +98,7 @@ struct pci_vpd_ops {
41939 struct pci_vpd {
41940 unsigned int len;
41941 const struct pci_vpd_ops *ops;
41942- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
41943+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
41944 };
41945
41946 extern int pci_vpd_pci22_init(struct pci_dev *dev);
41947diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
41948index 8474b6a..ee81993 100644
41949--- a/drivers/pci/pcie/aspm.c
41950+++ b/drivers/pci/pcie/aspm.c
41951@@ -27,9 +27,9 @@
41952 #define MODULE_PARAM_PREFIX "pcie_aspm."
41953
41954 /* Note: those are not register definitions */
41955-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
41956-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
41957-#define ASPM_STATE_L1 (4) /* L1 state */
41958+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
41959+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
41960+#define ASPM_STATE_L1 (4U) /* L1 state */
41961 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
41962 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
41963
41964diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
41965index 6186f03..1a78714 100644
41966--- a/drivers/pci/probe.c
41967+++ b/drivers/pci/probe.c
41968@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
41969 struct pci_bus_region region;
41970 bool bar_too_big = false, bar_disabled = false;
41971
41972- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
41973+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
41974
41975 /* No printks while decoding is disabled! */
41976 if (!dev->mmio_always_on) {
41977diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
41978index 9b8505c..f00870a 100644
41979--- a/drivers/pci/proc.c
41980+++ b/drivers/pci/proc.c
41981@@ -465,7 +465,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
41982 static int __init pci_proc_init(void)
41983 {
41984 struct pci_dev *dev = NULL;
41985+
41986+#ifdef CONFIG_GRKERNSEC_PROC_ADD
41987+#ifdef CONFIG_GRKERNSEC_PROC_USER
41988+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
41989+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
41990+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
41991+#endif
41992+#else
41993 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
41994+#endif
41995 proc_create("devices", 0, proc_bus_pci_dir,
41996 &proc_bus_pci_dev_operations);
41997 proc_initialized = 1;
41998diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
41999index 2111dbb..79e434b 100644
42000--- a/drivers/platform/x86/msi-laptop.c
42001+++ b/drivers/platform/x86/msi-laptop.c
42002@@ -820,12 +820,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
42003 int result;
42004
42005 /* allow userland write sysfs file */
42006- dev_attr_bluetooth.store = store_bluetooth;
42007- dev_attr_wlan.store = store_wlan;
42008- dev_attr_threeg.store = store_threeg;
42009- dev_attr_bluetooth.attr.mode |= S_IWUSR;
42010- dev_attr_wlan.attr.mode |= S_IWUSR;
42011- dev_attr_threeg.attr.mode |= S_IWUSR;
42012+ pax_open_kernel();
42013+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
42014+ *(void **)&dev_attr_wlan.store = store_wlan;
42015+ *(void **)&dev_attr_threeg.store = store_threeg;
42016+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
42017+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
42018+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
42019+ pax_close_kernel();
42020
42021 /* disable hardware control by fn key */
42022 result = ec_read(MSI_STANDARD_EC_SCM_LOAD_ADDRESS, &data);
42023diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
42024index 0fe987f..6f3d5c3 100644
42025--- a/drivers/platform/x86/sony-laptop.c
42026+++ b/drivers/platform/x86/sony-laptop.c
42027@@ -2356,7 +2356,7 @@ static void sony_nc_lid_resume_cleanup(struct platform_device *pd)
42028 }
42029
42030 /* High speed charging function */
42031-static struct device_attribute *hsc_handle;
42032+static device_attribute_no_const *hsc_handle;
42033
42034 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
42035 struct device_attribute *attr,
42036diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
42037index f946ca7..f25c833 100644
42038--- a/drivers/platform/x86/thinkpad_acpi.c
42039+++ b/drivers/platform/x86/thinkpad_acpi.c
42040@@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
42041 return 0;
42042 }
42043
42044-void static hotkey_mask_warn_incomplete_mask(void)
42045+static void hotkey_mask_warn_incomplete_mask(void)
42046 {
42047 /* log only what the user can fix... */
42048 const u32 wantedmask = hotkey_driver_mask &
42049@@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
42050 }
42051 }
42052
42053-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
42054- struct tp_nvram_state *newn,
42055- const u32 event_mask)
42056-{
42057-
42058 #define TPACPI_COMPARE_KEY(__scancode, __member) \
42059 do { \
42060 if ((event_mask & (1 << __scancode)) && \
42061@@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
42062 tpacpi_hotkey_send_key(__scancode); \
42063 } while (0)
42064
42065- void issue_volchange(const unsigned int oldvol,
42066- const unsigned int newvol)
42067- {
42068- unsigned int i = oldvol;
42069+static void issue_volchange(const unsigned int oldvol,
42070+ const unsigned int newvol,
42071+ const u32 event_mask)
42072+{
42073+ unsigned int i = oldvol;
42074
42075- while (i > newvol) {
42076- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
42077- i--;
42078- }
42079- while (i < newvol) {
42080- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
42081- i++;
42082- }
42083+ while (i > newvol) {
42084+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
42085+ i--;
42086 }
42087+ while (i < newvol) {
42088+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
42089+ i++;
42090+ }
42091+}
42092
42093- void issue_brightnesschange(const unsigned int oldbrt,
42094- const unsigned int newbrt)
42095- {
42096- unsigned int i = oldbrt;
42097+static void issue_brightnesschange(const unsigned int oldbrt,
42098+ const unsigned int newbrt,
42099+ const u32 event_mask)
42100+{
42101+ unsigned int i = oldbrt;
42102
42103- while (i > newbrt) {
42104- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
42105- i--;
42106- }
42107- while (i < newbrt) {
42108- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
42109- i++;
42110- }
42111+ while (i > newbrt) {
42112+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
42113+ i--;
42114+ }
42115+ while (i < newbrt) {
42116+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
42117+ i++;
42118 }
42119+}
42120
42121+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
42122+ struct tp_nvram_state *newn,
42123+ const u32 event_mask)
42124+{
42125 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
42126 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
42127 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
42128@@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
42129 oldn->volume_level != newn->volume_level) {
42130 /* recently muted, or repeated mute keypress, or
42131 * multiple presses ending in mute */
42132- issue_volchange(oldn->volume_level, newn->volume_level);
42133+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
42134 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
42135 }
42136 } else {
42137@@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
42138 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
42139 }
42140 if (oldn->volume_level != newn->volume_level) {
42141- issue_volchange(oldn->volume_level, newn->volume_level);
42142+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
42143 } else if (oldn->volume_toggle != newn->volume_toggle) {
42144 /* repeated vol up/down keypress at end of scale ? */
42145 if (newn->volume_level == 0)
42146@@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
42147 /* handle brightness */
42148 if (oldn->brightness_level != newn->brightness_level) {
42149 issue_brightnesschange(oldn->brightness_level,
42150- newn->brightness_level);
42151+ newn->brightness_level,
42152+ event_mask);
42153 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
42154 /* repeated key presses that didn't change state */
42155 if (newn->brightness_level == 0)
42156@@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
42157 && !tp_features.bright_unkfw)
42158 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
42159 }
42160+}
42161
42162 #undef TPACPI_COMPARE_KEY
42163 #undef TPACPI_MAY_SEND_KEY
42164-}
42165
42166 /*
42167 * Polling driver
42168diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
42169index 769d265..a3a05ca 100644
42170--- a/drivers/pnp/pnpbios/bioscalls.c
42171+++ b/drivers/pnp/pnpbios/bioscalls.c
42172@@ -58,7 +58,7 @@ do { \
42173 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
42174 } while(0)
42175
42176-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
42177+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
42178 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
42179
42180 /*
42181@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
42182
42183 cpu = get_cpu();
42184 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
42185+
42186+ pax_open_kernel();
42187 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
42188+ pax_close_kernel();
42189
42190 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
42191 spin_lock_irqsave(&pnp_bios_lock, flags);
42192@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
42193 :"memory");
42194 spin_unlock_irqrestore(&pnp_bios_lock, flags);
42195
42196+ pax_open_kernel();
42197 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
42198+ pax_close_kernel();
42199+
42200 put_cpu();
42201
42202 /* If we get here and this is set then the PnP BIOS faulted on us. */
42203@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
42204 return status;
42205 }
42206
42207-void pnpbios_calls_init(union pnp_bios_install_struct *header)
42208+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
42209 {
42210 int i;
42211
42212@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
42213 pnp_bios_callpoint.offset = header->fields.pm16offset;
42214 pnp_bios_callpoint.segment = PNP_CS16;
42215
42216+ pax_open_kernel();
42217+
42218 for_each_possible_cpu(i) {
42219 struct desc_struct *gdt = get_cpu_gdt_table(i);
42220 if (!gdt)
42221@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
42222 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
42223 (unsigned long)__va(header->fields.pm16dseg));
42224 }
42225+
42226+ pax_close_kernel();
42227 }
42228diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
42229index 3e6db1c..1fbbdae 100644
42230--- a/drivers/pnp/resource.c
42231+++ b/drivers/pnp/resource.c
42232@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
42233 return 1;
42234
42235 /* check if the resource is valid */
42236- if (*irq < 0 || *irq > 15)
42237+ if (*irq > 15)
42238 return 0;
42239
42240 /* check if the resource is reserved */
42241@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
42242 return 1;
42243
42244 /* check if the resource is valid */
42245- if (*dma < 0 || *dma == 4 || *dma > 7)
42246+ if (*dma == 4 || *dma > 7)
42247 return 0;
42248
42249 /* check if the resource is reserved */
42250diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
42251index 7df7c5f..bd48c47 100644
42252--- a/drivers/power/pda_power.c
42253+++ b/drivers/power/pda_power.c
42254@@ -37,7 +37,11 @@ static int polling;
42255
42256 #ifdef CONFIG_USB_OTG_UTILS
42257 static struct usb_phy *transceiver;
42258-static struct notifier_block otg_nb;
42259+static int otg_handle_notification(struct notifier_block *nb,
42260+ unsigned long event, void *unused);
42261+static struct notifier_block otg_nb = {
42262+ .notifier_call = otg_handle_notification
42263+};
42264 #endif
42265
42266 static struct regulator *ac_draw;
42267@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
42268
42269 #ifdef CONFIG_USB_OTG_UTILS
42270 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
42271- otg_nb.notifier_call = otg_handle_notification;
42272 ret = usb_register_notifier(transceiver, &otg_nb);
42273 if (ret) {
42274 dev_err(dev, "failure to register otg notifier\n");
42275diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
42276index cc439fd..8fa30df 100644
42277--- a/drivers/power/power_supply.h
42278+++ b/drivers/power/power_supply.h
42279@@ -16,12 +16,12 @@ struct power_supply;
42280
42281 #ifdef CONFIG_SYSFS
42282
42283-extern void power_supply_init_attrs(struct device_type *dev_type);
42284+extern void power_supply_init_attrs(void);
42285 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
42286
42287 #else
42288
42289-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
42290+static inline void power_supply_init_attrs(void) {}
42291 #define power_supply_uevent NULL
42292
42293 #endif /* CONFIG_SYSFS */
42294diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
42295index 8a7cfb3..72e6e9b 100644
42296--- a/drivers/power/power_supply_core.c
42297+++ b/drivers/power/power_supply_core.c
42298@@ -24,7 +24,10 @@
42299 struct class *power_supply_class;
42300 EXPORT_SYMBOL_GPL(power_supply_class);
42301
42302-static struct device_type power_supply_dev_type;
42303+extern const struct attribute_group *power_supply_attr_groups[];
42304+static struct device_type power_supply_dev_type = {
42305+ .groups = power_supply_attr_groups,
42306+};
42307
42308 static int __power_supply_changed_work(struct device *dev, void *data)
42309 {
42310@@ -393,7 +396,7 @@ static int __init power_supply_class_init(void)
42311 return PTR_ERR(power_supply_class);
42312
42313 power_supply_class->dev_uevent = power_supply_uevent;
42314- power_supply_init_attrs(&power_supply_dev_type);
42315+ power_supply_init_attrs();
42316
42317 return 0;
42318 }
42319diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
42320index 40fa3b7..d9c2e0e 100644
42321--- a/drivers/power/power_supply_sysfs.c
42322+++ b/drivers/power/power_supply_sysfs.c
42323@@ -229,17 +229,15 @@ static struct attribute_group power_supply_attr_group = {
42324 .is_visible = power_supply_attr_is_visible,
42325 };
42326
42327-static const struct attribute_group *power_supply_attr_groups[] = {
42328+const struct attribute_group *power_supply_attr_groups[] = {
42329 &power_supply_attr_group,
42330 NULL,
42331 };
42332
42333-void power_supply_init_attrs(struct device_type *dev_type)
42334+void power_supply_init_attrs(void)
42335 {
42336 int i;
42337
42338- dev_type->groups = power_supply_attr_groups;
42339-
42340 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
42341 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
42342 }
42343diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
42344index 4d7c635..9860196 100644
42345--- a/drivers/regulator/max8660.c
42346+++ b/drivers/regulator/max8660.c
42347@@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
42348 max8660->shadow_regs[MAX8660_OVER1] = 5;
42349 } else {
42350 /* Otherwise devices can be toggled via software */
42351- max8660_dcdc_ops.enable = max8660_dcdc_enable;
42352- max8660_dcdc_ops.disable = max8660_dcdc_disable;
42353+ pax_open_kernel();
42354+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
42355+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
42356+ pax_close_kernel();
42357 }
42358
42359 /*
42360diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
42361index 9a8ea91..c483dd9 100644
42362--- a/drivers/regulator/max8973-regulator.c
42363+++ b/drivers/regulator/max8973-regulator.c
42364@@ -401,9 +401,11 @@ static int max8973_probe(struct i2c_client *client,
42365 if (!pdata->enable_ext_control) {
42366 max->desc.enable_reg = MAX8973_VOUT;
42367 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
42368- max8973_dcdc_ops.enable = regulator_enable_regmap;
42369- max8973_dcdc_ops.disable = regulator_disable_regmap;
42370- max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
42371+ pax_open_kernel();
42372+ *(void **)&max8973_dcdc_ops.enable = regulator_enable_regmap;
42373+ *(void **)&max8973_dcdc_ops.disable = regulator_disable_regmap;
42374+ *(void **)&max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
42375+ pax_close_kernel();
42376 }
42377
42378 max->enable_external_control = pdata->enable_ext_control;
42379diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
42380index 0d84b1f..c2da6ac 100644
42381--- a/drivers/regulator/mc13892-regulator.c
42382+++ b/drivers/regulator/mc13892-regulator.c
42383@@ -540,10 +540,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
42384 }
42385 mc13xxx_unlock(mc13892);
42386
42387- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
42388+ pax_open_kernel();
42389+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
42390 = mc13892_vcam_set_mode;
42391- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
42392+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
42393 = mc13892_vcam_get_mode;
42394+ pax_close_kernel();
42395
42396 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
42397 ARRAY_SIZE(mc13892_regulators));
42398diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
42399index 16630aa..6afc992 100644
42400--- a/drivers/rtc/rtc-cmos.c
42401+++ b/drivers/rtc/rtc-cmos.c
42402@@ -724,7 +724,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
42403 hpet_rtc_timer_init();
42404
42405 /* export at least the first block of NVRAM */
42406- nvram.size = address_space - NVRAM_OFFSET;
42407+ pax_open_kernel();
42408+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
42409+ pax_close_kernel();
42410 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
42411 if (retval < 0) {
42412 dev_dbg(dev, "can't create nvram file? %d\n", retval);
42413diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
42414index 9a86b4b..3a383dc 100644
42415--- a/drivers/rtc/rtc-dev.c
42416+++ b/drivers/rtc/rtc-dev.c
42417@@ -14,6 +14,7 @@
42418 #include <linux/module.h>
42419 #include <linux/rtc.h>
42420 #include <linux/sched.h>
42421+#include <linux/grsecurity.h>
42422 #include "rtc-core.h"
42423
42424 static dev_t rtc_devt;
42425@@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
42426 if (copy_from_user(&tm, uarg, sizeof(tm)))
42427 return -EFAULT;
42428
42429+ gr_log_timechange();
42430+
42431 return rtc_set_time(rtc, &tm);
42432
42433 case RTC_PIE_ON:
42434diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
42435index e0d0ba4..3c65868 100644
42436--- a/drivers/rtc/rtc-ds1307.c
42437+++ b/drivers/rtc/rtc-ds1307.c
42438@@ -106,7 +106,7 @@ struct ds1307 {
42439 u8 offset; /* register's offset */
42440 u8 regs[11];
42441 u16 nvram_offset;
42442- struct bin_attribute *nvram;
42443+ bin_attribute_no_const *nvram;
42444 enum ds_type type;
42445 unsigned long flags;
42446 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
42447diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
42448index 130f29a..6179d03 100644
42449--- a/drivers/rtc/rtc-m48t59.c
42450+++ b/drivers/rtc/rtc-m48t59.c
42451@@ -482,7 +482,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
42452 goto out;
42453 }
42454
42455- m48t59_nvram_attr.size = pdata->offset;
42456+ pax_open_kernel();
42457+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
42458+ pax_close_kernel();
42459
42460 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
42461 if (ret) {
42462diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
42463index e693af6..2e525b6 100644
42464--- a/drivers/scsi/bfa/bfa_fcpim.h
42465+++ b/drivers/scsi/bfa/bfa_fcpim.h
42466@@ -36,7 +36,7 @@ struct bfa_iotag_s {
42467
42468 struct bfa_itn_s {
42469 bfa_isr_func_t isr;
42470-};
42471+} __no_const;
42472
42473 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
42474 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
42475diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
42476index 23a90e7..9cf04ee 100644
42477--- a/drivers/scsi/bfa/bfa_ioc.h
42478+++ b/drivers/scsi/bfa/bfa_ioc.h
42479@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
42480 bfa_ioc_disable_cbfn_t disable_cbfn;
42481 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
42482 bfa_ioc_reset_cbfn_t reset_cbfn;
42483-};
42484+} __no_const;
42485
42486 /*
42487 * IOC event notification mechanism.
42488@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
42489 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
42490 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
42491 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
42492-};
42493+} __no_const;
42494
42495 /*
42496 * Queue element to wait for room in request queue. FIFO order is
42497diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
42498index 593085a..47aa999 100644
42499--- a/drivers/scsi/hosts.c
42500+++ b/drivers/scsi/hosts.c
42501@@ -42,7 +42,7 @@
42502 #include "scsi_logging.h"
42503
42504
42505-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
42506+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
42507
42508
42509 static void scsi_host_cls_release(struct device *dev)
42510@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
42511 * subtract one because we increment first then return, but we need to
42512 * know what the next host number was before increment
42513 */
42514- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
42515+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
42516 shost->dma_channel = 0xff;
42517
42518 /* These three are default values which can be overridden */
42519diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
42520index 4f33806..afd6f60 100644
42521--- a/drivers/scsi/hpsa.c
42522+++ b/drivers/scsi/hpsa.c
42523@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
42524 unsigned long flags;
42525
42526 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
42527- return h->access.command_completed(h, q);
42528+ return h->access->command_completed(h, q);
42529
42530 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
42531 a = rq->head[rq->current_entry];
42532@@ -3374,7 +3374,7 @@ static void start_io(struct ctlr_info *h)
42533 while (!list_empty(&h->reqQ)) {
42534 c = list_entry(h->reqQ.next, struct CommandList, list);
42535 /* can't do anything if fifo is full */
42536- if ((h->access.fifo_full(h))) {
42537+ if ((h->access->fifo_full(h))) {
42538 dev_warn(&h->pdev->dev, "fifo full\n");
42539 break;
42540 }
42541@@ -3396,7 +3396,7 @@ static void start_io(struct ctlr_info *h)
42542
42543 /* Tell the controller execute command */
42544 spin_unlock_irqrestore(&h->lock, flags);
42545- h->access.submit_command(h, c);
42546+ h->access->submit_command(h, c);
42547 spin_lock_irqsave(&h->lock, flags);
42548 }
42549 spin_unlock_irqrestore(&h->lock, flags);
42550@@ -3404,17 +3404,17 @@ static void start_io(struct ctlr_info *h)
42551
42552 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
42553 {
42554- return h->access.command_completed(h, q);
42555+ return h->access->command_completed(h, q);
42556 }
42557
42558 static inline bool interrupt_pending(struct ctlr_info *h)
42559 {
42560- return h->access.intr_pending(h);
42561+ return h->access->intr_pending(h);
42562 }
42563
42564 static inline long interrupt_not_for_us(struct ctlr_info *h)
42565 {
42566- return (h->access.intr_pending(h) == 0) ||
42567+ return (h->access->intr_pending(h) == 0) ||
42568 (h->interrupts_enabled == 0);
42569 }
42570
42571@@ -4316,7 +4316,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
42572 if (prod_index < 0)
42573 return -ENODEV;
42574 h->product_name = products[prod_index].product_name;
42575- h->access = *(products[prod_index].access);
42576+ h->access = products[prod_index].access;
42577
42578 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
42579 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
42580@@ -4598,7 +4598,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
42581
42582 assert_spin_locked(&lockup_detector_lock);
42583 remove_ctlr_from_lockup_detector_list(h);
42584- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42585+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42586 spin_lock_irqsave(&h->lock, flags);
42587 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
42588 spin_unlock_irqrestore(&h->lock, flags);
42589@@ -4775,7 +4775,7 @@ reinit_after_soft_reset:
42590 }
42591
42592 /* make sure the board interrupts are off */
42593- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42594+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42595
42596 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
42597 goto clean2;
42598@@ -4809,7 +4809,7 @@ reinit_after_soft_reset:
42599 * fake ones to scoop up any residual completions.
42600 */
42601 spin_lock_irqsave(&h->lock, flags);
42602- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42603+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42604 spin_unlock_irqrestore(&h->lock, flags);
42605 free_irqs(h);
42606 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
42607@@ -4828,9 +4828,9 @@ reinit_after_soft_reset:
42608 dev_info(&h->pdev->dev, "Board READY.\n");
42609 dev_info(&h->pdev->dev,
42610 "Waiting for stale completions to drain.\n");
42611- h->access.set_intr_mask(h, HPSA_INTR_ON);
42612+ h->access->set_intr_mask(h, HPSA_INTR_ON);
42613 msleep(10000);
42614- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42615+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42616
42617 rc = controller_reset_failed(h->cfgtable);
42618 if (rc)
42619@@ -4851,7 +4851,7 @@ reinit_after_soft_reset:
42620 }
42621
42622 /* Turn the interrupts on so we can service requests */
42623- h->access.set_intr_mask(h, HPSA_INTR_ON);
42624+ h->access->set_intr_mask(h, HPSA_INTR_ON);
42625
42626 hpsa_hba_inquiry(h);
42627 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
42628@@ -4903,7 +4903,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
42629 * To write all data in the battery backed cache to disks
42630 */
42631 hpsa_flush_cache(h);
42632- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42633+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42634 hpsa_free_irqs_and_disable_msix(h);
42635 }
42636
42637@@ -5071,7 +5071,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
42638 return;
42639 }
42640 /* Change the access methods to the performant access methods */
42641- h->access = SA5_performant_access;
42642+ h->access = &SA5_performant_access;
42643 h->transMethod = CFGTBL_Trans_Performant;
42644 }
42645
42646diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
42647index 9816479..c5d4e97 100644
42648--- a/drivers/scsi/hpsa.h
42649+++ b/drivers/scsi/hpsa.h
42650@@ -79,7 +79,7 @@ struct ctlr_info {
42651 unsigned int msix_vector;
42652 unsigned int msi_vector;
42653 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
42654- struct access_method access;
42655+ struct access_method *access;
42656
42657 /* queue and queue Info */
42658 struct list_head reqQ;
42659diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
42660index c772d8d..35c362c 100644
42661--- a/drivers/scsi/libfc/fc_exch.c
42662+++ b/drivers/scsi/libfc/fc_exch.c
42663@@ -100,12 +100,12 @@ struct fc_exch_mgr {
42664 u16 pool_max_index;
42665
42666 struct {
42667- atomic_t no_free_exch;
42668- atomic_t no_free_exch_xid;
42669- atomic_t xid_not_found;
42670- atomic_t xid_busy;
42671- atomic_t seq_not_found;
42672- atomic_t non_bls_resp;
42673+ atomic_unchecked_t no_free_exch;
42674+ atomic_unchecked_t no_free_exch_xid;
42675+ atomic_unchecked_t xid_not_found;
42676+ atomic_unchecked_t xid_busy;
42677+ atomic_unchecked_t seq_not_found;
42678+ atomic_unchecked_t non_bls_resp;
42679 } stats;
42680 };
42681
42682@@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
42683 /* allocate memory for exchange */
42684 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
42685 if (!ep) {
42686- atomic_inc(&mp->stats.no_free_exch);
42687+ atomic_inc_unchecked(&mp->stats.no_free_exch);
42688 goto out;
42689 }
42690 memset(ep, 0, sizeof(*ep));
42691@@ -786,7 +786,7 @@ out:
42692 return ep;
42693 err:
42694 spin_unlock_bh(&pool->lock);
42695- atomic_inc(&mp->stats.no_free_exch_xid);
42696+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
42697 mempool_free(ep, mp->ep_pool);
42698 return NULL;
42699 }
42700@@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42701 xid = ntohs(fh->fh_ox_id); /* we originated exch */
42702 ep = fc_exch_find(mp, xid);
42703 if (!ep) {
42704- atomic_inc(&mp->stats.xid_not_found);
42705+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42706 reject = FC_RJT_OX_ID;
42707 goto out;
42708 }
42709@@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42710 ep = fc_exch_find(mp, xid);
42711 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
42712 if (ep) {
42713- atomic_inc(&mp->stats.xid_busy);
42714+ atomic_inc_unchecked(&mp->stats.xid_busy);
42715 reject = FC_RJT_RX_ID;
42716 goto rel;
42717 }
42718@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42719 }
42720 xid = ep->xid; /* get our XID */
42721 } else if (!ep) {
42722- atomic_inc(&mp->stats.xid_not_found);
42723+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42724 reject = FC_RJT_RX_ID; /* XID not found */
42725 goto out;
42726 }
42727@@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42728 } else {
42729 sp = &ep->seq;
42730 if (sp->id != fh->fh_seq_id) {
42731- atomic_inc(&mp->stats.seq_not_found);
42732+ atomic_inc_unchecked(&mp->stats.seq_not_found);
42733 if (f_ctl & FC_FC_END_SEQ) {
42734 /*
42735 * Update sequence_id based on incoming last
42736@@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
42737
42738 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
42739 if (!ep) {
42740- atomic_inc(&mp->stats.xid_not_found);
42741+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42742 goto out;
42743 }
42744 if (ep->esb_stat & ESB_ST_COMPLETE) {
42745- atomic_inc(&mp->stats.xid_not_found);
42746+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42747 goto rel;
42748 }
42749 if (ep->rxid == FC_XID_UNKNOWN)
42750 ep->rxid = ntohs(fh->fh_rx_id);
42751 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
42752- atomic_inc(&mp->stats.xid_not_found);
42753+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42754 goto rel;
42755 }
42756 if (ep->did != ntoh24(fh->fh_s_id) &&
42757 ep->did != FC_FID_FLOGI) {
42758- atomic_inc(&mp->stats.xid_not_found);
42759+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42760 goto rel;
42761 }
42762 sof = fr_sof(fp);
42763@@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
42764 sp->ssb_stat |= SSB_ST_RESP;
42765 sp->id = fh->fh_seq_id;
42766 } else if (sp->id != fh->fh_seq_id) {
42767- atomic_inc(&mp->stats.seq_not_found);
42768+ atomic_inc_unchecked(&mp->stats.seq_not_found);
42769 goto rel;
42770 }
42771
42772@@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
42773 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
42774
42775 if (!sp)
42776- atomic_inc(&mp->stats.xid_not_found);
42777+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42778 else
42779- atomic_inc(&mp->stats.non_bls_resp);
42780+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
42781
42782 fc_frame_free(fp);
42783 }
42784@@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
42785
42786 list_for_each_entry(ema, &lport->ema_list, ema_list) {
42787 mp = ema->mp;
42788- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
42789+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
42790 st->fc_no_free_exch_xid +=
42791- atomic_read(&mp->stats.no_free_exch_xid);
42792- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
42793- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
42794- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
42795- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
42796+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
42797+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
42798+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
42799+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
42800+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
42801 }
42802 }
42803 EXPORT_SYMBOL(fc_exch_update_stats);
42804diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
42805index bdb81cd..d3c7c2c 100644
42806--- a/drivers/scsi/libsas/sas_ata.c
42807+++ b/drivers/scsi/libsas/sas_ata.c
42808@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
42809 .postreset = ata_std_postreset,
42810 .error_handler = ata_std_error_handler,
42811 .post_internal_cmd = sas_ata_post_internal,
42812- .qc_defer = ata_std_qc_defer,
42813+ .qc_defer = ata_std_qc_defer,
42814 .qc_prep = ata_noop_qc_prep,
42815 .qc_issue = sas_ata_qc_issue,
42816 .qc_fill_rtf = sas_ata_qc_fill_rtf,
42817diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
42818index df4c13a..a51e90c 100644
42819--- a/drivers/scsi/lpfc/lpfc.h
42820+++ b/drivers/scsi/lpfc/lpfc.h
42821@@ -424,7 +424,7 @@ struct lpfc_vport {
42822 struct dentry *debug_nodelist;
42823 struct dentry *vport_debugfs_root;
42824 struct lpfc_debugfs_trc *disc_trc;
42825- atomic_t disc_trc_cnt;
42826+ atomic_unchecked_t disc_trc_cnt;
42827 #endif
42828 uint8_t stat_data_enabled;
42829 uint8_t stat_data_blocked;
42830@@ -842,8 +842,8 @@ struct lpfc_hba {
42831 struct timer_list fabric_block_timer;
42832 unsigned long bit_flags;
42833 #define FABRIC_COMANDS_BLOCKED 0
42834- atomic_t num_rsrc_err;
42835- atomic_t num_cmd_success;
42836+ atomic_unchecked_t num_rsrc_err;
42837+ atomic_unchecked_t num_cmd_success;
42838 unsigned long last_rsrc_error_time;
42839 unsigned long last_ramp_down_time;
42840 unsigned long last_ramp_up_time;
42841@@ -879,7 +879,7 @@ struct lpfc_hba {
42842
42843 struct dentry *debug_slow_ring_trc;
42844 struct lpfc_debugfs_trc *slow_ring_trc;
42845- atomic_t slow_ring_trc_cnt;
42846+ atomic_unchecked_t slow_ring_trc_cnt;
42847 /* iDiag debugfs sub-directory */
42848 struct dentry *idiag_root;
42849 struct dentry *idiag_pci_cfg;
42850diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
42851index f63f5ff..de29189 100644
42852--- a/drivers/scsi/lpfc/lpfc_debugfs.c
42853+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
42854@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
42855
42856 #include <linux/debugfs.h>
42857
42858-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
42859+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
42860 static unsigned long lpfc_debugfs_start_time = 0L;
42861
42862 /* iDiag */
42863@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
42864 lpfc_debugfs_enable = 0;
42865
42866 len = 0;
42867- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
42868+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
42869 (lpfc_debugfs_max_disc_trc - 1);
42870 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
42871 dtp = vport->disc_trc + i;
42872@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
42873 lpfc_debugfs_enable = 0;
42874
42875 len = 0;
42876- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
42877+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
42878 (lpfc_debugfs_max_slow_ring_trc - 1);
42879 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
42880 dtp = phba->slow_ring_trc + i;
42881@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
42882 !vport || !vport->disc_trc)
42883 return;
42884
42885- index = atomic_inc_return(&vport->disc_trc_cnt) &
42886+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
42887 (lpfc_debugfs_max_disc_trc - 1);
42888 dtp = vport->disc_trc + index;
42889 dtp->fmt = fmt;
42890 dtp->data1 = data1;
42891 dtp->data2 = data2;
42892 dtp->data3 = data3;
42893- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
42894+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
42895 dtp->jif = jiffies;
42896 #endif
42897 return;
42898@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
42899 !phba || !phba->slow_ring_trc)
42900 return;
42901
42902- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
42903+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
42904 (lpfc_debugfs_max_slow_ring_trc - 1);
42905 dtp = phba->slow_ring_trc + index;
42906 dtp->fmt = fmt;
42907 dtp->data1 = data1;
42908 dtp->data2 = data2;
42909 dtp->data3 = data3;
42910- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
42911+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
42912 dtp->jif = jiffies;
42913 #endif
42914 return;
42915@@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
42916 "slow_ring buffer\n");
42917 goto debug_failed;
42918 }
42919- atomic_set(&phba->slow_ring_trc_cnt, 0);
42920+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
42921 memset(phba->slow_ring_trc, 0,
42922 (sizeof(struct lpfc_debugfs_trc) *
42923 lpfc_debugfs_max_slow_ring_trc));
42924@@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
42925 "buffer\n");
42926 goto debug_failed;
42927 }
42928- atomic_set(&vport->disc_trc_cnt, 0);
42929+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
42930
42931 snprintf(name, sizeof(name), "discovery_trace");
42932 vport->debug_disc_trc =
42933diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
42934index 89ad558..76956c4 100644
42935--- a/drivers/scsi/lpfc/lpfc_init.c
42936+++ b/drivers/scsi/lpfc/lpfc_init.c
42937@@ -10618,8 +10618,10 @@ lpfc_init(void)
42938 "misc_register returned with status %d", error);
42939
42940 if (lpfc_enable_npiv) {
42941- lpfc_transport_functions.vport_create = lpfc_vport_create;
42942- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
42943+ pax_open_kernel();
42944+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
42945+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
42946+ pax_close_kernel();
42947 }
42948 lpfc_transport_template =
42949 fc_attach_transport(&lpfc_transport_functions);
42950diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
42951index 60e5a17..ff7a793 100644
42952--- a/drivers/scsi/lpfc/lpfc_scsi.c
42953+++ b/drivers/scsi/lpfc/lpfc_scsi.c
42954@@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
42955 uint32_t evt_posted;
42956
42957 spin_lock_irqsave(&phba->hbalock, flags);
42958- atomic_inc(&phba->num_rsrc_err);
42959+ atomic_inc_unchecked(&phba->num_rsrc_err);
42960 phba->last_rsrc_error_time = jiffies;
42961
42962 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
42963@@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
42964 unsigned long flags;
42965 struct lpfc_hba *phba = vport->phba;
42966 uint32_t evt_posted;
42967- atomic_inc(&phba->num_cmd_success);
42968+ atomic_inc_unchecked(&phba->num_cmd_success);
42969
42970 if (vport->cfg_lun_queue_depth <= queue_depth)
42971 return;
42972@@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
42973 unsigned long num_rsrc_err, num_cmd_success;
42974 int i;
42975
42976- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
42977- num_cmd_success = atomic_read(&phba->num_cmd_success);
42978+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
42979+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
42980
42981 /*
42982 * The error and success command counters are global per
42983@@ -419,8 +419,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
42984 }
42985 }
42986 lpfc_destroy_vport_work_array(phba, vports);
42987- atomic_set(&phba->num_rsrc_err, 0);
42988- atomic_set(&phba->num_cmd_success, 0);
42989+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
42990+ atomic_set_unchecked(&phba->num_cmd_success, 0);
42991 }
42992
42993 /**
42994@@ -454,8 +454,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
42995 }
42996 }
42997 lpfc_destroy_vport_work_array(phba, vports);
42998- atomic_set(&phba->num_rsrc_err, 0);
42999- atomic_set(&phba->num_cmd_success, 0);
43000+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
43001+ atomic_set_unchecked(&phba->num_cmd_success, 0);
43002 }
43003
43004 /**
43005diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
43006index b46f5e9..c4c4ccb 100644
43007--- a/drivers/scsi/pmcraid.c
43008+++ b/drivers/scsi/pmcraid.c
43009@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
43010 res->scsi_dev = scsi_dev;
43011 scsi_dev->hostdata = res;
43012 res->change_detected = 0;
43013- atomic_set(&res->read_failures, 0);
43014- atomic_set(&res->write_failures, 0);
43015+ atomic_set_unchecked(&res->read_failures, 0);
43016+ atomic_set_unchecked(&res->write_failures, 0);
43017 rc = 0;
43018 }
43019 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
43020@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
43021
43022 /* If this was a SCSI read/write command keep count of errors */
43023 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
43024- atomic_inc(&res->read_failures);
43025+ atomic_inc_unchecked(&res->read_failures);
43026 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
43027- atomic_inc(&res->write_failures);
43028+ atomic_inc_unchecked(&res->write_failures);
43029
43030 if (!RES_IS_GSCSI(res->cfg_entry) &&
43031 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
43032@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
43033 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
43034 * hrrq_id assigned here in queuecommand
43035 */
43036- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
43037+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
43038 pinstance->num_hrrq;
43039 cmd->cmd_done = pmcraid_io_done;
43040
43041@@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
43042 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
43043 * hrrq_id assigned here in queuecommand
43044 */
43045- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
43046+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
43047 pinstance->num_hrrq;
43048
43049 if (request_size) {
43050@@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
43051
43052 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
43053 /* add resources only after host is added into system */
43054- if (!atomic_read(&pinstance->expose_resources))
43055+ if (!atomic_read_unchecked(&pinstance->expose_resources))
43056 return;
43057
43058 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
43059@@ -5324,8 +5324,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
43060 init_waitqueue_head(&pinstance->reset_wait_q);
43061
43062 atomic_set(&pinstance->outstanding_cmds, 0);
43063- atomic_set(&pinstance->last_message_id, 0);
43064- atomic_set(&pinstance->expose_resources, 0);
43065+ atomic_set_unchecked(&pinstance->last_message_id, 0);
43066+ atomic_set_unchecked(&pinstance->expose_resources, 0);
43067
43068 INIT_LIST_HEAD(&pinstance->free_res_q);
43069 INIT_LIST_HEAD(&pinstance->used_res_q);
43070@@ -6038,7 +6038,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
43071 /* Schedule worker thread to handle CCN and take care of adding and
43072 * removing devices to OS
43073 */
43074- atomic_set(&pinstance->expose_resources, 1);
43075+ atomic_set_unchecked(&pinstance->expose_resources, 1);
43076 schedule_work(&pinstance->worker_q);
43077 return rc;
43078
43079diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
43080index e1d150f..6c6df44 100644
43081--- a/drivers/scsi/pmcraid.h
43082+++ b/drivers/scsi/pmcraid.h
43083@@ -748,7 +748,7 @@ struct pmcraid_instance {
43084 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
43085
43086 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
43087- atomic_t last_message_id;
43088+ atomic_unchecked_t last_message_id;
43089
43090 /* configuration table */
43091 struct pmcraid_config_table *cfg_table;
43092@@ -777,7 +777,7 @@ struct pmcraid_instance {
43093 atomic_t outstanding_cmds;
43094
43095 /* should add/delete resources to mid-layer now ?*/
43096- atomic_t expose_resources;
43097+ atomic_unchecked_t expose_resources;
43098
43099
43100
43101@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
43102 struct pmcraid_config_table_entry_ext cfg_entry_ext;
43103 };
43104 struct scsi_device *scsi_dev; /* Link scsi_device structure */
43105- atomic_t read_failures; /* count of failed READ commands */
43106- atomic_t write_failures; /* count of failed WRITE commands */
43107+ atomic_unchecked_t read_failures; /* count of failed READ commands */
43108+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
43109
43110 /* To indicate add/delete/modify during CCN */
43111 u8 change_detected;
43112diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
43113index 83d7984..a27d947 100644
43114--- a/drivers/scsi/qla2xxx/qla_attr.c
43115+++ b/drivers/scsi/qla2xxx/qla_attr.c
43116@@ -1969,7 +1969,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
43117 return 0;
43118 }
43119
43120-struct fc_function_template qla2xxx_transport_functions = {
43121+fc_function_template_no_const qla2xxx_transport_functions = {
43122
43123 .show_host_node_name = 1,
43124 .show_host_port_name = 1,
43125@@ -2016,7 +2016,7 @@ struct fc_function_template qla2xxx_transport_functions = {
43126 .bsg_timeout = qla24xx_bsg_timeout,
43127 };
43128
43129-struct fc_function_template qla2xxx_transport_vport_functions = {
43130+fc_function_template_no_const qla2xxx_transport_vport_functions = {
43131
43132 .show_host_node_name = 1,
43133 .show_host_port_name = 1,
43134diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
43135index 2411d1a..4673766 100644
43136--- a/drivers/scsi/qla2xxx/qla_gbl.h
43137+++ b/drivers/scsi/qla2xxx/qla_gbl.h
43138@@ -515,8 +515,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
43139 struct device_attribute;
43140 extern struct device_attribute *qla2x00_host_attrs[];
43141 struct fc_function_template;
43142-extern struct fc_function_template qla2xxx_transport_functions;
43143-extern struct fc_function_template qla2xxx_transport_vport_functions;
43144+extern fc_function_template_no_const qla2xxx_transport_functions;
43145+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
43146 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
43147 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
43148 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
43149diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
43150index 10d23f8..a7d5d4c 100644
43151--- a/drivers/scsi/qla2xxx/qla_os.c
43152+++ b/drivers/scsi/qla2xxx/qla_os.c
43153@@ -1472,8 +1472,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
43154 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
43155 /* Ok, a 64bit DMA mask is applicable. */
43156 ha->flags.enable_64bit_addressing = 1;
43157- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
43158- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
43159+ pax_open_kernel();
43160+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
43161+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
43162+ pax_close_kernel();
43163 return;
43164 }
43165 }
43166diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
43167index 329d553..f20d31d 100644
43168--- a/drivers/scsi/qla4xxx/ql4_def.h
43169+++ b/drivers/scsi/qla4xxx/ql4_def.h
43170@@ -273,7 +273,7 @@ struct ddb_entry {
43171 * (4000 only) */
43172 atomic_t relogin_timer; /* Max Time to wait for
43173 * relogin to complete */
43174- atomic_t relogin_retry_count; /* Num of times relogin has been
43175+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
43176 * retried */
43177 uint32_t default_time2wait; /* Default Min time between
43178 * relogins (+aens) */
43179diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
43180index 4cec123..7c1329f 100644
43181--- a/drivers/scsi/qla4xxx/ql4_os.c
43182+++ b/drivers/scsi/qla4xxx/ql4_os.c
43183@@ -2621,12 +2621,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
43184 */
43185 if (!iscsi_is_session_online(cls_sess)) {
43186 /* Reset retry relogin timer */
43187- atomic_inc(&ddb_entry->relogin_retry_count);
43188+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
43189 DEBUG2(ql4_printk(KERN_INFO, ha,
43190 "%s: index[%d] relogin timed out-retrying"
43191 " relogin (%d), retry (%d)\n", __func__,
43192 ddb_entry->fw_ddb_index,
43193- atomic_read(&ddb_entry->relogin_retry_count),
43194+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
43195 ddb_entry->default_time2wait + 4));
43196 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
43197 atomic_set(&ddb_entry->retry_relogin_timer,
43198@@ -4738,7 +4738,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
43199
43200 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
43201 atomic_set(&ddb_entry->relogin_timer, 0);
43202- atomic_set(&ddb_entry->relogin_retry_count, 0);
43203+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
43204 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
43205 ddb_entry->default_relogin_timeout =
43206 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
43207diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
43208index 2c0d0ec..4e8681a 100644
43209--- a/drivers/scsi/scsi.c
43210+++ b/drivers/scsi/scsi.c
43211@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
43212 unsigned long timeout;
43213 int rtn = 0;
43214
43215- atomic_inc(&cmd->device->iorequest_cnt);
43216+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
43217
43218 /* check if the device is still usable */
43219 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
43220diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
43221index f1bf5af..f67e943 100644
43222--- a/drivers/scsi/scsi_lib.c
43223+++ b/drivers/scsi/scsi_lib.c
43224@@ -1454,7 +1454,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
43225 shost = sdev->host;
43226 scsi_init_cmd_errh(cmd);
43227 cmd->result = DID_NO_CONNECT << 16;
43228- atomic_inc(&cmd->device->iorequest_cnt);
43229+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
43230
43231 /*
43232 * SCSI request completion path will do scsi_device_unbusy(),
43233@@ -1480,9 +1480,9 @@ static void scsi_softirq_done(struct request *rq)
43234
43235 INIT_LIST_HEAD(&cmd->eh_entry);
43236
43237- atomic_inc(&cmd->device->iodone_cnt);
43238+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
43239 if (cmd->result)
43240- atomic_inc(&cmd->device->ioerr_cnt);
43241+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
43242
43243 disposition = scsi_decide_disposition(cmd);
43244 if (disposition != SUCCESS &&
43245diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
43246index 931a7d9..0c2a754 100644
43247--- a/drivers/scsi/scsi_sysfs.c
43248+++ b/drivers/scsi/scsi_sysfs.c
43249@@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
43250 char *buf) \
43251 { \
43252 struct scsi_device *sdev = to_scsi_device(dev); \
43253- unsigned long long count = atomic_read(&sdev->field); \
43254+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
43255 return snprintf(buf, 20, "0x%llx\n", count); \
43256 } \
43257 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
43258diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
43259index 84a1fdf..693b0d6 100644
43260--- a/drivers/scsi/scsi_tgt_lib.c
43261+++ b/drivers/scsi/scsi_tgt_lib.c
43262@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
43263 int err;
43264
43265 dprintk("%lx %u\n", uaddr, len);
43266- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
43267+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
43268 if (err) {
43269 /*
43270 * TODO: need to fixup sg_tablesize, max_segment_size,
43271diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
43272index e894ca7..de9d7660 100644
43273--- a/drivers/scsi/scsi_transport_fc.c
43274+++ b/drivers/scsi/scsi_transport_fc.c
43275@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
43276 * Netlink Infrastructure
43277 */
43278
43279-static atomic_t fc_event_seq;
43280+static atomic_unchecked_t fc_event_seq;
43281
43282 /**
43283 * fc_get_event_number - Obtain the next sequential FC event number
43284@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
43285 u32
43286 fc_get_event_number(void)
43287 {
43288- return atomic_add_return(1, &fc_event_seq);
43289+ return atomic_add_return_unchecked(1, &fc_event_seq);
43290 }
43291 EXPORT_SYMBOL(fc_get_event_number);
43292
43293@@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
43294 {
43295 int error;
43296
43297- atomic_set(&fc_event_seq, 0);
43298+ atomic_set_unchecked(&fc_event_seq, 0);
43299
43300 error = transport_class_register(&fc_host_class);
43301 if (error)
43302@@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
43303 char *cp;
43304
43305 *val = simple_strtoul(buf, &cp, 0);
43306- if ((*cp && (*cp != '\n')) || (*val < 0))
43307+ if (*cp && (*cp != '\n'))
43308 return -EINVAL;
43309 /*
43310 * Check for overflow; dev_loss_tmo is u32
43311diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
43312index 31969f2..2b348f0 100644
43313--- a/drivers/scsi/scsi_transport_iscsi.c
43314+++ b/drivers/scsi/scsi_transport_iscsi.c
43315@@ -79,7 +79,7 @@ struct iscsi_internal {
43316 struct transport_container session_cont;
43317 };
43318
43319-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
43320+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
43321 static struct workqueue_struct *iscsi_eh_timer_workq;
43322
43323 static DEFINE_IDA(iscsi_sess_ida);
43324@@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
43325 int err;
43326
43327 ihost = shost->shost_data;
43328- session->sid = atomic_add_return(1, &iscsi_session_nr);
43329+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
43330
43331 if (target_id == ISCSI_MAX_TARGET) {
43332 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
43333@@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
43334 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
43335 ISCSI_TRANSPORT_VERSION);
43336
43337- atomic_set(&iscsi_session_nr, 0);
43338+ atomic_set_unchecked(&iscsi_session_nr, 0);
43339
43340 err = class_register(&iscsi_transport_class);
43341 if (err)
43342diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
43343index f379c7f..e8fc69c 100644
43344--- a/drivers/scsi/scsi_transport_srp.c
43345+++ b/drivers/scsi/scsi_transport_srp.c
43346@@ -33,7 +33,7 @@
43347 #include "scsi_transport_srp_internal.h"
43348
43349 struct srp_host_attrs {
43350- atomic_t next_port_id;
43351+ atomic_unchecked_t next_port_id;
43352 };
43353 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
43354
43355@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
43356 struct Scsi_Host *shost = dev_to_shost(dev);
43357 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
43358
43359- atomic_set(&srp_host->next_port_id, 0);
43360+ atomic_set_unchecked(&srp_host->next_port_id, 0);
43361 return 0;
43362 }
43363
43364@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
43365 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
43366 rport->roles = ids->roles;
43367
43368- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
43369+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
43370 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
43371
43372 transport_setup_device(&rport->dev);
43373diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
43374index 7992635..609faf8 100644
43375--- a/drivers/scsi/sd.c
43376+++ b/drivers/scsi/sd.c
43377@@ -2909,7 +2909,7 @@ static int sd_probe(struct device *dev)
43378 sdkp->disk = gd;
43379 sdkp->index = index;
43380 atomic_set(&sdkp->openers, 0);
43381- atomic_set(&sdkp->device->ioerr_cnt, 0);
43382+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
43383
43384 if (!sdp->request_queue->rq_timeout) {
43385 if (sdp->type != TYPE_MOD)
43386diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
43387index be2c9a6..275525c 100644
43388--- a/drivers/scsi/sg.c
43389+++ b/drivers/scsi/sg.c
43390@@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
43391 sdp->disk->disk_name,
43392 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
43393 NULL,
43394- (char *)arg);
43395+ (char __user *)arg);
43396 case BLKTRACESTART:
43397 return blk_trace_startstop(sdp->device->request_queue, 1);
43398 case BLKTRACESTOP:
43399diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
43400index 19ee901..6e8c2ef 100644
43401--- a/drivers/spi/spi.c
43402+++ b/drivers/spi/spi.c
43403@@ -1616,7 +1616,7 @@ int spi_bus_unlock(struct spi_master *master)
43404 EXPORT_SYMBOL_GPL(spi_bus_unlock);
43405
43406 /* portable code must never pass more than 32 bytes */
43407-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
43408+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
43409
43410 static u8 *buf;
43411
43412diff --git a/drivers/staging/iio/iio_hwmon.c b/drivers/staging/iio/iio_hwmon.c
43413index c7a5f97..71ecd35 100644
43414--- a/drivers/staging/iio/iio_hwmon.c
43415+++ b/drivers/staging/iio/iio_hwmon.c
43416@@ -72,7 +72,7 @@ static void iio_hwmon_free_attrs(struct iio_hwmon_state *st)
43417 static int iio_hwmon_probe(struct platform_device *pdev)
43418 {
43419 struct iio_hwmon_state *st;
43420- struct sensor_device_attribute *a;
43421+ sensor_device_attribute_no_const *a;
43422 int ret, i;
43423 int in_i = 1, temp_i = 1, curr_i = 1;
43424 enum iio_chan_type type;
43425diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
43426index 34afc16..ffe44dd 100644
43427--- a/drivers/staging/octeon/ethernet-rx.c
43428+++ b/drivers/staging/octeon/ethernet-rx.c
43429@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
43430 /* Increment RX stats for virtual ports */
43431 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
43432 #ifdef CONFIG_64BIT
43433- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
43434- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
43435+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
43436+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
43437 #else
43438- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
43439- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
43440+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
43441+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
43442 #endif
43443 }
43444 netif_receive_skb(skb);
43445@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
43446 dev->name);
43447 */
43448 #ifdef CONFIG_64BIT
43449- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
43450+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
43451 #else
43452- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
43453+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
43454 #endif
43455 dev_kfree_skb_irq(skb);
43456 }
43457diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
43458index ef32dc1..a159d68 100644
43459--- a/drivers/staging/octeon/ethernet.c
43460+++ b/drivers/staging/octeon/ethernet.c
43461@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
43462 * since the RX tasklet also increments it.
43463 */
43464 #ifdef CONFIG_64BIT
43465- atomic64_add(rx_status.dropped_packets,
43466- (atomic64_t *)&priv->stats.rx_dropped);
43467+ atomic64_add_unchecked(rx_status.dropped_packets,
43468+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
43469 #else
43470- atomic_add(rx_status.dropped_packets,
43471- (atomic_t *)&priv->stats.rx_dropped);
43472+ atomic_add_unchecked(rx_status.dropped_packets,
43473+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
43474 #endif
43475 }
43476
43477diff --git a/drivers/staging/ramster/tmem.c b/drivers/staging/ramster/tmem.c
43478index a2b7e03..aaf3630 100644
43479--- a/drivers/staging/ramster/tmem.c
43480+++ b/drivers/staging/ramster/tmem.c
43481@@ -50,25 +50,25 @@
43482 * A tmem host implementation must use this function to register callbacks
43483 * for memory allocation.
43484 */
43485-static struct tmem_hostops tmem_hostops;
43486+static struct tmem_hostops *tmem_hostops;
43487
43488 static void tmem_objnode_tree_init(void);
43489
43490 void tmem_register_hostops(struct tmem_hostops *m)
43491 {
43492 tmem_objnode_tree_init();
43493- tmem_hostops = *m;
43494+ tmem_hostops = m;
43495 }
43496
43497 /*
43498 * A tmem host implementation must use this function to register
43499 * callbacks for a page-accessible memory (PAM) implementation.
43500 */
43501-static struct tmem_pamops tmem_pamops;
43502+static struct tmem_pamops *tmem_pamops;
43503
43504 void tmem_register_pamops(struct tmem_pamops *m)
43505 {
43506- tmem_pamops = *m;
43507+ tmem_pamops = m;
43508 }
43509
43510 /*
43511@@ -174,7 +174,7 @@ static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb,
43512 obj->pampd_count = 0;
43513 #ifdef CONFIG_RAMSTER
43514 if (tmem_pamops.new_obj != NULL)
43515- (*tmem_pamops.new_obj)(obj);
43516+ (tmem_pamops->new_obj)(obj);
43517 #endif
43518 SET_SENTINEL(obj, OBJ);
43519
43520@@ -210,7 +210,7 @@ static void tmem_pool_flush(struct tmem_pool *pool, bool destroy)
43521 rbnode = rb_next(rbnode);
43522 tmem_pampd_destroy_all_in_obj(obj, true);
43523 tmem_obj_free(obj, hb);
43524- (*tmem_hostops.obj_free)(obj, pool);
43525+ (tmem_hostops->obj_free)(obj, pool);
43526 }
43527 spin_unlock(&hb->lock);
43528 }
43529@@ -261,7 +261,7 @@ static struct tmem_objnode *tmem_objnode_alloc(struct tmem_obj *obj)
43530 ASSERT_SENTINEL(obj, OBJ);
43531 BUG_ON(obj->pool == NULL);
43532 ASSERT_SENTINEL(obj->pool, POOL);
43533- objnode = (*tmem_hostops.objnode_alloc)(obj->pool);
43534+ objnode = (tmem_hostops->objnode_alloc)(obj->pool);
43535 if (unlikely(objnode == NULL))
43536 goto out;
43537 objnode->obj = obj;
43538@@ -290,7 +290,7 @@ static void tmem_objnode_free(struct tmem_objnode *objnode)
43539 ASSERT_SENTINEL(pool, POOL);
43540 objnode->obj->objnode_count--;
43541 objnode->obj = NULL;
43542- (*tmem_hostops.objnode_free)(objnode, pool);
43543+ (tmem_hostops->objnode_free)(objnode, pool);
43544 }
43545
43546 /*
43547@@ -348,7 +348,7 @@ static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index,
43548 void *old_pampd = *(void **)slot;
43549 *(void **)slot = new_pampd;
43550 if (!no_free)
43551- (*tmem_pamops.free)(old_pampd, obj->pool,
43552+ (tmem_pamops->free)(old_pampd, obj->pool,
43553 NULL, 0, false);
43554 ret = new_pampd;
43555 }
43556@@ -505,7 +505,7 @@ static void tmem_objnode_node_destroy(struct tmem_obj *obj,
43557 if (objnode->slots[i]) {
43558 if (ht == 1) {
43559 obj->pampd_count--;
43560- (*tmem_pamops.free)(objnode->slots[i],
43561+ (tmem_pamops->free)(objnode->slots[i],
43562 obj->pool, NULL, 0, true);
43563 objnode->slots[i] = NULL;
43564 continue;
43565@@ -524,7 +524,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
43566 return;
43567 if (obj->objnode_tree_height == 0) {
43568 obj->pampd_count--;
43569- (*tmem_pamops.free)(obj->objnode_tree_root,
43570+ (tmem_pamops->free)(obj->objnode_tree_root,
43571 obj->pool, NULL, 0, true);
43572 } else {
43573 tmem_objnode_node_destroy(obj, obj->objnode_tree_root,
43574@@ -535,7 +535,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
43575 obj->objnode_tree_root = NULL;
43576 #ifdef CONFIG_RAMSTER
43577 if (tmem_pamops.free_obj != NULL)
43578- (*tmem_pamops.free_obj)(obj->pool, obj, pool_destroy);
43579+ (tmem_pamops->free_obj)(obj->pool, obj, pool_destroy);
43580 #endif
43581 }
43582
43583@@ -574,7 +574,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
43584 /* if found, is a dup put, flush the old one */
43585 pampd_del = tmem_pampd_delete_from_obj(obj, index);
43586 BUG_ON(pampd_del != pampd);
43587- (*tmem_pamops.free)(pampd, pool, oidp, index, true);
43588+ (tmem_pamops->free)(pampd, pool, oidp, index, true);
43589 if (obj->pampd_count == 0) {
43590 objnew = obj;
43591 objfound = NULL;
43592@@ -582,7 +582,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
43593 pampd = NULL;
43594 }
43595 } else {
43596- obj = objnew = (*tmem_hostops.obj_alloc)(pool);
43597+ obj = objnew = (tmem_hostops->obj_alloc)(pool);
43598 if (unlikely(obj == NULL)) {
43599 ret = -ENOMEM;
43600 goto out;
43601@@ -597,16 +597,16 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
43602 if (unlikely(ret == -ENOMEM))
43603 /* may have partially built objnode tree ("stump") */
43604 goto delete_and_free;
43605- (*tmem_pamops.create_finish)(pampd, is_ephemeral(pool));
43606+ (tmem_pamops->create_finish)(pampd, is_ephemeral(pool));
43607 goto out;
43608
43609 delete_and_free:
43610 (void)tmem_pampd_delete_from_obj(obj, index);
43611 if (pampd)
43612- (*tmem_pamops.free)(pampd, pool, NULL, 0, true);
43613+ (tmem_pamops->free)(pampd, pool, NULL, 0, true);
43614 if (objnew) {
43615 tmem_obj_free(objnew, hb);
43616- (*tmem_hostops.obj_free)(objnew, pool);
43617+ (tmem_hostops->obj_free)(objnew, pool);
43618 }
43619 out:
43620 spin_unlock(&hb->lock);
43621@@ -651,7 +651,7 @@ void tmem_localify_finish(struct tmem_obj *obj, uint32_t index,
43622 if (pampd != NULL) {
43623 BUG_ON(obj == NULL);
43624 (void)tmem_pampd_replace_in_obj(obj, index, pampd, 1);
43625- (*tmem_pamops.create_finish)(pampd, is_ephemeral(obj->pool));
43626+ (tmem_pamops->create_finish)(pampd, is_ephemeral(obj->pool));
43627 } else if (delete) {
43628 BUG_ON(obj == NULL);
43629 (void)tmem_pampd_delete_from_obj(obj, index);
43630@@ -671,7 +671,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
43631 int ret = 0;
43632
43633 if (!is_ephemeral(pool))
43634- new_pampd = (*tmem_pamops.repatriate_preload)(
43635+ new_pampd = (tmem_pamops->repatriate_preload)(
43636 old_pampd, pool, oidp, index, &intransit);
43637 if (intransit)
43638 ret = -EAGAIN;
43639@@ -680,7 +680,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
43640 /* must release the hb->lock else repatriate can't sleep */
43641 spin_unlock(&hb->lock);
43642 if (!intransit)
43643- ret = (*tmem_pamops.repatriate)(old_pampd, new_pampd, pool,
43644+ ret = (tmem_pamops->repatriate)(old_pampd, new_pampd, pool,
43645 oidp, index, free, data);
43646 if (ret == -EAGAIN) {
43647 /* rare I think, but should cond_resched()??? */
43648@@ -714,7 +714,7 @@ int tmem_replace(struct tmem_pool *pool, struct tmem_oid *oidp,
43649 new_pampd = tmem_pampd_replace_in_obj(obj, index, new_pampd, 0);
43650 /* if we bug here, pamops wasn't properly set up for ramster */
43651 BUG_ON(tmem_pamops.replace_in_obj == NULL);
43652- ret = (*tmem_pamops.replace_in_obj)(new_pampd, obj);
43653+ ret = (tmem_pamops->replace_in_obj)(new_pampd, obj);
43654 out:
43655 spin_unlock(&hb->lock);
43656 return ret;
43657@@ -776,15 +776,15 @@ int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
43658 if (free) {
43659 if (obj->pampd_count == 0) {
43660 tmem_obj_free(obj, hb);
43661- (*tmem_hostops.obj_free)(obj, pool);
43662+ (tmem_hostops->obj_free)(obj, pool);
43663 obj = NULL;
43664 }
43665 }
43666 if (free)
43667- ret = (*tmem_pamops.get_data_and_free)(
43668+ ret = (tmem_pamops->get_data_and_free)(
43669 data, sizep, raw, pampd, pool, oidp, index);
43670 else
43671- ret = (*tmem_pamops.get_data)(
43672+ ret = (tmem_pamops->get_data)(
43673 data, sizep, raw, pampd, pool, oidp, index);
43674 if (ret < 0)
43675 goto out;
43676@@ -816,10 +816,10 @@ int tmem_flush_page(struct tmem_pool *pool,
43677 pampd = tmem_pampd_delete_from_obj(obj, index);
43678 if (pampd == NULL)
43679 goto out;
43680- (*tmem_pamops.free)(pampd, pool, oidp, index, true);
43681+ (tmem_pamops->free)(pampd, pool, oidp, index, true);
43682 if (obj->pampd_count == 0) {
43683 tmem_obj_free(obj, hb);
43684- (*tmem_hostops.obj_free)(obj, pool);
43685+ (tmem_hostops->obj_free)(obj, pool);
43686 }
43687 ret = 0;
43688
43689@@ -844,7 +844,7 @@ int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp)
43690 goto out;
43691 tmem_pampd_destroy_all_in_obj(obj, false);
43692 tmem_obj_free(obj, hb);
43693- (*tmem_hostops.obj_free)(obj, pool);
43694+ (tmem_hostops->obj_free)(obj, pool);
43695 ret = 0;
43696
43697 out:
43698diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
43699index dc23395..cf7e9b1 100644
43700--- a/drivers/staging/rtl8712/rtl871x_io.h
43701+++ b/drivers/staging/rtl8712/rtl871x_io.h
43702@@ -108,7 +108,7 @@ struct _io_ops {
43703 u8 *pmem);
43704 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
43705 u8 *pmem);
43706-};
43707+} __no_const;
43708
43709 struct io_req {
43710 struct list_head list;
43711diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
43712index 1f5088b..0e59820 100644
43713--- a/drivers/staging/sbe-2t3e3/netdev.c
43714+++ b/drivers/staging/sbe-2t3e3/netdev.c
43715@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43716 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
43717
43718 if (rlen)
43719- if (copy_to_user(data, &resp, rlen))
43720+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
43721 return -EFAULT;
43722
43723 return 0;
43724diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
43725index 5dddc4d..34fcb2f 100644
43726--- a/drivers/staging/usbip/vhci.h
43727+++ b/drivers/staging/usbip/vhci.h
43728@@ -83,7 +83,7 @@ struct vhci_hcd {
43729 unsigned resuming:1;
43730 unsigned long re_timeout;
43731
43732- atomic_t seqnum;
43733+ atomic_unchecked_t seqnum;
43734
43735 /*
43736 * NOTE:
43737diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
43738index c3aa219..bf8b3de 100644
43739--- a/drivers/staging/usbip/vhci_hcd.c
43740+++ b/drivers/staging/usbip/vhci_hcd.c
43741@@ -451,7 +451,7 @@ static void vhci_tx_urb(struct urb *urb)
43742 return;
43743 }
43744
43745- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
43746+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
43747 if (priv->seqnum == 0xffff)
43748 dev_info(&urb->dev->dev, "seqnum max\n");
43749
43750@@ -703,7 +703,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
43751 return -ENOMEM;
43752 }
43753
43754- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
43755+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
43756 if (unlink->seqnum == 0xffff)
43757 pr_info("seqnum max\n");
43758
43759@@ -907,7 +907,7 @@ static int vhci_start(struct usb_hcd *hcd)
43760 vdev->rhport = rhport;
43761 }
43762
43763- atomic_set(&vhci->seqnum, 0);
43764+ atomic_set_unchecked(&vhci->seqnum, 0);
43765 spin_lock_init(&vhci->lock);
43766
43767 hcd->power_budget = 0; /* no limit */
43768diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
43769index ba5f1c0..11d8122 100644
43770--- a/drivers/staging/usbip/vhci_rx.c
43771+++ b/drivers/staging/usbip/vhci_rx.c
43772@@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
43773 if (!urb) {
43774 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
43775 pr_info("max seqnum %d\n",
43776- atomic_read(&the_controller->seqnum));
43777+ atomic_read_unchecked(&the_controller->seqnum));
43778 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
43779 return;
43780 }
43781diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
43782index 5f13890..36a044b 100644
43783--- a/drivers/staging/vt6655/hostap.c
43784+++ b/drivers/staging/vt6655/hostap.c
43785@@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
43786 *
43787 */
43788
43789+static net_device_ops_no_const apdev_netdev_ops;
43790+
43791 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
43792 {
43793 PSDevice apdev_priv;
43794 struct net_device *dev = pDevice->dev;
43795 int ret;
43796- const struct net_device_ops apdev_netdev_ops = {
43797- .ndo_start_xmit = pDevice->tx_80211,
43798- };
43799
43800 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
43801
43802@@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
43803 *apdev_priv = *pDevice;
43804 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
43805
43806+ /* only half broken now */
43807+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
43808 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
43809
43810 pDevice->apdev->type = ARPHRD_IEEE80211;
43811diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
43812index 26a7d0e..897b083 100644
43813--- a/drivers/staging/vt6656/hostap.c
43814+++ b/drivers/staging/vt6656/hostap.c
43815@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
43816 *
43817 */
43818
43819+static net_device_ops_no_const apdev_netdev_ops;
43820+
43821 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
43822 {
43823 PSDevice apdev_priv;
43824 struct net_device *dev = pDevice->dev;
43825 int ret;
43826- const struct net_device_ops apdev_netdev_ops = {
43827- .ndo_start_xmit = pDevice->tx_80211,
43828- };
43829
43830 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
43831
43832@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
43833 *apdev_priv = *pDevice;
43834 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
43835
43836+ /* only half broken now */
43837+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
43838 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
43839
43840 pDevice->apdev->type = ARPHRD_IEEE80211;
43841diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
43842index 56c8e60..1920c63 100644
43843--- a/drivers/staging/zcache/tmem.c
43844+++ b/drivers/staging/zcache/tmem.c
43845@@ -39,7 +39,7 @@
43846 * A tmem host implementation must use this function to register callbacks
43847 * for memory allocation.
43848 */
43849-static struct tmem_hostops tmem_hostops;
43850+static tmem_hostops_no_const tmem_hostops;
43851
43852 static void tmem_objnode_tree_init(void);
43853
43854@@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
43855 * A tmem host implementation must use this function to register
43856 * callbacks for a page-accessible memory (PAM) implementation
43857 */
43858-static struct tmem_pamops tmem_pamops;
43859+static tmem_pamops_no_const tmem_pamops;
43860
43861 void tmem_register_pamops(struct tmem_pamops *m)
43862 {
43863diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
43864index 0d4aa82..f7832d4 100644
43865--- a/drivers/staging/zcache/tmem.h
43866+++ b/drivers/staging/zcache/tmem.h
43867@@ -180,6 +180,7 @@ struct tmem_pamops {
43868 void (*new_obj)(struct tmem_obj *);
43869 int (*replace_in_obj)(void *, struct tmem_obj *);
43870 };
43871+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
43872 extern void tmem_register_pamops(struct tmem_pamops *m);
43873
43874 /* memory allocation methods provided by the host implementation */
43875@@ -189,6 +190,7 @@ struct tmem_hostops {
43876 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
43877 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
43878 };
43879+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
43880 extern void tmem_register_hostops(struct tmem_hostops *m);
43881
43882 /* core tmem accessor functions */
43883diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
43884index 96f4981..4daaa7e 100644
43885--- a/drivers/target/target_core_device.c
43886+++ b/drivers/target/target_core_device.c
43887@@ -1370,7 +1370,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
43888 spin_lock_init(&dev->se_port_lock);
43889 spin_lock_init(&dev->se_tmr_lock);
43890 spin_lock_init(&dev->qf_cmd_lock);
43891- atomic_set(&dev->dev_ordered_id, 0);
43892+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
43893 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
43894 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
43895 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
43896diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
43897index fcf880f..a4d1e8f 100644
43898--- a/drivers/target/target_core_transport.c
43899+++ b/drivers/target/target_core_transport.c
43900@@ -1077,7 +1077,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
43901 * Used to determine when ORDERED commands should go from
43902 * Dormant to Active status.
43903 */
43904- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
43905+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
43906 smp_mb__after_atomic_inc();
43907 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
43908 cmd->se_ordered_id, cmd->sam_task_attr,
43909diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
43910index b09c8d1f..c4225c0 100644
43911--- a/drivers/tty/cyclades.c
43912+++ b/drivers/tty/cyclades.c
43913@@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
43914 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
43915 info->port.count);
43916 #endif
43917- info->port.count++;
43918+ atomic_inc(&info->port.count);
43919 #ifdef CY_DEBUG_COUNT
43920 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
43921- current->pid, info->port.count);
43922+ current->pid, atomic_read(&info->port.count));
43923 #endif
43924
43925 /*
43926@@ -3991,7 +3991,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
43927 for (j = 0; j < cy_card[i].nports; j++) {
43928 info = &cy_card[i].ports[j];
43929
43930- if (info->port.count) {
43931+ if (atomic_read(&info->port.count)) {
43932 /* XXX is the ldisc num worth this? */
43933 struct tty_struct *tty;
43934 struct tty_ldisc *ld;
43935diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
43936index 13ee53b..418d164 100644
43937--- a/drivers/tty/hvc/hvc_console.c
43938+++ b/drivers/tty/hvc/hvc_console.c
43939@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
43940
43941 spin_lock_irqsave(&hp->port.lock, flags);
43942 /* Check and then increment for fast path open. */
43943- if (hp->port.count++ > 0) {
43944+ if (atomic_inc_return(&hp->port.count) > 1) {
43945 spin_unlock_irqrestore(&hp->port.lock, flags);
43946 hvc_kick();
43947 return 0;
43948@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
43949
43950 spin_lock_irqsave(&hp->port.lock, flags);
43951
43952- if (--hp->port.count == 0) {
43953+ if (atomic_dec_return(&hp->port.count) == 0) {
43954 spin_unlock_irqrestore(&hp->port.lock, flags);
43955 /* We are done with the tty pointer now. */
43956 tty_port_tty_set(&hp->port, NULL);
43957@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
43958 */
43959 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
43960 } else {
43961- if (hp->port.count < 0)
43962+ if (atomic_read(&hp->port.count) < 0)
43963 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
43964- hp->vtermno, hp->port.count);
43965+ hp->vtermno, atomic_read(&hp->port.count));
43966 spin_unlock_irqrestore(&hp->port.lock, flags);
43967 }
43968 }
43969@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
43970 * open->hangup case this can be called after the final close so prevent
43971 * that from happening for now.
43972 */
43973- if (hp->port.count <= 0) {
43974+ if (atomic_read(&hp->port.count) <= 0) {
43975 spin_unlock_irqrestore(&hp->port.lock, flags);
43976 return;
43977 }
43978
43979- hp->port.count = 0;
43980+ atomic_set(&hp->port.count, 0);
43981 spin_unlock_irqrestore(&hp->port.lock, flags);
43982 tty_port_tty_set(&hp->port, NULL);
43983
43984@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
43985 return -EPIPE;
43986
43987 /* FIXME what's this (unprotected) check for? */
43988- if (hp->port.count <= 0)
43989+ if (atomic_read(&hp->port.count) <= 0)
43990 return -EIO;
43991
43992 spin_lock_irqsave(&hp->lock, flags);
43993diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
43994index 8776357..b2d4afd 100644
43995--- a/drivers/tty/hvc/hvcs.c
43996+++ b/drivers/tty/hvc/hvcs.c
43997@@ -83,6 +83,7 @@
43998 #include <asm/hvcserver.h>
43999 #include <asm/uaccess.h>
44000 #include <asm/vio.h>
44001+#include <asm/local.h>
44002
44003 /*
44004 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
44005@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
44006
44007 spin_lock_irqsave(&hvcsd->lock, flags);
44008
44009- if (hvcsd->port.count > 0) {
44010+ if (atomic_read(&hvcsd->port.count) > 0) {
44011 spin_unlock_irqrestore(&hvcsd->lock, flags);
44012 printk(KERN_INFO "HVCS: vterm state unchanged. "
44013 "The hvcs device node is still in use.\n");
44014@@ -1132,7 +1133,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
44015 }
44016 }
44017
44018- hvcsd->port.count = 0;
44019+ atomic_set(&hvcsd->port.count, 0);
44020 hvcsd->port.tty = tty;
44021 tty->driver_data = hvcsd;
44022
44023@@ -1185,7 +1186,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
44024 unsigned long flags;
44025
44026 spin_lock_irqsave(&hvcsd->lock, flags);
44027- hvcsd->port.count++;
44028+ atomic_inc(&hvcsd->port.count);
44029 hvcsd->todo_mask |= HVCS_SCHED_READ;
44030 spin_unlock_irqrestore(&hvcsd->lock, flags);
44031
44032@@ -1221,7 +1222,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
44033 hvcsd = tty->driver_data;
44034
44035 spin_lock_irqsave(&hvcsd->lock, flags);
44036- if (--hvcsd->port.count == 0) {
44037+ if (atomic_dec_and_test(&hvcsd->port.count)) {
44038
44039 vio_disable_interrupts(hvcsd->vdev);
44040
44041@@ -1246,10 +1247,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
44042
44043 free_irq(irq, hvcsd);
44044 return;
44045- } else if (hvcsd->port.count < 0) {
44046+ } else if (atomic_read(&hvcsd->port.count) < 0) {
44047 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
44048 " is missmanaged.\n",
44049- hvcsd->vdev->unit_address, hvcsd->port.count);
44050+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
44051 }
44052
44053 spin_unlock_irqrestore(&hvcsd->lock, flags);
44054@@ -1271,7 +1272,7 @@ static void hvcs_hangup(struct tty_struct * tty)
44055
44056 spin_lock_irqsave(&hvcsd->lock, flags);
44057 /* Preserve this so that we know how many kref refs to put */
44058- temp_open_count = hvcsd->port.count;
44059+ temp_open_count = atomic_read(&hvcsd->port.count);
44060
44061 /*
44062 * Don't kref put inside the spinlock because the destruction
44063@@ -1286,7 +1287,7 @@ static void hvcs_hangup(struct tty_struct * tty)
44064 tty->driver_data = NULL;
44065 hvcsd->port.tty = NULL;
44066
44067- hvcsd->port.count = 0;
44068+ atomic_set(&hvcsd->port.count, 0);
44069
44070 /* This will drop any buffered data on the floor which is OK in a hangup
44071 * scenario. */
44072@@ -1357,7 +1358,7 @@ static int hvcs_write(struct tty_struct *tty,
44073 * the middle of a write operation? This is a crummy place to do this
44074 * but we want to keep it all in the spinlock.
44075 */
44076- if (hvcsd->port.count <= 0) {
44077+ if (atomic_read(&hvcsd->port.count) <= 0) {
44078 spin_unlock_irqrestore(&hvcsd->lock, flags);
44079 return -ENODEV;
44080 }
44081@@ -1431,7 +1432,7 @@ static int hvcs_write_room(struct tty_struct *tty)
44082 {
44083 struct hvcs_struct *hvcsd = tty->driver_data;
44084
44085- if (!hvcsd || hvcsd->port.count <= 0)
44086+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
44087 return 0;
44088
44089 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
44090diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
44091index 2cde13d..645d78f 100644
44092--- a/drivers/tty/ipwireless/tty.c
44093+++ b/drivers/tty/ipwireless/tty.c
44094@@ -29,6 +29,7 @@
44095 #include <linux/tty_driver.h>
44096 #include <linux/tty_flip.h>
44097 #include <linux/uaccess.h>
44098+#include <asm/local.h>
44099
44100 #include "tty.h"
44101 #include "network.h"
44102@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
44103 mutex_unlock(&tty->ipw_tty_mutex);
44104 return -ENODEV;
44105 }
44106- if (tty->port.count == 0)
44107+ if (atomic_read(&tty->port.count) == 0)
44108 tty->tx_bytes_queued = 0;
44109
44110- tty->port.count++;
44111+ atomic_inc(&tty->port.count);
44112
44113 tty->port.tty = linux_tty;
44114 linux_tty->driver_data = tty;
44115@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
44116
44117 static void do_ipw_close(struct ipw_tty *tty)
44118 {
44119- tty->port.count--;
44120-
44121- if (tty->port.count == 0) {
44122+ if (atomic_dec_return(&tty->port.count) == 0) {
44123 struct tty_struct *linux_tty = tty->port.tty;
44124
44125 if (linux_tty != NULL) {
44126@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
44127 return;
44128
44129 mutex_lock(&tty->ipw_tty_mutex);
44130- if (tty->port.count == 0) {
44131+ if (atomic_read(&tty->port.count) == 0) {
44132 mutex_unlock(&tty->ipw_tty_mutex);
44133 return;
44134 }
44135@@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
44136 return;
44137 }
44138
44139- if (!tty->port.count) {
44140+ if (!atomic_read(&tty->port.count)) {
44141 mutex_unlock(&tty->ipw_tty_mutex);
44142 return;
44143 }
44144@@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
44145 return -ENODEV;
44146
44147 mutex_lock(&tty->ipw_tty_mutex);
44148- if (!tty->port.count) {
44149+ if (!atomic_read(&tty->port.count)) {
44150 mutex_unlock(&tty->ipw_tty_mutex);
44151 return -EINVAL;
44152 }
44153@@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
44154 if (!tty)
44155 return -ENODEV;
44156
44157- if (!tty->port.count)
44158+ if (!atomic_read(&tty->port.count))
44159 return -EINVAL;
44160
44161 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
44162@@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
44163 if (!tty)
44164 return 0;
44165
44166- if (!tty->port.count)
44167+ if (!atomic_read(&tty->port.count))
44168 return 0;
44169
44170 return tty->tx_bytes_queued;
44171@@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
44172 if (!tty)
44173 return -ENODEV;
44174
44175- if (!tty->port.count)
44176+ if (!atomic_read(&tty->port.count))
44177 return -EINVAL;
44178
44179 return get_control_lines(tty);
44180@@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
44181 if (!tty)
44182 return -ENODEV;
44183
44184- if (!tty->port.count)
44185+ if (!atomic_read(&tty->port.count))
44186 return -EINVAL;
44187
44188 return set_control_lines(tty, set, clear);
44189@@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
44190 if (!tty)
44191 return -ENODEV;
44192
44193- if (!tty->port.count)
44194+ if (!atomic_read(&tty->port.count))
44195 return -EINVAL;
44196
44197 /* FIXME: Exactly how is the tty object locked here .. */
44198@@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
44199 * are gone */
44200 mutex_lock(&ttyj->ipw_tty_mutex);
44201 }
44202- while (ttyj->port.count)
44203+ while (atomic_read(&ttyj->port.count))
44204 do_ipw_close(ttyj);
44205 ipwireless_disassociate_network_ttys(network,
44206 ttyj->channel_idx);
44207diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
44208index f9d2850..b006f04 100644
44209--- a/drivers/tty/moxa.c
44210+++ b/drivers/tty/moxa.c
44211@@ -1193,7 +1193,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
44212 }
44213
44214 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
44215- ch->port.count++;
44216+ atomic_inc(&ch->port.count);
44217 tty->driver_data = ch;
44218 tty_port_tty_set(&ch->port, tty);
44219 mutex_lock(&ch->port.mutex);
44220diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
44221index bfd6771..e0d93c4 100644
44222--- a/drivers/tty/n_gsm.c
44223+++ b/drivers/tty/n_gsm.c
44224@@ -1636,7 +1636,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
44225 spin_lock_init(&dlci->lock);
44226 mutex_init(&dlci->mutex);
44227 dlci->fifo = &dlci->_fifo;
44228- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
44229+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
44230 kfree(dlci);
44231 return NULL;
44232 }
44233@@ -2936,7 +2936,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
44234 struct gsm_dlci *dlci = tty->driver_data;
44235 struct tty_port *port = &dlci->port;
44236
44237- port->count++;
44238+ atomic_inc(&port->count);
44239 dlci_get(dlci);
44240 dlci_get(dlci->gsm->dlci[0]);
44241 mux_get(dlci->gsm);
44242diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
44243index 19083ef..6e34e97 100644
44244--- a/drivers/tty/n_tty.c
44245+++ b/drivers/tty/n_tty.c
44246@@ -2196,6 +2196,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
44247 {
44248 *ops = tty_ldisc_N_TTY;
44249 ops->owner = NULL;
44250- ops->refcount = ops->flags = 0;
44251+ atomic_set(&ops->refcount, 0);
44252+ ops->flags = 0;
44253 }
44254 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
44255diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
44256index ac35c90..c47deac 100644
44257--- a/drivers/tty/pty.c
44258+++ b/drivers/tty/pty.c
44259@@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
44260 panic("Couldn't register Unix98 pts driver");
44261
44262 /* Now create the /dev/ptmx special device */
44263+ pax_open_kernel();
44264 tty_default_fops(&ptmx_fops);
44265- ptmx_fops.open = ptmx_open;
44266+ *(void **)&ptmx_fops.open = ptmx_open;
44267+ pax_close_kernel();
44268
44269 cdev_init(&ptmx_cdev, &ptmx_fops);
44270 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
44271diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
44272index e42009a..566a036 100644
44273--- a/drivers/tty/rocket.c
44274+++ b/drivers/tty/rocket.c
44275@@ -925,7 +925,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
44276 tty->driver_data = info;
44277 tty_port_tty_set(port, tty);
44278
44279- if (port->count++ == 0) {
44280+ if (atomic_inc_return(&port->count) == 1) {
44281 atomic_inc(&rp_num_ports_open);
44282
44283 #ifdef ROCKET_DEBUG_OPEN
44284@@ -934,7 +934,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
44285 #endif
44286 }
44287 #ifdef ROCKET_DEBUG_OPEN
44288- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
44289+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
44290 #endif
44291
44292 /*
44293@@ -1529,7 +1529,7 @@ static void rp_hangup(struct tty_struct *tty)
44294 spin_unlock_irqrestore(&info->port.lock, flags);
44295 return;
44296 }
44297- if (info->port.count)
44298+ if (atomic_read(&info->port.count))
44299 atomic_dec(&rp_num_ports_open);
44300 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
44301 spin_unlock_irqrestore(&info->port.lock, flags);
44302diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
44303index 1002054..dd644a8 100644
44304--- a/drivers/tty/serial/kgdboc.c
44305+++ b/drivers/tty/serial/kgdboc.c
44306@@ -24,8 +24,9 @@
44307 #define MAX_CONFIG_LEN 40
44308
44309 static struct kgdb_io kgdboc_io_ops;
44310+static struct kgdb_io kgdboc_io_ops_console;
44311
44312-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
44313+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
44314 static int configured = -1;
44315
44316 static char config[MAX_CONFIG_LEN];
44317@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
44318 kgdboc_unregister_kbd();
44319 if (configured == 1)
44320 kgdb_unregister_io_module(&kgdboc_io_ops);
44321+ else if (configured == 2)
44322+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
44323 }
44324
44325 static int configure_kgdboc(void)
44326@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
44327 int err;
44328 char *cptr = config;
44329 struct console *cons;
44330+ int is_console = 0;
44331
44332 err = kgdboc_option_setup(config);
44333 if (err || !strlen(config) || isspace(config[0]))
44334 goto noconfig;
44335
44336 err = -ENODEV;
44337- kgdboc_io_ops.is_console = 0;
44338 kgdb_tty_driver = NULL;
44339
44340 kgdboc_use_kms = 0;
44341@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
44342 int idx;
44343 if (cons->device && cons->device(cons, &idx) == p &&
44344 idx == tty_line) {
44345- kgdboc_io_ops.is_console = 1;
44346+ is_console = 1;
44347 break;
44348 }
44349 cons = cons->next;
44350@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
44351 kgdb_tty_line = tty_line;
44352
44353 do_register:
44354- err = kgdb_register_io_module(&kgdboc_io_ops);
44355+ if (is_console) {
44356+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
44357+ configured = 2;
44358+ } else {
44359+ err = kgdb_register_io_module(&kgdboc_io_ops);
44360+ configured = 1;
44361+ }
44362 if (err)
44363 goto noconfig;
44364
44365@@ -205,8 +214,6 @@ do_register:
44366 if (err)
44367 goto nmi_con_failed;
44368
44369- configured = 1;
44370-
44371 return 0;
44372
44373 nmi_con_failed:
44374@@ -223,7 +230,7 @@ noconfig:
44375 static int __init init_kgdboc(void)
44376 {
44377 /* Already configured? */
44378- if (configured == 1)
44379+ if (configured >= 1)
44380 return 0;
44381
44382 return configure_kgdboc();
44383@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
44384 if (config[len - 1] == '\n')
44385 config[len - 1] = '\0';
44386
44387- if (configured == 1)
44388+ if (configured >= 1)
44389 cleanup_kgdboc();
44390
44391 /* Go and configure with the new params. */
44392@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
44393 .post_exception = kgdboc_post_exp_handler,
44394 };
44395
44396+static struct kgdb_io kgdboc_io_ops_console = {
44397+ .name = "kgdboc",
44398+ .read_char = kgdboc_get_char,
44399+ .write_char = kgdboc_put_char,
44400+ .pre_exception = kgdboc_pre_exp_handler,
44401+ .post_exception = kgdboc_post_exp_handler,
44402+ .is_console = 1
44403+};
44404+
44405 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
44406 /* This is only available if kgdboc is a built in for early debugging */
44407 static int __init kgdboc_early_init(char *opt)
44408diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
44409index e514b3a..c73d614 100644
44410--- a/drivers/tty/serial/samsung.c
44411+++ b/drivers/tty/serial/samsung.c
44412@@ -453,11 +453,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
44413 }
44414 }
44415
44416+static int s3c64xx_serial_startup(struct uart_port *port);
44417 static int s3c24xx_serial_startup(struct uart_port *port)
44418 {
44419 struct s3c24xx_uart_port *ourport = to_ourport(port);
44420 int ret;
44421
44422+ /* Startup sequence is different for s3c64xx and higher SoC's */
44423+ if (s3c24xx_serial_has_interrupt_mask(port))
44424+ return s3c64xx_serial_startup(port);
44425+
44426 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
44427 port->mapbase, port->membase);
44428
44429@@ -1122,10 +1127,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
44430 /* setup info for port */
44431 port->dev = &platdev->dev;
44432
44433- /* Startup sequence is different for s3c64xx and higher SoC's */
44434- if (s3c24xx_serial_has_interrupt_mask(port))
44435- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
44436-
44437 port->uartclk = 1;
44438
44439 if (cfg->uart_flags & UPF_CONS_FLOW) {
44440diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
44441index 2c7230a..2104f16 100644
44442--- a/drivers/tty/serial/serial_core.c
44443+++ b/drivers/tty/serial/serial_core.c
44444@@ -1455,7 +1455,7 @@ static void uart_hangup(struct tty_struct *tty)
44445 uart_flush_buffer(tty);
44446 uart_shutdown(tty, state);
44447 spin_lock_irqsave(&port->lock, flags);
44448- port->count = 0;
44449+ atomic_set(&port->count, 0);
44450 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
44451 spin_unlock_irqrestore(&port->lock, flags);
44452 tty_port_tty_set(port, NULL);
44453@@ -1551,7 +1551,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
44454 goto end;
44455 }
44456
44457- port->count++;
44458+ atomic_inc(&port->count);
44459 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
44460 retval = -ENXIO;
44461 goto err_dec_count;
44462@@ -1578,7 +1578,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
44463 /*
44464 * Make sure the device is in D0 state.
44465 */
44466- if (port->count == 1)
44467+ if (atomic_read(&port->count) == 1)
44468 uart_change_pm(state, 0);
44469
44470 /*
44471@@ -1596,7 +1596,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
44472 end:
44473 return retval;
44474 err_dec_count:
44475- port->count--;
44476+ atomic_inc(&port->count);
44477 mutex_unlock(&port->mutex);
44478 goto end;
44479 }
44480diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
44481index 9e071f6..f30ae69 100644
44482--- a/drivers/tty/synclink.c
44483+++ b/drivers/tty/synclink.c
44484@@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
44485
44486 if (debug_level >= DEBUG_LEVEL_INFO)
44487 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
44488- __FILE__,__LINE__, info->device_name, info->port.count);
44489+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
44490
44491 if (tty_port_close_start(&info->port, tty, filp) == 0)
44492 goto cleanup;
44493@@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
44494 cleanup:
44495 if (debug_level >= DEBUG_LEVEL_INFO)
44496 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
44497- tty->driver->name, info->port.count);
44498+ tty->driver->name, atomic_read(&info->port.count));
44499
44500 } /* end of mgsl_close() */
44501
44502@@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
44503
44504 mgsl_flush_buffer(tty);
44505 shutdown(info);
44506-
44507- info->port.count = 0;
44508+
44509+ atomic_set(&info->port.count, 0);
44510 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
44511 info->port.tty = NULL;
44512
44513@@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
44514
44515 if (debug_level >= DEBUG_LEVEL_INFO)
44516 printk("%s(%d):block_til_ready before block on %s count=%d\n",
44517- __FILE__,__LINE__, tty->driver->name, port->count );
44518+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44519
44520 spin_lock_irqsave(&info->irq_spinlock, flags);
44521 if (!tty_hung_up_p(filp)) {
44522 extra_count = true;
44523- port->count--;
44524+ atomic_dec(&port->count);
44525 }
44526 spin_unlock_irqrestore(&info->irq_spinlock, flags);
44527 port->blocked_open++;
44528@@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
44529
44530 if (debug_level >= DEBUG_LEVEL_INFO)
44531 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
44532- __FILE__,__LINE__, tty->driver->name, port->count );
44533+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44534
44535 tty_unlock(tty);
44536 schedule();
44537@@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
44538
44539 /* FIXME: Racy on hangup during close wait */
44540 if (extra_count)
44541- port->count++;
44542+ atomic_inc(&port->count);
44543 port->blocked_open--;
44544
44545 if (debug_level >= DEBUG_LEVEL_INFO)
44546 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
44547- __FILE__,__LINE__, tty->driver->name, port->count );
44548+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44549
44550 if (!retval)
44551 port->flags |= ASYNC_NORMAL_ACTIVE;
44552@@ -3405,7 +3405,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
44553
44554 if (debug_level >= DEBUG_LEVEL_INFO)
44555 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
44556- __FILE__,__LINE__,tty->driver->name, info->port.count);
44557+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
44558
44559 /* If port is closing, signal caller to try again */
44560 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
44561@@ -3424,10 +3424,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
44562 spin_unlock_irqrestore(&info->netlock, flags);
44563 goto cleanup;
44564 }
44565- info->port.count++;
44566+ atomic_inc(&info->port.count);
44567 spin_unlock_irqrestore(&info->netlock, flags);
44568
44569- if (info->port.count == 1) {
44570+ if (atomic_read(&info->port.count) == 1) {
44571 /* 1st open on this device, init hardware */
44572 retval = startup(info);
44573 if (retval < 0)
44574@@ -3451,8 +3451,8 @@ cleanup:
44575 if (retval) {
44576 if (tty->count == 1)
44577 info->port.tty = NULL; /* tty layer will release tty struct */
44578- if(info->port.count)
44579- info->port.count--;
44580+ if (atomic_read(&info->port.count))
44581+ atomic_dec(&info->port.count);
44582 }
44583
44584 return retval;
44585@@ -7662,7 +7662,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
44586 unsigned short new_crctype;
44587
44588 /* return error if TTY interface open */
44589- if (info->port.count)
44590+ if (atomic_read(&info->port.count))
44591 return -EBUSY;
44592
44593 switch (encoding)
44594@@ -7757,7 +7757,7 @@ static int hdlcdev_open(struct net_device *dev)
44595
44596 /* arbitrate between network and tty opens */
44597 spin_lock_irqsave(&info->netlock, flags);
44598- if (info->port.count != 0 || info->netcount != 0) {
44599+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
44600 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
44601 spin_unlock_irqrestore(&info->netlock, flags);
44602 return -EBUSY;
44603@@ -7843,7 +7843,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44604 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
44605
44606 /* return error if TTY interface open */
44607- if (info->port.count)
44608+ if (atomic_read(&info->port.count))
44609 return -EBUSY;
44610
44611 if (cmd != SIOCWANDEV)
44612diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
44613index aba1e59..877ac33 100644
44614--- a/drivers/tty/synclink_gt.c
44615+++ b/drivers/tty/synclink_gt.c
44616@@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
44617 tty->driver_data = info;
44618 info->port.tty = tty;
44619
44620- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
44621+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
44622
44623 /* If port is closing, signal caller to try again */
44624 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
44625@@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
44626 mutex_unlock(&info->port.mutex);
44627 goto cleanup;
44628 }
44629- info->port.count++;
44630+ atomic_inc(&info->port.count);
44631 spin_unlock_irqrestore(&info->netlock, flags);
44632
44633- if (info->port.count == 1) {
44634+ if (atomic_read(&info->port.count) == 1) {
44635 /* 1st open on this device, init hardware */
44636 retval = startup(info);
44637 if (retval < 0) {
44638@@ -716,8 +716,8 @@ cleanup:
44639 if (retval) {
44640 if (tty->count == 1)
44641 info->port.tty = NULL; /* tty layer will release tty struct */
44642- if(info->port.count)
44643- info->port.count--;
44644+ if(atomic_read(&info->port.count))
44645+ atomic_dec(&info->port.count);
44646 }
44647
44648 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
44649@@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44650
44651 if (sanity_check(info, tty->name, "close"))
44652 return;
44653- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
44654+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
44655
44656 if (tty_port_close_start(&info->port, tty, filp) == 0)
44657 goto cleanup;
44658@@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44659 tty_port_close_end(&info->port, tty);
44660 info->port.tty = NULL;
44661 cleanup:
44662- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
44663+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
44664 }
44665
44666 static void hangup(struct tty_struct *tty)
44667@@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
44668 shutdown(info);
44669
44670 spin_lock_irqsave(&info->port.lock, flags);
44671- info->port.count = 0;
44672+ atomic_set(&info->port.count, 0);
44673 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
44674 info->port.tty = NULL;
44675 spin_unlock_irqrestore(&info->port.lock, flags);
44676@@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
44677 unsigned short new_crctype;
44678
44679 /* return error if TTY interface open */
44680- if (info->port.count)
44681+ if (atomic_read(&info->port.count))
44682 return -EBUSY;
44683
44684 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
44685@@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
44686
44687 /* arbitrate between network and tty opens */
44688 spin_lock_irqsave(&info->netlock, flags);
44689- if (info->port.count != 0 || info->netcount != 0) {
44690+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
44691 DBGINFO(("%s hdlc_open busy\n", dev->name));
44692 spin_unlock_irqrestore(&info->netlock, flags);
44693 return -EBUSY;
44694@@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44695 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
44696
44697 /* return error if TTY interface open */
44698- if (info->port.count)
44699+ if (atomic_read(&info->port.count))
44700 return -EBUSY;
44701
44702 if (cmd != SIOCWANDEV)
44703@@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
44704 if (port == NULL)
44705 continue;
44706 spin_lock(&port->lock);
44707- if ((port->port.count || port->netcount) &&
44708+ if ((atomic_read(&port->port.count) || port->netcount) &&
44709 port->pending_bh && !port->bh_running &&
44710 !port->bh_requested) {
44711 DBGISR(("%s bh queued\n", port->device_name));
44712@@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44713 spin_lock_irqsave(&info->lock, flags);
44714 if (!tty_hung_up_p(filp)) {
44715 extra_count = true;
44716- port->count--;
44717+ atomic_dec(&port->count);
44718 }
44719 spin_unlock_irqrestore(&info->lock, flags);
44720 port->blocked_open++;
44721@@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44722 remove_wait_queue(&port->open_wait, &wait);
44723
44724 if (extra_count)
44725- port->count++;
44726+ atomic_inc(&port->count);
44727 port->blocked_open--;
44728
44729 if (!retval)
44730diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
44731index fd43fb6..34704ad 100644
44732--- a/drivers/tty/synclinkmp.c
44733+++ b/drivers/tty/synclinkmp.c
44734@@ -751,7 +751,7 @@ static int open(struct tty_struct *tty, struct file *filp)
44735
44736 if (debug_level >= DEBUG_LEVEL_INFO)
44737 printk("%s(%d):%s open(), old ref count = %d\n",
44738- __FILE__,__LINE__,tty->driver->name, info->port.count);
44739+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
44740
44741 /* If port is closing, signal caller to try again */
44742 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
44743@@ -770,10 +770,10 @@ static int open(struct tty_struct *tty, struct file *filp)
44744 spin_unlock_irqrestore(&info->netlock, flags);
44745 goto cleanup;
44746 }
44747- info->port.count++;
44748+ atomic_inc(&info->port.count);
44749 spin_unlock_irqrestore(&info->netlock, flags);
44750
44751- if (info->port.count == 1) {
44752+ if (atomic_read(&info->port.count) == 1) {
44753 /* 1st open on this device, init hardware */
44754 retval = startup(info);
44755 if (retval < 0)
44756@@ -797,8 +797,8 @@ cleanup:
44757 if (retval) {
44758 if (tty->count == 1)
44759 info->port.tty = NULL; /* tty layer will release tty struct */
44760- if(info->port.count)
44761- info->port.count--;
44762+ if(atomic_read(&info->port.count))
44763+ atomic_dec(&info->port.count);
44764 }
44765
44766 return retval;
44767@@ -816,7 +816,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44768
44769 if (debug_level >= DEBUG_LEVEL_INFO)
44770 printk("%s(%d):%s close() entry, count=%d\n",
44771- __FILE__,__LINE__, info->device_name, info->port.count);
44772+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
44773
44774 if (tty_port_close_start(&info->port, tty, filp) == 0)
44775 goto cleanup;
44776@@ -835,7 +835,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44777 cleanup:
44778 if (debug_level >= DEBUG_LEVEL_INFO)
44779 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
44780- tty->driver->name, info->port.count);
44781+ tty->driver->name, atomic_read(&info->port.count));
44782 }
44783
44784 /* Called by tty_hangup() when a hangup is signaled.
44785@@ -858,7 +858,7 @@ static void hangup(struct tty_struct *tty)
44786 shutdown(info);
44787
44788 spin_lock_irqsave(&info->port.lock, flags);
44789- info->port.count = 0;
44790+ atomic_set(&info->port.count, 0);
44791 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
44792 info->port.tty = NULL;
44793 spin_unlock_irqrestore(&info->port.lock, flags);
44794@@ -1566,7 +1566,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
44795 unsigned short new_crctype;
44796
44797 /* return error if TTY interface open */
44798- if (info->port.count)
44799+ if (atomic_read(&info->port.count))
44800 return -EBUSY;
44801
44802 switch (encoding)
44803@@ -1661,7 +1661,7 @@ static int hdlcdev_open(struct net_device *dev)
44804
44805 /* arbitrate between network and tty opens */
44806 spin_lock_irqsave(&info->netlock, flags);
44807- if (info->port.count != 0 || info->netcount != 0) {
44808+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
44809 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
44810 spin_unlock_irqrestore(&info->netlock, flags);
44811 return -EBUSY;
44812@@ -1747,7 +1747,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44813 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
44814
44815 /* return error if TTY interface open */
44816- if (info->port.count)
44817+ if (atomic_read(&info->port.count))
44818 return -EBUSY;
44819
44820 if (cmd != SIOCWANDEV)
44821@@ -2632,7 +2632,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
44822 * do not request bottom half processing if the
44823 * device is not open in a normal mode.
44824 */
44825- if ( port && (port->port.count || port->netcount) &&
44826+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
44827 port->pending_bh && !port->bh_running &&
44828 !port->bh_requested ) {
44829 if ( debug_level >= DEBUG_LEVEL_ISR )
44830@@ -3330,12 +3330,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44831
44832 if (debug_level >= DEBUG_LEVEL_INFO)
44833 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
44834- __FILE__,__LINE__, tty->driver->name, port->count );
44835+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44836
44837 spin_lock_irqsave(&info->lock, flags);
44838 if (!tty_hung_up_p(filp)) {
44839 extra_count = true;
44840- port->count--;
44841+ atomic_dec(&port->count);
44842 }
44843 spin_unlock_irqrestore(&info->lock, flags);
44844 port->blocked_open++;
44845@@ -3364,7 +3364,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44846
44847 if (debug_level >= DEBUG_LEVEL_INFO)
44848 printk("%s(%d):%s block_til_ready() count=%d\n",
44849- __FILE__,__LINE__, tty->driver->name, port->count );
44850+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44851
44852 tty_unlock(tty);
44853 schedule();
44854@@ -3375,12 +3375,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44855 remove_wait_queue(&port->open_wait, &wait);
44856
44857 if (extra_count)
44858- port->count++;
44859+ atomic_inc(&port->count);
44860 port->blocked_open--;
44861
44862 if (debug_level >= DEBUG_LEVEL_INFO)
44863 printk("%s(%d):%s block_til_ready() after, count=%d\n",
44864- __FILE__,__LINE__, tty->driver->name, port->count );
44865+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44866
44867 if (!retval)
44868 port->flags |= ASYNC_NORMAL_ACTIVE;
44869diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
44870index b3c4a25..723916f 100644
44871--- a/drivers/tty/sysrq.c
44872+++ b/drivers/tty/sysrq.c
44873@@ -867,7 +867,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
44874 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
44875 size_t count, loff_t *ppos)
44876 {
44877- if (count) {
44878+ if (count && capable(CAP_SYS_ADMIN)) {
44879 char c;
44880
44881 if (get_user(c, buf))
44882diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
44883index da9fde8..c07975f 100644
44884--- a/drivers/tty/tty_io.c
44885+++ b/drivers/tty/tty_io.c
44886@@ -3391,7 +3391,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
44887
44888 void tty_default_fops(struct file_operations *fops)
44889 {
44890- *fops = tty_fops;
44891+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
44892 }
44893
44894 /*
44895diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
44896index 78f1be2..3e98910 100644
44897--- a/drivers/tty/tty_ldisc.c
44898+++ b/drivers/tty/tty_ldisc.c
44899@@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
44900 if (atomic_dec_and_test(&ld->users)) {
44901 struct tty_ldisc_ops *ldo = ld->ops;
44902
44903- ldo->refcount--;
44904+ atomic_dec(&ldo->refcount);
44905 module_put(ldo->owner);
44906 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
44907
44908@@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
44909 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
44910 tty_ldiscs[disc] = new_ldisc;
44911 new_ldisc->num = disc;
44912- new_ldisc->refcount = 0;
44913+ atomic_set(&new_ldisc->refcount, 0);
44914 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
44915
44916 return ret;
44917@@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
44918 return -EINVAL;
44919
44920 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
44921- if (tty_ldiscs[disc]->refcount)
44922+ if (atomic_read(&tty_ldiscs[disc]->refcount))
44923 ret = -EBUSY;
44924 else
44925 tty_ldiscs[disc] = NULL;
44926@@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
44927 if (ldops) {
44928 ret = ERR_PTR(-EAGAIN);
44929 if (try_module_get(ldops->owner)) {
44930- ldops->refcount++;
44931+ atomic_inc(&ldops->refcount);
44932 ret = ldops;
44933 }
44934 }
44935@@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
44936 unsigned long flags;
44937
44938 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
44939- ldops->refcount--;
44940+ atomic_dec(&ldops->refcount);
44941 module_put(ldops->owner);
44942 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
44943 }
44944diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
44945index b7ff59d..7c6105e 100644
44946--- a/drivers/tty/tty_port.c
44947+++ b/drivers/tty/tty_port.c
44948@@ -218,7 +218,7 @@ void tty_port_hangup(struct tty_port *port)
44949 unsigned long flags;
44950
44951 spin_lock_irqsave(&port->lock, flags);
44952- port->count = 0;
44953+ atomic_set(&port->count, 0);
44954 port->flags &= ~ASYNC_NORMAL_ACTIVE;
44955 if (port->tty) {
44956 set_bit(TTY_IO_ERROR, &port->tty->flags);
44957@@ -344,7 +344,7 @@ int tty_port_block_til_ready(struct tty_port *port,
44958 /* The port lock protects the port counts */
44959 spin_lock_irqsave(&port->lock, flags);
44960 if (!tty_hung_up_p(filp))
44961- port->count--;
44962+ atomic_dec(&port->count);
44963 port->blocked_open++;
44964 spin_unlock_irqrestore(&port->lock, flags);
44965
44966@@ -386,7 +386,7 @@ int tty_port_block_til_ready(struct tty_port *port,
44967 we must not mess that up further */
44968 spin_lock_irqsave(&port->lock, flags);
44969 if (!tty_hung_up_p(filp))
44970- port->count++;
44971+ atomic_inc(&port->count);
44972 port->blocked_open--;
44973 if (retval == 0)
44974 port->flags |= ASYNC_NORMAL_ACTIVE;
44975@@ -406,19 +406,19 @@ int tty_port_close_start(struct tty_port *port,
44976 return 0;
44977 }
44978
44979- if (tty->count == 1 && port->count != 1) {
44980+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
44981 printk(KERN_WARNING
44982 "tty_port_close_start: tty->count = 1 port count = %d.\n",
44983- port->count);
44984- port->count = 1;
44985+ atomic_read(&port->count));
44986+ atomic_set(&port->count, 1);
44987 }
44988- if (--port->count < 0) {
44989+ if (atomic_dec_return(&port->count) < 0) {
44990 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
44991- port->count);
44992- port->count = 0;
44993+ atomic_read(&port->count));
44994+ atomic_set(&port->count, 0);
44995 }
44996
44997- if (port->count) {
44998+ if (atomic_read(&port->count)) {
44999 spin_unlock_irqrestore(&port->lock, flags);
45000 if (port->ops->drop)
45001 port->ops->drop(port);
45002@@ -516,7 +516,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
45003 {
45004 spin_lock_irq(&port->lock);
45005 if (!tty_hung_up_p(filp))
45006- ++port->count;
45007+ atomic_inc(&port->count);
45008 spin_unlock_irq(&port->lock);
45009 tty_port_tty_set(port, tty);
45010
45011diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
45012index 681765b..d3ccdf2 100644
45013--- a/drivers/tty/vt/keyboard.c
45014+++ b/drivers/tty/vt/keyboard.c
45015@@ -660,6 +660,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
45016 kbd->kbdmode == VC_OFF) &&
45017 value != KVAL(K_SAK))
45018 return; /* SAK is allowed even in raw mode */
45019+
45020+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
45021+ {
45022+ void *func = fn_handler[value];
45023+ if (func == fn_show_state || func == fn_show_ptregs ||
45024+ func == fn_show_mem)
45025+ return;
45026+ }
45027+#endif
45028+
45029 fn_handler[value](vc);
45030 }
45031
45032@@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
45033 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
45034 return -EFAULT;
45035
45036- if (!capable(CAP_SYS_TTY_CONFIG))
45037- perm = 0;
45038-
45039 switch (cmd) {
45040 case KDGKBENT:
45041 /* Ensure another thread doesn't free it under us */
45042@@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
45043 spin_unlock_irqrestore(&kbd_event_lock, flags);
45044 return put_user(val, &user_kbe->kb_value);
45045 case KDSKBENT:
45046+ if (!capable(CAP_SYS_TTY_CONFIG))
45047+ perm = 0;
45048+
45049 if (!perm)
45050 return -EPERM;
45051 if (!i && v == K_NOSUCHMAP) {
45052@@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
45053 int i, j, k;
45054 int ret;
45055
45056- if (!capable(CAP_SYS_TTY_CONFIG))
45057- perm = 0;
45058-
45059 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
45060 if (!kbs) {
45061 ret = -ENOMEM;
45062@@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
45063 kfree(kbs);
45064 return ((p && *p) ? -EOVERFLOW : 0);
45065 case KDSKBSENT:
45066+ if (!capable(CAP_SYS_TTY_CONFIG))
45067+ perm = 0;
45068+
45069 if (!perm) {
45070 ret = -EPERM;
45071 goto reterr;
45072diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
45073index 5110f36..8dc0a74 100644
45074--- a/drivers/uio/uio.c
45075+++ b/drivers/uio/uio.c
45076@@ -25,6 +25,7 @@
45077 #include <linux/kobject.h>
45078 #include <linux/cdev.h>
45079 #include <linux/uio_driver.h>
45080+#include <asm/local.h>
45081
45082 #define UIO_MAX_DEVICES (1U << MINORBITS)
45083
45084@@ -32,10 +33,10 @@ struct uio_device {
45085 struct module *owner;
45086 struct device *dev;
45087 int minor;
45088- atomic_t event;
45089+ atomic_unchecked_t event;
45090 struct fasync_struct *async_queue;
45091 wait_queue_head_t wait;
45092- int vma_count;
45093+ local_t vma_count;
45094 struct uio_info *info;
45095 struct kobject *map_dir;
45096 struct kobject *portio_dir;
45097@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
45098 struct device_attribute *attr, char *buf)
45099 {
45100 struct uio_device *idev = dev_get_drvdata(dev);
45101- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
45102+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
45103 }
45104
45105 static struct device_attribute uio_class_attributes[] = {
45106@@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
45107 {
45108 struct uio_device *idev = info->uio_dev;
45109
45110- atomic_inc(&idev->event);
45111+ atomic_inc_unchecked(&idev->event);
45112 wake_up_interruptible(&idev->wait);
45113 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
45114 }
45115@@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
45116 }
45117
45118 listener->dev = idev;
45119- listener->event_count = atomic_read(&idev->event);
45120+ listener->event_count = atomic_read_unchecked(&idev->event);
45121 filep->private_data = listener;
45122
45123 if (idev->info->open) {
45124@@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
45125 return -EIO;
45126
45127 poll_wait(filep, &idev->wait, wait);
45128- if (listener->event_count != atomic_read(&idev->event))
45129+ if (listener->event_count != atomic_read_unchecked(&idev->event))
45130 return POLLIN | POLLRDNORM;
45131 return 0;
45132 }
45133@@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
45134 do {
45135 set_current_state(TASK_INTERRUPTIBLE);
45136
45137- event_count = atomic_read(&idev->event);
45138+ event_count = atomic_read_unchecked(&idev->event);
45139 if (event_count != listener->event_count) {
45140 if (copy_to_user(buf, &event_count, count))
45141 retval = -EFAULT;
45142@@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
45143 static void uio_vma_open(struct vm_area_struct *vma)
45144 {
45145 struct uio_device *idev = vma->vm_private_data;
45146- idev->vma_count++;
45147+ local_inc(&idev->vma_count);
45148 }
45149
45150 static void uio_vma_close(struct vm_area_struct *vma)
45151 {
45152 struct uio_device *idev = vma->vm_private_data;
45153- idev->vma_count--;
45154+ local_dec(&idev->vma_count);
45155 }
45156
45157 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
45158@@ -819,7 +820,7 @@ int __uio_register_device(struct module *owner,
45159 idev->owner = owner;
45160 idev->info = info;
45161 init_waitqueue_head(&idev->wait);
45162- atomic_set(&idev->event, 0);
45163+ atomic_set_unchecked(&idev->event, 0);
45164
45165 ret = uio_get_minor(idev);
45166 if (ret)
45167diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
45168index b7eb86a..36d28af 100644
45169--- a/drivers/usb/atm/cxacru.c
45170+++ b/drivers/usb/atm/cxacru.c
45171@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
45172 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
45173 if (ret < 2)
45174 return -EINVAL;
45175- if (index < 0 || index > 0x7f)
45176+ if (index > 0x7f)
45177 return -EINVAL;
45178 pos += tmp;
45179
45180diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
45181index 35f10bf..6a38a0b 100644
45182--- a/drivers/usb/atm/usbatm.c
45183+++ b/drivers/usb/atm/usbatm.c
45184@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
45185 if (printk_ratelimit())
45186 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
45187 __func__, vpi, vci);
45188- atomic_inc(&vcc->stats->rx_err);
45189+ atomic_inc_unchecked(&vcc->stats->rx_err);
45190 return;
45191 }
45192
45193@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
45194 if (length > ATM_MAX_AAL5_PDU) {
45195 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
45196 __func__, length, vcc);
45197- atomic_inc(&vcc->stats->rx_err);
45198+ atomic_inc_unchecked(&vcc->stats->rx_err);
45199 goto out;
45200 }
45201
45202@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
45203 if (sarb->len < pdu_length) {
45204 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
45205 __func__, pdu_length, sarb->len, vcc);
45206- atomic_inc(&vcc->stats->rx_err);
45207+ atomic_inc_unchecked(&vcc->stats->rx_err);
45208 goto out;
45209 }
45210
45211 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
45212 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
45213 __func__, vcc);
45214- atomic_inc(&vcc->stats->rx_err);
45215+ atomic_inc_unchecked(&vcc->stats->rx_err);
45216 goto out;
45217 }
45218
45219@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
45220 if (printk_ratelimit())
45221 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
45222 __func__, length);
45223- atomic_inc(&vcc->stats->rx_drop);
45224+ atomic_inc_unchecked(&vcc->stats->rx_drop);
45225 goto out;
45226 }
45227
45228@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
45229
45230 vcc->push(vcc, skb);
45231
45232- atomic_inc(&vcc->stats->rx);
45233+ atomic_inc_unchecked(&vcc->stats->rx);
45234 out:
45235 skb_trim(sarb, 0);
45236 }
45237@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
45238 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
45239
45240 usbatm_pop(vcc, skb);
45241- atomic_inc(&vcc->stats->tx);
45242+ atomic_inc_unchecked(&vcc->stats->tx);
45243
45244 skb = skb_dequeue(&instance->sndqueue);
45245 }
45246@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
45247 if (!left--)
45248 return sprintf(page,
45249 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
45250- atomic_read(&atm_dev->stats.aal5.tx),
45251- atomic_read(&atm_dev->stats.aal5.tx_err),
45252- atomic_read(&atm_dev->stats.aal5.rx),
45253- atomic_read(&atm_dev->stats.aal5.rx_err),
45254- atomic_read(&atm_dev->stats.aal5.rx_drop));
45255+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
45256+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
45257+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
45258+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
45259+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
45260
45261 if (!left--) {
45262 if (instance->disconnected)
45263diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
45264index cbacea9..246cccd 100644
45265--- a/drivers/usb/core/devices.c
45266+++ b/drivers/usb/core/devices.c
45267@@ -126,7 +126,7 @@ static const char format_endpt[] =
45268 * time it gets called.
45269 */
45270 static struct device_connect_event {
45271- atomic_t count;
45272+ atomic_unchecked_t count;
45273 wait_queue_head_t wait;
45274 } device_event = {
45275 .count = ATOMIC_INIT(1),
45276@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
45277
45278 void usbfs_conn_disc_event(void)
45279 {
45280- atomic_add(2, &device_event.count);
45281+ atomic_add_unchecked(2, &device_event.count);
45282 wake_up(&device_event.wait);
45283 }
45284
45285@@ -645,7 +645,7 @@ static unsigned int usb_device_poll(struct file *file,
45286
45287 poll_wait(file, &device_event.wait, wait);
45288
45289- event_count = atomic_read(&device_event.count);
45290+ event_count = atomic_read_unchecked(&device_event.count);
45291 if (file->f_version != event_count) {
45292 file->f_version = event_count;
45293 return POLLIN | POLLRDNORM;
45294diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
45295index 8e64adf..9a33a3c 100644
45296--- a/drivers/usb/core/hcd.c
45297+++ b/drivers/usb/core/hcd.c
45298@@ -1522,7 +1522,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
45299 */
45300 usb_get_urb(urb);
45301 atomic_inc(&urb->use_count);
45302- atomic_inc(&urb->dev->urbnum);
45303+ atomic_inc_unchecked(&urb->dev->urbnum);
45304 usbmon_urb_submit(&hcd->self, urb);
45305
45306 /* NOTE requirements on root-hub callers (usbfs and the hub
45307@@ -1549,7 +1549,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
45308 urb->hcpriv = NULL;
45309 INIT_LIST_HEAD(&urb->urb_list);
45310 atomic_dec(&urb->use_count);
45311- atomic_dec(&urb->dev->urbnum);
45312+ atomic_dec_unchecked(&urb->dev->urbnum);
45313 if (atomic_read(&urb->reject))
45314 wake_up(&usb_kill_urb_queue);
45315 usb_put_urb(urb);
45316diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
45317index 131f736..99004c3 100644
45318--- a/drivers/usb/core/message.c
45319+++ b/drivers/usb/core/message.c
45320@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
45321 * method can wait for it to complete. Since you don't have a handle on the
45322 * URB used, you can't cancel the request.
45323 */
45324-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
45325+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
45326 __u8 requesttype, __u16 value, __u16 index, void *data,
45327 __u16 size, int timeout)
45328 {
45329diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
45330index 818e4a0..0fc9589 100644
45331--- a/drivers/usb/core/sysfs.c
45332+++ b/drivers/usb/core/sysfs.c
45333@@ -226,7 +226,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
45334 struct usb_device *udev;
45335
45336 udev = to_usb_device(dev);
45337- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
45338+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
45339 }
45340 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
45341
45342diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
45343index f81b925..78d22ec 100644
45344--- a/drivers/usb/core/usb.c
45345+++ b/drivers/usb/core/usb.c
45346@@ -388,7 +388,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
45347 set_dev_node(&dev->dev, dev_to_node(bus->controller));
45348 dev->state = USB_STATE_ATTACHED;
45349 dev->lpm_disable_count = 1;
45350- atomic_set(&dev->urbnum, 0);
45351+ atomic_set_unchecked(&dev->urbnum, 0);
45352
45353 INIT_LIST_HEAD(&dev->ep0.urb_list);
45354 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
45355diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
45356index 5e29dde..eca992f 100644
45357--- a/drivers/usb/early/ehci-dbgp.c
45358+++ b/drivers/usb/early/ehci-dbgp.c
45359@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
45360
45361 #ifdef CONFIG_KGDB
45362 static struct kgdb_io kgdbdbgp_io_ops;
45363-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
45364+static struct kgdb_io kgdbdbgp_io_ops_console;
45365+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
45366 #else
45367 #define dbgp_kgdb_mode (0)
45368 #endif
45369@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
45370 .write_char = kgdbdbgp_write_char,
45371 };
45372
45373+static struct kgdb_io kgdbdbgp_io_ops_console = {
45374+ .name = "kgdbdbgp",
45375+ .read_char = kgdbdbgp_read_char,
45376+ .write_char = kgdbdbgp_write_char,
45377+ .is_console = 1
45378+};
45379+
45380 static int kgdbdbgp_wait_time;
45381
45382 static int __init kgdbdbgp_parse_config(char *str)
45383@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
45384 ptr++;
45385 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
45386 }
45387- kgdb_register_io_module(&kgdbdbgp_io_ops);
45388- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
45389+ if (early_dbgp_console.index != -1)
45390+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
45391+ else
45392+ kgdb_register_io_module(&kgdbdbgp_io_ops);
45393
45394 return 0;
45395 }
45396diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
45397index 598dcc1..032dd4f 100644
45398--- a/drivers/usb/gadget/u_serial.c
45399+++ b/drivers/usb/gadget/u_serial.c
45400@@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
45401 spin_lock_irq(&port->port_lock);
45402
45403 /* already open? Great. */
45404- if (port->port.count) {
45405+ if (atomic_read(&port->port.count)) {
45406 status = 0;
45407- port->port.count++;
45408+ atomic_inc(&port->port.count);
45409
45410 /* currently opening/closing? wait ... */
45411 } else if (port->openclose) {
45412@@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
45413 tty->driver_data = port;
45414 port->port.tty = tty;
45415
45416- port->port.count = 1;
45417+ atomic_set(&port->port.count, 1);
45418 port->openclose = false;
45419
45420 /* if connected, start the I/O stream */
45421@@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
45422
45423 spin_lock_irq(&port->port_lock);
45424
45425- if (port->port.count != 1) {
45426- if (port->port.count == 0)
45427+ if (atomic_read(&port->port.count) != 1) {
45428+ if (atomic_read(&port->port.count) == 0)
45429 WARN_ON(1);
45430 else
45431- --port->port.count;
45432+ atomic_dec(&port->port.count);
45433 goto exit;
45434 }
45435
45436@@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
45437 * and sleep if necessary
45438 */
45439 port->openclose = true;
45440- port->port.count = 0;
45441+ atomic_set(&port->port.count, 0);
45442
45443 gser = port->port_usb;
45444 if (gser && gser->disconnect)
45445@@ -1159,7 +1159,7 @@ static int gs_closed(struct gs_port *port)
45446 int cond;
45447
45448 spin_lock_irq(&port->port_lock);
45449- cond = (port->port.count == 0) && !port->openclose;
45450+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
45451 spin_unlock_irq(&port->port_lock);
45452 return cond;
45453 }
45454@@ -1273,7 +1273,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
45455 /* if it's already open, start I/O ... and notify the serial
45456 * protocol about open/close status (connect/disconnect).
45457 */
45458- if (port->port.count) {
45459+ if (atomic_read(&port->port.count)) {
45460 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
45461 gs_start_io(port);
45462 if (gser->connect)
45463@@ -1320,7 +1320,7 @@ void gserial_disconnect(struct gserial *gser)
45464
45465 port->port_usb = NULL;
45466 gser->ioport = NULL;
45467- if (port->port.count > 0 || port->openclose) {
45468+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
45469 wake_up_interruptible(&port->drain_wait);
45470 if (port->port.tty)
45471 tty_hangup(port->port.tty);
45472@@ -1336,7 +1336,7 @@ void gserial_disconnect(struct gserial *gser)
45473
45474 /* finally, free any unused/unusable I/O buffers */
45475 spin_lock_irqsave(&port->port_lock, flags);
45476- if (port->port.count == 0 && !port->openclose)
45477+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
45478 gs_buf_free(&port->port_write_buf);
45479 gs_free_requests(gser->out, &port->read_pool, NULL);
45480 gs_free_requests(gser->out, &port->read_queue, NULL);
45481diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
45482index 5f3bcd3..bfca43f 100644
45483--- a/drivers/usb/serial/console.c
45484+++ b/drivers/usb/serial/console.c
45485@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
45486
45487 info->port = port;
45488
45489- ++port->port.count;
45490+ atomic_inc(&port->port.count);
45491 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
45492 if (serial->type->set_termios) {
45493 /*
45494@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
45495 }
45496 /* Now that any required fake tty operations are completed restore
45497 * the tty port count */
45498- --port->port.count;
45499+ atomic_dec(&port->port.count);
45500 /* The console is special in terms of closing the device so
45501 * indicate this port is now acting as a system console. */
45502 port->port.console = 1;
45503@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
45504 free_tty:
45505 kfree(tty);
45506 reset_open_count:
45507- port->port.count = 0;
45508+ atomic_set(&port->port.count, 0);
45509 usb_autopm_put_interface(serial->interface);
45510 error_get_interface:
45511 usb_serial_put(serial);
45512diff --git a/drivers/usb/storage/realtek_cr.c b/drivers/usb/storage/realtek_cr.c
45513index 6c3586a..a94e621 100644
45514--- a/drivers/usb/storage/realtek_cr.c
45515+++ b/drivers/usb/storage/realtek_cr.c
45516@@ -429,7 +429,7 @@ static int rts51x_read_status(struct us_data *us,
45517
45518 buf = kmalloc(len, GFP_NOIO);
45519 if (buf == NULL)
45520- return USB_STOR_TRANSPORT_ERROR;
45521+ return -ENOMEM;
45522
45523 US_DEBUGP("%s, lun = %d\n", __func__, lun);
45524
45525diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
45526index 75f70f0..d467e1a 100644
45527--- a/drivers/usb/storage/usb.h
45528+++ b/drivers/usb/storage/usb.h
45529@@ -63,7 +63,7 @@ struct us_unusual_dev {
45530 __u8 useProtocol;
45531 __u8 useTransport;
45532 int (*initFunction)(struct us_data *);
45533-};
45534+} __do_const;
45535
45536
45537 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
45538diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
45539index d6bea3e..60b250e 100644
45540--- a/drivers/usb/wusbcore/wa-hc.h
45541+++ b/drivers/usb/wusbcore/wa-hc.h
45542@@ -192,7 +192,7 @@ struct wahc {
45543 struct list_head xfer_delayed_list;
45544 spinlock_t xfer_list_lock;
45545 struct work_struct xfer_work;
45546- atomic_t xfer_id_count;
45547+ atomic_unchecked_t xfer_id_count;
45548 };
45549
45550
45551@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
45552 INIT_LIST_HEAD(&wa->xfer_delayed_list);
45553 spin_lock_init(&wa->xfer_list_lock);
45554 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
45555- atomic_set(&wa->xfer_id_count, 1);
45556+ atomic_set_unchecked(&wa->xfer_id_count, 1);
45557 }
45558
45559 /**
45560diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
45561index 57c01ab..8a05959 100644
45562--- a/drivers/usb/wusbcore/wa-xfer.c
45563+++ b/drivers/usb/wusbcore/wa-xfer.c
45564@@ -296,7 +296,7 @@ out:
45565 */
45566 static void wa_xfer_id_init(struct wa_xfer *xfer)
45567 {
45568- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
45569+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
45570 }
45571
45572 /*
45573diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
45574index 8c55011..eed4ae1a 100644
45575--- a/drivers/video/aty/aty128fb.c
45576+++ b/drivers/video/aty/aty128fb.c
45577@@ -149,7 +149,7 @@ enum {
45578 };
45579
45580 /* Must match above enum */
45581-static char * const r128_family[] = {
45582+static const char * const r128_family[] = {
45583 "AGP",
45584 "PCI",
45585 "PRO AGP",
45586diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
45587index 4f27fdc..d3537e6 100644
45588--- a/drivers/video/aty/atyfb_base.c
45589+++ b/drivers/video/aty/atyfb_base.c
45590@@ -1325,10 +1325,14 @@ static int atyfb_set_par(struct fb_info *info)
45591 par->accel_flags = var->accel_flags; /* hack */
45592
45593 if (var->accel_flags) {
45594- info->fbops->fb_sync = atyfb_sync;
45595+ pax_open_kernel();
45596+ *(void **)&info->fbops->fb_sync = atyfb_sync;
45597+ pax_close_kernel();
45598 info->flags &= ~FBINFO_HWACCEL_DISABLED;
45599 } else {
45600- info->fbops->fb_sync = NULL;
45601+ pax_open_kernel();
45602+ *(void **)&info->fbops->fb_sync = NULL;
45603+ pax_close_kernel();
45604 info->flags |= FBINFO_HWACCEL_DISABLED;
45605 }
45606
45607diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
45608index 95ec042..e6affdd 100644
45609--- a/drivers/video/aty/mach64_cursor.c
45610+++ b/drivers/video/aty/mach64_cursor.c
45611@@ -7,6 +7,7 @@
45612 #include <linux/string.h>
45613
45614 #include <asm/io.h>
45615+#include <asm/pgtable.h>
45616
45617 #ifdef __sparc__
45618 #include <asm/fbio.h>
45619@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
45620 info->sprite.buf_align = 16; /* and 64 lines tall. */
45621 info->sprite.flags = FB_PIXMAP_IO;
45622
45623- info->fbops->fb_cursor = atyfb_cursor;
45624+ pax_open_kernel();
45625+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
45626+ pax_close_kernel();
45627
45628 return 0;
45629 }
45630diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
45631index 6c5ed6b..b727c88 100644
45632--- a/drivers/video/backlight/kb3886_bl.c
45633+++ b/drivers/video/backlight/kb3886_bl.c
45634@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
45635 static unsigned long kb3886bl_flags;
45636 #define KB3886BL_SUSPENDED 0x01
45637
45638-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
45639+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
45640 {
45641 .ident = "Sahara Touch-iT",
45642 .matches = {
45643diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
45644index 88cad6b..dd746c7 100644
45645--- a/drivers/video/fb_defio.c
45646+++ b/drivers/video/fb_defio.c
45647@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
45648
45649 BUG_ON(!fbdefio);
45650 mutex_init(&fbdefio->lock);
45651- info->fbops->fb_mmap = fb_deferred_io_mmap;
45652+ pax_open_kernel();
45653+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
45654+ pax_close_kernel();
45655 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
45656 INIT_LIST_HEAD(&fbdefio->pagelist);
45657 if (fbdefio->delay == 0) /* set a default of 1 s */
45658@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
45659 page->mapping = NULL;
45660 }
45661
45662- info->fbops->fb_mmap = NULL;
45663+ *(void **)&info->fbops->fb_mmap = NULL;
45664 mutex_destroy(&fbdefio->lock);
45665 }
45666 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
45667diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
45668index 5c3960d..15cf8fc 100644
45669--- a/drivers/video/fbcmap.c
45670+++ b/drivers/video/fbcmap.c
45671@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
45672 rc = -ENODEV;
45673 goto out;
45674 }
45675- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
45676- !info->fbops->fb_setcmap)) {
45677+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
45678 rc = -EINVAL;
45679 goto out1;
45680 }
45681diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
45682index dc61c12..e29796e 100644
45683--- a/drivers/video/fbmem.c
45684+++ b/drivers/video/fbmem.c
45685@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
45686 image->dx += image->width + 8;
45687 }
45688 } else if (rotate == FB_ROTATE_UD) {
45689- for (x = 0; x < num && image->dx >= 0; x++) {
45690+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
45691 info->fbops->fb_imageblit(info, image);
45692 image->dx -= image->width + 8;
45693 }
45694@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
45695 image->dy += image->height + 8;
45696 }
45697 } else if (rotate == FB_ROTATE_CCW) {
45698- for (x = 0; x < num && image->dy >= 0; x++) {
45699+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
45700 info->fbops->fb_imageblit(info, image);
45701 image->dy -= image->height + 8;
45702 }
45703@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
45704 return -EFAULT;
45705 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
45706 return -EINVAL;
45707- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
45708+ if (con2fb.framebuffer >= FB_MAX)
45709 return -EINVAL;
45710 if (!registered_fb[con2fb.framebuffer])
45711 request_module("fb%d", con2fb.framebuffer);
45712diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
45713index 7672d2e..b56437f 100644
45714--- a/drivers/video/i810/i810_accel.c
45715+++ b/drivers/video/i810/i810_accel.c
45716@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
45717 }
45718 }
45719 printk("ringbuffer lockup!!!\n");
45720+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
45721 i810_report_error(mmio);
45722 par->dev_flags |= LOCKUP;
45723 info->pixmap.scan_align = 1;
45724diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
45725index 3c14e43..eafa544 100644
45726--- a/drivers/video/logo/logo_linux_clut224.ppm
45727+++ b/drivers/video/logo/logo_linux_clut224.ppm
45728@@ -1,1604 +1,1123 @@
45729 P3
45730-# Standard 224-color Linux logo
45731 80 80
45732 255
45733- 0 0 0 0 0 0 0 0 0 0 0 0
45734- 0 0 0 0 0 0 0 0 0 0 0 0
45735- 0 0 0 0 0 0 0 0 0 0 0 0
45736- 0 0 0 0 0 0 0 0 0 0 0 0
45737- 0 0 0 0 0 0 0 0 0 0 0 0
45738- 0 0 0 0 0 0 0 0 0 0 0 0
45739- 0 0 0 0 0 0 0 0 0 0 0 0
45740- 0 0 0 0 0 0 0 0 0 0 0 0
45741- 0 0 0 0 0 0 0 0 0 0 0 0
45742- 6 6 6 6 6 6 10 10 10 10 10 10
45743- 10 10 10 6 6 6 6 6 6 6 6 6
45744- 0 0 0 0 0 0 0 0 0 0 0 0
45745- 0 0 0 0 0 0 0 0 0 0 0 0
45746- 0 0 0 0 0 0 0 0 0 0 0 0
45747- 0 0 0 0 0 0 0 0 0 0 0 0
45748- 0 0 0 0 0 0 0 0 0 0 0 0
45749- 0 0 0 0 0 0 0 0 0 0 0 0
45750- 0 0 0 0 0 0 0 0 0 0 0 0
45751- 0 0 0 0 0 0 0 0 0 0 0 0
45752- 0 0 0 0 0 0 0 0 0 0 0 0
45753- 0 0 0 0 0 0 0 0 0 0 0 0
45754- 0 0 0 0 0 0 0 0 0 0 0 0
45755- 0 0 0 0 0 0 0 0 0 0 0 0
45756- 0 0 0 0 0 0 0 0 0 0 0 0
45757- 0 0 0 0 0 0 0 0 0 0 0 0
45758- 0 0 0 0 0 0 0 0 0 0 0 0
45759- 0 0 0 0 0 0 0 0 0 0 0 0
45760- 0 0 0 0 0 0 0 0 0 0 0 0
45761- 0 0 0 6 6 6 10 10 10 14 14 14
45762- 22 22 22 26 26 26 30 30 30 34 34 34
45763- 30 30 30 30 30 30 26 26 26 18 18 18
45764- 14 14 14 10 10 10 6 6 6 0 0 0
45765- 0 0 0 0 0 0 0 0 0 0 0 0
45766- 0 0 0 0 0 0 0 0 0 0 0 0
45767- 0 0 0 0 0 0 0 0 0 0 0 0
45768- 0 0 0 0 0 0 0 0 0 0 0 0
45769- 0 0 0 0 0 0 0 0 0 0 0 0
45770- 0 0 0 0 0 0 0 0 0 0 0 0
45771- 0 0 0 0 0 0 0 0 0 0 0 0
45772- 0 0 0 0 0 0 0 0 0 0 0 0
45773- 0 0 0 0 0 0 0 0 0 0 0 0
45774- 0 0 0 0 0 1 0 0 1 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- 6 6 6 14 14 14 26 26 26 42 42 42
45782- 54 54 54 66 66 66 78 78 78 78 78 78
45783- 78 78 78 74 74 74 66 66 66 54 54 54
45784- 42 42 42 26 26 26 18 18 18 10 10 10
45785- 6 6 6 0 0 0 0 0 0 0 0 0
45786- 0 0 0 0 0 0 0 0 0 0 0 0
45787- 0 0 0 0 0 0 0 0 0 0 0 0
45788- 0 0 0 0 0 0 0 0 0 0 0 0
45789- 0 0 0 0 0 0 0 0 0 0 0 0
45790- 0 0 0 0 0 0 0 0 0 0 0 0
45791- 0 0 0 0 0 0 0 0 0 0 0 0
45792- 0 0 0 0 0 0 0 0 0 0 0 0
45793- 0 0 0 0 0 0 0 0 0 0 0 0
45794- 0 0 1 0 0 0 0 0 0 0 0 0
45795- 0 0 0 0 0 0 0 0 0 0 0 0
45796- 0 0 0 0 0 0 0 0 0 0 0 0
45797- 0 0 0 0 0 0 0 0 0 0 0 0
45798- 0 0 0 0 0 0 0 0 0 0 0 0
45799- 0 0 0 0 0 0 0 0 0 0 0 0
45800- 0 0 0 0 0 0 0 0 0 10 10 10
45801- 22 22 22 42 42 42 66 66 66 86 86 86
45802- 66 66 66 38 38 38 38 38 38 22 22 22
45803- 26 26 26 34 34 34 54 54 54 66 66 66
45804- 86 86 86 70 70 70 46 46 46 26 26 26
45805- 14 14 14 6 6 6 0 0 0 0 0 0
45806- 0 0 0 0 0 0 0 0 0 0 0 0
45807- 0 0 0 0 0 0 0 0 0 0 0 0
45808- 0 0 0 0 0 0 0 0 0 0 0 0
45809- 0 0 0 0 0 0 0 0 0 0 0 0
45810- 0 0 0 0 0 0 0 0 0 0 0 0
45811- 0 0 0 0 0 0 0 0 0 0 0 0
45812- 0 0 0 0 0 0 0 0 0 0 0 0
45813- 0 0 0 0 0 0 0 0 0 0 0 0
45814- 0 0 1 0 0 1 0 0 1 0 0 0
45815- 0 0 0 0 0 0 0 0 0 0 0 0
45816- 0 0 0 0 0 0 0 0 0 0 0 0
45817- 0 0 0 0 0 0 0 0 0 0 0 0
45818- 0 0 0 0 0 0 0 0 0 0 0 0
45819- 0 0 0 0 0 0 0 0 0 0 0 0
45820- 0 0 0 0 0 0 10 10 10 26 26 26
45821- 50 50 50 82 82 82 58 58 58 6 6 6
45822- 2 2 6 2 2 6 2 2 6 2 2 6
45823- 2 2 6 2 2 6 2 2 6 2 2 6
45824- 6 6 6 54 54 54 86 86 86 66 66 66
45825- 38 38 38 18 18 18 6 6 6 0 0 0
45826- 0 0 0 0 0 0 0 0 0 0 0 0
45827- 0 0 0 0 0 0 0 0 0 0 0 0
45828- 0 0 0 0 0 0 0 0 0 0 0 0
45829- 0 0 0 0 0 0 0 0 0 0 0 0
45830- 0 0 0 0 0 0 0 0 0 0 0 0
45831- 0 0 0 0 0 0 0 0 0 0 0 0
45832- 0 0 0 0 0 0 0 0 0 0 0 0
45833- 0 0 0 0 0 0 0 0 0 0 0 0
45834- 0 0 0 0 0 0 0 0 0 0 0 0
45835- 0 0 0 0 0 0 0 0 0 0 0 0
45836- 0 0 0 0 0 0 0 0 0 0 0 0
45837- 0 0 0 0 0 0 0 0 0 0 0 0
45838- 0 0 0 0 0 0 0 0 0 0 0 0
45839- 0 0 0 0 0 0 0 0 0 0 0 0
45840- 0 0 0 6 6 6 22 22 22 50 50 50
45841- 78 78 78 34 34 34 2 2 6 2 2 6
45842- 2 2 6 2 2 6 2 2 6 2 2 6
45843- 2 2 6 2 2 6 2 2 6 2 2 6
45844- 2 2 6 2 2 6 6 6 6 70 70 70
45845- 78 78 78 46 46 46 22 22 22 6 6 6
45846- 0 0 0 0 0 0 0 0 0 0 0 0
45847- 0 0 0 0 0 0 0 0 0 0 0 0
45848- 0 0 0 0 0 0 0 0 0 0 0 0
45849- 0 0 0 0 0 0 0 0 0 0 0 0
45850- 0 0 0 0 0 0 0 0 0 0 0 0
45851- 0 0 0 0 0 0 0 0 0 0 0 0
45852- 0 0 0 0 0 0 0 0 0 0 0 0
45853- 0 0 0 0 0 0 0 0 0 0 0 0
45854- 0 0 1 0 0 1 0 0 1 0 0 0
45855- 0 0 0 0 0 0 0 0 0 0 0 0
45856- 0 0 0 0 0 0 0 0 0 0 0 0
45857- 0 0 0 0 0 0 0 0 0 0 0 0
45858- 0 0 0 0 0 0 0 0 0 0 0 0
45859- 0 0 0 0 0 0 0 0 0 0 0 0
45860- 6 6 6 18 18 18 42 42 42 82 82 82
45861- 26 26 26 2 2 6 2 2 6 2 2 6
45862- 2 2 6 2 2 6 2 2 6 2 2 6
45863- 2 2 6 2 2 6 2 2 6 14 14 14
45864- 46 46 46 34 34 34 6 6 6 2 2 6
45865- 42 42 42 78 78 78 42 42 42 18 18 18
45866- 6 6 6 0 0 0 0 0 0 0 0 0
45867- 0 0 0 0 0 0 0 0 0 0 0 0
45868- 0 0 0 0 0 0 0 0 0 0 0 0
45869- 0 0 0 0 0 0 0 0 0 0 0 0
45870- 0 0 0 0 0 0 0 0 0 0 0 0
45871- 0 0 0 0 0 0 0 0 0 0 0 0
45872- 0 0 0 0 0 0 0 0 0 0 0 0
45873- 0 0 0 0 0 0 0 0 0 0 0 0
45874- 0 0 1 0 0 0 0 0 1 0 0 0
45875- 0 0 0 0 0 0 0 0 0 0 0 0
45876- 0 0 0 0 0 0 0 0 0 0 0 0
45877- 0 0 0 0 0 0 0 0 0 0 0 0
45878- 0 0 0 0 0 0 0 0 0 0 0 0
45879- 0 0 0 0 0 0 0 0 0 0 0 0
45880- 10 10 10 30 30 30 66 66 66 58 58 58
45881- 2 2 6 2 2 6 2 2 6 2 2 6
45882- 2 2 6 2 2 6 2 2 6 2 2 6
45883- 2 2 6 2 2 6 2 2 6 26 26 26
45884- 86 86 86 101 101 101 46 46 46 10 10 10
45885- 2 2 6 58 58 58 70 70 70 34 34 34
45886- 10 10 10 0 0 0 0 0 0 0 0 0
45887- 0 0 0 0 0 0 0 0 0 0 0 0
45888- 0 0 0 0 0 0 0 0 0 0 0 0
45889- 0 0 0 0 0 0 0 0 0 0 0 0
45890- 0 0 0 0 0 0 0 0 0 0 0 0
45891- 0 0 0 0 0 0 0 0 0 0 0 0
45892- 0 0 0 0 0 0 0 0 0 0 0 0
45893- 0 0 0 0 0 0 0 0 0 0 0 0
45894- 0 0 1 0 0 1 0 0 1 0 0 0
45895- 0 0 0 0 0 0 0 0 0 0 0 0
45896- 0 0 0 0 0 0 0 0 0 0 0 0
45897- 0 0 0 0 0 0 0 0 0 0 0 0
45898- 0 0 0 0 0 0 0 0 0 0 0 0
45899- 0 0 0 0 0 0 0 0 0 0 0 0
45900- 14 14 14 42 42 42 86 86 86 10 10 10
45901- 2 2 6 2 2 6 2 2 6 2 2 6
45902- 2 2 6 2 2 6 2 2 6 2 2 6
45903- 2 2 6 2 2 6 2 2 6 30 30 30
45904- 94 94 94 94 94 94 58 58 58 26 26 26
45905- 2 2 6 6 6 6 78 78 78 54 54 54
45906- 22 22 22 6 6 6 0 0 0 0 0 0
45907- 0 0 0 0 0 0 0 0 0 0 0 0
45908- 0 0 0 0 0 0 0 0 0 0 0 0
45909- 0 0 0 0 0 0 0 0 0 0 0 0
45910- 0 0 0 0 0 0 0 0 0 0 0 0
45911- 0 0 0 0 0 0 0 0 0 0 0 0
45912- 0 0 0 0 0 0 0 0 0 0 0 0
45913- 0 0 0 0 0 0 0 0 0 0 0 0
45914- 0 0 0 0 0 0 0 0 0 0 0 0
45915- 0 0 0 0 0 0 0 0 0 0 0 0
45916- 0 0 0 0 0 0 0 0 0 0 0 0
45917- 0 0 0 0 0 0 0 0 0 0 0 0
45918- 0 0 0 0 0 0 0 0 0 0 0 0
45919- 0 0 0 0 0 0 0 0 0 6 6 6
45920- 22 22 22 62 62 62 62 62 62 2 2 6
45921- 2 2 6 2 2 6 2 2 6 2 2 6
45922- 2 2 6 2 2 6 2 2 6 2 2 6
45923- 2 2 6 2 2 6 2 2 6 26 26 26
45924- 54 54 54 38 38 38 18 18 18 10 10 10
45925- 2 2 6 2 2 6 34 34 34 82 82 82
45926- 38 38 38 14 14 14 0 0 0 0 0 0
45927- 0 0 0 0 0 0 0 0 0 0 0 0
45928- 0 0 0 0 0 0 0 0 0 0 0 0
45929- 0 0 0 0 0 0 0 0 0 0 0 0
45930- 0 0 0 0 0 0 0 0 0 0 0 0
45931- 0 0 0 0 0 0 0 0 0 0 0 0
45932- 0 0 0 0 0 0 0 0 0 0 0 0
45933- 0 0 0 0 0 0 0 0 0 0 0 0
45934- 0 0 0 0 0 1 0 0 1 0 0 0
45935- 0 0 0 0 0 0 0 0 0 0 0 0
45936- 0 0 0 0 0 0 0 0 0 0 0 0
45937- 0 0 0 0 0 0 0 0 0 0 0 0
45938- 0 0 0 0 0 0 0 0 0 0 0 0
45939- 0 0 0 0 0 0 0 0 0 6 6 6
45940- 30 30 30 78 78 78 30 30 30 2 2 6
45941- 2 2 6 2 2 6 2 2 6 2 2 6
45942- 2 2 6 2 2 6 2 2 6 2 2 6
45943- 2 2 6 2 2 6 2 2 6 10 10 10
45944- 10 10 10 2 2 6 2 2 6 2 2 6
45945- 2 2 6 2 2 6 2 2 6 78 78 78
45946- 50 50 50 18 18 18 6 6 6 0 0 0
45947- 0 0 0 0 0 0 0 0 0 0 0 0
45948- 0 0 0 0 0 0 0 0 0 0 0 0
45949- 0 0 0 0 0 0 0 0 0 0 0 0
45950- 0 0 0 0 0 0 0 0 0 0 0 0
45951- 0 0 0 0 0 0 0 0 0 0 0 0
45952- 0 0 0 0 0 0 0 0 0 0 0 0
45953- 0 0 0 0 0 0 0 0 0 0 0 0
45954- 0 0 1 0 0 0 0 0 0 0 0 0
45955- 0 0 0 0 0 0 0 0 0 0 0 0
45956- 0 0 0 0 0 0 0 0 0 0 0 0
45957- 0 0 0 0 0 0 0 0 0 0 0 0
45958- 0 0 0 0 0 0 0 0 0 0 0 0
45959- 0 0 0 0 0 0 0 0 0 10 10 10
45960- 38 38 38 86 86 86 14 14 14 2 2 6
45961- 2 2 6 2 2 6 2 2 6 2 2 6
45962- 2 2 6 2 2 6 2 2 6 2 2 6
45963- 2 2 6 2 2 6 2 2 6 2 2 6
45964- 2 2 6 2 2 6 2 2 6 2 2 6
45965- 2 2 6 2 2 6 2 2 6 54 54 54
45966- 66 66 66 26 26 26 6 6 6 0 0 0
45967- 0 0 0 0 0 0 0 0 0 0 0 0
45968- 0 0 0 0 0 0 0 0 0 0 0 0
45969- 0 0 0 0 0 0 0 0 0 0 0 0
45970- 0 0 0 0 0 0 0 0 0 0 0 0
45971- 0 0 0 0 0 0 0 0 0 0 0 0
45972- 0 0 0 0 0 0 0 0 0 0 0 0
45973- 0 0 0 0 0 0 0 0 0 0 0 0
45974- 0 0 0 0 0 1 0 0 1 0 0 0
45975- 0 0 0 0 0 0 0 0 0 0 0 0
45976- 0 0 0 0 0 0 0 0 0 0 0 0
45977- 0 0 0 0 0 0 0 0 0 0 0 0
45978- 0 0 0 0 0 0 0 0 0 0 0 0
45979- 0 0 0 0 0 0 0 0 0 14 14 14
45980- 42 42 42 82 82 82 2 2 6 2 2 6
45981- 2 2 6 6 6 6 10 10 10 2 2 6
45982- 2 2 6 2 2 6 2 2 6 2 2 6
45983- 2 2 6 2 2 6 2 2 6 6 6 6
45984- 14 14 14 10 10 10 2 2 6 2 2 6
45985- 2 2 6 2 2 6 2 2 6 18 18 18
45986- 82 82 82 34 34 34 10 10 10 0 0 0
45987- 0 0 0 0 0 0 0 0 0 0 0 0
45988- 0 0 0 0 0 0 0 0 0 0 0 0
45989- 0 0 0 0 0 0 0 0 0 0 0 0
45990- 0 0 0 0 0 0 0 0 0 0 0 0
45991- 0 0 0 0 0 0 0 0 0 0 0 0
45992- 0 0 0 0 0 0 0 0 0 0 0 0
45993- 0 0 0 0 0 0 0 0 0 0 0 0
45994- 0 0 1 0 0 0 0 0 0 0 0 0
45995- 0 0 0 0 0 0 0 0 0 0 0 0
45996- 0 0 0 0 0 0 0 0 0 0 0 0
45997- 0 0 0 0 0 0 0 0 0 0 0 0
45998- 0 0 0 0 0 0 0 0 0 0 0 0
45999- 0 0 0 0 0 0 0 0 0 14 14 14
46000- 46 46 46 86 86 86 2 2 6 2 2 6
46001- 6 6 6 6 6 6 22 22 22 34 34 34
46002- 6 6 6 2 2 6 2 2 6 2 2 6
46003- 2 2 6 2 2 6 18 18 18 34 34 34
46004- 10 10 10 50 50 50 22 22 22 2 2 6
46005- 2 2 6 2 2 6 2 2 6 10 10 10
46006- 86 86 86 42 42 42 14 14 14 0 0 0
46007- 0 0 0 0 0 0 0 0 0 0 0 0
46008- 0 0 0 0 0 0 0 0 0 0 0 0
46009- 0 0 0 0 0 0 0 0 0 0 0 0
46010- 0 0 0 0 0 0 0 0 0 0 0 0
46011- 0 0 0 0 0 0 0 0 0 0 0 0
46012- 0 0 0 0 0 0 0 0 0 0 0 0
46013- 0 0 0 0 0 0 0 0 0 0 0 0
46014- 0 0 1 0 0 1 0 0 1 0 0 0
46015- 0 0 0 0 0 0 0 0 0 0 0 0
46016- 0 0 0 0 0 0 0 0 0 0 0 0
46017- 0 0 0 0 0 0 0 0 0 0 0 0
46018- 0 0 0 0 0 0 0 0 0 0 0 0
46019- 0 0 0 0 0 0 0 0 0 14 14 14
46020- 46 46 46 86 86 86 2 2 6 2 2 6
46021- 38 38 38 116 116 116 94 94 94 22 22 22
46022- 22 22 22 2 2 6 2 2 6 2 2 6
46023- 14 14 14 86 86 86 138 138 138 162 162 162
46024-154 154 154 38 38 38 26 26 26 6 6 6
46025- 2 2 6 2 2 6 2 2 6 2 2 6
46026- 86 86 86 46 46 46 14 14 14 0 0 0
46027- 0 0 0 0 0 0 0 0 0 0 0 0
46028- 0 0 0 0 0 0 0 0 0 0 0 0
46029- 0 0 0 0 0 0 0 0 0 0 0 0
46030- 0 0 0 0 0 0 0 0 0 0 0 0
46031- 0 0 0 0 0 0 0 0 0 0 0 0
46032- 0 0 0 0 0 0 0 0 0 0 0 0
46033- 0 0 0 0 0 0 0 0 0 0 0 0
46034- 0 0 0 0 0 0 0 0 0 0 0 0
46035- 0 0 0 0 0 0 0 0 0 0 0 0
46036- 0 0 0 0 0 0 0 0 0 0 0 0
46037- 0 0 0 0 0 0 0 0 0 0 0 0
46038- 0 0 0 0 0 0 0 0 0 0 0 0
46039- 0 0 0 0 0 0 0 0 0 14 14 14
46040- 46 46 46 86 86 86 2 2 6 14 14 14
46041-134 134 134 198 198 198 195 195 195 116 116 116
46042- 10 10 10 2 2 6 2 2 6 6 6 6
46043-101 98 89 187 187 187 210 210 210 218 218 218
46044-214 214 214 134 134 134 14 14 14 6 6 6
46045- 2 2 6 2 2 6 2 2 6 2 2 6
46046- 86 86 86 50 50 50 18 18 18 6 6 6
46047- 0 0 0 0 0 0 0 0 0 0 0 0
46048- 0 0 0 0 0 0 0 0 0 0 0 0
46049- 0 0 0 0 0 0 0 0 0 0 0 0
46050- 0 0 0 0 0 0 0 0 0 0 0 0
46051- 0 0 0 0 0 0 0 0 0 0 0 0
46052- 0 0 0 0 0 0 0 0 0 0 0 0
46053- 0 0 0 0 0 0 0 0 1 0 0 0
46054- 0 0 1 0 0 1 0 0 1 0 0 0
46055- 0 0 0 0 0 0 0 0 0 0 0 0
46056- 0 0 0 0 0 0 0 0 0 0 0 0
46057- 0 0 0 0 0 0 0 0 0 0 0 0
46058- 0 0 0 0 0 0 0 0 0 0 0 0
46059- 0 0 0 0 0 0 0 0 0 14 14 14
46060- 46 46 46 86 86 86 2 2 6 54 54 54
46061-218 218 218 195 195 195 226 226 226 246 246 246
46062- 58 58 58 2 2 6 2 2 6 30 30 30
46063-210 210 210 253 253 253 174 174 174 123 123 123
46064-221 221 221 234 234 234 74 74 74 2 2 6
46065- 2 2 6 2 2 6 2 2 6 2 2 6
46066- 70 70 70 58 58 58 22 22 22 6 6 6
46067- 0 0 0 0 0 0 0 0 0 0 0 0
46068- 0 0 0 0 0 0 0 0 0 0 0 0
46069- 0 0 0 0 0 0 0 0 0 0 0 0
46070- 0 0 0 0 0 0 0 0 0 0 0 0
46071- 0 0 0 0 0 0 0 0 0 0 0 0
46072- 0 0 0 0 0 0 0 0 0 0 0 0
46073- 0 0 0 0 0 0 0 0 0 0 0 0
46074- 0 0 0 0 0 0 0 0 0 0 0 0
46075- 0 0 0 0 0 0 0 0 0 0 0 0
46076- 0 0 0 0 0 0 0 0 0 0 0 0
46077- 0 0 0 0 0 0 0 0 0 0 0 0
46078- 0 0 0 0 0 0 0 0 0 0 0 0
46079- 0 0 0 0 0 0 0 0 0 14 14 14
46080- 46 46 46 82 82 82 2 2 6 106 106 106
46081-170 170 170 26 26 26 86 86 86 226 226 226
46082-123 123 123 10 10 10 14 14 14 46 46 46
46083-231 231 231 190 190 190 6 6 6 70 70 70
46084- 90 90 90 238 238 238 158 158 158 2 2 6
46085- 2 2 6 2 2 6 2 2 6 2 2 6
46086- 70 70 70 58 58 58 22 22 22 6 6 6
46087- 0 0 0 0 0 0 0 0 0 0 0 0
46088- 0 0 0 0 0 0 0 0 0 0 0 0
46089- 0 0 0 0 0 0 0 0 0 0 0 0
46090- 0 0 0 0 0 0 0 0 0 0 0 0
46091- 0 0 0 0 0 0 0 0 0 0 0 0
46092- 0 0 0 0 0 0 0 0 0 0 0 0
46093- 0 0 0 0 0 0 0 0 1 0 0 0
46094- 0 0 1 0 0 1 0 0 1 0 0 0
46095- 0 0 0 0 0 0 0 0 0 0 0 0
46096- 0 0 0 0 0 0 0 0 0 0 0 0
46097- 0 0 0 0 0 0 0 0 0 0 0 0
46098- 0 0 0 0 0 0 0 0 0 0 0 0
46099- 0 0 0 0 0 0 0 0 0 14 14 14
46100- 42 42 42 86 86 86 6 6 6 116 116 116
46101-106 106 106 6 6 6 70 70 70 149 149 149
46102-128 128 128 18 18 18 38 38 38 54 54 54
46103-221 221 221 106 106 106 2 2 6 14 14 14
46104- 46 46 46 190 190 190 198 198 198 2 2 6
46105- 2 2 6 2 2 6 2 2 6 2 2 6
46106- 74 74 74 62 62 62 22 22 22 6 6 6
46107- 0 0 0 0 0 0 0 0 0 0 0 0
46108- 0 0 0 0 0 0 0 0 0 0 0 0
46109- 0 0 0 0 0 0 0 0 0 0 0 0
46110- 0 0 0 0 0 0 0 0 0 0 0 0
46111- 0 0 0 0 0 0 0 0 0 0 0 0
46112- 0 0 0 0 0 0 0 0 0 0 0 0
46113- 0 0 0 0 0 0 0 0 1 0 0 0
46114- 0 0 1 0 0 0 0 0 1 0 0 0
46115- 0 0 0 0 0 0 0 0 0 0 0 0
46116- 0 0 0 0 0 0 0 0 0 0 0 0
46117- 0 0 0 0 0 0 0 0 0 0 0 0
46118- 0 0 0 0 0 0 0 0 0 0 0 0
46119- 0 0 0 0 0 0 0 0 0 14 14 14
46120- 42 42 42 94 94 94 14 14 14 101 101 101
46121-128 128 128 2 2 6 18 18 18 116 116 116
46122-118 98 46 121 92 8 121 92 8 98 78 10
46123-162 162 162 106 106 106 2 2 6 2 2 6
46124- 2 2 6 195 195 195 195 195 195 6 6 6
46125- 2 2 6 2 2 6 2 2 6 2 2 6
46126- 74 74 74 62 62 62 22 22 22 6 6 6
46127- 0 0 0 0 0 0 0 0 0 0 0 0
46128- 0 0 0 0 0 0 0 0 0 0 0 0
46129- 0 0 0 0 0 0 0 0 0 0 0 0
46130- 0 0 0 0 0 0 0 0 0 0 0 0
46131- 0 0 0 0 0 0 0 0 0 0 0 0
46132- 0 0 0 0 0 0 0 0 0 0 0 0
46133- 0 0 0 0 0 0 0 0 1 0 0 1
46134- 0 0 1 0 0 0 0 0 1 0 0 0
46135- 0 0 0 0 0 0 0 0 0 0 0 0
46136- 0 0 0 0 0 0 0 0 0 0 0 0
46137- 0 0 0 0 0 0 0 0 0 0 0 0
46138- 0 0 0 0 0 0 0 0 0 0 0 0
46139- 0 0 0 0 0 0 0 0 0 10 10 10
46140- 38 38 38 90 90 90 14 14 14 58 58 58
46141-210 210 210 26 26 26 54 38 6 154 114 10
46142-226 170 11 236 186 11 225 175 15 184 144 12
46143-215 174 15 175 146 61 37 26 9 2 2 6
46144- 70 70 70 246 246 246 138 138 138 2 2 6
46145- 2 2 6 2 2 6 2 2 6 2 2 6
46146- 70 70 70 66 66 66 26 26 26 6 6 6
46147- 0 0 0 0 0 0 0 0 0 0 0 0
46148- 0 0 0 0 0 0 0 0 0 0 0 0
46149- 0 0 0 0 0 0 0 0 0 0 0 0
46150- 0 0 0 0 0 0 0 0 0 0 0 0
46151- 0 0 0 0 0 0 0 0 0 0 0 0
46152- 0 0 0 0 0 0 0 0 0 0 0 0
46153- 0 0 0 0 0 0 0 0 0 0 0 0
46154- 0 0 0 0 0 0 0 0 0 0 0 0
46155- 0 0 0 0 0 0 0 0 0 0 0 0
46156- 0 0 0 0 0 0 0 0 0 0 0 0
46157- 0 0 0 0 0 0 0 0 0 0 0 0
46158- 0 0 0 0 0 0 0 0 0 0 0 0
46159- 0 0 0 0 0 0 0 0 0 10 10 10
46160- 38 38 38 86 86 86 14 14 14 10 10 10
46161-195 195 195 188 164 115 192 133 9 225 175 15
46162-239 182 13 234 190 10 232 195 16 232 200 30
46163-245 207 45 241 208 19 232 195 16 184 144 12
46164-218 194 134 211 206 186 42 42 42 2 2 6
46165- 2 2 6 2 2 6 2 2 6 2 2 6
46166- 50 50 50 74 74 74 30 30 30 6 6 6
46167- 0 0 0 0 0 0 0 0 0 0 0 0
46168- 0 0 0 0 0 0 0 0 0 0 0 0
46169- 0 0 0 0 0 0 0 0 0 0 0 0
46170- 0 0 0 0 0 0 0 0 0 0 0 0
46171- 0 0 0 0 0 0 0 0 0 0 0 0
46172- 0 0 0 0 0 0 0 0 0 0 0 0
46173- 0 0 0 0 0 0 0 0 0 0 0 0
46174- 0 0 0 0 0 0 0 0 0 0 0 0
46175- 0 0 0 0 0 0 0 0 0 0 0 0
46176- 0 0 0 0 0 0 0 0 0 0 0 0
46177- 0 0 0 0 0 0 0 0 0 0 0 0
46178- 0 0 0 0 0 0 0 0 0 0 0 0
46179- 0 0 0 0 0 0 0 0 0 10 10 10
46180- 34 34 34 86 86 86 14 14 14 2 2 6
46181-121 87 25 192 133 9 219 162 10 239 182 13
46182-236 186 11 232 195 16 241 208 19 244 214 54
46183-246 218 60 246 218 38 246 215 20 241 208 19
46184-241 208 19 226 184 13 121 87 25 2 2 6
46185- 2 2 6 2 2 6 2 2 6 2 2 6
46186- 50 50 50 82 82 82 34 34 34 10 10 10
46187- 0 0 0 0 0 0 0 0 0 0 0 0
46188- 0 0 0 0 0 0 0 0 0 0 0 0
46189- 0 0 0 0 0 0 0 0 0 0 0 0
46190- 0 0 0 0 0 0 0 0 0 0 0 0
46191- 0 0 0 0 0 0 0 0 0 0 0 0
46192- 0 0 0 0 0 0 0 0 0 0 0 0
46193- 0 0 0 0 0 0 0 0 0 0 0 0
46194- 0 0 0 0 0 0 0 0 0 0 0 0
46195- 0 0 0 0 0 0 0 0 0 0 0 0
46196- 0 0 0 0 0 0 0 0 0 0 0 0
46197- 0 0 0 0 0 0 0 0 0 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 10 10 10
46200- 34 34 34 82 82 82 30 30 30 61 42 6
46201-180 123 7 206 145 10 230 174 11 239 182 13
46202-234 190 10 238 202 15 241 208 19 246 218 74
46203-246 218 38 246 215 20 246 215 20 246 215 20
46204-226 184 13 215 174 15 184 144 12 6 6 6
46205- 2 2 6 2 2 6 2 2 6 2 2 6
46206- 26 26 26 94 94 94 42 42 42 14 14 14
46207- 0 0 0 0 0 0 0 0 0 0 0 0
46208- 0 0 0 0 0 0 0 0 0 0 0 0
46209- 0 0 0 0 0 0 0 0 0 0 0 0
46210- 0 0 0 0 0 0 0 0 0 0 0 0
46211- 0 0 0 0 0 0 0 0 0 0 0 0
46212- 0 0 0 0 0 0 0 0 0 0 0 0
46213- 0 0 0 0 0 0 0 0 0 0 0 0
46214- 0 0 0 0 0 0 0 0 0 0 0 0
46215- 0 0 0 0 0 0 0 0 0 0 0 0
46216- 0 0 0 0 0 0 0 0 0 0 0 0
46217- 0 0 0 0 0 0 0 0 0 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 10 10 10
46220- 30 30 30 78 78 78 50 50 50 104 69 6
46221-192 133 9 216 158 10 236 178 12 236 186 11
46222-232 195 16 241 208 19 244 214 54 245 215 43
46223-246 215 20 246 215 20 241 208 19 198 155 10
46224-200 144 11 216 158 10 156 118 10 2 2 6
46225- 2 2 6 2 2 6 2 2 6 2 2 6
46226- 6 6 6 90 90 90 54 54 54 18 18 18
46227- 6 6 6 0 0 0 0 0 0 0 0 0
46228- 0 0 0 0 0 0 0 0 0 0 0 0
46229- 0 0 0 0 0 0 0 0 0 0 0 0
46230- 0 0 0 0 0 0 0 0 0 0 0 0
46231- 0 0 0 0 0 0 0 0 0 0 0 0
46232- 0 0 0 0 0 0 0 0 0 0 0 0
46233- 0 0 0 0 0 0 0 0 0 0 0 0
46234- 0 0 0 0 0 0 0 0 0 0 0 0
46235- 0 0 0 0 0 0 0 0 0 0 0 0
46236- 0 0 0 0 0 0 0 0 0 0 0 0
46237- 0 0 0 0 0 0 0 0 0 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 10 10 10
46240- 30 30 30 78 78 78 46 46 46 22 22 22
46241-137 92 6 210 162 10 239 182 13 238 190 10
46242-238 202 15 241 208 19 246 215 20 246 215 20
46243-241 208 19 203 166 17 185 133 11 210 150 10
46244-216 158 10 210 150 10 102 78 10 2 2 6
46245- 6 6 6 54 54 54 14 14 14 2 2 6
46246- 2 2 6 62 62 62 74 74 74 30 30 30
46247- 10 10 10 0 0 0 0 0 0 0 0 0
46248- 0 0 0 0 0 0 0 0 0 0 0 0
46249- 0 0 0 0 0 0 0 0 0 0 0 0
46250- 0 0 0 0 0 0 0 0 0 0 0 0
46251- 0 0 0 0 0 0 0 0 0 0 0 0
46252- 0 0 0 0 0 0 0 0 0 0 0 0
46253- 0 0 0 0 0 0 0 0 0 0 0 0
46254- 0 0 0 0 0 0 0 0 0 0 0 0
46255- 0 0 0 0 0 0 0 0 0 0 0 0
46256- 0 0 0 0 0 0 0 0 0 0 0 0
46257- 0 0 0 0 0 0 0 0 0 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 10 10 10
46260- 34 34 34 78 78 78 50 50 50 6 6 6
46261- 94 70 30 139 102 15 190 146 13 226 184 13
46262-232 200 30 232 195 16 215 174 15 190 146 13
46263-168 122 10 192 133 9 210 150 10 213 154 11
46264-202 150 34 182 157 106 101 98 89 2 2 6
46265- 2 2 6 78 78 78 116 116 116 58 58 58
46266- 2 2 6 22 22 22 90 90 90 46 46 46
46267- 18 18 18 6 6 6 0 0 0 0 0 0
46268- 0 0 0 0 0 0 0 0 0 0 0 0
46269- 0 0 0 0 0 0 0 0 0 0 0 0
46270- 0 0 0 0 0 0 0 0 0 0 0 0
46271- 0 0 0 0 0 0 0 0 0 0 0 0
46272- 0 0 0 0 0 0 0 0 0 0 0 0
46273- 0 0 0 0 0 0 0 0 0 0 0 0
46274- 0 0 0 0 0 0 0 0 0 0 0 0
46275- 0 0 0 0 0 0 0 0 0 0 0 0
46276- 0 0 0 0 0 0 0 0 0 0 0 0
46277- 0 0 0 0 0 0 0 0 0 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 10 10 10
46280- 38 38 38 86 86 86 50 50 50 6 6 6
46281-128 128 128 174 154 114 156 107 11 168 122 10
46282-198 155 10 184 144 12 197 138 11 200 144 11
46283-206 145 10 206 145 10 197 138 11 188 164 115
46284-195 195 195 198 198 198 174 174 174 14 14 14
46285- 2 2 6 22 22 22 116 116 116 116 116 116
46286- 22 22 22 2 2 6 74 74 74 70 70 70
46287- 30 30 30 10 10 10 0 0 0 0 0 0
46288- 0 0 0 0 0 0 0 0 0 0 0 0
46289- 0 0 0 0 0 0 0 0 0 0 0 0
46290- 0 0 0 0 0 0 0 0 0 0 0 0
46291- 0 0 0 0 0 0 0 0 0 0 0 0
46292- 0 0 0 0 0 0 0 0 0 0 0 0
46293- 0 0 0 0 0 0 0 0 0 0 0 0
46294- 0 0 0 0 0 0 0 0 0 0 0 0
46295- 0 0 0 0 0 0 0 0 0 0 0 0
46296- 0 0 0 0 0 0 0 0 0 0 0 0
46297- 0 0 0 0 0 0 0 0 0 0 0 0
46298- 0 0 0 0 0 0 0 0 0 0 0 0
46299- 0 0 0 0 0 0 6 6 6 18 18 18
46300- 50 50 50 101 101 101 26 26 26 10 10 10
46301-138 138 138 190 190 190 174 154 114 156 107 11
46302-197 138 11 200 144 11 197 138 11 192 133 9
46303-180 123 7 190 142 34 190 178 144 187 187 187
46304-202 202 202 221 221 221 214 214 214 66 66 66
46305- 2 2 6 2 2 6 50 50 50 62 62 62
46306- 6 6 6 2 2 6 10 10 10 90 90 90
46307- 50 50 50 18 18 18 6 6 6 0 0 0
46308- 0 0 0 0 0 0 0 0 0 0 0 0
46309- 0 0 0 0 0 0 0 0 0 0 0 0
46310- 0 0 0 0 0 0 0 0 0 0 0 0
46311- 0 0 0 0 0 0 0 0 0 0 0 0
46312- 0 0 0 0 0 0 0 0 0 0 0 0
46313- 0 0 0 0 0 0 0 0 0 0 0 0
46314- 0 0 0 0 0 0 0 0 0 0 0 0
46315- 0 0 0 0 0 0 0 0 0 0 0 0
46316- 0 0 0 0 0 0 0 0 0 0 0 0
46317- 0 0 0 0 0 0 0 0 0 0 0 0
46318- 0 0 0 0 0 0 0 0 0 0 0 0
46319- 0 0 0 0 0 0 10 10 10 34 34 34
46320- 74 74 74 74 74 74 2 2 6 6 6 6
46321-144 144 144 198 198 198 190 190 190 178 166 146
46322-154 121 60 156 107 11 156 107 11 168 124 44
46323-174 154 114 187 187 187 190 190 190 210 210 210
46324-246 246 246 253 253 253 253 253 253 182 182 182
46325- 6 6 6 2 2 6 2 2 6 2 2 6
46326- 2 2 6 2 2 6 2 2 6 62 62 62
46327- 74 74 74 34 34 34 14 14 14 0 0 0
46328- 0 0 0 0 0 0 0 0 0 0 0 0
46329- 0 0 0 0 0 0 0 0 0 0 0 0
46330- 0 0 0 0 0 0 0 0 0 0 0 0
46331- 0 0 0 0 0 0 0 0 0 0 0 0
46332- 0 0 0 0 0 0 0 0 0 0 0 0
46333- 0 0 0 0 0 0 0 0 0 0 0 0
46334- 0 0 0 0 0 0 0 0 0 0 0 0
46335- 0 0 0 0 0 0 0 0 0 0 0 0
46336- 0 0 0 0 0 0 0 0 0 0 0 0
46337- 0 0 0 0 0 0 0 0 0 0 0 0
46338- 0 0 0 0 0 0 0 0 0 0 0 0
46339- 0 0 0 10 10 10 22 22 22 54 54 54
46340- 94 94 94 18 18 18 2 2 6 46 46 46
46341-234 234 234 221 221 221 190 190 190 190 190 190
46342-190 190 190 187 187 187 187 187 187 190 190 190
46343-190 190 190 195 195 195 214 214 214 242 242 242
46344-253 253 253 253 253 253 253 253 253 253 253 253
46345- 82 82 82 2 2 6 2 2 6 2 2 6
46346- 2 2 6 2 2 6 2 2 6 14 14 14
46347- 86 86 86 54 54 54 22 22 22 6 6 6
46348- 0 0 0 0 0 0 0 0 0 0 0 0
46349- 0 0 0 0 0 0 0 0 0 0 0 0
46350- 0 0 0 0 0 0 0 0 0 0 0 0
46351- 0 0 0 0 0 0 0 0 0 0 0 0
46352- 0 0 0 0 0 0 0 0 0 0 0 0
46353- 0 0 0 0 0 0 0 0 0 0 0 0
46354- 0 0 0 0 0 0 0 0 0 0 0 0
46355- 0 0 0 0 0 0 0 0 0 0 0 0
46356- 0 0 0 0 0 0 0 0 0 0 0 0
46357- 0 0 0 0 0 0 0 0 0 0 0 0
46358- 0 0 0 0 0 0 0 0 0 0 0 0
46359- 6 6 6 18 18 18 46 46 46 90 90 90
46360- 46 46 46 18 18 18 6 6 6 182 182 182
46361-253 253 253 246 246 246 206 206 206 190 190 190
46362-190 190 190 190 190 190 190 190 190 190 190 190
46363-206 206 206 231 231 231 250 250 250 253 253 253
46364-253 253 253 253 253 253 253 253 253 253 253 253
46365-202 202 202 14 14 14 2 2 6 2 2 6
46366- 2 2 6 2 2 6 2 2 6 2 2 6
46367- 42 42 42 86 86 86 42 42 42 18 18 18
46368- 6 6 6 0 0 0 0 0 0 0 0 0
46369- 0 0 0 0 0 0 0 0 0 0 0 0
46370- 0 0 0 0 0 0 0 0 0 0 0 0
46371- 0 0 0 0 0 0 0 0 0 0 0 0
46372- 0 0 0 0 0 0 0 0 0 0 0 0
46373- 0 0 0 0 0 0 0 0 0 0 0 0
46374- 0 0 0 0 0 0 0 0 0 0 0 0
46375- 0 0 0 0 0 0 0 0 0 0 0 0
46376- 0 0 0 0 0 0 0 0 0 0 0 0
46377- 0 0 0 0 0 0 0 0 0 0 0 0
46378- 0 0 0 0 0 0 0 0 0 6 6 6
46379- 14 14 14 38 38 38 74 74 74 66 66 66
46380- 2 2 6 6 6 6 90 90 90 250 250 250
46381-253 253 253 253 253 253 238 238 238 198 198 198
46382-190 190 190 190 190 190 195 195 195 221 221 221
46383-246 246 246 253 253 253 253 253 253 253 253 253
46384-253 253 253 253 253 253 253 253 253 253 253 253
46385-253 253 253 82 82 82 2 2 6 2 2 6
46386- 2 2 6 2 2 6 2 2 6 2 2 6
46387- 2 2 6 78 78 78 70 70 70 34 34 34
46388- 14 14 14 6 6 6 0 0 0 0 0 0
46389- 0 0 0 0 0 0 0 0 0 0 0 0
46390- 0 0 0 0 0 0 0 0 0 0 0 0
46391- 0 0 0 0 0 0 0 0 0 0 0 0
46392- 0 0 0 0 0 0 0 0 0 0 0 0
46393- 0 0 0 0 0 0 0 0 0 0 0 0
46394- 0 0 0 0 0 0 0 0 0 0 0 0
46395- 0 0 0 0 0 0 0 0 0 0 0 0
46396- 0 0 0 0 0 0 0 0 0 0 0 0
46397- 0 0 0 0 0 0 0 0 0 0 0 0
46398- 0 0 0 0 0 0 0 0 0 14 14 14
46399- 34 34 34 66 66 66 78 78 78 6 6 6
46400- 2 2 6 18 18 18 218 218 218 253 253 253
46401-253 253 253 253 253 253 253 253 253 246 246 246
46402-226 226 226 231 231 231 246 246 246 253 253 253
46403-253 253 253 253 253 253 253 253 253 253 253 253
46404-253 253 253 253 253 253 253 253 253 253 253 253
46405-253 253 253 178 178 178 2 2 6 2 2 6
46406- 2 2 6 2 2 6 2 2 6 2 2 6
46407- 2 2 6 18 18 18 90 90 90 62 62 62
46408- 30 30 30 10 10 10 0 0 0 0 0 0
46409- 0 0 0 0 0 0 0 0 0 0 0 0
46410- 0 0 0 0 0 0 0 0 0 0 0 0
46411- 0 0 0 0 0 0 0 0 0 0 0 0
46412- 0 0 0 0 0 0 0 0 0 0 0 0
46413- 0 0 0 0 0 0 0 0 0 0 0 0
46414- 0 0 0 0 0 0 0 0 0 0 0 0
46415- 0 0 0 0 0 0 0 0 0 0 0 0
46416- 0 0 0 0 0 0 0 0 0 0 0 0
46417- 0 0 0 0 0 0 0 0 0 0 0 0
46418- 0 0 0 0 0 0 10 10 10 26 26 26
46419- 58 58 58 90 90 90 18 18 18 2 2 6
46420- 2 2 6 110 110 110 253 253 253 253 253 253
46421-253 253 253 253 253 253 253 253 253 253 253 253
46422-250 250 250 253 253 253 253 253 253 253 253 253
46423-253 253 253 253 253 253 253 253 253 253 253 253
46424-253 253 253 253 253 253 253 253 253 253 253 253
46425-253 253 253 231 231 231 18 18 18 2 2 6
46426- 2 2 6 2 2 6 2 2 6 2 2 6
46427- 2 2 6 2 2 6 18 18 18 94 94 94
46428- 54 54 54 26 26 26 10 10 10 0 0 0
46429- 0 0 0 0 0 0 0 0 0 0 0 0
46430- 0 0 0 0 0 0 0 0 0 0 0 0
46431- 0 0 0 0 0 0 0 0 0 0 0 0
46432- 0 0 0 0 0 0 0 0 0 0 0 0
46433- 0 0 0 0 0 0 0 0 0 0 0 0
46434- 0 0 0 0 0 0 0 0 0 0 0 0
46435- 0 0 0 0 0 0 0 0 0 0 0 0
46436- 0 0 0 0 0 0 0 0 0 0 0 0
46437- 0 0 0 0 0 0 0 0 0 0 0 0
46438- 0 0 0 6 6 6 22 22 22 50 50 50
46439- 90 90 90 26 26 26 2 2 6 2 2 6
46440- 14 14 14 195 195 195 250 250 250 253 253 253
46441-253 253 253 253 253 253 253 253 253 253 253 253
46442-253 253 253 253 253 253 253 253 253 253 253 253
46443-253 253 253 253 253 253 253 253 253 253 253 253
46444-253 253 253 253 253 253 253 253 253 253 253 253
46445-250 250 250 242 242 242 54 54 54 2 2 6
46446- 2 2 6 2 2 6 2 2 6 2 2 6
46447- 2 2 6 2 2 6 2 2 6 38 38 38
46448- 86 86 86 50 50 50 22 22 22 6 6 6
46449- 0 0 0 0 0 0 0 0 0 0 0 0
46450- 0 0 0 0 0 0 0 0 0 0 0 0
46451- 0 0 0 0 0 0 0 0 0 0 0 0
46452- 0 0 0 0 0 0 0 0 0 0 0 0
46453- 0 0 0 0 0 0 0 0 0 0 0 0
46454- 0 0 0 0 0 0 0 0 0 0 0 0
46455- 0 0 0 0 0 0 0 0 0 0 0 0
46456- 0 0 0 0 0 0 0 0 0 0 0 0
46457- 0 0 0 0 0 0 0 0 0 0 0 0
46458- 6 6 6 14 14 14 38 38 38 82 82 82
46459- 34 34 34 2 2 6 2 2 6 2 2 6
46460- 42 42 42 195 195 195 246 246 246 253 253 253
46461-253 253 253 253 253 253 253 253 253 250 250 250
46462-242 242 242 242 242 242 250 250 250 253 253 253
46463-253 253 253 253 253 253 253 253 253 253 253 253
46464-253 253 253 250 250 250 246 246 246 238 238 238
46465-226 226 226 231 231 231 101 101 101 6 6 6
46466- 2 2 6 2 2 6 2 2 6 2 2 6
46467- 2 2 6 2 2 6 2 2 6 2 2 6
46468- 38 38 38 82 82 82 42 42 42 14 14 14
46469- 6 6 6 0 0 0 0 0 0 0 0 0
46470- 0 0 0 0 0 0 0 0 0 0 0 0
46471- 0 0 0 0 0 0 0 0 0 0 0 0
46472- 0 0 0 0 0 0 0 0 0 0 0 0
46473- 0 0 0 0 0 0 0 0 0 0 0 0
46474- 0 0 0 0 0 0 0 0 0 0 0 0
46475- 0 0 0 0 0 0 0 0 0 0 0 0
46476- 0 0 0 0 0 0 0 0 0 0 0 0
46477- 0 0 0 0 0 0 0 0 0 0 0 0
46478- 10 10 10 26 26 26 62 62 62 66 66 66
46479- 2 2 6 2 2 6 2 2 6 6 6 6
46480- 70 70 70 170 170 170 206 206 206 234 234 234
46481-246 246 246 250 250 250 250 250 250 238 238 238
46482-226 226 226 231 231 231 238 238 238 250 250 250
46483-250 250 250 250 250 250 246 246 246 231 231 231
46484-214 214 214 206 206 206 202 202 202 202 202 202
46485-198 198 198 202 202 202 182 182 182 18 18 18
46486- 2 2 6 2 2 6 2 2 6 2 2 6
46487- 2 2 6 2 2 6 2 2 6 2 2 6
46488- 2 2 6 62 62 62 66 66 66 30 30 30
46489- 10 10 10 0 0 0 0 0 0 0 0 0
46490- 0 0 0 0 0 0 0 0 0 0 0 0
46491- 0 0 0 0 0 0 0 0 0 0 0 0
46492- 0 0 0 0 0 0 0 0 0 0 0 0
46493- 0 0 0 0 0 0 0 0 0 0 0 0
46494- 0 0 0 0 0 0 0 0 0 0 0 0
46495- 0 0 0 0 0 0 0 0 0 0 0 0
46496- 0 0 0 0 0 0 0 0 0 0 0 0
46497- 0 0 0 0 0 0 0 0 0 0 0 0
46498- 14 14 14 42 42 42 82 82 82 18 18 18
46499- 2 2 6 2 2 6 2 2 6 10 10 10
46500- 94 94 94 182 182 182 218 218 218 242 242 242
46501-250 250 250 253 253 253 253 253 253 250 250 250
46502-234 234 234 253 253 253 253 253 253 253 253 253
46503-253 253 253 253 253 253 253 253 253 246 246 246
46504-238 238 238 226 226 226 210 210 210 202 202 202
46505-195 195 195 195 195 195 210 210 210 158 158 158
46506- 6 6 6 14 14 14 50 50 50 14 14 14
46507- 2 2 6 2 2 6 2 2 6 2 2 6
46508- 2 2 6 6 6 6 86 86 86 46 46 46
46509- 18 18 18 6 6 6 0 0 0 0 0 0
46510- 0 0 0 0 0 0 0 0 0 0 0 0
46511- 0 0 0 0 0 0 0 0 0 0 0 0
46512- 0 0 0 0 0 0 0 0 0 0 0 0
46513- 0 0 0 0 0 0 0 0 0 0 0 0
46514- 0 0 0 0 0 0 0 0 0 0 0 0
46515- 0 0 0 0 0 0 0 0 0 0 0 0
46516- 0 0 0 0 0 0 0 0 0 0 0 0
46517- 0 0 0 0 0 0 0 0 0 6 6 6
46518- 22 22 22 54 54 54 70 70 70 2 2 6
46519- 2 2 6 10 10 10 2 2 6 22 22 22
46520-166 166 166 231 231 231 250 250 250 253 253 253
46521-253 253 253 253 253 253 253 253 253 250 250 250
46522-242 242 242 253 253 253 253 253 253 253 253 253
46523-253 253 253 253 253 253 253 253 253 253 253 253
46524-253 253 253 253 253 253 253 253 253 246 246 246
46525-231 231 231 206 206 206 198 198 198 226 226 226
46526- 94 94 94 2 2 6 6 6 6 38 38 38
46527- 30 30 30 2 2 6 2 2 6 2 2 6
46528- 2 2 6 2 2 6 62 62 62 66 66 66
46529- 26 26 26 10 10 10 0 0 0 0 0 0
46530- 0 0 0 0 0 0 0 0 0 0 0 0
46531- 0 0 0 0 0 0 0 0 0 0 0 0
46532- 0 0 0 0 0 0 0 0 0 0 0 0
46533- 0 0 0 0 0 0 0 0 0 0 0 0
46534- 0 0 0 0 0 0 0 0 0 0 0 0
46535- 0 0 0 0 0 0 0 0 0 0 0 0
46536- 0 0 0 0 0 0 0 0 0 0 0 0
46537- 0 0 0 0 0 0 0 0 0 10 10 10
46538- 30 30 30 74 74 74 50 50 50 2 2 6
46539- 26 26 26 26 26 26 2 2 6 106 106 106
46540-238 238 238 253 253 253 253 253 253 253 253 253
46541-253 253 253 253 253 253 253 253 253 253 253 253
46542-253 253 253 253 253 253 253 253 253 253 253 253
46543-253 253 253 253 253 253 253 253 253 253 253 253
46544-253 253 253 253 253 253 253 253 253 253 253 253
46545-253 253 253 246 246 246 218 218 218 202 202 202
46546-210 210 210 14 14 14 2 2 6 2 2 6
46547- 30 30 30 22 22 22 2 2 6 2 2 6
46548- 2 2 6 2 2 6 18 18 18 86 86 86
46549- 42 42 42 14 14 14 0 0 0 0 0 0
46550- 0 0 0 0 0 0 0 0 0 0 0 0
46551- 0 0 0 0 0 0 0 0 0 0 0 0
46552- 0 0 0 0 0 0 0 0 0 0 0 0
46553- 0 0 0 0 0 0 0 0 0 0 0 0
46554- 0 0 0 0 0 0 0 0 0 0 0 0
46555- 0 0 0 0 0 0 0 0 0 0 0 0
46556- 0 0 0 0 0 0 0 0 0 0 0 0
46557- 0 0 0 0 0 0 0 0 0 14 14 14
46558- 42 42 42 90 90 90 22 22 22 2 2 6
46559- 42 42 42 2 2 6 18 18 18 218 218 218
46560-253 253 253 253 253 253 253 253 253 253 253 253
46561-253 253 253 253 253 253 253 253 253 253 253 253
46562-253 253 253 253 253 253 253 253 253 253 253 253
46563-253 253 253 253 253 253 253 253 253 253 253 253
46564-253 253 253 253 253 253 253 253 253 253 253 253
46565-253 253 253 253 253 253 250 250 250 221 221 221
46566-218 218 218 101 101 101 2 2 6 14 14 14
46567- 18 18 18 38 38 38 10 10 10 2 2 6
46568- 2 2 6 2 2 6 2 2 6 78 78 78
46569- 58 58 58 22 22 22 6 6 6 0 0 0
46570- 0 0 0 0 0 0 0 0 0 0 0 0
46571- 0 0 0 0 0 0 0 0 0 0 0 0
46572- 0 0 0 0 0 0 0 0 0 0 0 0
46573- 0 0 0 0 0 0 0 0 0 0 0 0
46574- 0 0 0 0 0 0 0 0 0 0 0 0
46575- 0 0 0 0 0 0 0 0 0 0 0 0
46576- 0 0 0 0 0 0 0 0 0 0 0 0
46577- 0 0 0 0 0 0 6 6 6 18 18 18
46578- 54 54 54 82 82 82 2 2 6 26 26 26
46579- 22 22 22 2 2 6 123 123 123 253 253 253
46580-253 253 253 253 253 253 253 253 253 253 253 253
46581-253 253 253 253 253 253 253 253 253 253 253 253
46582-253 253 253 253 253 253 253 253 253 253 253 253
46583-253 253 253 253 253 253 253 253 253 253 253 253
46584-253 253 253 253 253 253 253 253 253 253 253 253
46585-253 253 253 253 253 253 253 253 253 250 250 250
46586-238 238 238 198 198 198 6 6 6 38 38 38
46587- 58 58 58 26 26 26 38 38 38 2 2 6
46588- 2 2 6 2 2 6 2 2 6 46 46 46
46589- 78 78 78 30 30 30 10 10 10 0 0 0
46590- 0 0 0 0 0 0 0 0 0 0 0 0
46591- 0 0 0 0 0 0 0 0 0 0 0 0
46592- 0 0 0 0 0 0 0 0 0 0 0 0
46593- 0 0 0 0 0 0 0 0 0 0 0 0
46594- 0 0 0 0 0 0 0 0 0 0 0 0
46595- 0 0 0 0 0 0 0 0 0 0 0 0
46596- 0 0 0 0 0 0 0 0 0 0 0 0
46597- 0 0 0 0 0 0 10 10 10 30 30 30
46598- 74 74 74 58 58 58 2 2 6 42 42 42
46599- 2 2 6 22 22 22 231 231 231 253 253 253
46600-253 253 253 253 253 253 253 253 253 253 253 253
46601-253 253 253 253 253 253 253 253 253 250 250 250
46602-253 253 253 253 253 253 253 253 253 253 253 253
46603-253 253 253 253 253 253 253 253 253 253 253 253
46604-253 253 253 253 253 253 253 253 253 253 253 253
46605-253 253 253 253 253 253 253 253 253 253 253 253
46606-253 253 253 246 246 246 46 46 46 38 38 38
46607- 42 42 42 14 14 14 38 38 38 14 14 14
46608- 2 2 6 2 2 6 2 2 6 6 6 6
46609- 86 86 86 46 46 46 14 14 14 0 0 0
46610- 0 0 0 0 0 0 0 0 0 0 0 0
46611- 0 0 0 0 0 0 0 0 0 0 0 0
46612- 0 0 0 0 0 0 0 0 0 0 0 0
46613- 0 0 0 0 0 0 0 0 0 0 0 0
46614- 0 0 0 0 0 0 0 0 0 0 0 0
46615- 0 0 0 0 0 0 0 0 0 0 0 0
46616- 0 0 0 0 0 0 0 0 0 0 0 0
46617- 0 0 0 6 6 6 14 14 14 42 42 42
46618- 90 90 90 18 18 18 18 18 18 26 26 26
46619- 2 2 6 116 116 116 253 253 253 253 253 253
46620-253 253 253 253 253 253 253 253 253 253 253 253
46621-253 253 253 253 253 253 250 250 250 238 238 238
46622-253 253 253 253 253 253 253 253 253 253 253 253
46623-253 253 253 253 253 253 253 253 253 253 253 253
46624-253 253 253 253 253 253 253 253 253 253 253 253
46625-253 253 253 253 253 253 253 253 253 253 253 253
46626-253 253 253 253 253 253 94 94 94 6 6 6
46627- 2 2 6 2 2 6 10 10 10 34 34 34
46628- 2 2 6 2 2 6 2 2 6 2 2 6
46629- 74 74 74 58 58 58 22 22 22 6 6 6
46630- 0 0 0 0 0 0 0 0 0 0 0 0
46631- 0 0 0 0 0 0 0 0 0 0 0 0
46632- 0 0 0 0 0 0 0 0 0 0 0 0
46633- 0 0 0 0 0 0 0 0 0 0 0 0
46634- 0 0 0 0 0 0 0 0 0 0 0 0
46635- 0 0 0 0 0 0 0 0 0 0 0 0
46636- 0 0 0 0 0 0 0 0 0 0 0 0
46637- 0 0 0 10 10 10 26 26 26 66 66 66
46638- 82 82 82 2 2 6 38 38 38 6 6 6
46639- 14 14 14 210 210 210 253 253 253 253 253 253
46640-253 253 253 253 253 253 253 253 253 253 253 253
46641-253 253 253 253 253 253 246 246 246 242 242 242
46642-253 253 253 253 253 253 253 253 253 253 253 253
46643-253 253 253 253 253 253 253 253 253 253 253 253
46644-253 253 253 253 253 253 253 253 253 253 253 253
46645-253 253 253 253 253 253 253 253 253 253 253 253
46646-253 253 253 253 253 253 144 144 144 2 2 6
46647- 2 2 6 2 2 6 2 2 6 46 46 46
46648- 2 2 6 2 2 6 2 2 6 2 2 6
46649- 42 42 42 74 74 74 30 30 30 10 10 10
46650- 0 0 0 0 0 0 0 0 0 0 0 0
46651- 0 0 0 0 0 0 0 0 0 0 0 0
46652- 0 0 0 0 0 0 0 0 0 0 0 0
46653- 0 0 0 0 0 0 0 0 0 0 0 0
46654- 0 0 0 0 0 0 0 0 0 0 0 0
46655- 0 0 0 0 0 0 0 0 0 0 0 0
46656- 0 0 0 0 0 0 0 0 0 0 0 0
46657- 6 6 6 14 14 14 42 42 42 90 90 90
46658- 26 26 26 6 6 6 42 42 42 2 2 6
46659- 74 74 74 250 250 250 253 253 253 253 253 253
46660-253 253 253 253 253 253 253 253 253 253 253 253
46661-253 253 253 253 253 253 242 242 242 242 242 242
46662-253 253 253 253 253 253 253 253 253 253 253 253
46663-253 253 253 253 253 253 253 253 253 253 253 253
46664-253 253 253 253 253 253 253 253 253 253 253 253
46665-253 253 253 253 253 253 253 253 253 253 253 253
46666-253 253 253 253 253 253 182 182 182 2 2 6
46667- 2 2 6 2 2 6 2 2 6 46 46 46
46668- 2 2 6 2 2 6 2 2 6 2 2 6
46669- 10 10 10 86 86 86 38 38 38 10 10 10
46670- 0 0 0 0 0 0 0 0 0 0 0 0
46671- 0 0 0 0 0 0 0 0 0 0 0 0
46672- 0 0 0 0 0 0 0 0 0 0 0 0
46673- 0 0 0 0 0 0 0 0 0 0 0 0
46674- 0 0 0 0 0 0 0 0 0 0 0 0
46675- 0 0 0 0 0 0 0 0 0 0 0 0
46676- 0 0 0 0 0 0 0 0 0 0 0 0
46677- 10 10 10 26 26 26 66 66 66 82 82 82
46678- 2 2 6 22 22 22 18 18 18 2 2 6
46679-149 149 149 253 253 253 253 253 253 253 253 253
46680-253 253 253 253 253 253 253 253 253 253 253 253
46681-253 253 253 253 253 253 234 234 234 242 242 242
46682-253 253 253 253 253 253 253 253 253 253 253 253
46683-253 253 253 253 253 253 253 253 253 253 253 253
46684-253 253 253 253 253 253 253 253 253 253 253 253
46685-253 253 253 253 253 253 253 253 253 253 253 253
46686-253 253 253 253 253 253 206 206 206 2 2 6
46687- 2 2 6 2 2 6 2 2 6 38 38 38
46688- 2 2 6 2 2 6 2 2 6 2 2 6
46689- 6 6 6 86 86 86 46 46 46 14 14 14
46690- 0 0 0 0 0 0 0 0 0 0 0 0
46691- 0 0 0 0 0 0 0 0 0 0 0 0
46692- 0 0 0 0 0 0 0 0 0 0 0 0
46693- 0 0 0 0 0 0 0 0 0 0 0 0
46694- 0 0 0 0 0 0 0 0 0 0 0 0
46695- 0 0 0 0 0 0 0 0 0 0 0 0
46696- 0 0 0 0 0 0 0 0 0 6 6 6
46697- 18 18 18 46 46 46 86 86 86 18 18 18
46698- 2 2 6 34 34 34 10 10 10 6 6 6
46699-210 210 210 253 253 253 253 253 253 253 253 253
46700-253 253 253 253 253 253 253 253 253 253 253 253
46701-253 253 253 253 253 253 234 234 234 242 242 242
46702-253 253 253 253 253 253 253 253 253 253 253 253
46703-253 253 253 253 253 253 253 253 253 253 253 253
46704-253 253 253 253 253 253 253 253 253 253 253 253
46705-253 253 253 253 253 253 253 253 253 253 253 253
46706-253 253 253 253 253 253 221 221 221 6 6 6
46707- 2 2 6 2 2 6 6 6 6 30 30 30
46708- 2 2 6 2 2 6 2 2 6 2 2 6
46709- 2 2 6 82 82 82 54 54 54 18 18 18
46710- 6 6 6 0 0 0 0 0 0 0 0 0
46711- 0 0 0 0 0 0 0 0 0 0 0 0
46712- 0 0 0 0 0 0 0 0 0 0 0 0
46713- 0 0 0 0 0 0 0 0 0 0 0 0
46714- 0 0 0 0 0 0 0 0 0 0 0 0
46715- 0 0 0 0 0 0 0 0 0 0 0 0
46716- 0 0 0 0 0 0 0 0 0 10 10 10
46717- 26 26 26 66 66 66 62 62 62 2 2 6
46718- 2 2 6 38 38 38 10 10 10 26 26 26
46719-238 238 238 253 253 253 253 253 253 253 253 253
46720-253 253 253 253 253 253 253 253 253 253 253 253
46721-253 253 253 253 253 253 231 231 231 238 238 238
46722-253 253 253 253 253 253 253 253 253 253 253 253
46723-253 253 253 253 253 253 253 253 253 253 253 253
46724-253 253 253 253 253 253 253 253 253 253 253 253
46725-253 253 253 253 253 253 253 253 253 253 253 253
46726-253 253 253 253 253 253 231 231 231 6 6 6
46727- 2 2 6 2 2 6 10 10 10 30 30 30
46728- 2 2 6 2 2 6 2 2 6 2 2 6
46729- 2 2 6 66 66 66 58 58 58 22 22 22
46730- 6 6 6 0 0 0 0 0 0 0 0 0
46731- 0 0 0 0 0 0 0 0 0 0 0 0
46732- 0 0 0 0 0 0 0 0 0 0 0 0
46733- 0 0 0 0 0 0 0 0 0 0 0 0
46734- 0 0 0 0 0 0 0 0 0 0 0 0
46735- 0 0 0 0 0 0 0 0 0 0 0 0
46736- 0 0 0 0 0 0 0 0 0 10 10 10
46737- 38 38 38 78 78 78 6 6 6 2 2 6
46738- 2 2 6 46 46 46 14 14 14 42 42 42
46739-246 246 246 253 253 253 253 253 253 253 253 253
46740-253 253 253 253 253 253 253 253 253 253 253 253
46741-253 253 253 253 253 253 231 231 231 242 242 242
46742-253 253 253 253 253 253 253 253 253 253 253 253
46743-253 253 253 253 253 253 253 253 253 253 253 253
46744-253 253 253 253 253 253 253 253 253 253 253 253
46745-253 253 253 253 253 253 253 253 253 253 253 253
46746-253 253 253 253 253 253 234 234 234 10 10 10
46747- 2 2 6 2 2 6 22 22 22 14 14 14
46748- 2 2 6 2 2 6 2 2 6 2 2 6
46749- 2 2 6 66 66 66 62 62 62 22 22 22
46750- 6 6 6 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 0 0 0 0 0 0 0 0 0
46753- 0 0 0 0 0 0 0 0 0 0 0 0
46754- 0 0 0 0 0 0 0 0 0 0 0 0
46755- 0 0 0 0 0 0 0 0 0 0 0 0
46756- 0 0 0 0 0 0 6 6 6 18 18 18
46757- 50 50 50 74 74 74 2 2 6 2 2 6
46758- 14 14 14 70 70 70 34 34 34 62 62 62
46759-250 250 250 253 253 253 253 253 253 253 253 253
46760-253 253 253 253 253 253 253 253 253 253 253 253
46761-253 253 253 253 253 253 231 231 231 246 246 246
46762-253 253 253 253 253 253 253 253 253 253 253 253
46763-253 253 253 253 253 253 253 253 253 253 253 253
46764-253 253 253 253 253 253 253 253 253 253 253 253
46765-253 253 253 253 253 253 253 253 253 253 253 253
46766-253 253 253 253 253 253 234 234 234 14 14 14
46767- 2 2 6 2 2 6 30 30 30 2 2 6
46768- 2 2 6 2 2 6 2 2 6 2 2 6
46769- 2 2 6 66 66 66 62 62 62 22 22 22
46770- 6 6 6 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 0 0 0
46773- 0 0 0 0 0 0 0 0 0 0 0 0
46774- 0 0 0 0 0 0 0 0 0 0 0 0
46775- 0 0 0 0 0 0 0 0 0 0 0 0
46776- 0 0 0 0 0 0 6 6 6 18 18 18
46777- 54 54 54 62 62 62 2 2 6 2 2 6
46778- 2 2 6 30 30 30 46 46 46 70 70 70
46779-250 250 250 253 253 253 253 253 253 253 253 253
46780-253 253 253 253 253 253 253 253 253 253 253 253
46781-253 253 253 253 253 253 231 231 231 246 246 246
46782-253 253 253 253 253 253 253 253 253 253 253 253
46783-253 253 253 253 253 253 253 253 253 253 253 253
46784-253 253 253 253 253 253 253 253 253 253 253 253
46785-253 253 253 253 253 253 253 253 253 253 253 253
46786-253 253 253 253 253 253 226 226 226 10 10 10
46787- 2 2 6 6 6 6 30 30 30 2 2 6
46788- 2 2 6 2 2 6 2 2 6 2 2 6
46789- 2 2 6 66 66 66 58 58 58 22 22 22
46790- 6 6 6 0 0 0 0 0 0 0 0 0
46791- 0 0 0 0 0 0 0 0 0 0 0 0
46792- 0 0 0 0 0 0 0 0 0 0 0 0
46793- 0 0 0 0 0 0 0 0 0 0 0 0
46794- 0 0 0 0 0 0 0 0 0 0 0 0
46795- 0 0 0 0 0 0 0 0 0 0 0 0
46796- 0 0 0 0 0 0 6 6 6 22 22 22
46797- 58 58 58 62 62 62 2 2 6 2 2 6
46798- 2 2 6 2 2 6 30 30 30 78 78 78
46799-250 250 250 253 253 253 253 253 253 253 253 253
46800-253 253 253 253 253 253 253 253 253 253 253 253
46801-253 253 253 253 253 253 231 231 231 246 246 246
46802-253 253 253 253 253 253 253 253 253 253 253 253
46803-253 253 253 253 253 253 253 253 253 253 253 253
46804-253 253 253 253 253 253 253 253 253 253 253 253
46805-253 253 253 253 253 253 253 253 253 253 253 253
46806-253 253 253 253 253 253 206 206 206 2 2 6
46807- 22 22 22 34 34 34 18 14 6 22 22 22
46808- 26 26 26 18 18 18 6 6 6 2 2 6
46809- 2 2 6 82 82 82 54 54 54 18 18 18
46810- 6 6 6 0 0 0 0 0 0 0 0 0
46811- 0 0 0 0 0 0 0 0 0 0 0 0
46812- 0 0 0 0 0 0 0 0 0 0 0 0
46813- 0 0 0 0 0 0 0 0 0 0 0 0
46814- 0 0 0 0 0 0 0 0 0 0 0 0
46815- 0 0 0 0 0 0 0 0 0 0 0 0
46816- 0 0 0 0 0 0 6 6 6 26 26 26
46817- 62 62 62 106 106 106 74 54 14 185 133 11
46818-210 162 10 121 92 8 6 6 6 62 62 62
46819-238 238 238 253 253 253 253 253 253 253 253 253
46820-253 253 253 253 253 253 253 253 253 253 253 253
46821-253 253 253 253 253 253 231 231 231 246 246 246
46822-253 253 253 253 253 253 253 253 253 253 253 253
46823-253 253 253 253 253 253 253 253 253 253 253 253
46824-253 253 253 253 253 253 253 253 253 253 253 253
46825-253 253 253 253 253 253 253 253 253 253 253 253
46826-253 253 253 253 253 253 158 158 158 18 18 18
46827- 14 14 14 2 2 6 2 2 6 2 2 6
46828- 6 6 6 18 18 18 66 66 66 38 38 38
46829- 6 6 6 94 94 94 50 50 50 18 18 18
46830- 6 6 6 0 0 0 0 0 0 0 0 0
46831- 0 0 0 0 0 0 0 0 0 0 0 0
46832- 0 0 0 0 0 0 0 0 0 0 0 0
46833- 0 0 0 0 0 0 0 0 0 0 0 0
46834- 0 0 0 0 0 0 0 0 0 0 0 0
46835- 0 0 0 0 0 0 0 0 0 6 6 6
46836- 10 10 10 10 10 10 18 18 18 38 38 38
46837- 78 78 78 142 134 106 216 158 10 242 186 14
46838-246 190 14 246 190 14 156 118 10 10 10 10
46839- 90 90 90 238 238 238 253 253 253 253 253 253
46840-253 253 253 253 253 253 253 253 253 253 253 253
46841-253 253 253 253 253 253 231 231 231 250 250 250
46842-253 253 253 253 253 253 253 253 253 253 253 253
46843-253 253 253 253 253 253 253 253 253 253 253 253
46844-253 253 253 253 253 253 253 253 253 253 253 253
46845-253 253 253 253 253 253 253 253 253 246 230 190
46846-238 204 91 238 204 91 181 142 44 37 26 9
46847- 2 2 6 2 2 6 2 2 6 2 2 6
46848- 2 2 6 2 2 6 38 38 38 46 46 46
46849- 26 26 26 106 106 106 54 54 54 18 18 18
46850- 6 6 6 0 0 0 0 0 0 0 0 0
46851- 0 0 0 0 0 0 0 0 0 0 0 0
46852- 0 0 0 0 0 0 0 0 0 0 0 0
46853- 0 0 0 0 0 0 0 0 0 0 0 0
46854- 0 0 0 0 0 0 0 0 0 0 0 0
46855- 0 0 0 6 6 6 14 14 14 22 22 22
46856- 30 30 30 38 38 38 50 50 50 70 70 70
46857-106 106 106 190 142 34 226 170 11 242 186 14
46858-246 190 14 246 190 14 246 190 14 154 114 10
46859- 6 6 6 74 74 74 226 226 226 253 253 253
46860-253 253 253 253 253 253 253 253 253 253 253 253
46861-253 253 253 253 253 253 231 231 231 250 250 250
46862-253 253 253 253 253 253 253 253 253 253 253 253
46863-253 253 253 253 253 253 253 253 253 253 253 253
46864-253 253 253 253 253 253 253 253 253 253 253 253
46865-253 253 253 253 253 253 253 253 253 228 184 62
46866-241 196 14 241 208 19 232 195 16 38 30 10
46867- 2 2 6 2 2 6 2 2 6 2 2 6
46868- 2 2 6 6 6 6 30 30 30 26 26 26
46869-203 166 17 154 142 90 66 66 66 26 26 26
46870- 6 6 6 0 0 0 0 0 0 0 0 0
46871- 0 0 0 0 0 0 0 0 0 0 0 0
46872- 0 0 0 0 0 0 0 0 0 0 0 0
46873- 0 0 0 0 0 0 0 0 0 0 0 0
46874- 0 0 0 0 0 0 0 0 0 0 0 0
46875- 6 6 6 18 18 18 38 38 38 58 58 58
46876- 78 78 78 86 86 86 101 101 101 123 123 123
46877-175 146 61 210 150 10 234 174 13 246 186 14
46878-246 190 14 246 190 14 246 190 14 238 190 10
46879-102 78 10 2 2 6 46 46 46 198 198 198
46880-253 253 253 253 253 253 253 253 253 253 253 253
46881-253 253 253 253 253 253 234 234 234 242 242 242
46882-253 253 253 253 253 253 253 253 253 253 253 253
46883-253 253 253 253 253 253 253 253 253 253 253 253
46884-253 253 253 253 253 253 253 253 253 253 253 253
46885-253 253 253 253 253 253 253 253 253 224 178 62
46886-242 186 14 241 196 14 210 166 10 22 18 6
46887- 2 2 6 2 2 6 2 2 6 2 2 6
46888- 2 2 6 2 2 6 6 6 6 121 92 8
46889-238 202 15 232 195 16 82 82 82 34 34 34
46890- 10 10 10 0 0 0 0 0 0 0 0 0
46891- 0 0 0 0 0 0 0 0 0 0 0 0
46892- 0 0 0 0 0 0 0 0 0 0 0 0
46893- 0 0 0 0 0 0 0 0 0 0 0 0
46894- 0 0 0 0 0 0 0 0 0 0 0 0
46895- 14 14 14 38 38 38 70 70 70 154 122 46
46896-190 142 34 200 144 11 197 138 11 197 138 11
46897-213 154 11 226 170 11 242 186 14 246 190 14
46898-246 190 14 246 190 14 246 190 14 246 190 14
46899-225 175 15 46 32 6 2 2 6 22 22 22
46900-158 158 158 250 250 250 253 253 253 253 253 253
46901-253 253 253 253 253 253 253 253 253 253 253 253
46902-253 253 253 253 253 253 253 253 253 253 253 253
46903-253 253 253 253 253 253 253 253 253 253 253 253
46904-253 253 253 253 253 253 253 253 253 253 253 253
46905-253 253 253 250 250 250 242 242 242 224 178 62
46906-239 182 13 236 186 11 213 154 11 46 32 6
46907- 2 2 6 2 2 6 2 2 6 2 2 6
46908- 2 2 6 2 2 6 61 42 6 225 175 15
46909-238 190 10 236 186 11 112 100 78 42 42 42
46910- 14 14 14 0 0 0 0 0 0 0 0 0
46911- 0 0 0 0 0 0 0 0 0 0 0 0
46912- 0 0 0 0 0 0 0 0 0 0 0 0
46913- 0 0 0 0 0 0 0 0 0 0 0 0
46914- 0 0 0 0 0 0 0 0 0 6 6 6
46915- 22 22 22 54 54 54 154 122 46 213 154 11
46916-226 170 11 230 174 11 226 170 11 226 170 11
46917-236 178 12 242 186 14 246 190 14 246 190 14
46918-246 190 14 246 190 14 246 190 14 246 190 14
46919-241 196 14 184 144 12 10 10 10 2 2 6
46920- 6 6 6 116 116 116 242 242 242 253 253 253
46921-253 253 253 253 253 253 253 253 253 253 253 253
46922-253 253 253 253 253 253 253 253 253 253 253 253
46923-253 253 253 253 253 253 253 253 253 253 253 253
46924-253 253 253 253 253 253 253 253 253 253 253 253
46925-253 253 253 231 231 231 198 198 198 214 170 54
46926-236 178 12 236 178 12 210 150 10 137 92 6
46927- 18 14 6 2 2 6 2 2 6 2 2 6
46928- 6 6 6 70 47 6 200 144 11 236 178 12
46929-239 182 13 239 182 13 124 112 88 58 58 58
46930- 22 22 22 6 6 6 0 0 0 0 0 0
46931- 0 0 0 0 0 0 0 0 0 0 0 0
46932- 0 0 0 0 0 0 0 0 0 0 0 0
46933- 0 0 0 0 0 0 0 0 0 0 0 0
46934- 0 0 0 0 0 0 0 0 0 10 10 10
46935- 30 30 30 70 70 70 180 133 36 226 170 11
46936-239 182 13 242 186 14 242 186 14 246 186 14
46937-246 190 14 246 190 14 246 190 14 246 190 14
46938-246 190 14 246 190 14 246 190 14 246 190 14
46939-246 190 14 232 195 16 98 70 6 2 2 6
46940- 2 2 6 2 2 6 66 66 66 221 221 221
46941-253 253 253 253 253 253 253 253 253 253 253 253
46942-253 253 253 253 253 253 253 253 253 253 253 253
46943-253 253 253 253 253 253 253 253 253 253 253 253
46944-253 253 253 253 253 253 253 253 253 253 253 253
46945-253 253 253 206 206 206 198 198 198 214 166 58
46946-230 174 11 230 174 11 216 158 10 192 133 9
46947-163 110 8 116 81 8 102 78 10 116 81 8
46948-167 114 7 197 138 11 226 170 11 239 182 13
46949-242 186 14 242 186 14 162 146 94 78 78 78
46950- 34 34 34 14 14 14 6 6 6 0 0 0
46951- 0 0 0 0 0 0 0 0 0 0 0 0
46952- 0 0 0 0 0 0 0 0 0 0 0 0
46953- 0 0 0 0 0 0 0 0 0 0 0 0
46954- 0 0 0 0 0 0 0 0 0 6 6 6
46955- 30 30 30 78 78 78 190 142 34 226 170 11
46956-239 182 13 246 190 14 246 190 14 246 190 14
46957-246 190 14 246 190 14 246 190 14 246 190 14
46958-246 190 14 246 190 14 246 190 14 246 190 14
46959-246 190 14 241 196 14 203 166 17 22 18 6
46960- 2 2 6 2 2 6 2 2 6 38 38 38
46961-218 218 218 253 253 253 253 253 253 253 253 253
46962-253 253 253 253 253 253 253 253 253 253 253 253
46963-253 253 253 253 253 253 253 253 253 253 253 253
46964-253 253 253 253 253 253 253 253 253 253 253 253
46965-250 250 250 206 206 206 198 198 198 202 162 69
46966-226 170 11 236 178 12 224 166 10 210 150 10
46967-200 144 11 197 138 11 192 133 9 197 138 11
46968-210 150 10 226 170 11 242 186 14 246 190 14
46969-246 190 14 246 186 14 225 175 15 124 112 88
46970- 62 62 62 30 30 30 14 14 14 6 6 6
46971- 0 0 0 0 0 0 0 0 0 0 0 0
46972- 0 0 0 0 0 0 0 0 0 0 0 0
46973- 0 0 0 0 0 0 0 0 0 0 0 0
46974- 0 0 0 0 0 0 0 0 0 10 10 10
46975- 30 30 30 78 78 78 174 135 50 224 166 10
46976-239 182 13 246 190 14 246 190 14 246 190 14
46977-246 190 14 246 190 14 246 190 14 246 190 14
46978-246 190 14 246 190 14 246 190 14 246 190 14
46979-246 190 14 246 190 14 241 196 14 139 102 15
46980- 2 2 6 2 2 6 2 2 6 2 2 6
46981- 78 78 78 250 250 250 253 253 253 253 253 253
46982-253 253 253 253 253 253 253 253 253 253 253 253
46983-253 253 253 253 253 253 253 253 253 253 253 253
46984-253 253 253 253 253 253 253 253 253 253 253 253
46985-250 250 250 214 214 214 198 198 198 190 150 46
46986-219 162 10 236 178 12 234 174 13 224 166 10
46987-216 158 10 213 154 11 213 154 11 216 158 10
46988-226 170 11 239 182 13 246 190 14 246 190 14
46989-246 190 14 246 190 14 242 186 14 206 162 42
46990-101 101 101 58 58 58 30 30 30 14 14 14
46991- 6 6 6 0 0 0 0 0 0 0 0 0
46992- 0 0 0 0 0 0 0 0 0 0 0 0
46993- 0 0 0 0 0 0 0 0 0 0 0 0
46994- 0 0 0 0 0 0 0 0 0 10 10 10
46995- 30 30 30 74 74 74 174 135 50 216 158 10
46996-236 178 12 246 190 14 246 190 14 246 190 14
46997-246 190 14 246 190 14 246 190 14 246 190 14
46998-246 190 14 246 190 14 246 190 14 246 190 14
46999-246 190 14 246 190 14 241 196 14 226 184 13
47000- 61 42 6 2 2 6 2 2 6 2 2 6
47001- 22 22 22 238 238 238 253 253 253 253 253 253
47002-253 253 253 253 253 253 253 253 253 253 253 253
47003-253 253 253 253 253 253 253 253 253 253 253 253
47004-253 253 253 253 253 253 253 253 253 253 253 253
47005-253 253 253 226 226 226 187 187 187 180 133 36
47006-216 158 10 236 178 12 239 182 13 236 178 12
47007-230 174 11 226 170 11 226 170 11 230 174 11
47008-236 178 12 242 186 14 246 190 14 246 190 14
47009-246 190 14 246 190 14 246 186 14 239 182 13
47010-206 162 42 106 106 106 66 66 66 34 34 34
47011- 14 14 14 6 6 6 0 0 0 0 0 0
47012- 0 0 0 0 0 0 0 0 0 0 0 0
47013- 0 0 0 0 0 0 0 0 0 0 0 0
47014- 0 0 0 0 0 0 0 0 0 6 6 6
47015- 26 26 26 70 70 70 163 133 67 213 154 11
47016-236 178 12 246 190 14 246 190 14 246 190 14
47017-246 190 14 246 190 14 246 190 14 246 190 14
47018-246 190 14 246 190 14 246 190 14 246 190 14
47019-246 190 14 246 190 14 246 190 14 241 196 14
47020-190 146 13 18 14 6 2 2 6 2 2 6
47021- 46 46 46 246 246 246 253 253 253 253 253 253
47022-253 253 253 253 253 253 253 253 253 253 253 253
47023-253 253 253 253 253 253 253 253 253 253 253 253
47024-253 253 253 253 253 253 253 253 253 253 253 253
47025-253 253 253 221 221 221 86 86 86 156 107 11
47026-216 158 10 236 178 12 242 186 14 246 186 14
47027-242 186 14 239 182 13 239 182 13 242 186 14
47028-242 186 14 246 186 14 246 190 14 246 190 14
47029-246 190 14 246 190 14 246 190 14 246 190 14
47030-242 186 14 225 175 15 142 122 72 66 66 66
47031- 30 30 30 10 10 10 0 0 0 0 0 0
47032- 0 0 0 0 0 0 0 0 0 0 0 0
47033- 0 0 0 0 0 0 0 0 0 0 0 0
47034- 0 0 0 0 0 0 0 0 0 6 6 6
47035- 26 26 26 70 70 70 163 133 67 210 150 10
47036-236 178 12 246 190 14 246 190 14 246 190 14
47037-246 190 14 246 190 14 246 190 14 246 190 14
47038-246 190 14 246 190 14 246 190 14 246 190 14
47039-246 190 14 246 190 14 246 190 14 246 190 14
47040-232 195 16 121 92 8 34 34 34 106 106 106
47041-221 221 221 253 253 253 253 253 253 253 253 253
47042-253 253 253 253 253 253 253 253 253 253 253 253
47043-253 253 253 253 253 253 253 253 253 253 253 253
47044-253 253 253 253 253 253 253 253 253 253 253 253
47045-242 242 242 82 82 82 18 14 6 163 110 8
47046-216 158 10 236 178 12 242 186 14 246 190 14
47047-246 190 14 246 190 14 246 190 14 246 190 14
47048-246 190 14 246 190 14 246 190 14 246 190 14
47049-246 190 14 246 190 14 246 190 14 246 190 14
47050-246 190 14 246 190 14 242 186 14 163 133 67
47051- 46 46 46 18 18 18 6 6 6 0 0 0
47052- 0 0 0 0 0 0 0 0 0 0 0 0
47053- 0 0 0 0 0 0 0 0 0 0 0 0
47054- 0 0 0 0 0 0 0 0 0 10 10 10
47055- 30 30 30 78 78 78 163 133 67 210 150 10
47056-236 178 12 246 186 14 246 190 14 246 190 14
47057-246 190 14 246 190 14 246 190 14 246 190 14
47058-246 190 14 246 190 14 246 190 14 246 190 14
47059-246 190 14 246 190 14 246 190 14 246 190 14
47060-241 196 14 215 174 15 190 178 144 253 253 253
47061-253 253 253 253 253 253 253 253 253 253 253 253
47062-253 253 253 253 253 253 253 253 253 253 253 253
47063-253 253 253 253 253 253 253 253 253 253 253 253
47064-253 253 253 253 253 253 253 253 253 218 218 218
47065- 58 58 58 2 2 6 22 18 6 167 114 7
47066-216 158 10 236 178 12 246 186 14 246 190 14
47067-246 190 14 246 190 14 246 190 14 246 190 14
47068-246 190 14 246 190 14 246 190 14 246 190 14
47069-246 190 14 246 190 14 246 190 14 246 190 14
47070-246 190 14 246 186 14 242 186 14 190 150 46
47071- 54 54 54 22 22 22 6 6 6 0 0 0
47072- 0 0 0 0 0 0 0 0 0 0 0 0
47073- 0 0 0 0 0 0 0 0 0 0 0 0
47074- 0 0 0 0 0 0 0 0 0 14 14 14
47075- 38 38 38 86 86 86 180 133 36 213 154 11
47076-236 178 12 246 186 14 246 190 14 246 190 14
47077-246 190 14 246 190 14 246 190 14 246 190 14
47078-246 190 14 246 190 14 246 190 14 246 190 14
47079-246 190 14 246 190 14 246 190 14 246 190 14
47080-246 190 14 232 195 16 190 146 13 214 214 214
47081-253 253 253 253 253 253 253 253 253 253 253 253
47082-253 253 253 253 253 253 253 253 253 253 253 253
47083-253 253 253 253 253 253 253 253 253 253 253 253
47084-253 253 253 250 250 250 170 170 170 26 26 26
47085- 2 2 6 2 2 6 37 26 9 163 110 8
47086-219 162 10 239 182 13 246 186 14 246 190 14
47087-246 190 14 246 190 14 246 190 14 246 190 14
47088-246 190 14 246 190 14 246 190 14 246 190 14
47089-246 190 14 246 190 14 246 190 14 246 190 14
47090-246 186 14 236 178 12 224 166 10 142 122 72
47091- 46 46 46 18 18 18 6 6 6 0 0 0
47092- 0 0 0 0 0 0 0 0 0 0 0 0
47093- 0 0 0 0 0 0 0 0 0 0 0 0
47094- 0 0 0 0 0 0 6 6 6 18 18 18
47095- 50 50 50 109 106 95 192 133 9 224 166 10
47096-242 186 14 246 190 14 246 190 14 246 190 14
47097-246 190 14 246 190 14 246 190 14 246 190 14
47098-246 190 14 246 190 14 246 190 14 246 190 14
47099-246 190 14 246 190 14 246 190 14 246 190 14
47100-242 186 14 226 184 13 210 162 10 142 110 46
47101-226 226 226 253 253 253 253 253 253 253 253 253
47102-253 253 253 253 253 253 253 253 253 253 253 253
47103-253 253 253 253 253 253 253 253 253 253 253 253
47104-198 198 198 66 66 66 2 2 6 2 2 6
47105- 2 2 6 2 2 6 50 34 6 156 107 11
47106-219 162 10 239 182 13 246 186 14 246 190 14
47107-246 190 14 246 190 14 246 190 14 246 190 14
47108-246 190 14 246 190 14 246 190 14 246 190 14
47109-246 190 14 246 190 14 246 190 14 242 186 14
47110-234 174 13 213 154 11 154 122 46 66 66 66
47111- 30 30 30 10 10 10 0 0 0 0 0 0
47112- 0 0 0 0 0 0 0 0 0 0 0 0
47113- 0 0 0 0 0 0 0 0 0 0 0 0
47114- 0 0 0 0 0 0 6 6 6 22 22 22
47115- 58 58 58 154 121 60 206 145 10 234 174 13
47116-242 186 14 246 186 14 246 190 14 246 190 14
47117-246 190 14 246 190 14 246 190 14 246 190 14
47118-246 190 14 246 190 14 246 190 14 246 190 14
47119-246 190 14 246 190 14 246 190 14 246 190 14
47120-246 186 14 236 178 12 210 162 10 163 110 8
47121- 61 42 6 138 138 138 218 218 218 250 250 250
47122-253 253 253 253 253 253 253 253 253 250 250 250
47123-242 242 242 210 210 210 144 144 144 66 66 66
47124- 6 6 6 2 2 6 2 2 6 2 2 6
47125- 2 2 6 2 2 6 61 42 6 163 110 8
47126-216 158 10 236 178 12 246 190 14 246 190 14
47127-246 190 14 246 190 14 246 190 14 246 190 14
47128-246 190 14 246 190 14 246 190 14 246 190 14
47129-246 190 14 239 182 13 230 174 11 216 158 10
47130-190 142 34 124 112 88 70 70 70 38 38 38
47131- 18 18 18 6 6 6 0 0 0 0 0 0
47132- 0 0 0 0 0 0 0 0 0 0 0 0
47133- 0 0 0 0 0 0 0 0 0 0 0 0
47134- 0 0 0 0 0 0 6 6 6 22 22 22
47135- 62 62 62 168 124 44 206 145 10 224 166 10
47136-236 178 12 239 182 13 242 186 14 242 186 14
47137-246 186 14 246 190 14 246 190 14 246 190 14
47138-246 190 14 246 190 14 246 190 14 246 190 14
47139-246 190 14 246 190 14 246 190 14 246 190 14
47140-246 190 14 236 178 12 216 158 10 175 118 6
47141- 80 54 7 2 2 6 6 6 6 30 30 30
47142- 54 54 54 62 62 62 50 50 50 38 38 38
47143- 14 14 14 2 2 6 2 2 6 2 2 6
47144- 2 2 6 2 2 6 2 2 6 2 2 6
47145- 2 2 6 6 6 6 80 54 7 167 114 7
47146-213 154 11 236 178 12 246 190 14 246 190 14
47147-246 190 14 246 190 14 246 190 14 246 190 14
47148-246 190 14 242 186 14 239 182 13 239 182 13
47149-230 174 11 210 150 10 174 135 50 124 112 88
47150- 82 82 82 54 54 54 34 34 34 18 18 18
47151- 6 6 6 0 0 0 0 0 0 0 0 0
47152- 0 0 0 0 0 0 0 0 0 0 0 0
47153- 0 0 0 0 0 0 0 0 0 0 0 0
47154- 0 0 0 0 0 0 6 6 6 18 18 18
47155- 50 50 50 158 118 36 192 133 9 200 144 11
47156-216 158 10 219 162 10 224 166 10 226 170 11
47157-230 174 11 236 178 12 239 182 13 239 182 13
47158-242 186 14 246 186 14 246 190 14 246 190 14
47159-246 190 14 246 190 14 246 190 14 246 190 14
47160-246 186 14 230 174 11 210 150 10 163 110 8
47161-104 69 6 10 10 10 2 2 6 2 2 6
47162- 2 2 6 2 2 6 2 2 6 2 2 6
47163- 2 2 6 2 2 6 2 2 6 2 2 6
47164- 2 2 6 2 2 6 2 2 6 2 2 6
47165- 2 2 6 6 6 6 91 60 6 167 114 7
47166-206 145 10 230 174 11 242 186 14 246 190 14
47167-246 190 14 246 190 14 246 186 14 242 186 14
47168-239 182 13 230 174 11 224 166 10 213 154 11
47169-180 133 36 124 112 88 86 86 86 58 58 58
47170- 38 38 38 22 22 22 10 10 10 6 6 6
47171- 0 0 0 0 0 0 0 0 0 0 0 0
47172- 0 0 0 0 0 0 0 0 0 0 0 0
47173- 0 0 0 0 0 0 0 0 0 0 0 0
47174- 0 0 0 0 0 0 0 0 0 14 14 14
47175- 34 34 34 70 70 70 138 110 50 158 118 36
47176-167 114 7 180 123 7 192 133 9 197 138 11
47177-200 144 11 206 145 10 213 154 11 219 162 10
47178-224 166 10 230 174 11 239 182 13 242 186 14
47179-246 186 14 246 186 14 246 186 14 246 186 14
47180-239 182 13 216 158 10 185 133 11 152 99 6
47181-104 69 6 18 14 6 2 2 6 2 2 6
47182- 2 2 6 2 2 6 2 2 6 2 2 6
47183- 2 2 6 2 2 6 2 2 6 2 2 6
47184- 2 2 6 2 2 6 2 2 6 2 2 6
47185- 2 2 6 6 6 6 80 54 7 152 99 6
47186-192 133 9 219 162 10 236 178 12 239 182 13
47187-246 186 14 242 186 14 239 182 13 236 178 12
47188-224 166 10 206 145 10 192 133 9 154 121 60
47189- 94 94 94 62 62 62 42 42 42 22 22 22
47190- 14 14 14 6 6 6 0 0 0 0 0 0
47191- 0 0 0 0 0 0 0 0 0 0 0 0
47192- 0 0 0 0 0 0 0 0 0 0 0 0
47193- 0 0 0 0 0 0 0 0 0 0 0 0
47194- 0 0 0 0 0 0 0 0 0 6 6 6
47195- 18 18 18 34 34 34 58 58 58 78 78 78
47196-101 98 89 124 112 88 142 110 46 156 107 11
47197-163 110 8 167 114 7 175 118 6 180 123 7
47198-185 133 11 197 138 11 210 150 10 219 162 10
47199-226 170 11 236 178 12 236 178 12 234 174 13
47200-219 162 10 197 138 11 163 110 8 130 83 6
47201- 91 60 6 10 10 10 2 2 6 2 2 6
47202- 18 18 18 38 38 38 38 38 38 38 38 38
47203- 38 38 38 38 38 38 38 38 38 38 38 38
47204- 38 38 38 38 38 38 26 26 26 2 2 6
47205- 2 2 6 6 6 6 70 47 6 137 92 6
47206-175 118 6 200 144 11 219 162 10 230 174 11
47207-234 174 13 230 174 11 219 162 10 210 150 10
47208-192 133 9 163 110 8 124 112 88 82 82 82
47209- 50 50 50 30 30 30 14 14 14 6 6 6
47210- 0 0 0 0 0 0 0 0 0 0 0 0
47211- 0 0 0 0 0 0 0 0 0 0 0 0
47212- 0 0 0 0 0 0 0 0 0 0 0 0
47213- 0 0 0 0 0 0 0 0 0 0 0 0
47214- 0 0 0 0 0 0 0 0 0 0 0 0
47215- 6 6 6 14 14 14 22 22 22 34 34 34
47216- 42 42 42 58 58 58 74 74 74 86 86 86
47217-101 98 89 122 102 70 130 98 46 121 87 25
47218-137 92 6 152 99 6 163 110 8 180 123 7
47219-185 133 11 197 138 11 206 145 10 200 144 11
47220-180 123 7 156 107 11 130 83 6 104 69 6
47221- 50 34 6 54 54 54 110 110 110 101 98 89
47222- 86 86 86 82 82 82 78 78 78 78 78 78
47223- 78 78 78 78 78 78 78 78 78 78 78 78
47224- 78 78 78 82 82 82 86 86 86 94 94 94
47225-106 106 106 101 101 101 86 66 34 124 80 6
47226-156 107 11 180 123 7 192 133 9 200 144 11
47227-206 145 10 200 144 11 192 133 9 175 118 6
47228-139 102 15 109 106 95 70 70 70 42 42 42
47229- 22 22 22 10 10 10 0 0 0 0 0 0
47230- 0 0 0 0 0 0 0 0 0 0 0 0
47231- 0 0 0 0 0 0 0 0 0 0 0 0
47232- 0 0 0 0 0 0 0 0 0 0 0 0
47233- 0 0 0 0 0 0 0 0 0 0 0 0
47234- 0 0 0 0 0 0 0 0 0 0 0 0
47235- 0 0 0 0 0 0 6 6 6 10 10 10
47236- 14 14 14 22 22 22 30 30 30 38 38 38
47237- 50 50 50 62 62 62 74 74 74 90 90 90
47238-101 98 89 112 100 78 121 87 25 124 80 6
47239-137 92 6 152 99 6 152 99 6 152 99 6
47240-138 86 6 124 80 6 98 70 6 86 66 30
47241-101 98 89 82 82 82 58 58 58 46 46 46
47242- 38 38 38 34 34 34 34 34 34 34 34 34
47243- 34 34 34 34 34 34 34 34 34 34 34 34
47244- 34 34 34 34 34 34 38 38 38 42 42 42
47245- 54 54 54 82 82 82 94 86 76 91 60 6
47246-134 86 6 156 107 11 167 114 7 175 118 6
47247-175 118 6 167 114 7 152 99 6 121 87 25
47248-101 98 89 62 62 62 34 34 34 18 18 18
47249- 6 6 6 0 0 0 0 0 0 0 0 0
47250- 0 0 0 0 0 0 0 0 0 0 0 0
47251- 0 0 0 0 0 0 0 0 0 0 0 0
47252- 0 0 0 0 0 0 0 0 0 0 0 0
47253- 0 0 0 0 0 0 0 0 0 0 0 0
47254- 0 0 0 0 0 0 0 0 0 0 0 0
47255- 0 0 0 0 0 0 0 0 0 0 0 0
47256- 0 0 0 6 6 6 6 6 6 10 10 10
47257- 18 18 18 22 22 22 30 30 30 42 42 42
47258- 50 50 50 66 66 66 86 86 86 101 98 89
47259-106 86 58 98 70 6 104 69 6 104 69 6
47260-104 69 6 91 60 6 82 62 34 90 90 90
47261- 62 62 62 38 38 38 22 22 22 14 14 14
47262- 10 10 10 10 10 10 10 10 10 10 10 10
47263- 10 10 10 10 10 10 6 6 6 10 10 10
47264- 10 10 10 10 10 10 10 10 10 14 14 14
47265- 22 22 22 42 42 42 70 70 70 89 81 66
47266- 80 54 7 104 69 6 124 80 6 137 92 6
47267-134 86 6 116 81 8 100 82 52 86 86 86
47268- 58 58 58 30 30 30 14 14 14 6 6 6
47269- 0 0 0 0 0 0 0 0 0 0 0 0
47270- 0 0 0 0 0 0 0 0 0 0 0 0
47271- 0 0 0 0 0 0 0 0 0 0 0 0
47272- 0 0 0 0 0 0 0 0 0 0 0 0
47273- 0 0 0 0 0 0 0 0 0 0 0 0
47274- 0 0 0 0 0 0 0 0 0 0 0 0
47275- 0 0 0 0 0 0 0 0 0 0 0 0
47276- 0 0 0 0 0 0 0 0 0 0 0 0
47277- 0 0 0 6 6 6 10 10 10 14 14 14
47278- 18 18 18 26 26 26 38 38 38 54 54 54
47279- 70 70 70 86 86 86 94 86 76 89 81 66
47280- 89 81 66 86 86 86 74 74 74 50 50 50
47281- 30 30 30 14 14 14 6 6 6 0 0 0
47282- 0 0 0 0 0 0 0 0 0 0 0 0
47283- 0 0 0 0 0 0 0 0 0 0 0 0
47284- 0 0 0 0 0 0 0 0 0 0 0 0
47285- 6 6 6 18 18 18 34 34 34 58 58 58
47286- 82 82 82 89 81 66 89 81 66 89 81 66
47287- 94 86 66 94 86 76 74 74 74 50 50 50
47288- 26 26 26 14 14 14 6 6 6 0 0 0
47289- 0 0 0 0 0 0 0 0 0 0 0 0
47290- 0 0 0 0 0 0 0 0 0 0 0 0
47291- 0 0 0 0 0 0 0 0 0 0 0 0
47292- 0 0 0 0 0 0 0 0 0 0 0 0
47293- 0 0 0 0 0 0 0 0 0 0 0 0
47294- 0 0 0 0 0 0 0 0 0 0 0 0
47295- 0 0 0 0 0 0 0 0 0 0 0 0
47296- 0 0 0 0 0 0 0 0 0 0 0 0
47297- 0 0 0 0 0 0 0 0 0 0 0 0
47298- 6 6 6 6 6 6 14 14 14 18 18 18
47299- 30 30 30 38 38 38 46 46 46 54 54 54
47300- 50 50 50 42 42 42 30 30 30 18 18 18
47301- 10 10 10 0 0 0 0 0 0 0 0 0
47302- 0 0 0 0 0 0 0 0 0 0 0 0
47303- 0 0 0 0 0 0 0 0 0 0 0 0
47304- 0 0 0 0 0 0 0 0 0 0 0 0
47305- 0 0 0 6 6 6 14 14 14 26 26 26
47306- 38 38 38 50 50 50 58 58 58 58 58 58
47307- 54 54 54 42 42 42 30 30 30 18 18 18
47308- 10 10 10 0 0 0 0 0 0 0 0 0
47309- 0 0 0 0 0 0 0 0 0 0 0 0
47310- 0 0 0 0 0 0 0 0 0 0 0 0
47311- 0 0 0 0 0 0 0 0 0 0 0 0
47312- 0 0 0 0 0 0 0 0 0 0 0 0
47313- 0 0 0 0 0 0 0 0 0 0 0 0
47314- 0 0 0 0 0 0 0 0 0 0 0 0
47315- 0 0 0 0 0 0 0 0 0 0 0 0
47316- 0 0 0 0 0 0 0 0 0 0 0 0
47317- 0 0 0 0 0 0 0 0 0 0 0 0
47318- 0 0 0 0 0 0 0 0 0 6 6 6
47319- 6 6 6 10 10 10 14 14 14 18 18 18
47320- 18 18 18 14 14 14 10 10 10 6 6 6
47321- 0 0 0 0 0 0 0 0 0 0 0 0
47322- 0 0 0 0 0 0 0 0 0 0 0 0
47323- 0 0 0 0 0 0 0 0 0 0 0 0
47324- 0 0 0 0 0 0 0 0 0 0 0 0
47325- 0 0 0 0 0 0 0 0 0 6 6 6
47326- 14 14 14 18 18 18 22 22 22 22 22 22
47327- 18 18 18 14 14 14 10 10 10 6 6 6
47328- 0 0 0 0 0 0 0 0 0 0 0 0
47329- 0 0 0 0 0 0 0 0 0 0 0 0
47330- 0 0 0 0 0 0 0 0 0 0 0 0
47331- 0 0 0 0 0 0 0 0 0 0 0 0
47332- 0 0 0 0 0 0 0 0 0 0 0 0
47333+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47334+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47335+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47336+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
47340+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47341+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47342+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47343+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47344+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47345+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47346+4 4 4 4 4 4
47347+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47348+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47349+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47350+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
47354+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47355+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47356+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47357+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47358+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47359+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47360+4 4 4 4 4 4
47361+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47362+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47363+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47364+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
47368+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47369+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47370+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47371+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47372+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47373+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47374+4 4 4 4 4 4
47375+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47376+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47377+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47378+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
47382+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47383+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47384+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47385+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47386+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47387+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47388+4 4 4 4 4 4
47389+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47390+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47391+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47392+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
47396+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47397+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47398+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47399+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47400+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47401+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47402+4 4 4 4 4 4
47403+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47404+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47405+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47406+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
47410+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47411+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47412+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47413+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47414+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47415+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47416+4 4 4 4 4 4
47417+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47418+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47419+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47420+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47421+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
47422+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
47423+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47424+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47425+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47426+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
47427+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
47428+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
47429+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47430+4 4 4 4 4 4
47431+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47432+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47433+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47434+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47435+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
47436+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
47437+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47438+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47439+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47440+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
47441+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
47442+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
47443+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47444+4 4 4 4 4 4
47445+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47446+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47447+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47448+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47449+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
47450+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
47451+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
47452+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47453+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47454+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
47455+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
47456+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
47457+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
47458+4 4 4 4 4 4
47459+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47460+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47461+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47462+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
47463+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
47464+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
47465+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
47466+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47467+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
47468+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
47469+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
47470+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
47471+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
47472+4 4 4 4 4 4
47473+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47474+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47475+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47476+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
47477+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
47478+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
47479+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
47480+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47481+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
47482+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
47483+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
47484+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
47485+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
47486+4 4 4 4 4 4
47487+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47488+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47489+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
47490+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
47491+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
47492+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
47493+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
47494+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
47495+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
47496+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
47497+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
47498+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
47499+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
47500+4 4 4 4 4 4
47501+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47502+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47503+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
47504+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
47505+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
47506+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
47507+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
47508+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
47509+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
47510+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
47511+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
47512+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
47513+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
47514+4 4 4 4 4 4
47515+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47516+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47517+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
47518+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
47519+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
47520+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
47521+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
47522+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
47523+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
47524+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
47525+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
47526+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
47527+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
47528+4 4 4 4 4 4
47529+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47530+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47531+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
47532+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
47533+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
47534+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
47535+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
47536+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
47537+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
47538+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
47539+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
47540+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
47541+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
47542+4 4 4 4 4 4
47543+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47544+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47545+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
47546+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
47547+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
47548+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
47549+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
47550+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
47551+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
47552+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
47553+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
47554+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
47555+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
47556+4 4 4 4 4 4
47557+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47558+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
47559+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
47560+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
47561+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
47562+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
47563+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
47564+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
47565+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
47566+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
47567+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
47568+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
47569+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
47570+4 4 4 4 4 4
47571+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47572+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
47573+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
47574+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
47575+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
47576+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
47577+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
47578+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
47579+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
47580+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
47581+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
47582+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
47583+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
47584+0 0 0 4 4 4
47585+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
47586+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
47587+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
47588+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
47589+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
47590+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
47591+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
47592+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
47593+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
47594+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
47595+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
47596+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
47597+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
47598+2 0 0 0 0 0
47599+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
47600+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
47601+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
47602+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
47603+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
47604+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
47605+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
47606+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
47607+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
47608+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
47609+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
47610+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
47611+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
47612+37 38 37 0 0 0
47613+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
47614+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
47615+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
47616+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
47617+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
47618+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
47619+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
47620+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
47621+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
47622+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
47623+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
47624+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
47625+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
47626+85 115 134 4 0 0
47627+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
47628+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
47629+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
47630+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
47631+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
47632+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
47633+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
47634+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
47635+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
47636+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
47637+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
47638+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
47639+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
47640+60 73 81 4 0 0
47641+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
47642+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
47643+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
47644+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
47645+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
47646+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
47647+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
47648+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
47649+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
47650+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
47651+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
47652+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
47653+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
47654+16 19 21 4 0 0
47655+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
47656+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
47657+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
47658+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
47659+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
47660+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
47661+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
47662+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
47663+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
47664+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
47665+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
47666+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
47667+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
47668+4 0 0 4 3 3
47669+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
47670+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
47671+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
47672+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
47673+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
47674+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
47675+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
47676+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
47677+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
47678+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
47679+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
47680+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
47681+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
47682+3 2 2 4 4 4
47683+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
47684+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
47685+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
47686+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
47687+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
47688+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
47689+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
47690+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
47691+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
47692+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
47693+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
47694+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
47695+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
47696+4 4 4 4 4 4
47697+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
47698+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
47699+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
47700+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
47701+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
47702+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
47703+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
47704+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
47705+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
47706+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
47707+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
47708+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
47709+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
47710+4 4 4 4 4 4
47711+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
47712+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
47713+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
47714+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
47715+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
47716+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
47717+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
47718+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
47719+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
47720+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
47721+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
47722+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
47723+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
47724+5 5 5 5 5 5
47725+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
47726+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
47727+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
47728+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
47729+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
47730+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47731+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
47732+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
47733+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
47734+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
47735+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
47736+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
47737+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
47738+5 5 5 4 4 4
47739+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
47740+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
47741+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
47742+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
47743+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
47744+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
47745+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
47746+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
47747+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
47748+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
47749+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
47750+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
47751+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47752+4 4 4 4 4 4
47753+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
47754+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
47755+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
47756+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
47757+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
47758+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47759+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47760+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
47761+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
47762+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
47763+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
47764+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
47765+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47766+4 4 4 4 4 4
47767+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
47768+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
47769+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
47770+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
47771+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
47772+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
47773+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
47774+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
47775+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
47776+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
47777+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
47778+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47779+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47780+4 4 4 4 4 4
47781+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
47782+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
47783+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
47784+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
47785+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
47786+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47787+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47788+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
47789+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
47790+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
47791+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
47792+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47793+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47794+4 4 4 4 4 4
47795+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
47796+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
47797+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
47798+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
47799+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
47800+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
47801+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
47802+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
47803+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
47804+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
47805+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47806+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47807+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47808+4 4 4 4 4 4
47809+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
47810+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
47811+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
47812+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
47813+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
47814+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
47815+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
47816+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
47817+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
47818+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
47819+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
47820+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47821+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47822+4 4 4 4 4 4
47823+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
47824+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
47825+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
47826+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
47827+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
47828+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
47829+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
47830+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
47831+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
47832+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
47833+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
47834+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47835+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47836+4 4 4 4 4 4
47837+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
47838+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
47839+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
47840+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
47841+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
47842+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
47843+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
47844+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
47845+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
47846+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
47847+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47848+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47849+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47850+4 4 4 4 4 4
47851+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
47852+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
47853+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
47854+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
47855+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47856+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
47857+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
47858+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
47859+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
47860+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
47861+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47862+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47863+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47864+4 4 4 4 4 4
47865+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
47866+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
47867+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
47868+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
47869+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47870+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
47871+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
47872+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
47873+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
47874+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
47875+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47876+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47877+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47878+4 4 4 4 4 4
47879+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
47880+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
47881+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
47882+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
47883+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47884+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
47885+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
47886+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
47887+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
47888+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47889+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47890+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47891+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47892+4 4 4 4 4 4
47893+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
47894+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
47895+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
47896+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
47897+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
47898+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
47899+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
47900+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
47901+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47902+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47903+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47904+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47905+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47906+4 4 4 4 4 4
47907+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
47908+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
47909+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
47910+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
47911+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47912+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
47913+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
47914+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
47915+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
47916+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47917+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47918+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47919+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47920+4 4 4 4 4 4
47921+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
47922+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
47923+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
47924+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
47925+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
47926+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
47927+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
47928+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
47929+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47930+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47931+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47932+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47933+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47934+4 4 4 4 4 4
47935+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
47936+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
47937+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
47938+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
47939+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
47940+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
47941+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
47942+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
47943+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
47944+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47945+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47946+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47947+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47948+4 4 4 4 4 4
47949+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
47950+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
47951+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
47952+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
47953+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
47954+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
47955+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
47956+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
47957+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47958+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47959+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47960+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47961+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47962+4 4 4 4 4 4
47963+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
47964+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
47965+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
47966+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
47967+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
47968+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
47969+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
47970+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
47971+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
47972+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47973+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47974+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47975+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47976+4 4 4 4 4 4
47977+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
47978+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
47979+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
47980+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
47981+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
47982+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
47983+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
47984+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
47985+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47986+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47987+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47988+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47989+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47990+4 4 4 4 4 4
47991+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47992+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
47993+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
47994+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
47995+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
47996+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
47997+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
47998+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
47999+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
48000+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
48001+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
48002+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48003+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48004+4 4 4 4 4 4
48005+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
48006+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
48007+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
48008+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
48009+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
48010+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
48011+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
48012+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
48013+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
48014+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
48015+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
48016+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48017+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48018+4 4 4 4 4 4
48019+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
48020+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
48021+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
48022+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
48023+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
48024+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
48025+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
48026+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
48027+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
48028+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
48029+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
48030+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48031+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48032+4 4 4 4 4 4
48033+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
48034+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
48035+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
48036+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
48037+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
48038+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
48039+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
48040+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
48041+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
48042+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
48043+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
48044+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48045+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48046+4 4 4 4 4 4
48047+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
48048+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
48049+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
48050+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
48051+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
48052+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
48053+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
48054+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
48055+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
48056+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
48057+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
48058+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48059+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48060+4 4 4 4 4 4
48061+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
48062+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
48063+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
48064+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
48065+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
48066+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
48067+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
48068+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
48069+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
48070+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
48071+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
48072+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48073+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48074+4 4 4 4 4 4
48075+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
48076+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
48077+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
48078+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
48079+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
48080+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
48081+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
48082+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
48083+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
48084+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
48085+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
48086+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48087+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48088+4 4 4 4 4 4
48089+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
48090+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
48091+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
48092+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
48093+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
48094+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
48095+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
48096+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
48097+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
48098+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
48099+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
48100+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48101+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48102+4 4 4 4 4 4
48103+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
48104+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
48105+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
48106+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
48107+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
48108+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
48109+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
48110+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
48111+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
48112+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
48113+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48114+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48115+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48116+4 4 4 4 4 4
48117+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
48118+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
48119+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
48120+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
48121+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
48122+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
48123+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48124+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
48125+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
48126+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
48127+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
48128+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48129+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48130+4 4 4 4 4 4
48131+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
48132+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
48133+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
48134+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
48135+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
48136+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
48137+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
48138+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
48139+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
48140+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
48141+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48142+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48143+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48144+4 4 4 4 4 4
48145+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
48146+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
48147+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
48148+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
48149+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
48150+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
48151+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
48152+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
48153+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
48154+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
48155+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48156+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48157+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48158+4 4 4 4 4 4
48159+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
48160+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
48161+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
48162+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
48163+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
48164+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
48165+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
48166+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
48167+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
48168+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
48169+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48170+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48171+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48172+4 4 4 4 4 4
48173+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
48174+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
48175+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
48176+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
48177+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
48178+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
48179+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
48180+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
48181+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
48182+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
48183+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48184+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48185+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48186+4 4 4 4 4 4
48187+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
48188+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
48189+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
48190+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
48191+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
48192+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
48193+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
48194+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
48195+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
48196+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
48197+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48198+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48199+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48200+4 4 4 4 4 4
48201+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
48202+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
48203+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
48204+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
48205+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
48206+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
48207+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
48208+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
48209+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
48210+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48211+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48212+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48213+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48214+4 4 4 4 4 4
48215+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
48216+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
48217+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
48218+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
48219+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
48220+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
48221+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
48222+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
48223+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
48224+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48225+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48226+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48227+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48228+4 4 4 4 4 4
48229+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
48230+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
48231+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
48232+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
48233+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
48234+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
48235+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
48236+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
48237+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48238+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48239+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48240+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48241+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48242+4 4 4 4 4 4
48243+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
48244+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
48245+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
48246+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
48247+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
48248+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
48249+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
48250+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
48251+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48252+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48253+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48254+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48255+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48256+4 4 4 4 4 4
48257+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
48258+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
48259+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
48260+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
48261+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
48262+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
48263+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
48264+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
48265+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48266+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48267+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48268+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48269+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48270+4 4 4 4 4 4
48271+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
48272+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
48273+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
48274+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
48275+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
48276+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
48277+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
48278+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
48279+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48280+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48281+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48282+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48283+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48284+4 4 4 4 4 4
48285+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48286+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
48287+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
48288+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
48289+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
48290+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
48291+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
48292+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
48293+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48294+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48295+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48296+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48297+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48298+4 4 4 4 4 4
48299+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48300+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
48301+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
48302+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
48303+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
48304+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
48305+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
48306+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
48307+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48308+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48309+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48310+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48311+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48312+4 4 4 4 4 4
48313+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48314+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48315+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
48316+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
48317+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
48318+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
48319+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
48320+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
48321+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48322+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48323+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48324+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48325+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48326+4 4 4 4 4 4
48327+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48328+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48329+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
48330+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
48331+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
48332+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
48333+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
48334+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48335+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48336+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48337+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48338+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48339+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48340+4 4 4 4 4 4
48341+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48342+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48343+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48344+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
48345+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
48346+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
48347+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
48348+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48349+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48350+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48351+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48352+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48353+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48354+4 4 4 4 4 4
48355+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48356+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48357+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48358+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
48359+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
48360+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
48361+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
48362+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48363+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48364+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48365+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48366+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48367+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48368+4 4 4 4 4 4
48369+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48370+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48371+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48372+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
48373+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
48374+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
48375+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
48376+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48377+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48378+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48379+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48380+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48381+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48382+4 4 4 4 4 4
48383+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48384+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48385+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48386+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
48387+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
48388+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
48389+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
48390+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48391+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48392+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48393+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48394+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48395+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48396+4 4 4 4 4 4
48397+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48398+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48399+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48400+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48401+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
48402+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
48403+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
48404+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48405+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48406+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48407+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48408+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48409+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48410+4 4 4 4 4 4
48411+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48412+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48413+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48414+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48415+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
48416+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
48417+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48418+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48419+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48420+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48421+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48422+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48423+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48424+4 4 4 4 4 4
48425+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48426+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48427+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48428+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48429+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
48430+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
48431+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48432+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48433+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48434+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48435+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48436+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48437+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48438+4 4 4 4 4 4
48439+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48440+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48441+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48442+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48443+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
48444+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
48445+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48446+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48447+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48448+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48449+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48450+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48451+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48452+4 4 4 4 4 4
48453diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
48454index fe92eed..106e085 100644
48455--- a/drivers/video/mb862xx/mb862xxfb_accel.c
48456+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
48457@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
48458 struct mb862xxfb_par *par = info->par;
48459
48460 if (info->var.bits_per_pixel == 32) {
48461- info->fbops->fb_fillrect = cfb_fillrect;
48462- info->fbops->fb_copyarea = cfb_copyarea;
48463- info->fbops->fb_imageblit = cfb_imageblit;
48464+ pax_open_kernel();
48465+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
48466+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
48467+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
48468+ pax_close_kernel();
48469 } else {
48470 outreg(disp, GC_L0EM, 3);
48471- info->fbops->fb_fillrect = mb86290fb_fillrect;
48472- info->fbops->fb_copyarea = mb86290fb_copyarea;
48473- info->fbops->fb_imageblit = mb86290fb_imageblit;
48474+ pax_open_kernel();
48475+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
48476+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
48477+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
48478+ pax_close_kernel();
48479 }
48480 outreg(draw, GDC_REG_DRAW_BASE, 0);
48481 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
48482diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
48483index ff22871..b129bed 100644
48484--- a/drivers/video/nvidia/nvidia.c
48485+++ b/drivers/video/nvidia/nvidia.c
48486@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
48487 info->fix.line_length = (info->var.xres_virtual *
48488 info->var.bits_per_pixel) >> 3;
48489 if (info->var.accel_flags) {
48490- info->fbops->fb_imageblit = nvidiafb_imageblit;
48491- info->fbops->fb_fillrect = nvidiafb_fillrect;
48492- info->fbops->fb_copyarea = nvidiafb_copyarea;
48493- info->fbops->fb_sync = nvidiafb_sync;
48494+ pax_open_kernel();
48495+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
48496+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
48497+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
48498+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
48499+ pax_close_kernel();
48500 info->pixmap.scan_align = 4;
48501 info->flags &= ~FBINFO_HWACCEL_DISABLED;
48502 info->flags |= FBINFO_READS_FAST;
48503 NVResetGraphics(info);
48504 } else {
48505- info->fbops->fb_imageblit = cfb_imageblit;
48506- info->fbops->fb_fillrect = cfb_fillrect;
48507- info->fbops->fb_copyarea = cfb_copyarea;
48508- info->fbops->fb_sync = NULL;
48509+ pax_open_kernel();
48510+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
48511+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
48512+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
48513+ *(void **)&info->fbops->fb_sync = NULL;
48514+ pax_close_kernel();
48515 info->pixmap.scan_align = 1;
48516 info->flags |= FBINFO_HWACCEL_DISABLED;
48517 info->flags &= ~FBINFO_READS_FAST;
48518@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
48519 info->pixmap.size = 8 * 1024;
48520 info->pixmap.flags = FB_PIXMAP_SYSTEM;
48521
48522- if (!hwcur)
48523- info->fbops->fb_cursor = NULL;
48524+ if (!hwcur) {
48525+ pax_open_kernel();
48526+ *(void **)&info->fbops->fb_cursor = NULL;
48527+ pax_close_kernel();
48528+ }
48529
48530 info->var.accel_flags = (!noaccel);
48531
48532diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
48533index 76d9053..dec2bfd 100644
48534--- a/drivers/video/s1d13xxxfb.c
48535+++ b/drivers/video/s1d13xxxfb.c
48536@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
48537
48538 switch(prod_id) {
48539 case S1D13506_PROD_ID: /* activate acceleration */
48540- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
48541- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
48542+ pax_open_kernel();
48543+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
48544+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
48545+ pax_close_kernel();
48546 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
48547 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
48548 break;
48549diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
48550index 97bd662..39fab85 100644
48551--- a/drivers/video/smscufx.c
48552+++ b/drivers/video/smscufx.c
48553@@ -1171,7 +1171,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
48554 fb_deferred_io_cleanup(info);
48555 kfree(info->fbdefio);
48556 info->fbdefio = NULL;
48557- info->fbops->fb_mmap = ufx_ops_mmap;
48558+ pax_open_kernel();
48559+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
48560+ pax_close_kernel();
48561 }
48562
48563 pr_debug("released /dev/fb%d user=%d count=%d",
48564diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
48565index 86d449e..8e04dc5 100644
48566--- a/drivers/video/udlfb.c
48567+++ b/drivers/video/udlfb.c
48568@@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
48569 dlfb_urb_completion(urb);
48570
48571 error:
48572- atomic_add(bytes_sent, &dev->bytes_sent);
48573- atomic_add(bytes_identical, &dev->bytes_identical);
48574- atomic_add(width*height*2, &dev->bytes_rendered);
48575+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
48576+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
48577+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
48578 end_cycles = get_cycles();
48579- atomic_add(((unsigned int) ((end_cycles - start_cycles)
48580+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
48581 >> 10)), /* Kcycles */
48582 &dev->cpu_kcycles_used);
48583
48584@@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
48585 dlfb_urb_completion(urb);
48586
48587 error:
48588- atomic_add(bytes_sent, &dev->bytes_sent);
48589- atomic_add(bytes_identical, &dev->bytes_identical);
48590- atomic_add(bytes_rendered, &dev->bytes_rendered);
48591+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
48592+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
48593+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
48594 end_cycles = get_cycles();
48595- atomic_add(((unsigned int) ((end_cycles - start_cycles)
48596+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
48597 >> 10)), /* Kcycles */
48598 &dev->cpu_kcycles_used);
48599 }
48600@@ -989,7 +989,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
48601 fb_deferred_io_cleanup(info);
48602 kfree(info->fbdefio);
48603 info->fbdefio = NULL;
48604- info->fbops->fb_mmap = dlfb_ops_mmap;
48605+ pax_open_kernel();
48606+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
48607+ pax_close_kernel();
48608 }
48609
48610 pr_warn("released /dev/fb%d user=%d count=%d\n",
48611@@ -1372,7 +1374,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
48612 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48613 struct dlfb_data *dev = fb_info->par;
48614 return snprintf(buf, PAGE_SIZE, "%u\n",
48615- atomic_read(&dev->bytes_rendered));
48616+ atomic_read_unchecked(&dev->bytes_rendered));
48617 }
48618
48619 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
48620@@ -1380,7 +1382,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
48621 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48622 struct dlfb_data *dev = fb_info->par;
48623 return snprintf(buf, PAGE_SIZE, "%u\n",
48624- atomic_read(&dev->bytes_identical));
48625+ atomic_read_unchecked(&dev->bytes_identical));
48626 }
48627
48628 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
48629@@ -1388,7 +1390,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
48630 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48631 struct dlfb_data *dev = fb_info->par;
48632 return snprintf(buf, PAGE_SIZE, "%u\n",
48633- atomic_read(&dev->bytes_sent));
48634+ atomic_read_unchecked(&dev->bytes_sent));
48635 }
48636
48637 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
48638@@ -1396,7 +1398,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
48639 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48640 struct dlfb_data *dev = fb_info->par;
48641 return snprintf(buf, PAGE_SIZE, "%u\n",
48642- atomic_read(&dev->cpu_kcycles_used));
48643+ atomic_read_unchecked(&dev->cpu_kcycles_used));
48644 }
48645
48646 static ssize_t edid_show(
48647@@ -1456,10 +1458,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
48648 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48649 struct dlfb_data *dev = fb_info->par;
48650
48651- atomic_set(&dev->bytes_rendered, 0);
48652- atomic_set(&dev->bytes_identical, 0);
48653- atomic_set(&dev->bytes_sent, 0);
48654- atomic_set(&dev->cpu_kcycles_used, 0);
48655+ atomic_set_unchecked(&dev->bytes_rendered, 0);
48656+ atomic_set_unchecked(&dev->bytes_identical, 0);
48657+ atomic_set_unchecked(&dev->bytes_sent, 0);
48658+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
48659
48660 return count;
48661 }
48662diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
48663index b75db01..ad2f34a 100644
48664--- a/drivers/video/uvesafb.c
48665+++ b/drivers/video/uvesafb.c
48666@@ -19,6 +19,7 @@
48667 #include <linux/io.h>
48668 #include <linux/mutex.h>
48669 #include <linux/slab.h>
48670+#include <linux/moduleloader.h>
48671 #include <video/edid.h>
48672 #include <video/uvesafb.h>
48673 #ifdef CONFIG_X86
48674@@ -569,10 +570,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
48675 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
48676 par->pmi_setpal = par->ypan = 0;
48677 } else {
48678+
48679+#ifdef CONFIG_PAX_KERNEXEC
48680+#ifdef CONFIG_MODULES
48681+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
48682+#endif
48683+ if (!par->pmi_code) {
48684+ par->pmi_setpal = par->ypan = 0;
48685+ return 0;
48686+ }
48687+#endif
48688+
48689 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
48690 + task->t.regs.edi);
48691+
48692+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48693+ pax_open_kernel();
48694+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
48695+ pax_close_kernel();
48696+
48697+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
48698+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
48699+#else
48700 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
48701 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
48702+#endif
48703+
48704 printk(KERN_INFO "uvesafb: protected mode interface info at "
48705 "%04x:%04x\n",
48706 (u16)task->t.regs.es, (u16)task->t.regs.edi);
48707@@ -817,13 +840,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
48708 par->ypan = ypan;
48709
48710 if (par->pmi_setpal || par->ypan) {
48711+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
48712 if (__supported_pte_mask & _PAGE_NX) {
48713 par->pmi_setpal = par->ypan = 0;
48714 printk(KERN_WARNING "uvesafb: NX protection is actively."
48715 "We have better not to use the PMI.\n");
48716- } else {
48717+ } else
48718+#endif
48719 uvesafb_vbe_getpmi(task, par);
48720- }
48721 }
48722 #else
48723 /* The protected mode interface is not available on non-x86. */
48724@@ -1457,8 +1481,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
48725 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
48726
48727 /* Disable blanking if the user requested so. */
48728- if (!blank)
48729- info->fbops->fb_blank = NULL;
48730+ if (!blank) {
48731+ pax_open_kernel();
48732+ *(void **)&info->fbops->fb_blank = NULL;
48733+ pax_close_kernel();
48734+ }
48735
48736 /*
48737 * Find out how much IO memory is required for the mode with
48738@@ -1534,8 +1561,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
48739 info->flags = FBINFO_FLAG_DEFAULT |
48740 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
48741
48742- if (!par->ypan)
48743- info->fbops->fb_pan_display = NULL;
48744+ if (!par->ypan) {
48745+ pax_open_kernel();
48746+ *(void **)&info->fbops->fb_pan_display = NULL;
48747+ pax_close_kernel();
48748+ }
48749 }
48750
48751 static void uvesafb_init_mtrr(struct fb_info *info)
48752@@ -1836,6 +1866,11 @@ out:
48753 if (par->vbe_modes)
48754 kfree(par->vbe_modes);
48755
48756+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48757+ if (par->pmi_code)
48758+ module_free_exec(NULL, par->pmi_code);
48759+#endif
48760+
48761 framebuffer_release(info);
48762 return err;
48763 }
48764@@ -1862,6 +1897,12 @@ static int uvesafb_remove(struct platform_device *dev)
48765 kfree(par->vbe_state_orig);
48766 if (par->vbe_state_saved)
48767 kfree(par->vbe_state_saved);
48768+
48769+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48770+ if (par->pmi_code)
48771+ module_free_exec(NULL, par->pmi_code);
48772+#endif
48773+
48774 }
48775
48776 framebuffer_release(info);
48777diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
48778index 501b340..d80aa17 100644
48779--- a/drivers/video/vesafb.c
48780+++ b/drivers/video/vesafb.c
48781@@ -9,6 +9,7 @@
48782 */
48783
48784 #include <linux/module.h>
48785+#include <linux/moduleloader.h>
48786 #include <linux/kernel.h>
48787 #include <linux/errno.h>
48788 #include <linux/string.h>
48789@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
48790 static int vram_total __initdata; /* Set total amount of memory */
48791 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
48792 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
48793-static void (*pmi_start)(void) __read_mostly;
48794-static void (*pmi_pal) (void) __read_mostly;
48795+static void (*pmi_start)(void) __read_only;
48796+static void (*pmi_pal) (void) __read_only;
48797 static int depth __read_mostly;
48798 static int vga_compat __read_mostly;
48799 /* --------------------------------------------------------------------- */
48800@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
48801 unsigned int size_vmode;
48802 unsigned int size_remap;
48803 unsigned int size_total;
48804+ void *pmi_code = NULL;
48805
48806 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
48807 return -ENODEV;
48808@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
48809 size_remap = size_total;
48810 vesafb_fix.smem_len = size_remap;
48811
48812-#ifndef __i386__
48813- screen_info.vesapm_seg = 0;
48814-#endif
48815-
48816 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
48817 printk(KERN_WARNING
48818 "vesafb: cannot reserve video memory at 0x%lx\n",
48819@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
48820 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
48821 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
48822
48823+#ifdef __i386__
48824+
48825+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48826+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
48827+ if (!pmi_code)
48828+#elif !defined(CONFIG_PAX_KERNEXEC)
48829+ if (0)
48830+#endif
48831+
48832+#endif
48833+ screen_info.vesapm_seg = 0;
48834+
48835 if (screen_info.vesapm_seg) {
48836- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
48837- screen_info.vesapm_seg,screen_info.vesapm_off);
48838+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
48839+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
48840 }
48841
48842 if (screen_info.vesapm_seg < 0xc000)
48843@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
48844
48845 if (ypan || pmi_setpal) {
48846 unsigned short *pmi_base;
48847+
48848 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
48849- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
48850- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
48851+
48852+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48853+ pax_open_kernel();
48854+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
48855+#else
48856+ pmi_code = pmi_base;
48857+#endif
48858+
48859+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
48860+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
48861+
48862+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48863+ pmi_start = ktva_ktla(pmi_start);
48864+ pmi_pal = ktva_ktla(pmi_pal);
48865+ pax_close_kernel();
48866+#endif
48867+
48868 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
48869 if (pmi_base[3]) {
48870 printk(KERN_INFO "vesafb: pmi: ports = ");
48871@@ -472,8 +498,11 @@ static int __init vesafb_probe(struct platform_device *dev)
48872 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
48873 (ypan ? FBINFO_HWACCEL_YPAN : 0);
48874
48875- if (!ypan)
48876- info->fbops->fb_pan_display = NULL;
48877+ if (!ypan) {
48878+ pax_open_kernel();
48879+ *(void **)&info->fbops->fb_pan_display = NULL;
48880+ pax_close_kernel();
48881+ }
48882
48883 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
48884 err = -ENOMEM;
48885@@ -488,6 +517,11 @@ static int __init vesafb_probe(struct platform_device *dev)
48886 info->node, info->fix.id);
48887 return 0;
48888 err:
48889+
48890+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48891+ module_free_exec(NULL, pmi_code);
48892+#endif
48893+
48894 if (info->screen_base)
48895 iounmap(info->screen_base);
48896 framebuffer_release(info);
48897diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
48898index 88714ae..16c2e11 100644
48899--- a/drivers/video/via/via_clock.h
48900+++ b/drivers/video/via/via_clock.h
48901@@ -56,7 +56,7 @@ struct via_clock {
48902
48903 void (*set_engine_pll_state)(u8 state);
48904 void (*set_engine_pll)(struct via_pll_config config);
48905-};
48906+} __no_const;
48907
48908
48909 static inline u32 get_pll_internal_frequency(u32 ref_freq,
48910diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
48911index fef20db..d28b1ab 100644
48912--- a/drivers/xen/xenfs/xenstored.c
48913+++ b/drivers/xen/xenfs/xenstored.c
48914@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
48915 static int xsd_kva_open(struct inode *inode, struct file *file)
48916 {
48917 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
48918+#ifdef CONFIG_GRKERNSEC_HIDESYM
48919+ NULL);
48920+#else
48921 xen_store_interface);
48922+#endif
48923+
48924 if (!file->private_data)
48925 return -ENOMEM;
48926 return 0;
48927diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
48928index 890bed5..17ae73e 100644
48929--- a/fs/9p/vfs_inode.c
48930+++ b/fs/9p/vfs_inode.c
48931@@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
48932 void
48933 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
48934 {
48935- char *s = nd_get_link(nd);
48936+ const char *s = nd_get_link(nd);
48937
48938 p9_debug(P9_DEBUG_VFS, " %s %s\n",
48939 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
48940diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
48941index 0efd152..b5802ad 100644
48942--- a/fs/Kconfig.binfmt
48943+++ b/fs/Kconfig.binfmt
48944@@ -89,7 +89,7 @@ config HAVE_AOUT
48945
48946 config BINFMT_AOUT
48947 tristate "Kernel support for a.out and ECOFF binaries"
48948- depends on HAVE_AOUT
48949+ depends on HAVE_AOUT && BROKEN
48950 ---help---
48951 A.out (Assembler.OUTput) is a set of formats for libraries and
48952 executables used in the earliest versions of UNIX. Linux used
48953diff --git a/fs/aio.c b/fs/aio.c
48954index 71f613c..9d01f1f 100644
48955--- a/fs/aio.c
48956+++ b/fs/aio.c
48957@@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
48958 size += sizeof(struct io_event) * nr_events;
48959 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
48960
48961- if (nr_pages < 0)
48962+ if (nr_pages <= 0)
48963 return -EINVAL;
48964
48965 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
48966@@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
48967 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
48968 {
48969 ssize_t ret;
48970+ struct iovec iovstack;
48971
48972 #ifdef CONFIG_COMPAT
48973 if (compat)
48974 ret = compat_rw_copy_check_uvector(type,
48975 (struct compat_iovec __user *)kiocb->ki_buf,
48976- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
48977+ kiocb->ki_nbytes, 1, &iovstack,
48978 &kiocb->ki_iovec);
48979 else
48980 #endif
48981 ret = rw_copy_check_uvector(type,
48982 (struct iovec __user *)kiocb->ki_buf,
48983- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
48984+ kiocb->ki_nbytes, 1, &iovstack,
48985 &kiocb->ki_iovec);
48986 if (ret < 0)
48987 goto out;
48988@@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
48989 if (ret < 0)
48990 goto out;
48991
48992+ if (kiocb->ki_iovec == &iovstack) {
48993+ kiocb->ki_inline_vec = iovstack;
48994+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
48995+ }
48996 kiocb->ki_nr_segs = kiocb->ki_nbytes;
48997 kiocb->ki_cur_seg = 0;
48998 /* ki_nbytes/left now reflect bytes instead of segs */
48999diff --git a/fs/attr.c b/fs/attr.c
49000index 1449adb..a2038c2 100644
49001--- a/fs/attr.c
49002+++ b/fs/attr.c
49003@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
49004 unsigned long limit;
49005
49006 limit = rlimit(RLIMIT_FSIZE);
49007+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
49008 if (limit != RLIM_INFINITY && offset > limit)
49009 goto out_sig;
49010 if (offset > inode->i_sb->s_maxbytes)
49011diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
49012index 03bc1d3..6205356 100644
49013--- a/fs/autofs4/waitq.c
49014+++ b/fs/autofs4/waitq.c
49015@@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
49016 {
49017 unsigned long sigpipe, flags;
49018 mm_segment_t fs;
49019- const char *data = (const char *)addr;
49020+ const char __user *data = (const char __force_user *)addr;
49021 ssize_t wr = 0;
49022
49023 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
49024@@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
49025 return 1;
49026 }
49027
49028+#ifdef CONFIG_GRKERNSEC_HIDESYM
49029+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
49030+#endif
49031+
49032 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
49033 enum autofs_notify notify)
49034 {
49035@@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
49036
49037 /* If this is a direct mount request create a dummy name */
49038 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
49039+#ifdef CONFIG_GRKERNSEC_HIDESYM
49040+ /* this name does get written to userland via autofs4_write() */
49041+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
49042+#else
49043 qstr.len = sprintf(name, "%p", dentry);
49044+#endif
49045 else {
49046 qstr.len = autofs4_getpath(sbi, dentry, &name);
49047 if (!qstr.len) {
49048diff --git a/fs/befs/endian.h b/fs/befs/endian.h
49049index 2722387..c8dd2a7 100644
49050--- a/fs/befs/endian.h
49051+++ b/fs/befs/endian.h
49052@@ -11,7 +11,7 @@
49053
49054 #include <asm/byteorder.h>
49055
49056-static inline u64
49057+static inline u64 __intentional_overflow(-1)
49058 fs64_to_cpu(const struct super_block *sb, fs64 n)
49059 {
49060 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
49061@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
49062 return (__force fs64)cpu_to_be64(n);
49063 }
49064
49065-static inline u32
49066+static inline u32 __intentional_overflow(-1)
49067 fs32_to_cpu(const struct super_block *sb, fs32 n)
49068 {
49069 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
49070diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
49071index 2b3bda8..6a2d4be 100644
49072--- a/fs/befs/linuxvfs.c
49073+++ b/fs/befs/linuxvfs.c
49074@@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
49075 {
49076 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
49077 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
49078- char *link = nd_get_link(nd);
49079+ const char *link = nd_get_link(nd);
49080 if (!IS_ERR(link))
49081 kfree(link);
49082 }
49083diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
49084index 6043567..16a9239 100644
49085--- a/fs/binfmt_aout.c
49086+++ b/fs/binfmt_aout.c
49087@@ -16,6 +16,7 @@
49088 #include <linux/string.h>
49089 #include <linux/fs.h>
49090 #include <linux/file.h>
49091+#include <linux/security.h>
49092 #include <linux/stat.h>
49093 #include <linux/fcntl.h>
49094 #include <linux/ptrace.h>
49095@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
49096 #endif
49097 # define START_STACK(u) ((void __user *)u.start_stack)
49098
49099+ memset(&dump, 0, sizeof(dump));
49100+
49101 fs = get_fs();
49102 set_fs(KERNEL_DS);
49103 has_dumped = 1;
49104@@ -70,10 +73,12 @@ static int aout_core_dump(struct coredump_params *cprm)
49105
49106 /* If the size of the dump file exceeds the rlimit, then see what would happen
49107 if we wrote the stack, but not the data area. */
49108+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
49109 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
49110 dump.u_dsize = 0;
49111
49112 /* Make sure we have enough room to write the stack and data areas. */
49113+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
49114 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
49115 dump.u_ssize = 0;
49116
49117@@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
49118 rlim = rlimit(RLIMIT_DATA);
49119 if (rlim >= RLIM_INFINITY)
49120 rlim = ~0;
49121+
49122+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
49123 if (ex.a_data + ex.a_bss > rlim)
49124 return -ENOMEM;
49125
49126@@ -268,6 +275,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
49127
49128 install_exec_creds(bprm);
49129
49130+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49131+ current->mm->pax_flags = 0UL;
49132+#endif
49133+
49134+#ifdef CONFIG_PAX_PAGEEXEC
49135+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
49136+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
49137+
49138+#ifdef CONFIG_PAX_EMUTRAMP
49139+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
49140+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
49141+#endif
49142+
49143+#ifdef CONFIG_PAX_MPROTECT
49144+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
49145+ current->mm->pax_flags |= MF_PAX_MPROTECT;
49146+#endif
49147+
49148+ }
49149+#endif
49150+
49151 if (N_MAGIC(ex) == OMAGIC) {
49152 unsigned long text_addr, map_size;
49153 loff_t pos;
49154@@ -333,7 +361,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
49155 }
49156
49157 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
49158- PROT_READ | PROT_WRITE | PROT_EXEC,
49159+ PROT_READ | PROT_WRITE,
49160 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
49161 fd_offset + ex.a_text);
49162 if (error != N_DATADDR(ex)) {
49163diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
49164index 0c42cdb..b62581e9 100644
49165--- a/fs/binfmt_elf.c
49166+++ b/fs/binfmt_elf.c
49167@@ -33,6 +33,7 @@
49168 #include <linux/elf.h>
49169 #include <linux/utsname.h>
49170 #include <linux/coredump.h>
49171+#include <linux/xattr.h>
49172 #include <asm/uaccess.h>
49173 #include <asm/param.h>
49174 #include <asm/page.h>
49175@@ -59,6 +60,10 @@ static int elf_core_dump(struct coredump_params *cprm);
49176 #define elf_core_dump NULL
49177 #endif
49178
49179+#ifdef CONFIG_PAX_MPROTECT
49180+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
49181+#endif
49182+
49183 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
49184 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
49185 #else
49186@@ -78,6 +83,11 @@ static struct linux_binfmt elf_format = {
49187 .load_binary = load_elf_binary,
49188 .load_shlib = load_elf_library,
49189 .core_dump = elf_core_dump,
49190+
49191+#ifdef CONFIG_PAX_MPROTECT
49192+ .handle_mprotect= elf_handle_mprotect,
49193+#endif
49194+
49195 .min_coredump = ELF_EXEC_PAGESIZE,
49196 };
49197
49198@@ -85,6 +95,8 @@ static struct linux_binfmt elf_format = {
49199
49200 static int set_brk(unsigned long start, unsigned long end)
49201 {
49202+ unsigned long e = end;
49203+
49204 start = ELF_PAGEALIGN(start);
49205 end = ELF_PAGEALIGN(end);
49206 if (end > start) {
49207@@ -93,7 +105,7 @@ static int set_brk(unsigned long start, unsigned long end)
49208 if (BAD_ADDR(addr))
49209 return addr;
49210 }
49211- current->mm->start_brk = current->mm->brk = end;
49212+ current->mm->start_brk = current->mm->brk = e;
49213 return 0;
49214 }
49215
49216@@ -154,12 +166,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
49217 elf_addr_t __user *u_rand_bytes;
49218 const char *k_platform = ELF_PLATFORM;
49219 const char *k_base_platform = ELF_BASE_PLATFORM;
49220- unsigned char k_rand_bytes[16];
49221+ u32 k_rand_bytes[4];
49222 int items;
49223 elf_addr_t *elf_info;
49224 int ei_index = 0;
49225 const struct cred *cred = current_cred();
49226 struct vm_area_struct *vma;
49227+ unsigned long saved_auxv[AT_VECTOR_SIZE];
49228
49229 /*
49230 * In some cases (e.g. Hyper-Threading), we want to avoid L1
49231@@ -201,8 +214,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
49232 * Generate 16 random bytes for userspace PRNG seeding.
49233 */
49234 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
49235- u_rand_bytes = (elf_addr_t __user *)
49236- STACK_ALLOC(p, sizeof(k_rand_bytes));
49237+ srandom32(k_rand_bytes[0] ^ random32());
49238+ srandom32(k_rand_bytes[1] ^ random32());
49239+ srandom32(k_rand_bytes[2] ^ random32());
49240+ srandom32(k_rand_bytes[3] ^ random32());
49241+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
49242+ u_rand_bytes = (elf_addr_t __user *) p;
49243 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
49244 return -EFAULT;
49245
49246@@ -314,9 +331,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
49247 return -EFAULT;
49248 current->mm->env_end = p;
49249
49250+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
49251+
49252 /* Put the elf_info on the stack in the right place. */
49253 sp = (elf_addr_t __user *)envp + 1;
49254- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
49255+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
49256 return -EFAULT;
49257 return 0;
49258 }
49259@@ -380,15 +399,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
49260 an ELF header */
49261
49262 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
49263- struct file *interpreter, unsigned long *interp_map_addr,
49264- unsigned long no_base)
49265+ struct file *interpreter, unsigned long no_base)
49266 {
49267 struct elf_phdr *elf_phdata;
49268 struct elf_phdr *eppnt;
49269- unsigned long load_addr = 0;
49270+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
49271 int load_addr_set = 0;
49272 unsigned long last_bss = 0, elf_bss = 0;
49273- unsigned long error = ~0UL;
49274+ unsigned long error = -EINVAL;
49275 unsigned long total_size;
49276 int retval, i, size;
49277
49278@@ -434,6 +452,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
49279 goto out_close;
49280 }
49281
49282+#ifdef CONFIG_PAX_SEGMEXEC
49283+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
49284+ pax_task_size = SEGMEXEC_TASK_SIZE;
49285+#endif
49286+
49287 eppnt = elf_phdata;
49288 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
49289 if (eppnt->p_type == PT_LOAD) {
49290@@ -457,8 +480,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
49291 map_addr = elf_map(interpreter, load_addr + vaddr,
49292 eppnt, elf_prot, elf_type, total_size);
49293 total_size = 0;
49294- if (!*interp_map_addr)
49295- *interp_map_addr = map_addr;
49296 error = map_addr;
49297 if (BAD_ADDR(map_addr))
49298 goto out_close;
49299@@ -477,8 +498,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
49300 k = load_addr + eppnt->p_vaddr;
49301 if (BAD_ADDR(k) ||
49302 eppnt->p_filesz > eppnt->p_memsz ||
49303- eppnt->p_memsz > TASK_SIZE ||
49304- TASK_SIZE - eppnt->p_memsz < k) {
49305+ eppnt->p_memsz > pax_task_size ||
49306+ pax_task_size - eppnt->p_memsz < k) {
49307 error = -ENOMEM;
49308 goto out_close;
49309 }
49310@@ -530,6 +551,315 @@ out:
49311 return error;
49312 }
49313
49314+#ifdef CONFIG_PAX_PT_PAX_FLAGS
49315+#ifdef CONFIG_PAX_SOFTMODE
49316+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
49317+{
49318+ unsigned long pax_flags = 0UL;
49319+
49320+#ifdef CONFIG_PAX_PAGEEXEC
49321+ if (elf_phdata->p_flags & PF_PAGEEXEC)
49322+ pax_flags |= MF_PAX_PAGEEXEC;
49323+#endif
49324+
49325+#ifdef CONFIG_PAX_SEGMEXEC
49326+ if (elf_phdata->p_flags & PF_SEGMEXEC)
49327+ pax_flags |= MF_PAX_SEGMEXEC;
49328+#endif
49329+
49330+#ifdef CONFIG_PAX_EMUTRAMP
49331+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
49332+ pax_flags |= MF_PAX_EMUTRAMP;
49333+#endif
49334+
49335+#ifdef CONFIG_PAX_MPROTECT
49336+ if (elf_phdata->p_flags & PF_MPROTECT)
49337+ pax_flags |= MF_PAX_MPROTECT;
49338+#endif
49339+
49340+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
49341+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
49342+ pax_flags |= MF_PAX_RANDMMAP;
49343+#endif
49344+
49345+ return pax_flags;
49346+}
49347+#endif
49348+
49349+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
49350+{
49351+ unsigned long pax_flags = 0UL;
49352+
49353+#ifdef CONFIG_PAX_PAGEEXEC
49354+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
49355+ pax_flags |= MF_PAX_PAGEEXEC;
49356+#endif
49357+
49358+#ifdef CONFIG_PAX_SEGMEXEC
49359+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
49360+ pax_flags |= MF_PAX_SEGMEXEC;
49361+#endif
49362+
49363+#ifdef CONFIG_PAX_EMUTRAMP
49364+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
49365+ pax_flags |= MF_PAX_EMUTRAMP;
49366+#endif
49367+
49368+#ifdef CONFIG_PAX_MPROTECT
49369+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
49370+ pax_flags |= MF_PAX_MPROTECT;
49371+#endif
49372+
49373+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
49374+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
49375+ pax_flags |= MF_PAX_RANDMMAP;
49376+#endif
49377+
49378+ return pax_flags;
49379+}
49380+#endif
49381+
49382+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
49383+#ifdef CONFIG_PAX_SOFTMODE
49384+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
49385+{
49386+ unsigned long pax_flags = 0UL;
49387+
49388+#ifdef CONFIG_PAX_PAGEEXEC
49389+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
49390+ pax_flags |= MF_PAX_PAGEEXEC;
49391+#endif
49392+
49393+#ifdef CONFIG_PAX_SEGMEXEC
49394+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
49395+ pax_flags |= MF_PAX_SEGMEXEC;
49396+#endif
49397+
49398+#ifdef CONFIG_PAX_EMUTRAMP
49399+ if (pax_flags_softmode & MF_PAX_EMUTRAMP)
49400+ pax_flags |= MF_PAX_EMUTRAMP;
49401+#endif
49402+
49403+#ifdef CONFIG_PAX_MPROTECT
49404+ if (pax_flags_softmode & MF_PAX_MPROTECT)
49405+ pax_flags |= MF_PAX_MPROTECT;
49406+#endif
49407+
49408+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
49409+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
49410+ pax_flags |= MF_PAX_RANDMMAP;
49411+#endif
49412+
49413+ return pax_flags;
49414+}
49415+#endif
49416+
49417+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
49418+{
49419+ unsigned long pax_flags = 0UL;
49420+
49421+#ifdef CONFIG_PAX_PAGEEXEC
49422+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
49423+ pax_flags |= MF_PAX_PAGEEXEC;
49424+#endif
49425+
49426+#ifdef CONFIG_PAX_SEGMEXEC
49427+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
49428+ pax_flags |= MF_PAX_SEGMEXEC;
49429+#endif
49430+
49431+#ifdef CONFIG_PAX_EMUTRAMP
49432+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
49433+ pax_flags |= MF_PAX_EMUTRAMP;
49434+#endif
49435+
49436+#ifdef CONFIG_PAX_MPROTECT
49437+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
49438+ pax_flags |= MF_PAX_MPROTECT;
49439+#endif
49440+
49441+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
49442+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
49443+ pax_flags |= MF_PAX_RANDMMAP;
49444+#endif
49445+
49446+ return pax_flags;
49447+}
49448+#endif
49449+
49450+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49451+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
49452+{
49453+ unsigned long pax_flags = 0UL;
49454+
49455+#ifdef CONFIG_PAX_EI_PAX
49456+
49457+#ifdef CONFIG_PAX_PAGEEXEC
49458+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
49459+ pax_flags |= MF_PAX_PAGEEXEC;
49460+#endif
49461+
49462+#ifdef CONFIG_PAX_SEGMEXEC
49463+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
49464+ pax_flags |= MF_PAX_SEGMEXEC;
49465+#endif
49466+
49467+#ifdef CONFIG_PAX_EMUTRAMP
49468+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
49469+ pax_flags |= MF_PAX_EMUTRAMP;
49470+#endif
49471+
49472+#ifdef CONFIG_PAX_MPROTECT
49473+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
49474+ pax_flags |= MF_PAX_MPROTECT;
49475+#endif
49476+
49477+#ifdef CONFIG_PAX_ASLR
49478+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
49479+ pax_flags |= MF_PAX_RANDMMAP;
49480+#endif
49481+
49482+#else
49483+
49484+#ifdef CONFIG_PAX_PAGEEXEC
49485+ pax_flags |= MF_PAX_PAGEEXEC;
49486+#endif
49487+
49488+#ifdef CONFIG_PAX_SEGMEXEC
49489+ pax_flags |= MF_PAX_SEGMEXEC;
49490+#endif
49491+
49492+#ifdef CONFIG_PAX_MPROTECT
49493+ pax_flags |= MF_PAX_MPROTECT;
49494+#endif
49495+
49496+#ifdef CONFIG_PAX_RANDMMAP
49497+ if (randomize_va_space)
49498+ pax_flags |= MF_PAX_RANDMMAP;
49499+#endif
49500+
49501+#endif
49502+
49503+ return pax_flags;
49504+}
49505+
49506+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
49507+{
49508+
49509+#ifdef CONFIG_PAX_PT_PAX_FLAGS
49510+ unsigned long i;
49511+
49512+ for (i = 0UL; i < elf_ex->e_phnum; i++)
49513+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
49514+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
49515+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
49516+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
49517+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
49518+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
49519+ return ~0UL;
49520+
49521+#ifdef CONFIG_PAX_SOFTMODE
49522+ if (pax_softmode)
49523+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
49524+ else
49525+#endif
49526+
49527+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
49528+ break;
49529+ }
49530+#endif
49531+
49532+ return ~0UL;
49533+}
49534+
49535+static unsigned long pax_parse_xattr_pax(struct file * const file)
49536+{
49537+
49538+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
49539+ ssize_t xattr_size, i;
49540+ unsigned char xattr_value[5];
49541+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
49542+
49543+ xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
49544+ if (xattr_size <= 0 || xattr_size > 5)
49545+ return ~0UL;
49546+
49547+ for (i = 0; i < xattr_size; i++)
49548+ switch (xattr_value[i]) {
49549+ default:
49550+ return ~0UL;
49551+
49552+#define parse_flag(option1, option2, flag) \
49553+ case option1: \
49554+ if (pax_flags_hardmode & MF_PAX_##flag) \
49555+ return ~0UL; \
49556+ pax_flags_hardmode |= MF_PAX_##flag; \
49557+ break; \
49558+ case option2: \
49559+ if (pax_flags_softmode & MF_PAX_##flag) \
49560+ return ~0UL; \
49561+ pax_flags_softmode |= MF_PAX_##flag; \
49562+ break;
49563+
49564+ parse_flag('p', 'P', PAGEEXEC);
49565+ parse_flag('e', 'E', EMUTRAMP);
49566+ parse_flag('m', 'M', MPROTECT);
49567+ parse_flag('r', 'R', RANDMMAP);
49568+ parse_flag('s', 'S', SEGMEXEC);
49569+
49570+#undef parse_flag
49571+ }
49572+
49573+ if (pax_flags_hardmode & pax_flags_softmode)
49574+ return ~0UL;
49575+
49576+#ifdef CONFIG_PAX_SOFTMODE
49577+ if (pax_softmode)
49578+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
49579+ else
49580+#endif
49581+
49582+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
49583+#else
49584+ return ~0UL;
49585+#endif
49586+
49587+}
49588+
49589+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
49590+{
49591+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
49592+
49593+ pax_flags = pax_parse_ei_pax(elf_ex);
49594+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
49595+ xattr_pax_flags = pax_parse_xattr_pax(file);
49596+
49597+ if (pt_pax_flags == ~0UL)
49598+ pt_pax_flags = xattr_pax_flags;
49599+ else if (xattr_pax_flags == ~0UL)
49600+ xattr_pax_flags = pt_pax_flags;
49601+ if (pt_pax_flags != xattr_pax_flags)
49602+ return -EINVAL;
49603+ if (pt_pax_flags != ~0UL)
49604+ pax_flags = pt_pax_flags;
49605+
49606+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
49607+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
49608+ if ((__supported_pte_mask & _PAGE_NX))
49609+ pax_flags &= ~MF_PAX_SEGMEXEC;
49610+ else
49611+ pax_flags &= ~MF_PAX_PAGEEXEC;
49612+ }
49613+#endif
49614+
49615+ if (0 > pax_check_flags(&pax_flags))
49616+ return -EINVAL;
49617+
49618+ current->mm->pax_flags = pax_flags;
49619+ return 0;
49620+}
49621+#endif
49622+
49623 /*
49624 * These are the functions used to load ELF style executables and shared
49625 * libraries. There is no binary dependent code anywhere else.
49626@@ -546,6 +876,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
49627 {
49628 unsigned int random_variable = 0;
49629
49630+#ifdef CONFIG_PAX_RANDUSTACK
49631+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
49632+ return stack_top - current->mm->delta_stack;
49633+#endif
49634+
49635 if ((current->flags & PF_RANDOMIZE) &&
49636 !(current->personality & ADDR_NO_RANDOMIZE)) {
49637 random_variable = get_random_int() & STACK_RND_MASK;
49638@@ -564,7 +899,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
49639 unsigned long load_addr = 0, load_bias = 0;
49640 int load_addr_set = 0;
49641 char * elf_interpreter = NULL;
49642- unsigned long error;
49643+ unsigned long error = 0;
49644 struct elf_phdr *elf_ppnt, *elf_phdata;
49645 unsigned long elf_bss, elf_brk;
49646 int retval, i;
49647@@ -574,12 +909,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
49648 unsigned long start_code, end_code, start_data, end_data;
49649 unsigned long reloc_func_desc __maybe_unused = 0;
49650 int executable_stack = EXSTACK_DEFAULT;
49651- unsigned long def_flags = 0;
49652 struct pt_regs *regs = current_pt_regs();
49653 struct {
49654 struct elfhdr elf_ex;
49655 struct elfhdr interp_elf_ex;
49656 } *loc;
49657+ unsigned long pax_task_size = TASK_SIZE;
49658
49659 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
49660 if (!loc) {
49661@@ -715,11 +1050,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
49662 goto out_free_dentry;
49663
49664 /* OK, This is the point of no return */
49665- current->mm->def_flags = def_flags;
49666+
49667+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49668+ current->mm->pax_flags = 0UL;
49669+#endif
49670+
49671+#ifdef CONFIG_PAX_DLRESOLVE
49672+ current->mm->call_dl_resolve = 0UL;
49673+#endif
49674+
49675+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
49676+ current->mm->call_syscall = 0UL;
49677+#endif
49678+
49679+#ifdef CONFIG_PAX_ASLR
49680+ current->mm->delta_mmap = 0UL;
49681+ current->mm->delta_stack = 0UL;
49682+#endif
49683+
49684+ current->mm->def_flags = 0;
49685+
49686+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49687+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
49688+ send_sig(SIGKILL, current, 0);
49689+ goto out_free_dentry;
49690+ }
49691+#endif
49692+
49693+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
49694+ pax_set_initial_flags(bprm);
49695+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
49696+ if (pax_set_initial_flags_func)
49697+ (pax_set_initial_flags_func)(bprm);
49698+#endif
49699+
49700+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49701+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
49702+ current->mm->context.user_cs_limit = PAGE_SIZE;
49703+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
49704+ }
49705+#endif
49706+
49707+#ifdef CONFIG_PAX_SEGMEXEC
49708+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
49709+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
49710+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
49711+ pax_task_size = SEGMEXEC_TASK_SIZE;
49712+ current->mm->def_flags |= VM_NOHUGEPAGE;
49713+ }
49714+#endif
49715+
49716+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
49717+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
49718+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
49719+ put_cpu();
49720+ }
49721+#endif
49722
49723 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
49724 may depend on the personality. */
49725 SET_PERSONALITY(loc->elf_ex);
49726+
49727+#ifdef CONFIG_PAX_ASLR
49728+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
49729+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
49730+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
49731+ }
49732+#endif
49733+
49734+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
49735+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
49736+ executable_stack = EXSTACK_DISABLE_X;
49737+ current->personality &= ~READ_IMPLIES_EXEC;
49738+ } else
49739+#endif
49740+
49741 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
49742 current->personality |= READ_IMPLIES_EXEC;
49743
49744@@ -810,6 +1215,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
49745 #else
49746 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
49747 #endif
49748+
49749+#ifdef CONFIG_PAX_RANDMMAP
49750+ /* PaX: randomize base address at the default exe base if requested */
49751+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
49752+#ifdef CONFIG_SPARC64
49753+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
49754+#else
49755+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
49756+#endif
49757+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
49758+ elf_flags |= MAP_FIXED;
49759+ }
49760+#endif
49761+
49762 }
49763
49764 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
49765@@ -842,9 +1261,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
49766 * allowed task size. Note that p_filesz must always be
49767 * <= p_memsz so it is only necessary to check p_memsz.
49768 */
49769- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
49770- elf_ppnt->p_memsz > TASK_SIZE ||
49771- TASK_SIZE - elf_ppnt->p_memsz < k) {
49772+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
49773+ elf_ppnt->p_memsz > pax_task_size ||
49774+ pax_task_size - elf_ppnt->p_memsz < k) {
49775 /* set_brk can never work. Avoid overflows. */
49776 send_sig(SIGKILL, current, 0);
49777 retval = -EINVAL;
49778@@ -883,17 +1302,44 @@ static int load_elf_binary(struct linux_binprm *bprm)
49779 goto out_free_dentry;
49780 }
49781 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
49782- send_sig(SIGSEGV, current, 0);
49783- retval = -EFAULT; /* Nobody gets to see this, but.. */
49784- goto out_free_dentry;
49785+ /*
49786+ * This bss-zeroing can fail if the ELF
49787+ * file specifies odd protections. So
49788+ * we don't check the return value
49789+ */
49790 }
49791
49792+#ifdef CONFIG_PAX_RANDMMAP
49793+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
49794+ unsigned long start, size, flags, vm_flags;
49795+
49796+ start = ELF_PAGEALIGN(elf_brk);
49797+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
49798+ flags = MAP_FIXED | MAP_PRIVATE;
49799+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
49800+
49801+ down_write(&current->mm->mmap_sem);
49802+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
49803+ retval = -ENOMEM;
49804+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
49805+// if (current->personality & ADDR_NO_RANDOMIZE)
49806+// vm_flags |= VM_READ | VM_MAYREAD;
49807+ start = mmap_region(NULL, start, PAGE_ALIGN(size), flags, vm_flags, 0);
49808+ retval = IS_ERR_VALUE(start) ? start : 0;
49809+ }
49810+ up_write(&current->mm->mmap_sem);
49811+ if (retval == 0)
49812+ retval = set_brk(start + size, start + size + PAGE_SIZE);
49813+ if (retval < 0) {
49814+ send_sig(SIGKILL, current, 0);
49815+ goto out_free_dentry;
49816+ }
49817+ }
49818+#endif
49819+
49820 if (elf_interpreter) {
49821- unsigned long interp_map_addr = 0;
49822-
49823 elf_entry = load_elf_interp(&loc->interp_elf_ex,
49824 interpreter,
49825- &interp_map_addr,
49826 load_bias);
49827 if (!IS_ERR((void *)elf_entry)) {
49828 /*
49829@@ -1115,7 +1561,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
49830 * Decide what to dump of a segment, part, all or none.
49831 */
49832 static unsigned long vma_dump_size(struct vm_area_struct *vma,
49833- unsigned long mm_flags)
49834+ unsigned long mm_flags, long signr)
49835 {
49836 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
49837
49838@@ -1152,7 +1598,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
49839 if (vma->vm_file == NULL)
49840 return 0;
49841
49842- if (FILTER(MAPPED_PRIVATE))
49843+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
49844 goto whole;
49845
49846 /*
49847@@ -1374,9 +1820,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
49848 {
49849 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
49850 int i = 0;
49851- do
49852+ do {
49853 i += 2;
49854- while (auxv[i - 2] != AT_NULL);
49855+ } while (auxv[i - 2] != AT_NULL);
49856 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
49857 }
49858
49859@@ -2006,14 +2452,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
49860 }
49861
49862 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
49863- unsigned long mm_flags)
49864+ struct coredump_params *cprm)
49865 {
49866 struct vm_area_struct *vma;
49867 size_t size = 0;
49868
49869 for (vma = first_vma(current, gate_vma); vma != NULL;
49870 vma = next_vma(vma, gate_vma))
49871- size += vma_dump_size(vma, mm_flags);
49872+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
49873 return size;
49874 }
49875
49876@@ -2107,7 +2553,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49877
49878 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
49879
49880- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
49881+ offset += elf_core_vma_data_size(gate_vma, cprm);
49882 offset += elf_core_extra_data_size();
49883 e_shoff = offset;
49884
49885@@ -2121,10 +2567,12 @@ static int elf_core_dump(struct coredump_params *cprm)
49886 offset = dataoff;
49887
49888 size += sizeof(*elf);
49889+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49890 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
49891 goto end_coredump;
49892
49893 size += sizeof(*phdr4note);
49894+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49895 if (size > cprm->limit
49896 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
49897 goto end_coredump;
49898@@ -2138,7 +2586,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49899 phdr.p_offset = offset;
49900 phdr.p_vaddr = vma->vm_start;
49901 phdr.p_paddr = 0;
49902- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
49903+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
49904 phdr.p_memsz = vma->vm_end - vma->vm_start;
49905 offset += phdr.p_filesz;
49906 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
49907@@ -2149,6 +2597,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49908 phdr.p_align = ELF_EXEC_PAGESIZE;
49909
49910 size += sizeof(phdr);
49911+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49912 if (size > cprm->limit
49913 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
49914 goto end_coredump;
49915@@ -2173,7 +2622,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49916 unsigned long addr;
49917 unsigned long end;
49918
49919- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
49920+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
49921
49922 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
49923 struct page *page;
49924@@ -2182,6 +2631,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49925 page = get_dump_page(addr);
49926 if (page) {
49927 void *kaddr = kmap(page);
49928+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
49929 stop = ((size += PAGE_SIZE) > cprm->limit) ||
49930 !dump_write(cprm->file, kaddr,
49931 PAGE_SIZE);
49932@@ -2199,6 +2649,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49933
49934 if (e_phnum == PN_XNUM) {
49935 size += sizeof(*shdr4extnum);
49936+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49937 if (size > cprm->limit
49938 || !dump_write(cprm->file, shdr4extnum,
49939 sizeof(*shdr4extnum)))
49940@@ -2219,6 +2670,97 @@ out:
49941
49942 #endif /* CONFIG_ELF_CORE */
49943
49944+#ifdef CONFIG_PAX_MPROTECT
49945+/* PaX: non-PIC ELF libraries need relocations on their executable segments
49946+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
49947+ * we'll remove VM_MAYWRITE for good on RELRO segments.
49948+ *
49949+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
49950+ * basis because we want to allow the common case and not the special ones.
49951+ */
49952+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
49953+{
49954+ struct elfhdr elf_h;
49955+ struct elf_phdr elf_p;
49956+ unsigned long i;
49957+ unsigned long oldflags;
49958+ bool is_textrel_rw, is_textrel_rx, is_relro;
49959+
49960+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
49961+ return;
49962+
49963+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
49964+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
49965+
49966+#ifdef CONFIG_PAX_ELFRELOCS
49967+ /* possible TEXTREL */
49968+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
49969+ 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);
49970+#else
49971+ is_textrel_rw = false;
49972+ is_textrel_rx = false;
49973+#endif
49974+
49975+ /* possible RELRO */
49976+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
49977+
49978+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
49979+ return;
49980+
49981+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
49982+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
49983+
49984+#ifdef CONFIG_PAX_ETEXECRELOCS
49985+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
49986+#else
49987+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
49988+#endif
49989+
49990+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
49991+ !elf_check_arch(&elf_h) ||
49992+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
49993+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
49994+ return;
49995+
49996+ for (i = 0UL; i < elf_h.e_phnum; i++) {
49997+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
49998+ return;
49999+ switch (elf_p.p_type) {
50000+ case PT_DYNAMIC:
50001+ if (!is_textrel_rw && !is_textrel_rx)
50002+ continue;
50003+ i = 0UL;
50004+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
50005+ elf_dyn dyn;
50006+
50007+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
50008+ return;
50009+ if (dyn.d_tag == DT_NULL)
50010+ return;
50011+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
50012+ gr_log_textrel(vma);
50013+ if (is_textrel_rw)
50014+ vma->vm_flags |= VM_MAYWRITE;
50015+ else
50016+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
50017+ vma->vm_flags &= ~VM_MAYWRITE;
50018+ return;
50019+ }
50020+ i++;
50021+ }
50022+ return;
50023+
50024+ case PT_GNU_RELRO:
50025+ if (!is_relro)
50026+ continue;
50027+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
50028+ vma->vm_flags &= ~VM_MAYWRITE;
50029+ return;
50030+ }
50031+ }
50032+}
50033+#endif
50034+
50035 static int __init init_elf_binfmt(void)
50036 {
50037 register_binfmt(&elf_format);
50038diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
50039index b563719..3868998 100644
50040--- a/fs/binfmt_flat.c
50041+++ b/fs/binfmt_flat.c
50042@@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
50043 realdatastart = (unsigned long) -ENOMEM;
50044 printk("Unable to allocate RAM for process data, errno %d\n",
50045 (int)-realdatastart);
50046+ down_write(&current->mm->mmap_sem);
50047 vm_munmap(textpos, text_len);
50048+ up_write(&current->mm->mmap_sem);
50049 ret = realdatastart;
50050 goto err;
50051 }
50052@@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
50053 }
50054 if (IS_ERR_VALUE(result)) {
50055 printk("Unable to read data+bss, errno %d\n", (int)-result);
50056+ down_write(&current->mm->mmap_sem);
50057 vm_munmap(textpos, text_len);
50058 vm_munmap(realdatastart, len);
50059+ up_write(&current->mm->mmap_sem);
50060 ret = result;
50061 goto err;
50062 }
50063@@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
50064 }
50065 if (IS_ERR_VALUE(result)) {
50066 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
50067+ down_write(&current->mm->mmap_sem);
50068 vm_munmap(textpos, text_len + data_len + extra +
50069 MAX_SHARED_LIBS * sizeof(unsigned long));
50070+ up_write(&current->mm->mmap_sem);
50071 ret = result;
50072 goto err;
50073 }
50074diff --git a/fs/bio.c b/fs/bio.c
50075index b96fc6c..431d628 100644
50076--- a/fs/bio.c
50077+++ b/fs/bio.c
50078@@ -818,7 +818,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
50079 /*
50080 * Overflow, abort
50081 */
50082- if (end < start)
50083+ if (end < start || end - start > INT_MAX - nr_pages)
50084 return ERR_PTR(-EINVAL);
50085
50086 nr_pages += end - start;
50087@@ -952,7 +952,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
50088 /*
50089 * Overflow, abort
50090 */
50091- if (end < start)
50092+ if (end < start || end - start > INT_MAX - nr_pages)
50093 return ERR_PTR(-EINVAL);
50094
50095 nr_pages += end - start;
50096@@ -1214,7 +1214,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
50097 const int read = bio_data_dir(bio) == READ;
50098 struct bio_map_data *bmd = bio->bi_private;
50099 int i;
50100- char *p = bmd->sgvecs[0].iov_base;
50101+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
50102
50103 __bio_for_each_segment(bvec, bio, i, 0) {
50104 char *addr = page_address(bvec->bv_page);
50105diff --git a/fs/block_dev.c b/fs/block_dev.c
50106index 883dc49..f27794a 100644
50107--- a/fs/block_dev.c
50108+++ b/fs/block_dev.c
50109@@ -652,7 +652,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
50110 else if (bdev->bd_contains == bdev)
50111 return true; /* is a whole device which isn't held */
50112
50113- else if (whole->bd_holder == bd_may_claim)
50114+ else if (whole->bd_holder == (void *)bd_may_claim)
50115 return true; /* is a partition of a device that is being partitioned */
50116 else if (whole->bd_holder != NULL)
50117 return false; /* is a partition of a held device */
50118diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
50119index ce1c169..1ef484f 100644
50120--- a/fs/btrfs/ctree.c
50121+++ b/fs/btrfs/ctree.c
50122@@ -1036,9 +1036,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
50123 free_extent_buffer(buf);
50124 add_root_to_dirty_list(root);
50125 } else {
50126- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
50127- parent_start = parent->start;
50128- else
50129+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
50130+ if (parent)
50131+ parent_start = parent->start;
50132+ else
50133+ parent_start = 0;
50134+ } else
50135 parent_start = 0;
50136
50137 WARN_ON(trans->transid != btrfs_header_generation(parent));
50138diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
50139index 7c4e6cc..27bd5c2 100644
50140--- a/fs/btrfs/inode.c
50141+++ b/fs/btrfs/inode.c
50142@@ -7314,7 +7314,7 @@ fail:
50143 return -ENOMEM;
50144 }
50145
50146-static int btrfs_getattr(struct vfsmount *mnt,
50147+int btrfs_getattr(struct vfsmount *mnt,
50148 struct dentry *dentry, struct kstat *stat)
50149 {
50150 struct inode *inode = dentry->d_inode;
50151@@ -7328,6 +7328,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
50152 return 0;
50153 }
50154
50155+EXPORT_SYMBOL(btrfs_getattr);
50156+
50157+dev_t get_btrfs_dev_from_inode(struct inode *inode)
50158+{
50159+ return BTRFS_I(inode)->root->anon_dev;
50160+}
50161+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
50162+
50163 /*
50164 * If a file is moved, it will inherit the cow and compression flags of the new
50165 * directory.
50166diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
50167index 338f259..b657640 100644
50168--- a/fs/btrfs/ioctl.c
50169+++ b/fs/btrfs/ioctl.c
50170@@ -3033,9 +3033,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
50171 for (i = 0; i < num_types; i++) {
50172 struct btrfs_space_info *tmp;
50173
50174+ /* Don't copy in more than we allocated */
50175 if (!slot_count)
50176 break;
50177
50178+ slot_count--;
50179+
50180 info = NULL;
50181 rcu_read_lock();
50182 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
50183@@ -3057,10 +3060,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
50184 memcpy(dest, &space, sizeof(space));
50185 dest++;
50186 space_args.total_spaces++;
50187- slot_count--;
50188 }
50189- if (!slot_count)
50190- break;
50191 }
50192 up_read(&info->groups_sem);
50193 }
50194diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
50195index 300e09a..9fe4539 100644
50196--- a/fs/btrfs/relocation.c
50197+++ b/fs/btrfs/relocation.c
50198@@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
50199 }
50200 spin_unlock(&rc->reloc_root_tree.lock);
50201
50202- BUG_ON((struct btrfs_root *)node->data != root);
50203+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
50204
50205 if (!del) {
50206 spin_lock(&rc->reloc_root_tree.lock);
50207diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
50208index d8982e9..29a85fa 100644
50209--- a/fs/btrfs/super.c
50210+++ b/fs/btrfs/super.c
50211@@ -267,7 +267,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
50212 function, line, errstr);
50213 return;
50214 }
50215- ACCESS_ONCE(trans->transaction->aborted) = errno;
50216+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
50217 __btrfs_std_error(root->fs_info, function, line, errno, NULL);
50218 }
50219 /*
50220diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
50221index 622f469..e8d2d55 100644
50222--- a/fs/cachefiles/bind.c
50223+++ b/fs/cachefiles/bind.c
50224@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
50225 args);
50226
50227 /* start by checking things over */
50228- ASSERT(cache->fstop_percent >= 0 &&
50229- cache->fstop_percent < cache->fcull_percent &&
50230+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
50231 cache->fcull_percent < cache->frun_percent &&
50232 cache->frun_percent < 100);
50233
50234- ASSERT(cache->bstop_percent >= 0 &&
50235- cache->bstop_percent < cache->bcull_percent &&
50236+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
50237 cache->bcull_percent < cache->brun_percent &&
50238 cache->brun_percent < 100);
50239
50240diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
50241index 0a1467b..6a53245 100644
50242--- a/fs/cachefiles/daemon.c
50243+++ b/fs/cachefiles/daemon.c
50244@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
50245 if (n > buflen)
50246 return -EMSGSIZE;
50247
50248- if (copy_to_user(_buffer, buffer, n) != 0)
50249+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
50250 return -EFAULT;
50251
50252 return n;
50253@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
50254 if (test_bit(CACHEFILES_DEAD, &cache->flags))
50255 return -EIO;
50256
50257- if (datalen < 0 || datalen > PAGE_SIZE - 1)
50258+ if (datalen > PAGE_SIZE - 1)
50259 return -EOPNOTSUPP;
50260
50261 /* drag the command string into the kernel so we can parse it */
50262@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
50263 if (args[0] != '%' || args[1] != '\0')
50264 return -EINVAL;
50265
50266- if (fstop < 0 || fstop >= cache->fcull_percent)
50267+ if (fstop >= cache->fcull_percent)
50268 return cachefiles_daemon_range_error(cache, args);
50269
50270 cache->fstop_percent = fstop;
50271@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
50272 if (args[0] != '%' || args[1] != '\0')
50273 return -EINVAL;
50274
50275- if (bstop < 0 || bstop >= cache->bcull_percent)
50276+ if (bstop >= cache->bcull_percent)
50277 return cachefiles_daemon_range_error(cache, args);
50278
50279 cache->bstop_percent = bstop;
50280diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
50281index 4938251..7e01445 100644
50282--- a/fs/cachefiles/internal.h
50283+++ b/fs/cachefiles/internal.h
50284@@ -59,7 +59,7 @@ struct cachefiles_cache {
50285 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
50286 struct rb_root active_nodes; /* active nodes (can't be culled) */
50287 rwlock_t active_lock; /* lock for active_nodes */
50288- atomic_t gravecounter; /* graveyard uniquifier */
50289+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
50290 unsigned frun_percent; /* when to stop culling (% files) */
50291 unsigned fcull_percent; /* when to start culling (% files) */
50292 unsigned fstop_percent; /* when to stop allocating (% files) */
50293@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
50294 * proc.c
50295 */
50296 #ifdef CONFIG_CACHEFILES_HISTOGRAM
50297-extern atomic_t cachefiles_lookup_histogram[HZ];
50298-extern atomic_t cachefiles_mkdir_histogram[HZ];
50299-extern atomic_t cachefiles_create_histogram[HZ];
50300+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
50301+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
50302+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
50303
50304 extern int __init cachefiles_proc_init(void);
50305 extern void cachefiles_proc_cleanup(void);
50306 static inline
50307-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
50308+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
50309 {
50310 unsigned long jif = jiffies - start_jif;
50311 if (jif >= HZ)
50312 jif = HZ - 1;
50313- atomic_inc(&histogram[jif]);
50314+ atomic_inc_unchecked(&histogram[jif]);
50315 }
50316
50317 #else
50318diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
50319index 8c01c5fc..15f982e 100644
50320--- a/fs/cachefiles/namei.c
50321+++ b/fs/cachefiles/namei.c
50322@@ -317,7 +317,7 @@ try_again:
50323 /* first step is to make up a grave dentry in the graveyard */
50324 sprintf(nbuffer, "%08x%08x",
50325 (uint32_t) get_seconds(),
50326- (uint32_t) atomic_inc_return(&cache->gravecounter));
50327+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
50328
50329 /* do the multiway lock magic */
50330 trap = lock_rename(cache->graveyard, dir);
50331diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
50332index eccd339..4c1d995 100644
50333--- a/fs/cachefiles/proc.c
50334+++ b/fs/cachefiles/proc.c
50335@@ -14,9 +14,9 @@
50336 #include <linux/seq_file.h>
50337 #include "internal.h"
50338
50339-atomic_t cachefiles_lookup_histogram[HZ];
50340-atomic_t cachefiles_mkdir_histogram[HZ];
50341-atomic_t cachefiles_create_histogram[HZ];
50342+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
50343+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
50344+atomic_unchecked_t cachefiles_create_histogram[HZ];
50345
50346 /*
50347 * display the latency histogram
50348@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
50349 return 0;
50350 default:
50351 index = (unsigned long) v - 3;
50352- x = atomic_read(&cachefiles_lookup_histogram[index]);
50353- y = atomic_read(&cachefiles_mkdir_histogram[index]);
50354- z = atomic_read(&cachefiles_create_histogram[index]);
50355+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
50356+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
50357+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
50358 if (x == 0 && y == 0 && z == 0)
50359 return 0;
50360
50361diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
50362index 4809922..aab2c39 100644
50363--- a/fs/cachefiles/rdwr.c
50364+++ b/fs/cachefiles/rdwr.c
50365@@ -965,7 +965,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
50366 old_fs = get_fs();
50367 set_fs(KERNEL_DS);
50368 ret = file->f_op->write(
50369- file, (const void __user *) data, len, &pos);
50370+ file, (const void __force_user *) data, len, &pos);
50371 set_fs(old_fs);
50372 kunmap(page);
50373 if (ret != len)
50374diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
50375index 8c1aabe..bbf856a 100644
50376--- a/fs/ceph/dir.c
50377+++ b/fs/ceph/dir.c
50378@@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
50379 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
50380 struct ceph_mds_client *mdsc = fsc->mdsc;
50381 unsigned frag = fpos_frag(filp->f_pos);
50382- int off = fpos_off(filp->f_pos);
50383+ unsigned int off = fpos_off(filp->f_pos);
50384 int err;
50385 u32 ftype;
50386 struct ceph_mds_reply_info_parsed *rinfo;
50387diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
50388index d9ea6ed..1e6c8ac 100644
50389--- a/fs/cifs/cifs_debug.c
50390+++ b/fs/cifs/cifs_debug.c
50391@@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
50392
50393 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
50394 #ifdef CONFIG_CIFS_STATS2
50395- atomic_set(&totBufAllocCount, 0);
50396- atomic_set(&totSmBufAllocCount, 0);
50397+ atomic_set_unchecked(&totBufAllocCount, 0);
50398+ atomic_set_unchecked(&totSmBufAllocCount, 0);
50399 #endif /* CONFIG_CIFS_STATS2 */
50400 spin_lock(&cifs_tcp_ses_lock);
50401 list_for_each(tmp1, &cifs_tcp_ses_list) {
50402@@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
50403 tcon = list_entry(tmp3,
50404 struct cifs_tcon,
50405 tcon_list);
50406- atomic_set(&tcon->num_smbs_sent, 0);
50407+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
50408 if (server->ops->clear_stats)
50409 server->ops->clear_stats(tcon);
50410 }
50411@@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
50412 smBufAllocCount.counter, cifs_min_small);
50413 #ifdef CONFIG_CIFS_STATS2
50414 seq_printf(m, "Total Large %d Small %d Allocations\n",
50415- atomic_read(&totBufAllocCount),
50416- atomic_read(&totSmBufAllocCount));
50417+ atomic_read_unchecked(&totBufAllocCount),
50418+ atomic_read_unchecked(&totSmBufAllocCount));
50419 #endif /* CONFIG_CIFS_STATS2 */
50420
50421 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
50422@@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
50423 if (tcon->need_reconnect)
50424 seq_puts(m, "\tDISCONNECTED ");
50425 seq_printf(m, "\nSMBs: %d",
50426- atomic_read(&tcon->num_smbs_sent));
50427+ atomic_read_unchecked(&tcon->num_smbs_sent));
50428 if (server->ops->print_stats)
50429 server->ops->print_stats(m, tcon);
50430 }
50431diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
50432index b9db388..9a73d6d 100644
50433--- a/fs/cifs/cifsfs.c
50434+++ b/fs/cifs/cifsfs.c
50435@@ -1026,7 +1026,7 @@ cifs_init_request_bufs(void)
50436 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
50437 cifs_req_cachep = kmem_cache_create("cifs_request",
50438 CIFSMaxBufSize + max_hdr_size, 0,
50439- SLAB_HWCACHE_ALIGN, NULL);
50440+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
50441 if (cifs_req_cachep == NULL)
50442 return -ENOMEM;
50443
50444@@ -1053,7 +1053,7 @@ cifs_init_request_bufs(void)
50445 efficient to alloc 1 per page off the slab compared to 17K (5page)
50446 alloc of large cifs buffers even when page debugging is on */
50447 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
50448- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
50449+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
50450 NULL);
50451 if (cifs_sm_req_cachep == NULL) {
50452 mempool_destroy(cifs_req_poolp);
50453@@ -1138,8 +1138,8 @@ init_cifs(void)
50454 atomic_set(&bufAllocCount, 0);
50455 atomic_set(&smBufAllocCount, 0);
50456 #ifdef CONFIG_CIFS_STATS2
50457- atomic_set(&totBufAllocCount, 0);
50458- atomic_set(&totSmBufAllocCount, 0);
50459+ atomic_set_unchecked(&totBufAllocCount, 0);
50460+ atomic_set_unchecked(&totSmBufAllocCount, 0);
50461 #endif /* CONFIG_CIFS_STATS2 */
50462
50463 atomic_set(&midCount, 0);
50464diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
50465index e6899ce..d6b2920 100644
50466--- a/fs/cifs/cifsglob.h
50467+++ b/fs/cifs/cifsglob.h
50468@@ -751,35 +751,35 @@ struct cifs_tcon {
50469 __u16 Flags; /* optional support bits */
50470 enum statusEnum tidStatus;
50471 #ifdef CONFIG_CIFS_STATS
50472- atomic_t num_smbs_sent;
50473+ atomic_unchecked_t num_smbs_sent;
50474 union {
50475 struct {
50476- atomic_t num_writes;
50477- atomic_t num_reads;
50478- atomic_t num_flushes;
50479- atomic_t num_oplock_brks;
50480- atomic_t num_opens;
50481- atomic_t num_closes;
50482- atomic_t num_deletes;
50483- atomic_t num_mkdirs;
50484- atomic_t num_posixopens;
50485- atomic_t num_posixmkdirs;
50486- atomic_t num_rmdirs;
50487- atomic_t num_renames;
50488- atomic_t num_t2renames;
50489- atomic_t num_ffirst;
50490- atomic_t num_fnext;
50491- atomic_t num_fclose;
50492- atomic_t num_hardlinks;
50493- atomic_t num_symlinks;
50494- atomic_t num_locks;
50495- atomic_t num_acl_get;
50496- atomic_t num_acl_set;
50497+ atomic_unchecked_t num_writes;
50498+ atomic_unchecked_t num_reads;
50499+ atomic_unchecked_t num_flushes;
50500+ atomic_unchecked_t num_oplock_brks;
50501+ atomic_unchecked_t num_opens;
50502+ atomic_unchecked_t num_closes;
50503+ atomic_unchecked_t num_deletes;
50504+ atomic_unchecked_t num_mkdirs;
50505+ atomic_unchecked_t num_posixopens;
50506+ atomic_unchecked_t num_posixmkdirs;
50507+ atomic_unchecked_t num_rmdirs;
50508+ atomic_unchecked_t num_renames;
50509+ atomic_unchecked_t num_t2renames;
50510+ atomic_unchecked_t num_ffirst;
50511+ atomic_unchecked_t num_fnext;
50512+ atomic_unchecked_t num_fclose;
50513+ atomic_unchecked_t num_hardlinks;
50514+ atomic_unchecked_t num_symlinks;
50515+ atomic_unchecked_t num_locks;
50516+ atomic_unchecked_t num_acl_get;
50517+ atomic_unchecked_t num_acl_set;
50518 } cifs_stats;
50519 #ifdef CONFIG_CIFS_SMB2
50520 struct {
50521- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
50522- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
50523+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
50524+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
50525 } smb2_stats;
50526 #endif /* CONFIG_CIFS_SMB2 */
50527 } stats;
50528@@ -1080,7 +1080,7 @@ convert_delimiter(char *path, char delim)
50529 }
50530
50531 #ifdef CONFIG_CIFS_STATS
50532-#define cifs_stats_inc atomic_inc
50533+#define cifs_stats_inc atomic_inc_unchecked
50534
50535 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
50536 unsigned int bytes)
50537@@ -1445,8 +1445,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
50538 /* Various Debug counters */
50539 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
50540 #ifdef CONFIG_CIFS_STATS2
50541-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
50542-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
50543+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
50544+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
50545 #endif
50546 GLOBAL_EXTERN atomic_t smBufAllocCount;
50547 GLOBAL_EXTERN atomic_t midCount;
50548diff --git a/fs/cifs/link.c b/fs/cifs/link.c
50549index 51dc2fb..1e12a33 100644
50550--- a/fs/cifs/link.c
50551+++ b/fs/cifs/link.c
50552@@ -616,7 +616,7 @@ symlink_exit:
50553
50554 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
50555 {
50556- char *p = nd_get_link(nd);
50557+ const char *p = nd_get_link(nd);
50558 if (!IS_ERR(p))
50559 kfree(p);
50560 }
50561diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
50562index 3a00c0d..42d901c 100644
50563--- a/fs/cifs/misc.c
50564+++ b/fs/cifs/misc.c
50565@@ -169,7 +169,7 @@ cifs_buf_get(void)
50566 memset(ret_buf, 0, buf_size + 3);
50567 atomic_inc(&bufAllocCount);
50568 #ifdef CONFIG_CIFS_STATS2
50569- atomic_inc(&totBufAllocCount);
50570+ atomic_inc_unchecked(&totBufAllocCount);
50571 #endif /* CONFIG_CIFS_STATS2 */
50572 }
50573
50574@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
50575 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
50576 atomic_inc(&smBufAllocCount);
50577 #ifdef CONFIG_CIFS_STATS2
50578- atomic_inc(&totSmBufAllocCount);
50579+ atomic_inc_unchecked(&totSmBufAllocCount);
50580 #endif /* CONFIG_CIFS_STATS2 */
50581
50582 }
50583diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
50584index 47bc5a8..10decbe 100644
50585--- a/fs/cifs/smb1ops.c
50586+++ b/fs/cifs/smb1ops.c
50587@@ -586,27 +586,27 @@ static void
50588 cifs_clear_stats(struct cifs_tcon *tcon)
50589 {
50590 #ifdef CONFIG_CIFS_STATS
50591- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
50592- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
50593- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
50594- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
50595- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
50596- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
50597- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
50598- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
50599- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
50600- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
50601- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
50602- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
50603- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
50604- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
50605- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
50606- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
50607- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
50608- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
50609- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
50610- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
50611- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
50612+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
50613+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
50614+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
50615+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
50616+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
50617+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
50618+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
50619+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
50620+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
50621+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
50622+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
50623+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
50624+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
50625+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
50626+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
50627+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
50628+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
50629+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
50630+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
50631+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
50632+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
50633 #endif
50634 }
50635
50636@@ -615,36 +615,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
50637 {
50638 #ifdef CONFIG_CIFS_STATS
50639 seq_printf(m, " Oplocks breaks: %d",
50640- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
50641+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
50642 seq_printf(m, "\nReads: %d Bytes: %llu",
50643- atomic_read(&tcon->stats.cifs_stats.num_reads),
50644+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
50645 (long long)(tcon->bytes_read));
50646 seq_printf(m, "\nWrites: %d Bytes: %llu",
50647- atomic_read(&tcon->stats.cifs_stats.num_writes),
50648+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
50649 (long long)(tcon->bytes_written));
50650 seq_printf(m, "\nFlushes: %d",
50651- atomic_read(&tcon->stats.cifs_stats.num_flushes));
50652+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
50653 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
50654- atomic_read(&tcon->stats.cifs_stats.num_locks),
50655- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
50656- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
50657+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
50658+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
50659+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
50660 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
50661- atomic_read(&tcon->stats.cifs_stats.num_opens),
50662- atomic_read(&tcon->stats.cifs_stats.num_closes),
50663- atomic_read(&tcon->stats.cifs_stats.num_deletes));
50664+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
50665+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
50666+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
50667 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
50668- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
50669- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
50670+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
50671+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
50672 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
50673- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
50674- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
50675+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
50676+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
50677 seq_printf(m, "\nRenames: %d T2 Renames %d",
50678- atomic_read(&tcon->stats.cifs_stats.num_renames),
50679- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
50680+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
50681+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
50682 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
50683- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
50684- atomic_read(&tcon->stats.cifs_stats.num_fnext),
50685- atomic_read(&tcon->stats.cifs_stats.num_fclose));
50686+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
50687+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
50688+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
50689 #endif
50690 }
50691
50692diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
50693index bceffe7..cd1ae59 100644
50694--- a/fs/cifs/smb2ops.c
50695+++ b/fs/cifs/smb2ops.c
50696@@ -274,8 +274,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
50697 #ifdef CONFIG_CIFS_STATS
50698 int i;
50699 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
50700- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
50701- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
50702+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
50703+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
50704 }
50705 #endif
50706 }
50707@@ -284,66 +284,66 @@ static void
50708 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
50709 {
50710 #ifdef CONFIG_CIFS_STATS
50711- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
50712- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
50713+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
50714+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
50715 seq_printf(m, "\nNegotiates: %d sent %d failed",
50716- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
50717- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
50718+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
50719+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
50720 seq_printf(m, "\nSessionSetups: %d sent %d failed",
50721- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
50722- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
50723+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
50724+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
50725 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
50726 seq_printf(m, "\nLogoffs: %d sent %d failed",
50727- atomic_read(&sent[SMB2_LOGOFF_HE]),
50728- atomic_read(&failed[SMB2_LOGOFF_HE]));
50729+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
50730+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
50731 seq_printf(m, "\nTreeConnects: %d sent %d failed",
50732- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
50733- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
50734+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
50735+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
50736 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
50737- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
50738- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
50739+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
50740+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
50741 seq_printf(m, "\nCreates: %d sent %d failed",
50742- atomic_read(&sent[SMB2_CREATE_HE]),
50743- atomic_read(&failed[SMB2_CREATE_HE]));
50744+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
50745+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
50746 seq_printf(m, "\nCloses: %d sent %d failed",
50747- atomic_read(&sent[SMB2_CLOSE_HE]),
50748- atomic_read(&failed[SMB2_CLOSE_HE]));
50749+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
50750+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
50751 seq_printf(m, "\nFlushes: %d sent %d failed",
50752- atomic_read(&sent[SMB2_FLUSH_HE]),
50753- atomic_read(&failed[SMB2_FLUSH_HE]));
50754+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
50755+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
50756 seq_printf(m, "\nReads: %d sent %d failed",
50757- atomic_read(&sent[SMB2_READ_HE]),
50758- atomic_read(&failed[SMB2_READ_HE]));
50759+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
50760+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
50761 seq_printf(m, "\nWrites: %d sent %d failed",
50762- atomic_read(&sent[SMB2_WRITE_HE]),
50763- atomic_read(&failed[SMB2_WRITE_HE]));
50764+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
50765+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
50766 seq_printf(m, "\nLocks: %d sent %d failed",
50767- atomic_read(&sent[SMB2_LOCK_HE]),
50768- atomic_read(&failed[SMB2_LOCK_HE]));
50769+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
50770+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
50771 seq_printf(m, "\nIOCTLs: %d sent %d failed",
50772- atomic_read(&sent[SMB2_IOCTL_HE]),
50773- atomic_read(&failed[SMB2_IOCTL_HE]));
50774+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
50775+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
50776 seq_printf(m, "\nCancels: %d sent %d failed",
50777- atomic_read(&sent[SMB2_CANCEL_HE]),
50778- atomic_read(&failed[SMB2_CANCEL_HE]));
50779+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
50780+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
50781 seq_printf(m, "\nEchos: %d sent %d failed",
50782- atomic_read(&sent[SMB2_ECHO_HE]),
50783- atomic_read(&failed[SMB2_ECHO_HE]));
50784+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
50785+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
50786 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
50787- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
50788- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
50789+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
50790+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
50791 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
50792- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
50793- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
50794+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
50795+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
50796 seq_printf(m, "\nQueryInfos: %d sent %d failed",
50797- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
50798- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
50799+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
50800+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
50801 seq_printf(m, "\nSetInfos: %d sent %d failed",
50802- atomic_read(&sent[SMB2_SET_INFO_HE]),
50803- atomic_read(&failed[SMB2_SET_INFO_HE]));
50804+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
50805+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
50806 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
50807- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
50808- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
50809+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
50810+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
50811 #endif
50812 }
50813
50814diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
50815index 41d9d07..dbb4772 100644
50816--- a/fs/cifs/smb2pdu.c
50817+++ b/fs/cifs/smb2pdu.c
50818@@ -1761,8 +1761,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
50819 default:
50820 cERROR(1, "info level %u isn't supported",
50821 srch_inf->info_level);
50822- rc = -EINVAL;
50823- goto qdir_exit;
50824+ return -EINVAL;
50825 }
50826
50827 req->FileIndex = cpu_to_le32(index);
50828diff --git a/fs/coda/cache.c b/fs/coda/cache.c
50829index 958ae0e..505c9d0 100644
50830--- a/fs/coda/cache.c
50831+++ b/fs/coda/cache.c
50832@@ -24,7 +24,7 @@
50833 #include "coda_linux.h"
50834 #include "coda_cache.h"
50835
50836-static atomic_t permission_epoch = ATOMIC_INIT(0);
50837+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
50838
50839 /* replace or extend an acl cache hit */
50840 void coda_cache_enter(struct inode *inode, int mask)
50841@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
50842 struct coda_inode_info *cii = ITOC(inode);
50843
50844 spin_lock(&cii->c_lock);
50845- cii->c_cached_epoch = atomic_read(&permission_epoch);
50846+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
50847 if (cii->c_uid != current_fsuid()) {
50848 cii->c_uid = current_fsuid();
50849 cii->c_cached_perm = mask;
50850@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
50851 {
50852 struct coda_inode_info *cii = ITOC(inode);
50853 spin_lock(&cii->c_lock);
50854- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
50855+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
50856 spin_unlock(&cii->c_lock);
50857 }
50858
50859 /* remove all acl caches */
50860 void coda_cache_clear_all(struct super_block *sb)
50861 {
50862- atomic_inc(&permission_epoch);
50863+ atomic_inc_unchecked(&permission_epoch);
50864 }
50865
50866
50867@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
50868 spin_lock(&cii->c_lock);
50869 hit = (mask & cii->c_cached_perm) == mask &&
50870 cii->c_uid == current_fsuid() &&
50871- cii->c_cached_epoch == atomic_read(&permission_epoch);
50872+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
50873 spin_unlock(&cii->c_lock);
50874
50875 return hit;
50876diff --git a/fs/compat.c b/fs/compat.c
50877index a06dcbc..dacb6d3 100644
50878--- a/fs/compat.c
50879+++ b/fs/compat.c
50880@@ -54,7 +54,7 @@
50881 #include <asm/ioctls.h>
50882 #include "internal.h"
50883
50884-int compat_log = 1;
50885+int compat_log = 0;
50886
50887 int compat_printk(const char *fmt, ...)
50888 {
50889@@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
50890
50891 set_fs(KERNEL_DS);
50892 /* The __user pointer cast is valid because of the set_fs() */
50893- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
50894+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
50895 set_fs(oldfs);
50896 /* truncating is ok because it's a user address */
50897 if (!ret)
50898@@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
50899 goto out;
50900
50901 ret = -EINVAL;
50902- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
50903+ if (nr_segs > UIO_MAXIOV)
50904 goto out;
50905 if (nr_segs > fast_segs) {
50906 ret = -ENOMEM;
50907@@ -835,6 +835,7 @@ struct compat_old_linux_dirent {
50908
50909 struct compat_readdir_callback {
50910 struct compat_old_linux_dirent __user *dirent;
50911+ struct file * file;
50912 int result;
50913 };
50914
50915@@ -852,6 +853,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
50916 buf->result = -EOVERFLOW;
50917 return -EOVERFLOW;
50918 }
50919+
50920+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50921+ return 0;
50922+
50923 buf->result++;
50924 dirent = buf->dirent;
50925 if (!access_ok(VERIFY_WRITE, dirent,
50926@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
50927
50928 buf.result = 0;
50929 buf.dirent = dirent;
50930+ buf.file = f.file;
50931
50932 error = vfs_readdir(f.file, compat_fillonedir, &buf);
50933 if (buf.result)
50934@@ -901,6 +907,7 @@ struct compat_linux_dirent {
50935 struct compat_getdents_callback {
50936 struct compat_linux_dirent __user *current_dir;
50937 struct compat_linux_dirent __user *previous;
50938+ struct file * file;
50939 int count;
50940 int error;
50941 };
50942@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
50943 buf->error = -EOVERFLOW;
50944 return -EOVERFLOW;
50945 }
50946+
50947+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50948+ return 0;
50949+
50950 dirent = buf->previous;
50951 if (dirent) {
50952 if (__put_user(offset, &dirent->d_off))
50953@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
50954 buf.previous = NULL;
50955 buf.count = count;
50956 buf.error = 0;
50957+ buf.file = f.file;
50958
50959 error = vfs_readdir(f.file, compat_filldir, &buf);
50960 if (error >= 0)
50961@@ -987,6 +999,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
50962 struct compat_getdents_callback64 {
50963 struct linux_dirent64 __user *current_dir;
50964 struct linux_dirent64 __user *previous;
50965+ struct file * file;
50966 int count;
50967 int error;
50968 };
50969@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
50970 buf->error = -EINVAL; /* only used if we fail.. */
50971 if (reclen > buf->count)
50972 return -EINVAL;
50973+
50974+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50975+ return 0;
50976+
50977 dirent = buf->previous;
50978
50979 if (dirent) {
50980@@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
50981 buf.previous = NULL;
50982 buf.count = count;
50983 buf.error = 0;
50984+ buf.file = f.file;
50985
50986 error = vfs_readdir(f.file, compat_filldir64, &buf);
50987 if (error >= 0)
50988 error = buf.error;
50989 lastdirent = buf.previous;
50990 if (lastdirent) {
50991- typeof(lastdirent->d_off) d_off = f.file->f_pos;
50992+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
50993 if (__put_user_unaligned(d_off, &lastdirent->d_off))
50994 error = -EFAULT;
50995 else
50996diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
50997index a81147e..20bf2b5 100644
50998--- a/fs/compat_binfmt_elf.c
50999+++ b/fs/compat_binfmt_elf.c
51000@@ -30,11 +30,13 @@
51001 #undef elf_phdr
51002 #undef elf_shdr
51003 #undef elf_note
51004+#undef elf_dyn
51005 #undef elf_addr_t
51006 #define elfhdr elf32_hdr
51007 #define elf_phdr elf32_phdr
51008 #define elf_shdr elf32_shdr
51009 #define elf_note elf32_note
51010+#define elf_dyn Elf32_Dyn
51011 #define elf_addr_t Elf32_Addr
51012
51013 /*
51014diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
51015index e2f57a0..3c78771 100644
51016--- a/fs/compat_ioctl.c
51017+++ b/fs/compat_ioctl.c
51018@@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
51019 return -EFAULT;
51020 if (__get_user(udata, &ss32->iomem_base))
51021 return -EFAULT;
51022- ss.iomem_base = compat_ptr(udata);
51023+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
51024 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
51025 __get_user(ss.port_high, &ss32->port_high))
51026 return -EFAULT;
51027@@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
51028 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
51029 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
51030 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
51031- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
51032+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
51033 return -EFAULT;
51034
51035 return ioctl_preallocate(file, p);
51036@@ -1620,8 +1620,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
51037 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
51038 {
51039 unsigned int a, b;
51040- a = *(unsigned int *)p;
51041- b = *(unsigned int *)q;
51042+ a = *(const unsigned int *)p;
51043+ b = *(const unsigned int *)q;
51044 if (a > b)
51045 return 1;
51046 if (a < b)
51047diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
51048index 712b10f..c33c4ca 100644
51049--- a/fs/configfs/dir.c
51050+++ b/fs/configfs/dir.c
51051@@ -1037,10 +1037,11 @@ static int configfs_dump(struct configfs_dirent *sd, int level)
51052 static int configfs_depend_prep(struct dentry *origin,
51053 struct config_item *target)
51054 {
51055- struct configfs_dirent *child_sd, *sd = origin->d_fsdata;
51056+ struct configfs_dirent *child_sd, *sd;
51057 int ret = 0;
51058
51059- BUG_ON(!origin || !sd);
51060+ BUG_ON(!origin || !origin->d_fsdata);
51061+ sd = origin->d_fsdata;
51062
51063 if (sd->s_element == target) /* Boo-yah */
51064 goto out;
51065@@ -1564,7 +1565,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
51066 }
51067 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
51068 struct configfs_dirent *next;
51069- const char * name;
51070+ const unsigned char * name;
51071+ char d_name[sizeof(next->s_dentry->d_iname)];
51072 int len;
51073 struct inode *inode = NULL;
51074
51075@@ -1574,7 +1576,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
51076 continue;
51077
51078 name = configfs_get_name(next);
51079- len = strlen(name);
51080+ if (next->s_dentry && name == next->s_dentry->d_iname) {
51081+ len = next->s_dentry->d_name.len;
51082+ memcpy(d_name, name, len);
51083+ name = d_name;
51084+ } else
51085+ len = strlen(name);
51086
51087 /*
51088 * We'll have a dentry and an inode for
51089diff --git a/fs/coredump.c b/fs/coredump.c
51090index 1774932..5812106 100644
51091--- a/fs/coredump.c
51092+++ b/fs/coredump.c
51093@@ -52,7 +52,7 @@ struct core_name {
51094 char *corename;
51095 int used, size;
51096 };
51097-static atomic_t call_count = ATOMIC_INIT(1);
51098+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
51099
51100 /* The maximal length of core_pattern is also specified in sysctl.c */
51101
51102@@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
51103 {
51104 char *old_corename = cn->corename;
51105
51106- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
51107+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
51108 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
51109
51110 if (!cn->corename) {
51111@@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
51112 int pid_in_pattern = 0;
51113 int err = 0;
51114
51115- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
51116+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
51117 cn->corename = kmalloc(cn->size, GFP_KERNEL);
51118 cn->used = 0;
51119
51120@@ -414,17 +414,17 @@ static void wait_for_dump_helpers(struct file *file)
51121 pipe = file->f_path.dentry->d_inode->i_pipe;
51122
51123 pipe_lock(pipe);
51124- pipe->readers++;
51125- pipe->writers--;
51126+ atomic_inc(&pipe->readers);
51127+ atomic_dec(&pipe->writers);
51128
51129- while ((pipe->readers > 1) && (!signal_pending(current))) {
51130+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
51131 wake_up_interruptible_sync(&pipe->wait);
51132 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
51133 pipe_wait(pipe);
51134 }
51135
51136- pipe->readers--;
51137- pipe->writers++;
51138+ atomic_dec(&pipe->readers);
51139+ atomic_inc(&pipe->writers);
51140 pipe_unlock(pipe);
51141
51142 }
51143@@ -471,7 +471,8 @@ void do_coredump(siginfo_t *siginfo)
51144 int ispipe;
51145 struct files_struct *displaced;
51146 bool need_nonrelative = false;
51147- static atomic_t core_dump_count = ATOMIC_INIT(0);
51148+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
51149+ long signr = siginfo->si_signo;
51150 struct coredump_params cprm = {
51151 .siginfo = siginfo,
51152 .regs = signal_pt_regs(),
51153@@ -484,7 +485,10 @@ void do_coredump(siginfo_t *siginfo)
51154 .mm_flags = mm->flags,
51155 };
51156
51157- audit_core_dumps(siginfo->si_signo);
51158+ audit_core_dumps(signr);
51159+
51160+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
51161+ gr_handle_brute_attach(cprm.mm_flags);
51162
51163 binfmt = mm->binfmt;
51164 if (!binfmt || !binfmt->core_dump)
51165@@ -508,7 +512,7 @@ void do_coredump(siginfo_t *siginfo)
51166 need_nonrelative = true;
51167 }
51168
51169- retval = coredump_wait(siginfo->si_signo, &core_state);
51170+ retval = coredump_wait(signr, &core_state);
51171 if (retval < 0)
51172 goto fail_creds;
51173
51174@@ -556,7 +560,7 @@ void do_coredump(siginfo_t *siginfo)
51175 }
51176 cprm.limit = RLIM_INFINITY;
51177
51178- dump_count = atomic_inc_return(&core_dump_count);
51179+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
51180 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
51181 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
51182 task_tgid_vnr(current), current->comm);
51183@@ -583,6 +587,8 @@ void do_coredump(siginfo_t *siginfo)
51184 } else {
51185 struct inode *inode;
51186
51187+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
51188+
51189 if (cprm.limit < binfmt->min_coredump)
51190 goto fail_unlock;
51191
51192@@ -640,7 +646,7 @@ close_fail:
51193 filp_close(cprm.file, NULL);
51194 fail_dropcount:
51195 if (ispipe)
51196- atomic_dec(&core_dump_count);
51197+ atomic_dec_unchecked(&core_dump_count);
51198 fail_unlock:
51199 kfree(cn.corename);
51200 fail_corename:
51201@@ -659,7 +665,7 @@ fail:
51202 */
51203 int dump_write(struct file *file, const void *addr, int nr)
51204 {
51205- return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
51206+ return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
51207 }
51208 EXPORT_SYMBOL(dump_write);
51209
51210diff --git a/fs/dcache.c b/fs/dcache.c
51211index c3bbf85..5b71101 100644
51212--- a/fs/dcache.c
51213+++ b/fs/dcache.c
51214@@ -3139,7 +3139,7 @@ void __init vfs_caches_init(unsigned long mempages)
51215 mempages -= reserve;
51216
51217 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
51218- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
51219+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
51220
51221 dcache_init();
51222 inode_init();
51223diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
51224index a5f12b7..4ee8a6f 100644
51225--- a/fs/debugfs/inode.c
51226+++ b/fs/debugfs/inode.c
51227@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
51228 */
51229 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
51230 {
51231+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
51232+ return __create_file(name, S_IFDIR | S_IRWXU,
51233+#else
51234 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
51235+#endif
51236 parent, NULL, NULL);
51237 }
51238 EXPORT_SYMBOL_GPL(debugfs_create_dir);
51239diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
51240index cc7709e..7e7211f 100644
51241--- a/fs/ecryptfs/inode.c
51242+++ b/fs/ecryptfs/inode.c
51243@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
51244 old_fs = get_fs();
51245 set_fs(get_ds());
51246 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
51247- (char __user *)lower_buf,
51248+ (char __force_user *)lower_buf,
51249 PATH_MAX);
51250 set_fs(old_fs);
51251 if (rc < 0)
51252@@ -706,7 +706,7 @@ out:
51253 static void
51254 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
51255 {
51256- char *buf = nd_get_link(nd);
51257+ const char *buf = nd_get_link(nd);
51258 if (!IS_ERR(buf)) {
51259 /* Free the char* */
51260 kfree(buf);
51261diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
51262index 412e6ed..d8263e8 100644
51263--- a/fs/ecryptfs/miscdev.c
51264+++ b/fs/ecryptfs/miscdev.c
51265@@ -80,13 +80,6 @@ ecryptfs_miscdev_open(struct inode *inode, struct file *file)
51266 int rc;
51267
51268 mutex_lock(&ecryptfs_daemon_hash_mux);
51269- rc = try_module_get(THIS_MODULE);
51270- if (rc == 0) {
51271- rc = -EIO;
51272- printk(KERN_ERR "%s: Error attempting to increment module use "
51273- "count; rc = [%d]\n", __func__, rc);
51274- goto out_unlock_daemon_list;
51275- }
51276 rc = ecryptfs_find_daemon_by_euid(&daemon);
51277 if (!rc) {
51278 rc = -EINVAL;
51279@@ -96,7 +89,7 @@ ecryptfs_miscdev_open(struct inode *inode, struct file *file)
51280 if (rc) {
51281 printk(KERN_ERR "%s: Error attempting to spawn daemon; "
51282 "rc = [%d]\n", __func__, rc);
51283- goto out_module_put_unlock_daemon_list;
51284+ goto out_unlock_daemon_list;
51285 }
51286 mutex_lock(&daemon->mux);
51287 if (daemon->flags & ECRYPTFS_DAEMON_MISCDEV_OPEN) {
51288@@ -108,9 +101,6 @@ ecryptfs_miscdev_open(struct inode *inode, struct file *file)
51289 atomic_inc(&ecryptfs_num_miscdev_opens);
51290 out_unlock_daemon:
51291 mutex_unlock(&daemon->mux);
51292-out_module_put_unlock_daemon_list:
51293- if (rc)
51294- module_put(THIS_MODULE);
51295 out_unlock_daemon_list:
51296 mutex_unlock(&ecryptfs_daemon_hash_mux);
51297 return rc;
51298@@ -147,7 +137,6 @@ ecryptfs_miscdev_release(struct inode *inode, struct file *file)
51299 "bug.\n", __func__, rc);
51300 BUG();
51301 }
51302- module_put(THIS_MODULE);
51303 return rc;
51304 }
51305
51306@@ -315,7 +304,7 @@ check_list:
51307 goto out_unlock_msg_ctx;
51308 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
51309 if (msg_ctx->msg) {
51310- if (copy_to_user(&buf[i], packet_length, packet_length_size))
51311+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
51312 goto out_unlock_msg_ctx;
51313 i += packet_length_size;
51314 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
51315@@ -471,6 +460,7 @@ out_free:
51316
51317
51318 static const struct file_operations ecryptfs_miscdev_fops = {
51319+ .owner = THIS_MODULE,
51320 .open = ecryptfs_miscdev_open,
51321 .poll = ecryptfs_miscdev_poll,
51322 .read = ecryptfs_miscdev_read,
51323diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
51324index b2a34a1..162fa69 100644
51325--- a/fs/ecryptfs/read_write.c
51326+++ b/fs/ecryptfs/read_write.c
51327@@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
51328 return -EIO;
51329 fs_save = get_fs();
51330 set_fs(get_ds());
51331- rc = vfs_write(lower_file, data, size, &offset);
51332+ rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
51333 set_fs(fs_save);
51334 mark_inode_dirty_sync(ecryptfs_inode);
51335 return rc;
51336@@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
51337 return -EIO;
51338 fs_save = get_fs();
51339 set_fs(get_ds());
51340- rc = vfs_read(lower_file, data, size, &offset);
51341+ rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
51342 set_fs(fs_save);
51343 return rc;
51344 }
51345diff --git a/fs/exec.c b/fs/exec.c
51346index 20df02c..9a87617 100644
51347--- a/fs/exec.c
51348+++ b/fs/exec.c
51349@@ -55,8 +55,20 @@
51350 #include <linux/pipe_fs_i.h>
51351 #include <linux/oom.h>
51352 #include <linux/compat.h>
51353+#include <linux/random.h>
51354+#include <linux/seq_file.h>
51355+#include <linux/coredump.h>
51356+#include <linux/mman.h>
51357+
51358+#ifdef CONFIG_PAX_REFCOUNT
51359+#include <linux/kallsyms.h>
51360+#include <linux/kdebug.h>
51361+#endif
51362+
51363+#include <trace/events/fs.h>
51364
51365 #include <asm/uaccess.h>
51366+#include <asm/sections.h>
51367 #include <asm/mmu_context.h>
51368 #include <asm/tlb.h>
51369
51370@@ -66,6 +78,18 @@
51371
51372 #include <trace/events/sched.h>
51373
51374+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
51375+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
51376+{
51377+ 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");
51378+}
51379+#endif
51380+
51381+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
51382+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
51383+EXPORT_SYMBOL(pax_set_initial_flags_func);
51384+#endif
51385+
51386 int suid_dumpable = 0;
51387
51388 static LIST_HEAD(formats);
51389@@ -75,8 +99,8 @@ void __register_binfmt(struct linux_binfmt * fmt, int insert)
51390 {
51391 BUG_ON(!fmt);
51392 write_lock(&binfmt_lock);
51393- insert ? list_add(&fmt->lh, &formats) :
51394- list_add_tail(&fmt->lh, &formats);
51395+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
51396+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
51397 write_unlock(&binfmt_lock);
51398 }
51399
51400@@ -85,7 +109,7 @@ EXPORT_SYMBOL(__register_binfmt);
51401 void unregister_binfmt(struct linux_binfmt * fmt)
51402 {
51403 write_lock(&binfmt_lock);
51404- list_del(&fmt->lh);
51405+ pax_list_del((struct list_head *)&fmt->lh);
51406 write_unlock(&binfmt_lock);
51407 }
51408
51409@@ -180,18 +204,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
51410 int write)
51411 {
51412 struct page *page;
51413- int ret;
51414
51415-#ifdef CONFIG_STACK_GROWSUP
51416- if (write) {
51417- ret = expand_downwards(bprm->vma, pos);
51418- if (ret < 0)
51419- return NULL;
51420- }
51421-#endif
51422- ret = get_user_pages(current, bprm->mm, pos,
51423- 1, write, 1, &page, NULL);
51424- if (ret <= 0)
51425+ if (0 > expand_downwards(bprm->vma, pos))
51426+ return NULL;
51427+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
51428 return NULL;
51429
51430 if (write) {
51431@@ -207,6 +223,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
51432 if (size <= ARG_MAX)
51433 return page;
51434
51435+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51436+ // only allow 512KB for argv+env on suid/sgid binaries
51437+ // to prevent easy ASLR exhaustion
51438+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
51439+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
51440+ (size > (512 * 1024))) {
51441+ put_page(page);
51442+ return NULL;
51443+ }
51444+#endif
51445+
51446 /*
51447 * Limit to 1/4-th the stack size for the argv+env strings.
51448 * This ensures that:
51449@@ -266,6 +293,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
51450 vma->vm_end = STACK_TOP_MAX;
51451 vma->vm_start = vma->vm_end - PAGE_SIZE;
51452 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
51453+
51454+#ifdef CONFIG_PAX_SEGMEXEC
51455+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
51456+#endif
51457+
51458 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
51459 INIT_LIST_HEAD(&vma->anon_vma_chain);
51460
51461@@ -276,6 +308,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
51462 mm->stack_vm = mm->total_vm = 1;
51463 up_write(&mm->mmap_sem);
51464 bprm->p = vma->vm_end - sizeof(void *);
51465+
51466+#ifdef CONFIG_PAX_RANDUSTACK
51467+ if (randomize_va_space)
51468+ bprm->p ^= random32() & ~PAGE_MASK;
51469+#endif
51470+
51471 return 0;
51472 err:
51473 up_write(&mm->mmap_sem);
51474@@ -396,7 +434,7 @@ struct user_arg_ptr {
51475 } ptr;
51476 };
51477
51478-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
51479+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
51480 {
51481 const char __user *native;
51482
51483@@ -405,14 +443,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
51484 compat_uptr_t compat;
51485
51486 if (get_user(compat, argv.ptr.compat + nr))
51487- return ERR_PTR(-EFAULT);
51488+ return (const char __force_user *)ERR_PTR(-EFAULT);
51489
51490 return compat_ptr(compat);
51491 }
51492 #endif
51493
51494 if (get_user(native, argv.ptr.native + nr))
51495- return ERR_PTR(-EFAULT);
51496+ return (const char __force_user *)ERR_PTR(-EFAULT);
51497
51498 return native;
51499 }
51500@@ -431,7 +469,7 @@ static int count(struct user_arg_ptr argv, int max)
51501 if (!p)
51502 break;
51503
51504- if (IS_ERR(p))
51505+ if (IS_ERR((const char __force_kernel *)p))
51506 return -EFAULT;
51507
51508 if (i >= max)
51509@@ -466,7 +504,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
51510
51511 ret = -EFAULT;
51512 str = get_user_arg_ptr(argv, argc);
51513- if (IS_ERR(str))
51514+ if (IS_ERR((const char __force_kernel *)str))
51515 goto out;
51516
51517 len = strnlen_user(str, MAX_ARG_STRLEN);
51518@@ -548,7 +586,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
51519 int r;
51520 mm_segment_t oldfs = get_fs();
51521 struct user_arg_ptr argv = {
51522- .ptr.native = (const char __user *const __user *)__argv,
51523+ .ptr.native = (const char __force_user *const __force_user *)__argv,
51524 };
51525
51526 set_fs(KERNEL_DS);
51527@@ -583,7 +621,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
51528 unsigned long new_end = old_end - shift;
51529 struct mmu_gather tlb;
51530
51531- BUG_ON(new_start > new_end);
51532+ if (new_start >= new_end || new_start < mmap_min_addr)
51533+ return -ENOMEM;
51534
51535 /*
51536 * ensure there are no vmas between where we want to go
51537@@ -592,6 +631,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
51538 if (vma != find_vma(mm, new_start))
51539 return -EFAULT;
51540
51541+#ifdef CONFIG_PAX_SEGMEXEC
51542+ BUG_ON(pax_find_mirror_vma(vma));
51543+#endif
51544+
51545 /*
51546 * cover the whole range: [new_start, old_end)
51547 */
51548@@ -672,10 +715,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
51549 stack_top = arch_align_stack(stack_top);
51550 stack_top = PAGE_ALIGN(stack_top);
51551
51552- if (unlikely(stack_top < mmap_min_addr) ||
51553- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
51554- return -ENOMEM;
51555-
51556 stack_shift = vma->vm_end - stack_top;
51557
51558 bprm->p -= stack_shift;
51559@@ -687,8 +726,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
51560 bprm->exec -= stack_shift;
51561
51562 down_write(&mm->mmap_sem);
51563+
51564+ /* Move stack pages down in memory. */
51565+ if (stack_shift) {
51566+ ret = shift_arg_pages(vma, stack_shift);
51567+ if (ret)
51568+ goto out_unlock;
51569+ }
51570+
51571 vm_flags = VM_STACK_FLAGS;
51572
51573+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
51574+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
51575+ vm_flags &= ~VM_EXEC;
51576+
51577+#ifdef CONFIG_PAX_MPROTECT
51578+ if (mm->pax_flags & MF_PAX_MPROTECT)
51579+ vm_flags &= ~VM_MAYEXEC;
51580+#endif
51581+
51582+ }
51583+#endif
51584+
51585 /*
51586 * Adjust stack execute permissions; explicitly enable for
51587 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
51588@@ -707,13 +766,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
51589 goto out_unlock;
51590 BUG_ON(prev != vma);
51591
51592- /* Move stack pages down in memory. */
51593- if (stack_shift) {
51594- ret = shift_arg_pages(vma, stack_shift);
51595- if (ret)
51596- goto out_unlock;
51597- }
51598-
51599 /* mprotect_fixup is overkill to remove the temporary stack flags */
51600 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
51601
51602@@ -737,6 +789,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
51603 #endif
51604 current->mm->start_stack = bprm->p;
51605 ret = expand_stack(vma, stack_base);
51606+
51607+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
51608+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
51609+ unsigned long size, flags, vm_flags;
51610+
51611+ size = STACK_TOP - vma->vm_end;
51612+ flags = MAP_FIXED | MAP_PRIVATE;
51613+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
51614+
51615+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, flags, vm_flags, 0);
51616+
51617+#ifdef CONFIG_X86
51618+ if (!ret) {
51619+ size = mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
51620+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), flags, vm_flags, 0);
51621+ }
51622+#endif
51623+
51624+ }
51625+#endif
51626+
51627 if (ret)
51628 ret = -EFAULT;
51629
51630@@ -772,6 +845,8 @@ struct file *open_exec(const char *name)
51631
51632 fsnotify_open(file);
51633
51634+ trace_open_exec(name);
51635+
51636 err = deny_write_access(file);
51637 if (err)
51638 goto exit;
51639@@ -795,7 +870,7 @@ int kernel_read(struct file *file, loff_t offset,
51640 old_fs = get_fs();
51641 set_fs(get_ds());
51642 /* The cast to a user pointer is valid due to the set_fs() */
51643- result = vfs_read(file, (void __user *)addr, count, &pos);
51644+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
51645 set_fs(old_fs);
51646 return result;
51647 }
51648@@ -1247,7 +1322,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
51649 }
51650 rcu_read_unlock();
51651
51652- if (p->fs->users > n_fs) {
51653+ if (atomic_read(&p->fs->users) > n_fs) {
51654 bprm->unsafe |= LSM_UNSAFE_SHARE;
51655 } else {
51656 res = -EAGAIN;
51657@@ -1447,6 +1522,31 @@ int search_binary_handler(struct linux_binprm *bprm)
51658
51659 EXPORT_SYMBOL(search_binary_handler);
51660
51661+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51662+static DEFINE_PER_CPU(u64, exec_counter);
51663+static int __init init_exec_counters(void)
51664+{
51665+ unsigned int cpu;
51666+
51667+ for_each_possible_cpu(cpu) {
51668+ per_cpu(exec_counter, cpu) = (u64)cpu;
51669+ }
51670+
51671+ return 0;
51672+}
51673+early_initcall(init_exec_counters);
51674+static inline void increment_exec_counter(void)
51675+{
51676+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
51677+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
51678+}
51679+#else
51680+static inline void increment_exec_counter(void) {}
51681+#endif
51682+
51683+extern void gr_handle_exec_args(struct linux_binprm *bprm,
51684+ struct user_arg_ptr argv);
51685+
51686 /*
51687 * sys_execve() executes a new program.
51688 */
51689@@ -1454,6 +1554,11 @@ static int do_execve_common(const char *filename,
51690 struct user_arg_ptr argv,
51691 struct user_arg_ptr envp)
51692 {
51693+#ifdef CONFIG_GRKERNSEC
51694+ struct file *old_exec_file;
51695+ struct acl_subject_label *old_acl;
51696+ struct rlimit old_rlim[RLIM_NLIMITS];
51697+#endif
51698 struct linux_binprm *bprm;
51699 struct file *file;
51700 struct files_struct *displaced;
51701@@ -1461,6 +1566,8 @@ static int do_execve_common(const char *filename,
51702 int retval;
51703 const struct cred *cred = current_cred();
51704
51705+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
51706+
51707 /*
51708 * We move the actual failure in case of RLIMIT_NPROC excess from
51709 * set*uid() to execve() because too many poorly written programs
51710@@ -1501,12 +1608,27 @@ static int do_execve_common(const char *filename,
51711 if (IS_ERR(file))
51712 goto out_unmark;
51713
51714+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
51715+ retval = -EPERM;
51716+ goto out_file;
51717+ }
51718+
51719 sched_exec();
51720
51721 bprm->file = file;
51722 bprm->filename = filename;
51723 bprm->interp = filename;
51724
51725+ if (gr_process_user_ban()) {
51726+ retval = -EPERM;
51727+ goto out_file;
51728+ }
51729+
51730+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
51731+ retval = -EACCES;
51732+ goto out_file;
51733+ }
51734+
51735 retval = bprm_mm_init(bprm);
51736 if (retval)
51737 goto out_file;
51738@@ -1523,24 +1645,65 @@ static int do_execve_common(const char *filename,
51739 if (retval < 0)
51740 goto out;
51741
51742+#ifdef CONFIG_GRKERNSEC
51743+ old_acl = current->acl;
51744+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
51745+ old_exec_file = current->exec_file;
51746+ get_file(file);
51747+ current->exec_file = file;
51748+#endif
51749+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51750+ /* limit suid stack to 8MB
51751+ * we saved the old limits above and will restore them if this exec fails
51752+ */
51753+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
51754+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
51755+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
51756+#endif
51757+
51758+ if (!gr_tpe_allow(file)) {
51759+ retval = -EACCES;
51760+ goto out_fail;
51761+ }
51762+
51763+ if (gr_check_crash_exec(file)) {
51764+ retval = -EACCES;
51765+ goto out_fail;
51766+ }
51767+
51768+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
51769+ bprm->unsafe);
51770+ if (retval < 0)
51771+ goto out_fail;
51772+
51773 retval = copy_strings_kernel(1, &bprm->filename, bprm);
51774 if (retval < 0)
51775- goto out;
51776+ goto out_fail;
51777
51778 bprm->exec = bprm->p;
51779 retval = copy_strings(bprm->envc, envp, bprm);
51780 if (retval < 0)
51781- goto out;
51782+ goto out_fail;
51783
51784 retval = copy_strings(bprm->argc, argv, bprm);
51785 if (retval < 0)
51786- goto out;
51787+ goto out_fail;
51788+
51789+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
51790+
51791+ gr_handle_exec_args(bprm, argv);
51792
51793 retval = search_binary_handler(bprm);
51794 if (retval < 0)
51795- goto out;
51796+ goto out_fail;
51797+#ifdef CONFIG_GRKERNSEC
51798+ if (old_exec_file)
51799+ fput(old_exec_file);
51800+#endif
51801
51802 /* execve succeeded */
51803+
51804+ increment_exec_counter();
51805 current->fs->in_exec = 0;
51806 current->in_execve = 0;
51807 acct_update_integrals(current);
51808@@ -1549,6 +1712,14 @@ static int do_execve_common(const char *filename,
51809 put_files_struct(displaced);
51810 return retval;
51811
51812+out_fail:
51813+#ifdef CONFIG_GRKERNSEC
51814+ current->acl = old_acl;
51815+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
51816+ fput(current->exec_file);
51817+ current->exec_file = old_exec_file;
51818+#endif
51819+
51820 out:
51821 if (bprm->mm) {
51822 acct_arg_size(bprm, 0);
51823@@ -1697,3 +1868,278 @@ asmlinkage long compat_sys_execve(const char __user * filename,
51824 return error;
51825 }
51826 #endif
51827+
51828+int pax_check_flags(unsigned long *flags)
51829+{
51830+ int retval = 0;
51831+
51832+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
51833+ if (*flags & MF_PAX_SEGMEXEC)
51834+ {
51835+ *flags &= ~MF_PAX_SEGMEXEC;
51836+ retval = -EINVAL;
51837+ }
51838+#endif
51839+
51840+ if ((*flags & MF_PAX_PAGEEXEC)
51841+
51842+#ifdef CONFIG_PAX_PAGEEXEC
51843+ && (*flags & MF_PAX_SEGMEXEC)
51844+#endif
51845+
51846+ )
51847+ {
51848+ *flags &= ~MF_PAX_PAGEEXEC;
51849+ retval = -EINVAL;
51850+ }
51851+
51852+ if ((*flags & MF_PAX_MPROTECT)
51853+
51854+#ifdef CONFIG_PAX_MPROTECT
51855+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
51856+#endif
51857+
51858+ )
51859+ {
51860+ *flags &= ~MF_PAX_MPROTECT;
51861+ retval = -EINVAL;
51862+ }
51863+
51864+ if ((*flags & MF_PAX_EMUTRAMP)
51865+
51866+#ifdef CONFIG_PAX_EMUTRAMP
51867+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
51868+#endif
51869+
51870+ )
51871+ {
51872+ *flags &= ~MF_PAX_EMUTRAMP;
51873+ retval = -EINVAL;
51874+ }
51875+
51876+ return retval;
51877+}
51878+
51879+EXPORT_SYMBOL(pax_check_flags);
51880+
51881+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
51882+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
51883+{
51884+ struct task_struct *tsk = current;
51885+ struct mm_struct *mm = current->mm;
51886+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
51887+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
51888+ char *path_exec = NULL;
51889+ char *path_fault = NULL;
51890+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
51891+ siginfo_t info = { };
51892+
51893+ if (buffer_exec && buffer_fault) {
51894+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
51895+
51896+ down_read(&mm->mmap_sem);
51897+ vma = mm->mmap;
51898+ while (vma && (!vma_exec || !vma_fault)) {
51899+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
51900+ vma_exec = vma;
51901+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
51902+ vma_fault = vma;
51903+ vma = vma->vm_next;
51904+ }
51905+ if (vma_exec) {
51906+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
51907+ if (IS_ERR(path_exec))
51908+ path_exec = "<path too long>";
51909+ else {
51910+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
51911+ if (path_exec) {
51912+ *path_exec = 0;
51913+ path_exec = buffer_exec;
51914+ } else
51915+ path_exec = "<path too long>";
51916+ }
51917+ }
51918+ if (vma_fault) {
51919+ start = vma_fault->vm_start;
51920+ end = vma_fault->vm_end;
51921+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
51922+ if (vma_fault->vm_file) {
51923+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
51924+ if (IS_ERR(path_fault))
51925+ path_fault = "<path too long>";
51926+ else {
51927+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
51928+ if (path_fault) {
51929+ *path_fault = 0;
51930+ path_fault = buffer_fault;
51931+ } else
51932+ path_fault = "<path too long>";
51933+ }
51934+ } else
51935+ path_fault = "<anonymous mapping>";
51936+ }
51937+ up_read(&mm->mmap_sem);
51938+ }
51939+ if (tsk->signal->curr_ip)
51940+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
51941+ else
51942+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
51943+ 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),
51944+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
51945+ free_page((unsigned long)buffer_exec);
51946+ free_page((unsigned long)buffer_fault);
51947+ pax_report_insns(regs, pc, sp);
51948+ info.si_signo = SIGKILL;
51949+ info.si_errno = 0;
51950+ info.si_code = SI_KERNEL;
51951+ info.si_pid = 0;
51952+ info.si_uid = 0;
51953+ do_coredump(&info);
51954+}
51955+#endif
51956+
51957+#ifdef CONFIG_PAX_REFCOUNT
51958+void pax_report_refcount_overflow(struct pt_regs *regs)
51959+{
51960+ if (current->signal->curr_ip)
51961+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
51962+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
51963+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
51964+ else
51965+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
51966+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
51967+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
51968+ show_regs(regs);
51969+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
51970+}
51971+#endif
51972+
51973+#ifdef CONFIG_PAX_USERCOPY
51974+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
51975+static noinline int check_stack_object(const void *obj, unsigned long len)
51976+{
51977+ const void * const stack = task_stack_page(current);
51978+ const void * const stackend = stack + THREAD_SIZE;
51979+
51980+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
51981+ const void *frame = NULL;
51982+ const void *oldframe;
51983+#endif
51984+
51985+ if (obj + len < obj)
51986+ return -1;
51987+
51988+ if (obj + len <= stack || stackend <= obj)
51989+ return 0;
51990+
51991+ if (obj < stack || stackend < obj + len)
51992+ return -1;
51993+
51994+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
51995+ oldframe = __builtin_frame_address(1);
51996+ if (oldframe)
51997+ frame = __builtin_frame_address(2);
51998+ /*
51999+ low ----------------------------------------------> high
52000+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
52001+ ^----------------^
52002+ allow copies only within here
52003+ */
52004+ while (stack <= frame && frame < stackend) {
52005+ /* if obj + len extends past the last frame, this
52006+ check won't pass and the next frame will be 0,
52007+ causing us to bail out and correctly report
52008+ the copy as invalid
52009+ */
52010+ if (obj + len <= frame)
52011+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
52012+ oldframe = frame;
52013+ frame = *(const void * const *)frame;
52014+ }
52015+ return -1;
52016+#else
52017+ return 1;
52018+#endif
52019+}
52020+
52021+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
52022+{
52023+ if (current->signal->curr_ip)
52024+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
52025+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
52026+ else
52027+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
52028+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
52029+ dump_stack();
52030+ gr_handle_kernel_exploit();
52031+ do_group_exit(SIGKILL);
52032+}
52033+#endif
52034+
52035+#ifdef CONFIG_PAX_USERCOPY
52036+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
52037+{
52038+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
52039+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
52040+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
52041+#else
52042+ unsigned long textlow = _stext;
52043+ unsigned long texthigh = _etext;
52044+#endif
52045+
52046+ if (high < textlow || low > texthigh)
52047+ return false;
52048+ else
52049+ return true;
52050+}
52051+#endif
52052+
52053+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
52054+{
52055+
52056+#ifdef CONFIG_PAX_USERCOPY
52057+ const char *type;
52058+
52059+ if (!n)
52060+ return;
52061+
52062+ type = check_heap_object(ptr, n);
52063+ if (!type) {
52064+ int ret = check_stack_object(ptr, n);
52065+ if (ret == 1 || ret == 2)
52066+ return;
52067+ if (ret == 0) {
52068+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
52069+ type = "<kernel text>";
52070+ else
52071+ return;
52072+ } else
52073+ type = "<process stack>";
52074+ }
52075+
52076+ pax_report_usercopy(ptr, n, to_user, type);
52077+#endif
52078+
52079+}
52080+EXPORT_SYMBOL(__check_object_size);
52081+
52082+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
52083+void pax_track_stack(void)
52084+{
52085+ unsigned long sp = (unsigned long)&sp;
52086+ if (sp < current_thread_info()->lowest_stack &&
52087+ sp > (unsigned long)task_stack_page(current))
52088+ current_thread_info()->lowest_stack = sp;
52089+}
52090+EXPORT_SYMBOL(pax_track_stack);
52091+#endif
52092+
52093+#ifdef CONFIG_PAX_SIZE_OVERFLOW
52094+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
52095+{
52096+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
52097+ dump_stack();
52098+ do_group_exit(SIGKILL);
52099+}
52100+EXPORT_SYMBOL(report_size_overflow);
52101+#endif
52102diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
52103index 2616d0e..2ffdec9 100644
52104--- a/fs/ext2/balloc.c
52105+++ b/fs/ext2/balloc.c
52106@@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
52107
52108 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
52109 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
52110- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
52111+ if (free_blocks < root_blocks + 1 &&
52112 !uid_eq(sbi->s_resuid, current_fsuid()) &&
52113 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
52114- !in_group_p (sbi->s_resgid))) {
52115+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
52116 return 0;
52117 }
52118 return 1;
52119diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
52120index 22548f5..41521d8 100644
52121--- a/fs/ext3/balloc.c
52122+++ b/fs/ext3/balloc.c
52123@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
52124
52125 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
52126 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
52127- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
52128+ if (free_blocks < root_blocks + 1 &&
52129 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
52130 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
52131- !in_group_p (sbi->s_resgid))) {
52132+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
52133 return 0;
52134 }
52135 return 1;
52136diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
52137index 92e68b3..115d987 100644
52138--- a/fs/ext4/balloc.c
52139+++ b/fs/ext4/balloc.c
52140@@ -505,8 +505,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
52141 /* Hm, nope. Are (enough) root reserved clusters available? */
52142 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
52143 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
52144- capable(CAP_SYS_RESOURCE) ||
52145- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
52146+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
52147+ capable_nolog(CAP_SYS_RESOURCE)) {
52148
52149 if (free_clusters >= (nclusters + dirty_clusters))
52150 return 1;
52151diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
52152index bbcd6a0..2824592 100644
52153--- a/fs/ext4/ext4.h
52154+++ b/fs/ext4/ext4.h
52155@@ -1265,19 +1265,19 @@ struct ext4_sb_info {
52156 unsigned long s_mb_last_start;
52157
52158 /* stats for buddy allocator */
52159- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
52160- atomic_t s_bal_success; /* we found long enough chunks */
52161- atomic_t s_bal_allocated; /* in blocks */
52162- atomic_t s_bal_ex_scanned; /* total extents scanned */
52163- atomic_t s_bal_goals; /* goal hits */
52164- atomic_t s_bal_breaks; /* too long searches */
52165- atomic_t s_bal_2orders; /* 2^order hits */
52166+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
52167+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
52168+ atomic_unchecked_t s_bal_allocated; /* in blocks */
52169+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
52170+ atomic_unchecked_t s_bal_goals; /* goal hits */
52171+ atomic_unchecked_t s_bal_breaks; /* too long searches */
52172+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
52173 spinlock_t s_bal_lock;
52174 unsigned long s_mb_buddies_generated;
52175 unsigned long long s_mb_generation_time;
52176- atomic_t s_mb_lost_chunks;
52177- atomic_t s_mb_preallocated;
52178- atomic_t s_mb_discarded;
52179+ atomic_unchecked_t s_mb_lost_chunks;
52180+ atomic_unchecked_t s_mb_preallocated;
52181+ atomic_unchecked_t s_mb_discarded;
52182 atomic_t s_lock_busy;
52183
52184 /* locality groups */
52185diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
52186index 82f8c2d..ce7c889 100644
52187--- a/fs/ext4/mballoc.c
52188+++ b/fs/ext4/mballoc.c
52189@@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
52190 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
52191
52192 if (EXT4_SB(sb)->s_mb_stats)
52193- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
52194+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
52195
52196 break;
52197 }
52198@@ -2044,7 +2044,7 @@ repeat:
52199 ac->ac_status = AC_STATUS_CONTINUE;
52200 ac->ac_flags |= EXT4_MB_HINT_FIRST;
52201 cr = 3;
52202- atomic_inc(&sbi->s_mb_lost_chunks);
52203+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
52204 goto repeat;
52205 }
52206 }
52207@@ -2552,25 +2552,25 @@ int ext4_mb_release(struct super_block *sb)
52208 if (sbi->s_mb_stats) {
52209 ext4_msg(sb, KERN_INFO,
52210 "mballoc: %u blocks %u reqs (%u success)",
52211- atomic_read(&sbi->s_bal_allocated),
52212- atomic_read(&sbi->s_bal_reqs),
52213- atomic_read(&sbi->s_bal_success));
52214+ atomic_read_unchecked(&sbi->s_bal_allocated),
52215+ atomic_read_unchecked(&sbi->s_bal_reqs),
52216+ atomic_read_unchecked(&sbi->s_bal_success));
52217 ext4_msg(sb, KERN_INFO,
52218 "mballoc: %u extents scanned, %u goal hits, "
52219 "%u 2^N hits, %u breaks, %u lost",
52220- atomic_read(&sbi->s_bal_ex_scanned),
52221- atomic_read(&sbi->s_bal_goals),
52222- atomic_read(&sbi->s_bal_2orders),
52223- atomic_read(&sbi->s_bal_breaks),
52224- atomic_read(&sbi->s_mb_lost_chunks));
52225+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
52226+ atomic_read_unchecked(&sbi->s_bal_goals),
52227+ atomic_read_unchecked(&sbi->s_bal_2orders),
52228+ atomic_read_unchecked(&sbi->s_bal_breaks),
52229+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
52230 ext4_msg(sb, KERN_INFO,
52231 "mballoc: %lu generated and it took %Lu",
52232 sbi->s_mb_buddies_generated,
52233 sbi->s_mb_generation_time);
52234 ext4_msg(sb, KERN_INFO,
52235 "mballoc: %u preallocated, %u discarded",
52236- atomic_read(&sbi->s_mb_preallocated),
52237- atomic_read(&sbi->s_mb_discarded));
52238+ atomic_read_unchecked(&sbi->s_mb_preallocated),
52239+ atomic_read_unchecked(&sbi->s_mb_discarded));
52240 }
52241
52242 free_percpu(sbi->s_locality_groups);
52243@@ -3060,16 +3060,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
52244 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
52245
52246 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
52247- atomic_inc(&sbi->s_bal_reqs);
52248- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
52249+ atomic_inc_unchecked(&sbi->s_bal_reqs);
52250+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
52251 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
52252- atomic_inc(&sbi->s_bal_success);
52253- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
52254+ atomic_inc_unchecked(&sbi->s_bal_success);
52255+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
52256 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
52257 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
52258- atomic_inc(&sbi->s_bal_goals);
52259+ atomic_inc_unchecked(&sbi->s_bal_goals);
52260 if (ac->ac_found > sbi->s_mb_max_to_scan)
52261- atomic_inc(&sbi->s_bal_breaks);
52262+ atomic_inc_unchecked(&sbi->s_bal_breaks);
52263 }
52264
52265 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
52266@@ -3469,7 +3469,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
52267 trace_ext4_mb_new_inode_pa(ac, pa);
52268
52269 ext4_mb_use_inode_pa(ac, pa);
52270- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
52271+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
52272
52273 ei = EXT4_I(ac->ac_inode);
52274 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
52275@@ -3529,7 +3529,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
52276 trace_ext4_mb_new_group_pa(ac, pa);
52277
52278 ext4_mb_use_group_pa(ac, pa);
52279- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
52280+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
52281
52282 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
52283 lg = ac->ac_lg;
52284@@ -3618,7 +3618,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
52285 * from the bitmap and continue.
52286 */
52287 }
52288- atomic_add(free, &sbi->s_mb_discarded);
52289+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
52290
52291 return err;
52292 }
52293@@ -3636,7 +3636,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
52294 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
52295 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
52296 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
52297- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
52298+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
52299 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
52300
52301 return 0;
52302diff --git a/fs/ext4/super.c b/fs/ext4/super.c
52303index 24c767d..893aa55 100644
52304--- a/fs/ext4/super.c
52305+++ b/fs/ext4/super.c
52306@@ -2429,7 +2429,7 @@ struct ext4_attr {
52307 ssize_t (*store)(struct ext4_attr *, struct ext4_sb_info *,
52308 const char *, size_t);
52309 int offset;
52310-};
52311+} __do_const;
52312
52313 static int parse_strtoul(const char *buf,
52314 unsigned long max, unsigned long *value)
52315diff --git a/fs/fcntl.c b/fs/fcntl.c
52316index 71a600a..20d87b1 100644
52317--- a/fs/fcntl.c
52318+++ b/fs/fcntl.c
52319@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
52320 if (err)
52321 return err;
52322
52323+ if (gr_handle_chroot_fowner(pid, type))
52324+ return -ENOENT;
52325+ if (gr_check_protected_task_fowner(pid, type))
52326+ return -EACCES;
52327+
52328 f_modown(filp, pid, type, force);
52329 return 0;
52330 }
52331diff --git a/fs/fhandle.c b/fs/fhandle.c
52332index 999ff5c..41f4109 100644
52333--- a/fs/fhandle.c
52334+++ b/fs/fhandle.c
52335@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
52336 } else
52337 retval = 0;
52338 /* copy the mount id */
52339- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
52340- sizeof(*mnt_id)) ||
52341+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
52342 copy_to_user(ufh, handle,
52343 sizeof(struct file_handle) + handle_bytes))
52344 retval = -EFAULT;
52345diff --git a/fs/fifo.c b/fs/fifo.c
52346index cf6f434..3d7942c 100644
52347--- a/fs/fifo.c
52348+++ b/fs/fifo.c
52349@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
52350 */
52351 filp->f_op = &read_pipefifo_fops;
52352 pipe->r_counter++;
52353- if (pipe->readers++ == 0)
52354+ if (atomic_inc_return(&pipe->readers) == 1)
52355 wake_up_partner(inode);
52356
52357- if (!pipe->writers) {
52358+ if (!atomic_read(&pipe->writers)) {
52359 if ((filp->f_flags & O_NONBLOCK)) {
52360 /* suppress POLLHUP until we have
52361 * seen a writer */
52362@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
52363 * errno=ENXIO when there is no process reading the FIFO.
52364 */
52365 ret = -ENXIO;
52366- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
52367+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
52368 goto err;
52369
52370 filp->f_op = &write_pipefifo_fops;
52371 pipe->w_counter++;
52372- if (!pipe->writers++)
52373+ if (atomic_inc_return(&pipe->writers) == 1)
52374 wake_up_partner(inode);
52375
52376- if (!pipe->readers) {
52377+ if (!atomic_read(&pipe->readers)) {
52378 if (wait_for_partner(inode, &pipe->r_counter))
52379 goto err_wr;
52380 }
52381@@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
52382 */
52383 filp->f_op = &rdwr_pipefifo_fops;
52384
52385- pipe->readers++;
52386- pipe->writers++;
52387+ atomic_inc(&pipe->readers);
52388+ atomic_inc(&pipe->writers);
52389 pipe->r_counter++;
52390 pipe->w_counter++;
52391- if (pipe->readers == 1 || pipe->writers == 1)
52392+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
52393 wake_up_partner(inode);
52394 break;
52395
52396@@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
52397 return 0;
52398
52399 err_rd:
52400- if (!--pipe->readers)
52401+ if (atomic_dec_and_test(&pipe->readers))
52402 wake_up_interruptible(&pipe->wait);
52403 ret = -ERESTARTSYS;
52404 goto err;
52405
52406 err_wr:
52407- if (!--pipe->writers)
52408+ if (atomic_dec_and_test(&pipe->writers))
52409 wake_up_interruptible(&pipe->wait);
52410 ret = -ERESTARTSYS;
52411 goto err;
52412
52413 err:
52414- if (!pipe->readers && !pipe->writers)
52415+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
52416 free_pipe_info(inode);
52417
52418 err_nocleanup:
52419diff --git a/fs/file.c b/fs/file.c
52420index 2b3570b..c57924b 100644
52421--- a/fs/file.c
52422+++ b/fs/file.c
52423@@ -16,6 +16,7 @@
52424 #include <linux/slab.h>
52425 #include <linux/vmalloc.h>
52426 #include <linux/file.h>
52427+#include <linux/security.h>
52428 #include <linux/fdtable.h>
52429 #include <linux/bitops.h>
52430 #include <linux/interrupt.h>
52431@@ -892,6 +893,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
52432 if (!file)
52433 return __close_fd(files, fd);
52434
52435+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
52436 if (fd >= rlimit(RLIMIT_NOFILE))
52437 return -EBADF;
52438
52439@@ -918,6 +920,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
52440 if (unlikely(oldfd == newfd))
52441 return -EINVAL;
52442
52443+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
52444 if (newfd >= rlimit(RLIMIT_NOFILE))
52445 return -EBADF;
52446
52447@@ -973,6 +976,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
52448 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
52449 {
52450 int err;
52451+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
52452 if (from >= rlimit(RLIMIT_NOFILE))
52453 return -EINVAL;
52454 err = alloc_fd(from, flags);
52455diff --git a/fs/filesystems.c b/fs/filesystems.c
52456index da165f6..3671bdb 100644
52457--- a/fs/filesystems.c
52458+++ b/fs/filesystems.c
52459@@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
52460 int len = dot ? dot - name : strlen(name);
52461
52462 fs = __get_fs_type(name, len);
52463+
52464+#ifdef CONFIG_GRKERNSEC_MODHARDEN
52465+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
52466+#else
52467 if (!fs && (request_module("%.*s", len, name) == 0))
52468+#endif
52469 fs = __get_fs_type(name, len);
52470
52471 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
52472diff --git a/fs/fs_struct.c b/fs/fs_struct.c
52473index fe6ca58..65318cf 100644
52474--- a/fs/fs_struct.c
52475+++ b/fs/fs_struct.c
52476@@ -4,6 +4,7 @@
52477 #include <linux/path.h>
52478 #include <linux/slab.h>
52479 #include <linux/fs_struct.h>
52480+#include <linux/grsecurity.h>
52481 #include "internal.h"
52482
52483 /*
52484@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
52485 write_seqcount_begin(&fs->seq);
52486 old_root = fs->root;
52487 fs->root = *path;
52488+ gr_set_chroot_entries(current, path);
52489 write_seqcount_end(&fs->seq);
52490 spin_unlock(&fs->lock);
52491 if (old_root.dentry)
52492@@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
52493 return 1;
52494 }
52495
52496+static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
52497+{
52498+ if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
52499+ return 0;
52500+ *p = *new;
52501+
52502+ /* This function is only called from pivot_root(). Leave our
52503+ gr_chroot_dentry and is_chrooted flags as-is, so that a
52504+ pivoted root isn't treated as a chroot
52505+ */
52506+ //gr_set_chroot_entries(task, new);
52507+
52508+ return 1;
52509+}
52510+
52511 void chroot_fs_refs(struct path *old_root, struct path *new_root)
52512 {
52513 struct task_struct *g, *p;
52514@@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
52515 int hits = 0;
52516 spin_lock(&fs->lock);
52517 write_seqcount_begin(&fs->seq);
52518- hits += replace_path(&fs->root, old_root, new_root);
52519+ hits += replace_root_path(p, &fs->root, old_root, new_root);
52520 hits += replace_path(&fs->pwd, old_root, new_root);
52521 write_seqcount_end(&fs->seq);
52522 while (hits--) {
52523@@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
52524 task_lock(tsk);
52525 spin_lock(&fs->lock);
52526 tsk->fs = NULL;
52527- kill = !--fs->users;
52528+ gr_clear_chroot_entries(tsk);
52529+ kill = !atomic_dec_return(&fs->users);
52530 spin_unlock(&fs->lock);
52531 task_unlock(tsk);
52532 if (kill)
52533@@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
52534 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
52535 /* We don't need to lock fs - think why ;-) */
52536 if (fs) {
52537- fs->users = 1;
52538+ atomic_set(&fs->users, 1);
52539 fs->in_exec = 0;
52540 spin_lock_init(&fs->lock);
52541 seqcount_init(&fs->seq);
52542@@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
52543 spin_lock(&old->lock);
52544 fs->root = old->root;
52545 path_get(&fs->root);
52546+ /* instead of calling gr_set_chroot_entries here,
52547+ we call it from every caller of this function
52548+ */
52549 fs->pwd = old->pwd;
52550 path_get(&fs->pwd);
52551 spin_unlock(&old->lock);
52552@@ -139,8 +160,9 @@ int unshare_fs_struct(void)
52553
52554 task_lock(current);
52555 spin_lock(&fs->lock);
52556- kill = !--fs->users;
52557+ kill = !atomic_dec_return(&fs->users);
52558 current->fs = new_fs;
52559+ gr_set_chroot_entries(current, &new_fs->root);
52560 spin_unlock(&fs->lock);
52561 task_unlock(current);
52562
52563@@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
52564
52565 int current_umask(void)
52566 {
52567- return current->fs->umask;
52568+ return current->fs->umask | gr_acl_umask();
52569 }
52570 EXPORT_SYMBOL(current_umask);
52571
52572 /* to be mentioned only in INIT_TASK */
52573 struct fs_struct init_fs = {
52574- .users = 1,
52575+ .users = ATOMIC_INIT(1),
52576 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
52577 .seq = SEQCNT_ZERO,
52578 .umask = 0022,
52579diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
52580index 8dcb114..b1072e2 100644
52581--- a/fs/fscache/cookie.c
52582+++ b/fs/fscache/cookie.c
52583@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
52584 parent ? (char *) parent->def->name : "<no-parent>",
52585 def->name, netfs_data);
52586
52587- fscache_stat(&fscache_n_acquires);
52588+ fscache_stat_unchecked(&fscache_n_acquires);
52589
52590 /* if there's no parent cookie, then we don't create one here either */
52591 if (!parent) {
52592- fscache_stat(&fscache_n_acquires_null);
52593+ fscache_stat_unchecked(&fscache_n_acquires_null);
52594 _leave(" [no parent]");
52595 return NULL;
52596 }
52597@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
52598 /* allocate and initialise a cookie */
52599 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
52600 if (!cookie) {
52601- fscache_stat(&fscache_n_acquires_oom);
52602+ fscache_stat_unchecked(&fscache_n_acquires_oom);
52603 _leave(" [ENOMEM]");
52604 return NULL;
52605 }
52606@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
52607
52608 switch (cookie->def->type) {
52609 case FSCACHE_COOKIE_TYPE_INDEX:
52610- fscache_stat(&fscache_n_cookie_index);
52611+ fscache_stat_unchecked(&fscache_n_cookie_index);
52612 break;
52613 case FSCACHE_COOKIE_TYPE_DATAFILE:
52614- fscache_stat(&fscache_n_cookie_data);
52615+ fscache_stat_unchecked(&fscache_n_cookie_data);
52616 break;
52617 default:
52618- fscache_stat(&fscache_n_cookie_special);
52619+ fscache_stat_unchecked(&fscache_n_cookie_special);
52620 break;
52621 }
52622
52623@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
52624 if (fscache_acquire_non_index_cookie(cookie) < 0) {
52625 atomic_dec(&parent->n_children);
52626 __fscache_cookie_put(cookie);
52627- fscache_stat(&fscache_n_acquires_nobufs);
52628+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
52629 _leave(" = NULL");
52630 return NULL;
52631 }
52632 }
52633
52634- fscache_stat(&fscache_n_acquires_ok);
52635+ fscache_stat_unchecked(&fscache_n_acquires_ok);
52636 _leave(" = %p", cookie);
52637 return cookie;
52638 }
52639@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
52640 cache = fscache_select_cache_for_object(cookie->parent);
52641 if (!cache) {
52642 up_read(&fscache_addremove_sem);
52643- fscache_stat(&fscache_n_acquires_no_cache);
52644+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
52645 _leave(" = -ENOMEDIUM [no cache]");
52646 return -ENOMEDIUM;
52647 }
52648@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
52649 object = cache->ops->alloc_object(cache, cookie);
52650 fscache_stat_d(&fscache_n_cop_alloc_object);
52651 if (IS_ERR(object)) {
52652- fscache_stat(&fscache_n_object_no_alloc);
52653+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
52654 ret = PTR_ERR(object);
52655 goto error;
52656 }
52657
52658- fscache_stat(&fscache_n_object_alloc);
52659+ fscache_stat_unchecked(&fscache_n_object_alloc);
52660
52661 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
52662
52663@@ -378,7 +378,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
52664
52665 _enter("{%s}", cookie->def->name);
52666
52667- fscache_stat(&fscache_n_invalidates);
52668+ fscache_stat_unchecked(&fscache_n_invalidates);
52669
52670 /* Only permit invalidation of data files. Invalidating an index will
52671 * require the caller to release all its attachments to the tree rooted
52672@@ -437,10 +437,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
52673 struct fscache_object *object;
52674 struct hlist_node *_p;
52675
52676- fscache_stat(&fscache_n_updates);
52677+ fscache_stat_unchecked(&fscache_n_updates);
52678
52679 if (!cookie) {
52680- fscache_stat(&fscache_n_updates_null);
52681+ fscache_stat_unchecked(&fscache_n_updates_null);
52682 _leave(" [no cookie]");
52683 return;
52684 }
52685@@ -474,12 +474,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
52686 struct fscache_object *object;
52687 unsigned long event;
52688
52689- fscache_stat(&fscache_n_relinquishes);
52690+ fscache_stat_unchecked(&fscache_n_relinquishes);
52691 if (retire)
52692- fscache_stat(&fscache_n_relinquishes_retire);
52693+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
52694
52695 if (!cookie) {
52696- fscache_stat(&fscache_n_relinquishes_null);
52697+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
52698 _leave(" [no cookie]");
52699 return;
52700 }
52701@@ -495,7 +495,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
52702
52703 /* wait for the cookie to finish being instantiated (or to fail) */
52704 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
52705- fscache_stat(&fscache_n_relinquishes_waitcrt);
52706+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
52707 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
52708 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
52709 }
52710diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
52711index ee38fef..0a326d4 100644
52712--- a/fs/fscache/internal.h
52713+++ b/fs/fscache/internal.h
52714@@ -148,101 +148,101 @@ extern void fscache_proc_cleanup(void);
52715 * stats.c
52716 */
52717 #ifdef CONFIG_FSCACHE_STATS
52718-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
52719-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
52720+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
52721+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
52722
52723-extern atomic_t fscache_n_op_pend;
52724-extern atomic_t fscache_n_op_run;
52725-extern atomic_t fscache_n_op_enqueue;
52726-extern atomic_t fscache_n_op_deferred_release;
52727-extern atomic_t fscache_n_op_release;
52728-extern atomic_t fscache_n_op_gc;
52729-extern atomic_t fscache_n_op_cancelled;
52730-extern atomic_t fscache_n_op_rejected;
52731+extern atomic_unchecked_t fscache_n_op_pend;
52732+extern atomic_unchecked_t fscache_n_op_run;
52733+extern atomic_unchecked_t fscache_n_op_enqueue;
52734+extern atomic_unchecked_t fscache_n_op_deferred_release;
52735+extern atomic_unchecked_t fscache_n_op_release;
52736+extern atomic_unchecked_t fscache_n_op_gc;
52737+extern atomic_unchecked_t fscache_n_op_cancelled;
52738+extern atomic_unchecked_t fscache_n_op_rejected;
52739
52740-extern atomic_t fscache_n_attr_changed;
52741-extern atomic_t fscache_n_attr_changed_ok;
52742-extern atomic_t fscache_n_attr_changed_nobufs;
52743-extern atomic_t fscache_n_attr_changed_nomem;
52744-extern atomic_t fscache_n_attr_changed_calls;
52745+extern atomic_unchecked_t fscache_n_attr_changed;
52746+extern atomic_unchecked_t fscache_n_attr_changed_ok;
52747+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
52748+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
52749+extern atomic_unchecked_t fscache_n_attr_changed_calls;
52750
52751-extern atomic_t fscache_n_allocs;
52752-extern atomic_t fscache_n_allocs_ok;
52753-extern atomic_t fscache_n_allocs_wait;
52754-extern atomic_t fscache_n_allocs_nobufs;
52755-extern atomic_t fscache_n_allocs_intr;
52756-extern atomic_t fscache_n_allocs_object_dead;
52757-extern atomic_t fscache_n_alloc_ops;
52758-extern atomic_t fscache_n_alloc_op_waits;
52759+extern atomic_unchecked_t fscache_n_allocs;
52760+extern atomic_unchecked_t fscache_n_allocs_ok;
52761+extern atomic_unchecked_t fscache_n_allocs_wait;
52762+extern atomic_unchecked_t fscache_n_allocs_nobufs;
52763+extern atomic_unchecked_t fscache_n_allocs_intr;
52764+extern atomic_unchecked_t fscache_n_allocs_object_dead;
52765+extern atomic_unchecked_t fscache_n_alloc_ops;
52766+extern atomic_unchecked_t fscache_n_alloc_op_waits;
52767
52768-extern atomic_t fscache_n_retrievals;
52769-extern atomic_t fscache_n_retrievals_ok;
52770-extern atomic_t fscache_n_retrievals_wait;
52771-extern atomic_t fscache_n_retrievals_nodata;
52772-extern atomic_t fscache_n_retrievals_nobufs;
52773-extern atomic_t fscache_n_retrievals_intr;
52774-extern atomic_t fscache_n_retrievals_nomem;
52775-extern atomic_t fscache_n_retrievals_object_dead;
52776-extern atomic_t fscache_n_retrieval_ops;
52777-extern atomic_t fscache_n_retrieval_op_waits;
52778+extern atomic_unchecked_t fscache_n_retrievals;
52779+extern atomic_unchecked_t fscache_n_retrievals_ok;
52780+extern atomic_unchecked_t fscache_n_retrievals_wait;
52781+extern atomic_unchecked_t fscache_n_retrievals_nodata;
52782+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
52783+extern atomic_unchecked_t fscache_n_retrievals_intr;
52784+extern atomic_unchecked_t fscache_n_retrievals_nomem;
52785+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
52786+extern atomic_unchecked_t fscache_n_retrieval_ops;
52787+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
52788
52789-extern atomic_t fscache_n_stores;
52790-extern atomic_t fscache_n_stores_ok;
52791-extern atomic_t fscache_n_stores_again;
52792-extern atomic_t fscache_n_stores_nobufs;
52793-extern atomic_t fscache_n_stores_oom;
52794-extern atomic_t fscache_n_store_ops;
52795-extern atomic_t fscache_n_store_calls;
52796-extern atomic_t fscache_n_store_pages;
52797-extern atomic_t fscache_n_store_radix_deletes;
52798-extern atomic_t fscache_n_store_pages_over_limit;
52799+extern atomic_unchecked_t fscache_n_stores;
52800+extern atomic_unchecked_t fscache_n_stores_ok;
52801+extern atomic_unchecked_t fscache_n_stores_again;
52802+extern atomic_unchecked_t fscache_n_stores_nobufs;
52803+extern atomic_unchecked_t fscache_n_stores_oom;
52804+extern atomic_unchecked_t fscache_n_store_ops;
52805+extern atomic_unchecked_t fscache_n_store_calls;
52806+extern atomic_unchecked_t fscache_n_store_pages;
52807+extern atomic_unchecked_t fscache_n_store_radix_deletes;
52808+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
52809
52810-extern atomic_t fscache_n_store_vmscan_not_storing;
52811-extern atomic_t fscache_n_store_vmscan_gone;
52812-extern atomic_t fscache_n_store_vmscan_busy;
52813-extern atomic_t fscache_n_store_vmscan_cancelled;
52814-extern atomic_t fscache_n_store_vmscan_wait;
52815+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
52816+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
52817+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
52818+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
52819+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
52820
52821-extern atomic_t fscache_n_marks;
52822-extern atomic_t fscache_n_uncaches;
52823+extern atomic_unchecked_t fscache_n_marks;
52824+extern atomic_unchecked_t fscache_n_uncaches;
52825
52826-extern atomic_t fscache_n_acquires;
52827-extern atomic_t fscache_n_acquires_null;
52828-extern atomic_t fscache_n_acquires_no_cache;
52829-extern atomic_t fscache_n_acquires_ok;
52830-extern atomic_t fscache_n_acquires_nobufs;
52831-extern atomic_t fscache_n_acquires_oom;
52832+extern atomic_unchecked_t fscache_n_acquires;
52833+extern atomic_unchecked_t fscache_n_acquires_null;
52834+extern atomic_unchecked_t fscache_n_acquires_no_cache;
52835+extern atomic_unchecked_t fscache_n_acquires_ok;
52836+extern atomic_unchecked_t fscache_n_acquires_nobufs;
52837+extern atomic_unchecked_t fscache_n_acquires_oom;
52838
52839-extern atomic_t fscache_n_invalidates;
52840-extern atomic_t fscache_n_invalidates_run;
52841+extern atomic_unchecked_t fscache_n_invalidates;
52842+extern atomic_unchecked_t fscache_n_invalidates_run;
52843
52844-extern atomic_t fscache_n_updates;
52845-extern atomic_t fscache_n_updates_null;
52846-extern atomic_t fscache_n_updates_run;
52847+extern atomic_unchecked_t fscache_n_updates;
52848+extern atomic_unchecked_t fscache_n_updates_null;
52849+extern atomic_unchecked_t fscache_n_updates_run;
52850
52851-extern atomic_t fscache_n_relinquishes;
52852-extern atomic_t fscache_n_relinquishes_null;
52853-extern atomic_t fscache_n_relinquishes_waitcrt;
52854-extern atomic_t fscache_n_relinquishes_retire;
52855+extern atomic_unchecked_t fscache_n_relinquishes;
52856+extern atomic_unchecked_t fscache_n_relinquishes_null;
52857+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
52858+extern atomic_unchecked_t fscache_n_relinquishes_retire;
52859
52860-extern atomic_t fscache_n_cookie_index;
52861-extern atomic_t fscache_n_cookie_data;
52862-extern atomic_t fscache_n_cookie_special;
52863+extern atomic_unchecked_t fscache_n_cookie_index;
52864+extern atomic_unchecked_t fscache_n_cookie_data;
52865+extern atomic_unchecked_t fscache_n_cookie_special;
52866
52867-extern atomic_t fscache_n_object_alloc;
52868-extern atomic_t fscache_n_object_no_alloc;
52869-extern atomic_t fscache_n_object_lookups;
52870-extern atomic_t fscache_n_object_lookups_negative;
52871-extern atomic_t fscache_n_object_lookups_positive;
52872-extern atomic_t fscache_n_object_lookups_timed_out;
52873-extern atomic_t fscache_n_object_created;
52874-extern atomic_t fscache_n_object_avail;
52875-extern atomic_t fscache_n_object_dead;
52876+extern atomic_unchecked_t fscache_n_object_alloc;
52877+extern atomic_unchecked_t fscache_n_object_no_alloc;
52878+extern atomic_unchecked_t fscache_n_object_lookups;
52879+extern atomic_unchecked_t fscache_n_object_lookups_negative;
52880+extern atomic_unchecked_t fscache_n_object_lookups_positive;
52881+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
52882+extern atomic_unchecked_t fscache_n_object_created;
52883+extern atomic_unchecked_t fscache_n_object_avail;
52884+extern atomic_unchecked_t fscache_n_object_dead;
52885
52886-extern atomic_t fscache_n_checkaux_none;
52887-extern atomic_t fscache_n_checkaux_okay;
52888-extern atomic_t fscache_n_checkaux_update;
52889-extern atomic_t fscache_n_checkaux_obsolete;
52890+extern atomic_unchecked_t fscache_n_checkaux_none;
52891+extern atomic_unchecked_t fscache_n_checkaux_okay;
52892+extern atomic_unchecked_t fscache_n_checkaux_update;
52893+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
52894
52895 extern atomic_t fscache_n_cop_alloc_object;
52896 extern atomic_t fscache_n_cop_lookup_object;
52897@@ -267,6 +267,11 @@ static inline void fscache_stat(atomic_t *stat)
52898 atomic_inc(stat);
52899 }
52900
52901+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
52902+{
52903+ atomic_inc_unchecked(stat);
52904+}
52905+
52906 static inline void fscache_stat_d(atomic_t *stat)
52907 {
52908 atomic_dec(stat);
52909@@ -279,6 +284,7 @@ extern const struct file_operations fscache_stats_fops;
52910
52911 #define __fscache_stat(stat) (NULL)
52912 #define fscache_stat(stat) do {} while (0)
52913+#define fscache_stat_unchecked(stat) do {} while (0)
52914 #define fscache_stat_d(stat) do {} while (0)
52915 #endif
52916
52917diff --git a/fs/fscache/object.c b/fs/fscache/object.c
52918index 50d41c1..10ee117 100644
52919--- a/fs/fscache/object.c
52920+++ b/fs/fscache/object.c
52921@@ -143,7 +143,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52922 /* Invalidate an object on disk */
52923 case FSCACHE_OBJECT_INVALIDATING:
52924 clear_bit(FSCACHE_OBJECT_EV_INVALIDATE, &object->events);
52925- fscache_stat(&fscache_n_invalidates_run);
52926+ fscache_stat_unchecked(&fscache_n_invalidates_run);
52927 fscache_stat(&fscache_n_cop_invalidate_object);
52928 fscache_invalidate_object(object);
52929 fscache_stat_d(&fscache_n_cop_invalidate_object);
52930@@ -153,7 +153,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52931 /* update the object metadata on disk */
52932 case FSCACHE_OBJECT_UPDATING:
52933 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
52934- fscache_stat(&fscache_n_updates_run);
52935+ fscache_stat_unchecked(&fscache_n_updates_run);
52936 fscache_stat(&fscache_n_cop_update_object);
52937 object->cache->ops->update_object(object);
52938 fscache_stat_d(&fscache_n_cop_update_object);
52939@@ -242,7 +242,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52940 spin_lock(&object->lock);
52941 object->state = FSCACHE_OBJECT_DEAD;
52942 spin_unlock(&object->lock);
52943- fscache_stat(&fscache_n_object_dead);
52944+ fscache_stat_unchecked(&fscache_n_object_dead);
52945 goto terminal_transit;
52946
52947 /* handle the parent cache of this object being withdrawn from
52948@@ -257,7 +257,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52949 spin_lock(&object->lock);
52950 object->state = FSCACHE_OBJECT_DEAD;
52951 spin_unlock(&object->lock);
52952- fscache_stat(&fscache_n_object_dead);
52953+ fscache_stat_unchecked(&fscache_n_object_dead);
52954 goto terminal_transit;
52955
52956 /* complain about the object being woken up once it is
52957@@ -495,7 +495,7 @@ static void fscache_lookup_object(struct fscache_object *object)
52958 parent->cookie->def->name, cookie->def->name,
52959 object->cache->tag->name);
52960
52961- fscache_stat(&fscache_n_object_lookups);
52962+ fscache_stat_unchecked(&fscache_n_object_lookups);
52963 fscache_stat(&fscache_n_cop_lookup_object);
52964 ret = object->cache->ops->lookup_object(object);
52965 fscache_stat_d(&fscache_n_cop_lookup_object);
52966@@ -506,7 +506,7 @@ static void fscache_lookup_object(struct fscache_object *object)
52967 if (ret == -ETIMEDOUT) {
52968 /* probably stuck behind another object, so move this one to
52969 * the back of the queue */
52970- fscache_stat(&fscache_n_object_lookups_timed_out);
52971+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
52972 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
52973 }
52974
52975@@ -529,7 +529,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
52976
52977 spin_lock(&object->lock);
52978 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
52979- fscache_stat(&fscache_n_object_lookups_negative);
52980+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
52981
52982 /* transit here to allow write requests to begin stacking up
52983 * and read requests to begin returning ENODATA */
52984@@ -575,7 +575,7 @@ void fscache_obtained_object(struct fscache_object *object)
52985 * result, in which case there may be data available */
52986 spin_lock(&object->lock);
52987 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
52988- fscache_stat(&fscache_n_object_lookups_positive);
52989+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
52990
52991 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
52992
52993@@ -589,7 +589,7 @@ void fscache_obtained_object(struct fscache_object *object)
52994 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
52995 } else {
52996 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
52997- fscache_stat(&fscache_n_object_created);
52998+ fscache_stat_unchecked(&fscache_n_object_created);
52999
53000 object->state = FSCACHE_OBJECT_AVAILABLE;
53001 spin_unlock(&object->lock);
53002@@ -634,7 +634,7 @@ static void fscache_object_available(struct fscache_object *object)
53003 fscache_enqueue_dependents(object);
53004
53005 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
53006- fscache_stat(&fscache_n_object_avail);
53007+ fscache_stat_unchecked(&fscache_n_object_avail);
53008
53009 _leave("");
53010 }
53011@@ -894,7 +894,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
53012 enum fscache_checkaux result;
53013
53014 if (!object->cookie->def->check_aux) {
53015- fscache_stat(&fscache_n_checkaux_none);
53016+ fscache_stat_unchecked(&fscache_n_checkaux_none);
53017 return FSCACHE_CHECKAUX_OKAY;
53018 }
53019
53020@@ -903,17 +903,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
53021 switch (result) {
53022 /* entry okay as is */
53023 case FSCACHE_CHECKAUX_OKAY:
53024- fscache_stat(&fscache_n_checkaux_okay);
53025+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
53026 break;
53027
53028 /* entry requires update */
53029 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
53030- fscache_stat(&fscache_n_checkaux_update);
53031+ fscache_stat_unchecked(&fscache_n_checkaux_update);
53032 break;
53033
53034 /* entry requires deletion */
53035 case FSCACHE_CHECKAUX_OBSOLETE:
53036- fscache_stat(&fscache_n_checkaux_obsolete);
53037+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
53038 break;
53039
53040 default:
53041diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
53042index 762a9ec..2023284 100644
53043--- a/fs/fscache/operation.c
53044+++ b/fs/fscache/operation.c
53045@@ -17,7 +17,7 @@
53046 #include <linux/slab.h>
53047 #include "internal.h"
53048
53049-atomic_t fscache_op_debug_id;
53050+atomic_unchecked_t fscache_op_debug_id;
53051 EXPORT_SYMBOL(fscache_op_debug_id);
53052
53053 /**
53054@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
53055 ASSERTCMP(atomic_read(&op->usage), >, 0);
53056 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
53057
53058- fscache_stat(&fscache_n_op_enqueue);
53059+ fscache_stat_unchecked(&fscache_n_op_enqueue);
53060 switch (op->flags & FSCACHE_OP_TYPE) {
53061 case FSCACHE_OP_ASYNC:
53062 _debug("queue async");
53063@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
53064 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
53065 if (op->processor)
53066 fscache_enqueue_operation(op);
53067- fscache_stat(&fscache_n_op_run);
53068+ fscache_stat_unchecked(&fscache_n_op_run);
53069 }
53070
53071 /*
53072@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
53073 if (object->n_in_progress > 0) {
53074 atomic_inc(&op->usage);
53075 list_add_tail(&op->pend_link, &object->pending_ops);
53076- fscache_stat(&fscache_n_op_pend);
53077+ fscache_stat_unchecked(&fscache_n_op_pend);
53078 } else if (!list_empty(&object->pending_ops)) {
53079 atomic_inc(&op->usage);
53080 list_add_tail(&op->pend_link, &object->pending_ops);
53081- fscache_stat(&fscache_n_op_pend);
53082+ fscache_stat_unchecked(&fscache_n_op_pend);
53083 fscache_start_operations(object);
53084 } else {
53085 ASSERTCMP(object->n_in_progress, ==, 0);
53086@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
53087 object->n_exclusive++; /* reads and writes must wait */
53088 atomic_inc(&op->usage);
53089 list_add_tail(&op->pend_link, &object->pending_ops);
53090- fscache_stat(&fscache_n_op_pend);
53091+ fscache_stat_unchecked(&fscache_n_op_pend);
53092 ret = 0;
53093 } else {
53094 /* If we're in any other state, there must have been an I/O
53095@@ -215,11 +215,11 @@ int fscache_submit_op(struct fscache_object *object,
53096 if (object->n_exclusive > 0) {
53097 atomic_inc(&op->usage);
53098 list_add_tail(&op->pend_link, &object->pending_ops);
53099- fscache_stat(&fscache_n_op_pend);
53100+ fscache_stat_unchecked(&fscache_n_op_pend);
53101 } else if (!list_empty(&object->pending_ops)) {
53102 atomic_inc(&op->usage);
53103 list_add_tail(&op->pend_link, &object->pending_ops);
53104- fscache_stat(&fscache_n_op_pend);
53105+ fscache_stat_unchecked(&fscache_n_op_pend);
53106 fscache_start_operations(object);
53107 } else {
53108 ASSERTCMP(object->n_exclusive, ==, 0);
53109@@ -231,12 +231,12 @@ int fscache_submit_op(struct fscache_object *object,
53110 object->n_ops++;
53111 atomic_inc(&op->usage);
53112 list_add_tail(&op->pend_link, &object->pending_ops);
53113- fscache_stat(&fscache_n_op_pend);
53114+ fscache_stat_unchecked(&fscache_n_op_pend);
53115 ret = 0;
53116 } else if (object->state == FSCACHE_OBJECT_DYING ||
53117 object->state == FSCACHE_OBJECT_LC_DYING ||
53118 object->state == FSCACHE_OBJECT_WITHDRAWING) {
53119- fscache_stat(&fscache_n_op_rejected);
53120+ fscache_stat_unchecked(&fscache_n_op_rejected);
53121 op->state = FSCACHE_OP_ST_CANCELLED;
53122 ret = -ENOBUFS;
53123 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
53124@@ -315,7 +315,7 @@ int fscache_cancel_op(struct fscache_operation *op,
53125 ret = -EBUSY;
53126 if (op->state == FSCACHE_OP_ST_PENDING) {
53127 ASSERT(!list_empty(&op->pend_link));
53128- fscache_stat(&fscache_n_op_cancelled);
53129+ fscache_stat_unchecked(&fscache_n_op_cancelled);
53130 list_del_init(&op->pend_link);
53131 if (do_cancel)
53132 do_cancel(op);
53133@@ -347,7 +347,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
53134 while (!list_empty(&object->pending_ops)) {
53135 op = list_entry(object->pending_ops.next,
53136 struct fscache_operation, pend_link);
53137- fscache_stat(&fscache_n_op_cancelled);
53138+ fscache_stat_unchecked(&fscache_n_op_cancelled);
53139 list_del_init(&op->pend_link);
53140
53141 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
53142@@ -419,7 +419,7 @@ void fscache_put_operation(struct fscache_operation *op)
53143 op->state, ==, FSCACHE_OP_ST_CANCELLED);
53144 op->state = FSCACHE_OP_ST_DEAD;
53145
53146- fscache_stat(&fscache_n_op_release);
53147+ fscache_stat_unchecked(&fscache_n_op_release);
53148
53149 if (op->release) {
53150 op->release(op);
53151@@ -442,7 +442,7 @@ void fscache_put_operation(struct fscache_operation *op)
53152 * lock, and defer it otherwise */
53153 if (!spin_trylock(&object->lock)) {
53154 _debug("defer put");
53155- fscache_stat(&fscache_n_op_deferred_release);
53156+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
53157
53158 cache = object->cache;
53159 spin_lock(&cache->op_gc_list_lock);
53160@@ -495,7 +495,7 @@ void fscache_operation_gc(struct work_struct *work)
53161
53162 _debug("GC DEFERRED REL OBJ%x OP%x",
53163 object->debug_id, op->debug_id);
53164- fscache_stat(&fscache_n_op_gc);
53165+ fscache_stat_unchecked(&fscache_n_op_gc);
53166
53167 ASSERTCMP(atomic_read(&op->usage), ==, 0);
53168 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
53169diff --git a/fs/fscache/page.c b/fs/fscache/page.c
53170index ff000e5..c44ec6d 100644
53171--- a/fs/fscache/page.c
53172+++ b/fs/fscache/page.c
53173@@ -61,7 +61,7 @@ try_again:
53174 val = radix_tree_lookup(&cookie->stores, page->index);
53175 if (!val) {
53176 rcu_read_unlock();
53177- fscache_stat(&fscache_n_store_vmscan_not_storing);
53178+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
53179 __fscache_uncache_page(cookie, page);
53180 return true;
53181 }
53182@@ -91,11 +91,11 @@ try_again:
53183 spin_unlock(&cookie->stores_lock);
53184
53185 if (xpage) {
53186- fscache_stat(&fscache_n_store_vmscan_cancelled);
53187- fscache_stat(&fscache_n_store_radix_deletes);
53188+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
53189+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
53190 ASSERTCMP(xpage, ==, page);
53191 } else {
53192- fscache_stat(&fscache_n_store_vmscan_gone);
53193+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
53194 }
53195
53196 wake_up_bit(&cookie->flags, 0);
53197@@ -110,11 +110,11 @@ page_busy:
53198 * sleeping on memory allocation, so we may need to impose a timeout
53199 * too. */
53200 if (!(gfp & __GFP_WAIT)) {
53201- fscache_stat(&fscache_n_store_vmscan_busy);
53202+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
53203 return false;
53204 }
53205
53206- fscache_stat(&fscache_n_store_vmscan_wait);
53207+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
53208 __fscache_wait_on_page_write(cookie, page);
53209 gfp &= ~__GFP_WAIT;
53210 goto try_again;
53211@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
53212 FSCACHE_COOKIE_STORING_TAG);
53213 if (!radix_tree_tag_get(&cookie->stores, page->index,
53214 FSCACHE_COOKIE_PENDING_TAG)) {
53215- fscache_stat(&fscache_n_store_radix_deletes);
53216+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
53217 xpage = radix_tree_delete(&cookie->stores, page->index);
53218 }
53219 spin_unlock(&cookie->stores_lock);
53220@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
53221
53222 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
53223
53224- fscache_stat(&fscache_n_attr_changed_calls);
53225+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
53226
53227 if (fscache_object_is_active(object)) {
53228 fscache_stat(&fscache_n_cop_attr_changed);
53229@@ -187,11 +187,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
53230
53231 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
53232
53233- fscache_stat(&fscache_n_attr_changed);
53234+ fscache_stat_unchecked(&fscache_n_attr_changed);
53235
53236 op = kzalloc(sizeof(*op), GFP_KERNEL);
53237 if (!op) {
53238- fscache_stat(&fscache_n_attr_changed_nomem);
53239+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
53240 _leave(" = -ENOMEM");
53241 return -ENOMEM;
53242 }
53243@@ -209,7 +209,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
53244 if (fscache_submit_exclusive_op(object, op) < 0)
53245 goto nobufs;
53246 spin_unlock(&cookie->lock);
53247- fscache_stat(&fscache_n_attr_changed_ok);
53248+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
53249 fscache_put_operation(op);
53250 _leave(" = 0");
53251 return 0;
53252@@ -217,7 +217,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
53253 nobufs:
53254 spin_unlock(&cookie->lock);
53255 kfree(op);
53256- fscache_stat(&fscache_n_attr_changed_nobufs);
53257+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
53258 _leave(" = %d", -ENOBUFS);
53259 return -ENOBUFS;
53260 }
53261@@ -255,7 +255,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
53262 /* allocate a retrieval operation and attempt to submit it */
53263 op = kzalloc(sizeof(*op), GFP_NOIO);
53264 if (!op) {
53265- fscache_stat(&fscache_n_retrievals_nomem);
53266+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
53267 return NULL;
53268 }
53269
53270@@ -283,13 +283,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
53271 return 0;
53272 }
53273
53274- fscache_stat(&fscache_n_retrievals_wait);
53275+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
53276
53277 jif = jiffies;
53278 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
53279 fscache_wait_bit_interruptible,
53280 TASK_INTERRUPTIBLE) != 0) {
53281- fscache_stat(&fscache_n_retrievals_intr);
53282+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
53283 _leave(" = -ERESTARTSYS");
53284 return -ERESTARTSYS;
53285 }
53286@@ -318,8 +318,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
53287 */
53288 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
53289 struct fscache_retrieval *op,
53290- atomic_t *stat_op_waits,
53291- atomic_t *stat_object_dead)
53292+ atomic_unchecked_t *stat_op_waits,
53293+ atomic_unchecked_t *stat_object_dead)
53294 {
53295 int ret;
53296
53297@@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
53298 goto check_if_dead;
53299
53300 _debug(">>> WT");
53301- fscache_stat(stat_op_waits);
53302+ fscache_stat_unchecked(stat_op_waits);
53303 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
53304 fscache_wait_bit_interruptible,
53305 TASK_INTERRUPTIBLE) != 0) {
53306@@ -344,14 +344,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
53307
53308 check_if_dead:
53309 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
53310- fscache_stat(stat_object_dead);
53311+ fscache_stat_unchecked(stat_object_dead);
53312 _leave(" = -ENOBUFS [cancelled]");
53313 return -ENOBUFS;
53314 }
53315 if (unlikely(fscache_object_is_dead(object))) {
53316 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
53317 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
53318- fscache_stat(stat_object_dead);
53319+ fscache_stat_unchecked(stat_object_dead);
53320 return -ENOBUFS;
53321 }
53322 return 0;
53323@@ -378,7 +378,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
53324
53325 _enter("%p,%p,,,", cookie, page);
53326
53327- fscache_stat(&fscache_n_retrievals);
53328+ fscache_stat_unchecked(&fscache_n_retrievals);
53329
53330 if (hlist_empty(&cookie->backing_objects))
53331 goto nobufs;
53332@@ -417,7 +417,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
53333 goto nobufs_unlock_dec;
53334 spin_unlock(&cookie->lock);
53335
53336- fscache_stat(&fscache_n_retrieval_ops);
53337+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
53338
53339 /* pin the netfs read context in case we need to do the actual netfs
53340 * read because we've encountered a cache read failure */
53341@@ -447,15 +447,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
53342
53343 error:
53344 if (ret == -ENOMEM)
53345- fscache_stat(&fscache_n_retrievals_nomem);
53346+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
53347 else if (ret == -ERESTARTSYS)
53348- fscache_stat(&fscache_n_retrievals_intr);
53349+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
53350 else if (ret == -ENODATA)
53351- fscache_stat(&fscache_n_retrievals_nodata);
53352+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
53353 else if (ret < 0)
53354- fscache_stat(&fscache_n_retrievals_nobufs);
53355+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
53356 else
53357- fscache_stat(&fscache_n_retrievals_ok);
53358+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
53359
53360 fscache_put_retrieval(op);
53361 _leave(" = %d", ret);
53362@@ -467,7 +467,7 @@ nobufs_unlock:
53363 spin_unlock(&cookie->lock);
53364 kfree(op);
53365 nobufs:
53366- fscache_stat(&fscache_n_retrievals_nobufs);
53367+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
53368 _leave(" = -ENOBUFS");
53369 return -ENOBUFS;
53370 }
53371@@ -505,7 +505,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
53372
53373 _enter("%p,,%d,,,", cookie, *nr_pages);
53374
53375- fscache_stat(&fscache_n_retrievals);
53376+ fscache_stat_unchecked(&fscache_n_retrievals);
53377
53378 if (hlist_empty(&cookie->backing_objects))
53379 goto nobufs;
53380@@ -541,7 +541,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
53381 goto nobufs_unlock_dec;
53382 spin_unlock(&cookie->lock);
53383
53384- fscache_stat(&fscache_n_retrieval_ops);
53385+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
53386
53387 /* pin the netfs read context in case we need to do the actual netfs
53388 * read because we've encountered a cache read failure */
53389@@ -571,15 +571,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
53390
53391 error:
53392 if (ret == -ENOMEM)
53393- fscache_stat(&fscache_n_retrievals_nomem);
53394+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
53395 else if (ret == -ERESTARTSYS)
53396- fscache_stat(&fscache_n_retrievals_intr);
53397+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
53398 else if (ret == -ENODATA)
53399- fscache_stat(&fscache_n_retrievals_nodata);
53400+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
53401 else if (ret < 0)
53402- fscache_stat(&fscache_n_retrievals_nobufs);
53403+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
53404 else
53405- fscache_stat(&fscache_n_retrievals_ok);
53406+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
53407
53408 fscache_put_retrieval(op);
53409 _leave(" = %d", ret);
53410@@ -591,7 +591,7 @@ nobufs_unlock:
53411 spin_unlock(&cookie->lock);
53412 kfree(op);
53413 nobufs:
53414- fscache_stat(&fscache_n_retrievals_nobufs);
53415+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
53416 _leave(" = -ENOBUFS");
53417 return -ENOBUFS;
53418 }
53419@@ -615,7 +615,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
53420
53421 _enter("%p,%p,,,", cookie, page);
53422
53423- fscache_stat(&fscache_n_allocs);
53424+ fscache_stat_unchecked(&fscache_n_allocs);
53425
53426 if (hlist_empty(&cookie->backing_objects))
53427 goto nobufs;
53428@@ -647,7 +647,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
53429 goto nobufs_unlock;
53430 spin_unlock(&cookie->lock);
53431
53432- fscache_stat(&fscache_n_alloc_ops);
53433+ fscache_stat_unchecked(&fscache_n_alloc_ops);
53434
53435 ret = fscache_wait_for_retrieval_activation(
53436 object, op,
53437@@ -663,11 +663,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
53438
53439 error:
53440 if (ret == -ERESTARTSYS)
53441- fscache_stat(&fscache_n_allocs_intr);
53442+ fscache_stat_unchecked(&fscache_n_allocs_intr);
53443 else if (ret < 0)
53444- fscache_stat(&fscache_n_allocs_nobufs);
53445+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
53446 else
53447- fscache_stat(&fscache_n_allocs_ok);
53448+ fscache_stat_unchecked(&fscache_n_allocs_ok);
53449
53450 fscache_put_retrieval(op);
53451 _leave(" = %d", ret);
53452@@ -677,7 +677,7 @@ nobufs_unlock:
53453 spin_unlock(&cookie->lock);
53454 kfree(op);
53455 nobufs:
53456- fscache_stat(&fscache_n_allocs_nobufs);
53457+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
53458 _leave(" = -ENOBUFS");
53459 return -ENOBUFS;
53460 }
53461@@ -736,7 +736,7 @@ static void fscache_write_op(struct fscache_operation *_op)
53462
53463 spin_lock(&cookie->stores_lock);
53464
53465- fscache_stat(&fscache_n_store_calls);
53466+ fscache_stat_unchecked(&fscache_n_store_calls);
53467
53468 /* find a page to store */
53469 page = NULL;
53470@@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
53471 page = results[0];
53472 _debug("gang %d [%lx]", n, page->index);
53473 if (page->index > op->store_limit) {
53474- fscache_stat(&fscache_n_store_pages_over_limit);
53475+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
53476 goto superseded;
53477 }
53478
53479@@ -759,7 +759,7 @@ static void fscache_write_op(struct fscache_operation *_op)
53480 spin_unlock(&cookie->stores_lock);
53481 spin_unlock(&object->lock);
53482
53483- fscache_stat(&fscache_n_store_pages);
53484+ fscache_stat_unchecked(&fscache_n_store_pages);
53485 fscache_stat(&fscache_n_cop_write_page);
53486 ret = object->cache->ops->write_page(op, page);
53487 fscache_stat_d(&fscache_n_cop_write_page);
53488@@ -860,7 +860,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
53489 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
53490 ASSERT(PageFsCache(page));
53491
53492- fscache_stat(&fscache_n_stores);
53493+ fscache_stat_unchecked(&fscache_n_stores);
53494
53495 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
53496 _leave(" = -ENOBUFS [invalidating]");
53497@@ -916,7 +916,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
53498 spin_unlock(&cookie->stores_lock);
53499 spin_unlock(&object->lock);
53500
53501- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
53502+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
53503 op->store_limit = object->store_limit;
53504
53505 if (fscache_submit_op(object, &op->op) < 0)
53506@@ -924,8 +924,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
53507
53508 spin_unlock(&cookie->lock);
53509 radix_tree_preload_end();
53510- fscache_stat(&fscache_n_store_ops);
53511- fscache_stat(&fscache_n_stores_ok);
53512+ fscache_stat_unchecked(&fscache_n_store_ops);
53513+ fscache_stat_unchecked(&fscache_n_stores_ok);
53514
53515 /* the work queue now carries its own ref on the object */
53516 fscache_put_operation(&op->op);
53517@@ -933,14 +933,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
53518 return 0;
53519
53520 already_queued:
53521- fscache_stat(&fscache_n_stores_again);
53522+ fscache_stat_unchecked(&fscache_n_stores_again);
53523 already_pending:
53524 spin_unlock(&cookie->stores_lock);
53525 spin_unlock(&object->lock);
53526 spin_unlock(&cookie->lock);
53527 radix_tree_preload_end();
53528 kfree(op);
53529- fscache_stat(&fscache_n_stores_ok);
53530+ fscache_stat_unchecked(&fscache_n_stores_ok);
53531 _leave(" = 0");
53532 return 0;
53533
53534@@ -959,14 +959,14 @@ nobufs:
53535 spin_unlock(&cookie->lock);
53536 radix_tree_preload_end();
53537 kfree(op);
53538- fscache_stat(&fscache_n_stores_nobufs);
53539+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
53540 _leave(" = -ENOBUFS");
53541 return -ENOBUFS;
53542
53543 nomem_free:
53544 kfree(op);
53545 nomem:
53546- fscache_stat(&fscache_n_stores_oom);
53547+ fscache_stat_unchecked(&fscache_n_stores_oom);
53548 _leave(" = -ENOMEM");
53549 return -ENOMEM;
53550 }
53551@@ -984,7 +984,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
53552 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
53553 ASSERTCMP(page, !=, NULL);
53554
53555- fscache_stat(&fscache_n_uncaches);
53556+ fscache_stat_unchecked(&fscache_n_uncaches);
53557
53558 /* cache withdrawal may beat us to it */
53559 if (!PageFsCache(page))
53560@@ -1035,7 +1035,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
53561 struct fscache_cookie *cookie = op->op.object->cookie;
53562
53563 #ifdef CONFIG_FSCACHE_STATS
53564- atomic_inc(&fscache_n_marks);
53565+ atomic_inc_unchecked(&fscache_n_marks);
53566 #endif
53567
53568 _debug("- mark %p{%lx}", page, page->index);
53569diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
53570index 8179e8b..5072cc7 100644
53571--- a/fs/fscache/stats.c
53572+++ b/fs/fscache/stats.c
53573@@ -18,99 +18,99 @@
53574 /*
53575 * operation counters
53576 */
53577-atomic_t fscache_n_op_pend;
53578-atomic_t fscache_n_op_run;
53579-atomic_t fscache_n_op_enqueue;
53580-atomic_t fscache_n_op_requeue;
53581-atomic_t fscache_n_op_deferred_release;
53582-atomic_t fscache_n_op_release;
53583-atomic_t fscache_n_op_gc;
53584-atomic_t fscache_n_op_cancelled;
53585-atomic_t fscache_n_op_rejected;
53586+atomic_unchecked_t fscache_n_op_pend;
53587+atomic_unchecked_t fscache_n_op_run;
53588+atomic_unchecked_t fscache_n_op_enqueue;
53589+atomic_unchecked_t fscache_n_op_requeue;
53590+atomic_unchecked_t fscache_n_op_deferred_release;
53591+atomic_unchecked_t fscache_n_op_release;
53592+atomic_unchecked_t fscache_n_op_gc;
53593+atomic_unchecked_t fscache_n_op_cancelled;
53594+atomic_unchecked_t fscache_n_op_rejected;
53595
53596-atomic_t fscache_n_attr_changed;
53597-atomic_t fscache_n_attr_changed_ok;
53598-atomic_t fscache_n_attr_changed_nobufs;
53599-atomic_t fscache_n_attr_changed_nomem;
53600-atomic_t fscache_n_attr_changed_calls;
53601+atomic_unchecked_t fscache_n_attr_changed;
53602+atomic_unchecked_t fscache_n_attr_changed_ok;
53603+atomic_unchecked_t fscache_n_attr_changed_nobufs;
53604+atomic_unchecked_t fscache_n_attr_changed_nomem;
53605+atomic_unchecked_t fscache_n_attr_changed_calls;
53606
53607-atomic_t fscache_n_allocs;
53608-atomic_t fscache_n_allocs_ok;
53609-atomic_t fscache_n_allocs_wait;
53610-atomic_t fscache_n_allocs_nobufs;
53611-atomic_t fscache_n_allocs_intr;
53612-atomic_t fscache_n_allocs_object_dead;
53613-atomic_t fscache_n_alloc_ops;
53614-atomic_t fscache_n_alloc_op_waits;
53615+atomic_unchecked_t fscache_n_allocs;
53616+atomic_unchecked_t fscache_n_allocs_ok;
53617+atomic_unchecked_t fscache_n_allocs_wait;
53618+atomic_unchecked_t fscache_n_allocs_nobufs;
53619+atomic_unchecked_t fscache_n_allocs_intr;
53620+atomic_unchecked_t fscache_n_allocs_object_dead;
53621+atomic_unchecked_t fscache_n_alloc_ops;
53622+atomic_unchecked_t fscache_n_alloc_op_waits;
53623
53624-atomic_t fscache_n_retrievals;
53625-atomic_t fscache_n_retrievals_ok;
53626-atomic_t fscache_n_retrievals_wait;
53627-atomic_t fscache_n_retrievals_nodata;
53628-atomic_t fscache_n_retrievals_nobufs;
53629-atomic_t fscache_n_retrievals_intr;
53630-atomic_t fscache_n_retrievals_nomem;
53631-atomic_t fscache_n_retrievals_object_dead;
53632-atomic_t fscache_n_retrieval_ops;
53633-atomic_t fscache_n_retrieval_op_waits;
53634+atomic_unchecked_t fscache_n_retrievals;
53635+atomic_unchecked_t fscache_n_retrievals_ok;
53636+atomic_unchecked_t fscache_n_retrievals_wait;
53637+atomic_unchecked_t fscache_n_retrievals_nodata;
53638+atomic_unchecked_t fscache_n_retrievals_nobufs;
53639+atomic_unchecked_t fscache_n_retrievals_intr;
53640+atomic_unchecked_t fscache_n_retrievals_nomem;
53641+atomic_unchecked_t fscache_n_retrievals_object_dead;
53642+atomic_unchecked_t fscache_n_retrieval_ops;
53643+atomic_unchecked_t fscache_n_retrieval_op_waits;
53644
53645-atomic_t fscache_n_stores;
53646-atomic_t fscache_n_stores_ok;
53647-atomic_t fscache_n_stores_again;
53648-atomic_t fscache_n_stores_nobufs;
53649-atomic_t fscache_n_stores_oom;
53650-atomic_t fscache_n_store_ops;
53651-atomic_t fscache_n_store_calls;
53652-atomic_t fscache_n_store_pages;
53653-atomic_t fscache_n_store_radix_deletes;
53654-atomic_t fscache_n_store_pages_over_limit;
53655+atomic_unchecked_t fscache_n_stores;
53656+atomic_unchecked_t fscache_n_stores_ok;
53657+atomic_unchecked_t fscache_n_stores_again;
53658+atomic_unchecked_t fscache_n_stores_nobufs;
53659+atomic_unchecked_t fscache_n_stores_oom;
53660+atomic_unchecked_t fscache_n_store_ops;
53661+atomic_unchecked_t fscache_n_store_calls;
53662+atomic_unchecked_t fscache_n_store_pages;
53663+atomic_unchecked_t fscache_n_store_radix_deletes;
53664+atomic_unchecked_t fscache_n_store_pages_over_limit;
53665
53666-atomic_t fscache_n_store_vmscan_not_storing;
53667-atomic_t fscache_n_store_vmscan_gone;
53668-atomic_t fscache_n_store_vmscan_busy;
53669-atomic_t fscache_n_store_vmscan_cancelled;
53670-atomic_t fscache_n_store_vmscan_wait;
53671+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
53672+atomic_unchecked_t fscache_n_store_vmscan_gone;
53673+atomic_unchecked_t fscache_n_store_vmscan_busy;
53674+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
53675+atomic_unchecked_t fscache_n_store_vmscan_wait;
53676
53677-atomic_t fscache_n_marks;
53678-atomic_t fscache_n_uncaches;
53679+atomic_unchecked_t fscache_n_marks;
53680+atomic_unchecked_t fscache_n_uncaches;
53681
53682-atomic_t fscache_n_acquires;
53683-atomic_t fscache_n_acquires_null;
53684-atomic_t fscache_n_acquires_no_cache;
53685-atomic_t fscache_n_acquires_ok;
53686-atomic_t fscache_n_acquires_nobufs;
53687-atomic_t fscache_n_acquires_oom;
53688+atomic_unchecked_t fscache_n_acquires;
53689+atomic_unchecked_t fscache_n_acquires_null;
53690+atomic_unchecked_t fscache_n_acquires_no_cache;
53691+atomic_unchecked_t fscache_n_acquires_ok;
53692+atomic_unchecked_t fscache_n_acquires_nobufs;
53693+atomic_unchecked_t fscache_n_acquires_oom;
53694
53695-atomic_t fscache_n_invalidates;
53696-atomic_t fscache_n_invalidates_run;
53697+atomic_unchecked_t fscache_n_invalidates;
53698+atomic_unchecked_t fscache_n_invalidates_run;
53699
53700-atomic_t fscache_n_updates;
53701-atomic_t fscache_n_updates_null;
53702-atomic_t fscache_n_updates_run;
53703+atomic_unchecked_t fscache_n_updates;
53704+atomic_unchecked_t fscache_n_updates_null;
53705+atomic_unchecked_t fscache_n_updates_run;
53706
53707-atomic_t fscache_n_relinquishes;
53708-atomic_t fscache_n_relinquishes_null;
53709-atomic_t fscache_n_relinquishes_waitcrt;
53710-atomic_t fscache_n_relinquishes_retire;
53711+atomic_unchecked_t fscache_n_relinquishes;
53712+atomic_unchecked_t fscache_n_relinquishes_null;
53713+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
53714+atomic_unchecked_t fscache_n_relinquishes_retire;
53715
53716-atomic_t fscache_n_cookie_index;
53717-atomic_t fscache_n_cookie_data;
53718-atomic_t fscache_n_cookie_special;
53719+atomic_unchecked_t fscache_n_cookie_index;
53720+atomic_unchecked_t fscache_n_cookie_data;
53721+atomic_unchecked_t fscache_n_cookie_special;
53722
53723-atomic_t fscache_n_object_alloc;
53724-atomic_t fscache_n_object_no_alloc;
53725-atomic_t fscache_n_object_lookups;
53726-atomic_t fscache_n_object_lookups_negative;
53727-atomic_t fscache_n_object_lookups_positive;
53728-atomic_t fscache_n_object_lookups_timed_out;
53729-atomic_t fscache_n_object_created;
53730-atomic_t fscache_n_object_avail;
53731-atomic_t fscache_n_object_dead;
53732+atomic_unchecked_t fscache_n_object_alloc;
53733+atomic_unchecked_t fscache_n_object_no_alloc;
53734+atomic_unchecked_t fscache_n_object_lookups;
53735+atomic_unchecked_t fscache_n_object_lookups_negative;
53736+atomic_unchecked_t fscache_n_object_lookups_positive;
53737+atomic_unchecked_t fscache_n_object_lookups_timed_out;
53738+atomic_unchecked_t fscache_n_object_created;
53739+atomic_unchecked_t fscache_n_object_avail;
53740+atomic_unchecked_t fscache_n_object_dead;
53741
53742-atomic_t fscache_n_checkaux_none;
53743-atomic_t fscache_n_checkaux_okay;
53744-atomic_t fscache_n_checkaux_update;
53745-atomic_t fscache_n_checkaux_obsolete;
53746+atomic_unchecked_t fscache_n_checkaux_none;
53747+atomic_unchecked_t fscache_n_checkaux_okay;
53748+atomic_unchecked_t fscache_n_checkaux_update;
53749+atomic_unchecked_t fscache_n_checkaux_obsolete;
53750
53751 atomic_t fscache_n_cop_alloc_object;
53752 atomic_t fscache_n_cop_lookup_object;
53753@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
53754 seq_puts(m, "FS-Cache statistics\n");
53755
53756 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
53757- atomic_read(&fscache_n_cookie_index),
53758- atomic_read(&fscache_n_cookie_data),
53759- atomic_read(&fscache_n_cookie_special));
53760+ atomic_read_unchecked(&fscache_n_cookie_index),
53761+ atomic_read_unchecked(&fscache_n_cookie_data),
53762+ atomic_read_unchecked(&fscache_n_cookie_special));
53763
53764 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
53765- atomic_read(&fscache_n_object_alloc),
53766- atomic_read(&fscache_n_object_no_alloc),
53767- atomic_read(&fscache_n_object_avail),
53768- atomic_read(&fscache_n_object_dead));
53769+ atomic_read_unchecked(&fscache_n_object_alloc),
53770+ atomic_read_unchecked(&fscache_n_object_no_alloc),
53771+ atomic_read_unchecked(&fscache_n_object_avail),
53772+ atomic_read_unchecked(&fscache_n_object_dead));
53773 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
53774- atomic_read(&fscache_n_checkaux_none),
53775- atomic_read(&fscache_n_checkaux_okay),
53776- atomic_read(&fscache_n_checkaux_update),
53777- atomic_read(&fscache_n_checkaux_obsolete));
53778+ atomic_read_unchecked(&fscache_n_checkaux_none),
53779+ atomic_read_unchecked(&fscache_n_checkaux_okay),
53780+ atomic_read_unchecked(&fscache_n_checkaux_update),
53781+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
53782
53783 seq_printf(m, "Pages : mrk=%u unc=%u\n",
53784- atomic_read(&fscache_n_marks),
53785- atomic_read(&fscache_n_uncaches));
53786+ atomic_read_unchecked(&fscache_n_marks),
53787+ atomic_read_unchecked(&fscache_n_uncaches));
53788
53789 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
53790 " oom=%u\n",
53791- atomic_read(&fscache_n_acquires),
53792- atomic_read(&fscache_n_acquires_null),
53793- atomic_read(&fscache_n_acquires_no_cache),
53794- atomic_read(&fscache_n_acquires_ok),
53795- atomic_read(&fscache_n_acquires_nobufs),
53796- atomic_read(&fscache_n_acquires_oom));
53797+ atomic_read_unchecked(&fscache_n_acquires),
53798+ atomic_read_unchecked(&fscache_n_acquires_null),
53799+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
53800+ atomic_read_unchecked(&fscache_n_acquires_ok),
53801+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
53802+ atomic_read_unchecked(&fscache_n_acquires_oom));
53803
53804 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
53805- atomic_read(&fscache_n_object_lookups),
53806- atomic_read(&fscache_n_object_lookups_negative),
53807- atomic_read(&fscache_n_object_lookups_positive),
53808- atomic_read(&fscache_n_object_created),
53809- atomic_read(&fscache_n_object_lookups_timed_out));
53810+ atomic_read_unchecked(&fscache_n_object_lookups),
53811+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
53812+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
53813+ atomic_read_unchecked(&fscache_n_object_created),
53814+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
53815
53816 seq_printf(m, "Invals : n=%u run=%u\n",
53817- atomic_read(&fscache_n_invalidates),
53818- atomic_read(&fscache_n_invalidates_run));
53819+ atomic_read_unchecked(&fscache_n_invalidates),
53820+ atomic_read_unchecked(&fscache_n_invalidates_run));
53821
53822 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
53823- atomic_read(&fscache_n_updates),
53824- atomic_read(&fscache_n_updates_null),
53825- atomic_read(&fscache_n_updates_run));
53826+ atomic_read_unchecked(&fscache_n_updates),
53827+ atomic_read_unchecked(&fscache_n_updates_null),
53828+ atomic_read_unchecked(&fscache_n_updates_run));
53829
53830 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
53831- atomic_read(&fscache_n_relinquishes),
53832- atomic_read(&fscache_n_relinquishes_null),
53833- atomic_read(&fscache_n_relinquishes_waitcrt),
53834- atomic_read(&fscache_n_relinquishes_retire));
53835+ atomic_read_unchecked(&fscache_n_relinquishes),
53836+ atomic_read_unchecked(&fscache_n_relinquishes_null),
53837+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
53838+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
53839
53840 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
53841- atomic_read(&fscache_n_attr_changed),
53842- atomic_read(&fscache_n_attr_changed_ok),
53843- atomic_read(&fscache_n_attr_changed_nobufs),
53844- atomic_read(&fscache_n_attr_changed_nomem),
53845- atomic_read(&fscache_n_attr_changed_calls));
53846+ atomic_read_unchecked(&fscache_n_attr_changed),
53847+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
53848+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
53849+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
53850+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
53851
53852 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
53853- atomic_read(&fscache_n_allocs),
53854- atomic_read(&fscache_n_allocs_ok),
53855- atomic_read(&fscache_n_allocs_wait),
53856- atomic_read(&fscache_n_allocs_nobufs),
53857- atomic_read(&fscache_n_allocs_intr));
53858+ atomic_read_unchecked(&fscache_n_allocs),
53859+ atomic_read_unchecked(&fscache_n_allocs_ok),
53860+ atomic_read_unchecked(&fscache_n_allocs_wait),
53861+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
53862+ atomic_read_unchecked(&fscache_n_allocs_intr));
53863 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
53864- atomic_read(&fscache_n_alloc_ops),
53865- atomic_read(&fscache_n_alloc_op_waits),
53866- atomic_read(&fscache_n_allocs_object_dead));
53867+ atomic_read_unchecked(&fscache_n_alloc_ops),
53868+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
53869+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
53870
53871 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
53872 " int=%u oom=%u\n",
53873- atomic_read(&fscache_n_retrievals),
53874- atomic_read(&fscache_n_retrievals_ok),
53875- atomic_read(&fscache_n_retrievals_wait),
53876- atomic_read(&fscache_n_retrievals_nodata),
53877- atomic_read(&fscache_n_retrievals_nobufs),
53878- atomic_read(&fscache_n_retrievals_intr),
53879- atomic_read(&fscache_n_retrievals_nomem));
53880+ atomic_read_unchecked(&fscache_n_retrievals),
53881+ atomic_read_unchecked(&fscache_n_retrievals_ok),
53882+ atomic_read_unchecked(&fscache_n_retrievals_wait),
53883+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
53884+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
53885+ atomic_read_unchecked(&fscache_n_retrievals_intr),
53886+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
53887 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
53888- atomic_read(&fscache_n_retrieval_ops),
53889- atomic_read(&fscache_n_retrieval_op_waits),
53890- atomic_read(&fscache_n_retrievals_object_dead));
53891+ atomic_read_unchecked(&fscache_n_retrieval_ops),
53892+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
53893+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
53894
53895 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
53896- atomic_read(&fscache_n_stores),
53897- atomic_read(&fscache_n_stores_ok),
53898- atomic_read(&fscache_n_stores_again),
53899- atomic_read(&fscache_n_stores_nobufs),
53900- atomic_read(&fscache_n_stores_oom));
53901+ atomic_read_unchecked(&fscache_n_stores),
53902+ atomic_read_unchecked(&fscache_n_stores_ok),
53903+ atomic_read_unchecked(&fscache_n_stores_again),
53904+ atomic_read_unchecked(&fscache_n_stores_nobufs),
53905+ atomic_read_unchecked(&fscache_n_stores_oom));
53906 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
53907- atomic_read(&fscache_n_store_ops),
53908- atomic_read(&fscache_n_store_calls),
53909- atomic_read(&fscache_n_store_pages),
53910- atomic_read(&fscache_n_store_radix_deletes),
53911- atomic_read(&fscache_n_store_pages_over_limit));
53912+ atomic_read_unchecked(&fscache_n_store_ops),
53913+ atomic_read_unchecked(&fscache_n_store_calls),
53914+ atomic_read_unchecked(&fscache_n_store_pages),
53915+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
53916+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
53917
53918 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
53919- atomic_read(&fscache_n_store_vmscan_not_storing),
53920- atomic_read(&fscache_n_store_vmscan_gone),
53921- atomic_read(&fscache_n_store_vmscan_busy),
53922- atomic_read(&fscache_n_store_vmscan_cancelled),
53923- atomic_read(&fscache_n_store_vmscan_wait));
53924+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
53925+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
53926+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
53927+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
53928+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
53929
53930 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
53931- atomic_read(&fscache_n_op_pend),
53932- atomic_read(&fscache_n_op_run),
53933- atomic_read(&fscache_n_op_enqueue),
53934- atomic_read(&fscache_n_op_cancelled),
53935- atomic_read(&fscache_n_op_rejected));
53936+ atomic_read_unchecked(&fscache_n_op_pend),
53937+ atomic_read_unchecked(&fscache_n_op_run),
53938+ atomic_read_unchecked(&fscache_n_op_enqueue),
53939+ atomic_read_unchecked(&fscache_n_op_cancelled),
53940+ atomic_read_unchecked(&fscache_n_op_rejected));
53941 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
53942- atomic_read(&fscache_n_op_deferred_release),
53943- atomic_read(&fscache_n_op_release),
53944- atomic_read(&fscache_n_op_gc));
53945+ atomic_read_unchecked(&fscache_n_op_deferred_release),
53946+ atomic_read_unchecked(&fscache_n_op_release),
53947+ atomic_read_unchecked(&fscache_n_op_gc));
53948
53949 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
53950 atomic_read(&fscache_n_cop_alloc_object),
53951diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
53952index e397b67..b0d8709 100644
53953--- a/fs/fuse/cuse.c
53954+++ b/fs/fuse/cuse.c
53955@@ -593,10 +593,12 @@ static int __init cuse_init(void)
53956 INIT_LIST_HEAD(&cuse_conntbl[i]);
53957
53958 /* inherit and extend fuse_dev_operations */
53959- cuse_channel_fops = fuse_dev_operations;
53960- cuse_channel_fops.owner = THIS_MODULE;
53961- cuse_channel_fops.open = cuse_channel_open;
53962- cuse_channel_fops.release = cuse_channel_release;
53963+ pax_open_kernel();
53964+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
53965+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
53966+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
53967+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
53968+ pax_close_kernel();
53969
53970 cuse_class = class_create(THIS_MODULE, "cuse");
53971 if (IS_ERR(cuse_class))
53972diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
53973index e83351a..41e3c9c 100644
53974--- a/fs/fuse/dev.c
53975+++ b/fs/fuse/dev.c
53976@@ -1236,7 +1236,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
53977 ret = 0;
53978 pipe_lock(pipe);
53979
53980- if (!pipe->readers) {
53981+ if (!atomic_read(&pipe->readers)) {
53982 send_sig(SIGPIPE, current, 0);
53983 if (!ret)
53984 ret = -EPIPE;
53985diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
53986index 315e1f8..91f890c 100644
53987--- a/fs/fuse/dir.c
53988+++ b/fs/fuse/dir.c
53989@@ -1233,7 +1233,7 @@ static char *read_link(struct dentry *dentry)
53990 return link;
53991 }
53992
53993-static void free_link(char *link)
53994+static void free_link(const char *link)
53995 {
53996 if (!IS_ERR(link))
53997 free_page((unsigned long) link);
53998diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
53999index 2b6f569..fcb4d1f 100644
54000--- a/fs/gfs2/inode.c
54001+++ b/fs/gfs2/inode.c
54002@@ -1499,7 +1499,7 @@ out:
54003
54004 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
54005 {
54006- char *s = nd_get_link(nd);
54007+ const char *s = nd_get_link(nd);
54008 if (!IS_ERR(s))
54009 kfree(s);
54010 }
54011diff --git a/fs/hfsplus/extents.c b/fs/hfsplus/extents.c
54012index eba76eab..fc8ddc1 100644
54013--- a/fs/hfsplus/extents.c
54014+++ b/fs/hfsplus/extents.c
54015@@ -533,7 +533,7 @@ void hfsplus_file_truncate(struct inode *inode)
54016 struct address_space *mapping = inode->i_mapping;
54017 struct page *page;
54018 void *fsdata;
54019- u32 size = inode->i_size;
54020+ loff_t size = inode->i_size;
54021
54022 res = pagecache_write_begin(NULL, mapping, size, 0,
54023 AOP_FLAG_UNINTERRUPTIBLE,
54024diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
54025index 78bde32..767e906 100644
54026--- a/fs/hugetlbfs/inode.c
54027+++ b/fs/hugetlbfs/inode.c
54028@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
54029 struct mm_struct *mm = current->mm;
54030 struct vm_area_struct *vma;
54031 struct hstate *h = hstate_file(file);
54032+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
54033 struct vm_unmapped_area_info info;
54034
54035 if (len & ~huge_page_mask(h))
54036@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
54037 return addr;
54038 }
54039
54040+#ifdef CONFIG_PAX_RANDMMAP
54041+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
54042+#endif
54043+
54044 if (addr) {
54045 addr = ALIGN(addr, huge_page_size(h));
54046 vma = find_vma(mm, addr);
54047- if (TASK_SIZE - len >= addr &&
54048- (!vma || addr + len <= vma->vm_start))
54049+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
54050 return addr;
54051 }
54052
54053 info.flags = 0;
54054 info.length = len;
54055 info.low_limit = TASK_UNMAPPED_BASE;
54056+
54057+#ifdef CONFIG_PAX_RANDMMAP
54058+ if (mm->pax_flags & MF_PAX_RANDMMAP)
54059+ info.low_limit += mm->delta_mmap;
54060+#endif
54061+
54062 info.high_limit = TASK_SIZE;
54063 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
54064 info.align_offset = 0;
54065@@ -897,7 +907,7 @@ static struct file_system_type hugetlbfs_fs_type = {
54066 .kill_sb = kill_litter_super,
54067 };
54068
54069-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
54070+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
54071
54072 static int can_do_hugetlb_shm(void)
54073 {
54074diff --git a/fs/inode.c b/fs/inode.c
54075index b98540e..6a439ea 100644
54076--- a/fs/inode.c
54077+++ b/fs/inode.c
54078@@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
54079
54080 #ifdef CONFIG_SMP
54081 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
54082- static atomic_t shared_last_ino;
54083- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
54084+ static atomic_unchecked_t shared_last_ino;
54085+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
54086
54087 res = next - LAST_INO_BATCH;
54088 }
54089diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
54090index 4a6cf28..d3a29d3 100644
54091--- a/fs/jffs2/erase.c
54092+++ b/fs/jffs2/erase.c
54093@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
54094 struct jffs2_unknown_node marker = {
54095 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
54096 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
54097- .totlen = cpu_to_je32(c->cleanmarker_size)
54098+ .totlen = cpu_to_je32(c->cleanmarker_size),
54099+ .hdr_crc = cpu_to_je32(0)
54100 };
54101
54102 jffs2_prealloc_raw_node_refs(c, jeb, 1);
54103diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
54104index a6597d6..41b30ec 100644
54105--- a/fs/jffs2/wbuf.c
54106+++ b/fs/jffs2/wbuf.c
54107@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
54108 {
54109 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
54110 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
54111- .totlen = constant_cpu_to_je32(8)
54112+ .totlen = constant_cpu_to_je32(8),
54113+ .hdr_crc = constant_cpu_to_je32(0)
54114 };
54115
54116 /*
54117diff --git a/fs/jfs/super.c b/fs/jfs/super.c
54118index 1a543be..a4e1363 100644
54119--- a/fs/jfs/super.c
54120+++ b/fs/jfs/super.c
54121@@ -225,7 +225,7 @@ static const match_table_t tokens = {
54122 static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
54123 int *flag)
54124 {
54125- void *nls_map = (void *)-1; /* -1: no change; NULL: none */
54126+ const void *nls_map = (const void *)-1; /* -1: no change; NULL: none */
54127 char *p;
54128 struct jfs_sb_info *sbi = JFS_SBI(sb);
54129
54130@@ -253,7 +253,7 @@ static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
54131 /* Don't do anything ;-) */
54132 break;
54133 case Opt_iocharset:
54134- if (nls_map && nls_map != (void *) -1)
54135+ if (nls_map && nls_map != (const void *) -1)
54136 unload_nls(nls_map);
54137 if (!strcmp(args[0].from, "none"))
54138 nls_map = NULL;
54139@@ -855,7 +855,7 @@ static int __init init_jfs_fs(void)
54140
54141 jfs_inode_cachep =
54142 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
54143- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
54144+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
54145 init_once);
54146 if (jfs_inode_cachep == NULL)
54147 return -ENOMEM;
54148diff --git a/fs/libfs.c b/fs/libfs.c
54149index 916da8c..1588998 100644
54150--- a/fs/libfs.c
54151+++ b/fs/libfs.c
54152@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
54153
54154 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
54155 struct dentry *next;
54156+ char d_name[sizeof(next->d_iname)];
54157+ const unsigned char *name;
54158+
54159 next = list_entry(p, struct dentry, d_u.d_child);
54160 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
54161 if (!simple_positive(next)) {
54162@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
54163
54164 spin_unlock(&next->d_lock);
54165 spin_unlock(&dentry->d_lock);
54166- if (filldir(dirent, next->d_name.name,
54167+ name = next->d_name.name;
54168+ if (name == next->d_iname) {
54169+ memcpy(d_name, name, next->d_name.len);
54170+ name = d_name;
54171+ }
54172+ if (filldir(dirent, name,
54173 next->d_name.len, filp->f_pos,
54174 next->d_inode->i_ino,
54175 dt_type(next->d_inode)) < 0)
54176diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
54177index 52e5120..808936e 100644
54178--- a/fs/lockd/clntproc.c
54179+++ b/fs/lockd/clntproc.c
54180@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
54181 /*
54182 * Cookie counter for NLM requests
54183 */
54184-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
54185+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
54186
54187 void nlmclnt_next_cookie(struct nlm_cookie *c)
54188 {
54189- u32 cookie = atomic_inc_return(&nlm_cookie);
54190+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
54191
54192 memcpy(c->data, &cookie, 4);
54193 c->len=4;
54194diff --git a/fs/locks.c b/fs/locks.c
54195index a94e331..060bce3 100644
54196--- a/fs/locks.c
54197+++ b/fs/locks.c
54198@@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
54199 return;
54200
54201 if (filp->f_op && filp->f_op->flock) {
54202- struct file_lock fl = {
54203+ struct file_lock flock = {
54204 .fl_pid = current->tgid,
54205 .fl_file = filp,
54206 .fl_flags = FL_FLOCK,
54207 .fl_type = F_UNLCK,
54208 .fl_end = OFFSET_MAX,
54209 };
54210- filp->f_op->flock(filp, F_SETLKW, &fl);
54211- if (fl.fl_ops && fl.fl_ops->fl_release_private)
54212- fl.fl_ops->fl_release_private(&fl);
54213+ filp->f_op->flock(filp, F_SETLKW, &flock);
54214+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
54215+ flock.fl_ops->fl_release_private(&flock);
54216 }
54217
54218 lock_flocks();
54219diff --git a/fs/namei.c b/fs/namei.c
54220index ec97aef..e67718d 100644
54221--- a/fs/namei.c
54222+++ b/fs/namei.c
54223@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
54224 if (ret != -EACCES)
54225 return ret;
54226
54227+#ifdef CONFIG_GRKERNSEC
54228+ /* we'll block if we have to log due to a denied capability use */
54229+ if (mask & MAY_NOT_BLOCK)
54230+ return -ECHILD;
54231+#endif
54232+
54233 if (S_ISDIR(inode->i_mode)) {
54234 /* DACs are overridable for directories */
54235- if (inode_capable(inode, CAP_DAC_OVERRIDE))
54236- return 0;
54237 if (!(mask & MAY_WRITE))
54238- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
54239+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
54240+ inode_capable(inode, CAP_DAC_READ_SEARCH))
54241 return 0;
54242+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
54243+ return 0;
54244 return -EACCES;
54245 }
54246 /*
54247+ * Searching includes executable on directories, else just read.
54248+ */
54249+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
54250+ if (mask == MAY_READ)
54251+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
54252+ inode_capable(inode, CAP_DAC_READ_SEARCH))
54253+ return 0;
54254+
54255+ /*
54256 * Read/write DACs are always overridable.
54257 * Executable DACs are overridable when there is
54258 * at least one exec bit set.
54259@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
54260 if (inode_capable(inode, CAP_DAC_OVERRIDE))
54261 return 0;
54262
54263- /*
54264- * Searching includes executable on directories, else just read.
54265- */
54266- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
54267- if (mask == MAY_READ)
54268- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
54269- return 0;
54270-
54271 return -EACCES;
54272 }
54273
54274@@ -824,7 +832,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
54275 {
54276 struct dentry *dentry = link->dentry;
54277 int error;
54278- char *s;
54279+ const char *s;
54280
54281 BUG_ON(nd->flags & LOOKUP_RCU);
54282
54283@@ -845,6 +853,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
54284 if (error)
54285 goto out_put_nd_path;
54286
54287+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
54288+ dentry->d_inode, dentry, nd->path.mnt)) {
54289+ error = -EACCES;
54290+ goto out_put_nd_path;
54291+ }
54292+
54293 nd->last_type = LAST_BIND;
54294 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
54295 error = PTR_ERR(*p);
54296@@ -1594,6 +1608,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
54297 break;
54298 res = walk_component(nd, path, &nd->last,
54299 nd->last_type, LOOKUP_FOLLOW);
54300+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
54301+ res = -EACCES;
54302 put_link(nd, &link, cookie);
54303 } while (res > 0);
54304
54305@@ -1692,7 +1708,7 @@ EXPORT_SYMBOL(full_name_hash);
54306 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
54307 {
54308 unsigned long a, b, adata, bdata, mask, hash, len;
54309- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
54310+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
54311
54312 hash = a = 0;
54313 len = -sizeof(unsigned long);
54314@@ -1977,6 +1993,8 @@ static int path_lookupat(int dfd, const char *name,
54315 if (err)
54316 break;
54317 err = lookup_last(nd, &path);
54318+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
54319+ err = -EACCES;
54320 put_link(nd, &link, cookie);
54321 }
54322 }
54323@@ -1984,6 +2002,13 @@ static int path_lookupat(int dfd, const char *name,
54324 if (!err)
54325 err = complete_walk(nd);
54326
54327+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
54328+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
54329+ path_put(&nd->path);
54330+ err = -ENOENT;
54331+ }
54332+ }
54333+
54334 if (!err && nd->flags & LOOKUP_DIRECTORY) {
54335 if (!nd->inode->i_op->lookup) {
54336 path_put(&nd->path);
54337@@ -2011,8 +2036,15 @@ static int filename_lookup(int dfd, struct filename *name,
54338 retval = path_lookupat(dfd, name->name,
54339 flags | LOOKUP_REVAL, nd);
54340
54341- if (likely(!retval))
54342+ if (likely(!retval)) {
54343 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
54344+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
54345+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
54346+ path_put(&nd->path);
54347+ return -ENOENT;
54348+ }
54349+ }
54350+ }
54351 return retval;
54352 }
54353
54354@@ -2390,6 +2422,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
54355 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
54356 return -EPERM;
54357
54358+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
54359+ return -EPERM;
54360+ if (gr_handle_rawio(inode))
54361+ return -EPERM;
54362+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
54363+ return -EACCES;
54364+
54365 return 0;
54366 }
54367
54368@@ -2611,7 +2650,7 @@ looked_up:
54369 * cleared otherwise prior to returning.
54370 */
54371 static int lookup_open(struct nameidata *nd, struct path *path,
54372- struct file *file,
54373+ struct path *link, struct file *file,
54374 const struct open_flags *op,
54375 bool got_write, int *opened)
54376 {
54377@@ -2646,6 +2685,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
54378 /* Negative dentry, just create the file */
54379 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
54380 umode_t mode = op->mode;
54381+
54382+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
54383+ error = -EACCES;
54384+ goto out_dput;
54385+ }
54386+
54387+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
54388+ error = -EACCES;
54389+ goto out_dput;
54390+ }
54391+
54392 if (!IS_POSIXACL(dir->d_inode))
54393 mode &= ~current_umask();
54394 /*
54395@@ -2667,6 +2717,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
54396 nd->flags & LOOKUP_EXCL);
54397 if (error)
54398 goto out_dput;
54399+ else
54400+ gr_handle_create(dentry, nd->path.mnt);
54401 }
54402 out_no_open:
54403 path->dentry = dentry;
54404@@ -2681,7 +2733,7 @@ out_dput:
54405 /*
54406 * Handle the last step of open()
54407 */
54408-static int do_last(struct nameidata *nd, struct path *path,
54409+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
54410 struct file *file, const struct open_flags *op,
54411 int *opened, struct filename *name)
54412 {
54413@@ -2710,16 +2762,32 @@ static int do_last(struct nameidata *nd, struct path *path,
54414 error = complete_walk(nd);
54415 if (error)
54416 return error;
54417+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
54418+ error = -ENOENT;
54419+ goto out;
54420+ }
54421 audit_inode(name, nd->path.dentry, 0);
54422 if (open_flag & O_CREAT) {
54423 error = -EISDIR;
54424 goto out;
54425 }
54426+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
54427+ error = -EACCES;
54428+ goto out;
54429+ }
54430 goto finish_open;
54431 case LAST_BIND:
54432 error = complete_walk(nd);
54433 if (error)
54434 return error;
54435+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
54436+ error = -ENOENT;
54437+ goto out;
54438+ }
54439+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
54440+ error = -EACCES;
54441+ goto out;
54442+ }
54443 audit_inode(name, dir, 0);
54444 goto finish_open;
54445 }
54446@@ -2768,7 +2836,7 @@ retry_lookup:
54447 */
54448 }
54449 mutex_lock(&dir->d_inode->i_mutex);
54450- error = lookup_open(nd, path, file, op, got_write, opened);
54451+ error = lookup_open(nd, path, link, file, op, got_write, opened);
54452 mutex_unlock(&dir->d_inode->i_mutex);
54453
54454 if (error <= 0) {
54455@@ -2792,11 +2860,28 @@ retry_lookup:
54456 goto finish_open_created;
54457 }
54458
54459+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
54460+ error = -ENOENT;
54461+ goto exit_dput;
54462+ }
54463+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
54464+ error = -EACCES;
54465+ goto exit_dput;
54466+ }
54467+
54468 /*
54469 * create/update audit record if it already exists.
54470 */
54471- if (path->dentry->d_inode)
54472+ if (path->dentry->d_inode) {
54473+ /* only check if O_CREAT is specified, all other checks need to go
54474+ into may_open */
54475+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
54476+ error = -EACCES;
54477+ goto exit_dput;
54478+ }
54479+
54480 audit_inode(name, path->dentry, 0);
54481+ }
54482
54483 /*
54484 * If atomic_open() acquired write access it is dropped now due to
54485@@ -2837,6 +2922,11 @@ finish_lookup:
54486 }
54487 }
54488 BUG_ON(inode != path->dentry->d_inode);
54489+ /* if we're resolving a symlink to another symlink */
54490+ if (link && gr_handle_symlink_owner(link, inode)) {
54491+ error = -EACCES;
54492+ goto out;
54493+ }
54494 return 1;
54495 }
54496
54497@@ -2846,7 +2936,6 @@ finish_lookup:
54498 save_parent.dentry = nd->path.dentry;
54499 save_parent.mnt = mntget(path->mnt);
54500 nd->path.dentry = path->dentry;
54501-
54502 }
54503 nd->inode = inode;
54504 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
54505@@ -2855,6 +2944,16 @@ finish_lookup:
54506 path_put(&save_parent);
54507 return error;
54508 }
54509+
54510+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
54511+ error = -ENOENT;
54512+ goto out;
54513+ }
54514+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
54515+ error = -EACCES;
54516+ goto out;
54517+ }
54518+
54519 error = -EISDIR;
54520 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
54521 goto out;
54522@@ -2953,7 +3052,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
54523 if (unlikely(error))
54524 goto out;
54525
54526- error = do_last(nd, &path, file, op, &opened, pathname);
54527+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
54528 while (unlikely(error > 0)) { /* trailing symlink */
54529 struct path link = path;
54530 void *cookie;
54531@@ -2971,7 +3070,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
54532 error = follow_link(&link, nd, &cookie);
54533 if (unlikely(error))
54534 break;
54535- error = do_last(nd, &path, file, op, &opened, pathname);
54536+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
54537 put_link(nd, &link, cookie);
54538 }
54539 out:
54540@@ -3071,8 +3170,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
54541 goto unlock;
54542
54543 error = -EEXIST;
54544- if (dentry->d_inode)
54545+ if (dentry->d_inode) {
54546+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
54547+ error = -ENOENT;
54548+ }
54549 goto fail;
54550+ }
54551 /*
54552 * Special case - lookup gave negative, but... we had foo/bar/
54553 * From the vfs_mknod() POV we just have a negative dentry -
54554@@ -3124,6 +3227,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
54555 }
54556 EXPORT_SYMBOL(user_path_create);
54557
54558+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
54559+{
54560+ struct filename *tmp = getname(pathname);
54561+ struct dentry *res;
54562+ if (IS_ERR(tmp))
54563+ return ERR_CAST(tmp);
54564+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
54565+ if (IS_ERR(res))
54566+ putname(tmp);
54567+ else
54568+ *to = tmp;
54569+ return res;
54570+}
54571+
54572 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
54573 {
54574 int error = may_create(dir, dentry);
54575@@ -3186,6 +3303,17 @@ retry:
54576
54577 if (!IS_POSIXACL(path.dentry->d_inode))
54578 mode &= ~current_umask();
54579+
54580+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
54581+ error = -EPERM;
54582+ goto out;
54583+ }
54584+
54585+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
54586+ error = -EACCES;
54587+ goto out;
54588+ }
54589+
54590 error = security_path_mknod(&path, dentry, mode, dev);
54591 if (error)
54592 goto out;
54593@@ -3202,6 +3330,8 @@ retry:
54594 break;
54595 }
54596 out:
54597+ if (!error)
54598+ gr_handle_create(dentry, path.mnt);
54599 done_path_create(&path, dentry);
54600 if (retry_estale(error, lookup_flags)) {
54601 lookup_flags |= LOOKUP_REVAL;
54602@@ -3254,9 +3384,16 @@ retry:
54603
54604 if (!IS_POSIXACL(path.dentry->d_inode))
54605 mode &= ~current_umask();
54606+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
54607+ error = -EACCES;
54608+ goto out;
54609+ }
54610 error = security_path_mkdir(&path, dentry, mode);
54611 if (!error)
54612 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
54613+ if (!error)
54614+ gr_handle_create(dentry, path.mnt);
54615+out:
54616 done_path_create(&path, dentry);
54617 if (retry_estale(error, lookup_flags)) {
54618 lookup_flags |= LOOKUP_REVAL;
54619@@ -3337,6 +3474,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
54620 struct filename *name;
54621 struct dentry *dentry;
54622 struct nameidata nd;
54623+ ino_t saved_ino = 0;
54624+ dev_t saved_dev = 0;
54625 unsigned int lookup_flags = 0;
54626 retry:
54627 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
54628@@ -3369,10 +3508,21 @@ retry:
54629 error = -ENOENT;
54630 goto exit3;
54631 }
54632+
54633+ saved_ino = dentry->d_inode->i_ino;
54634+ saved_dev = gr_get_dev_from_dentry(dentry);
54635+
54636+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
54637+ error = -EACCES;
54638+ goto exit3;
54639+ }
54640+
54641 error = security_path_rmdir(&nd.path, dentry);
54642 if (error)
54643 goto exit3;
54644 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
54645+ if (!error && (saved_dev || saved_ino))
54646+ gr_handle_delete(saved_ino, saved_dev);
54647 exit3:
54648 dput(dentry);
54649 exit2:
54650@@ -3438,6 +3588,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
54651 struct dentry *dentry;
54652 struct nameidata nd;
54653 struct inode *inode = NULL;
54654+ ino_t saved_ino = 0;
54655+ dev_t saved_dev = 0;
54656 unsigned int lookup_flags = 0;
54657 retry:
54658 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
54659@@ -3464,10 +3616,22 @@ retry:
54660 if (!inode)
54661 goto slashes;
54662 ihold(inode);
54663+
54664+ if (inode->i_nlink <= 1) {
54665+ saved_ino = inode->i_ino;
54666+ saved_dev = gr_get_dev_from_dentry(dentry);
54667+ }
54668+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
54669+ error = -EACCES;
54670+ goto exit2;
54671+ }
54672+
54673 error = security_path_unlink(&nd.path, dentry);
54674 if (error)
54675 goto exit2;
54676 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
54677+ if (!error && (saved_ino || saved_dev))
54678+ gr_handle_delete(saved_ino, saved_dev);
54679 exit2:
54680 dput(dentry);
54681 }
54682@@ -3545,9 +3709,17 @@ retry:
54683 if (IS_ERR(dentry))
54684 goto out_putname;
54685
54686+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
54687+ error = -EACCES;
54688+ goto out;
54689+ }
54690+
54691 error = security_path_symlink(&path, dentry, from->name);
54692 if (!error)
54693 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
54694+ if (!error)
54695+ gr_handle_create(dentry, path.mnt);
54696+out:
54697 done_path_create(&path, dentry);
54698 if (retry_estale(error, lookup_flags)) {
54699 lookup_flags |= LOOKUP_REVAL;
54700@@ -3621,6 +3793,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
54701 {
54702 struct dentry *new_dentry;
54703 struct path old_path, new_path;
54704+ struct filename *to = NULL;
54705 int how = 0;
54706 int error;
54707
54708@@ -3644,7 +3817,7 @@ retry:
54709 if (error)
54710 return error;
54711
54712- new_dentry = user_path_create(newdfd, newname, &new_path,
54713+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
54714 (how & LOOKUP_REVAL));
54715 error = PTR_ERR(new_dentry);
54716 if (IS_ERR(new_dentry))
54717@@ -3656,11 +3829,28 @@ retry:
54718 error = may_linkat(&old_path);
54719 if (unlikely(error))
54720 goto out_dput;
54721+
54722+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
54723+ old_path.dentry->d_inode,
54724+ old_path.dentry->d_inode->i_mode, to)) {
54725+ error = -EACCES;
54726+ goto out_dput;
54727+ }
54728+
54729+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
54730+ old_path.dentry, old_path.mnt, to)) {
54731+ error = -EACCES;
54732+ goto out_dput;
54733+ }
54734+
54735 error = security_path_link(old_path.dentry, &new_path, new_dentry);
54736 if (error)
54737 goto out_dput;
54738 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
54739+ if (!error)
54740+ gr_handle_create(new_dentry, new_path.mnt);
54741 out_dput:
54742+ putname(to);
54743 done_path_create(&new_path, new_dentry);
54744 if (retry_estale(error, how)) {
54745 how |= LOOKUP_REVAL;
54746@@ -3906,12 +4096,21 @@ retry:
54747 if (new_dentry == trap)
54748 goto exit5;
54749
54750+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
54751+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
54752+ to);
54753+ if (error)
54754+ goto exit5;
54755+
54756 error = security_path_rename(&oldnd.path, old_dentry,
54757 &newnd.path, new_dentry);
54758 if (error)
54759 goto exit5;
54760 error = vfs_rename(old_dir->d_inode, old_dentry,
54761 new_dir->d_inode, new_dentry);
54762+ if (!error)
54763+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
54764+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
54765 exit5:
54766 dput(new_dentry);
54767 exit4:
54768@@ -3943,6 +4142,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
54769
54770 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
54771 {
54772+ char tmpbuf[64];
54773+ const char *newlink;
54774 int len;
54775
54776 len = PTR_ERR(link);
54777@@ -3952,7 +4153,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
54778 len = strlen(link);
54779 if (len > (unsigned) buflen)
54780 len = buflen;
54781- if (copy_to_user(buffer, link, len))
54782+
54783+ if (len < sizeof(tmpbuf)) {
54784+ memcpy(tmpbuf, link, len);
54785+ newlink = tmpbuf;
54786+ } else
54787+ newlink = link;
54788+
54789+ if (copy_to_user(buffer, newlink, len))
54790 len = -EFAULT;
54791 out:
54792 return len;
54793diff --git a/fs/namespace.c b/fs/namespace.c
54794index 5dd7709..6f64e9c 100644
54795--- a/fs/namespace.c
54796+++ b/fs/namespace.c
54797@@ -1219,6 +1219,9 @@ static int do_umount(struct mount *mnt, int flags)
54798 if (!(sb->s_flags & MS_RDONLY))
54799 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
54800 up_write(&sb->s_umount);
54801+
54802+ gr_log_remount(mnt->mnt_devname, retval);
54803+
54804 return retval;
54805 }
54806
54807@@ -1238,6 +1241,9 @@ static int do_umount(struct mount *mnt, int flags)
54808 br_write_unlock(&vfsmount_lock);
54809 up_write(&namespace_sem);
54810 release_mounts(&umount_list);
54811+
54812+ gr_log_unmount(mnt->mnt_devname, retval);
54813+
54814 return retval;
54815 }
54816
54817@@ -1713,7 +1719,7 @@ static int do_loopback(struct path *path, const char *old_name,
54818
54819 if (IS_ERR(mnt)) {
54820 err = PTR_ERR(mnt);
54821- goto out;
54822+ goto out2;
54823 }
54824
54825 err = graft_tree(mnt, path);
54826@@ -2294,6 +2300,16 @@ long do_mount(const char *dev_name, const char *dir_name,
54827 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
54828 MS_STRICTATIME);
54829
54830+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
54831+ retval = -EPERM;
54832+ goto dput_out;
54833+ }
54834+
54835+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
54836+ retval = -EPERM;
54837+ goto dput_out;
54838+ }
54839+
54840 if (flags & MS_REMOUNT)
54841 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
54842 data_page);
54843@@ -2308,6 +2324,9 @@ long do_mount(const char *dev_name, const char *dir_name,
54844 dev_name, data_page);
54845 dput_out:
54846 path_put(&path);
54847+
54848+ gr_log_mount(dev_name, dir_name, retval);
54849+
54850 return retval;
54851 }
54852
54853@@ -2594,6 +2613,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
54854 if (error)
54855 goto out2;
54856
54857+ if (gr_handle_chroot_pivot()) {
54858+ error = -EPERM;
54859+ goto out2;
54860+ }
54861+
54862 get_fs_root(current->fs, &root);
54863 error = lock_mount(&old);
54864 if (error)
54865@@ -2842,7 +2866,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
54866 !nsown_capable(CAP_SYS_ADMIN))
54867 return -EPERM;
54868
54869- if (fs->users != 1)
54870+ if (atomic_read(&fs->users) != 1)
54871 return -EINVAL;
54872
54873 get_mnt_ns(mnt_ns);
54874diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
54875index 59461c9..b17c57e 100644
54876--- a/fs/nfs/callback_xdr.c
54877+++ b/fs/nfs/callback_xdr.c
54878@@ -51,7 +51,7 @@ struct callback_op {
54879 callback_decode_arg_t decode_args;
54880 callback_encode_res_t encode_res;
54881 long res_maxsize;
54882-};
54883+} __do_const;
54884
54885 static struct callback_op callback_ops[];
54886
54887diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
54888index ebeb94c..ff35337 100644
54889--- a/fs/nfs/inode.c
54890+++ b/fs/nfs/inode.c
54891@@ -1042,16 +1042,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
54892 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
54893 }
54894
54895-static atomic_long_t nfs_attr_generation_counter;
54896+static atomic_long_unchecked_t nfs_attr_generation_counter;
54897
54898 static unsigned long nfs_read_attr_generation_counter(void)
54899 {
54900- return atomic_long_read(&nfs_attr_generation_counter);
54901+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
54902 }
54903
54904 unsigned long nfs_inc_attr_generation_counter(void)
54905 {
54906- return atomic_long_inc_return(&nfs_attr_generation_counter);
54907+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
54908 }
54909
54910 void nfs_fattr_init(struct nfs_fattr *fattr)
54911diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
54912index 9d1c5db..1e13db8 100644
54913--- a/fs/nfsd/nfs4proc.c
54914+++ b/fs/nfsd/nfs4proc.c
54915@@ -1097,7 +1097,7 @@ struct nfsd4_operation {
54916 nfsd4op_rsize op_rsize_bop;
54917 stateid_getter op_get_currentstateid;
54918 stateid_setter op_set_currentstateid;
54919-};
54920+} __do_const;
54921
54922 static struct nfsd4_operation nfsd4_ops[];
54923
54924diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
54925index d1dd710..32ac0e8 100644
54926--- a/fs/nfsd/nfs4xdr.c
54927+++ b/fs/nfsd/nfs4xdr.c
54928@@ -1456,7 +1456,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
54929
54930 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
54931
54932-static nfsd4_dec nfsd4_dec_ops[] = {
54933+static const nfsd4_dec nfsd4_dec_ops[] = {
54934 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
54935 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
54936 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
54937@@ -1496,7 +1496,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
54938 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
54939 };
54940
54941-static nfsd4_dec nfsd41_dec_ops[] = {
54942+static const nfsd4_dec nfsd41_dec_ops[] = {
54943 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
54944 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
54945 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
54946@@ -1558,7 +1558,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
54947 };
54948
54949 struct nfsd4_minorversion_ops {
54950- nfsd4_dec *decoders;
54951+ const nfsd4_dec *decoders;
54952 int nops;
54953 };
54954
54955diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
54956index 69c6413..c0408d2 100644
54957--- a/fs/nfsd/vfs.c
54958+++ b/fs/nfsd/vfs.c
54959@@ -939,7 +939,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
54960 } else {
54961 oldfs = get_fs();
54962 set_fs(KERNEL_DS);
54963- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
54964+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
54965 set_fs(oldfs);
54966 }
54967
54968@@ -1026,7 +1026,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
54969
54970 /* Write the data. */
54971 oldfs = get_fs(); set_fs(KERNEL_DS);
54972- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
54973+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
54974 set_fs(oldfs);
54975 if (host_err < 0)
54976 goto out_nfserr;
54977@@ -1572,7 +1572,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
54978 */
54979
54980 oldfs = get_fs(); set_fs(KERNEL_DS);
54981- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
54982+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
54983 set_fs(oldfs);
54984
54985 if (host_err < 0)
54986diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
54987index fea6bd5..8ee9d81 100644
54988--- a/fs/nls/nls_base.c
54989+++ b/fs/nls/nls_base.c
54990@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
54991
54992 int register_nls(struct nls_table * nls)
54993 {
54994- struct nls_table ** tmp = &tables;
54995+ struct nls_table *tmp = tables;
54996
54997 if (nls->next)
54998 return -EBUSY;
54999
55000 spin_lock(&nls_lock);
55001- while (*tmp) {
55002- if (nls == *tmp) {
55003+ while (tmp) {
55004+ if (nls == tmp) {
55005 spin_unlock(&nls_lock);
55006 return -EBUSY;
55007 }
55008- tmp = &(*tmp)->next;
55009+ tmp = tmp->next;
55010 }
55011- nls->next = tables;
55012+ pax_open_kernel();
55013+ *(struct nls_table **)&nls->next = tables;
55014+ pax_close_kernel();
55015 tables = nls;
55016 spin_unlock(&nls_lock);
55017 return 0;
55018@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
55019
55020 int unregister_nls(struct nls_table * nls)
55021 {
55022- struct nls_table ** tmp = &tables;
55023+ struct nls_table * const * tmp = &tables;
55024
55025 spin_lock(&nls_lock);
55026 while (*tmp) {
55027 if (nls == *tmp) {
55028- *tmp = nls->next;
55029+ pax_open_kernel();
55030+ *(struct nls_table **)tmp = nls->next;
55031+ pax_close_kernel();
55032 spin_unlock(&nls_lock);
55033 return 0;
55034 }
55035diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
55036index 7424929..35f6be5 100644
55037--- a/fs/nls/nls_euc-jp.c
55038+++ b/fs/nls/nls_euc-jp.c
55039@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
55040 p_nls = load_nls("cp932");
55041
55042 if (p_nls) {
55043- table.charset2upper = p_nls->charset2upper;
55044- table.charset2lower = p_nls->charset2lower;
55045+ pax_open_kernel();
55046+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
55047+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
55048+ pax_close_kernel();
55049 return register_nls(&table);
55050 }
55051
55052diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
55053index e7bc1d7..06bd4bb 100644
55054--- a/fs/nls/nls_koi8-ru.c
55055+++ b/fs/nls/nls_koi8-ru.c
55056@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
55057 p_nls = load_nls("koi8-u");
55058
55059 if (p_nls) {
55060- table.charset2upper = p_nls->charset2upper;
55061- table.charset2lower = p_nls->charset2lower;
55062+ pax_open_kernel();
55063+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
55064+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
55065+ pax_close_kernel();
55066 return register_nls(&table);
55067 }
55068
55069diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
55070index 9ff4a5e..deb1f0f 100644
55071--- a/fs/notify/fanotify/fanotify_user.c
55072+++ b/fs/notify/fanotify/fanotify_user.c
55073@@ -251,8 +251,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
55074
55075 fd = fanotify_event_metadata.fd;
55076 ret = -EFAULT;
55077- if (copy_to_user(buf, &fanotify_event_metadata,
55078- fanotify_event_metadata.event_len))
55079+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
55080+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
55081 goto out_close_fd;
55082
55083 ret = prepare_for_access_response(group, event, fd);
55084diff --git a/fs/notify/notification.c b/fs/notify/notification.c
55085index 7b51b05..5ea5ef6 100644
55086--- a/fs/notify/notification.c
55087+++ b/fs/notify/notification.c
55088@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
55089 * get set to 0 so it will never get 'freed'
55090 */
55091 static struct fsnotify_event *q_overflow_event;
55092-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
55093+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
55094
55095 /**
55096 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
55097@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
55098 */
55099 u32 fsnotify_get_cookie(void)
55100 {
55101- return atomic_inc_return(&fsnotify_sync_cookie);
55102+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
55103 }
55104 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
55105
55106diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
55107index 99e3610..02c1068 100644
55108--- a/fs/ntfs/dir.c
55109+++ b/fs/ntfs/dir.c
55110@@ -1329,7 +1329,7 @@ find_next_index_buffer:
55111 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
55112 ~(s64)(ndir->itype.index.block_size - 1)));
55113 /* Bounds checks. */
55114- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
55115+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
55116 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
55117 "inode 0x%lx or driver bug.", vdir->i_ino);
55118 goto err_out;
55119diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
55120index 5b2d4f0..c6de396 100644
55121--- a/fs/ntfs/file.c
55122+++ b/fs/ntfs/file.c
55123@@ -2242,6 +2242,6 @@ const struct inode_operations ntfs_file_inode_ops = {
55124 #endif /* NTFS_RW */
55125 };
55126
55127-const struct file_operations ntfs_empty_file_ops = {};
55128+const struct file_operations ntfs_empty_file_ops __read_only;
55129
55130-const struct inode_operations ntfs_empty_inode_ops = {};
55131+const struct inode_operations ntfs_empty_inode_ops __read_only;
55132diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
55133index a9f78c7..ed8a381 100644
55134--- a/fs/ocfs2/localalloc.c
55135+++ b/fs/ocfs2/localalloc.c
55136@@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
55137 goto bail;
55138 }
55139
55140- atomic_inc(&osb->alloc_stats.moves);
55141+ atomic_inc_unchecked(&osb->alloc_stats.moves);
55142
55143 bail:
55144 if (handle)
55145diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
55146index d355e6e..578d905 100644
55147--- a/fs/ocfs2/ocfs2.h
55148+++ b/fs/ocfs2/ocfs2.h
55149@@ -235,11 +235,11 @@ enum ocfs2_vol_state
55150
55151 struct ocfs2_alloc_stats
55152 {
55153- atomic_t moves;
55154- atomic_t local_data;
55155- atomic_t bitmap_data;
55156- atomic_t bg_allocs;
55157- atomic_t bg_extends;
55158+ atomic_unchecked_t moves;
55159+ atomic_unchecked_t local_data;
55160+ atomic_unchecked_t bitmap_data;
55161+ atomic_unchecked_t bg_allocs;
55162+ atomic_unchecked_t bg_extends;
55163 };
55164
55165 enum ocfs2_local_alloc_state
55166diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
55167index b7e74b5..19c6536 100644
55168--- a/fs/ocfs2/suballoc.c
55169+++ b/fs/ocfs2/suballoc.c
55170@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
55171 mlog_errno(status);
55172 goto bail;
55173 }
55174- atomic_inc(&osb->alloc_stats.bg_extends);
55175+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
55176
55177 /* You should never ask for this much metadata */
55178 BUG_ON(bits_wanted >
55179@@ -2007,7 +2007,7 @@ int ocfs2_claim_metadata(handle_t *handle,
55180 mlog_errno(status);
55181 goto bail;
55182 }
55183- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
55184+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
55185
55186 *suballoc_loc = res.sr_bg_blkno;
55187 *suballoc_bit_start = res.sr_bit_offset;
55188@@ -2171,7 +2171,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
55189 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
55190 res->sr_bits);
55191
55192- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
55193+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
55194
55195 BUG_ON(res->sr_bits != 1);
55196
55197@@ -2213,7 +2213,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
55198 mlog_errno(status);
55199 goto bail;
55200 }
55201- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
55202+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
55203
55204 BUG_ON(res.sr_bits != 1);
55205
55206@@ -2317,7 +2317,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
55207 cluster_start,
55208 num_clusters);
55209 if (!status)
55210- atomic_inc(&osb->alloc_stats.local_data);
55211+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
55212 } else {
55213 if (min_clusters > (osb->bitmap_cpg - 1)) {
55214 /* The only paths asking for contiguousness
55215@@ -2343,7 +2343,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
55216 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
55217 res.sr_bg_blkno,
55218 res.sr_bit_offset);
55219- atomic_inc(&osb->alloc_stats.bitmap_data);
55220+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
55221 *num_clusters = res.sr_bits;
55222 }
55223 }
55224diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
55225index 0e91ec2..f4b3fc6 100644
55226--- a/fs/ocfs2/super.c
55227+++ b/fs/ocfs2/super.c
55228@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
55229 "%10s => GlobalAllocs: %d LocalAllocs: %d "
55230 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
55231 "Stats",
55232- atomic_read(&osb->alloc_stats.bitmap_data),
55233- atomic_read(&osb->alloc_stats.local_data),
55234- atomic_read(&osb->alloc_stats.bg_allocs),
55235- atomic_read(&osb->alloc_stats.moves),
55236- atomic_read(&osb->alloc_stats.bg_extends));
55237+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
55238+ atomic_read_unchecked(&osb->alloc_stats.local_data),
55239+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
55240+ atomic_read_unchecked(&osb->alloc_stats.moves),
55241+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
55242
55243 out += snprintf(buf + out, len - out,
55244 "%10s => State: %u Descriptor: %llu Size: %u bits "
55245@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
55246 spin_lock_init(&osb->osb_xattr_lock);
55247 ocfs2_init_steal_slots(osb);
55248
55249- atomic_set(&osb->alloc_stats.moves, 0);
55250- atomic_set(&osb->alloc_stats.local_data, 0);
55251- atomic_set(&osb->alloc_stats.bitmap_data, 0);
55252- atomic_set(&osb->alloc_stats.bg_allocs, 0);
55253- atomic_set(&osb->alloc_stats.bg_extends, 0);
55254+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
55255+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
55256+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
55257+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
55258+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
55259
55260 /* Copy the blockcheck stats from the superblock probe */
55261 osb->osb_ecc_stats = *stats;
55262diff --git a/fs/open.c b/fs/open.c
55263index 9b33c0c..2ffcca2 100644
55264--- a/fs/open.c
55265+++ b/fs/open.c
55266@@ -31,6 +31,8 @@
55267 #include <linux/ima.h>
55268 #include <linux/dnotify.h>
55269
55270+#define CREATE_TRACE_POINTS
55271+#include <trace/events/fs.h>
55272 #include "internal.h"
55273
55274 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
55275@@ -101,6 +103,8 @@ long vfs_truncate(struct path *path, loff_t length)
55276 error = locks_verify_truncate(inode, NULL, length);
55277 if (!error)
55278 error = security_path_truncate(path);
55279+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
55280+ error = -EACCES;
55281 if (!error)
55282 error = do_truncate(path->dentry, length, 0, NULL);
55283
55284@@ -178,6 +182,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
55285 error = locks_verify_truncate(inode, f.file, length);
55286 if (!error)
55287 error = security_path_truncate(&f.file->f_path);
55288+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
55289+ error = -EACCES;
55290 if (!error)
55291 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
55292 sb_end_write(inode->i_sb);
55293@@ -373,6 +379,9 @@ retry:
55294 if (__mnt_is_readonly(path.mnt))
55295 res = -EROFS;
55296
55297+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
55298+ res = -EACCES;
55299+
55300 out_path_release:
55301 path_put(&path);
55302 if (retry_estale(res, lookup_flags)) {
55303@@ -404,6 +413,8 @@ retry:
55304 if (error)
55305 goto dput_and_out;
55306
55307+ gr_log_chdir(path.dentry, path.mnt);
55308+
55309 set_fs_pwd(current->fs, &path);
55310
55311 dput_and_out:
55312@@ -433,6 +444,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
55313 goto out_putf;
55314
55315 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
55316+
55317+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
55318+ error = -EPERM;
55319+
55320+ if (!error)
55321+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
55322+
55323 if (!error)
55324 set_fs_pwd(current->fs, &f.file->f_path);
55325 out_putf:
55326@@ -462,7 +480,13 @@ retry:
55327 if (error)
55328 goto dput_and_out;
55329
55330+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
55331+ goto dput_and_out;
55332+
55333 set_fs_root(current->fs, &path);
55334+
55335+ gr_handle_chroot_chdir(&path);
55336+
55337 error = 0;
55338 dput_and_out:
55339 path_put(&path);
55340@@ -484,6 +508,16 @@ static int chmod_common(struct path *path, umode_t mode)
55341 if (error)
55342 return error;
55343 mutex_lock(&inode->i_mutex);
55344+
55345+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
55346+ error = -EACCES;
55347+ goto out_unlock;
55348+ }
55349+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
55350+ error = -EACCES;
55351+ goto out_unlock;
55352+ }
55353+
55354 error = security_path_chmod(path, mode);
55355 if (error)
55356 goto out_unlock;
55357@@ -544,6 +578,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
55358 uid = make_kuid(current_user_ns(), user);
55359 gid = make_kgid(current_user_ns(), group);
55360
55361+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
55362+ return -EACCES;
55363+
55364 newattrs.ia_valid = ATTR_CTIME;
55365 if (user != (uid_t) -1) {
55366 if (!uid_valid(uid))
55367@@ -960,6 +997,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
55368 } else {
55369 fsnotify_open(f);
55370 fd_install(fd, f);
55371+ trace_do_sys_open(tmp->name, flags, mode);
55372 }
55373 }
55374 putname(tmp);
55375diff --git a/fs/pipe.c b/fs/pipe.c
55376index 8e2e73f..1ef1048 100644
55377--- a/fs/pipe.c
55378+++ b/fs/pipe.c
55379@@ -438,9 +438,9 @@ redo:
55380 }
55381 if (bufs) /* More to do? */
55382 continue;
55383- if (!pipe->writers)
55384+ if (!atomic_read(&pipe->writers))
55385 break;
55386- if (!pipe->waiting_writers) {
55387+ if (!atomic_read(&pipe->waiting_writers)) {
55388 /* syscall merging: Usually we must not sleep
55389 * if O_NONBLOCK is set, or if we got some data.
55390 * But if a writer sleeps in kernel space, then
55391@@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
55392 mutex_lock(&inode->i_mutex);
55393 pipe = inode->i_pipe;
55394
55395- if (!pipe->readers) {
55396+ if (!atomic_read(&pipe->readers)) {
55397 send_sig(SIGPIPE, current, 0);
55398 ret = -EPIPE;
55399 goto out;
55400@@ -553,7 +553,7 @@ redo1:
55401 for (;;) {
55402 int bufs;
55403
55404- if (!pipe->readers) {
55405+ if (!atomic_read(&pipe->readers)) {
55406 send_sig(SIGPIPE, current, 0);
55407 if (!ret)
55408 ret = -EPIPE;
55409@@ -644,9 +644,9 @@ redo2:
55410 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
55411 do_wakeup = 0;
55412 }
55413- pipe->waiting_writers++;
55414+ atomic_inc(&pipe->waiting_writers);
55415 pipe_wait(pipe);
55416- pipe->waiting_writers--;
55417+ atomic_dec(&pipe->waiting_writers);
55418 }
55419 out:
55420 mutex_unlock(&inode->i_mutex);
55421@@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
55422 mask = 0;
55423 if (filp->f_mode & FMODE_READ) {
55424 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
55425- if (!pipe->writers && filp->f_version != pipe->w_counter)
55426+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
55427 mask |= POLLHUP;
55428 }
55429
55430@@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
55431 * Most Unices do not set POLLERR for FIFOs but on Linux they
55432 * behave exactly like pipes for poll().
55433 */
55434- if (!pipe->readers)
55435+ if (!atomic_read(&pipe->readers))
55436 mask |= POLLERR;
55437 }
55438
55439@@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
55440
55441 mutex_lock(&inode->i_mutex);
55442 pipe = inode->i_pipe;
55443- pipe->readers -= decr;
55444- pipe->writers -= decw;
55445+ atomic_sub(decr, &pipe->readers);
55446+ atomic_sub(decw, &pipe->writers);
55447
55448- if (!pipe->readers && !pipe->writers) {
55449+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
55450 free_pipe_info(inode);
55451 } else {
55452 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
55453@@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
55454
55455 if (inode->i_pipe) {
55456 ret = 0;
55457- inode->i_pipe->readers++;
55458+ atomic_inc(&inode->i_pipe->readers);
55459 }
55460
55461 mutex_unlock(&inode->i_mutex);
55462@@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
55463
55464 if (inode->i_pipe) {
55465 ret = 0;
55466- inode->i_pipe->writers++;
55467+ atomic_inc(&inode->i_pipe->writers);
55468 }
55469
55470 mutex_unlock(&inode->i_mutex);
55471@@ -871,9 +871,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
55472 if (inode->i_pipe) {
55473 ret = 0;
55474 if (filp->f_mode & FMODE_READ)
55475- inode->i_pipe->readers++;
55476+ atomic_inc(&inode->i_pipe->readers);
55477 if (filp->f_mode & FMODE_WRITE)
55478- inode->i_pipe->writers++;
55479+ atomic_inc(&inode->i_pipe->writers);
55480 }
55481
55482 mutex_unlock(&inode->i_mutex);
55483@@ -965,7 +965,7 @@ void free_pipe_info(struct inode *inode)
55484 inode->i_pipe = NULL;
55485 }
55486
55487-static struct vfsmount *pipe_mnt __read_mostly;
55488+struct vfsmount *pipe_mnt __read_mostly;
55489
55490 /*
55491 * pipefs_dname() is called from d_path().
55492@@ -995,7 +995,8 @@ static struct inode * get_pipe_inode(void)
55493 goto fail_iput;
55494 inode->i_pipe = pipe;
55495
55496- pipe->readers = pipe->writers = 1;
55497+ atomic_set(&pipe->readers, 1);
55498+ atomic_set(&pipe->writers, 1);
55499 inode->i_fop = &rdwr_pipefifo_fops;
55500
55501 /*
55502diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
55503index 15af622..0e9f4467 100644
55504--- a/fs/proc/Kconfig
55505+++ b/fs/proc/Kconfig
55506@@ -30,12 +30,12 @@ config PROC_FS
55507
55508 config PROC_KCORE
55509 bool "/proc/kcore support" if !ARM
55510- depends on PROC_FS && MMU
55511+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
55512
55513 config PROC_VMCORE
55514 bool "/proc/vmcore support"
55515- depends on PROC_FS && CRASH_DUMP
55516- default y
55517+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
55518+ default n
55519 help
55520 Exports the dump image of crashed kernel in ELF format.
55521
55522@@ -59,8 +59,8 @@ config PROC_SYSCTL
55523 limited in memory.
55524
55525 config PROC_PAGE_MONITOR
55526- default y
55527- depends on PROC_FS && MMU
55528+ default n
55529+ depends on PROC_FS && MMU && !GRKERNSEC
55530 bool "Enable /proc page monitoring" if EXPERT
55531 help
55532 Various /proc files exist to monitor process memory utilization:
55533diff --git a/fs/proc/array.c b/fs/proc/array.c
55534index 6a91e6f..e54dbc14 100644
55535--- a/fs/proc/array.c
55536+++ b/fs/proc/array.c
55537@@ -60,6 +60,7 @@
55538 #include <linux/tty.h>
55539 #include <linux/string.h>
55540 #include <linux/mman.h>
55541+#include <linux/grsecurity.h>
55542 #include <linux/proc_fs.h>
55543 #include <linux/ioport.h>
55544 #include <linux/uaccess.h>
55545@@ -362,6 +363,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
55546 seq_putc(m, '\n');
55547 }
55548
55549+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55550+static inline void task_pax(struct seq_file *m, struct task_struct *p)
55551+{
55552+ if (p->mm)
55553+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
55554+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
55555+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
55556+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
55557+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
55558+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
55559+ else
55560+ seq_printf(m, "PaX:\t-----\n");
55561+}
55562+#endif
55563+
55564 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
55565 struct pid *pid, struct task_struct *task)
55566 {
55567@@ -380,9 +396,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
55568 task_cpus_allowed(m, task);
55569 cpuset_task_status_allowed(m, task);
55570 task_context_switch_counts(m, task);
55571+
55572+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55573+ task_pax(m, task);
55574+#endif
55575+
55576+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
55577+ task_grsec_rbac(m, task);
55578+#endif
55579+
55580 return 0;
55581 }
55582
55583+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55584+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
55585+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
55586+ _mm->pax_flags & MF_PAX_SEGMEXEC))
55587+#endif
55588+
55589 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55590 struct pid *pid, struct task_struct *task, int whole)
55591 {
55592@@ -404,6 +435,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55593 char tcomm[sizeof(task->comm)];
55594 unsigned long flags;
55595
55596+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55597+ if (current->exec_id != m->exec_id) {
55598+ gr_log_badprocpid("stat");
55599+ return 0;
55600+ }
55601+#endif
55602+
55603 state = *get_task_state(task);
55604 vsize = eip = esp = 0;
55605 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
55606@@ -475,6 +513,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55607 gtime = task->gtime;
55608 }
55609
55610+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55611+ if (PAX_RAND_FLAGS(mm)) {
55612+ eip = 0;
55613+ esp = 0;
55614+ wchan = 0;
55615+ }
55616+#endif
55617+#ifdef CONFIG_GRKERNSEC_HIDESYM
55618+ wchan = 0;
55619+ eip =0;
55620+ esp =0;
55621+#endif
55622+
55623 /* scale priority and nice values from timeslices to -20..20 */
55624 /* to make it look like a "normal" Unix priority/nice value */
55625 priority = task_prio(task);
55626@@ -511,9 +562,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55627 seq_put_decimal_ull(m, ' ', vsize);
55628 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
55629 seq_put_decimal_ull(m, ' ', rsslim);
55630+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55631+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
55632+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
55633+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
55634+#else
55635 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
55636 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
55637 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
55638+#endif
55639 seq_put_decimal_ull(m, ' ', esp);
55640 seq_put_decimal_ull(m, ' ', eip);
55641 /* The signal information here is obsolete.
55642@@ -535,7 +592,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55643 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
55644 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
55645
55646- if (mm && permitted) {
55647+ if (mm && permitted
55648+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55649+ && !PAX_RAND_FLAGS(mm)
55650+#endif
55651+ ) {
55652 seq_put_decimal_ull(m, ' ', mm->start_data);
55653 seq_put_decimal_ull(m, ' ', mm->end_data);
55654 seq_put_decimal_ull(m, ' ', mm->start_brk);
55655@@ -573,8 +634,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
55656 struct pid *pid, struct task_struct *task)
55657 {
55658 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
55659- struct mm_struct *mm = get_task_mm(task);
55660+ struct mm_struct *mm;
55661
55662+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55663+ if (current->exec_id != m->exec_id) {
55664+ gr_log_badprocpid("statm");
55665+ return 0;
55666+ }
55667+#endif
55668+ mm = get_task_mm(task);
55669 if (mm) {
55670 size = task_statm(mm, &shared, &text, &data, &resident);
55671 mmput(mm);
55672@@ -597,6 +665,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
55673 return 0;
55674 }
55675
55676+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
55677+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
55678+{
55679+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
55680+}
55681+#endif
55682+
55683 #ifdef CONFIG_CHECKPOINT_RESTORE
55684 static struct pid *
55685 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
55686diff --git a/fs/proc/base.c b/fs/proc/base.c
55687index 9b43ff77..0fa9564 100644
55688--- a/fs/proc/base.c
55689+++ b/fs/proc/base.c
55690@@ -111,6 +111,14 @@ struct pid_entry {
55691 union proc_op op;
55692 };
55693
55694+struct getdents_callback {
55695+ struct linux_dirent __user * current_dir;
55696+ struct linux_dirent __user * previous;
55697+ struct file * file;
55698+ int count;
55699+ int error;
55700+};
55701+
55702 #define NOD(NAME, MODE, IOP, FOP, OP) { \
55703 .name = (NAME), \
55704 .len = sizeof(NAME) - 1, \
55705@@ -208,6 +216,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
55706 if (!mm->arg_end)
55707 goto out_mm; /* Shh! No looking before we're done */
55708
55709+ if (gr_acl_handle_procpidmem(task))
55710+ goto out_mm;
55711+
55712 len = mm->arg_end - mm->arg_start;
55713
55714 if (len > PAGE_SIZE)
55715@@ -235,12 +246,28 @@ out:
55716 return res;
55717 }
55718
55719+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55720+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
55721+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
55722+ _mm->pax_flags & MF_PAX_SEGMEXEC))
55723+#endif
55724+
55725 static int proc_pid_auxv(struct task_struct *task, char *buffer)
55726 {
55727 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
55728 int res = PTR_ERR(mm);
55729 if (mm && !IS_ERR(mm)) {
55730 unsigned int nwords = 0;
55731+
55732+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55733+ /* allow if we're currently ptracing this task */
55734+ if (PAX_RAND_FLAGS(mm) &&
55735+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
55736+ mmput(mm);
55737+ return 0;
55738+ }
55739+#endif
55740+
55741 do {
55742 nwords += 2;
55743 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
55744@@ -254,7 +281,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
55745 }
55746
55747
55748-#ifdef CONFIG_KALLSYMS
55749+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55750 /*
55751 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
55752 * Returns the resolved symbol. If that fails, simply return the address.
55753@@ -293,7 +320,7 @@ static void unlock_trace(struct task_struct *task)
55754 mutex_unlock(&task->signal->cred_guard_mutex);
55755 }
55756
55757-#ifdef CONFIG_STACKTRACE
55758+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55759
55760 #define MAX_STACK_TRACE_DEPTH 64
55761
55762@@ -485,7 +512,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
55763 return count;
55764 }
55765
55766-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
55767+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
55768 static int proc_pid_syscall(struct task_struct *task, char *buffer)
55769 {
55770 long nr;
55771@@ -514,7 +541,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
55772 /************************************************************************/
55773
55774 /* permission checks */
55775-static int proc_fd_access_allowed(struct inode *inode)
55776+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
55777 {
55778 struct task_struct *task;
55779 int allowed = 0;
55780@@ -524,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
55781 */
55782 task = get_proc_task(inode);
55783 if (task) {
55784- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
55785+ if (log)
55786+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
55787+ else
55788+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
55789 put_task_struct(task);
55790 }
55791 return allowed;
55792@@ -555,10 +585,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
55793 struct task_struct *task,
55794 int hide_pid_min)
55795 {
55796+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55797+ return false;
55798+
55799+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55800+ rcu_read_lock();
55801+ {
55802+ const struct cred *tmpcred = current_cred();
55803+ const struct cred *cred = __task_cred(task);
55804+
55805+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
55806+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55807+ || in_group_p(grsec_proc_gid)
55808+#endif
55809+ ) {
55810+ rcu_read_unlock();
55811+ return true;
55812+ }
55813+ }
55814+ rcu_read_unlock();
55815+
55816+ if (!pid->hide_pid)
55817+ return false;
55818+#endif
55819+
55820 if (pid->hide_pid < hide_pid_min)
55821 return true;
55822 if (in_group_p(pid->pid_gid))
55823 return true;
55824+
55825 return ptrace_may_access(task, PTRACE_MODE_READ);
55826 }
55827
55828@@ -576,7 +631,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
55829 put_task_struct(task);
55830
55831 if (!has_perms) {
55832+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55833+ {
55834+#else
55835 if (pid->hide_pid == 2) {
55836+#endif
55837 /*
55838 * Let's make getdents(), stat(), and open()
55839 * consistent with each other. If a process
55840@@ -674,6 +733,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
55841 if (!task)
55842 return -ESRCH;
55843
55844+ if (gr_acl_handle_procpidmem(task)) {
55845+ put_task_struct(task);
55846+ return -EPERM;
55847+ }
55848+
55849 mm = mm_access(task, mode);
55850 put_task_struct(task);
55851
55852@@ -689,6 +753,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
55853
55854 file->private_data = mm;
55855
55856+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55857+ file->f_version = current->exec_id;
55858+#endif
55859+
55860 return 0;
55861 }
55862
55863@@ -710,6 +778,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
55864 ssize_t copied;
55865 char *page;
55866
55867+#ifdef CONFIG_GRKERNSEC
55868+ if (write)
55869+ return -EPERM;
55870+#endif
55871+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55872+ if (file->f_version != current->exec_id) {
55873+ gr_log_badprocpid("mem");
55874+ return 0;
55875+ }
55876+#endif
55877+
55878 if (!mm)
55879 return 0;
55880
55881@@ -722,7 +801,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
55882 goto free;
55883
55884 while (count > 0) {
55885- int this_len = min_t(int, count, PAGE_SIZE);
55886+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
55887
55888 if (write && copy_from_user(page, buf, this_len)) {
55889 copied = -EFAULT;
55890@@ -814,6 +893,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
55891 if (!mm)
55892 return 0;
55893
55894+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55895+ if (file->f_version != current->exec_id) {
55896+ gr_log_badprocpid("environ");
55897+ return 0;
55898+ }
55899+#endif
55900+
55901 page = (char *)__get_free_page(GFP_TEMPORARY);
55902 if (!page)
55903 return -ENOMEM;
55904@@ -823,7 +909,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
55905 goto free;
55906 while (count > 0) {
55907 size_t this_len, max_len;
55908- int retval;
55909+ ssize_t retval;
55910
55911 if (src >= (mm->env_end - mm->env_start))
55912 break;
55913@@ -1429,7 +1515,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
55914 int error = -EACCES;
55915
55916 /* Are we allowed to snoop on the tasks file descriptors? */
55917- if (!proc_fd_access_allowed(inode))
55918+ if (!proc_fd_access_allowed(inode, 0))
55919 goto out;
55920
55921 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
55922@@ -1473,8 +1559,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
55923 struct path path;
55924
55925 /* Are we allowed to snoop on the tasks file descriptors? */
55926- if (!proc_fd_access_allowed(inode))
55927- goto out;
55928+ /* logging this is needed for learning on chromium to work properly,
55929+ but we don't want to flood the logs from 'ps' which does a readlink
55930+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
55931+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
55932+ */
55933+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
55934+ if (!proc_fd_access_allowed(inode,0))
55935+ goto out;
55936+ } else {
55937+ if (!proc_fd_access_allowed(inode,1))
55938+ goto out;
55939+ }
55940
55941 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
55942 if (error)
55943@@ -1524,7 +1620,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
55944 rcu_read_lock();
55945 cred = __task_cred(task);
55946 inode->i_uid = cred->euid;
55947+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55948+ inode->i_gid = grsec_proc_gid;
55949+#else
55950 inode->i_gid = cred->egid;
55951+#endif
55952 rcu_read_unlock();
55953 }
55954 security_task_to_inode(task, inode);
55955@@ -1560,10 +1660,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
55956 return -ENOENT;
55957 }
55958 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
55959+#ifdef CONFIG_GRKERNSEC_PROC_USER
55960+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
55961+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55962+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
55963+#endif
55964 task_dumpable(task)) {
55965 cred = __task_cred(task);
55966 stat->uid = cred->euid;
55967+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55968+ stat->gid = grsec_proc_gid;
55969+#else
55970 stat->gid = cred->egid;
55971+#endif
55972 }
55973 }
55974 rcu_read_unlock();
55975@@ -1601,11 +1710,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
55976
55977 if (task) {
55978 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
55979+#ifdef CONFIG_GRKERNSEC_PROC_USER
55980+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
55981+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55982+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
55983+#endif
55984 task_dumpable(task)) {
55985 rcu_read_lock();
55986 cred = __task_cred(task);
55987 inode->i_uid = cred->euid;
55988+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55989+ inode->i_gid = grsec_proc_gid;
55990+#else
55991 inode->i_gid = cred->egid;
55992+#endif
55993 rcu_read_unlock();
55994 } else {
55995 inode->i_uid = GLOBAL_ROOT_UID;
55996@@ -2058,6 +2176,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
55997 if (!task)
55998 goto out_no_task;
55999
56000+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
56001+ goto out;
56002+
56003 /*
56004 * Yes, it does not scale. And it should not. Don't add
56005 * new entries into /proc/<tgid>/ without very good reasons.
56006@@ -2102,6 +2223,9 @@ static int proc_pident_readdir(struct file *filp,
56007 if (!task)
56008 goto out_no_task;
56009
56010+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
56011+ goto out;
56012+
56013 ret = 0;
56014 i = filp->f_pos;
56015 switch (i) {
56016@@ -2515,7 +2639,7 @@ static const struct pid_entry tgid_base_stuff[] = {
56017 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
56018 #endif
56019 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
56020-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
56021+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
56022 INF("syscall", S_IRUGO, proc_pid_syscall),
56023 #endif
56024 INF("cmdline", S_IRUGO, proc_pid_cmdline),
56025@@ -2540,10 +2664,10 @@ static const struct pid_entry tgid_base_stuff[] = {
56026 #ifdef CONFIG_SECURITY
56027 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
56028 #endif
56029-#ifdef CONFIG_KALLSYMS
56030+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
56031 INF("wchan", S_IRUGO, proc_pid_wchan),
56032 #endif
56033-#ifdef CONFIG_STACKTRACE
56034+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
56035 ONE("stack", S_IRUGO, proc_pid_stack),
56036 #endif
56037 #ifdef CONFIG_SCHEDSTATS
56038@@ -2577,6 +2701,9 @@ static const struct pid_entry tgid_base_stuff[] = {
56039 #ifdef CONFIG_HARDWALL
56040 INF("hardwall", S_IRUGO, proc_pid_hardwall),
56041 #endif
56042+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
56043+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
56044+#endif
56045 #ifdef CONFIG_USER_NS
56046 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
56047 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
56048@@ -2705,7 +2832,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
56049 if (!inode)
56050 goto out;
56051
56052+#ifdef CONFIG_GRKERNSEC_PROC_USER
56053+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
56054+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
56055+ inode->i_gid = grsec_proc_gid;
56056+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
56057+#else
56058 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
56059+#endif
56060 inode->i_op = &proc_tgid_base_inode_operations;
56061 inode->i_fop = &proc_tgid_base_operations;
56062 inode->i_flags|=S_IMMUTABLE;
56063@@ -2743,7 +2877,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
56064 if (!task)
56065 goto out;
56066
56067+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
56068+ goto out_put_task;
56069+
56070 result = proc_pid_instantiate(dir, dentry, task, NULL);
56071+out_put_task:
56072 put_task_struct(task);
56073 out:
56074 return result;
56075@@ -2806,6 +2944,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
56076 static int fake_filldir(void *buf, const char *name, int namelen,
56077 loff_t offset, u64 ino, unsigned d_type)
56078 {
56079+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
56080+ __buf->error = -EINVAL;
56081 return 0;
56082 }
56083
56084@@ -2857,7 +2997,7 @@ static const struct pid_entry tid_base_stuff[] = {
56085 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
56086 #endif
56087 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
56088-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
56089+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
56090 INF("syscall", S_IRUGO, proc_pid_syscall),
56091 #endif
56092 INF("cmdline", S_IRUGO, proc_pid_cmdline),
56093@@ -2884,10 +3024,10 @@ static const struct pid_entry tid_base_stuff[] = {
56094 #ifdef CONFIG_SECURITY
56095 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
56096 #endif
56097-#ifdef CONFIG_KALLSYMS
56098+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
56099 INF("wchan", S_IRUGO, proc_pid_wchan),
56100 #endif
56101-#ifdef CONFIG_STACKTRACE
56102+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
56103 ONE("stack", S_IRUGO, proc_pid_stack),
56104 #endif
56105 #ifdef CONFIG_SCHEDSTATS
56106diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
56107index 82676e3..5f8518a 100644
56108--- a/fs/proc/cmdline.c
56109+++ b/fs/proc/cmdline.c
56110@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
56111
56112 static int __init proc_cmdline_init(void)
56113 {
56114+#ifdef CONFIG_GRKERNSEC_PROC_ADD
56115+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
56116+#else
56117 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
56118+#endif
56119 return 0;
56120 }
56121 module_init(proc_cmdline_init);
56122diff --git a/fs/proc/devices.c b/fs/proc/devices.c
56123index b143471..bb105e5 100644
56124--- a/fs/proc/devices.c
56125+++ b/fs/proc/devices.c
56126@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
56127
56128 static int __init proc_devices_init(void)
56129 {
56130+#ifdef CONFIG_GRKERNSEC_PROC_ADD
56131+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
56132+#else
56133 proc_create("devices", 0, NULL, &proc_devinfo_operations);
56134+#endif
56135 return 0;
56136 }
56137 module_init(proc_devices_init);
56138diff --git a/fs/proc/fd.c b/fs/proc/fd.c
56139index d7a4a28..0201742 100644
56140--- a/fs/proc/fd.c
56141+++ b/fs/proc/fd.c
56142@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
56143 if (!task)
56144 return -ENOENT;
56145
56146- files = get_files_struct(task);
56147+ if (!gr_acl_handle_procpidmem(task))
56148+ files = get_files_struct(task);
56149 put_task_struct(task);
56150
56151 if (files) {
56152@@ -302,11 +303,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
56153 */
56154 int proc_fd_permission(struct inode *inode, int mask)
56155 {
56156+ struct task_struct *task;
56157 int rv = generic_permission(inode, mask);
56158- if (rv == 0)
56159- return 0;
56160+
56161 if (task_pid(current) == proc_pid(inode))
56162 rv = 0;
56163+
56164+ task = get_proc_task(inode);
56165+ if (task == NULL)
56166+ return rv;
56167+
56168+ if (gr_acl_handle_procpidmem(task))
56169+ rv = -EACCES;
56170+
56171+ put_task_struct(task);
56172+
56173 return rv;
56174 }
56175
56176diff --git a/fs/proc/inode.c b/fs/proc/inode.c
56177index 0ac1e1b..0497e58 100644
56178--- a/fs/proc/inode.c
56179+++ b/fs/proc/inode.c
56180@@ -21,11 +21,17 @@
56181 #include <linux/seq_file.h>
56182 #include <linux/slab.h>
56183 #include <linux/mount.h>
56184+#include <linux/grsecurity.h>
56185
56186 #include <asm/uaccess.h>
56187
56188 #include "internal.h"
56189
56190+#ifdef CONFIG_PROC_SYSCTL
56191+extern const struct inode_operations proc_sys_inode_operations;
56192+extern const struct inode_operations proc_sys_dir_operations;
56193+#endif
56194+
56195 static void proc_evict_inode(struct inode *inode)
56196 {
56197 struct proc_dir_entry *de;
56198@@ -53,6 +59,13 @@ static void proc_evict_inode(struct inode *inode)
56199 ns = PROC_I(inode)->ns;
56200 if (ns_ops && ns)
56201 ns_ops->put(ns);
56202+
56203+#ifdef CONFIG_PROC_SYSCTL
56204+ if (inode->i_op == &proc_sys_inode_operations ||
56205+ inode->i_op == &proc_sys_dir_operations)
56206+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
56207+#endif
56208+
56209 }
56210
56211 static struct kmem_cache * proc_inode_cachep;
56212@@ -455,7 +468,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
56213 if (de->mode) {
56214 inode->i_mode = de->mode;
56215 inode->i_uid = de->uid;
56216+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
56217+ inode->i_gid = grsec_proc_gid;
56218+#else
56219 inode->i_gid = de->gid;
56220+#endif
56221 }
56222 if (de->size)
56223 inode->i_size = de->size;
56224diff --git a/fs/proc/internal.h b/fs/proc/internal.h
56225index 252544c..04395b9 100644
56226--- a/fs/proc/internal.h
56227+++ b/fs/proc/internal.h
56228@@ -55,6 +55,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
56229 struct pid *pid, struct task_struct *task);
56230 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
56231 struct pid *pid, struct task_struct *task);
56232+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
56233+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
56234+#endif
56235 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
56236
56237 extern const struct file_operations proc_tid_children_operations;
56238diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
56239index e96d4f1..8b116ed 100644
56240--- a/fs/proc/kcore.c
56241+++ b/fs/proc/kcore.c
56242@@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
56243 * the addresses in the elf_phdr on our list.
56244 */
56245 start = kc_offset_to_vaddr(*fpos - elf_buflen);
56246- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
56247+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
56248+ if (tsz > buflen)
56249 tsz = buflen;
56250-
56251+
56252 while (buflen) {
56253 struct kcore_list *m;
56254
56255@@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
56256 kfree(elf_buf);
56257 } else {
56258 if (kern_addr_valid(start)) {
56259- unsigned long n;
56260+ char *elf_buf;
56261+ mm_segment_t oldfs;
56262
56263- n = copy_to_user(buffer, (char *)start, tsz);
56264- /*
56265- * We cannot distinguish between fault on source
56266- * and fault on destination. When this happens
56267- * we clear too and hope it will trigger the
56268- * EFAULT again.
56269- */
56270- if (n) {
56271- if (clear_user(buffer + tsz - n,
56272- n))
56273+ elf_buf = kmalloc(tsz, GFP_KERNEL);
56274+ if (!elf_buf)
56275+ return -ENOMEM;
56276+ oldfs = get_fs();
56277+ set_fs(KERNEL_DS);
56278+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
56279+ set_fs(oldfs);
56280+ if (copy_to_user(buffer, elf_buf, tsz)) {
56281+ kfree(elf_buf);
56282 return -EFAULT;
56283+ }
56284 }
56285+ set_fs(oldfs);
56286+ kfree(elf_buf);
56287 } else {
56288 if (clear_user(buffer, tsz))
56289 return -EFAULT;
56290@@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
56291
56292 static int open_kcore(struct inode *inode, struct file *filp)
56293 {
56294+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
56295+ return -EPERM;
56296+#endif
56297 if (!capable(CAP_SYS_RAWIO))
56298 return -EPERM;
56299 if (kcore_need_update)
56300diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
56301index 80e4645..53e5fcf 100644
56302--- a/fs/proc/meminfo.c
56303+++ b/fs/proc/meminfo.c
56304@@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
56305 vmi.used >> 10,
56306 vmi.largest_chunk >> 10
56307 #ifdef CONFIG_MEMORY_FAILURE
56308- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
56309+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
56310 #endif
56311 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
56312 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
56313diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
56314index b1822dd..df622cb 100644
56315--- a/fs/proc/nommu.c
56316+++ b/fs/proc/nommu.c
56317@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
56318 if (len < 1)
56319 len = 1;
56320 seq_printf(m, "%*c", len, ' ');
56321- seq_path(m, &file->f_path, "");
56322+ seq_path(m, &file->f_path, "\n\\");
56323 }
56324
56325 seq_putc(m, '\n');
56326diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
56327index fe72cd0..21b52ff 100644
56328--- a/fs/proc/proc_net.c
56329+++ b/fs/proc/proc_net.c
56330@@ -23,6 +23,7 @@
56331 #include <linux/nsproxy.h>
56332 #include <net/net_namespace.h>
56333 #include <linux/seq_file.h>
56334+#include <linux/grsecurity.h>
56335
56336 #include "internal.h"
56337
56338@@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
56339 struct task_struct *task;
56340 struct nsproxy *ns;
56341 struct net *net = NULL;
56342+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
56343+ const struct cred *cred = current_cred();
56344+#endif
56345+
56346+#ifdef CONFIG_GRKERNSEC_PROC_USER
56347+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
56348+ return net;
56349+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
56350+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
56351+ return net;
56352+#endif
56353
56354 rcu_read_lock();
56355 task = pid_task(proc_pid(dir), PIDTYPE_PID);
56356diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
56357index 1827d88..43b0279 100644
56358--- a/fs/proc/proc_sysctl.c
56359+++ b/fs/proc/proc_sysctl.c
56360@@ -12,11 +12,15 @@
56361 #include <linux/module.h>
56362 #include "internal.h"
56363
56364+extern int gr_handle_chroot_sysctl(const int op);
56365+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
56366+ const int op);
56367+
56368 static const struct dentry_operations proc_sys_dentry_operations;
56369 static const struct file_operations proc_sys_file_operations;
56370-static const struct inode_operations proc_sys_inode_operations;
56371+const struct inode_operations proc_sys_inode_operations;
56372 static const struct file_operations proc_sys_dir_file_operations;
56373-static const struct inode_operations proc_sys_dir_operations;
56374+const struct inode_operations proc_sys_dir_operations;
56375
56376 void proc_sys_poll_notify(struct ctl_table_poll *poll)
56377 {
56378@@ -466,6 +470,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
56379
56380 err = NULL;
56381 d_set_d_op(dentry, &proc_sys_dentry_operations);
56382+
56383+ gr_handle_proc_create(dentry, inode);
56384+
56385 d_add(dentry, inode);
56386
56387 out:
56388@@ -481,6 +488,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
56389 struct inode *inode = filp->f_path.dentry->d_inode;
56390 struct ctl_table_header *head = grab_header(inode);
56391 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
56392+ int op = write ? MAY_WRITE : MAY_READ;
56393 ssize_t error;
56394 size_t res;
56395
56396@@ -492,7 +500,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
56397 * and won't be until we finish.
56398 */
56399 error = -EPERM;
56400- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
56401+ if (sysctl_perm(head, table, op))
56402 goto out;
56403
56404 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
56405@@ -500,6 +508,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
56406 if (!table->proc_handler)
56407 goto out;
56408
56409+#ifdef CONFIG_GRKERNSEC
56410+ error = -EPERM;
56411+ if (gr_handle_chroot_sysctl(op))
56412+ goto out;
56413+ dget(filp->f_path.dentry);
56414+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
56415+ dput(filp->f_path.dentry);
56416+ goto out;
56417+ }
56418+ dput(filp->f_path.dentry);
56419+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
56420+ goto out;
56421+ if (write && !capable(CAP_SYS_ADMIN))
56422+ goto out;
56423+#endif
56424+
56425 /* careful: calling conventions are nasty here */
56426 res = count;
56427 error = table->proc_handler(table, write, buf, &res, ppos);
56428@@ -597,6 +621,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
56429 return -ENOMEM;
56430 } else {
56431 d_set_d_op(child, &proc_sys_dentry_operations);
56432+
56433+ gr_handle_proc_create(child, inode);
56434+
56435 d_add(child, inode);
56436 }
56437 } else {
56438@@ -640,6 +667,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
56439 if ((*pos)++ < file->f_pos)
56440 return 0;
56441
56442+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
56443+ return 0;
56444+
56445 if (unlikely(S_ISLNK(table->mode)))
56446 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
56447 else
56448@@ -750,6 +780,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
56449 if (IS_ERR(head))
56450 return PTR_ERR(head);
56451
56452+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
56453+ return -ENOENT;
56454+
56455 generic_fillattr(inode, stat);
56456 if (table)
56457 stat->mode = (stat->mode & S_IFMT) | table->mode;
56458@@ -772,13 +805,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
56459 .llseek = generic_file_llseek,
56460 };
56461
56462-static const struct inode_operations proc_sys_inode_operations = {
56463+const struct inode_operations proc_sys_inode_operations = {
56464 .permission = proc_sys_permission,
56465 .setattr = proc_sys_setattr,
56466 .getattr = proc_sys_getattr,
56467 };
56468
56469-static const struct inode_operations proc_sys_dir_operations = {
56470+const struct inode_operations proc_sys_dir_operations = {
56471 .lookup = proc_sys_lookup,
56472 .permission = proc_sys_permission,
56473 .setattr = proc_sys_setattr,
56474@@ -854,7 +887,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
56475 static struct ctl_dir *new_dir(struct ctl_table_set *set,
56476 const char *name, int namelen)
56477 {
56478- struct ctl_table *table;
56479+ ctl_table_no_const *table;
56480 struct ctl_dir *new;
56481 struct ctl_node *node;
56482 char *new_name;
56483@@ -866,7 +899,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
56484 return NULL;
56485
56486 node = (struct ctl_node *)(new + 1);
56487- table = (struct ctl_table *)(node + 1);
56488+ table = (ctl_table_no_const *)(node + 1);
56489 new_name = (char *)(table + 2);
56490 memcpy(new_name, name, namelen);
56491 new_name[namelen] = '\0';
56492@@ -1035,7 +1068,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
56493 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
56494 struct ctl_table_root *link_root)
56495 {
56496- struct ctl_table *link_table, *entry, *link;
56497+ ctl_table_no_const *link_table, *link;
56498+ struct ctl_table *entry;
56499 struct ctl_table_header *links;
56500 struct ctl_node *node;
56501 char *link_name;
56502@@ -1058,7 +1092,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
56503 return NULL;
56504
56505 node = (struct ctl_node *)(links + 1);
56506- link_table = (struct ctl_table *)(node + nr_entries);
56507+ link_table = (ctl_table_no_const *)(node + nr_entries);
56508 link_name = (char *)&link_table[nr_entries + 1];
56509
56510 for (link = link_table, entry = table; entry->procname; link++, entry++) {
56511@@ -1306,8 +1340,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
56512 struct ctl_table_header ***subheader, struct ctl_table_set *set,
56513 struct ctl_table *table)
56514 {
56515- struct ctl_table *ctl_table_arg = NULL;
56516- struct ctl_table *entry, *files;
56517+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
56518+ struct ctl_table *entry;
56519 int nr_files = 0;
56520 int nr_dirs = 0;
56521 int err = -ENOMEM;
56522@@ -1319,10 +1353,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
56523 nr_files++;
56524 }
56525
56526- files = table;
56527 /* If there are mixed files and directories we need a new table */
56528 if (nr_dirs && nr_files) {
56529- struct ctl_table *new;
56530+ ctl_table_no_const *new;
56531 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
56532 GFP_KERNEL);
56533 if (!files)
56534@@ -1340,7 +1373,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
56535 /* Register everything except a directory full of subdirectories */
56536 if (nr_files || !nr_dirs) {
56537 struct ctl_table_header *header;
56538- header = __register_sysctl_table(set, path, files);
56539+ header = __register_sysctl_table(set, path, files ? files : table);
56540 if (!header) {
56541 kfree(ctl_table_arg);
56542 goto out;
56543diff --git a/fs/proc/root.c b/fs/proc/root.c
56544index 9c7fab1..ed1c8e0 100644
56545--- a/fs/proc/root.c
56546+++ b/fs/proc/root.c
56547@@ -180,7 +180,15 @@ void __init proc_root_init(void)
56548 #ifdef CONFIG_PROC_DEVICETREE
56549 proc_device_tree_init();
56550 #endif
56551+#ifdef CONFIG_GRKERNSEC_PROC_ADD
56552+#ifdef CONFIG_GRKERNSEC_PROC_USER
56553+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
56554+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
56555+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
56556+#endif
56557+#else
56558 proc_mkdir("bus", NULL);
56559+#endif
56560 proc_sys_init();
56561 }
56562
56563diff --git a/fs/proc/self.c b/fs/proc/self.c
56564index aa5cc3b..c91a5d0 100644
56565--- a/fs/proc/self.c
56566+++ b/fs/proc/self.c
56567@@ -37,7 +37,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
56568 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
56569 void *cookie)
56570 {
56571- char *s = nd_get_link(nd);
56572+ const char *s = nd_get_link(nd);
56573 if (!IS_ERR(s))
56574 kfree(s);
56575 }
56576diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
56577index ca5ce7f..02c1cf0 100644
56578--- a/fs/proc/task_mmu.c
56579+++ b/fs/proc/task_mmu.c
56580@@ -11,12 +11,19 @@
56581 #include <linux/rmap.h>
56582 #include <linux/swap.h>
56583 #include <linux/swapops.h>
56584+#include <linux/grsecurity.h>
56585
56586 #include <asm/elf.h>
56587 #include <asm/uaccess.h>
56588 #include <asm/tlbflush.h>
56589 #include "internal.h"
56590
56591+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56592+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
56593+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
56594+ _mm->pax_flags & MF_PAX_SEGMEXEC))
56595+#endif
56596+
56597 void task_mem(struct seq_file *m, struct mm_struct *mm)
56598 {
56599 unsigned long data, text, lib, swap;
56600@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
56601 "VmExe:\t%8lu kB\n"
56602 "VmLib:\t%8lu kB\n"
56603 "VmPTE:\t%8lu kB\n"
56604- "VmSwap:\t%8lu kB\n",
56605- hiwater_vm << (PAGE_SHIFT-10),
56606+ "VmSwap:\t%8lu kB\n"
56607+
56608+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56609+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
56610+#endif
56611+
56612+ ,hiwater_vm << (PAGE_SHIFT-10),
56613 total_vm << (PAGE_SHIFT-10),
56614 mm->locked_vm << (PAGE_SHIFT-10),
56615 mm->pinned_vm << (PAGE_SHIFT-10),
56616@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
56617 data << (PAGE_SHIFT-10),
56618 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
56619 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
56620- swap << (PAGE_SHIFT-10));
56621+ swap << (PAGE_SHIFT-10)
56622+
56623+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56624+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56625+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
56626+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
56627+#else
56628+ , mm->context.user_cs_base
56629+ , mm->context.user_cs_limit
56630+#endif
56631+#endif
56632+
56633+ );
56634 }
56635
56636 unsigned long task_vsize(struct mm_struct *mm)
56637@@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56638 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
56639 }
56640
56641- /* We don't show the stack guard page in /proc/maps */
56642+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56643+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
56644+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
56645+#else
56646 start = vma->vm_start;
56647- if (stack_guard_page_start(vma, start))
56648- start += PAGE_SIZE;
56649 end = vma->vm_end;
56650- if (stack_guard_page_end(vma, end))
56651- end -= PAGE_SIZE;
56652+#endif
56653
56654 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
56655 start,
56656@@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56657 flags & VM_WRITE ? 'w' : '-',
56658 flags & VM_EXEC ? 'x' : '-',
56659 flags & VM_MAYSHARE ? 's' : 'p',
56660+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56661+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
56662+#else
56663 pgoff,
56664+#endif
56665 MAJOR(dev), MINOR(dev), ino, &len);
56666
56667 /*
56668@@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56669 */
56670 if (file) {
56671 pad_len_spaces(m, len);
56672- seq_path(m, &file->f_path, "\n");
56673+ seq_path(m, &file->f_path, "\n\\");
56674 goto done;
56675 }
56676
56677@@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56678 * Thread stack in /proc/PID/task/TID/maps or
56679 * the main process stack.
56680 */
56681- if (!is_pid || (vma->vm_start <= mm->start_stack &&
56682- vma->vm_end >= mm->start_stack)) {
56683+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
56684+ (vma->vm_start <= mm->start_stack &&
56685+ vma->vm_end >= mm->start_stack)) {
56686 name = "[stack]";
56687 } else {
56688 /* Thread stack in /proc/PID/maps */
56689@@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
56690 struct proc_maps_private *priv = m->private;
56691 struct task_struct *task = priv->task;
56692
56693+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56694+ if (current->exec_id != m->exec_id) {
56695+ gr_log_badprocpid("maps");
56696+ return 0;
56697+ }
56698+#endif
56699+
56700 show_map_vma(m, vma, is_pid);
56701
56702 if (m->count < m->size) /* vma is copied successfully */
56703@@ -589,12 +625,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
56704 .private = &mss,
56705 };
56706
56707+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56708+ if (current->exec_id != m->exec_id) {
56709+ gr_log_badprocpid("smaps");
56710+ return 0;
56711+ }
56712+#endif
56713 memset(&mss, 0, sizeof mss);
56714- mss.vma = vma;
56715- /* mmap_sem is held in m_start */
56716- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
56717- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
56718-
56719+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56720+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
56721+#endif
56722+ mss.vma = vma;
56723+ /* mmap_sem is held in m_start */
56724+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
56725+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
56726+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56727+ }
56728+#endif
56729 show_map_vma(m, vma, is_pid);
56730
56731 seq_printf(m,
56732@@ -612,7 +659,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
56733 "KernelPageSize: %8lu kB\n"
56734 "MMUPageSize: %8lu kB\n"
56735 "Locked: %8lu kB\n",
56736+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56737+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
56738+#else
56739 (vma->vm_end - vma->vm_start) >> 10,
56740+#endif
56741 mss.resident >> 10,
56742 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
56743 mss.shared_clean >> 10,
56744@@ -1264,6 +1315,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
56745 int n;
56746 char buffer[50];
56747
56748+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56749+ if (current->exec_id != m->exec_id) {
56750+ gr_log_badprocpid("numa_maps");
56751+ return 0;
56752+ }
56753+#endif
56754+
56755 if (!mm)
56756 return 0;
56757
56758@@ -1281,11 +1339,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
56759 mpol_to_str(buffer, sizeof(buffer), pol);
56760 mpol_cond_put(pol);
56761
56762+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56763+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
56764+#else
56765 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
56766+#endif
56767
56768 if (file) {
56769 seq_printf(m, " file=");
56770- seq_path(m, &file->f_path, "\n\t= ");
56771+ seq_path(m, &file->f_path, "\n\t\\= ");
56772 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
56773 seq_printf(m, " heap");
56774 } else {
56775diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
56776index 1ccfa53..0848f95 100644
56777--- a/fs/proc/task_nommu.c
56778+++ b/fs/proc/task_nommu.c
56779@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
56780 else
56781 bytes += kobjsize(mm);
56782
56783- if (current->fs && current->fs->users > 1)
56784+ if (current->fs && atomic_read(&current->fs->users) > 1)
56785 sbytes += kobjsize(current->fs);
56786 else
56787 bytes += kobjsize(current->fs);
56788@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
56789
56790 if (file) {
56791 pad_len_spaces(m, len);
56792- seq_path(m, &file->f_path, "");
56793+ seq_path(m, &file->f_path, "\n\\");
56794 } else if (mm) {
56795 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
56796
56797diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
56798index b00fcc9..e0c6381 100644
56799--- a/fs/qnx6/qnx6.h
56800+++ b/fs/qnx6/qnx6.h
56801@@ -74,7 +74,7 @@ enum {
56802 BYTESEX_BE,
56803 };
56804
56805-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
56806+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
56807 {
56808 if (sbi->s_bytesex == BYTESEX_LE)
56809 return le64_to_cpu((__force __le64)n);
56810@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
56811 return (__force __fs64)cpu_to_be64(n);
56812 }
56813
56814-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
56815+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
56816 {
56817 if (sbi->s_bytesex == BYTESEX_LE)
56818 return le32_to_cpu((__force __le32)n);
56819diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
56820index 16e8abb..2dcf914 100644
56821--- a/fs/quota/netlink.c
56822+++ b/fs/quota/netlink.c
56823@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
56824 void quota_send_warning(struct kqid qid, dev_t dev,
56825 const char warntype)
56826 {
56827- static atomic_t seq;
56828+ static atomic_unchecked_t seq;
56829 struct sk_buff *skb;
56830 void *msg_head;
56831 int ret;
56832@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
56833 "VFS: Not enough memory to send quota warning.\n");
56834 return;
56835 }
56836- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
56837+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
56838 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
56839 if (!msg_head) {
56840 printk(KERN_ERR
56841diff --git a/fs/readdir.c b/fs/readdir.c
56842index 5e69ef5..e5d9099 100644
56843--- a/fs/readdir.c
56844+++ b/fs/readdir.c
56845@@ -17,6 +17,7 @@
56846 #include <linux/security.h>
56847 #include <linux/syscalls.h>
56848 #include <linux/unistd.h>
56849+#include <linux/namei.h>
56850
56851 #include <asm/uaccess.h>
56852
56853@@ -67,6 +68,7 @@ struct old_linux_dirent {
56854
56855 struct readdir_callback {
56856 struct old_linux_dirent __user * dirent;
56857+ struct file * file;
56858 int result;
56859 };
56860
56861@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
56862 buf->result = -EOVERFLOW;
56863 return -EOVERFLOW;
56864 }
56865+
56866+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56867+ return 0;
56868+
56869 buf->result++;
56870 dirent = buf->dirent;
56871 if (!access_ok(VERIFY_WRITE, dirent,
56872@@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
56873
56874 buf.result = 0;
56875 buf.dirent = dirent;
56876+ buf.file = f.file;
56877
56878 error = vfs_readdir(f.file, fillonedir, &buf);
56879 if (buf.result)
56880@@ -139,6 +146,7 @@ struct linux_dirent {
56881 struct getdents_callback {
56882 struct linux_dirent __user * current_dir;
56883 struct linux_dirent __user * previous;
56884+ struct file * file;
56885 int count;
56886 int error;
56887 };
56888@@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
56889 buf->error = -EOVERFLOW;
56890 return -EOVERFLOW;
56891 }
56892+
56893+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56894+ return 0;
56895+
56896 dirent = buf->previous;
56897 if (dirent) {
56898 if (__put_user(offset, &dirent->d_off))
56899@@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
56900 buf.previous = NULL;
56901 buf.count = count;
56902 buf.error = 0;
56903+ buf.file = f.file;
56904
56905 error = vfs_readdir(f.file, filldir, &buf);
56906 if (error >= 0)
56907@@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
56908 struct getdents_callback64 {
56909 struct linux_dirent64 __user * current_dir;
56910 struct linux_dirent64 __user * previous;
56911+ struct file *file;
56912 int count;
56913 int error;
56914 };
56915@@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
56916 buf->error = -EINVAL; /* only used if we fail.. */
56917 if (reclen > buf->count)
56918 return -EINVAL;
56919+
56920+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56921+ return 0;
56922+
56923 dirent = buf->previous;
56924 if (dirent) {
56925 if (__put_user(offset, &dirent->d_off))
56926@@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
56927
56928 buf.current_dir = dirent;
56929 buf.previous = NULL;
56930+ buf.file = f.file;
56931 buf.count = count;
56932 buf.error = 0;
56933
56934@@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
56935 error = buf.error;
56936 lastdirent = buf.previous;
56937 if (lastdirent) {
56938- typeof(lastdirent->d_off) d_off = f.file->f_pos;
56939+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
56940 if (__put_user(d_off, &lastdirent->d_off))
56941 error = -EFAULT;
56942 else
56943diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
56944index 2b7882b..1c5ef48 100644
56945--- a/fs/reiserfs/do_balan.c
56946+++ b/fs/reiserfs/do_balan.c
56947@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
56948 return;
56949 }
56950
56951- atomic_inc(&(fs_generation(tb->tb_sb)));
56952+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
56953 do_balance_starts(tb);
56954
56955 /* balance leaf returns 0 except if combining L R and S into
56956diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
56957index e60e870..f40ac16 100644
56958--- a/fs/reiserfs/procfs.c
56959+++ b/fs/reiserfs/procfs.c
56960@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
56961 "SMALL_TAILS " : "NO_TAILS ",
56962 replay_only(sb) ? "REPLAY_ONLY " : "",
56963 convert_reiserfs(sb) ? "CONV " : "",
56964- atomic_read(&r->s_generation_counter),
56965+ atomic_read_unchecked(&r->s_generation_counter),
56966 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
56967 SF(s_do_balance), SF(s_unneeded_left_neighbor),
56968 SF(s_good_search_by_key_reada), SF(s_bmaps),
56969diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
56970index 157e474..65a6114 100644
56971--- a/fs/reiserfs/reiserfs.h
56972+++ b/fs/reiserfs/reiserfs.h
56973@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
56974 /* Comment? -Hans */
56975 wait_queue_head_t s_wait;
56976 /* To be obsoleted soon by per buffer seals.. -Hans */
56977- atomic_t s_generation_counter; // increased by one every time the
56978+ atomic_unchecked_t s_generation_counter; // increased by one every time the
56979 // tree gets re-balanced
56980 unsigned long s_properties; /* File system properties. Currently holds
56981 on-disk FS format */
56982@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
56983 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
56984
56985 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
56986-#define get_generation(s) atomic_read (&fs_generation(s))
56987+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
56988 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
56989 #define __fs_changed(gen,s) (gen != get_generation (s))
56990 #define fs_changed(gen,s) \
56991diff --git a/fs/select.c b/fs/select.c
56992index 2ef72d9..f213b17 100644
56993--- a/fs/select.c
56994+++ b/fs/select.c
56995@@ -20,6 +20,7 @@
56996 #include <linux/export.h>
56997 #include <linux/slab.h>
56998 #include <linux/poll.h>
56999+#include <linux/security.h>
57000 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
57001 #include <linux/file.h>
57002 #include <linux/fdtable.h>
57003@@ -826,6 +827,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
57004 struct poll_list *walk = head;
57005 unsigned long todo = nfds;
57006
57007+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
57008 if (nfds > rlimit(RLIMIT_NOFILE))
57009 return -EINVAL;
57010
57011diff --git a/fs/seq_file.c b/fs/seq_file.c
57012index f2bc3df..239d4f6 100644
57013--- a/fs/seq_file.c
57014+++ b/fs/seq_file.c
57015@@ -10,6 +10,7 @@
57016 #include <linux/seq_file.h>
57017 #include <linux/slab.h>
57018 #include <linux/cred.h>
57019+#include <linux/sched.h>
57020
57021 #include <asm/uaccess.h>
57022 #include <asm/page.h>
57023@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
57024 #ifdef CONFIG_USER_NS
57025 p->user_ns = file->f_cred->user_ns;
57026 #endif
57027+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
57028+ p->exec_id = current->exec_id;
57029+#endif
57030
57031 /*
57032 * Wrappers around seq_open(e.g. swaps_open) need to be
57033@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
57034 return 0;
57035 }
57036 if (!m->buf) {
57037- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
57038+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
57039 if (!m->buf)
57040 return -ENOMEM;
57041 }
57042@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
57043 Eoverflow:
57044 m->op->stop(m, p);
57045 kfree(m->buf);
57046- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
57047+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
57048 return !m->buf ? -ENOMEM : -EAGAIN;
57049 }
57050
57051@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
57052
57053 /* grab buffer if we didn't have one */
57054 if (!m->buf) {
57055- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
57056+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
57057 if (!m->buf)
57058 goto Enomem;
57059 }
57060@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
57061 goto Fill;
57062 m->op->stop(m, p);
57063 kfree(m->buf);
57064- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
57065+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
57066 if (!m->buf)
57067 goto Enomem;
57068 m->count = 0;
57069@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
57070 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
57071 void *data)
57072 {
57073- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
57074+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
57075 int res = -ENOMEM;
57076
57077 if (op) {
57078diff --git a/fs/splice.c b/fs/splice.c
57079index 6909d89..5b2e8f9 100644
57080--- a/fs/splice.c
57081+++ b/fs/splice.c
57082@@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
57083 pipe_lock(pipe);
57084
57085 for (;;) {
57086- if (!pipe->readers) {
57087+ if (!atomic_read(&pipe->readers)) {
57088 send_sig(SIGPIPE, current, 0);
57089 if (!ret)
57090 ret = -EPIPE;
57091@@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
57092 do_wakeup = 0;
57093 }
57094
57095- pipe->waiting_writers++;
57096+ atomic_inc(&pipe->waiting_writers);
57097 pipe_wait(pipe);
57098- pipe->waiting_writers--;
57099+ atomic_dec(&pipe->waiting_writers);
57100 }
57101
57102 pipe_unlock(pipe);
57103@@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
57104 old_fs = get_fs();
57105 set_fs(get_ds());
57106 /* The cast to a user pointer is valid due to the set_fs() */
57107- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
57108+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
57109 set_fs(old_fs);
57110
57111 return res;
57112@@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
57113 old_fs = get_fs();
57114 set_fs(get_ds());
57115 /* The cast to a user pointer is valid due to the set_fs() */
57116- res = vfs_write(file, (const char __user *)buf, count, &pos);
57117+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
57118 set_fs(old_fs);
57119
57120 return res;
57121@@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
57122 goto err;
57123
57124 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
57125- vec[i].iov_base = (void __user *) page_address(page);
57126+ vec[i].iov_base = (void __force_user *) page_address(page);
57127 vec[i].iov_len = this_len;
57128 spd.pages[i] = page;
57129 spd.nr_pages++;
57130@@ -851,10 +851,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
57131 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
57132 {
57133 while (!pipe->nrbufs) {
57134- if (!pipe->writers)
57135+ if (!atomic_read(&pipe->writers))
57136 return 0;
57137
57138- if (!pipe->waiting_writers && sd->num_spliced)
57139+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
57140 return 0;
57141
57142 if (sd->flags & SPLICE_F_NONBLOCK)
57143@@ -1189,7 +1189,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
57144 * out of the pipe right after the splice_to_pipe(). So set
57145 * PIPE_READERS appropriately.
57146 */
57147- pipe->readers = 1;
57148+ atomic_set(&pipe->readers, 1);
57149
57150 current->splice_pipe = pipe;
57151 }
57152@@ -1738,9 +1738,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
57153 ret = -ERESTARTSYS;
57154 break;
57155 }
57156- if (!pipe->writers)
57157+ if (!atomic_read(&pipe->writers))
57158 break;
57159- if (!pipe->waiting_writers) {
57160+ if (!atomic_read(&pipe->waiting_writers)) {
57161 if (flags & SPLICE_F_NONBLOCK) {
57162 ret = -EAGAIN;
57163 break;
57164@@ -1772,7 +1772,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
57165 pipe_lock(pipe);
57166
57167 while (pipe->nrbufs >= pipe->buffers) {
57168- if (!pipe->readers) {
57169+ if (!atomic_read(&pipe->readers)) {
57170 send_sig(SIGPIPE, current, 0);
57171 ret = -EPIPE;
57172 break;
57173@@ -1785,9 +1785,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
57174 ret = -ERESTARTSYS;
57175 break;
57176 }
57177- pipe->waiting_writers++;
57178+ atomic_inc(&pipe->waiting_writers);
57179 pipe_wait(pipe);
57180- pipe->waiting_writers--;
57181+ atomic_dec(&pipe->waiting_writers);
57182 }
57183
57184 pipe_unlock(pipe);
57185@@ -1823,14 +1823,14 @@ retry:
57186 pipe_double_lock(ipipe, opipe);
57187
57188 do {
57189- if (!opipe->readers) {
57190+ if (!atomic_read(&opipe->readers)) {
57191 send_sig(SIGPIPE, current, 0);
57192 if (!ret)
57193 ret = -EPIPE;
57194 break;
57195 }
57196
57197- if (!ipipe->nrbufs && !ipipe->writers)
57198+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
57199 break;
57200
57201 /*
57202@@ -1927,7 +1927,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
57203 pipe_double_lock(ipipe, opipe);
57204
57205 do {
57206- if (!opipe->readers) {
57207+ if (!atomic_read(&opipe->readers)) {
57208 send_sig(SIGPIPE, current, 0);
57209 if (!ret)
57210 ret = -EPIPE;
57211@@ -1972,7 +1972,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
57212 * return EAGAIN if we have the potential of some data in the
57213 * future, otherwise just return 0
57214 */
57215- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
57216+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
57217 ret = -EAGAIN;
57218
57219 pipe_unlock(ipipe);
57220diff --git a/fs/stat.c b/fs/stat.c
57221index 14f4545..9b7f55b 100644
57222--- a/fs/stat.c
57223+++ b/fs/stat.c
57224@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
57225 stat->gid = inode->i_gid;
57226 stat->rdev = inode->i_rdev;
57227 stat->size = i_size_read(inode);
57228- stat->atime = inode->i_atime;
57229- stat->mtime = inode->i_mtime;
57230+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
57231+ stat->atime = inode->i_ctime;
57232+ stat->mtime = inode->i_ctime;
57233+ } else {
57234+ stat->atime = inode->i_atime;
57235+ stat->mtime = inode->i_mtime;
57236+ }
57237 stat->ctime = inode->i_ctime;
57238 stat->blksize = (1 << inode->i_blkbits);
57239 stat->blocks = inode->i_blocks;
57240@@ -46,8 +51,14 @@ int vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
57241 if (retval)
57242 return retval;
57243
57244- if (inode->i_op->getattr)
57245- return inode->i_op->getattr(mnt, dentry, stat);
57246+ if (inode->i_op->getattr) {
57247+ retval = inode->i_op->getattr(mnt, dentry, stat);
57248+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
57249+ stat->atime = stat->ctime;
57250+ stat->mtime = stat->ctime;
57251+ }
57252+ return retval;
57253+ }
57254
57255 generic_fillattr(inode, stat);
57256 return 0;
57257diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
57258index 614b2b5..4d321e6 100644
57259--- a/fs/sysfs/bin.c
57260+++ b/fs/sysfs/bin.c
57261@@ -235,13 +235,13 @@ static int bin_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
57262 return ret;
57263 }
57264
57265-static int bin_access(struct vm_area_struct *vma, unsigned long addr,
57266- void *buf, int len, int write)
57267+static ssize_t bin_access(struct vm_area_struct *vma, unsigned long addr,
57268+ void *buf, size_t len, int write)
57269 {
57270 struct file *file = vma->vm_file;
57271 struct bin_buffer *bb = file->private_data;
57272 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
57273- int ret;
57274+ ssize_t ret;
57275
57276 if (!bb->vm_ops)
57277 return -EINVAL;
57278diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
57279index 1f8c823..ed57cfe 100644
57280--- a/fs/sysfs/dir.c
57281+++ b/fs/sysfs/dir.c
57282@@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
57283 *
57284 * Returns 31 bit hash of ns + name (so it fits in an off_t )
57285 */
57286-static unsigned int sysfs_name_hash(const void *ns, const char *name)
57287+static unsigned int sysfs_name_hash(const void *ns, const unsigned char *name)
57288 {
57289 unsigned long hash = init_name_hash();
57290 unsigned int len = strlen(name);
57291@@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
57292 struct sysfs_dirent *sd;
57293 int rc;
57294
57295+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
57296+ const char *parent_name = parent_sd->s_name;
57297+
57298+ mode = S_IFDIR | S_IRWXU;
57299+
57300+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
57301+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
57302+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
57303+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
57304+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
57305+#endif
57306+
57307 /* allocate */
57308 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
57309 if (!sd)
57310diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
57311index 602f56d..6853db8 100644
57312--- a/fs/sysfs/file.c
57313+++ b/fs/sysfs/file.c
57314@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
57315
57316 struct sysfs_open_dirent {
57317 atomic_t refcnt;
57318- atomic_t event;
57319+ atomic_unchecked_t event;
57320 wait_queue_head_t poll;
57321 struct list_head buffers; /* goes through sysfs_buffer.list */
57322 };
57323@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
57324 if (!sysfs_get_active(attr_sd))
57325 return -ENODEV;
57326
57327- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
57328+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
57329 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
57330
57331 sysfs_put_active(attr_sd);
57332@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
57333 return -ENOMEM;
57334
57335 atomic_set(&new_od->refcnt, 0);
57336- atomic_set(&new_od->event, 1);
57337+ atomic_set_unchecked(&new_od->event, 1);
57338 init_waitqueue_head(&new_od->poll);
57339 INIT_LIST_HEAD(&new_od->buffers);
57340 goto retry;
57341@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
57342
57343 sysfs_put_active(attr_sd);
57344
57345- if (buffer->event != atomic_read(&od->event))
57346+ if (buffer->event != atomic_read_unchecked(&od->event))
57347 goto trigger;
57348
57349 return DEFAULT_POLLMASK;
57350@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
57351
57352 od = sd->s_attr.open;
57353 if (od) {
57354- atomic_inc(&od->event);
57355+ atomic_inc_unchecked(&od->event);
57356 wake_up_interruptible(&od->poll);
57357 }
57358
57359diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
57360index 3c9eb56..9dea5be 100644
57361--- a/fs/sysfs/symlink.c
57362+++ b/fs/sysfs/symlink.c
57363@@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
57364
57365 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
57366 {
57367- char *page = nd_get_link(nd);
57368+ const char *page = nd_get_link(nd);
57369 if (!IS_ERR(page))
57370 free_page((unsigned long)page);
57371 }
57372diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
57373index 69d4889..a810bd4 100644
57374--- a/fs/sysv/sysv.h
57375+++ b/fs/sysv/sysv.h
57376@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
57377 #endif
57378 }
57379
57380-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
57381+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
57382 {
57383 if (sbi->s_bytesex == BYTESEX_PDP)
57384 return PDP_swab((__force __u32)n);
57385diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
57386index e18b988..f1d4ad0f 100644
57387--- a/fs/ubifs/io.c
57388+++ b/fs/ubifs/io.c
57389@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
57390 return err;
57391 }
57392
57393-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
57394+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
57395 {
57396 int err;
57397
57398diff --git a/fs/udf/misc.c b/fs/udf/misc.c
57399index c175b4d..8f36a16 100644
57400--- a/fs/udf/misc.c
57401+++ b/fs/udf/misc.c
57402@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
57403
57404 u8 udf_tag_checksum(const struct tag *t)
57405 {
57406- u8 *data = (u8 *)t;
57407+ const u8 *data = (const u8 *)t;
57408 u8 checksum = 0;
57409 int i;
57410 for (i = 0; i < sizeof(struct tag); ++i)
57411diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
57412index 8d974c4..b82f6ec 100644
57413--- a/fs/ufs/swab.h
57414+++ b/fs/ufs/swab.h
57415@@ -22,7 +22,7 @@ enum {
57416 BYTESEX_BE
57417 };
57418
57419-static inline u64
57420+static inline u64 __intentional_overflow(-1)
57421 fs64_to_cpu(struct super_block *sbp, __fs64 n)
57422 {
57423 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
57424@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
57425 return (__force __fs64)cpu_to_be64(n);
57426 }
57427
57428-static inline u32
57429+static inline u32 __intentional_overflow(-1)
57430 fs32_to_cpu(struct super_block *sbp, __fs32 n)
57431 {
57432 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
57433diff --git a/fs/utimes.c b/fs/utimes.c
57434index f4fb7ec..3fe03c0 100644
57435--- a/fs/utimes.c
57436+++ b/fs/utimes.c
57437@@ -1,6 +1,7 @@
57438 #include <linux/compiler.h>
57439 #include <linux/file.h>
57440 #include <linux/fs.h>
57441+#include <linux/security.h>
57442 #include <linux/linkage.h>
57443 #include <linux/mount.h>
57444 #include <linux/namei.h>
57445@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
57446 goto mnt_drop_write_and_out;
57447 }
57448 }
57449+
57450+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
57451+ error = -EACCES;
57452+ goto mnt_drop_write_and_out;
57453+ }
57454+
57455 mutex_lock(&inode->i_mutex);
57456 error = notify_change(path->dentry, &newattrs);
57457 mutex_unlock(&inode->i_mutex);
57458diff --git a/fs/xattr.c b/fs/xattr.c
57459index 3377dff..4feded6 100644
57460--- a/fs/xattr.c
57461+++ b/fs/xattr.c
57462@@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
57463 * Extended attribute SET operations
57464 */
57465 static long
57466-setxattr(struct dentry *d, const char __user *name, const void __user *value,
57467+setxattr(struct path *path, const char __user *name, const void __user *value,
57468 size_t size, int flags)
57469 {
57470 int error;
57471@@ -355,7 +355,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
57472 posix_acl_fix_xattr_from_user(kvalue, size);
57473 }
57474
57475- error = vfs_setxattr(d, kname, kvalue, size, flags);
57476+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
57477+ error = -EACCES;
57478+ goto out;
57479+ }
57480+
57481+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
57482 out:
57483 if (vvalue)
57484 vfree(vvalue);
57485@@ -377,7 +382,7 @@ retry:
57486 return error;
57487 error = mnt_want_write(path.mnt);
57488 if (!error) {
57489- error = setxattr(path.dentry, name, value, size, flags);
57490+ error = setxattr(&path, name, value, size, flags);
57491 mnt_drop_write(path.mnt);
57492 }
57493 path_put(&path);
57494@@ -401,7 +406,7 @@ retry:
57495 return error;
57496 error = mnt_want_write(path.mnt);
57497 if (!error) {
57498- error = setxattr(path.dentry, name, value, size, flags);
57499+ error = setxattr(&path, name, value, size, flags);
57500 mnt_drop_write(path.mnt);
57501 }
57502 path_put(&path);
57503@@ -416,16 +421,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
57504 const void __user *,value, size_t, size, int, flags)
57505 {
57506 struct fd f = fdget(fd);
57507- struct dentry *dentry;
57508 int error = -EBADF;
57509
57510 if (!f.file)
57511 return error;
57512- dentry = f.file->f_path.dentry;
57513- audit_inode(NULL, dentry, 0);
57514+ audit_inode(NULL, f.file->f_path.dentry, 0);
57515 error = mnt_want_write_file(f.file);
57516 if (!error) {
57517- error = setxattr(dentry, name, value, size, flags);
57518+ error = setxattr(&f.file->f_path, name, value, size, flags);
57519 mnt_drop_write_file(f.file);
57520 }
57521 fdput(f);
57522diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
57523index 9fbea87..6b19972 100644
57524--- a/fs/xattr_acl.c
57525+++ b/fs/xattr_acl.c
57526@@ -76,8 +76,8 @@ struct posix_acl *
57527 posix_acl_from_xattr(struct user_namespace *user_ns,
57528 const void *value, size_t size)
57529 {
57530- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
57531- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
57532+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
57533+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
57534 int count;
57535 struct posix_acl *acl;
57536 struct posix_acl_entry *acl_e;
57537diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
57538index 572a858..12a9b0d 100644
57539--- a/fs/xfs/xfs_bmap.c
57540+++ b/fs/xfs/xfs_bmap.c
57541@@ -192,7 +192,7 @@ xfs_bmap_validate_ret(
57542 int nmap,
57543 int ret_nmap);
57544 #else
57545-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
57546+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
57547 #endif /* DEBUG */
57548
57549 STATIC int
57550diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
57551index 1b9fc3e..e1bdde0 100644
57552--- a/fs/xfs/xfs_dir2_sf.c
57553+++ b/fs/xfs/xfs_dir2_sf.c
57554@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
57555 }
57556
57557 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
57558- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
57559+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
57560+ char name[sfep->namelen];
57561+ memcpy(name, sfep->name, sfep->namelen);
57562+ if (filldir(dirent, name, sfep->namelen,
57563+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
57564+ *offset = off & 0x7fffffff;
57565+ return 0;
57566+ }
57567+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
57568 off & 0x7fffffff, ino, DT_UNKNOWN)) {
57569 *offset = off & 0x7fffffff;
57570 return 0;
57571diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
57572index c1c3ef8..0952438 100644
57573--- a/fs/xfs/xfs_ioctl.c
57574+++ b/fs/xfs/xfs_ioctl.c
57575@@ -127,7 +127,7 @@ xfs_find_handle(
57576 }
57577
57578 error = -EFAULT;
57579- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
57580+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
57581 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
57582 goto out_put;
57583
57584diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
57585index d82efaa..0904a8e 100644
57586--- a/fs/xfs/xfs_iops.c
57587+++ b/fs/xfs/xfs_iops.c
57588@@ -395,7 +395,7 @@ xfs_vn_put_link(
57589 struct nameidata *nd,
57590 void *p)
57591 {
57592- char *s = nd_get_link(nd);
57593+ const char *s = nd_get_link(nd);
57594
57595 if (!IS_ERR(s))
57596 kfree(s);
57597diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
57598new file mode 100644
57599index 0000000..92247e4
57600--- /dev/null
57601+++ b/grsecurity/Kconfig
57602@@ -0,0 +1,1021 @@
57603+#
57604+# grecurity configuration
57605+#
57606+menu "Memory Protections"
57607+depends on GRKERNSEC
57608+
57609+config GRKERNSEC_KMEM
57610+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
57611+ default y if GRKERNSEC_CONFIG_AUTO
57612+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
57613+ help
57614+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
57615+ be written to or read from to modify or leak the contents of the running
57616+ kernel. /dev/port will also not be allowed to be opened and support
57617+ for /dev/cpu/*/msr will be removed. If you have module
57618+ support disabled, enabling this will close up five ways that are
57619+ currently used to insert malicious code into the running kernel.
57620+
57621+ Even with all these features enabled, we still highly recommend that
57622+ you use the RBAC system, as it is still possible for an attacker to
57623+ modify the running kernel through privileged I/O granted by ioperm/iopl.
57624+
57625+ If you are not using XFree86, you may be able to stop this additional
57626+ case by enabling the 'Disable privileged I/O' option. Though nothing
57627+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
57628+ but only to video memory, which is the only writing we allow in this
57629+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
57630+ not be allowed to mprotect it with PROT_WRITE later.
57631+ Enabling this feature will prevent the "cpupower" and "powertop" tools
57632+ from working.
57633+
57634+ It is highly recommended that you say Y here if you meet all the
57635+ conditions above.
57636+
57637+config GRKERNSEC_VM86
57638+ bool "Restrict VM86 mode"
57639+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
57640+ depends on X86_32
57641+
57642+ help
57643+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
57644+ make use of a special execution mode on 32bit x86 processors called
57645+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
57646+ video cards and will still work with this option enabled. The purpose
57647+ of the option is to prevent exploitation of emulation errors in
57648+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
57649+ Nearly all users should be able to enable this option.
57650+
57651+config GRKERNSEC_IO
57652+ bool "Disable privileged I/O"
57653+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
57654+ depends on X86
57655+ select RTC_CLASS
57656+ select RTC_INTF_DEV
57657+ select RTC_DRV_CMOS
57658+
57659+ help
57660+ If you say Y here, all ioperm and iopl calls will return an error.
57661+ Ioperm and iopl can be used to modify the running kernel.
57662+ Unfortunately, some programs need this access to operate properly,
57663+ the most notable of which are XFree86 and hwclock. hwclock can be
57664+ remedied by having RTC support in the kernel, so real-time
57665+ clock support is enabled if this option is enabled, to ensure
57666+ that hwclock operates correctly. XFree86 still will not
57667+ operate correctly with this option enabled, so DO NOT CHOOSE Y
57668+ IF YOU USE XFree86. If you use XFree86 and you still want to
57669+ protect your kernel against modification, use the RBAC system.
57670+
57671+config GRKERNSEC_JIT_HARDEN
57672+ bool "Harden BPF JIT against spray attacks"
57673+ default y if GRKERNSEC_CONFIG_AUTO
57674+ depends on BPF_JIT
57675+ help
57676+ If you say Y here, the native code generated by the kernel's Berkeley
57677+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
57678+ attacks that attempt to fit attacker-beneficial instructions in
57679+ 32bit immediate fields of JIT-generated native instructions. The
57680+ attacker will generally aim to cause an unintended instruction sequence
57681+ of JIT-generated native code to execute by jumping into the middle of
57682+ a generated instruction. This feature effectively randomizes the 32bit
57683+ immediate constants present in the generated code to thwart such attacks.
57684+
57685+ If you're using KERNEXEC, it's recommended that you enable this option
57686+ to supplement the hardening of the kernel.
57687+
57688+config GRKERNSEC_RAND_THREADSTACK
57689+ bool "Insert random gaps between thread stacks"
57690+ default y if GRKERNSEC_CONFIG_AUTO
57691+ depends on PAX_RANDMMAP && !PPC
57692+ help
57693+ If you say Y here, a random-sized gap will be enforced between allocated
57694+ thread stacks. Glibc's NPTL and other threading libraries that
57695+ pass MAP_STACK to the kernel for thread stack allocation are supported.
57696+ The implementation currently provides 8 bits of entropy for the gap.
57697+
57698+ Many distributions do not compile threaded remote services with the
57699+ -fstack-check argument to GCC, causing the variable-sized stack-based
57700+ allocator, alloca(), to not probe the stack on allocation. This
57701+ permits an unbounded alloca() to skip over any guard page and potentially
57702+ modify another thread's stack reliably. An enforced random gap
57703+ reduces the reliability of such an attack and increases the chance
57704+ that such a read/write to another thread's stack instead lands in
57705+ an unmapped area, causing a crash and triggering grsecurity's
57706+ anti-bruteforcing logic.
57707+
57708+config GRKERNSEC_PROC_MEMMAP
57709+ bool "Harden ASLR against information leaks and entropy reduction"
57710+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
57711+ depends on PAX_NOEXEC || PAX_ASLR
57712+ help
57713+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
57714+ give no information about the addresses of its mappings if
57715+ PaX features that rely on random addresses are enabled on the task.
57716+ In addition to sanitizing this information and disabling other
57717+ dangerous sources of information, this option causes reads of sensitive
57718+ /proc/<pid> entries where the file descriptor was opened in a different
57719+ task than the one performing the read. Such attempts are logged.
57720+ This option also limits argv/env strings for suid/sgid binaries
57721+ to 512KB to prevent a complete exhaustion of the stack entropy provided
57722+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
57723+ binaries to prevent alternative mmap layouts from being abused.
57724+
57725+ If you use PaX it is essential that you say Y here as it closes up
57726+ several holes that make full ASLR useless locally.
57727+
57728+config GRKERNSEC_BRUTE
57729+ bool "Deter exploit bruteforcing"
57730+ default y if GRKERNSEC_CONFIG_AUTO
57731+ help
57732+ If you say Y here, attempts to bruteforce exploits against forking
57733+ daemons such as apache or sshd, as well as against suid/sgid binaries
57734+ will be deterred. When a child of a forking daemon is killed by PaX
57735+ or crashes due to an illegal instruction or other suspicious signal,
57736+ the parent process will be delayed 30 seconds upon every subsequent
57737+ fork until the administrator is able to assess the situation and
57738+ restart the daemon.
57739+ In the suid/sgid case, the attempt is logged, the user has all their
57740+ processes terminated, and they are prevented from executing any further
57741+ processes for 15 minutes.
57742+ It is recommended that you also enable signal logging in the auditing
57743+ section so that logs are generated when a process triggers a suspicious
57744+ signal.
57745+ If the sysctl option is enabled, a sysctl option with name
57746+ "deter_bruteforce" is created.
57747+
57748+
57749+config GRKERNSEC_MODHARDEN
57750+ bool "Harden module auto-loading"
57751+ default y if GRKERNSEC_CONFIG_AUTO
57752+ depends on MODULES
57753+ help
57754+ If you say Y here, module auto-loading in response to use of some
57755+ feature implemented by an unloaded module will be restricted to
57756+ root users. Enabling this option helps defend against attacks
57757+ by unprivileged users who abuse the auto-loading behavior to
57758+ cause a vulnerable module to load that is then exploited.
57759+
57760+ If this option prevents a legitimate use of auto-loading for a
57761+ non-root user, the administrator can execute modprobe manually
57762+ with the exact name of the module mentioned in the alert log.
57763+ Alternatively, the administrator can add the module to the list
57764+ of modules loaded at boot by modifying init scripts.
57765+
57766+ Modification of init scripts will most likely be needed on
57767+ Ubuntu servers with encrypted home directory support enabled,
57768+ as the first non-root user logging in will cause the ecb(aes),
57769+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
57770+
57771+config GRKERNSEC_HIDESYM
57772+ bool "Hide kernel symbols"
57773+ default y if GRKERNSEC_CONFIG_AUTO
57774+ select PAX_USERCOPY_SLABS
57775+ help
57776+ If you say Y here, getting information on loaded modules, and
57777+ displaying all kernel symbols through a syscall will be restricted
57778+ to users with CAP_SYS_MODULE. For software compatibility reasons,
57779+ /proc/kallsyms will be restricted to the root user. The RBAC
57780+ system can hide that entry even from root.
57781+
57782+ This option also prevents leaking of kernel addresses through
57783+ several /proc entries.
57784+
57785+ Note that this option is only effective provided the following
57786+ conditions are met:
57787+ 1) The kernel using grsecurity is not precompiled by some distribution
57788+ 2) You have also enabled GRKERNSEC_DMESG
57789+ 3) You are using the RBAC system and hiding other files such as your
57790+ kernel image and System.map. Alternatively, enabling this option
57791+ causes the permissions on /boot, /lib/modules, and the kernel
57792+ source directory to change at compile time to prevent
57793+ reading by non-root users.
57794+ If the above conditions are met, this option will aid in providing a
57795+ useful protection against local kernel exploitation of overflows
57796+ and arbitrary read/write vulnerabilities.
57797+
57798+config GRKERNSEC_KERN_LOCKOUT
57799+ bool "Active kernel exploit response"
57800+ default y if GRKERNSEC_CONFIG_AUTO
57801+ depends on X86 || ARM || PPC || SPARC
57802+ help
57803+ If you say Y here, when a PaX alert is triggered due to suspicious
57804+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
57805+ or an OOPS occurs due to bad memory accesses, instead of just
57806+ terminating the offending process (and potentially allowing
57807+ a subsequent exploit from the same user), we will take one of two
57808+ actions:
57809+ If the user was root, we will panic the system
57810+ If the user was non-root, we will log the attempt, terminate
57811+ all processes owned by the user, then prevent them from creating
57812+ any new processes until the system is restarted
57813+ This deters repeated kernel exploitation/bruteforcing attempts
57814+ and is useful for later forensics.
57815+
57816+endmenu
57817+menu "Role Based Access Control Options"
57818+depends on GRKERNSEC
57819+
57820+config GRKERNSEC_RBAC_DEBUG
57821+ bool
57822+
57823+config GRKERNSEC_NO_RBAC
57824+ bool "Disable RBAC system"
57825+ help
57826+ If you say Y here, the /dev/grsec device will be removed from the kernel,
57827+ preventing the RBAC system from being enabled. You should only say Y
57828+ here if you have no intention of using the RBAC system, so as to prevent
57829+ an attacker with root access from misusing the RBAC system to hide files
57830+ and processes when loadable module support and /dev/[k]mem have been
57831+ locked down.
57832+
57833+config GRKERNSEC_ACL_HIDEKERN
57834+ bool "Hide kernel processes"
57835+ help
57836+ If you say Y here, all kernel threads will be hidden to all
57837+ processes but those whose subject has the "view hidden processes"
57838+ flag.
57839+
57840+config GRKERNSEC_ACL_MAXTRIES
57841+ int "Maximum tries before password lockout"
57842+ default 3
57843+ help
57844+ This option enforces the maximum number of times a user can attempt
57845+ to authorize themselves with the grsecurity RBAC system before being
57846+ denied the ability to attempt authorization again for a specified time.
57847+ The lower the number, the harder it will be to brute-force a password.
57848+
57849+config GRKERNSEC_ACL_TIMEOUT
57850+ int "Time to wait after max password tries, in seconds"
57851+ default 30
57852+ help
57853+ This option specifies the time the user must wait after attempting to
57854+ authorize to the RBAC system with the maximum number of invalid
57855+ passwords. The higher the number, the harder it will be to brute-force
57856+ a password.
57857+
57858+endmenu
57859+menu "Filesystem Protections"
57860+depends on GRKERNSEC
57861+
57862+config GRKERNSEC_PROC
57863+ bool "Proc restrictions"
57864+ default y if GRKERNSEC_CONFIG_AUTO
57865+ help
57866+ If you say Y here, the permissions of the /proc filesystem
57867+ will be altered to enhance system security and privacy. You MUST
57868+ choose either a user only restriction or a user and group restriction.
57869+ Depending upon the option you choose, you can either restrict users to
57870+ see only the processes they themselves run, or choose a group that can
57871+ view all processes and files normally restricted to root if you choose
57872+ the "restrict to user only" option. NOTE: If you're running identd or
57873+ ntpd as a non-root user, you will have to run it as the group you
57874+ specify here.
57875+
57876+config GRKERNSEC_PROC_USER
57877+ bool "Restrict /proc to user only"
57878+ depends on GRKERNSEC_PROC
57879+ help
57880+ If you say Y here, non-root users will only be able to view their own
57881+ processes, and restricts them from viewing network-related information,
57882+ and viewing kernel symbol and module information.
57883+
57884+config GRKERNSEC_PROC_USERGROUP
57885+ bool "Allow special group"
57886+ default y if GRKERNSEC_CONFIG_AUTO
57887+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
57888+ help
57889+ If you say Y here, you will be able to select a group that will be
57890+ able to view all processes and network-related information. If you've
57891+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
57892+ remain hidden. This option is useful if you want to run identd as
57893+ a non-root user. The group you select may also be chosen at boot time
57894+ via "grsec_proc_gid=" on the kernel commandline.
57895+
57896+config GRKERNSEC_PROC_GID
57897+ int "GID for special group"
57898+ depends on GRKERNSEC_PROC_USERGROUP
57899+ default 1001
57900+
57901+config GRKERNSEC_PROC_ADD
57902+ bool "Additional restrictions"
57903+ default y if GRKERNSEC_CONFIG_AUTO
57904+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
57905+ help
57906+ If you say Y here, additional restrictions will be placed on
57907+ /proc that keep normal users from viewing device information and
57908+ slabinfo information that could be useful for exploits.
57909+
57910+config GRKERNSEC_LINK
57911+ bool "Linking restrictions"
57912+ default y if GRKERNSEC_CONFIG_AUTO
57913+ help
57914+ If you say Y here, /tmp race exploits will be prevented, since users
57915+ will no longer be able to follow symlinks owned by other users in
57916+ world-writable +t directories (e.g. /tmp), unless the owner of the
57917+ symlink is the owner of the directory. users will also not be
57918+ able to hardlink to files they do not own. If the sysctl option is
57919+ enabled, a sysctl option with name "linking_restrictions" is created.
57920+
57921+config GRKERNSEC_SYMLINKOWN
57922+ bool "Kernel-enforced SymlinksIfOwnerMatch"
57923+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
57924+ help
57925+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
57926+ that prevents it from being used as a security feature. As Apache
57927+ verifies the symlink by performing a stat() against the target of
57928+ the symlink before it is followed, an attacker can setup a symlink
57929+ to point to a same-owned file, then replace the symlink with one
57930+ that targets another user's file just after Apache "validates" the
57931+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
57932+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
57933+ will be in place for the group you specify. If the sysctl option
57934+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
57935+ created.
57936+
57937+config GRKERNSEC_SYMLINKOWN_GID
57938+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
57939+ depends on GRKERNSEC_SYMLINKOWN
57940+ default 1006
57941+ help
57942+ Setting this GID determines what group kernel-enforced
57943+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
57944+ is enabled, a sysctl option with name "symlinkown_gid" is created.
57945+
57946+config GRKERNSEC_FIFO
57947+ bool "FIFO restrictions"
57948+ default y if GRKERNSEC_CONFIG_AUTO
57949+ help
57950+ If you say Y here, users will not be able to write to FIFOs they don't
57951+ own in world-writable +t directories (e.g. /tmp), unless the owner of
57952+ the FIFO is the same owner of the directory it's held in. If the sysctl
57953+ option is enabled, a sysctl option with name "fifo_restrictions" is
57954+ created.
57955+
57956+config GRKERNSEC_SYSFS_RESTRICT
57957+ bool "Sysfs/debugfs restriction"
57958+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
57959+ depends on SYSFS
57960+ help
57961+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
57962+ any filesystem normally mounted under it (e.g. debugfs) will be
57963+ mostly accessible only by root. These filesystems generally provide access
57964+ to hardware and debug information that isn't appropriate for unprivileged
57965+ users of the system. Sysfs and debugfs have also become a large source
57966+ of new vulnerabilities, ranging from infoleaks to local compromise.
57967+ There has been very little oversight with an eye toward security involved
57968+ in adding new exporters of information to these filesystems, so their
57969+ use is discouraged.
57970+ For reasons of compatibility, a few directories have been whitelisted
57971+ for access by non-root users:
57972+ /sys/fs/selinux
57973+ /sys/fs/fuse
57974+ /sys/devices/system/cpu
57975+
57976+config GRKERNSEC_ROFS
57977+ bool "Runtime read-only mount protection"
57978+ help
57979+ If you say Y here, a sysctl option with name "romount_protect" will
57980+ be created. By setting this option to 1 at runtime, filesystems
57981+ will be protected in the following ways:
57982+ * No new writable mounts will be allowed
57983+ * Existing read-only mounts won't be able to be remounted read/write
57984+ * Write operations will be denied on all block devices
57985+ This option acts independently of grsec_lock: once it is set to 1,
57986+ it cannot be turned off. Therefore, please be mindful of the resulting
57987+ behavior if this option is enabled in an init script on a read-only
57988+ filesystem. This feature is mainly intended for secure embedded systems.
57989+
57990+config GRKERNSEC_DEVICE_SIDECHANNEL
57991+ bool "Eliminate stat/notify-based device sidechannels"
57992+ default y if GRKERNSEC_CONFIG_AUTO
57993+ help
57994+ If you say Y here, timing analyses on block or character
57995+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
57996+ will be thwarted for unprivileged users. If a process without
57997+ CAP_MKNOD stats such a device, the last access and last modify times
57998+ will match the device's create time. No access or modify events
57999+ will be triggered through inotify/dnotify/fanotify for such devices.
58000+ This feature will prevent attacks that may at a minimum
58001+ allow an attacker to determine the administrator's password length.
58002+
58003+config GRKERNSEC_CHROOT
58004+ bool "Chroot jail restrictions"
58005+ default y if GRKERNSEC_CONFIG_AUTO
58006+ help
58007+ If you say Y here, you will be able to choose several options that will
58008+ make breaking out of a chrooted jail much more difficult. If you
58009+ encounter no software incompatibilities with the following options, it
58010+ is recommended that you enable each one.
58011+
58012+config GRKERNSEC_CHROOT_MOUNT
58013+ bool "Deny mounts"
58014+ default y if GRKERNSEC_CONFIG_AUTO
58015+ depends on GRKERNSEC_CHROOT
58016+ help
58017+ If you say Y here, processes inside a chroot will not be able to
58018+ mount or remount filesystems. If the sysctl option is enabled, a
58019+ sysctl option with name "chroot_deny_mount" is created.
58020+
58021+config GRKERNSEC_CHROOT_DOUBLE
58022+ bool "Deny double-chroots"
58023+ default y if GRKERNSEC_CONFIG_AUTO
58024+ depends on GRKERNSEC_CHROOT
58025+ help
58026+ If you say Y here, processes inside a chroot will not be able to chroot
58027+ again outside the chroot. This is a widely used method of breaking
58028+ out of a chroot jail and should not be allowed. If the sysctl
58029+ option is enabled, a sysctl option with name
58030+ "chroot_deny_chroot" is created.
58031+
58032+config GRKERNSEC_CHROOT_PIVOT
58033+ bool "Deny pivot_root in chroot"
58034+ default y if GRKERNSEC_CONFIG_AUTO
58035+ depends on GRKERNSEC_CHROOT
58036+ help
58037+ If you say Y here, processes inside a chroot will not be able to use
58038+ a function called pivot_root() that was introduced in Linux 2.3.41. It
58039+ works similar to chroot in that it changes the root filesystem. This
58040+ function could be misused in a chrooted process to attempt to break out
58041+ of the chroot, and therefore should not be allowed. If the sysctl
58042+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
58043+ created.
58044+
58045+config GRKERNSEC_CHROOT_CHDIR
58046+ bool "Enforce chdir(\"/\") on all chroots"
58047+ default y if GRKERNSEC_CONFIG_AUTO
58048+ depends on GRKERNSEC_CHROOT
58049+ help
58050+ If you say Y here, the current working directory of all newly-chrooted
58051+ applications will be set to the the root directory of the chroot.
58052+ The man page on chroot(2) states:
58053+ Note that this call does not change the current working
58054+ directory, so that `.' can be outside the tree rooted at
58055+ `/'. In particular, the super-user can escape from a
58056+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
58057+
58058+ It is recommended that you say Y here, since it's not known to break
58059+ any software. If the sysctl option is enabled, a sysctl option with
58060+ name "chroot_enforce_chdir" is created.
58061+
58062+config GRKERNSEC_CHROOT_CHMOD
58063+ bool "Deny (f)chmod +s"
58064+ default y if GRKERNSEC_CONFIG_AUTO
58065+ depends on GRKERNSEC_CHROOT
58066+ help
58067+ If you say Y here, processes inside a chroot will not be able to chmod
58068+ or fchmod files to make them have suid or sgid bits. This protects
58069+ against another published method of breaking a chroot. If the sysctl
58070+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
58071+ created.
58072+
58073+config GRKERNSEC_CHROOT_FCHDIR
58074+ bool "Deny fchdir out of chroot"
58075+ default y if GRKERNSEC_CONFIG_AUTO
58076+ depends on GRKERNSEC_CHROOT
58077+ help
58078+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
58079+ to a file descriptor of the chrooting process that points to a directory
58080+ outside the filesystem will be stopped. If the sysctl option
58081+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
58082+
58083+config GRKERNSEC_CHROOT_MKNOD
58084+ bool "Deny mknod"
58085+ default y if GRKERNSEC_CONFIG_AUTO
58086+ depends on GRKERNSEC_CHROOT
58087+ help
58088+ If you say Y here, processes inside a chroot will not be allowed to
58089+ mknod. The problem with using mknod inside a chroot is that it
58090+ would allow an attacker to create a device entry that is the same
58091+ as one on the physical root of your system, which could range from
58092+ anything from the console device to a device for your harddrive (which
58093+ they could then use to wipe the drive or steal data). It is recommended
58094+ that you say Y here, unless you run into software incompatibilities.
58095+ If the sysctl option is enabled, a sysctl option with name
58096+ "chroot_deny_mknod" is created.
58097+
58098+config GRKERNSEC_CHROOT_SHMAT
58099+ bool "Deny shmat() out of chroot"
58100+ default y if GRKERNSEC_CONFIG_AUTO
58101+ depends on GRKERNSEC_CHROOT
58102+ help
58103+ If you say Y here, processes inside a chroot will not be able to attach
58104+ to shared memory segments that were created outside of the chroot jail.
58105+ It is recommended that you say Y here. If the sysctl option is enabled,
58106+ a sysctl option with name "chroot_deny_shmat" is created.
58107+
58108+config GRKERNSEC_CHROOT_UNIX
58109+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
58110+ default y if GRKERNSEC_CONFIG_AUTO
58111+ depends on GRKERNSEC_CHROOT
58112+ help
58113+ If you say Y here, processes inside a chroot will not be able to
58114+ connect to abstract (meaning not belonging to a filesystem) Unix
58115+ domain sockets that were bound outside of a chroot. It is recommended
58116+ that you say Y here. If the sysctl option is enabled, a sysctl option
58117+ with name "chroot_deny_unix" is created.
58118+
58119+config GRKERNSEC_CHROOT_FINDTASK
58120+ bool "Protect outside processes"
58121+ default y if GRKERNSEC_CONFIG_AUTO
58122+ depends on GRKERNSEC_CHROOT
58123+ help
58124+ If you say Y here, processes inside a chroot will not be able to
58125+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
58126+ getsid, or view any process outside of the chroot. If the sysctl
58127+ option is enabled, a sysctl option with name "chroot_findtask" is
58128+ created.
58129+
58130+config GRKERNSEC_CHROOT_NICE
58131+ bool "Restrict priority changes"
58132+ default y if GRKERNSEC_CONFIG_AUTO
58133+ depends on GRKERNSEC_CHROOT
58134+ help
58135+ If you say Y here, processes inside a chroot will not be able to raise
58136+ the priority of processes in the chroot, or alter the priority of
58137+ processes outside the chroot. This provides more security than simply
58138+ removing CAP_SYS_NICE from the process' capability set. If the
58139+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
58140+ is created.
58141+
58142+config GRKERNSEC_CHROOT_SYSCTL
58143+ bool "Deny sysctl writes"
58144+ default y if GRKERNSEC_CONFIG_AUTO
58145+ depends on GRKERNSEC_CHROOT
58146+ help
58147+ If you say Y here, an attacker in a chroot will not be able to
58148+ write to sysctl entries, either by sysctl(2) or through a /proc
58149+ interface. It is strongly recommended that you say Y here. If the
58150+ sysctl option is enabled, a sysctl option with name
58151+ "chroot_deny_sysctl" is created.
58152+
58153+config GRKERNSEC_CHROOT_CAPS
58154+ bool "Capability restrictions"
58155+ default y if GRKERNSEC_CONFIG_AUTO
58156+ depends on GRKERNSEC_CHROOT
58157+ help
58158+ If you say Y here, the capabilities on all processes within a
58159+ chroot jail will be lowered to stop module insertion, raw i/o,
58160+ system and net admin tasks, rebooting the system, modifying immutable
58161+ files, modifying IPC owned by another, and changing the system time.
58162+ This is left an option because it can break some apps. Disable this
58163+ if your chrooted apps are having problems performing those kinds of
58164+ tasks. If the sysctl option is enabled, a sysctl option with
58165+ name "chroot_caps" is created.
58166+
58167+endmenu
58168+menu "Kernel Auditing"
58169+depends on GRKERNSEC
58170+
58171+config GRKERNSEC_AUDIT_GROUP
58172+ bool "Single group for auditing"
58173+ help
58174+ If you say Y here, the exec and chdir logging features will only operate
58175+ on a group you specify. This option is recommended if you only want to
58176+ watch certain users instead of having a large amount of logs from the
58177+ entire system. If the sysctl option is enabled, a sysctl option with
58178+ name "audit_group" is created.
58179+
58180+config GRKERNSEC_AUDIT_GID
58181+ int "GID for auditing"
58182+ depends on GRKERNSEC_AUDIT_GROUP
58183+ default 1007
58184+
58185+config GRKERNSEC_EXECLOG
58186+ bool "Exec logging"
58187+ help
58188+ If you say Y here, all execve() calls will be logged (since the
58189+ other exec*() calls are frontends to execve(), all execution
58190+ will be logged). Useful for shell-servers that like to keep track
58191+ of their users. If the sysctl option is enabled, a sysctl option with
58192+ name "exec_logging" is created.
58193+ WARNING: This option when enabled will produce a LOT of logs, especially
58194+ on an active system.
58195+
58196+config GRKERNSEC_RESLOG
58197+ bool "Resource logging"
58198+ default y if GRKERNSEC_CONFIG_AUTO
58199+ help
58200+ If you say Y here, all attempts to overstep resource limits will
58201+ be logged with the resource name, the requested size, and the current
58202+ limit. It is highly recommended that you say Y here. If the sysctl
58203+ option is enabled, a sysctl option with name "resource_logging" is
58204+ created. If the RBAC system is enabled, the sysctl value is ignored.
58205+
58206+config GRKERNSEC_CHROOT_EXECLOG
58207+ bool "Log execs within chroot"
58208+ help
58209+ If you say Y here, all executions inside a chroot jail will be logged
58210+ to syslog. This can cause a large amount of logs if certain
58211+ applications (eg. djb's daemontools) are installed on the system, and
58212+ is therefore left as an option. If the sysctl option is enabled, a
58213+ sysctl option with name "chroot_execlog" is created.
58214+
58215+config GRKERNSEC_AUDIT_PTRACE
58216+ bool "Ptrace logging"
58217+ help
58218+ If you say Y here, all attempts to attach to a process via ptrace
58219+ will be logged. If the sysctl option is enabled, a sysctl option
58220+ with name "audit_ptrace" is created.
58221+
58222+config GRKERNSEC_AUDIT_CHDIR
58223+ bool "Chdir logging"
58224+ help
58225+ If you say Y here, all chdir() calls will be logged. If the sysctl
58226+ option is enabled, a sysctl option with name "audit_chdir" is created.
58227+
58228+config GRKERNSEC_AUDIT_MOUNT
58229+ bool "(Un)Mount logging"
58230+ help
58231+ If you say Y here, all mounts and unmounts will be logged. If the
58232+ sysctl option is enabled, a sysctl option with name "audit_mount" is
58233+ created.
58234+
58235+config GRKERNSEC_SIGNAL
58236+ bool "Signal logging"
58237+ default y if GRKERNSEC_CONFIG_AUTO
58238+ help
58239+ If you say Y here, certain important signals will be logged, such as
58240+ SIGSEGV, which will as a result inform you of when a error in a program
58241+ occurred, which in some cases could mean a possible exploit attempt.
58242+ If the sysctl option is enabled, a sysctl option with name
58243+ "signal_logging" is created.
58244+
58245+config GRKERNSEC_FORKFAIL
58246+ bool "Fork failure logging"
58247+ help
58248+ If you say Y here, all failed fork() attempts will be logged.
58249+ This could suggest a fork bomb, or someone attempting to overstep
58250+ their process limit. If the sysctl option is enabled, a sysctl option
58251+ with name "forkfail_logging" is created.
58252+
58253+config GRKERNSEC_TIME
58254+ bool "Time change logging"
58255+ default y if GRKERNSEC_CONFIG_AUTO
58256+ help
58257+ If you say Y here, any changes of the system clock will be logged.
58258+ If the sysctl option is enabled, a sysctl option with name
58259+ "timechange_logging" is created.
58260+
58261+config GRKERNSEC_PROC_IPADDR
58262+ bool "/proc/<pid>/ipaddr support"
58263+ default y if GRKERNSEC_CONFIG_AUTO
58264+ help
58265+ If you say Y here, a new entry will be added to each /proc/<pid>
58266+ directory that contains the IP address of the person using the task.
58267+ The IP is carried across local TCP and AF_UNIX stream sockets.
58268+ This information can be useful for IDS/IPSes to perform remote response
58269+ to a local attack. The entry is readable by only the owner of the
58270+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
58271+ the RBAC system), and thus does not create privacy concerns.
58272+
58273+config GRKERNSEC_RWXMAP_LOG
58274+ bool 'Denied RWX mmap/mprotect logging'
58275+ default y if GRKERNSEC_CONFIG_AUTO
58276+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
58277+ help
58278+ If you say Y here, calls to mmap() and mprotect() with explicit
58279+ usage of PROT_WRITE and PROT_EXEC together will be logged when
58280+ denied by the PAX_MPROTECT feature. If the sysctl option is
58281+ enabled, a sysctl option with name "rwxmap_logging" is created.
58282+
58283+config GRKERNSEC_AUDIT_TEXTREL
58284+ bool 'ELF text relocations logging (READ HELP)'
58285+ depends on PAX_MPROTECT
58286+ help
58287+ If you say Y here, text relocations will be logged with the filename
58288+ of the offending library or binary. The purpose of the feature is
58289+ to help Linux distribution developers get rid of libraries and
58290+ binaries that need text relocations which hinder the future progress
58291+ of PaX. Only Linux distribution developers should say Y here, and
58292+ never on a production machine, as this option creates an information
58293+ leak that could aid an attacker in defeating the randomization of
58294+ a single memory region. If the sysctl option is enabled, a sysctl
58295+ option with name "audit_textrel" is created.
58296+
58297+endmenu
58298+
58299+menu "Executable Protections"
58300+depends on GRKERNSEC
58301+
58302+config GRKERNSEC_DMESG
58303+ bool "Dmesg(8) restriction"
58304+ default y if GRKERNSEC_CONFIG_AUTO
58305+ help
58306+ If you say Y here, non-root users will not be able to use dmesg(8)
58307+ to view the contents of the kernel's circular log buffer.
58308+ The kernel's log buffer often contains kernel addresses and other
58309+ identifying information useful to an attacker in fingerprinting a
58310+ system for a targeted exploit.
58311+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
58312+ created.
58313+
58314+config GRKERNSEC_HARDEN_PTRACE
58315+ bool "Deter ptrace-based process snooping"
58316+ default y if GRKERNSEC_CONFIG_AUTO
58317+ help
58318+ If you say Y here, TTY sniffers and other malicious monitoring
58319+ programs implemented through ptrace will be defeated. If you
58320+ have been using the RBAC system, this option has already been
58321+ enabled for several years for all users, with the ability to make
58322+ fine-grained exceptions.
58323+
58324+ This option only affects the ability of non-root users to ptrace
58325+ processes that are not a descendent of the ptracing process.
58326+ This means that strace ./binary and gdb ./binary will still work,
58327+ but attaching to arbitrary processes will not. If the sysctl
58328+ option is enabled, a sysctl option with name "harden_ptrace" is
58329+ created.
58330+
58331+config GRKERNSEC_PTRACE_READEXEC
58332+ bool "Require read access to ptrace sensitive binaries"
58333+ default y if GRKERNSEC_CONFIG_AUTO
58334+ help
58335+ If you say Y here, unprivileged users will not be able to ptrace unreadable
58336+ binaries. This option is useful in environments that
58337+ remove the read bits (e.g. file mode 4711) from suid binaries to
58338+ prevent infoleaking of their contents. This option adds
58339+ consistency to the use of that file mode, as the binary could normally
58340+ be read out when run without privileges while ptracing.
58341+
58342+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
58343+ is created.
58344+
58345+config GRKERNSEC_SETXID
58346+ bool "Enforce consistent multithreaded privileges"
58347+ default y if GRKERNSEC_CONFIG_AUTO
58348+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
58349+ help
58350+ If you say Y here, a change from a root uid to a non-root uid
58351+ in a multithreaded application will cause the resulting uids,
58352+ gids, supplementary groups, and capabilities in that thread
58353+ to be propagated to the other threads of the process. In most
58354+ cases this is unnecessary, as glibc will emulate this behavior
58355+ on behalf of the application. Other libcs do not act in the
58356+ same way, allowing the other threads of the process to continue
58357+ running with root privileges. If the sysctl option is enabled,
58358+ a sysctl option with name "consistent_setxid" is created.
58359+
58360+config GRKERNSEC_TPE
58361+ bool "Trusted Path Execution (TPE)"
58362+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
58363+ help
58364+ If you say Y here, you will be able to choose a gid to add to the
58365+ supplementary groups of users you want to mark as "untrusted."
58366+ These users will not be able to execute any files that are not in
58367+ root-owned directories writable only by root. If the sysctl option
58368+ is enabled, a sysctl option with name "tpe" is created.
58369+
58370+config GRKERNSEC_TPE_ALL
58371+ bool "Partially restrict all non-root users"
58372+ depends on GRKERNSEC_TPE
58373+ help
58374+ If you say Y here, all non-root users will be covered under
58375+ a weaker TPE restriction. This is separate from, and in addition to,
58376+ the main TPE options that you have selected elsewhere. Thus, if a
58377+ "trusted" GID is chosen, this restriction applies to even that GID.
58378+ Under this restriction, all non-root users will only be allowed to
58379+ execute files in directories they own that are not group or
58380+ world-writable, or in directories owned by root and writable only by
58381+ root. If the sysctl option is enabled, a sysctl option with name
58382+ "tpe_restrict_all" is created.
58383+
58384+config GRKERNSEC_TPE_INVERT
58385+ bool "Invert GID option"
58386+ depends on GRKERNSEC_TPE
58387+ help
58388+ If you say Y here, the group you specify in the TPE configuration will
58389+ decide what group TPE restrictions will be *disabled* for. This
58390+ option is useful if you want TPE restrictions to be applied to most
58391+ users on the system. If the sysctl option is enabled, a sysctl option
58392+ with name "tpe_invert" is created. Unlike other sysctl options, this
58393+ entry will default to on for backward-compatibility.
58394+
58395+config GRKERNSEC_TPE_GID
58396+ int
58397+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
58398+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
58399+
58400+config GRKERNSEC_TPE_UNTRUSTED_GID
58401+ int "GID for TPE-untrusted users"
58402+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
58403+ default 1005
58404+ help
58405+ Setting this GID determines what group TPE restrictions will be
58406+ *enabled* for. If the sysctl option is enabled, a sysctl option
58407+ with name "tpe_gid" is created.
58408+
58409+config GRKERNSEC_TPE_TRUSTED_GID
58410+ int "GID for TPE-trusted users"
58411+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
58412+ default 1005
58413+ help
58414+ Setting this GID determines what group TPE restrictions will be
58415+ *disabled* for. If the sysctl option is enabled, a sysctl option
58416+ with name "tpe_gid" is created.
58417+
58418+endmenu
58419+menu "Network Protections"
58420+depends on GRKERNSEC
58421+
58422+config GRKERNSEC_RANDNET
58423+ bool "Larger entropy pools"
58424+ default y if GRKERNSEC_CONFIG_AUTO
58425+ help
58426+ If you say Y here, the entropy pools used for many features of Linux
58427+ and grsecurity will be doubled in size. Since several grsecurity
58428+ features use additional randomness, it is recommended that you say Y
58429+ here. Saying Y here has a similar effect as modifying
58430+ /proc/sys/kernel/random/poolsize.
58431+
58432+config GRKERNSEC_BLACKHOLE
58433+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
58434+ default y if GRKERNSEC_CONFIG_AUTO
58435+ depends on NET
58436+ help
58437+ If you say Y here, neither TCP resets nor ICMP
58438+ destination-unreachable packets will be sent in response to packets
58439+ sent to ports for which no associated listening process exists.
58440+ This feature supports both IPV4 and IPV6 and exempts the
58441+ loopback interface from blackholing. Enabling this feature
58442+ makes a host more resilient to DoS attacks and reduces network
58443+ visibility against scanners.
58444+
58445+ The blackhole feature as-implemented is equivalent to the FreeBSD
58446+ blackhole feature, as it prevents RST responses to all packets, not
58447+ just SYNs. Under most application behavior this causes no
58448+ problems, but applications (like haproxy) may not close certain
58449+ connections in a way that cleanly terminates them on the remote
58450+ end, leaving the remote host in LAST_ACK state. Because of this
58451+ side-effect and to prevent intentional LAST_ACK DoSes, this
58452+ feature also adds automatic mitigation against such attacks.
58453+ The mitigation drastically reduces the amount of time a socket
58454+ can spend in LAST_ACK state. If you're using haproxy and not
58455+ all servers it connects to have this option enabled, consider
58456+ disabling this feature on the haproxy host.
58457+
58458+ If the sysctl option is enabled, two sysctl options with names
58459+ "ip_blackhole" and "lastack_retries" will be created.
58460+ While "ip_blackhole" takes the standard zero/non-zero on/off
58461+ toggle, "lastack_retries" uses the same kinds of values as
58462+ "tcp_retries1" and "tcp_retries2". The default value of 4
58463+ prevents a socket from lasting more than 45 seconds in LAST_ACK
58464+ state.
58465+
58466+config GRKERNSEC_NO_SIMULT_CONNECT
58467+ bool "Disable TCP Simultaneous Connect"
58468+ default y if GRKERNSEC_CONFIG_AUTO
58469+ depends on NET
58470+ help
58471+ If you say Y here, a feature by Willy Tarreau will be enabled that
58472+ removes a weakness in Linux's strict implementation of TCP that
58473+ allows two clients to connect to each other without either entering
58474+ a listening state. The weakness allows an attacker to easily prevent
58475+ a client from connecting to a known server provided the source port
58476+ for the connection is guessed correctly.
58477+
58478+ As the weakness could be used to prevent an antivirus or IPS from
58479+ fetching updates, or prevent an SSL gateway from fetching a CRL,
58480+ it should be eliminated by enabling this option. Though Linux is
58481+ one of few operating systems supporting simultaneous connect, it
58482+ has no legitimate use in practice and is rarely supported by firewalls.
58483+
58484+config GRKERNSEC_SOCKET
58485+ bool "Socket restrictions"
58486+ depends on NET
58487+ help
58488+ If you say Y here, you will be able to choose from several options.
58489+ If you assign a GID on your system and add it to the supplementary
58490+ groups of users you want to restrict socket access to, this patch
58491+ will perform up to three things, based on the option(s) you choose.
58492+
58493+config GRKERNSEC_SOCKET_ALL
58494+ bool "Deny any sockets to group"
58495+ depends on GRKERNSEC_SOCKET
58496+ help
58497+ If you say Y here, you will be able to choose a GID of whose users will
58498+ be unable to connect to other hosts from your machine or run server
58499+ applications from your machine. If the sysctl option is enabled, a
58500+ sysctl option with name "socket_all" is created.
58501+
58502+config GRKERNSEC_SOCKET_ALL_GID
58503+ int "GID to deny all sockets for"
58504+ depends on GRKERNSEC_SOCKET_ALL
58505+ default 1004
58506+ help
58507+ Here you can choose the GID to disable socket access for. Remember to
58508+ add the users you want socket access disabled for to the GID
58509+ specified here. If the sysctl option is enabled, a sysctl option
58510+ with name "socket_all_gid" is created.
58511+
58512+config GRKERNSEC_SOCKET_CLIENT
58513+ bool "Deny client sockets to group"
58514+ depends on GRKERNSEC_SOCKET
58515+ help
58516+ If you say Y here, you will be able to choose a GID of whose users will
58517+ be unable to connect to other hosts from your machine, but will be
58518+ able to run servers. If this option is enabled, all users in the group
58519+ you specify will have to use passive mode when initiating ftp transfers
58520+ from the shell on your machine. If the sysctl option is enabled, a
58521+ sysctl option with name "socket_client" is created.
58522+
58523+config GRKERNSEC_SOCKET_CLIENT_GID
58524+ int "GID to deny client sockets for"
58525+ depends on GRKERNSEC_SOCKET_CLIENT
58526+ default 1003
58527+ help
58528+ Here you can choose the GID to disable client socket access for.
58529+ Remember to add the users you want client socket access disabled for to
58530+ the GID specified here. If the sysctl option is enabled, a sysctl
58531+ option with name "socket_client_gid" is created.
58532+
58533+config GRKERNSEC_SOCKET_SERVER
58534+ bool "Deny server sockets to group"
58535+ depends on GRKERNSEC_SOCKET
58536+ help
58537+ If you say Y here, you will be able to choose a GID of whose users will
58538+ be unable to run server applications from your machine. If the sysctl
58539+ option is enabled, a sysctl option with name "socket_server" is created.
58540+
58541+config GRKERNSEC_SOCKET_SERVER_GID
58542+ int "GID to deny server sockets for"
58543+ depends on GRKERNSEC_SOCKET_SERVER
58544+ default 1002
58545+ help
58546+ Here you can choose the GID to disable server socket access for.
58547+ Remember to add the users you want server socket access disabled for to
58548+ the GID specified here. If the sysctl option is enabled, a sysctl
58549+ option with name "socket_server_gid" is created.
58550+
58551+endmenu
58552+menu "Sysctl Support"
58553+depends on GRKERNSEC && SYSCTL
58554+
58555+config GRKERNSEC_SYSCTL
58556+ bool "Sysctl support"
58557+ default y if GRKERNSEC_CONFIG_AUTO
58558+ help
58559+ If you say Y here, you will be able to change the options that
58560+ grsecurity runs with at bootup, without having to recompile your
58561+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
58562+ to enable (1) or disable (0) various features. All the sysctl entries
58563+ are mutable until the "grsec_lock" entry is set to a non-zero value.
58564+ All features enabled in the kernel configuration are disabled at boot
58565+ if you do not say Y to the "Turn on features by default" option.
58566+ All options should be set at startup, and the grsec_lock entry should
58567+ be set to a non-zero value after all the options are set.
58568+ *THIS IS EXTREMELY IMPORTANT*
58569+
58570+config GRKERNSEC_SYSCTL_DISTRO
58571+ bool "Extra sysctl support for distro makers (READ HELP)"
58572+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
58573+ help
58574+ If you say Y here, additional sysctl options will be created
58575+ for features that affect processes running as root. Therefore,
58576+ it is critical when using this option that the grsec_lock entry be
58577+ enabled after boot. Only distros with prebuilt kernel packages
58578+ with this option enabled that can ensure grsec_lock is enabled
58579+ after boot should use this option.
58580+ *Failure to set grsec_lock after boot makes all grsec features
58581+ this option covers useless*
58582+
58583+ Currently this option creates the following sysctl entries:
58584+ "Disable Privileged I/O": "disable_priv_io"
58585+
58586+config GRKERNSEC_SYSCTL_ON
58587+ bool "Turn on features by default"
58588+ default y if GRKERNSEC_CONFIG_AUTO
58589+ depends on GRKERNSEC_SYSCTL
58590+ help
58591+ If you say Y here, instead of having all features enabled in the
58592+ kernel configuration disabled at boot time, the features will be
58593+ enabled at boot time. It is recommended you say Y here unless
58594+ there is some reason you would want all sysctl-tunable features to
58595+ be disabled by default. As mentioned elsewhere, it is important
58596+ to enable the grsec_lock entry once you have finished modifying
58597+ the sysctl entries.
58598+
58599+endmenu
58600+menu "Logging Options"
58601+depends on GRKERNSEC
58602+
58603+config GRKERNSEC_FLOODTIME
58604+ int "Seconds in between log messages (minimum)"
58605+ default 10
58606+ help
58607+ This option allows you to enforce the number of seconds between
58608+ grsecurity log messages. The default should be suitable for most
58609+ people, however, if you choose to change it, choose a value small enough
58610+ to allow informative logs to be produced, but large enough to
58611+ prevent flooding.
58612+
58613+config GRKERNSEC_FLOODBURST
58614+ int "Number of messages in a burst (maximum)"
58615+ default 6
58616+ help
58617+ This option allows you to choose the maximum number of messages allowed
58618+ within the flood time interval you chose in a separate option. The
58619+ default should be suitable for most people, however if you find that
58620+ many of your logs are being interpreted as flooding, you may want to
58621+ raise this value.
58622+
58623+endmenu
58624diff --git a/grsecurity/Makefile b/grsecurity/Makefile
58625new file mode 100644
58626index 0000000..1b9afa9
58627--- /dev/null
58628+++ b/grsecurity/Makefile
58629@@ -0,0 +1,38 @@
58630+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
58631+# during 2001-2009 it has been completely redesigned by Brad Spengler
58632+# into an RBAC system
58633+#
58634+# All code in this directory and various hooks inserted throughout the kernel
58635+# are copyright Brad Spengler - Open Source Security, Inc., and released
58636+# under the GPL v2 or higher
58637+
58638+KBUILD_CFLAGS += -Werror
58639+
58640+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
58641+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
58642+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
58643+
58644+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
58645+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
58646+ gracl_learn.o grsec_log.o
58647+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
58648+
58649+ifdef CONFIG_NET
58650+obj-y += grsec_sock.o
58651+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
58652+endif
58653+
58654+ifndef CONFIG_GRKERNSEC
58655+obj-y += grsec_disabled.o
58656+endif
58657+
58658+ifdef CONFIG_GRKERNSEC_HIDESYM
58659+extra-y := grsec_hidesym.o
58660+$(obj)/grsec_hidesym.o:
58661+ @-chmod -f 500 /boot
58662+ @-chmod -f 500 /lib/modules
58663+ @-chmod -f 500 /lib64/modules
58664+ @-chmod -f 500 /lib32/modules
58665+ @-chmod -f 700 .
58666+ @echo ' grsec: protected kernel image paths'
58667+endif
58668diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
58669new file mode 100644
58670index 0000000..b306b36
58671--- /dev/null
58672+++ b/grsecurity/gracl.c
58673@@ -0,0 +1,4071 @@
58674+#include <linux/kernel.h>
58675+#include <linux/module.h>
58676+#include <linux/sched.h>
58677+#include <linux/mm.h>
58678+#include <linux/file.h>
58679+#include <linux/fs.h>
58680+#include <linux/namei.h>
58681+#include <linux/mount.h>
58682+#include <linux/tty.h>
58683+#include <linux/proc_fs.h>
58684+#include <linux/lglock.h>
58685+#include <linux/slab.h>
58686+#include <linux/vmalloc.h>
58687+#include <linux/types.h>
58688+#include <linux/sysctl.h>
58689+#include <linux/netdevice.h>
58690+#include <linux/ptrace.h>
58691+#include <linux/gracl.h>
58692+#include <linux/gralloc.h>
58693+#include <linux/security.h>
58694+#include <linux/grinternal.h>
58695+#include <linux/pid_namespace.h>
58696+#include <linux/stop_machine.h>
58697+#include <linux/fdtable.h>
58698+#include <linux/percpu.h>
58699+#include <linux/lglock.h>
58700+#include <linux/hugetlb.h>
58701+#include <linux/posix-timers.h>
58702+#include "../fs/mount.h"
58703+
58704+#include <asm/uaccess.h>
58705+#include <asm/errno.h>
58706+#include <asm/mman.h>
58707+
58708+extern struct lglock vfsmount_lock;
58709+
58710+static struct acl_role_db acl_role_set;
58711+static struct name_db name_set;
58712+static struct inodev_db inodev_set;
58713+
58714+/* for keeping track of userspace pointers used for subjects, so we
58715+ can share references in the kernel as well
58716+*/
58717+
58718+static struct path real_root;
58719+
58720+static struct acl_subj_map_db subj_map_set;
58721+
58722+static struct acl_role_label *default_role;
58723+
58724+static struct acl_role_label *role_list;
58725+
58726+static u16 acl_sp_role_value;
58727+
58728+extern char *gr_shared_page[4];
58729+static DEFINE_MUTEX(gr_dev_mutex);
58730+DEFINE_RWLOCK(gr_inode_lock);
58731+
58732+struct gr_arg *gr_usermode;
58733+
58734+static unsigned int gr_status __read_only = GR_STATUS_INIT;
58735+
58736+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
58737+extern void gr_clear_learn_entries(void);
58738+
58739+unsigned char *gr_system_salt;
58740+unsigned char *gr_system_sum;
58741+
58742+static struct sprole_pw **acl_special_roles = NULL;
58743+static __u16 num_sprole_pws = 0;
58744+
58745+static struct acl_role_label *kernel_role = NULL;
58746+
58747+static unsigned int gr_auth_attempts = 0;
58748+static unsigned long gr_auth_expires = 0UL;
58749+
58750+#ifdef CONFIG_NET
58751+extern struct vfsmount *sock_mnt;
58752+#endif
58753+
58754+extern struct vfsmount *pipe_mnt;
58755+extern struct vfsmount *shm_mnt;
58756+
58757+#ifdef CONFIG_HUGETLBFS
58758+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
58759+#endif
58760+
58761+static struct acl_object_label *fakefs_obj_rw;
58762+static struct acl_object_label *fakefs_obj_rwx;
58763+
58764+extern int gr_init_uidset(void);
58765+extern void gr_free_uidset(void);
58766+extern void gr_remove_uid(uid_t uid);
58767+extern int gr_find_uid(uid_t uid);
58768+
58769+__inline__ int
58770+gr_acl_is_enabled(void)
58771+{
58772+ return (gr_status & GR_READY);
58773+}
58774+
58775+#ifdef CONFIG_BTRFS_FS
58776+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
58777+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
58778+#endif
58779+
58780+static inline dev_t __get_dev(const struct dentry *dentry)
58781+{
58782+#ifdef CONFIG_BTRFS_FS
58783+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
58784+ return get_btrfs_dev_from_inode(dentry->d_inode);
58785+ else
58786+#endif
58787+ return dentry->d_inode->i_sb->s_dev;
58788+}
58789+
58790+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
58791+{
58792+ return __get_dev(dentry);
58793+}
58794+
58795+static char gr_task_roletype_to_char(struct task_struct *task)
58796+{
58797+ switch (task->role->roletype &
58798+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
58799+ GR_ROLE_SPECIAL)) {
58800+ case GR_ROLE_DEFAULT:
58801+ return 'D';
58802+ case GR_ROLE_USER:
58803+ return 'U';
58804+ case GR_ROLE_GROUP:
58805+ return 'G';
58806+ case GR_ROLE_SPECIAL:
58807+ return 'S';
58808+ }
58809+
58810+ return 'X';
58811+}
58812+
58813+char gr_roletype_to_char(void)
58814+{
58815+ return gr_task_roletype_to_char(current);
58816+}
58817+
58818+__inline__ int
58819+gr_acl_tpe_check(void)
58820+{
58821+ if (unlikely(!(gr_status & GR_READY)))
58822+ return 0;
58823+ if (current->role->roletype & GR_ROLE_TPE)
58824+ return 1;
58825+ else
58826+ return 0;
58827+}
58828+
58829+int
58830+gr_handle_rawio(const struct inode *inode)
58831+{
58832+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58833+ if (inode && S_ISBLK(inode->i_mode) &&
58834+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
58835+ !capable(CAP_SYS_RAWIO))
58836+ return 1;
58837+#endif
58838+ return 0;
58839+}
58840+
58841+static int
58842+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
58843+{
58844+ if (likely(lena != lenb))
58845+ return 0;
58846+
58847+ return !memcmp(a, b, lena);
58848+}
58849+
58850+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
58851+{
58852+ *buflen -= namelen;
58853+ if (*buflen < 0)
58854+ return -ENAMETOOLONG;
58855+ *buffer -= namelen;
58856+ memcpy(*buffer, str, namelen);
58857+ return 0;
58858+}
58859+
58860+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
58861+{
58862+ return prepend(buffer, buflen, name->name, name->len);
58863+}
58864+
58865+static int prepend_path(const struct path *path, struct path *root,
58866+ char **buffer, int *buflen)
58867+{
58868+ struct dentry *dentry = path->dentry;
58869+ struct vfsmount *vfsmnt = path->mnt;
58870+ struct mount *mnt = real_mount(vfsmnt);
58871+ bool slash = false;
58872+ int error = 0;
58873+
58874+ while (dentry != root->dentry || vfsmnt != root->mnt) {
58875+ struct dentry * parent;
58876+
58877+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
58878+ /* Global root? */
58879+ if (!mnt_has_parent(mnt)) {
58880+ goto out;
58881+ }
58882+ dentry = mnt->mnt_mountpoint;
58883+ mnt = mnt->mnt_parent;
58884+ vfsmnt = &mnt->mnt;
58885+ continue;
58886+ }
58887+ parent = dentry->d_parent;
58888+ prefetch(parent);
58889+ spin_lock(&dentry->d_lock);
58890+ error = prepend_name(buffer, buflen, &dentry->d_name);
58891+ spin_unlock(&dentry->d_lock);
58892+ if (!error)
58893+ error = prepend(buffer, buflen, "/", 1);
58894+ if (error)
58895+ break;
58896+
58897+ slash = true;
58898+ dentry = parent;
58899+ }
58900+
58901+out:
58902+ if (!error && !slash)
58903+ error = prepend(buffer, buflen, "/", 1);
58904+
58905+ return error;
58906+}
58907+
58908+/* this must be called with vfsmount_lock and rename_lock held */
58909+
58910+static char *__our_d_path(const struct path *path, struct path *root,
58911+ char *buf, int buflen)
58912+{
58913+ char *res = buf + buflen;
58914+ int error;
58915+
58916+ prepend(&res, &buflen, "\0", 1);
58917+ error = prepend_path(path, root, &res, &buflen);
58918+ if (error)
58919+ return ERR_PTR(error);
58920+
58921+ return res;
58922+}
58923+
58924+static char *
58925+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
58926+{
58927+ char *retval;
58928+
58929+ retval = __our_d_path(path, root, buf, buflen);
58930+ if (unlikely(IS_ERR(retval)))
58931+ retval = strcpy(buf, "<path too long>");
58932+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
58933+ retval[1] = '\0';
58934+
58935+ return retval;
58936+}
58937+
58938+static char *
58939+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
58940+ char *buf, int buflen)
58941+{
58942+ struct path path;
58943+ char *res;
58944+
58945+ path.dentry = (struct dentry *)dentry;
58946+ path.mnt = (struct vfsmount *)vfsmnt;
58947+
58948+ /* we can use real_root.dentry, real_root.mnt, because this is only called
58949+ by the RBAC system */
58950+ res = gen_full_path(&path, &real_root, buf, buflen);
58951+
58952+ return res;
58953+}
58954+
58955+static char *
58956+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
58957+ char *buf, int buflen)
58958+{
58959+ char *res;
58960+ struct path path;
58961+ struct path root;
58962+ struct task_struct *reaper = init_pid_ns.child_reaper;
58963+
58964+ path.dentry = (struct dentry *)dentry;
58965+ path.mnt = (struct vfsmount *)vfsmnt;
58966+
58967+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
58968+ get_fs_root(reaper->fs, &root);
58969+
58970+ br_read_lock(&vfsmount_lock);
58971+ write_seqlock(&rename_lock);
58972+ res = gen_full_path(&path, &root, buf, buflen);
58973+ write_sequnlock(&rename_lock);
58974+ br_read_unlock(&vfsmount_lock);
58975+
58976+ path_put(&root);
58977+ return res;
58978+}
58979+
58980+static char *
58981+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
58982+{
58983+ char *ret;
58984+ br_read_lock(&vfsmount_lock);
58985+ write_seqlock(&rename_lock);
58986+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
58987+ PAGE_SIZE);
58988+ write_sequnlock(&rename_lock);
58989+ br_read_unlock(&vfsmount_lock);
58990+ return ret;
58991+}
58992+
58993+static char *
58994+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
58995+{
58996+ char *ret;
58997+ char *buf;
58998+ int buflen;
58999+
59000+ br_read_lock(&vfsmount_lock);
59001+ write_seqlock(&rename_lock);
59002+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
59003+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
59004+ buflen = (int)(ret - buf);
59005+ if (buflen >= 5)
59006+ prepend(&ret, &buflen, "/proc", 5);
59007+ else
59008+ ret = strcpy(buf, "<path too long>");
59009+ write_sequnlock(&rename_lock);
59010+ br_read_unlock(&vfsmount_lock);
59011+ return ret;
59012+}
59013+
59014+char *
59015+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
59016+{
59017+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
59018+ PAGE_SIZE);
59019+}
59020+
59021+char *
59022+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
59023+{
59024+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
59025+ PAGE_SIZE);
59026+}
59027+
59028+char *
59029+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
59030+{
59031+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
59032+ PAGE_SIZE);
59033+}
59034+
59035+char *
59036+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
59037+{
59038+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
59039+ PAGE_SIZE);
59040+}
59041+
59042+char *
59043+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
59044+{
59045+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
59046+ PAGE_SIZE);
59047+}
59048+
59049+__inline__ __u32
59050+to_gr_audit(const __u32 reqmode)
59051+{
59052+ /* masks off auditable permission flags, then shifts them to create
59053+ auditing flags, and adds the special case of append auditing if
59054+ we're requesting write */
59055+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
59056+}
59057+
59058+struct acl_subject_label *
59059+lookup_subject_map(const struct acl_subject_label *userp)
59060+{
59061+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
59062+ struct subject_map *match;
59063+
59064+ match = subj_map_set.s_hash[index];
59065+
59066+ while (match && match->user != userp)
59067+ match = match->next;
59068+
59069+ if (match != NULL)
59070+ return match->kernel;
59071+ else
59072+ return NULL;
59073+}
59074+
59075+static void
59076+insert_subj_map_entry(struct subject_map *subjmap)
59077+{
59078+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
59079+ struct subject_map **curr;
59080+
59081+ subjmap->prev = NULL;
59082+
59083+ curr = &subj_map_set.s_hash[index];
59084+ if (*curr != NULL)
59085+ (*curr)->prev = subjmap;
59086+
59087+ subjmap->next = *curr;
59088+ *curr = subjmap;
59089+
59090+ return;
59091+}
59092+
59093+static struct acl_role_label *
59094+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
59095+ const gid_t gid)
59096+{
59097+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
59098+ struct acl_role_label *match;
59099+ struct role_allowed_ip *ipp;
59100+ unsigned int x;
59101+ u32 curr_ip = task->signal->curr_ip;
59102+
59103+ task->signal->saved_ip = curr_ip;
59104+
59105+ match = acl_role_set.r_hash[index];
59106+
59107+ while (match) {
59108+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
59109+ for (x = 0; x < match->domain_child_num; x++) {
59110+ if (match->domain_children[x] == uid)
59111+ goto found;
59112+ }
59113+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
59114+ break;
59115+ match = match->next;
59116+ }
59117+found:
59118+ if (match == NULL) {
59119+ try_group:
59120+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
59121+ match = acl_role_set.r_hash[index];
59122+
59123+ while (match) {
59124+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
59125+ for (x = 0; x < match->domain_child_num; x++) {
59126+ if (match->domain_children[x] == gid)
59127+ goto found2;
59128+ }
59129+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
59130+ break;
59131+ match = match->next;
59132+ }
59133+found2:
59134+ if (match == NULL)
59135+ match = default_role;
59136+ if (match->allowed_ips == NULL)
59137+ return match;
59138+ else {
59139+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
59140+ if (likely
59141+ ((ntohl(curr_ip) & ipp->netmask) ==
59142+ (ntohl(ipp->addr) & ipp->netmask)))
59143+ return match;
59144+ }
59145+ match = default_role;
59146+ }
59147+ } else if (match->allowed_ips == NULL) {
59148+ return match;
59149+ } else {
59150+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
59151+ if (likely
59152+ ((ntohl(curr_ip) & ipp->netmask) ==
59153+ (ntohl(ipp->addr) & ipp->netmask)))
59154+ return match;
59155+ }
59156+ goto try_group;
59157+ }
59158+
59159+ return match;
59160+}
59161+
59162+struct acl_subject_label *
59163+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
59164+ const struct acl_role_label *role)
59165+{
59166+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
59167+ struct acl_subject_label *match;
59168+
59169+ match = role->subj_hash[index];
59170+
59171+ while (match && (match->inode != ino || match->device != dev ||
59172+ (match->mode & GR_DELETED))) {
59173+ match = match->next;
59174+ }
59175+
59176+ if (match && !(match->mode & GR_DELETED))
59177+ return match;
59178+ else
59179+ return NULL;
59180+}
59181+
59182+struct acl_subject_label *
59183+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
59184+ const struct acl_role_label *role)
59185+{
59186+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
59187+ struct acl_subject_label *match;
59188+
59189+ match = role->subj_hash[index];
59190+
59191+ while (match && (match->inode != ino || match->device != dev ||
59192+ !(match->mode & GR_DELETED))) {
59193+ match = match->next;
59194+ }
59195+
59196+ if (match && (match->mode & GR_DELETED))
59197+ return match;
59198+ else
59199+ return NULL;
59200+}
59201+
59202+static struct acl_object_label *
59203+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
59204+ const struct acl_subject_label *subj)
59205+{
59206+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
59207+ struct acl_object_label *match;
59208+
59209+ match = subj->obj_hash[index];
59210+
59211+ while (match && (match->inode != ino || match->device != dev ||
59212+ (match->mode & GR_DELETED))) {
59213+ match = match->next;
59214+ }
59215+
59216+ if (match && !(match->mode & GR_DELETED))
59217+ return match;
59218+ else
59219+ return NULL;
59220+}
59221+
59222+static struct acl_object_label *
59223+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
59224+ const struct acl_subject_label *subj)
59225+{
59226+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
59227+ struct acl_object_label *match;
59228+
59229+ match = subj->obj_hash[index];
59230+
59231+ while (match && (match->inode != ino || match->device != dev ||
59232+ !(match->mode & GR_DELETED))) {
59233+ match = match->next;
59234+ }
59235+
59236+ if (match && (match->mode & GR_DELETED))
59237+ return match;
59238+
59239+ match = subj->obj_hash[index];
59240+
59241+ while (match && (match->inode != ino || match->device != dev ||
59242+ (match->mode & GR_DELETED))) {
59243+ match = match->next;
59244+ }
59245+
59246+ if (match && !(match->mode & GR_DELETED))
59247+ return match;
59248+ else
59249+ return NULL;
59250+}
59251+
59252+static struct name_entry *
59253+lookup_name_entry(const char *name)
59254+{
59255+ unsigned int len = strlen(name);
59256+ unsigned int key = full_name_hash(name, len);
59257+ unsigned int index = key % name_set.n_size;
59258+ struct name_entry *match;
59259+
59260+ match = name_set.n_hash[index];
59261+
59262+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
59263+ match = match->next;
59264+
59265+ return match;
59266+}
59267+
59268+static struct name_entry *
59269+lookup_name_entry_create(const char *name)
59270+{
59271+ unsigned int len = strlen(name);
59272+ unsigned int key = full_name_hash(name, len);
59273+ unsigned int index = key % name_set.n_size;
59274+ struct name_entry *match;
59275+
59276+ match = name_set.n_hash[index];
59277+
59278+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
59279+ !match->deleted))
59280+ match = match->next;
59281+
59282+ if (match && match->deleted)
59283+ return match;
59284+
59285+ match = name_set.n_hash[index];
59286+
59287+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
59288+ match->deleted))
59289+ match = match->next;
59290+
59291+ if (match && !match->deleted)
59292+ return match;
59293+ else
59294+ return NULL;
59295+}
59296+
59297+static struct inodev_entry *
59298+lookup_inodev_entry(const ino_t ino, const dev_t dev)
59299+{
59300+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
59301+ struct inodev_entry *match;
59302+
59303+ match = inodev_set.i_hash[index];
59304+
59305+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
59306+ match = match->next;
59307+
59308+ return match;
59309+}
59310+
59311+static void
59312+insert_inodev_entry(struct inodev_entry *entry)
59313+{
59314+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
59315+ inodev_set.i_size);
59316+ struct inodev_entry **curr;
59317+
59318+ entry->prev = NULL;
59319+
59320+ curr = &inodev_set.i_hash[index];
59321+ if (*curr != NULL)
59322+ (*curr)->prev = entry;
59323+
59324+ entry->next = *curr;
59325+ *curr = entry;
59326+
59327+ return;
59328+}
59329+
59330+static void
59331+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
59332+{
59333+ unsigned int index =
59334+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
59335+ struct acl_role_label **curr;
59336+ struct acl_role_label *tmp, *tmp2;
59337+
59338+ curr = &acl_role_set.r_hash[index];
59339+
59340+ /* simple case, slot is empty, just set it to our role */
59341+ if (*curr == NULL) {
59342+ *curr = role;
59343+ } else {
59344+ /* example:
59345+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
59346+ 2 -> 3
59347+ */
59348+ /* first check to see if we can already be reached via this slot */
59349+ tmp = *curr;
59350+ while (tmp && tmp != role)
59351+ tmp = tmp->next;
59352+ if (tmp == role) {
59353+ /* we don't need to add ourselves to this slot's chain */
59354+ return;
59355+ }
59356+ /* we need to add ourselves to this chain, two cases */
59357+ if (role->next == NULL) {
59358+ /* simple case, append the current chain to our role */
59359+ role->next = *curr;
59360+ *curr = role;
59361+ } else {
59362+ /* 1 -> 2 -> 3 -> 4
59363+ 2 -> 3 -> 4
59364+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
59365+ */
59366+ /* trickier case: walk our role's chain until we find
59367+ the role for the start of the current slot's chain */
59368+ tmp = role;
59369+ tmp2 = *curr;
59370+ while (tmp->next && tmp->next != tmp2)
59371+ tmp = tmp->next;
59372+ if (tmp->next == tmp2) {
59373+ /* from example above, we found 3, so just
59374+ replace this slot's chain with ours */
59375+ *curr = role;
59376+ } else {
59377+ /* we didn't find a subset of our role's chain
59378+ in the current slot's chain, so append their
59379+ chain to ours, and set us as the first role in
59380+ the slot's chain
59381+
59382+ we could fold this case with the case above,
59383+ but making it explicit for clarity
59384+ */
59385+ tmp->next = tmp2;
59386+ *curr = role;
59387+ }
59388+ }
59389+ }
59390+
59391+ return;
59392+}
59393+
59394+static void
59395+insert_acl_role_label(struct acl_role_label *role)
59396+{
59397+ int i;
59398+
59399+ if (role_list == NULL) {
59400+ role_list = role;
59401+ role->prev = NULL;
59402+ } else {
59403+ role->prev = role_list;
59404+ role_list = role;
59405+ }
59406+
59407+ /* used for hash chains */
59408+ role->next = NULL;
59409+
59410+ if (role->roletype & GR_ROLE_DOMAIN) {
59411+ for (i = 0; i < role->domain_child_num; i++)
59412+ __insert_acl_role_label(role, role->domain_children[i]);
59413+ } else
59414+ __insert_acl_role_label(role, role->uidgid);
59415+}
59416+
59417+static int
59418+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
59419+{
59420+ struct name_entry **curr, *nentry;
59421+ struct inodev_entry *ientry;
59422+ unsigned int len = strlen(name);
59423+ unsigned int key = full_name_hash(name, len);
59424+ unsigned int index = key % name_set.n_size;
59425+
59426+ curr = &name_set.n_hash[index];
59427+
59428+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
59429+ curr = &((*curr)->next);
59430+
59431+ if (*curr != NULL)
59432+ return 1;
59433+
59434+ nentry = acl_alloc(sizeof (struct name_entry));
59435+ if (nentry == NULL)
59436+ return 0;
59437+ ientry = acl_alloc(sizeof (struct inodev_entry));
59438+ if (ientry == NULL)
59439+ return 0;
59440+ ientry->nentry = nentry;
59441+
59442+ nentry->key = key;
59443+ nentry->name = name;
59444+ nentry->inode = inode;
59445+ nentry->device = device;
59446+ nentry->len = len;
59447+ nentry->deleted = deleted;
59448+
59449+ nentry->prev = NULL;
59450+ curr = &name_set.n_hash[index];
59451+ if (*curr != NULL)
59452+ (*curr)->prev = nentry;
59453+ nentry->next = *curr;
59454+ *curr = nentry;
59455+
59456+ /* insert us into the table searchable by inode/dev */
59457+ insert_inodev_entry(ientry);
59458+
59459+ return 1;
59460+}
59461+
59462+static void
59463+insert_acl_obj_label(struct acl_object_label *obj,
59464+ struct acl_subject_label *subj)
59465+{
59466+ unsigned int index =
59467+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
59468+ struct acl_object_label **curr;
59469+
59470+
59471+ obj->prev = NULL;
59472+
59473+ curr = &subj->obj_hash[index];
59474+ if (*curr != NULL)
59475+ (*curr)->prev = obj;
59476+
59477+ obj->next = *curr;
59478+ *curr = obj;
59479+
59480+ return;
59481+}
59482+
59483+static void
59484+insert_acl_subj_label(struct acl_subject_label *obj,
59485+ struct acl_role_label *role)
59486+{
59487+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
59488+ struct acl_subject_label **curr;
59489+
59490+ obj->prev = NULL;
59491+
59492+ curr = &role->subj_hash[index];
59493+ if (*curr != NULL)
59494+ (*curr)->prev = obj;
59495+
59496+ obj->next = *curr;
59497+ *curr = obj;
59498+
59499+ return;
59500+}
59501+
59502+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
59503+
59504+static void *
59505+create_table(__u32 * len, int elementsize)
59506+{
59507+ unsigned int table_sizes[] = {
59508+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
59509+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
59510+ 4194301, 8388593, 16777213, 33554393, 67108859
59511+ };
59512+ void *newtable = NULL;
59513+ unsigned int pwr = 0;
59514+
59515+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
59516+ table_sizes[pwr] <= *len)
59517+ pwr++;
59518+
59519+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
59520+ return newtable;
59521+
59522+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
59523+ newtable =
59524+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
59525+ else
59526+ newtable = vmalloc(table_sizes[pwr] * elementsize);
59527+
59528+ *len = table_sizes[pwr];
59529+
59530+ return newtable;
59531+}
59532+
59533+static int
59534+init_variables(const struct gr_arg *arg)
59535+{
59536+ struct task_struct *reaper = init_pid_ns.child_reaper;
59537+ unsigned int stacksize;
59538+
59539+ subj_map_set.s_size = arg->role_db.num_subjects;
59540+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
59541+ name_set.n_size = arg->role_db.num_objects;
59542+ inodev_set.i_size = arg->role_db.num_objects;
59543+
59544+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
59545+ !name_set.n_size || !inodev_set.i_size)
59546+ return 1;
59547+
59548+ if (!gr_init_uidset())
59549+ return 1;
59550+
59551+ /* set up the stack that holds allocation info */
59552+
59553+ stacksize = arg->role_db.num_pointers + 5;
59554+
59555+ if (!acl_alloc_stack_init(stacksize))
59556+ return 1;
59557+
59558+ /* grab reference for the real root dentry and vfsmount */
59559+ get_fs_root(reaper->fs, &real_root);
59560+
59561+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59562+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
59563+#endif
59564+
59565+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
59566+ if (fakefs_obj_rw == NULL)
59567+ return 1;
59568+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
59569+
59570+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
59571+ if (fakefs_obj_rwx == NULL)
59572+ return 1;
59573+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
59574+
59575+ subj_map_set.s_hash =
59576+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
59577+ acl_role_set.r_hash =
59578+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
59579+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
59580+ inodev_set.i_hash =
59581+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
59582+
59583+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
59584+ !name_set.n_hash || !inodev_set.i_hash)
59585+ return 1;
59586+
59587+ memset(subj_map_set.s_hash, 0,
59588+ sizeof(struct subject_map *) * subj_map_set.s_size);
59589+ memset(acl_role_set.r_hash, 0,
59590+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
59591+ memset(name_set.n_hash, 0,
59592+ sizeof (struct name_entry *) * name_set.n_size);
59593+ memset(inodev_set.i_hash, 0,
59594+ sizeof (struct inodev_entry *) * inodev_set.i_size);
59595+
59596+ return 0;
59597+}
59598+
59599+/* free information not needed after startup
59600+ currently contains user->kernel pointer mappings for subjects
59601+*/
59602+
59603+static void
59604+free_init_variables(void)
59605+{
59606+ __u32 i;
59607+
59608+ if (subj_map_set.s_hash) {
59609+ for (i = 0; i < subj_map_set.s_size; i++) {
59610+ if (subj_map_set.s_hash[i]) {
59611+ kfree(subj_map_set.s_hash[i]);
59612+ subj_map_set.s_hash[i] = NULL;
59613+ }
59614+ }
59615+
59616+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
59617+ PAGE_SIZE)
59618+ kfree(subj_map_set.s_hash);
59619+ else
59620+ vfree(subj_map_set.s_hash);
59621+ }
59622+
59623+ return;
59624+}
59625+
59626+static void
59627+free_variables(void)
59628+{
59629+ struct acl_subject_label *s;
59630+ struct acl_role_label *r;
59631+ struct task_struct *task, *task2;
59632+ unsigned int x;
59633+
59634+ gr_clear_learn_entries();
59635+
59636+ read_lock(&tasklist_lock);
59637+ do_each_thread(task2, task) {
59638+ task->acl_sp_role = 0;
59639+ task->acl_role_id = 0;
59640+ task->acl = NULL;
59641+ task->role = NULL;
59642+ } while_each_thread(task2, task);
59643+ read_unlock(&tasklist_lock);
59644+
59645+ /* release the reference to the real root dentry and vfsmount */
59646+ path_put(&real_root);
59647+ memset(&real_root, 0, sizeof(real_root));
59648+
59649+ /* free all object hash tables */
59650+
59651+ FOR_EACH_ROLE_START(r)
59652+ if (r->subj_hash == NULL)
59653+ goto next_role;
59654+ FOR_EACH_SUBJECT_START(r, s, x)
59655+ if (s->obj_hash == NULL)
59656+ break;
59657+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
59658+ kfree(s->obj_hash);
59659+ else
59660+ vfree(s->obj_hash);
59661+ FOR_EACH_SUBJECT_END(s, x)
59662+ FOR_EACH_NESTED_SUBJECT_START(r, s)
59663+ if (s->obj_hash == NULL)
59664+ break;
59665+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
59666+ kfree(s->obj_hash);
59667+ else
59668+ vfree(s->obj_hash);
59669+ FOR_EACH_NESTED_SUBJECT_END(s)
59670+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
59671+ kfree(r->subj_hash);
59672+ else
59673+ vfree(r->subj_hash);
59674+ r->subj_hash = NULL;
59675+next_role:
59676+ FOR_EACH_ROLE_END(r)
59677+
59678+ acl_free_all();
59679+
59680+ if (acl_role_set.r_hash) {
59681+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
59682+ PAGE_SIZE)
59683+ kfree(acl_role_set.r_hash);
59684+ else
59685+ vfree(acl_role_set.r_hash);
59686+ }
59687+ if (name_set.n_hash) {
59688+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
59689+ PAGE_SIZE)
59690+ kfree(name_set.n_hash);
59691+ else
59692+ vfree(name_set.n_hash);
59693+ }
59694+
59695+ if (inodev_set.i_hash) {
59696+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
59697+ PAGE_SIZE)
59698+ kfree(inodev_set.i_hash);
59699+ else
59700+ vfree(inodev_set.i_hash);
59701+ }
59702+
59703+ gr_free_uidset();
59704+
59705+ memset(&name_set, 0, sizeof (struct name_db));
59706+ memset(&inodev_set, 0, sizeof (struct inodev_db));
59707+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
59708+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
59709+
59710+ default_role = NULL;
59711+ kernel_role = NULL;
59712+ role_list = NULL;
59713+
59714+ return;
59715+}
59716+
59717+static __u32
59718+count_user_objs(struct acl_object_label *userp)
59719+{
59720+ struct acl_object_label o_tmp;
59721+ __u32 num = 0;
59722+
59723+ while (userp) {
59724+ if (copy_from_user(&o_tmp, userp,
59725+ sizeof (struct acl_object_label)))
59726+ break;
59727+
59728+ userp = o_tmp.prev;
59729+ num++;
59730+ }
59731+
59732+ return num;
59733+}
59734+
59735+static struct acl_subject_label *
59736+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
59737+
59738+static int
59739+copy_user_glob(struct acl_object_label *obj)
59740+{
59741+ struct acl_object_label *g_tmp, **guser;
59742+ unsigned int len;
59743+ char *tmp;
59744+
59745+ if (obj->globbed == NULL)
59746+ return 0;
59747+
59748+ guser = &obj->globbed;
59749+ while (*guser) {
59750+ g_tmp = (struct acl_object_label *)
59751+ acl_alloc(sizeof (struct acl_object_label));
59752+ if (g_tmp == NULL)
59753+ return -ENOMEM;
59754+
59755+ if (copy_from_user(g_tmp, *guser,
59756+ sizeof (struct acl_object_label)))
59757+ return -EFAULT;
59758+
59759+ len = strnlen_user(g_tmp->filename, PATH_MAX);
59760+
59761+ if (!len || len >= PATH_MAX)
59762+ return -EINVAL;
59763+
59764+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59765+ return -ENOMEM;
59766+
59767+ if (copy_from_user(tmp, g_tmp->filename, len))
59768+ return -EFAULT;
59769+ tmp[len-1] = '\0';
59770+ g_tmp->filename = tmp;
59771+
59772+ *guser = g_tmp;
59773+ guser = &(g_tmp->next);
59774+ }
59775+
59776+ return 0;
59777+}
59778+
59779+static int
59780+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
59781+ struct acl_role_label *role)
59782+{
59783+ struct acl_object_label *o_tmp;
59784+ unsigned int len;
59785+ int ret;
59786+ char *tmp;
59787+
59788+ while (userp) {
59789+ if ((o_tmp = (struct acl_object_label *)
59790+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
59791+ return -ENOMEM;
59792+
59793+ if (copy_from_user(o_tmp, userp,
59794+ sizeof (struct acl_object_label)))
59795+ return -EFAULT;
59796+
59797+ userp = o_tmp->prev;
59798+
59799+ len = strnlen_user(o_tmp->filename, PATH_MAX);
59800+
59801+ if (!len || len >= PATH_MAX)
59802+ return -EINVAL;
59803+
59804+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59805+ return -ENOMEM;
59806+
59807+ if (copy_from_user(tmp, o_tmp->filename, len))
59808+ return -EFAULT;
59809+ tmp[len-1] = '\0';
59810+ o_tmp->filename = tmp;
59811+
59812+ insert_acl_obj_label(o_tmp, subj);
59813+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
59814+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
59815+ return -ENOMEM;
59816+
59817+ ret = copy_user_glob(o_tmp);
59818+ if (ret)
59819+ return ret;
59820+
59821+ if (o_tmp->nested) {
59822+ int already_copied;
59823+
59824+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
59825+ if (IS_ERR(o_tmp->nested))
59826+ return PTR_ERR(o_tmp->nested);
59827+
59828+ /* insert into nested subject list if we haven't copied this one yet
59829+ to prevent duplicate entries */
59830+ if (!already_copied) {
59831+ o_tmp->nested->next = role->hash->first;
59832+ role->hash->first = o_tmp->nested;
59833+ }
59834+ }
59835+ }
59836+
59837+ return 0;
59838+}
59839+
59840+static __u32
59841+count_user_subjs(struct acl_subject_label *userp)
59842+{
59843+ struct acl_subject_label s_tmp;
59844+ __u32 num = 0;
59845+
59846+ while (userp) {
59847+ if (copy_from_user(&s_tmp, userp,
59848+ sizeof (struct acl_subject_label)))
59849+ break;
59850+
59851+ userp = s_tmp.prev;
59852+ }
59853+
59854+ return num;
59855+}
59856+
59857+static int
59858+copy_user_allowedips(struct acl_role_label *rolep)
59859+{
59860+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
59861+
59862+ ruserip = rolep->allowed_ips;
59863+
59864+ while (ruserip) {
59865+ rlast = rtmp;
59866+
59867+ if ((rtmp = (struct role_allowed_ip *)
59868+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
59869+ return -ENOMEM;
59870+
59871+ if (copy_from_user(rtmp, ruserip,
59872+ sizeof (struct role_allowed_ip)))
59873+ return -EFAULT;
59874+
59875+ ruserip = rtmp->prev;
59876+
59877+ if (!rlast) {
59878+ rtmp->prev = NULL;
59879+ rolep->allowed_ips = rtmp;
59880+ } else {
59881+ rlast->next = rtmp;
59882+ rtmp->prev = rlast;
59883+ }
59884+
59885+ if (!ruserip)
59886+ rtmp->next = NULL;
59887+ }
59888+
59889+ return 0;
59890+}
59891+
59892+static int
59893+copy_user_transitions(struct acl_role_label *rolep)
59894+{
59895+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
59896+
59897+ unsigned int len;
59898+ char *tmp;
59899+
59900+ rusertp = rolep->transitions;
59901+
59902+ while (rusertp) {
59903+ rlast = rtmp;
59904+
59905+ if ((rtmp = (struct role_transition *)
59906+ acl_alloc(sizeof (struct role_transition))) == NULL)
59907+ return -ENOMEM;
59908+
59909+ if (copy_from_user(rtmp, rusertp,
59910+ sizeof (struct role_transition)))
59911+ return -EFAULT;
59912+
59913+ rusertp = rtmp->prev;
59914+
59915+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
59916+
59917+ if (!len || len >= GR_SPROLE_LEN)
59918+ return -EINVAL;
59919+
59920+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59921+ return -ENOMEM;
59922+
59923+ if (copy_from_user(tmp, rtmp->rolename, len))
59924+ return -EFAULT;
59925+ tmp[len-1] = '\0';
59926+ rtmp->rolename = tmp;
59927+
59928+ if (!rlast) {
59929+ rtmp->prev = NULL;
59930+ rolep->transitions = rtmp;
59931+ } else {
59932+ rlast->next = rtmp;
59933+ rtmp->prev = rlast;
59934+ }
59935+
59936+ if (!rusertp)
59937+ rtmp->next = NULL;
59938+ }
59939+
59940+ return 0;
59941+}
59942+
59943+static struct acl_subject_label *
59944+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
59945+{
59946+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
59947+ unsigned int len;
59948+ char *tmp;
59949+ __u32 num_objs;
59950+ struct acl_ip_label **i_tmp, *i_utmp2;
59951+ struct gr_hash_struct ghash;
59952+ struct subject_map *subjmap;
59953+ unsigned int i_num;
59954+ int err;
59955+
59956+ if (already_copied != NULL)
59957+ *already_copied = 0;
59958+
59959+ s_tmp = lookup_subject_map(userp);
59960+
59961+ /* we've already copied this subject into the kernel, just return
59962+ the reference to it, and don't copy it over again
59963+ */
59964+ if (s_tmp) {
59965+ if (already_copied != NULL)
59966+ *already_copied = 1;
59967+ return(s_tmp);
59968+ }
59969+
59970+ if ((s_tmp = (struct acl_subject_label *)
59971+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
59972+ return ERR_PTR(-ENOMEM);
59973+
59974+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
59975+ if (subjmap == NULL)
59976+ return ERR_PTR(-ENOMEM);
59977+
59978+ subjmap->user = userp;
59979+ subjmap->kernel = s_tmp;
59980+ insert_subj_map_entry(subjmap);
59981+
59982+ if (copy_from_user(s_tmp, userp,
59983+ sizeof (struct acl_subject_label)))
59984+ return ERR_PTR(-EFAULT);
59985+
59986+ len = strnlen_user(s_tmp->filename, PATH_MAX);
59987+
59988+ if (!len || len >= PATH_MAX)
59989+ return ERR_PTR(-EINVAL);
59990+
59991+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59992+ return ERR_PTR(-ENOMEM);
59993+
59994+ if (copy_from_user(tmp, s_tmp->filename, len))
59995+ return ERR_PTR(-EFAULT);
59996+ tmp[len-1] = '\0';
59997+ s_tmp->filename = tmp;
59998+
59999+ if (!strcmp(s_tmp->filename, "/"))
60000+ role->root_label = s_tmp;
60001+
60002+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
60003+ return ERR_PTR(-EFAULT);
60004+
60005+ /* copy user and group transition tables */
60006+
60007+ if (s_tmp->user_trans_num) {
60008+ uid_t *uidlist;
60009+
60010+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
60011+ if (uidlist == NULL)
60012+ return ERR_PTR(-ENOMEM);
60013+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
60014+ return ERR_PTR(-EFAULT);
60015+
60016+ s_tmp->user_transitions = uidlist;
60017+ }
60018+
60019+ if (s_tmp->group_trans_num) {
60020+ gid_t *gidlist;
60021+
60022+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
60023+ if (gidlist == NULL)
60024+ return ERR_PTR(-ENOMEM);
60025+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
60026+ return ERR_PTR(-EFAULT);
60027+
60028+ s_tmp->group_transitions = gidlist;
60029+ }
60030+
60031+ /* set up object hash table */
60032+ num_objs = count_user_objs(ghash.first);
60033+
60034+ s_tmp->obj_hash_size = num_objs;
60035+ s_tmp->obj_hash =
60036+ (struct acl_object_label **)
60037+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
60038+
60039+ if (!s_tmp->obj_hash)
60040+ return ERR_PTR(-ENOMEM);
60041+
60042+ memset(s_tmp->obj_hash, 0,
60043+ s_tmp->obj_hash_size *
60044+ sizeof (struct acl_object_label *));
60045+
60046+ /* add in objects */
60047+ err = copy_user_objs(ghash.first, s_tmp, role);
60048+
60049+ if (err)
60050+ return ERR_PTR(err);
60051+
60052+ /* set pointer for parent subject */
60053+ if (s_tmp->parent_subject) {
60054+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
60055+
60056+ if (IS_ERR(s_tmp2))
60057+ return s_tmp2;
60058+
60059+ s_tmp->parent_subject = s_tmp2;
60060+ }
60061+
60062+ /* add in ip acls */
60063+
60064+ if (!s_tmp->ip_num) {
60065+ s_tmp->ips = NULL;
60066+ goto insert;
60067+ }
60068+
60069+ i_tmp =
60070+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
60071+ sizeof (struct acl_ip_label *));
60072+
60073+ if (!i_tmp)
60074+ return ERR_PTR(-ENOMEM);
60075+
60076+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
60077+ *(i_tmp + i_num) =
60078+ (struct acl_ip_label *)
60079+ acl_alloc(sizeof (struct acl_ip_label));
60080+ if (!*(i_tmp + i_num))
60081+ return ERR_PTR(-ENOMEM);
60082+
60083+ if (copy_from_user
60084+ (&i_utmp2, s_tmp->ips + i_num,
60085+ sizeof (struct acl_ip_label *)))
60086+ return ERR_PTR(-EFAULT);
60087+
60088+ if (copy_from_user
60089+ (*(i_tmp + i_num), i_utmp2,
60090+ sizeof (struct acl_ip_label)))
60091+ return ERR_PTR(-EFAULT);
60092+
60093+ if ((*(i_tmp + i_num))->iface == NULL)
60094+ continue;
60095+
60096+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
60097+ if (!len || len >= IFNAMSIZ)
60098+ return ERR_PTR(-EINVAL);
60099+ tmp = acl_alloc(len);
60100+ if (tmp == NULL)
60101+ return ERR_PTR(-ENOMEM);
60102+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
60103+ return ERR_PTR(-EFAULT);
60104+ (*(i_tmp + i_num))->iface = tmp;
60105+ }
60106+
60107+ s_tmp->ips = i_tmp;
60108+
60109+insert:
60110+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
60111+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
60112+ return ERR_PTR(-ENOMEM);
60113+
60114+ return s_tmp;
60115+}
60116+
60117+static int
60118+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
60119+{
60120+ struct acl_subject_label s_pre;
60121+ struct acl_subject_label * ret;
60122+ int err;
60123+
60124+ while (userp) {
60125+ if (copy_from_user(&s_pre, userp,
60126+ sizeof (struct acl_subject_label)))
60127+ return -EFAULT;
60128+
60129+ ret = do_copy_user_subj(userp, role, NULL);
60130+
60131+ err = PTR_ERR(ret);
60132+ if (IS_ERR(ret))
60133+ return err;
60134+
60135+ insert_acl_subj_label(ret, role);
60136+
60137+ userp = s_pre.prev;
60138+ }
60139+
60140+ return 0;
60141+}
60142+
60143+static int
60144+copy_user_acl(struct gr_arg *arg)
60145+{
60146+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
60147+ struct acl_subject_label *subj_list;
60148+ struct sprole_pw *sptmp;
60149+ struct gr_hash_struct *ghash;
60150+ uid_t *domainlist;
60151+ unsigned int r_num;
60152+ unsigned int len;
60153+ char *tmp;
60154+ int err = 0;
60155+ __u16 i;
60156+ __u32 num_subjs;
60157+
60158+ /* we need a default and kernel role */
60159+ if (arg->role_db.num_roles < 2)
60160+ return -EINVAL;
60161+
60162+ /* copy special role authentication info from userspace */
60163+
60164+ num_sprole_pws = arg->num_sprole_pws;
60165+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
60166+
60167+ if (!acl_special_roles && num_sprole_pws)
60168+ return -ENOMEM;
60169+
60170+ for (i = 0; i < num_sprole_pws; i++) {
60171+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
60172+ if (!sptmp)
60173+ return -ENOMEM;
60174+ if (copy_from_user(sptmp, arg->sprole_pws + i,
60175+ sizeof (struct sprole_pw)))
60176+ return -EFAULT;
60177+
60178+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
60179+
60180+ if (!len || len >= GR_SPROLE_LEN)
60181+ return -EINVAL;
60182+
60183+ if ((tmp = (char *) acl_alloc(len)) == NULL)
60184+ return -ENOMEM;
60185+
60186+ if (copy_from_user(tmp, sptmp->rolename, len))
60187+ return -EFAULT;
60188+
60189+ tmp[len-1] = '\0';
60190+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60191+ printk(KERN_ALERT "Copying special role %s\n", tmp);
60192+#endif
60193+ sptmp->rolename = tmp;
60194+ acl_special_roles[i] = sptmp;
60195+ }
60196+
60197+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
60198+
60199+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
60200+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
60201+
60202+ if (!r_tmp)
60203+ return -ENOMEM;
60204+
60205+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
60206+ sizeof (struct acl_role_label *)))
60207+ return -EFAULT;
60208+
60209+ if (copy_from_user(r_tmp, r_utmp2,
60210+ sizeof (struct acl_role_label)))
60211+ return -EFAULT;
60212+
60213+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
60214+
60215+ if (!len || len >= PATH_MAX)
60216+ return -EINVAL;
60217+
60218+ if ((tmp = (char *) acl_alloc(len)) == NULL)
60219+ return -ENOMEM;
60220+
60221+ if (copy_from_user(tmp, r_tmp->rolename, len))
60222+ return -EFAULT;
60223+
60224+ tmp[len-1] = '\0';
60225+ r_tmp->rolename = tmp;
60226+
60227+ if (!strcmp(r_tmp->rolename, "default")
60228+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
60229+ default_role = r_tmp;
60230+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
60231+ kernel_role = r_tmp;
60232+ }
60233+
60234+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
60235+ return -ENOMEM;
60236+
60237+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
60238+ return -EFAULT;
60239+
60240+ r_tmp->hash = ghash;
60241+
60242+ num_subjs = count_user_subjs(r_tmp->hash->first);
60243+
60244+ r_tmp->subj_hash_size = num_subjs;
60245+ r_tmp->subj_hash =
60246+ (struct acl_subject_label **)
60247+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
60248+
60249+ if (!r_tmp->subj_hash)
60250+ return -ENOMEM;
60251+
60252+ err = copy_user_allowedips(r_tmp);
60253+ if (err)
60254+ return err;
60255+
60256+ /* copy domain info */
60257+ if (r_tmp->domain_children != NULL) {
60258+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
60259+ if (domainlist == NULL)
60260+ return -ENOMEM;
60261+
60262+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
60263+ return -EFAULT;
60264+
60265+ r_tmp->domain_children = domainlist;
60266+ }
60267+
60268+ err = copy_user_transitions(r_tmp);
60269+ if (err)
60270+ return err;
60271+
60272+ memset(r_tmp->subj_hash, 0,
60273+ r_tmp->subj_hash_size *
60274+ sizeof (struct acl_subject_label *));
60275+
60276+ /* acquire the list of subjects, then NULL out
60277+ the list prior to parsing the subjects for this role,
60278+ as during this parsing the list is replaced with a list
60279+ of *nested* subjects for the role
60280+ */
60281+ subj_list = r_tmp->hash->first;
60282+
60283+ /* set nested subject list to null */
60284+ r_tmp->hash->first = NULL;
60285+
60286+ err = copy_user_subjs(subj_list, r_tmp);
60287+
60288+ if (err)
60289+ return err;
60290+
60291+ insert_acl_role_label(r_tmp);
60292+ }
60293+
60294+ if (default_role == NULL || kernel_role == NULL)
60295+ return -EINVAL;
60296+
60297+ return err;
60298+}
60299+
60300+static int
60301+gracl_init(struct gr_arg *args)
60302+{
60303+ int error = 0;
60304+
60305+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
60306+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
60307+
60308+ if (init_variables(args)) {
60309+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
60310+ error = -ENOMEM;
60311+ free_variables();
60312+ goto out;
60313+ }
60314+
60315+ error = copy_user_acl(args);
60316+ free_init_variables();
60317+ if (error) {
60318+ free_variables();
60319+ goto out;
60320+ }
60321+
60322+ if ((error = gr_set_acls(0))) {
60323+ free_variables();
60324+ goto out;
60325+ }
60326+
60327+ pax_open_kernel();
60328+ gr_status |= GR_READY;
60329+ pax_close_kernel();
60330+
60331+ out:
60332+ return error;
60333+}
60334+
60335+/* derived from glibc fnmatch() 0: match, 1: no match*/
60336+
60337+static int
60338+glob_match(const char *p, const char *n)
60339+{
60340+ char c;
60341+
60342+ while ((c = *p++) != '\0') {
60343+ switch (c) {
60344+ case '?':
60345+ if (*n == '\0')
60346+ return 1;
60347+ else if (*n == '/')
60348+ return 1;
60349+ break;
60350+ case '\\':
60351+ if (*n != c)
60352+ return 1;
60353+ break;
60354+ case '*':
60355+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
60356+ if (*n == '/')
60357+ return 1;
60358+ else if (c == '?') {
60359+ if (*n == '\0')
60360+ return 1;
60361+ else
60362+ ++n;
60363+ }
60364+ }
60365+ if (c == '\0') {
60366+ return 0;
60367+ } else {
60368+ const char *endp;
60369+
60370+ if ((endp = strchr(n, '/')) == NULL)
60371+ endp = n + strlen(n);
60372+
60373+ if (c == '[') {
60374+ for (--p; n < endp; ++n)
60375+ if (!glob_match(p, n))
60376+ return 0;
60377+ } else if (c == '/') {
60378+ while (*n != '\0' && *n != '/')
60379+ ++n;
60380+ if (*n == '/' && !glob_match(p, n + 1))
60381+ return 0;
60382+ } else {
60383+ for (--p; n < endp; ++n)
60384+ if (*n == c && !glob_match(p, n))
60385+ return 0;
60386+ }
60387+
60388+ return 1;
60389+ }
60390+ case '[':
60391+ {
60392+ int not;
60393+ char cold;
60394+
60395+ if (*n == '\0' || *n == '/')
60396+ return 1;
60397+
60398+ not = (*p == '!' || *p == '^');
60399+ if (not)
60400+ ++p;
60401+
60402+ c = *p++;
60403+ for (;;) {
60404+ unsigned char fn = (unsigned char)*n;
60405+
60406+ if (c == '\0')
60407+ return 1;
60408+ else {
60409+ if (c == fn)
60410+ goto matched;
60411+ cold = c;
60412+ c = *p++;
60413+
60414+ if (c == '-' && *p != ']') {
60415+ unsigned char cend = *p++;
60416+
60417+ if (cend == '\0')
60418+ return 1;
60419+
60420+ if (cold <= fn && fn <= cend)
60421+ goto matched;
60422+
60423+ c = *p++;
60424+ }
60425+ }
60426+
60427+ if (c == ']')
60428+ break;
60429+ }
60430+ if (!not)
60431+ return 1;
60432+ break;
60433+ matched:
60434+ while (c != ']') {
60435+ if (c == '\0')
60436+ return 1;
60437+
60438+ c = *p++;
60439+ }
60440+ if (not)
60441+ return 1;
60442+ }
60443+ break;
60444+ default:
60445+ if (c != *n)
60446+ return 1;
60447+ }
60448+
60449+ ++n;
60450+ }
60451+
60452+ if (*n == '\0')
60453+ return 0;
60454+
60455+ if (*n == '/')
60456+ return 0;
60457+
60458+ return 1;
60459+}
60460+
60461+static struct acl_object_label *
60462+chk_glob_label(struct acl_object_label *globbed,
60463+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
60464+{
60465+ struct acl_object_label *tmp;
60466+
60467+ if (*path == NULL)
60468+ *path = gr_to_filename_nolock(dentry, mnt);
60469+
60470+ tmp = globbed;
60471+
60472+ while (tmp) {
60473+ if (!glob_match(tmp->filename, *path))
60474+ return tmp;
60475+ tmp = tmp->next;
60476+ }
60477+
60478+ return NULL;
60479+}
60480+
60481+static struct acl_object_label *
60482+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
60483+ const ino_t curr_ino, const dev_t curr_dev,
60484+ const struct acl_subject_label *subj, char **path, const int checkglob)
60485+{
60486+ struct acl_subject_label *tmpsubj;
60487+ struct acl_object_label *retval;
60488+ struct acl_object_label *retval2;
60489+
60490+ tmpsubj = (struct acl_subject_label *) subj;
60491+ read_lock(&gr_inode_lock);
60492+ do {
60493+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
60494+ if (retval) {
60495+ if (checkglob && retval->globbed) {
60496+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
60497+ if (retval2)
60498+ retval = retval2;
60499+ }
60500+ break;
60501+ }
60502+ } while ((tmpsubj = tmpsubj->parent_subject));
60503+ read_unlock(&gr_inode_lock);
60504+
60505+ return retval;
60506+}
60507+
60508+static __inline__ struct acl_object_label *
60509+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
60510+ struct dentry *curr_dentry,
60511+ const struct acl_subject_label *subj, char **path, const int checkglob)
60512+{
60513+ int newglob = checkglob;
60514+ ino_t inode;
60515+ dev_t device;
60516+
60517+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
60518+ as we don't want a / * rule to match instead of the / object
60519+ don't do this for create lookups that call this function though, since they're looking up
60520+ on the parent and thus need globbing checks on all paths
60521+ */
60522+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
60523+ newglob = GR_NO_GLOB;
60524+
60525+ spin_lock(&curr_dentry->d_lock);
60526+ inode = curr_dentry->d_inode->i_ino;
60527+ device = __get_dev(curr_dentry);
60528+ spin_unlock(&curr_dentry->d_lock);
60529+
60530+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
60531+}
60532+
60533+#ifdef CONFIG_HUGETLBFS
60534+static inline bool
60535+is_hugetlbfs_mnt(const struct vfsmount *mnt)
60536+{
60537+ int i;
60538+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
60539+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
60540+ return true;
60541+ }
60542+
60543+ return false;
60544+}
60545+#endif
60546+
60547+static struct acl_object_label *
60548+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60549+ const struct acl_subject_label *subj, char *path, const int checkglob)
60550+{
60551+ struct dentry *dentry = (struct dentry *) l_dentry;
60552+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
60553+ struct mount *real_mnt = real_mount(mnt);
60554+ struct acl_object_label *retval;
60555+ struct dentry *parent;
60556+
60557+ br_read_lock(&vfsmount_lock);
60558+ write_seqlock(&rename_lock);
60559+
60560+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
60561+#ifdef CONFIG_NET
60562+ mnt == sock_mnt ||
60563+#endif
60564+#ifdef CONFIG_HUGETLBFS
60565+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
60566+#endif
60567+ /* ignore Eric Biederman */
60568+ IS_PRIVATE(l_dentry->d_inode))) {
60569+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
60570+ goto out;
60571+ }
60572+
60573+ for (;;) {
60574+ if (dentry == real_root.dentry && mnt == real_root.mnt)
60575+ break;
60576+
60577+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
60578+ if (!mnt_has_parent(real_mnt))
60579+ break;
60580+
60581+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
60582+ if (retval != NULL)
60583+ goto out;
60584+
60585+ dentry = real_mnt->mnt_mountpoint;
60586+ real_mnt = real_mnt->mnt_parent;
60587+ mnt = &real_mnt->mnt;
60588+ continue;
60589+ }
60590+
60591+ parent = dentry->d_parent;
60592+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
60593+ if (retval != NULL)
60594+ goto out;
60595+
60596+ dentry = parent;
60597+ }
60598+
60599+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
60600+
60601+ /* real_root is pinned so we don't have to hold a reference */
60602+ if (retval == NULL)
60603+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
60604+out:
60605+ write_sequnlock(&rename_lock);
60606+ br_read_unlock(&vfsmount_lock);
60607+
60608+ BUG_ON(retval == NULL);
60609+
60610+ return retval;
60611+}
60612+
60613+static __inline__ struct acl_object_label *
60614+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60615+ const struct acl_subject_label *subj)
60616+{
60617+ char *path = NULL;
60618+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
60619+}
60620+
60621+static __inline__ struct acl_object_label *
60622+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60623+ const struct acl_subject_label *subj)
60624+{
60625+ char *path = NULL;
60626+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
60627+}
60628+
60629+static __inline__ struct acl_object_label *
60630+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60631+ const struct acl_subject_label *subj, char *path)
60632+{
60633+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
60634+}
60635+
60636+static struct acl_subject_label *
60637+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60638+ const struct acl_role_label *role)
60639+{
60640+ struct dentry *dentry = (struct dentry *) l_dentry;
60641+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
60642+ struct mount *real_mnt = real_mount(mnt);
60643+ struct acl_subject_label *retval;
60644+ struct dentry *parent;
60645+
60646+ br_read_lock(&vfsmount_lock);
60647+ write_seqlock(&rename_lock);
60648+
60649+ for (;;) {
60650+ if (dentry == real_root.dentry && mnt == real_root.mnt)
60651+ break;
60652+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
60653+ if (!mnt_has_parent(real_mnt))
60654+ break;
60655+
60656+ spin_lock(&dentry->d_lock);
60657+ read_lock(&gr_inode_lock);
60658+ retval =
60659+ lookup_acl_subj_label(dentry->d_inode->i_ino,
60660+ __get_dev(dentry), role);
60661+ read_unlock(&gr_inode_lock);
60662+ spin_unlock(&dentry->d_lock);
60663+ if (retval != NULL)
60664+ goto out;
60665+
60666+ dentry = real_mnt->mnt_mountpoint;
60667+ real_mnt = real_mnt->mnt_parent;
60668+ mnt = &real_mnt->mnt;
60669+ continue;
60670+ }
60671+
60672+ spin_lock(&dentry->d_lock);
60673+ read_lock(&gr_inode_lock);
60674+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
60675+ __get_dev(dentry), role);
60676+ read_unlock(&gr_inode_lock);
60677+ parent = dentry->d_parent;
60678+ spin_unlock(&dentry->d_lock);
60679+
60680+ if (retval != NULL)
60681+ goto out;
60682+
60683+ dentry = parent;
60684+ }
60685+
60686+ spin_lock(&dentry->d_lock);
60687+ read_lock(&gr_inode_lock);
60688+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
60689+ __get_dev(dentry), role);
60690+ read_unlock(&gr_inode_lock);
60691+ spin_unlock(&dentry->d_lock);
60692+
60693+ if (unlikely(retval == NULL)) {
60694+ /* real_root is pinned, we don't need to hold a reference */
60695+ read_lock(&gr_inode_lock);
60696+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
60697+ __get_dev(real_root.dentry), role);
60698+ read_unlock(&gr_inode_lock);
60699+ }
60700+out:
60701+ write_sequnlock(&rename_lock);
60702+ br_read_unlock(&vfsmount_lock);
60703+
60704+ BUG_ON(retval == NULL);
60705+
60706+ return retval;
60707+}
60708+
60709+static void
60710+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
60711+{
60712+ struct task_struct *task = current;
60713+ const struct cred *cred = current_cred();
60714+
60715+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
60716+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
60717+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
60718+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
60719+
60720+ return;
60721+}
60722+
60723+static void
60724+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
60725+{
60726+ struct task_struct *task = current;
60727+ const struct cred *cred = current_cred();
60728+
60729+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
60730+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
60731+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
60732+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
60733+
60734+ return;
60735+}
60736+
60737+static void
60738+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
60739+{
60740+ struct task_struct *task = current;
60741+ const struct cred *cred = current_cred();
60742+
60743+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
60744+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
60745+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
60746+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
60747+
60748+ return;
60749+}
60750+
60751+__u32
60752+gr_search_file(const struct dentry * dentry, const __u32 mode,
60753+ const struct vfsmount * mnt)
60754+{
60755+ __u32 retval = mode;
60756+ struct acl_subject_label *curracl;
60757+ struct acl_object_label *currobj;
60758+
60759+ if (unlikely(!(gr_status & GR_READY)))
60760+ return (mode & ~GR_AUDITS);
60761+
60762+ curracl = current->acl;
60763+
60764+ currobj = chk_obj_label(dentry, mnt, curracl);
60765+ retval = currobj->mode & mode;
60766+
60767+ /* if we're opening a specified transfer file for writing
60768+ (e.g. /dev/initctl), then transfer our role to init
60769+ */
60770+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
60771+ current->role->roletype & GR_ROLE_PERSIST)) {
60772+ struct task_struct *task = init_pid_ns.child_reaper;
60773+
60774+ if (task->role != current->role) {
60775+ task->acl_sp_role = 0;
60776+ task->acl_role_id = current->acl_role_id;
60777+ task->role = current->role;
60778+ rcu_read_lock();
60779+ read_lock(&grsec_exec_file_lock);
60780+ gr_apply_subject_to_task(task);
60781+ read_unlock(&grsec_exec_file_lock);
60782+ rcu_read_unlock();
60783+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
60784+ }
60785+ }
60786+
60787+ if (unlikely
60788+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
60789+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
60790+ __u32 new_mode = mode;
60791+
60792+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
60793+
60794+ retval = new_mode;
60795+
60796+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
60797+ new_mode |= GR_INHERIT;
60798+
60799+ if (!(mode & GR_NOLEARN))
60800+ gr_log_learn(dentry, mnt, new_mode);
60801+ }
60802+
60803+ return retval;
60804+}
60805+
60806+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
60807+ const struct dentry *parent,
60808+ const struct vfsmount *mnt)
60809+{
60810+ struct name_entry *match;
60811+ struct acl_object_label *matchpo;
60812+ struct acl_subject_label *curracl;
60813+ char *path;
60814+
60815+ if (unlikely(!(gr_status & GR_READY)))
60816+ return NULL;
60817+
60818+ preempt_disable();
60819+ path = gr_to_filename_rbac(new_dentry, mnt);
60820+ match = lookup_name_entry_create(path);
60821+
60822+ curracl = current->acl;
60823+
60824+ if (match) {
60825+ read_lock(&gr_inode_lock);
60826+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
60827+ read_unlock(&gr_inode_lock);
60828+
60829+ if (matchpo) {
60830+ preempt_enable();
60831+ return matchpo;
60832+ }
60833+ }
60834+
60835+ // lookup parent
60836+
60837+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
60838+
60839+ preempt_enable();
60840+ return matchpo;
60841+}
60842+
60843+__u32
60844+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
60845+ const struct vfsmount * mnt, const __u32 mode)
60846+{
60847+ struct acl_object_label *matchpo;
60848+ __u32 retval;
60849+
60850+ if (unlikely(!(gr_status & GR_READY)))
60851+ return (mode & ~GR_AUDITS);
60852+
60853+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
60854+
60855+ retval = matchpo->mode & mode;
60856+
60857+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
60858+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
60859+ __u32 new_mode = mode;
60860+
60861+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
60862+
60863+ gr_log_learn(new_dentry, mnt, new_mode);
60864+ return new_mode;
60865+ }
60866+
60867+ return retval;
60868+}
60869+
60870+__u32
60871+gr_check_link(const struct dentry * new_dentry,
60872+ const struct dentry * parent_dentry,
60873+ const struct vfsmount * parent_mnt,
60874+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
60875+{
60876+ struct acl_object_label *obj;
60877+ __u32 oldmode, newmode;
60878+ __u32 needmode;
60879+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
60880+ GR_DELETE | GR_INHERIT;
60881+
60882+ if (unlikely(!(gr_status & GR_READY)))
60883+ return (GR_CREATE | GR_LINK);
60884+
60885+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
60886+ oldmode = obj->mode;
60887+
60888+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
60889+ newmode = obj->mode;
60890+
60891+ needmode = newmode & checkmodes;
60892+
60893+ // old name for hardlink must have at least the permissions of the new name
60894+ if ((oldmode & needmode) != needmode)
60895+ goto bad;
60896+
60897+ // if old name had restrictions/auditing, make sure the new name does as well
60898+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
60899+
60900+ // don't allow hardlinking of suid/sgid/fcapped files without permission
60901+ if (is_privileged_binary(old_dentry))
60902+ needmode |= GR_SETID;
60903+
60904+ if ((newmode & needmode) != needmode)
60905+ goto bad;
60906+
60907+ // enforce minimum permissions
60908+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
60909+ return newmode;
60910+bad:
60911+ needmode = oldmode;
60912+ if (is_privileged_binary(old_dentry))
60913+ needmode |= GR_SETID;
60914+
60915+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
60916+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
60917+ return (GR_CREATE | GR_LINK);
60918+ } else if (newmode & GR_SUPPRESS)
60919+ return GR_SUPPRESS;
60920+ else
60921+ return 0;
60922+}
60923+
60924+int
60925+gr_check_hidden_task(const struct task_struct *task)
60926+{
60927+ if (unlikely(!(gr_status & GR_READY)))
60928+ return 0;
60929+
60930+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
60931+ return 1;
60932+
60933+ return 0;
60934+}
60935+
60936+int
60937+gr_check_protected_task(const struct task_struct *task)
60938+{
60939+ if (unlikely(!(gr_status & GR_READY) || !task))
60940+ return 0;
60941+
60942+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
60943+ task->acl != current->acl)
60944+ return 1;
60945+
60946+ return 0;
60947+}
60948+
60949+int
60950+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
60951+{
60952+ struct task_struct *p;
60953+ int ret = 0;
60954+
60955+ if (unlikely(!(gr_status & GR_READY) || !pid))
60956+ return ret;
60957+
60958+ read_lock(&tasklist_lock);
60959+ do_each_pid_task(pid, type, p) {
60960+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
60961+ p->acl != current->acl) {
60962+ ret = 1;
60963+ goto out;
60964+ }
60965+ } while_each_pid_task(pid, type, p);
60966+out:
60967+ read_unlock(&tasklist_lock);
60968+
60969+ return ret;
60970+}
60971+
60972+void
60973+gr_copy_label(struct task_struct *tsk)
60974+{
60975+ tsk->signal->used_accept = 0;
60976+ tsk->acl_sp_role = 0;
60977+ tsk->acl_role_id = current->acl_role_id;
60978+ tsk->acl = current->acl;
60979+ tsk->role = current->role;
60980+ tsk->signal->curr_ip = current->signal->curr_ip;
60981+ tsk->signal->saved_ip = current->signal->saved_ip;
60982+ if (current->exec_file)
60983+ get_file(current->exec_file);
60984+ tsk->exec_file = current->exec_file;
60985+ tsk->is_writable = current->is_writable;
60986+ if (unlikely(current->signal->used_accept)) {
60987+ current->signal->curr_ip = 0;
60988+ current->signal->saved_ip = 0;
60989+ }
60990+
60991+ return;
60992+}
60993+
60994+static void
60995+gr_set_proc_res(struct task_struct *task)
60996+{
60997+ struct acl_subject_label *proc;
60998+ unsigned short i;
60999+
61000+ proc = task->acl;
61001+
61002+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
61003+ return;
61004+
61005+ for (i = 0; i < RLIM_NLIMITS; i++) {
61006+ if (!(proc->resmask & (1U << i)))
61007+ continue;
61008+
61009+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
61010+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
61011+
61012+ if (i == RLIMIT_CPU)
61013+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
61014+ }
61015+
61016+ return;
61017+}
61018+
61019+extern int __gr_process_user_ban(struct user_struct *user);
61020+
61021+int
61022+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
61023+{
61024+ unsigned int i;
61025+ __u16 num;
61026+ uid_t *uidlist;
61027+ uid_t curuid;
61028+ int realok = 0;
61029+ int effectiveok = 0;
61030+ int fsok = 0;
61031+ uid_t globalreal, globaleffective, globalfs;
61032+
61033+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
61034+ struct user_struct *user;
61035+
61036+ if (!uid_valid(real))
61037+ goto skipit;
61038+
61039+ /* find user based on global namespace */
61040+
61041+ globalreal = GR_GLOBAL_UID(real);
61042+
61043+ user = find_user(make_kuid(&init_user_ns, globalreal));
61044+ if (user == NULL)
61045+ goto skipit;
61046+
61047+ if (__gr_process_user_ban(user)) {
61048+ /* for find_user */
61049+ free_uid(user);
61050+ return 1;
61051+ }
61052+
61053+ /* for find_user */
61054+ free_uid(user);
61055+
61056+skipit:
61057+#endif
61058+
61059+ if (unlikely(!(gr_status & GR_READY)))
61060+ return 0;
61061+
61062+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
61063+ gr_log_learn_uid_change(real, effective, fs);
61064+
61065+ num = current->acl->user_trans_num;
61066+ uidlist = current->acl->user_transitions;
61067+
61068+ if (uidlist == NULL)
61069+ return 0;
61070+
61071+ if (!uid_valid(real)) {
61072+ realok = 1;
61073+ globalreal = (uid_t)-1;
61074+ } else {
61075+ globalreal = GR_GLOBAL_UID(real);
61076+ }
61077+ if (!uid_valid(effective)) {
61078+ effectiveok = 1;
61079+ globaleffective = (uid_t)-1;
61080+ } else {
61081+ globaleffective = GR_GLOBAL_UID(effective);
61082+ }
61083+ if (!uid_valid(fs)) {
61084+ fsok = 1;
61085+ globalfs = (uid_t)-1;
61086+ } else {
61087+ globalfs = GR_GLOBAL_UID(fs);
61088+ }
61089+
61090+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
61091+ for (i = 0; i < num; i++) {
61092+ curuid = uidlist[i];
61093+ if (globalreal == curuid)
61094+ realok = 1;
61095+ if (globaleffective == curuid)
61096+ effectiveok = 1;
61097+ if (globalfs == curuid)
61098+ fsok = 1;
61099+ }
61100+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
61101+ for (i = 0; i < num; i++) {
61102+ curuid = uidlist[i];
61103+ if (globalreal == curuid)
61104+ break;
61105+ if (globaleffective == curuid)
61106+ break;
61107+ if (globalfs == curuid)
61108+ break;
61109+ }
61110+ /* not in deny list */
61111+ if (i == num) {
61112+ realok = 1;
61113+ effectiveok = 1;
61114+ fsok = 1;
61115+ }
61116+ }
61117+
61118+ if (realok && effectiveok && fsok)
61119+ return 0;
61120+ else {
61121+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
61122+ return 1;
61123+ }
61124+}
61125+
61126+int
61127+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
61128+{
61129+ unsigned int i;
61130+ __u16 num;
61131+ gid_t *gidlist;
61132+ gid_t curgid;
61133+ int realok = 0;
61134+ int effectiveok = 0;
61135+ int fsok = 0;
61136+ gid_t globalreal, globaleffective, globalfs;
61137+
61138+ if (unlikely(!(gr_status & GR_READY)))
61139+ return 0;
61140+
61141+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
61142+ gr_log_learn_gid_change(real, effective, fs);
61143+
61144+ num = current->acl->group_trans_num;
61145+ gidlist = current->acl->group_transitions;
61146+
61147+ if (gidlist == NULL)
61148+ return 0;
61149+
61150+ if (!gid_valid(real)) {
61151+ realok = 1;
61152+ globalreal = (gid_t)-1;
61153+ } else {
61154+ globalreal = GR_GLOBAL_GID(real);
61155+ }
61156+ if (!gid_valid(effective)) {
61157+ effectiveok = 1;
61158+ globaleffective = (gid_t)-1;
61159+ } else {
61160+ globaleffective = GR_GLOBAL_GID(effective);
61161+ }
61162+ if (!gid_valid(fs)) {
61163+ fsok = 1;
61164+ globalfs = (gid_t)-1;
61165+ } else {
61166+ globalfs = GR_GLOBAL_GID(fs);
61167+ }
61168+
61169+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
61170+ for (i = 0; i < num; i++) {
61171+ curgid = gidlist[i];
61172+ if (globalreal == curgid)
61173+ realok = 1;
61174+ if (globaleffective == curgid)
61175+ effectiveok = 1;
61176+ if (globalfs == curgid)
61177+ fsok = 1;
61178+ }
61179+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
61180+ for (i = 0; i < num; i++) {
61181+ curgid = gidlist[i];
61182+ if (globalreal == curgid)
61183+ break;
61184+ if (globaleffective == curgid)
61185+ break;
61186+ if (globalfs == curgid)
61187+ break;
61188+ }
61189+ /* not in deny list */
61190+ if (i == num) {
61191+ realok = 1;
61192+ effectiveok = 1;
61193+ fsok = 1;
61194+ }
61195+ }
61196+
61197+ if (realok && effectiveok && fsok)
61198+ return 0;
61199+ else {
61200+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
61201+ return 1;
61202+ }
61203+}
61204+
61205+extern int gr_acl_is_capable(const int cap);
61206+
61207+void
61208+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
61209+{
61210+ struct acl_role_label *role = task->role;
61211+ struct acl_subject_label *subj = NULL;
61212+ struct acl_object_label *obj;
61213+ struct file *filp;
61214+ uid_t uid;
61215+ gid_t gid;
61216+
61217+ if (unlikely(!(gr_status & GR_READY)))
61218+ return;
61219+
61220+ uid = GR_GLOBAL_UID(kuid);
61221+ gid = GR_GLOBAL_GID(kgid);
61222+
61223+ filp = task->exec_file;
61224+
61225+ /* kernel process, we'll give them the kernel role */
61226+ if (unlikely(!filp)) {
61227+ task->role = kernel_role;
61228+ task->acl = kernel_role->root_label;
61229+ return;
61230+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
61231+ role = lookup_acl_role_label(task, uid, gid);
61232+
61233+ /* don't change the role if we're not a privileged process */
61234+ if (role && task->role != role &&
61235+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
61236+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
61237+ return;
61238+
61239+ /* perform subject lookup in possibly new role
61240+ we can use this result below in the case where role == task->role
61241+ */
61242+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
61243+
61244+ /* if we changed uid/gid, but result in the same role
61245+ and are using inheritance, don't lose the inherited subject
61246+ if current subject is other than what normal lookup
61247+ would result in, we arrived via inheritance, don't
61248+ lose subject
61249+ */
61250+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
61251+ (subj == task->acl)))
61252+ task->acl = subj;
61253+
61254+ task->role = role;
61255+
61256+ task->is_writable = 0;
61257+
61258+ /* ignore additional mmap checks for processes that are writable
61259+ by the default ACL */
61260+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
61261+ if (unlikely(obj->mode & GR_WRITE))
61262+ task->is_writable = 1;
61263+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
61264+ if (unlikely(obj->mode & GR_WRITE))
61265+ task->is_writable = 1;
61266+
61267+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
61268+ 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);
61269+#endif
61270+
61271+ gr_set_proc_res(task);
61272+
61273+ return;
61274+}
61275+
61276+int
61277+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
61278+ const int unsafe_flags)
61279+{
61280+ struct task_struct *task = current;
61281+ struct acl_subject_label *newacl;
61282+ struct acl_object_label *obj;
61283+ __u32 retmode;
61284+
61285+ if (unlikely(!(gr_status & GR_READY)))
61286+ return 0;
61287+
61288+ newacl = chk_subj_label(dentry, mnt, task->role);
61289+
61290+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
61291+ did an exec
61292+ */
61293+ rcu_read_lock();
61294+ read_lock(&tasklist_lock);
61295+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
61296+ (task->parent->acl->mode & GR_POVERRIDE))) {
61297+ read_unlock(&tasklist_lock);
61298+ rcu_read_unlock();
61299+ goto skip_check;
61300+ }
61301+ read_unlock(&tasklist_lock);
61302+ rcu_read_unlock();
61303+
61304+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
61305+ !(task->role->roletype & GR_ROLE_GOD) &&
61306+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
61307+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
61308+ if (unsafe_flags & LSM_UNSAFE_SHARE)
61309+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
61310+ else
61311+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
61312+ return -EACCES;
61313+ }
61314+
61315+skip_check:
61316+
61317+ obj = chk_obj_label(dentry, mnt, task->acl);
61318+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
61319+
61320+ if (!(task->acl->mode & GR_INHERITLEARN) &&
61321+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
61322+ if (obj->nested)
61323+ task->acl = obj->nested;
61324+ else
61325+ task->acl = newacl;
61326+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
61327+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
61328+
61329+ task->is_writable = 0;
61330+
61331+ /* ignore additional mmap checks for processes that are writable
61332+ by the default ACL */
61333+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
61334+ if (unlikely(obj->mode & GR_WRITE))
61335+ task->is_writable = 1;
61336+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
61337+ if (unlikely(obj->mode & GR_WRITE))
61338+ task->is_writable = 1;
61339+
61340+ gr_set_proc_res(task);
61341+
61342+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
61343+ 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);
61344+#endif
61345+ return 0;
61346+}
61347+
61348+/* always called with valid inodev ptr */
61349+static void
61350+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
61351+{
61352+ struct acl_object_label *matchpo;
61353+ struct acl_subject_label *matchps;
61354+ struct acl_subject_label *subj;
61355+ struct acl_role_label *role;
61356+ unsigned int x;
61357+
61358+ FOR_EACH_ROLE_START(role)
61359+ FOR_EACH_SUBJECT_START(role, subj, x)
61360+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
61361+ matchpo->mode |= GR_DELETED;
61362+ FOR_EACH_SUBJECT_END(subj,x)
61363+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
61364+ /* nested subjects aren't in the role's subj_hash table */
61365+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
61366+ matchpo->mode |= GR_DELETED;
61367+ FOR_EACH_NESTED_SUBJECT_END(subj)
61368+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
61369+ matchps->mode |= GR_DELETED;
61370+ FOR_EACH_ROLE_END(role)
61371+
61372+ inodev->nentry->deleted = 1;
61373+
61374+ return;
61375+}
61376+
61377+void
61378+gr_handle_delete(const ino_t ino, const dev_t dev)
61379+{
61380+ struct inodev_entry *inodev;
61381+
61382+ if (unlikely(!(gr_status & GR_READY)))
61383+ return;
61384+
61385+ write_lock(&gr_inode_lock);
61386+ inodev = lookup_inodev_entry(ino, dev);
61387+ if (inodev != NULL)
61388+ do_handle_delete(inodev, ino, dev);
61389+ write_unlock(&gr_inode_lock);
61390+
61391+ return;
61392+}
61393+
61394+static void
61395+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
61396+ const ino_t newinode, const dev_t newdevice,
61397+ struct acl_subject_label *subj)
61398+{
61399+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
61400+ struct acl_object_label *match;
61401+
61402+ match = subj->obj_hash[index];
61403+
61404+ while (match && (match->inode != oldinode ||
61405+ match->device != olddevice ||
61406+ !(match->mode & GR_DELETED)))
61407+ match = match->next;
61408+
61409+ if (match && (match->inode == oldinode)
61410+ && (match->device == olddevice)
61411+ && (match->mode & GR_DELETED)) {
61412+ if (match->prev == NULL) {
61413+ subj->obj_hash[index] = match->next;
61414+ if (match->next != NULL)
61415+ match->next->prev = NULL;
61416+ } else {
61417+ match->prev->next = match->next;
61418+ if (match->next != NULL)
61419+ match->next->prev = match->prev;
61420+ }
61421+ match->prev = NULL;
61422+ match->next = NULL;
61423+ match->inode = newinode;
61424+ match->device = newdevice;
61425+ match->mode &= ~GR_DELETED;
61426+
61427+ insert_acl_obj_label(match, subj);
61428+ }
61429+
61430+ return;
61431+}
61432+
61433+static void
61434+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
61435+ const ino_t newinode, const dev_t newdevice,
61436+ struct acl_role_label *role)
61437+{
61438+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
61439+ struct acl_subject_label *match;
61440+
61441+ match = role->subj_hash[index];
61442+
61443+ while (match && (match->inode != oldinode ||
61444+ match->device != olddevice ||
61445+ !(match->mode & GR_DELETED)))
61446+ match = match->next;
61447+
61448+ if (match && (match->inode == oldinode)
61449+ && (match->device == olddevice)
61450+ && (match->mode & GR_DELETED)) {
61451+ if (match->prev == NULL) {
61452+ role->subj_hash[index] = match->next;
61453+ if (match->next != NULL)
61454+ match->next->prev = NULL;
61455+ } else {
61456+ match->prev->next = match->next;
61457+ if (match->next != NULL)
61458+ match->next->prev = match->prev;
61459+ }
61460+ match->prev = NULL;
61461+ match->next = NULL;
61462+ match->inode = newinode;
61463+ match->device = newdevice;
61464+ match->mode &= ~GR_DELETED;
61465+
61466+ insert_acl_subj_label(match, role);
61467+ }
61468+
61469+ return;
61470+}
61471+
61472+static void
61473+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
61474+ const ino_t newinode, const dev_t newdevice)
61475+{
61476+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
61477+ struct inodev_entry *match;
61478+
61479+ match = inodev_set.i_hash[index];
61480+
61481+ while (match && (match->nentry->inode != oldinode ||
61482+ match->nentry->device != olddevice || !match->nentry->deleted))
61483+ match = match->next;
61484+
61485+ if (match && (match->nentry->inode == oldinode)
61486+ && (match->nentry->device == olddevice) &&
61487+ match->nentry->deleted) {
61488+ if (match->prev == NULL) {
61489+ inodev_set.i_hash[index] = match->next;
61490+ if (match->next != NULL)
61491+ match->next->prev = NULL;
61492+ } else {
61493+ match->prev->next = match->next;
61494+ if (match->next != NULL)
61495+ match->next->prev = match->prev;
61496+ }
61497+ match->prev = NULL;
61498+ match->next = NULL;
61499+ match->nentry->inode = newinode;
61500+ match->nentry->device = newdevice;
61501+ match->nentry->deleted = 0;
61502+
61503+ insert_inodev_entry(match);
61504+ }
61505+
61506+ return;
61507+}
61508+
61509+static void
61510+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
61511+{
61512+ struct acl_subject_label *subj;
61513+ struct acl_role_label *role;
61514+ unsigned int x;
61515+
61516+ FOR_EACH_ROLE_START(role)
61517+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
61518+
61519+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
61520+ if ((subj->inode == ino) && (subj->device == dev)) {
61521+ subj->inode = ino;
61522+ subj->device = dev;
61523+ }
61524+ /* nested subjects aren't in the role's subj_hash table */
61525+ update_acl_obj_label(matchn->inode, matchn->device,
61526+ ino, dev, subj);
61527+ FOR_EACH_NESTED_SUBJECT_END(subj)
61528+ FOR_EACH_SUBJECT_START(role, subj, x)
61529+ update_acl_obj_label(matchn->inode, matchn->device,
61530+ ino, dev, subj);
61531+ FOR_EACH_SUBJECT_END(subj,x)
61532+ FOR_EACH_ROLE_END(role)
61533+
61534+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
61535+
61536+ return;
61537+}
61538+
61539+static void
61540+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
61541+ const struct vfsmount *mnt)
61542+{
61543+ ino_t ino = dentry->d_inode->i_ino;
61544+ dev_t dev = __get_dev(dentry);
61545+
61546+ __do_handle_create(matchn, ino, dev);
61547+
61548+ return;
61549+}
61550+
61551+void
61552+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
61553+{
61554+ struct name_entry *matchn;
61555+
61556+ if (unlikely(!(gr_status & GR_READY)))
61557+ return;
61558+
61559+ preempt_disable();
61560+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
61561+
61562+ if (unlikely((unsigned long)matchn)) {
61563+ write_lock(&gr_inode_lock);
61564+ do_handle_create(matchn, dentry, mnt);
61565+ write_unlock(&gr_inode_lock);
61566+ }
61567+ preempt_enable();
61568+
61569+ return;
61570+}
61571+
61572+void
61573+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
61574+{
61575+ struct name_entry *matchn;
61576+
61577+ if (unlikely(!(gr_status & GR_READY)))
61578+ return;
61579+
61580+ preempt_disable();
61581+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
61582+
61583+ if (unlikely((unsigned long)matchn)) {
61584+ write_lock(&gr_inode_lock);
61585+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
61586+ write_unlock(&gr_inode_lock);
61587+ }
61588+ preempt_enable();
61589+
61590+ return;
61591+}
61592+
61593+void
61594+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
61595+ struct dentry *old_dentry,
61596+ struct dentry *new_dentry,
61597+ struct vfsmount *mnt, const __u8 replace)
61598+{
61599+ struct name_entry *matchn;
61600+ struct inodev_entry *inodev;
61601+ struct inode *inode = new_dentry->d_inode;
61602+ ino_t old_ino = old_dentry->d_inode->i_ino;
61603+ dev_t old_dev = __get_dev(old_dentry);
61604+
61605+ /* vfs_rename swaps the name and parent link for old_dentry and
61606+ new_dentry
61607+ at this point, old_dentry has the new name, parent link, and inode
61608+ for the renamed file
61609+ if a file is being replaced by a rename, new_dentry has the inode
61610+ and name for the replaced file
61611+ */
61612+
61613+ if (unlikely(!(gr_status & GR_READY)))
61614+ return;
61615+
61616+ preempt_disable();
61617+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
61618+
61619+ /* we wouldn't have to check d_inode if it weren't for
61620+ NFS silly-renaming
61621+ */
61622+
61623+ write_lock(&gr_inode_lock);
61624+ if (unlikely(replace && inode)) {
61625+ ino_t new_ino = inode->i_ino;
61626+ dev_t new_dev = __get_dev(new_dentry);
61627+
61628+ inodev = lookup_inodev_entry(new_ino, new_dev);
61629+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
61630+ do_handle_delete(inodev, new_ino, new_dev);
61631+ }
61632+
61633+ inodev = lookup_inodev_entry(old_ino, old_dev);
61634+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
61635+ do_handle_delete(inodev, old_ino, old_dev);
61636+
61637+ if (unlikely((unsigned long)matchn))
61638+ do_handle_create(matchn, old_dentry, mnt);
61639+
61640+ write_unlock(&gr_inode_lock);
61641+ preempt_enable();
61642+
61643+ return;
61644+}
61645+
61646+static int
61647+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
61648+ unsigned char **sum)
61649+{
61650+ struct acl_role_label *r;
61651+ struct role_allowed_ip *ipp;
61652+ struct role_transition *trans;
61653+ unsigned int i;
61654+ int found = 0;
61655+ u32 curr_ip = current->signal->curr_ip;
61656+
61657+ current->signal->saved_ip = curr_ip;
61658+
61659+ /* check transition table */
61660+
61661+ for (trans = current->role->transitions; trans; trans = trans->next) {
61662+ if (!strcmp(rolename, trans->rolename)) {
61663+ found = 1;
61664+ break;
61665+ }
61666+ }
61667+
61668+ if (!found)
61669+ return 0;
61670+
61671+ /* handle special roles that do not require authentication
61672+ and check ip */
61673+
61674+ FOR_EACH_ROLE_START(r)
61675+ if (!strcmp(rolename, r->rolename) &&
61676+ (r->roletype & GR_ROLE_SPECIAL)) {
61677+ found = 0;
61678+ if (r->allowed_ips != NULL) {
61679+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
61680+ if ((ntohl(curr_ip) & ipp->netmask) ==
61681+ (ntohl(ipp->addr) & ipp->netmask))
61682+ found = 1;
61683+ }
61684+ } else
61685+ found = 2;
61686+ if (!found)
61687+ return 0;
61688+
61689+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
61690+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
61691+ *salt = NULL;
61692+ *sum = NULL;
61693+ return 1;
61694+ }
61695+ }
61696+ FOR_EACH_ROLE_END(r)
61697+
61698+ for (i = 0; i < num_sprole_pws; i++) {
61699+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
61700+ *salt = acl_special_roles[i]->salt;
61701+ *sum = acl_special_roles[i]->sum;
61702+ return 1;
61703+ }
61704+ }
61705+
61706+ return 0;
61707+}
61708+
61709+static void
61710+assign_special_role(char *rolename)
61711+{
61712+ struct acl_object_label *obj;
61713+ struct acl_role_label *r;
61714+ struct acl_role_label *assigned = NULL;
61715+ struct task_struct *tsk;
61716+ struct file *filp;
61717+
61718+ FOR_EACH_ROLE_START(r)
61719+ if (!strcmp(rolename, r->rolename) &&
61720+ (r->roletype & GR_ROLE_SPECIAL)) {
61721+ assigned = r;
61722+ break;
61723+ }
61724+ FOR_EACH_ROLE_END(r)
61725+
61726+ if (!assigned)
61727+ return;
61728+
61729+ read_lock(&tasklist_lock);
61730+ read_lock(&grsec_exec_file_lock);
61731+
61732+ tsk = current->real_parent;
61733+ if (tsk == NULL)
61734+ goto out_unlock;
61735+
61736+ filp = tsk->exec_file;
61737+ if (filp == NULL)
61738+ goto out_unlock;
61739+
61740+ tsk->is_writable = 0;
61741+
61742+ tsk->acl_sp_role = 1;
61743+ tsk->acl_role_id = ++acl_sp_role_value;
61744+ tsk->role = assigned;
61745+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
61746+
61747+ /* ignore additional mmap checks for processes that are writable
61748+ by the default ACL */
61749+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
61750+ if (unlikely(obj->mode & GR_WRITE))
61751+ tsk->is_writable = 1;
61752+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
61753+ if (unlikely(obj->mode & GR_WRITE))
61754+ tsk->is_writable = 1;
61755+
61756+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
61757+ 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));
61758+#endif
61759+
61760+out_unlock:
61761+ read_unlock(&grsec_exec_file_lock);
61762+ read_unlock(&tasklist_lock);
61763+ return;
61764+}
61765+
61766+int gr_check_secure_terminal(struct task_struct *task)
61767+{
61768+ struct task_struct *p, *p2, *p3;
61769+ struct files_struct *files;
61770+ struct fdtable *fdt;
61771+ struct file *our_file = NULL, *file;
61772+ int i;
61773+
61774+ if (task->signal->tty == NULL)
61775+ return 1;
61776+
61777+ files = get_files_struct(task);
61778+ if (files != NULL) {
61779+ rcu_read_lock();
61780+ fdt = files_fdtable(files);
61781+ for (i=0; i < fdt->max_fds; i++) {
61782+ file = fcheck_files(files, i);
61783+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
61784+ get_file(file);
61785+ our_file = file;
61786+ }
61787+ }
61788+ rcu_read_unlock();
61789+ put_files_struct(files);
61790+ }
61791+
61792+ if (our_file == NULL)
61793+ return 1;
61794+
61795+ read_lock(&tasklist_lock);
61796+ do_each_thread(p2, p) {
61797+ files = get_files_struct(p);
61798+ if (files == NULL ||
61799+ (p->signal && p->signal->tty == task->signal->tty)) {
61800+ if (files != NULL)
61801+ put_files_struct(files);
61802+ continue;
61803+ }
61804+ rcu_read_lock();
61805+ fdt = files_fdtable(files);
61806+ for (i=0; i < fdt->max_fds; i++) {
61807+ file = fcheck_files(files, i);
61808+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
61809+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
61810+ p3 = task;
61811+ while (task_pid_nr(p3) > 0) {
61812+ if (p3 == p)
61813+ break;
61814+ p3 = p3->real_parent;
61815+ }
61816+ if (p3 == p)
61817+ break;
61818+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
61819+ gr_handle_alertkill(p);
61820+ rcu_read_unlock();
61821+ put_files_struct(files);
61822+ read_unlock(&tasklist_lock);
61823+ fput(our_file);
61824+ return 0;
61825+ }
61826+ }
61827+ rcu_read_unlock();
61828+ put_files_struct(files);
61829+ } while_each_thread(p2, p);
61830+ read_unlock(&tasklist_lock);
61831+
61832+ fput(our_file);
61833+ return 1;
61834+}
61835+
61836+static int gr_rbac_disable(void *unused)
61837+{
61838+ pax_open_kernel();
61839+ gr_status &= ~GR_READY;
61840+ pax_close_kernel();
61841+
61842+ return 0;
61843+}
61844+
61845+ssize_t
61846+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
61847+{
61848+ struct gr_arg_wrapper uwrap;
61849+ unsigned char *sprole_salt = NULL;
61850+ unsigned char *sprole_sum = NULL;
61851+ int error = sizeof (struct gr_arg_wrapper);
61852+ int error2 = 0;
61853+
61854+ mutex_lock(&gr_dev_mutex);
61855+
61856+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
61857+ error = -EPERM;
61858+ goto out;
61859+ }
61860+
61861+ if (count != sizeof (struct gr_arg_wrapper)) {
61862+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
61863+ error = -EINVAL;
61864+ goto out;
61865+ }
61866+
61867+
61868+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
61869+ gr_auth_expires = 0;
61870+ gr_auth_attempts = 0;
61871+ }
61872+
61873+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
61874+ error = -EFAULT;
61875+ goto out;
61876+ }
61877+
61878+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
61879+ error = -EINVAL;
61880+ goto out;
61881+ }
61882+
61883+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
61884+ error = -EFAULT;
61885+ goto out;
61886+ }
61887+
61888+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
61889+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
61890+ time_after(gr_auth_expires, get_seconds())) {
61891+ error = -EBUSY;
61892+ goto out;
61893+ }
61894+
61895+ /* if non-root trying to do anything other than use a special role,
61896+ do not attempt authentication, do not count towards authentication
61897+ locking
61898+ */
61899+
61900+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
61901+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
61902+ gr_is_global_nonroot(current_uid())) {
61903+ error = -EPERM;
61904+ goto out;
61905+ }
61906+
61907+ /* ensure pw and special role name are null terminated */
61908+
61909+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
61910+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
61911+
61912+ /* Okay.
61913+ * We have our enough of the argument structure..(we have yet
61914+ * to copy_from_user the tables themselves) . Copy the tables
61915+ * only if we need them, i.e. for loading operations. */
61916+
61917+ switch (gr_usermode->mode) {
61918+ case GR_STATUS:
61919+ if (gr_status & GR_READY) {
61920+ error = 1;
61921+ if (!gr_check_secure_terminal(current))
61922+ error = 3;
61923+ } else
61924+ error = 2;
61925+ goto out;
61926+ case GR_SHUTDOWN:
61927+ if ((gr_status & GR_READY)
61928+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
61929+ stop_machine(gr_rbac_disable, NULL, NULL);
61930+ free_variables();
61931+ memset(gr_usermode, 0, sizeof (struct gr_arg));
61932+ memset(gr_system_salt, 0, GR_SALT_LEN);
61933+ memset(gr_system_sum, 0, GR_SHA_LEN);
61934+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
61935+ } else if (gr_status & GR_READY) {
61936+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
61937+ error = -EPERM;
61938+ } else {
61939+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
61940+ error = -EAGAIN;
61941+ }
61942+ break;
61943+ case GR_ENABLE:
61944+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
61945+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
61946+ else {
61947+ if (gr_status & GR_READY)
61948+ error = -EAGAIN;
61949+ else
61950+ error = error2;
61951+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
61952+ }
61953+ break;
61954+ case GR_RELOAD:
61955+ if (!(gr_status & GR_READY)) {
61956+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
61957+ error = -EAGAIN;
61958+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
61959+ stop_machine(gr_rbac_disable, NULL, NULL);
61960+ free_variables();
61961+ error2 = gracl_init(gr_usermode);
61962+ if (!error2)
61963+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
61964+ else {
61965+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
61966+ error = error2;
61967+ }
61968+ } else {
61969+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
61970+ error = -EPERM;
61971+ }
61972+ break;
61973+ case GR_SEGVMOD:
61974+ if (unlikely(!(gr_status & GR_READY))) {
61975+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
61976+ error = -EAGAIN;
61977+ break;
61978+ }
61979+
61980+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
61981+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
61982+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
61983+ struct acl_subject_label *segvacl;
61984+ segvacl =
61985+ lookup_acl_subj_label(gr_usermode->segv_inode,
61986+ gr_usermode->segv_device,
61987+ current->role);
61988+ if (segvacl) {
61989+ segvacl->crashes = 0;
61990+ segvacl->expires = 0;
61991+ }
61992+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
61993+ gr_remove_uid(gr_usermode->segv_uid);
61994+ }
61995+ } else {
61996+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
61997+ error = -EPERM;
61998+ }
61999+ break;
62000+ case GR_SPROLE:
62001+ case GR_SPROLEPAM:
62002+ if (unlikely(!(gr_status & GR_READY))) {
62003+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
62004+ error = -EAGAIN;
62005+ break;
62006+ }
62007+
62008+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
62009+ current->role->expires = 0;
62010+ current->role->auth_attempts = 0;
62011+ }
62012+
62013+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
62014+ time_after(current->role->expires, get_seconds())) {
62015+ error = -EBUSY;
62016+ goto out;
62017+ }
62018+
62019+ if (lookup_special_role_auth
62020+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
62021+ && ((!sprole_salt && !sprole_sum)
62022+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
62023+ char *p = "";
62024+ assign_special_role(gr_usermode->sp_role);
62025+ read_lock(&tasklist_lock);
62026+ if (current->real_parent)
62027+ p = current->real_parent->role->rolename;
62028+ read_unlock(&tasklist_lock);
62029+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
62030+ p, acl_sp_role_value);
62031+ } else {
62032+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
62033+ error = -EPERM;
62034+ if(!(current->role->auth_attempts++))
62035+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
62036+
62037+ goto out;
62038+ }
62039+ break;
62040+ case GR_UNSPROLE:
62041+ if (unlikely(!(gr_status & GR_READY))) {
62042+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
62043+ error = -EAGAIN;
62044+ break;
62045+ }
62046+
62047+ if (current->role->roletype & GR_ROLE_SPECIAL) {
62048+ char *p = "";
62049+ int i = 0;
62050+
62051+ read_lock(&tasklist_lock);
62052+ if (current->real_parent) {
62053+ p = current->real_parent->role->rolename;
62054+ i = current->real_parent->acl_role_id;
62055+ }
62056+ read_unlock(&tasklist_lock);
62057+
62058+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
62059+ gr_set_acls(1);
62060+ } else {
62061+ error = -EPERM;
62062+ goto out;
62063+ }
62064+ break;
62065+ default:
62066+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
62067+ error = -EINVAL;
62068+ break;
62069+ }
62070+
62071+ if (error != -EPERM)
62072+ goto out;
62073+
62074+ if(!(gr_auth_attempts++))
62075+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
62076+
62077+ out:
62078+ mutex_unlock(&gr_dev_mutex);
62079+ return error;
62080+}
62081+
62082+/* must be called with
62083+ rcu_read_lock();
62084+ read_lock(&tasklist_lock);
62085+ read_lock(&grsec_exec_file_lock);
62086+*/
62087+int gr_apply_subject_to_task(struct task_struct *task)
62088+{
62089+ struct acl_object_label *obj;
62090+ char *tmpname;
62091+ struct acl_subject_label *tmpsubj;
62092+ struct file *filp;
62093+ struct name_entry *nmatch;
62094+
62095+ filp = task->exec_file;
62096+ if (filp == NULL)
62097+ return 0;
62098+
62099+ /* the following is to apply the correct subject
62100+ on binaries running when the RBAC system
62101+ is enabled, when the binaries have been
62102+ replaced or deleted since their execution
62103+ -----
62104+ when the RBAC system starts, the inode/dev
62105+ from exec_file will be one the RBAC system
62106+ is unaware of. It only knows the inode/dev
62107+ of the present file on disk, or the absence
62108+ of it.
62109+ */
62110+ preempt_disable();
62111+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
62112+
62113+ nmatch = lookup_name_entry(tmpname);
62114+ preempt_enable();
62115+ tmpsubj = NULL;
62116+ if (nmatch) {
62117+ if (nmatch->deleted)
62118+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
62119+ else
62120+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
62121+ if (tmpsubj != NULL)
62122+ task->acl = tmpsubj;
62123+ }
62124+ if (tmpsubj == NULL)
62125+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
62126+ task->role);
62127+ if (task->acl) {
62128+ task->is_writable = 0;
62129+ /* ignore additional mmap checks for processes that are writable
62130+ by the default ACL */
62131+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
62132+ if (unlikely(obj->mode & GR_WRITE))
62133+ task->is_writable = 1;
62134+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
62135+ if (unlikely(obj->mode & GR_WRITE))
62136+ task->is_writable = 1;
62137+
62138+ gr_set_proc_res(task);
62139+
62140+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
62141+ 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);
62142+#endif
62143+ } else {
62144+ return 1;
62145+ }
62146+
62147+ return 0;
62148+}
62149+
62150+int
62151+gr_set_acls(const int type)
62152+{
62153+ struct task_struct *task, *task2;
62154+ struct acl_role_label *role = current->role;
62155+ __u16 acl_role_id = current->acl_role_id;
62156+ const struct cred *cred;
62157+ int ret;
62158+
62159+ rcu_read_lock();
62160+ read_lock(&tasklist_lock);
62161+ read_lock(&grsec_exec_file_lock);
62162+ do_each_thread(task2, task) {
62163+ /* check to see if we're called from the exit handler,
62164+ if so, only replace ACLs that have inherited the admin
62165+ ACL */
62166+
62167+ if (type && (task->role != role ||
62168+ task->acl_role_id != acl_role_id))
62169+ continue;
62170+
62171+ task->acl_role_id = 0;
62172+ task->acl_sp_role = 0;
62173+
62174+ if (task->exec_file) {
62175+ cred = __task_cred(task);
62176+ task->role = lookup_acl_role_label(task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
62177+ ret = gr_apply_subject_to_task(task);
62178+ if (ret) {
62179+ read_unlock(&grsec_exec_file_lock);
62180+ read_unlock(&tasklist_lock);
62181+ rcu_read_unlock();
62182+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
62183+ return ret;
62184+ }
62185+ } else {
62186+ // it's a kernel process
62187+ task->role = kernel_role;
62188+ task->acl = kernel_role->root_label;
62189+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
62190+ task->acl->mode &= ~GR_PROCFIND;
62191+#endif
62192+ }
62193+ } while_each_thread(task2, task);
62194+ read_unlock(&grsec_exec_file_lock);
62195+ read_unlock(&tasklist_lock);
62196+ rcu_read_unlock();
62197+
62198+ return 0;
62199+}
62200+
62201+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
62202+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
62203+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
62204+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
62205+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
62206+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
62207+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
62208+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
62209+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
62210+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
62211+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
62212+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
62213+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
62214+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
62215+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
62216+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
62217+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
62218+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
62219+};
62220+
62221+void
62222+gr_learn_resource(const struct task_struct *task,
62223+ const int res, const unsigned long wanted, const int gt)
62224+{
62225+ struct acl_subject_label *acl;
62226+ const struct cred *cred;
62227+
62228+ if (unlikely((gr_status & GR_READY) &&
62229+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
62230+ goto skip_reslog;
62231+
62232+ gr_log_resource(task, res, wanted, gt);
62233+skip_reslog:
62234+
62235+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
62236+ return;
62237+
62238+ acl = task->acl;
62239+
62240+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
62241+ !(acl->resmask & (1U << (unsigned short) res))))
62242+ return;
62243+
62244+ if (wanted >= acl->res[res].rlim_cur) {
62245+ unsigned long res_add;
62246+
62247+ res_add = wanted + res_learn_bumps[res];
62248+
62249+ acl->res[res].rlim_cur = res_add;
62250+
62251+ if (wanted > acl->res[res].rlim_max)
62252+ acl->res[res].rlim_max = res_add;
62253+
62254+ /* only log the subject filename, since resource logging is supported for
62255+ single-subject learning only */
62256+ rcu_read_lock();
62257+ cred = __task_cred(task);
62258+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
62259+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
62260+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
62261+ "", (unsigned long) res, &task->signal->saved_ip);
62262+ rcu_read_unlock();
62263+ }
62264+
62265+ return;
62266+}
62267+EXPORT_SYMBOL(gr_learn_resource);
62268+#endif
62269+
62270+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
62271+void
62272+pax_set_initial_flags(struct linux_binprm *bprm)
62273+{
62274+ struct task_struct *task = current;
62275+ struct acl_subject_label *proc;
62276+ unsigned long flags;
62277+
62278+ if (unlikely(!(gr_status & GR_READY)))
62279+ return;
62280+
62281+ flags = pax_get_flags(task);
62282+
62283+ proc = task->acl;
62284+
62285+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
62286+ flags &= ~MF_PAX_PAGEEXEC;
62287+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
62288+ flags &= ~MF_PAX_SEGMEXEC;
62289+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
62290+ flags &= ~MF_PAX_RANDMMAP;
62291+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
62292+ flags &= ~MF_PAX_EMUTRAMP;
62293+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
62294+ flags &= ~MF_PAX_MPROTECT;
62295+
62296+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
62297+ flags |= MF_PAX_PAGEEXEC;
62298+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
62299+ flags |= MF_PAX_SEGMEXEC;
62300+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
62301+ flags |= MF_PAX_RANDMMAP;
62302+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
62303+ flags |= MF_PAX_EMUTRAMP;
62304+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
62305+ flags |= MF_PAX_MPROTECT;
62306+
62307+ pax_set_flags(task, flags);
62308+
62309+ return;
62310+}
62311+#endif
62312+
62313+int
62314+gr_handle_proc_ptrace(struct task_struct *task)
62315+{
62316+ struct file *filp;
62317+ struct task_struct *tmp = task;
62318+ struct task_struct *curtemp = current;
62319+ __u32 retmode;
62320+
62321+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
62322+ if (unlikely(!(gr_status & GR_READY)))
62323+ return 0;
62324+#endif
62325+
62326+ read_lock(&tasklist_lock);
62327+ read_lock(&grsec_exec_file_lock);
62328+ filp = task->exec_file;
62329+
62330+ while (task_pid_nr(tmp) > 0) {
62331+ if (tmp == curtemp)
62332+ break;
62333+ tmp = tmp->real_parent;
62334+ }
62335+
62336+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
62337+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
62338+ read_unlock(&grsec_exec_file_lock);
62339+ read_unlock(&tasklist_lock);
62340+ return 1;
62341+ }
62342+
62343+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
62344+ if (!(gr_status & GR_READY)) {
62345+ read_unlock(&grsec_exec_file_lock);
62346+ read_unlock(&tasklist_lock);
62347+ return 0;
62348+ }
62349+#endif
62350+
62351+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
62352+ read_unlock(&grsec_exec_file_lock);
62353+ read_unlock(&tasklist_lock);
62354+
62355+ if (retmode & GR_NOPTRACE)
62356+ return 1;
62357+
62358+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
62359+ && (current->acl != task->acl || (current->acl != current->role->root_label
62360+ && task_pid_nr(current) != task_pid_nr(task))))
62361+ return 1;
62362+
62363+ return 0;
62364+}
62365+
62366+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
62367+{
62368+ if (unlikely(!(gr_status & GR_READY)))
62369+ return;
62370+
62371+ if (!(current->role->roletype & GR_ROLE_GOD))
62372+ return;
62373+
62374+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
62375+ p->role->rolename, gr_task_roletype_to_char(p),
62376+ p->acl->filename);
62377+}
62378+
62379+int
62380+gr_handle_ptrace(struct task_struct *task, const long request)
62381+{
62382+ struct task_struct *tmp = task;
62383+ struct task_struct *curtemp = current;
62384+ __u32 retmode;
62385+
62386+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
62387+ if (unlikely(!(gr_status & GR_READY)))
62388+ return 0;
62389+#endif
62390+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
62391+ read_lock(&tasklist_lock);
62392+ while (task_pid_nr(tmp) > 0) {
62393+ if (tmp == curtemp)
62394+ break;
62395+ tmp = tmp->real_parent;
62396+ }
62397+
62398+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
62399+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
62400+ read_unlock(&tasklist_lock);
62401+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
62402+ return 1;
62403+ }
62404+ read_unlock(&tasklist_lock);
62405+ }
62406+
62407+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
62408+ if (!(gr_status & GR_READY))
62409+ return 0;
62410+#endif
62411+
62412+ read_lock(&grsec_exec_file_lock);
62413+ if (unlikely(!task->exec_file)) {
62414+ read_unlock(&grsec_exec_file_lock);
62415+ return 0;
62416+ }
62417+
62418+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
62419+ read_unlock(&grsec_exec_file_lock);
62420+
62421+ if (retmode & GR_NOPTRACE) {
62422+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
62423+ return 1;
62424+ }
62425+
62426+ if (retmode & GR_PTRACERD) {
62427+ switch (request) {
62428+ case PTRACE_SEIZE:
62429+ case PTRACE_POKETEXT:
62430+ case PTRACE_POKEDATA:
62431+ case PTRACE_POKEUSR:
62432+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
62433+ case PTRACE_SETREGS:
62434+ case PTRACE_SETFPREGS:
62435+#endif
62436+#ifdef CONFIG_X86
62437+ case PTRACE_SETFPXREGS:
62438+#endif
62439+#ifdef CONFIG_ALTIVEC
62440+ case PTRACE_SETVRREGS:
62441+#endif
62442+ return 1;
62443+ default:
62444+ return 0;
62445+ }
62446+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
62447+ !(current->role->roletype & GR_ROLE_GOD) &&
62448+ (current->acl != task->acl)) {
62449+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
62450+ return 1;
62451+ }
62452+
62453+ return 0;
62454+}
62455+
62456+static int is_writable_mmap(const struct file *filp)
62457+{
62458+ struct task_struct *task = current;
62459+ struct acl_object_label *obj, *obj2;
62460+
62461+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
62462+ !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))) {
62463+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
62464+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
62465+ task->role->root_label);
62466+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
62467+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
62468+ return 1;
62469+ }
62470+ }
62471+ return 0;
62472+}
62473+
62474+int
62475+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
62476+{
62477+ __u32 mode;
62478+
62479+ if (unlikely(!file || !(prot & PROT_EXEC)))
62480+ return 1;
62481+
62482+ if (is_writable_mmap(file))
62483+ return 0;
62484+
62485+ mode =
62486+ gr_search_file(file->f_path.dentry,
62487+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
62488+ file->f_path.mnt);
62489+
62490+ if (!gr_tpe_allow(file))
62491+ return 0;
62492+
62493+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
62494+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
62495+ return 0;
62496+ } else if (unlikely(!(mode & GR_EXEC))) {
62497+ return 0;
62498+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
62499+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
62500+ return 1;
62501+ }
62502+
62503+ return 1;
62504+}
62505+
62506+int
62507+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
62508+{
62509+ __u32 mode;
62510+
62511+ if (unlikely(!file || !(prot & PROT_EXEC)))
62512+ return 1;
62513+
62514+ if (is_writable_mmap(file))
62515+ return 0;
62516+
62517+ mode =
62518+ gr_search_file(file->f_path.dentry,
62519+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
62520+ file->f_path.mnt);
62521+
62522+ if (!gr_tpe_allow(file))
62523+ return 0;
62524+
62525+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
62526+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
62527+ return 0;
62528+ } else if (unlikely(!(mode & GR_EXEC))) {
62529+ return 0;
62530+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
62531+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
62532+ return 1;
62533+ }
62534+
62535+ return 1;
62536+}
62537+
62538+void
62539+gr_acl_handle_psacct(struct task_struct *task, const long code)
62540+{
62541+ unsigned long runtime;
62542+ unsigned long cputime;
62543+ unsigned int wday, cday;
62544+ __u8 whr, chr;
62545+ __u8 wmin, cmin;
62546+ __u8 wsec, csec;
62547+ struct timespec timeval;
62548+
62549+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
62550+ !(task->acl->mode & GR_PROCACCT)))
62551+ return;
62552+
62553+ do_posix_clock_monotonic_gettime(&timeval);
62554+ runtime = timeval.tv_sec - task->start_time.tv_sec;
62555+ wday = runtime / (3600 * 24);
62556+ runtime -= wday * (3600 * 24);
62557+ whr = runtime / 3600;
62558+ runtime -= whr * 3600;
62559+ wmin = runtime / 60;
62560+ runtime -= wmin * 60;
62561+ wsec = runtime;
62562+
62563+ cputime = (task->utime + task->stime) / HZ;
62564+ cday = cputime / (3600 * 24);
62565+ cputime -= cday * (3600 * 24);
62566+ chr = cputime / 3600;
62567+ cputime -= chr * 3600;
62568+ cmin = cputime / 60;
62569+ cputime -= cmin * 60;
62570+ csec = cputime;
62571+
62572+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
62573+
62574+ return;
62575+}
62576+
62577+void gr_set_kernel_label(struct task_struct *task)
62578+{
62579+ if (gr_status & GR_READY) {
62580+ task->role = kernel_role;
62581+ task->acl = kernel_role->root_label;
62582+ }
62583+ return;
62584+}
62585+
62586+#ifdef CONFIG_TASKSTATS
62587+int gr_is_taskstats_denied(int pid)
62588+{
62589+ struct task_struct *task;
62590+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62591+ const struct cred *cred;
62592+#endif
62593+ int ret = 0;
62594+
62595+ /* restrict taskstats viewing to un-chrooted root users
62596+ who have the 'view' subject flag if the RBAC system is enabled
62597+ */
62598+
62599+ rcu_read_lock();
62600+ read_lock(&tasklist_lock);
62601+ task = find_task_by_vpid(pid);
62602+ if (task) {
62603+#ifdef CONFIG_GRKERNSEC_CHROOT
62604+ if (proc_is_chrooted(task))
62605+ ret = -EACCES;
62606+#endif
62607+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62608+ cred = __task_cred(task);
62609+#ifdef CONFIG_GRKERNSEC_PROC_USER
62610+ if (gr_is_global_nonroot(cred->uid))
62611+ ret = -EACCES;
62612+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62613+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
62614+ ret = -EACCES;
62615+#endif
62616+#endif
62617+ if (gr_status & GR_READY) {
62618+ if (!(task->acl->mode & GR_VIEW))
62619+ ret = -EACCES;
62620+ }
62621+ } else
62622+ ret = -ENOENT;
62623+
62624+ read_unlock(&tasklist_lock);
62625+ rcu_read_unlock();
62626+
62627+ return ret;
62628+}
62629+#endif
62630+
62631+/* AUXV entries are filled via a descendant of search_binary_handler
62632+ after we've already applied the subject for the target
62633+*/
62634+int gr_acl_enable_at_secure(void)
62635+{
62636+ if (unlikely(!(gr_status & GR_READY)))
62637+ return 0;
62638+
62639+ if (current->acl->mode & GR_ATSECURE)
62640+ return 1;
62641+
62642+ return 0;
62643+}
62644+
62645+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
62646+{
62647+ struct task_struct *task = current;
62648+ struct dentry *dentry = file->f_path.dentry;
62649+ struct vfsmount *mnt = file->f_path.mnt;
62650+ struct acl_object_label *obj, *tmp;
62651+ struct acl_subject_label *subj;
62652+ unsigned int bufsize;
62653+ int is_not_root;
62654+ char *path;
62655+ dev_t dev = __get_dev(dentry);
62656+
62657+ if (unlikely(!(gr_status & GR_READY)))
62658+ return 1;
62659+
62660+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
62661+ return 1;
62662+
62663+ /* ignore Eric Biederman */
62664+ if (IS_PRIVATE(dentry->d_inode))
62665+ return 1;
62666+
62667+ subj = task->acl;
62668+ read_lock(&gr_inode_lock);
62669+ do {
62670+ obj = lookup_acl_obj_label(ino, dev, subj);
62671+ if (obj != NULL) {
62672+ read_unlock(&gr_inode_lock);
62673+ return (obj->mode & GR_FIND) ? 1 : 0;
62674+ }
62675+ } while ((subj = subj->parent_subject));
62676+ read_unlock(&gr_inode_lock);
62677+
62678+ /* this is purely an optimization since we're looking for an object
62679+ for the directory we're doing a readdir on
62680+ if it's possible for any globbed object to match the entry we're
62681+ filling into the directory, then the object we find here will be
62682+ an anchor point with attached globbed objects
62683+ */
62684+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
62685+ if (obj->globbed == NULL)
62686+ return (obj->mode & GR_FIND) ? 1 : 0;
62687+
62688+ is_not_root = ((obj->filename[0] == '/') &&
62689+ (obj->filename[1] == '\0')) ? 0 : 1;
62690+ bufsize = PAGE_SIZE - namelen - is_not_root;
62691+
62692+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
62693+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
62694+ return 1;
62695+
62696+ preempt_disable();
62697+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
62698+ bufsize);
62699+
62700+ bufsize = strlen(path);
62701+
62702+ /* if base is "/", don't append an additional slash */
62703+ if (is_not_root)
62704+ *(path + bufsize) = '/';
62705+ memcpy(path + bufsize + is_not_root, name, namelen);
62706+ *(path + bufsize + namelen + is_not_root) = '\0';
62707+
62708+ tmp = obj->globbed;
62709+ while (tmp) {
62710+ if (!glob_match(tmp->filename, path)) {
62711+ preempt_enable();
62712+ return (tmp->mode & GR_FIND) ? 1 : 0;
62713+ }
62714+ tmp = tmp->next;
62715+ }
62716+ preempt_enable();
62717+ return (obj->mode & GR_FIND) ? 1 : 0;
62718+}
62719+
62720+void gr_put_exec_file(struct task_struct *task)
62721+{
62722+ struct file *filp;
62723+
62724+ write_lock(&grsec_exec_file_lock);
62725+ filp = task->exec_file;
62726+ task->exec_file = NULL;
62727+ write_unlock(&grsec_exec_file_lock);
62728+
62729+ if (filp)
62730+ fput(filp);
62731+
62732+ return;
62733+}
62734+
62735+
62736+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
62737+EXPORT_SYMBOL(gr_acl_is_enabled);
62738+#endif
62739+EXPORT_SYMBOL(gr_set_kernel_label);
62740+#ifdef CONFIG_SECURITY
62741+EXPORT_SYMBOL(gr_check_user_change);
62742+EXPORT_SYMBOL(gr_check_group_change);
62743+#endif
62744+
62745diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
62746new file mode 100644
62747index 0000000..34fefda
62748--- /dev/null
62749+++ b/grsecurity/gracl_alloc.c
62750@@ -0,0 +1,105 @@
62751+#include <linux/kernel.h>
62752+#include <linux/mm.h>
62753+#include <linux/slab.h>
62754+#include <linux/vmalloc.h>
62755+#include <linux/gracl.h>
62756+#include <linux/grsecurity.h>
62757+
62758+static unsigned long alloc_stack_next = 1;
62759+static unsigned long alloc_stack_size = 1;
62760+static void **alloc_stack;
62761+
62762+static __inline__ int
62763+alloc_pop(void)
62764+{
62765+ if (alloc_stack_next == 1)
62766+ return 0;
62767+
62768+ kfree(alloc_stack[alloc_stack_next - 2]);
62769+
62770+ alloc_stack_next--;
62771+
62772+ return 1;
62773+}
62774+
62775+static __inline__ int
62776+alloc_push(void *buf)
62777+{
62778+ if (alloc_stack_next >= alloc_stack_size)
62779+ return 1;
62780+
62781+ alloc_stack[alloc_stack_next - 1] = buf;
62782+
62783+ alloc_stack_next++;
62784+
62785+ return 0;
62786+}
62787+
62788+void *
62789+acl_alloc(unsigned long len)
62790+{
62791+ void *ret = NULL;
62792+
62793+ if (!len || len > PAGE_SIZE)
62794+ goto out;
62795+
62796+ ret = kmalloc(len, GFP_KERNEL);
62797+
62798+ if (ret) {
62799+ if (alloc_push(ret)) {
62800+ kfree(ret);
62801+ ret = NULL;
62802+ }
62803+ }
62804+
62805+out:
62806+ return ret;
62807+}
62808+
62809+void *
62810+acl_alloc_num(unsigned long num, unsigned long len)
62811+{
62812+ if (!len || (num > (PAGE_SIZE / len)))
62813+ return NULL;
62814+
62815+ return acl_alloc(num * len);
62816+}
62817+
62818+void
62819+acl_free_all(void)
62820+{
62821+ if (gr_acl_is_enabled() || !alloc_stack)
62822+ return;
62823+
62824+ while (alloc_pop()) ;
62825+
62826+ if (alloc_stack) {
62827+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
62828+ kfree(alloc_stack);
62829+ else
62830+ vfree(alloc_stack);
62831+ }
62832+
62833+ alloc_stack = NULL;
62834+ alloc_stack_size = 1;
62835+ alloc_stack_next = 1;
62836+
62837+ return;
62838+}
62839+
62840+int
62841+acl_alloc_stack_init(unsigned long size)
62842+{
62843+ if ((size * sizeof (void *)) <= PAGE_SIZE)
62844+ alloc_stack =
62845+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
62846+ else
62847+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
62848+
62849+ alloc_stack_size = size;
62850+
62851+ if (!alloc_stack)
62852+ return 0;
62853+ else
62854+ return 1;
62855+}
62856diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
62857new file mode 100644
62858index 0000000..bdd51ea
62859--- /dev/null
62860+++ b/grsecurity/gracl_cap.c
62861@@ -0,0 +1,110 @@
62862+#include <linux/kernel.h>
62863+#include <linux/module.h>
62864+#include <linux/sched.h>
62865+#include <linux/gracl.h>
62866+#include <linux/grsecurity.h>
62867+#include <linux/grinternal.h>
62868+
62869+extern const char *captab_log[];
62870+extern int captab_log_entries;
62871+
62872+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
62873+{
62874+ struct acl_subject_label *curracl;
62875+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
62876+ kernel_cap_t cap_audit = __cap_empty_set;
62877+
62878+ if (!gr_acl_is_enabled())
62879+ return 1;
62880+
62881+ curracl = task->acl;
62882+
62883+ cap_drop = curracl->cap_lower;
62884+ cap_mask = curracl->cap_mask;
62885+ cap_audit = curracl->cap_invert_audit;
62886+
62887+ while ((curracl = curracl->parent_subject)) {
62888+ /* if the cap isn't specified in the current computed mask but is specified in the
62889+ current level subject, and is lowered in the current level subject, then add
62890+ it to the set of dropped capabilities
62891+ otherwise, add the current level subject's mask to the current computed mask
62892+ */
62893+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
62894+ cap_raise(cap_mask, cap);
62895+ if (cap_raised(curracl->cap_lower, cap))
62896+ cap_raise(cap_drop, cap);
62897+ if (cap_raised(curracl->cap_invert_audit, cap))
62898+ cap_raise(cap_audit, cap);
62899+ }
62900+ }
62901+
62902+ if (!cap_raised(cap_drop, cap)) {
62903+ if (cap_raised(cap_audit, cap))
62904+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
62905+ return 1;
62906+ }
62907+
62908+ curracl = task->acl;
62909+
62910+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
62911+ && cap_raised(cred->cap_effective, cap)) {
62912+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
62913+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
62914+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
62915+ gr_to_filename(task->exec_file->f_path.dentry,
62916+ task->exec_file->f_path.mnt) : curracl->filename,
62917+ curracl->filename, 0UL,
62918+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
62919+ return 1;
62920+ }
62921+
62922+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
62923+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
62924+
62925+ return 0;
62926+}
62927+
62928+int
62929+gr_acl_is_capable(const int cap)
62930+{
62931+ return gr_task_acl_is_capable(current, current_cred(), cap);
62932+}
62933+
62934+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
62935+{
62936+ struct acl_subject_label *curracl;
62937+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
62938+
62939+ if (!gr_acl_is_enabled())
62940+ return 1;
62941+
62942+ curracl = task->acl;
62943+
62944+ cap_drop = curracl->cap_lower;
62945+ cap_mask = curracl->cap_mask;
62946+
62947+ while ((curracl = curracl->parent_subject)) {
62948+ /* if the cap isn't specified in the current computed mask but is specified in the
62949+ current level subject, and is lowered in the current level subject, then add
62950+ it to the set of dropped capabilities
62951+ otherwise, add the current level subject's mask to the current computed mask
62952+ */
62953+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
62954+ cap_raise(cap_mask, cap);
62955+ if (cap_raised(curracl->cap_lower, cap))
62956+ cap_raise(cap_drop, cap);
62957+ }
62958+ }
62959+
62960+ if (!cap_raised(cap_drop, cap))
62961+ return 1;
62962+
62963+ return 0;
62964+}
62965+
62966+int
62967+gr_acl_is_capable_nolog(const int cap)
62968+{
62969+ return gr_task_acl_is_capable_nolog(current, cap);
62970+}
62971+
62972diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
62973new file mode 100644
62974index 0000000..a340c17
62975--- /dev/null
62976+++ b/grsecurity/gracl_fs.c
62977@@ -0,0 +1,431 @@
62978+#include <linux/kernel.h>
62979+#include <linux/sched.h>
62980+#include <linux/types.h>
62981+#include <linux/fs.h>
62982+#include <linux/file.h>
62983+#include <linux/stat.h>
62984+#include <linux/grsecurity.h>
62985+#include <linux/grinternal.h>
62986+#include <linux/gracl.h>
62987+
62988+umode_t
62989+gr_acl_umask(void)
62990+{
62991+ if (unlikely(!gr_acl_is_enabled()))
62992+ return 0;
62993+
62994+ return current->role->umask;
62995+}
62996+
62997+__u32
62998+gr_acl_handle_hidden_file(const struct dentry * dentry,
62999+ const struct vfsmount * mnt)
63000+{
63001+ __u32 mode;
63002+
63003+ if (unlikely(!dentry->d_inode))
63004+ return GR_FIND;
63005+
63006+ mode =
63007+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
63008+
63009+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
63010+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
63011+ return mode;
63012+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
63013+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
63014+ return 0;
63015+ } else if (unlikely(!(mode & GR_FIND)))
63016+ return 0;
63017+
63018+ return GR_FIND;
63019+}
63020+
63021+__u32
63022+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
63023+ int acc_mode)
63024+{
63025+ __u32 reqmode = GR_FIND;
63026+ __u32 mode;
63027+
63028+ if (unlikely(!dentry->d_inode))
63029+ return reqmode;
63030+
63031+ if (acc_mode & MAY_APPEND)
63032+ reqmode |= GR_APPEND;
63033+ else if (acc_mode & MAY_WRITE)
63034+ reqmode |= GR_WRITE;
63035+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
63036+ reqmode |= GR_READ;
63037+
63038+ mode =
63039+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
63040+ mnt);
63041+
63042+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
63043+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
63044+ reqmode & GR_READ ? " reading" : "",
63045+ reqmode & GR_WRITE ? " writing" : reqmode &
63046+ GR_APPEND ? " appending" : "");
63047+ return reqmode;
63048+ } else
63049+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
63050+ {
63051+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
63052+ reqmode & GR_READ ? " reading" : "",
63053+ reqmode & GR_WRITE ? " writing" : reqmode &
63054+ GR_APPEND ? " appending" : "");
63055+ return 0;
63056+ } else if (unlikely((mode & reqmode) != reqmode))
63057+ return 0;
63058+
63059+ return reqmode;
63060+}
63061+
63062+__u32
63063+gr_acl_handle_creat(const struct dentry * dentry,
63064+ const struct dentry * p_dentry,
63065+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
63066+ const int imode)
63067+{
63068+ __u32 reqmode = GR_WRITE | GR_CREATE;
63069+ __u32 mode;
63070+
63071+ if (acc_mode & MAY_APPEND)
63072+ reqmode |= GR_APPEND;
63073+ // if a directory was required or the directory already exists, then
63074+ // don't count this open as a read
63075+ if ((acc_mode & MAY_READ) &&
63076+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
63077+ reqmode |= GR_READ;
63078+ if ((open_flags & O_CREAT) &&
63079+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
63080+ reqmode |= GR_SETID;
63081+
63082+ mode =
63083+ gr_check_create(dentry, p_dentry, p_mnt,
63084+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
63085+
63086+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
63087+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
63088+ reqmode & GR_READ ? " reading" : "",
63089+ reqmode & GR_WRITE ? " writing" : reqmode &
63090+ GR_APPEND ? " appending" : "");
63091+ return reqmode;
63092+ } else
63093+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
63094+ {
63095+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
63096+ reqmode & GR_READ ? " reading" : "",
63097+ reqmode & GR_WRITE ? " writing" : reqmode &
63098+ GR_APPEND ? " appending" : "");
63099+ return 0;
63100+ } else if (unlikely((mode & reqmode) != reqmode))
63101+ return 0;
63102+
63103+ return reqmode;
63104+}
63105+
63106+__u32
63107+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
63108+ const int fmode)
63109+{
63110+ __u32 mode, reqmode = GR_FIND;
63111+
63112+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
63113+ reqmode |= GR_EXEC;
63114+ if (fmode & S_IWOTH)
63115+ reqmode |= GR_WRITE;
63116+ if (fmode & S_IROTH)
63117+ reqmode |= GR_READ;
63118+
63119+ mode =
63120+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
63121+ mnt);
63122+
63123+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
63124+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
63125+ reqmode & GR_READ ? " reading" : "",
63126+ reqmode & GR_WRITE ? " writing" : "",
63127+ reqmode & GR_EXEC ? " executing" : "");
63128+ return reqmode;
63129+ } else
63130+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
63131+ {
63132+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
63133+ reqmode & GR_READ ? " reading" : "",
63134+ reqmode & GR_WRITE ? " writing" : "",
63135+ reqmode & GR_EXEC ? " executing" : "");
63136+ return 0;
63137+ } else if (unlikely((mode & reqmode) != reqmode))
63138+ return 0;
63139+
63140+ return reqmode;
63141+}
63142+
63143+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
63144+{
63145+ __u32 mode;
63146+
63147+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
63148+
63149+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
63150+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
63151+ return mode;
63152+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
63153+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
63154+ return 0;
63155+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
63156+ return 0;
63157+
63158+ return (reqmode);
63159+}
63160+
63161+__u32
63162+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
63163+{
63164+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
63165+}
63166+
63167+__u32
63168+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
63169+{
63170+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
63171+}
63172+
63173+__u32
63174+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
63175+{
63176+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
63177+}
63178+
63179+__u32
63180+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
63181+{
63182+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
63183+}
63184+
63185+__u32
63186+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
63187+ umode_t *modeptr)
63188+{
63189+ umode_t mode;
63190+
63191+ *modeptr &= ~gr_acl_umask();
63192+ mode = *modeptr;
63193+
63194+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
63195+ return 1;
63196+
63197+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
63198+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
63199+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
63200+ GR_CHMOD_ACL_MSG);
63201+ } else {
63202+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
63203+ }
63204+}
63205+
63206+__u32
63207+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
63208+{
63209+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
63210+}
63211+
63212+__u32
63213+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
63214+{
63215+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
63216+}
63217+
63218+__u32
63219+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
63220+{
63221+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
63222+}
63223+
63224+__u32
63225+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
63226+{
63227+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
63228+ GR_UNIXCONNECT_ACL_MSG);
63229+}
63230+
63231+/* hardlinks require at minimum create and link permission,
63232+ any additional privilege required is based on the
63233+ privilege of the file being linked to
63234+*/
63235+__u32
63236+gr_acl_handle_link(const struct dentry * new_dentry,
63237+ const struct dentry * parent_dentry,
63238+ const struct vfsmount * parent_mnt,
63239+ const struct dentry * old_dentry,
63240+ const struct vfsmount * old_mnt, const struct filename *to)
63241+{
63242+ __u32 mode;
63243+ __u32 needmode = GR_CREATE | GR_LINK;
63244+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
63245+
63246+ mode =
63247+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
63248+ old_mnt);
63249+
63250+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
63251+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
63252+ return mode;
63253+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
63254+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
63255+ return 0;
63256+ } else if (unlikely((mode & needmode) != needmode))
63257+ return 0;
63258+
63259+ return 1;
63260+}
63261+
63262+__u32
63263+gr_acl_handle_symlink(const struct dentry * new_dentry,
63264+ const struct dentry * parent_dentry,
63265+ const struct vfsmount * parent_mnt, const struct filename *from)
63266+{
63267+ __u32 needmode = GR_WRITE | GR_CREATE;
63268+ __u32 mode;
63269+
63270+ mode =
63271+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
63272+ GR_CREATE | GR_AUDIT_CREATE |
63273+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
63274+
63275+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
63276+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
63277+ return mode;
63278+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
63279+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
63280+ return 0;
63281+ } else if (unlikely((mode & needmode) != needmode))
63282+ return 0;
63283+
63284+ return (GR_WRITE | GR_CREATE);
63285+}
63286+
63287+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)
63288+{
63289+ __u32 mode;
63290+
63291+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
63292+
63293+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
63294+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
63295+ return mode;
63296+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
63297+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
63298+ return 0;
63299+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
63300+ return 0;
63301+
63302+ return (reqmode);
63303+}
63304+
63305+__u32
63306+gr_acl_handle_mknod(const struct dentry * new_dentry,
63307+ const struct dentry * parent_dentry,
63308+ const struct vfsmount * parent_mnt,
63309+ const int mode)
63310+{
63311+ __u32 reqmode = GR_WRITE | GR_CREATE;
63312+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
63313+ reqmode |= GR_SETID;
63314+
63315+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
63316+ reqmode, GR_MKNOD_ACL_MSG);
63317+}
63318+
63319+__u32
63320+gr_acl_handle_mkdir(const struct dentry *new_dentry,
63321+ const struct dentry *parent_dentry,
63322+ const struct vfsmount *parent_mnt)
63323+{
63324+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
63325+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
63326+}
63327+
63328+#define RENAME_CHECK_SUCCESS(old, new) \
63329+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
63330+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
63331+
63332+int
63333+gr_acl_handle_rename(struct dentry *new_dentry,
63334+ struct dentry *parent_dentry,
63335+ const struct vfsmount *parent_mnt,
63336+ struct dentry *old_dentry,
63337+ struct inode *old_parent_inode,
63338+ struct vfsmount *old_mnt, const struct filename *newname)
63339+{
63340+ __u32 comp1, comp2;
63341+ int error = 0;
63342+
63343+ if (unlikely(!gr_acl_is_enabled()))
63344+ return 0;
63345+
63346+ if (!new_dentry->d_inode) {
63347+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
63348+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
63349+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
63350+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
63351+ GR_DELETE | GR_AUDIT_DELETE |
63352+ GR_AUDIT_READ | GR_AUDIT_WRITE |
63353+ GR_SUPPRESS, old_mnt);
63354+ } else {
63355+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
63356+ GR_CREATE | GR_DELETE |
63357+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
63358+ GR_AUDIT_READ | GR_AUDIT_WRITE |
63359+ GR_SUPPRESS, parent_mnt);
63360+ comp2 =
63361+ gr_search_file(old_dentry,
63362+ GR_READ | GR_WRITE | GR_AUDIT_READ |
63363+ GR_DELETE | GR_AUDIT_DELETE |
63364+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
63365+ }
63366+
63367+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
63368+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
63369+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
63370+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
63371+ && !(comp2 & GR_SUPPRESS)) {
63372+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
63373+ error = -EACCES;
63374+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
63375+ error = -EACCES;
63376+
63377+ return error;
63378+}
63379+
63380+void
63381+gr_acl_handle_exit(void)
63382+{
63383+ u16 id;
63384+ char *rolename;
63385+
63386+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
63387+ !(current->role->roletype & GR_ROLE_PERSIST))) {
63388+ id = current->acl_role_id;
63389+ rolename = current->role->rolename;
63390+ gr_set_acls(1);
63391+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
63392+ }
63393+
63394+ gr_put_exec_file(current);
63395+ return;
63396+}
63397+
63398+int
63399+gr_acl_handle_procpidmem(const struct task_struct *task)
63400+{
63401+ if (unlikely(!gr_acl_is_enabled()))
63402+ return 0;
63403+
63404+ if (task != current && task->acl->mode & GR_PROTPROCFD)
63405+ return -EACCES;
63406+
63407+ return 0;
63408+}
63409diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
63410new file mode 100644
63411index 0000000..8132048
63412--- /dev/null
63413+++ b/grsecurity/gracl_ip.c
63414@@ -0,0 +1,387 @@
63415+#include <linux/kernel.h>
63416+#include <asm/uaccess.h>
63417+#include <asm/errno.h>
63418+#include <net/sock.h>
63419+#include <linux/file.h>
63420+#include <linux/fs.h>
63421+#include <linux/net.h>
63422+#include <linux/in.h>
63423+#include <linux/skbuff.h>
63424+#include <linux/ip.h>
63425+#include <linux/udp.h>
63426+#include <linux/types.h>
63427+#include <linux/sched.h>
63428+#include <linux/netdevice.h>
63429+#include <linux/inetdevice.h>
63430+#include <linux/gracl.h>
63431+#include <linux/grsecurity.h>
63432+#include <linux/grinternal.h>
63433+
63434+#define GR_BIND 0x01
63435+#define GR_CONNECT 0x02
63436+#define GR_INVERT 0x04
63437+#define GR_BINDOVERRIDE 0x08
63438+#define GR_CONNECTOVERRIDE 0x10
63439+#define GR_SOCK_FAMILY 0x20
63440+
63441+static const char * gr_protocols[IPPROTO_MAX] = {
63442+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
63443+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
63444+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
63445+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
63446+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
63447+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
63448+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
63449+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
63450+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
63451+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
63452+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
63453+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
63454+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
63455+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
63456+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
63457+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
63458+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
63459+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
63460+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
63461+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
63462+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
63463+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
63464+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
63465+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
63466+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
63467+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
63468+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
63469+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
63470+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
63471+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
63472+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
63473+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
63474+ };
63475+
63476+static const char * gr_socktypes[SOCK_MAX] = {
63477+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
63478+ "unknown:7", "unknown:8", "unknown:9", "packet"
63479+ };
63480+
63481+static const char * gr_sockfamilies[AF_MAX+1] = {
63482+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
63483+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
63484+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
63485+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
63486+ };
63487+
63488+const char *
63489+gr_proto_to_name(unsigned char proto)
63490+{
63491+ return gr_protocols[proto];
63492+}
63493+
63494+const char *
63495+gr_socktype_to_name(unsigned char type)
63496+{
63497+ return gr_socktypes[type];
63498+}
63499+
63500+const char *
63501+gr_sockfamily_to_name(unsigned char family)
63502+{
63503+ return gr_sockfamilies[family];
63504+}
63505+
63506+int
63507+gr_search_socket(const int domain, const int type, const int protocol)
63508+{
63509+ struct acl_subject_label *curr;
63510+ const struct cred *cred = current_cred();
63511+
63512+ if (unlikely(!gr_acl_is_enabled()))
63513+ goto exit;
63514+
63515+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
63516+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
63517+ goto exit; // let the kernel handle it
63518+
63519+ curr = current->acl;
63520+
63521+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
63522+ /* the family is allowed, if this is PF_INET allow it only if
63523+ the extra sock type/protocol checks pass */
63524+ if (domain == PF_INET)
63525+ goto inet_check;
63526+ goto exit;
63527+ } else {
63528+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
63529+ __u32 fakeip = 0;
63530+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63531+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63532+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63533+ gr_to_filename(current->exec_file->f_path.dentry,
63534+ current->exec_file->f_path.mnt) :
63535+ curr->filename, curr->filename,
63536+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
63537+ &current->signal->saved_ip);
63538+ goto exit;
63539+ }
63540+ goto exit_fail;
63541+ }
63542+
63543+inet_check:
63544+ /* the rest of this checking is for IPv4 only */
63545+ if (!curr->ips)
63546+ goto exit;
63547+
63548+ if ((curr->ip_type & (1U << type)) &&
63549+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
63550+ goto exit;
63551+
63552+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
63553+ /* we don't place acls on raw sockets , and sometimes
63554+ dgram/ip sockets are opened for ioctl and not
63555+ bind/connect, so we'll fake a bind learn log */
63556+ if (type == SOCK_RAW || type == SOCK_PACKET) {
63557+ __u32 fakeip = 0;
63558+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63559+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63560+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63561+ gr_to_filename(current->exec_file->f_path.dentry,
63562+ current->exec_file->f_path.mnt) :
63563+ curr->filename, curr->filename,
63564+ &fakeip, 0, type,
63565+ protocol, GR_CONNECT, &current->signal->saved_ip);
63566+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
63567+ __u32 fakeip = 0;
63568+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63569+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63570+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63571+ gr_to_filename(current->exec_file->f_path.dentry,
63572+ current->exec_file->f_path.mnt) :
63573+ curr->filename, curr->filename,
63574+ &fakeip, 0, type,
63575+ protocol, GR_BIND, &current->signal->saved_ip);
63576+ }
63577+ /* we'll log when they use connect or bind */
63578+ goto exit;
63579+ }
63580+
63581+exit_fail:
63582+ if (domain == PF_INET)
63583+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
63584+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
63585+ else
63586+#ifndef CONFIG_IPV6
63587+ if (domain != PF_INET6)
63588+#endif
63589+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
63590+ gr_socktype_to_name(type), protocol);
63591+
63592+ return 0;
63593+exit:
63594+ return 1;
63595+}
63596+
63597+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)
63598+{
63599+ if ((ip->mode & mode) &&
63600+ (ip_port >= ip->low) &&
63601+ (ip_port <= ip->high) &&
63602+ ((ntohl(ip_addr) & our_netmask) ==
63603+ (ntohl(our_addr) & our_netmask))
63604+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
63605+ && (ip->type & (1U << type))) {
63606+ if (ip->mode & GR_INVERT)
63607+ return 2; // specifically denied
63608+ else
63609+ return 1; // allowed
63610+ }
63611+
63612+ return 0; // not specifically allowed, may continue parsing
63613+}
63614+
63615+static int
63616+gr_search_connectbind(const int full_mode, struct sock *sk,
63617+ struct sockaddr_in *addr, const int type)
63618+{
63619+ char iface[IFNAMSIZ] = {0};
63620+ struct acl_subject_label *curr;
63621+ struct acl_ip_label *ip;
63622+ struct inet_sock *isk;
63623+ struct net_device *dev;
63624+ struct in_device *idev;
63625+ unsigned long i;
63626+ int ret;
63627+ int mode = full_mode & (GR_BIND | GR_CONNECT);
63628+ __u32 ip_addr = 0;
63629+ __u32 our_addr;
63630+ __u32 our_netmask;
63631+ char *p;
63632+ __u16 ip_port = 0;
63633+ const struct cred *cred = current_cred();
63634+
63635+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
63636+ return 0;
63637+
63638+ curr = current->acl;
63639+ isk = inet_sk(sk);
63640+
63641+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
63642+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
63643+ addr->sin_addr.s_addr = curr->inaddr_any_override;
63644+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
63645+ struct sockaddr_in saddr;
63646+ int err;
63647+
63648+ saddr.sin_family = AF_INET;
63649+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
63650+ saddr.sin_port = isk->inet_sport;
63651+
63652+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
63653+ if (err)
63654+ return err;
63655+
63656+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
63657+ if (err)
63658+ return err;
63659+ }
63660+
63661+ if (!curr->ips)
63662+ return 0;
63663+
63664+ ip_addr = addr->sin_addr.s_addr;
63665+ ip_port = ntohs(addr->sin_port);
63666+
63667+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
63668+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63669+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63670+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63671+ gr_to_filename(current->exec_file->f_path.dentry,
63672+ current->exec_file->f_path.mnt) :
63673+ curr->filename, curr->filename,
63674+ &ip_addr, ip_port, type,
63675+ sk->sk_protocol, mode, &current->signal->saved_ip);
63676+ return 0;
63677+ }
63678+
63679+ for (i = 0; i < curr->ip_num; i++) {
63680+ ip = *(curr->ips + i);
63681+ if (ip->iface != NULL) {
63682+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
63683+ p = strchr(iface, ':');
63684+ if (p != NULL)
63685+ *p = '\0';
63686+ dev = dev_get_by_name(sock_net(sk), iface);
63687+ if (dev == NULL)
63688+ continue;
63689+ idev = in_dev_get(dev);
63690+ if (idev == NULL) {
63691+ dev_put(dev);
63692+ continue;
63693+ }
63694+ rcu_read_lock();
63695+ for_ifa(idev) {
63696+ if (!strcmp(ip->iface, ifa->ifa_label)) {
63697+ our_addr = ifa->ifa_address;
63698+ our_netmask = 0xffffffff;
63699+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
63700+ if (ret == 1) {
63701+ rcu_read_unlock();
63702+ in_dev_put(idev);
63703+ dev_put(dev);
63704+ return 0;
63705+ } else if (ret == 2) {
63706+ rcu_read_unlock();
63707+ in_dev_put(idev);
63708+ dev_put(dev);
63709+ goto denied;
63710+ }
63711+ }
63712+ } endfor_ifa(idev);
63713+ rcu_read_unlock();
63714+ in_dev_put(idev);
63715+ dev_put(dev);
63716+ } else {
63717+ our_addr = ip->addr;
63718+ our_netmask = ip->netmask;
63719+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
63720+ if (ret == 1)
63721+ return 0;
63722+ else if (ret == 2)
63723+ goto denied;
63724+ }
63725+ }
63726+
63727+denied:
63728+ if (mode == GR_BIND)
63729+ 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));
63730+ else if (mode == GR_CONNECT)
63731+ 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));
63732+
63733+ return -EACCES;
63734+}
63735+
63736+int
63737+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
63738+{
63739+ /* always allow disconnection of dgram sockets with connect */
63740+ if (addr->sin_family == AF_UNSPEC)
63741+ return 0;
63742+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
63743+}
63744+
63745+int
63746+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
63747+{
63748+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
63749+}
63750+
63751+int gr_search_listen(struct socket *sock)
63752+{
63753+ struct sock *sk = sock->sk;
63754+ struct sockaddr_in addr;
63755+
63756+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
63757+ addr.sin_port = inet_sk(sk)->inet_sport;
63758+
63759+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
63760+}
63761+
63762+int gr_search_accept(struct socket *sock)
63763+{
63764+ struct sock *sk = sock->sk;
63765+ struct sockaddr_in addr;
63766+
63767+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
63768+ addr.sin_port = inet_sk(sk)->inet_sport;
63769+
63770+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
63771+}
63772+
63773+int
63774+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
63775+{
63776+ if (addr)
63777+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
63778+ else {
63779+ struct sockaddr_in sin;
63780+ const struct inet_sock *inet = inet_sk(sk);
63781+
63782+ sin.sin_addr.s_addr = inet->inet_daddr;
63783+ sin.sin_port = inet->inet_dport;
63784+
63785+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
63786+ }
63787+}
63788+
63789+int
63790+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
63791+{
63792+ struct sockaddr_in sin;
63793+
63794+ if (unlikely(skb->len < sizeof (struct udphdr)))
63795+ return 0; // skip this packet
63796+
63797+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
63798+ sin.sin_port = udp_hdr(skb)->source;
63799+
63800+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
63801+}
63802diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
63803new file mode 100644
63804index 0000000..25f54ef
63805--- /dev/null
63806+++ b/grsecurity/gracl_learn.c
63807@@ -0,0 +1,207 @@
63808+#include <linux/kernel.h>
63809+#include <linux/mm.h>
63810+#include <linux/sched.h>
63811+#include <linux/poll.h>
63812+#include <linux/string.h>
63813+#include <linux/file.h>
63814+#include <linux/types.h>
63815+#include <linux/vmalloc.h>
63816+#include <linux/grinternal.h>
63817+
63818+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
63819+ size_t count, loff_t *ppos);
63820+extern int gr_acl_is_enabled(void);
63821+
63822+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
63823+static int gr_learn_attached;
63824+
63825+/* use a 512k buffer */
63826+#define LEARN_BUFFER_SIZE (512 * 1024)
63827+
63828+static DEFINE_SPINLOCK(gr_learn_lock);
63829+static DEFINE_MUTEX(gr_learn_user_mutex);
63830+
63831+/* we need to maintain two buffers, so that the kernel context of grlearn
63832+ uses a semaphore around the userspace copying, and the other kernel contexts
63833+ use a spinlock when copying into the buffer, since they cannot sleep
63834+*/
63835+static char *learn_buffer;
63836+static char *learn_buffer_user;
63837+static int learn_buffer_len;
63838+static int learn_buffer_user_len;
63839+
63840+static ssize_t
63841+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
63842+{
63843+ DECLARE_WAITQUEUE(wait, current);
63844+ ssize_t retval = 0;
63845+
63846+ add_wait_queue(&learn_wait, &wait);
63847+ set_current_state(TASK_INTERRUPTIBLE);
63848+ do {
63849+ mutex_lock(&gr_learn_user_mutex);
63850+ spin_lock(&gr_learn_lock);
63851+ if (learn_buffer_len)
63852+ break;
63853+ spin_unlock(&gr_learn_lock);
63854+ mutex_unlock(&gr_learn_user_mutex);
63855+ if (file->f_flags & O_NONBLOCK) {
63856+ retval = -EAGAIN;
63857+ goto out;
63858+ }
63859+ if (signal_pending(current)) {
63860+ retval = -ERESTARTSYS;
63861+ goto out;
63862+ }
63863+
63864+ schedule();
63865+ } while (1);
63866+
63867+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
63868+ learn_buffer_user_len = learn_buffer_len;
63869+ retval = learn_buffer_len;
63870+ learn_buffer_len = 0;
63871+
63872+ spin_unlock(&gr_learn_lock);
63873+
63874+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
63875+ retval = -EFAULT;
63876+
63877+ mutex_unlock(&gr_learn_user_mutex);
63878+out:
63879+ set_current_state(TASK_RUNNING);
63880+ remove_wait_queue(&learn_wait, &wait);
63881+ return retval;
63882+}
63883+
63884+static unsigned int
63885+poll_learn(struct file * file, poll_table * wait)
63886+{
63887+ poll_wait(file, &learn_wait, wait);
63888+
63889+ if (learn_buffer_len)
63890+ return (POLLIN | POLLRDNORM);
63891+
63892+ return 0;
63893+}
63894+
63895+void
63896+gr_clear_learn_entries(void)
63897+{
63898+ char *tmp;
63899+
63900+ mutex_lock(&gr_learn_user_mutex);
63901+ spin_lock(&gr_learn_lock);
63902+ tmp = learn_buffer;
63903+ learn_buffer = NULL;
63904+ spin_unlock(&gr_learn_lock);
63905+ if (tmp)
63906+ vfree(tmp);
63907+ if (learn_buffer_user != NULL) {
63908+ vfree(learn_buffer_user);
63909+ learn_buffer_user = NULL;
63910+ }
63911+ learn_buffer_len = 0;
63912+ mutex_unlock(&gr_learn_user_mutex);
63913+
63914+ return;
63915+}
63916+
63917+void
63918+gr_add_learn_entry(const char *fmt, ...)
63919+{
63920+ va_list args;
63921+ unsigned int len;
63922+
63923+ if (!gr_learn_attached)
63924+ return;
63925+
63926+ spin_lock(&gr_learn_lock);
63927+
63928+ /* leave a gap at the end so we know when it's "full" but don't have to
63929+ compute the exact length of the string we're trying to append
63930+ */
63931+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
63932+ spin_unlock(&gr_learn_lock);
63933+ wake_up_interruptible(&learn_wait);
63934+ return;
63935+ }
63936+ if (learn_buffer == NULL) {
63937+ spin_unlock(&gr_learn_lock);
63938+ return;
63939+ }
63940+
63941+ va_start(args, fmt);
63942+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
63943+ va_end(args);
63944+
63945+ learn_buffer_len += len + 1;
63946+
63947+ spin_unlock(&gr_learn_lock);
63948+ wake_up_interruptible(&learn_wait);
63949+
63950+ return;
63951+}
63952+
63953+static int
63954+open_learn(struct inode *inode, struct file *file)
63955+{
63956+ if (file->f_mode & FMODE_READ && gr_learn_attached)
63957+ return -EBUSY;
63958+ if (file->f_mode & FMODE_READ) {
63959+ int retval = 0;
63960+ mutex_lock(&gr_learn_user_mutex);
63961+ if (learn_buffer == NULL)
63962+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
63963+ if (learn_buffer_user == NULL)
63964+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
63965+ if (learn_buffer == NULL) {
63966+ retval = -ENOMEM;
63967+ goto out_error;
63968+ }
63969+ if (learn_buffer_user == NULL) {
63970+ retval = -ENOMEM;
63971+ goto out_error;
63972+ }
63973+ learn_buffer_len = 0;
63974+ learn_buffer_user_len = 0;
63975+ gr_learn_attached = 1;
63976+out_error:
63977+ mutex_unlock(&gr_learn_user_mutex);
63978+ return retval;
63979+ }
63980+ return 0;
63981+}
63982+
63983+static int
63984+close_learn(struct inode *inode, struct file *file)
63985+{
63986+ if (file->f_mode & FMODE_READ) {
63987+ char *tmp = NULL;
63988+ mutex_lock(&gr_learn_user_mutex);
63989+ spin_lock(&gr_learn_lock);
63990+ tmp = learn_buffer;
63991+ learn_buffer = NULL;
63992+ spin_unlock(&gr_learn_lock);
63993+ if (tmp)
63994+ vfree(tmp);
63995+ if (learn_buffer_user != NULL) {
63996+ vfree(learn_buffer_user);
63997+ learn_buffer_user = NULL;
63998+ }
63999+ learn_buffer_len = 0;
64000+ learn_buffer_user_len = 0;
64001+ gr_learn_attached = 0;
64002+ mutex_unlock(&gr_learn_user_mutex);
64003+ }
64004+
64005+ return 0;
64006+}
64007+
64008+const struct file_operations grsec_fops = {
64009+ .read = read_learn,
64010+ .write = write_grsec_handler,
64011+ .open = open_learn,
64012+ .release = close_learn,
64013+ .poll = poll_learn,
64014+};
64015diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
64016new file mode 100644
64017index 0000000..39645c9
64018--- /dev/null
64019+++ b/grsecurity/gracl_res.c
64020@@ -0,0 +1,68 @@
64021+#include <linux/kernel.h>
64022+#include <linux/sched.h>
64023+#include <linux/gracl.h>
64024+#include <linux/grinternal.h>
64025+
64026+static const char *restab_log[] = {
64027+ [RLIMIT_CPU] = "RLIMIT_CPU",
64028+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
64029+ [RLIMIT_DATA] = "RLIMIT_DATA",
64030+ [RLIMIT_STACK] = "RLIMIT_STACK",
64031+ [RLIMIT_CORE] = "RLIMIT_CORE",
64032+ [RLIMIT_RSS] = "RLIMIT_RSS",
64033+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
64034+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
64035+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
64036+ [RLIMIT_AS] = "RLIMIT_AS",
64037+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
64038+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
64039+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
64040+ [RLIMIT_NICE] = "RLIMIT_NICE",
64041+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
64042+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
64043+ [GR_CRASH_RES] = "RLIMIT_CRASH"
64044+};
64045+
64046+void
64047+gr_log_resource(const struct task_struct *task,
64048+ const int res, const unsigned long wanted, const int gt)
64049+{
64050+ const struct cred *cred;
64051+ unsigned long rlim;
64052+
64053+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
64054+ return;
64055+
64056+ // not yet supported resource
64057+ if (unlikely(!restab_log[res]))
64058+ return;
64059+
64060+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
64061+ rlim = task_rlimit_max(task, res);
64062+ else
64063+ rlim = task_rlimit(task, res);
64064+
64065+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
64066+ return;
64067+
64068+ rcu_read_lock();
64069+ cred = __task_cred(task);
64070+
64071+ if (res == RLIMIT_NPROC &&
64072+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
64073+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
64074+ goto out_rcu_unlock;
64075+ else if (res == RLIMIT_MEMLOCK &&
64076+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
64077+ goto out_rcu_unlock;
64078+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
64079+ goto out_rcu_unlock;
64080+ rcu_read_unlock();
64081+
64082+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
64083+
64084+ return;
64085+out_rcu_unlock:
64086+ rcu_read_unlock();
64087+ return;
64088+}
64089diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
64090new file mode 100644
64091index 0000000..cb1e5ab
64092--- /dev/null
64093+++ b/grsecurity/gracl_segv.c
64094@@ -0,0 +1,303 @@
64095+#include <linux/kernel.h>
64096+#include <linux/mm.h>
64097+#include <asm/uaccess.h>
64098+#include <asm/errno.h>
64099+#include <asm/mman.h>
64100+#include <net/sock.h>
64101+#include <linux/file.h>
64102+#include <linux/fs.h>
64103+#include <linux/net.h>
64104+#include <linux/in.h>
64105+#include <linux/slab.h>
64106+#include <linux/types.h>
64107+#include <linux/sched.h>
64108+#include <linux/timer.h>
64109+#include <linux/gracl.h>
64110+#include <linux/grsecurity.h>
64111+#include <linux/grinternal.h>
64112+
64113+static struct crash_uid *uid_set;
64114+static unsigned short uid_used;
64115+static DEFINE_SPINLOCK(gr_uid_lock);
64116+extern rwlock_t gr_inode_lock;
64117+extern struct acl_subject_label *
64118+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
64119+ struct acl_role_label *role);
64120+
64121+#ifdef CONFIG_BTRFS_FS
64122+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
64123+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
64124+#endif
64125+
64126+static inline dev_t __get_dev(const struct dentry *dentry)
64127+{
64128+#ifdef CONFIG_BTRFS_FS
64129+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
64130+ return get_btrfs_dev_from_inode(dentry->d_inode);
64131+ else
64132+#endif
64133+ return dentry->d_inode->i_sb->s_dev;
64134+}
64135+
64136+int
64137+gr_init_uidset(void)
64138+{
64139+ uid_set =
64140+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
64141+ uid_used = 0;
64142+
64143+ return uid_set ? 1 : 0;
64144+}
64145+
64146+void
64147+gr_free_uidset(void)
64148+{
64149+ if (uid_set)
64150+ kfree(uid_set);
64151+
64152+ return;
64153+}
64154+
64155+int
64156+gr_find_uid(const uid_t uid)
64157+{
64158+ struct crash_uid *tmp = uid_set;
64159+ uid_t buid;
64160+ int low = 0, high = uid_used - 1, mid;
64161+
64162+ while (high >= low) {
64163+ mid = (low + high) >> 1;
64164+ buid = tmp[mid].uid;
64165+ if (buid == uid)
64166+ return mid;
64167+ if (buid > uid)
64168+ high = mid - 1;
64169+ if (buid < uid)
64170+ low = mid + 1;
64171+ }
64172+
64173+ return -1;
64174+}
64175+
64176+static __inline__ void
64177+gr_insertsort(void)
64178+{
64179+ unsigned short i, j;
64180+ struct crash_uid index;
64181+
64182+ for (i = 1; i < uid_used; i++) {
64183+ index = uid_set[i];
64184+ j = i;
64185+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
64186+ uid_set[j] = uid_set[j - 1];
64187+ j--;
64188+ }
64189+ uid_set[j] = index;
64190+ }
64191+
64192+ return;
64193+}
64194+
64195+static __inline__ void
64196+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
64197+{
64198+ int loc;
64199+ uid_t uid = GR_GLOBAL_UID(kuid);
64200+
64201+ if (uid_used == GR_UIDTABLE_MAX)
64202+ return;
64203+
64204+ loc = gr_find_uid(uid);
64205+
64206+ if (loc >= 0) {
64207+ uid_set[loc].expires = expires;
64208+ return;
64209+ }
64210+
64211+ uid_set[uid_used].uid = uid;
64212+ uid_set[uid_used].expires = expires;
64213+ uid_used++;
64214+
64215+ gr_insertsort();
64216+
64217+ return;
64218+}
64219+
64220+void
64221+gr_remove_uid(const unsigned short loc)
64222+{
64223+ unsigned short i;
64224+
64225+ for (i = loc + 1; i < uid_used; i++)
64226+ uid_set[i - 1] = uid_set[i];
64227+
64228+ uid_used--;
64229+
64230+ return;
64231+}
64232+
64233+int
64234+gr_check_crash_uid(const kuid_t kuid)
64235+{
64236+ int loc;
64237+ int ret = 0;
64238+ uid_t uid;
64239+
64240+ if (unlikely(!gr_acl_is_enabled()))
64241+ return 0;
64242+
64243+ uid = GR_GLOBAL_UID(kuid);
64244+
64245+ spin_lock(&gr_uid_lock);
64246+ loc = gr_find_uid(uid);
64247+
64248+ if (loc < 0)
64249+ goto out_unlock;
64250+
64251+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
64252+ gr_remove_uid(loc);
64253+ else
64254+ ret = 1;
64255+
64256+out_unlock:
64257+ spin_unlock(&gr_uid_lock);
64258+ return ret;
64259+}
64260+
64261+static __inline__ int
64262+proc_is_setxid(const struct cred *cred)
64263+{
64264+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
64265+ !uid_eq(cred->uid, cred->fsuid))
64266+ return 1;
64267+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
64268+ !gid_eq(cred->gid, cred->fsgid))
64269+ return 1;
64270+
64271+ return 0;
64272+}
64273+
64274+extern int gr_fake_force_sig(int sig, struct task_struct *t);
64275+
64276+void
64277+gr_handle_crash(struct task_struct *task, const int sig)
64278+{
64279+ struct acl_subject_label *curr;
64280+ struct task_struct *tsk, *tsk2;
64281+ const struct cred *cred;
64282+ const struct cred *cred2;
64283+
64284+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
64285+ return;
64286+
64287+ if (unlikely(!gr_acl_is_enabled()))
64288+ return;
64289+
64290+ curr = task->acl;
64291+
64292+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
64293+ return;
64294+
64295+ if (time_before_eq(curr->expires, get_seconds())) {
64296+ curr->expires = 0;
64297+ curr->crashes = 0;
64298+ }
64299+
64300+ curr->crashes++;
64301+
64302+ if (!curr->expires)
64303+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
64304+
64305+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
64306+ time_after(curr->expires, get_seconds())) {
64307+ rcu_read_lock();
64308+ cred = __task_cred(task);
64309+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
64310+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
64311+ spin_lock(&gr_uid_lock);
64312+ gr_insert_uid(cred->uid, curr->expires);
64313+ spin_unlock(&gr_uid_lock);
64314+ curr->expires = 0;
64315+ curr->crashes = 0;
64316+ read_lock(&tasklist_lock);
64317+ do_each_thread(tsk2, tsk) {
64318+ cred2 = __task_cred(tsk);
64319+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
64320+ gr_fake_force_sig(SIGKILL, tsk);
64321+ } while_each_thread(tsk2, tsk);
64322+ read_unlock(&tasklist_lock);
64323+ } else {
64324+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
64325+ read_lock(&tasklist_lock);
64326+ read_lock(&grsec_exec_file_lock);
64327+ do_each_thread(tsk2, tsk) {
64328+ if (likely(tsk != task)) {
64329+ // if this thread has the same subject as the one that triggered
64330+ // RES_CRASH and it's the same binary, kill it
64331+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
64332+ gr_fake_force_sig(SIGKILL, tsk);
64333+ }
64334+ } while_each_thread(tsk2, tsk);
64335+ read_unlock(&grsec_exec_file_lock);
64336+ read_unlock(&tasklist_lock);
64337+ }
64338+ rcu_read_unlock();
64339+ }
64340+
64341+ return;
64342+}
64343+
64344+int
64345+gr_check_crash_exec(const struct file *filp)
64346+{
64347+ struct acl_subject_label *curr;
64348+
64349+ if (unlikely(!gr_acl_is_enabled()))
64350+ return 0;
64351+
64352+ read_lock(&gr_inode_lock);
64353+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
64354+ __get_dev(filp->f_path.dentry),
64355+ current->role);
64356+ read_unlock(&gr_inode_lock);
64357+
64358+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
64359+ (!curr->crashes && !curr->expires))
64360+ return 0;
64361+
64362+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
64363+ time_after(curr->expires, get_seconds()))
64364+ return 1;
64365+ else if (time_before_eq(curr->expires, get_seconds())) {
64366+ curr->crashes = 0;
64367+ curr->expires = 0;
64368+ }
64369+
64370+ return 0;
64371+}
64372+
64373+void
64374+gr_handle_alertkill(struct task_struct *task)
64375+{
64376+ struct acl_subject_label *curracl;
64377+ __u32 curr_ip;
64378+ struct task_struct *p, *p2;
64379+
64380+ if (unlikely(!gr_acl_is_enabled()))
64381+ return;
64382+
64383+ curracl = task->acl;
64384+ curr_ip = task->signal->curr_ip;
64385+
64386+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
64387+ read_lock(&tasklist_lock);
64388+ do_each_thread(p2, p) {
64389+ if (p->signal->curr_ip == curr_ip)
64390+ gr_fake_force_sig(SIGKILL, p);
64391+ } while_each_thread(p2, p);
64392+ read_unlock(&tasklist_lock);
64393+ } else if (curracl->mode & GR_KILLPROC)
64394+ gr_fake_force_sig(SIGKILL, task);
64395+
64396+ return;
64397+}
64398diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
64399new file mode 100644
64400index 0000000..98011b0
64401--- /dev/null
64402+++ b/grsecurity/gracl_shm.c
64403@@ -0,0 +1,40 @@
64404+#include <linux/kernel.h>
64405+#include <linux/mm.h>
64406+#include <linux/sched.h>
64407+#include <linux/file.h>
64408+#include <linux/ipc.h>
64409+#include <linux/gracl.h>
64410+#include <linux/grsecurity.h>
64411+#include <linux/grinternal.h>
64412+
64413+int
64414+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64415+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
64416+{
64417+ struct task_struct *task;
64418+
64419+ if (!gr_acl_is_enabled())
64420+ return 1;
64421+
64422+ rcu_read_lock();
64423+ read_lock(&tasklist_lock);
64424+
64425+ task = find_task_by_vpid(shm_cprid);
64426+
64427+ if (unlikely(!task))
64428+ task = find_task_by_vpid(shm_lapid);
64429+
64430+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
64431+ (task_pid_nr(task) == shm_lapid)) &&
64432+ (task->acl->mode & GR_PROTSHM) &&
64433+ (task->acl != current->acl))) {
64434+ read_unlock(&tasklist_lock);
64435+ rcu_read_unlock();
64436+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
64437+ return 0;
64438+ }
64439+ read_unlock(&tasklist_lock);
64440+ rcu_read_unlock();
64441+
64442+ return 1;
64443+}
64444diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
64445new file mode 100644
64446index 0000000..bc0be01
64447--- /dev/null
64448+++ b/grsecurity/grsec_chdir.c
64449@@ -0,0 +1,19 @@
64450+#include <linux/kernel.h>
64451+#include <linux/sched.h>
64452+#include <linux/fs.h>
64453+#include <linux/file.h>
64454+#include <linux/grsecurity.h>
64455+#include <linux/grinternal.h>
64456+
64457+void
64458+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
64459+{
64460+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
64461+ if ((grsec_enable_chdir && grsec_enable_group &&
64462+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
64463+ !grsec_enable_group)) {
64464+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
64465+ }
64466+#endif
64467+ return;
64468+}
64469diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
64470new file mode 100644
64471index 0000000..6d2de57
64472--- /dev/null
64473+++ b/grsecurity/grsec_chroot.c
64474@@ -0,0 +1,357 @@
64475+#include <linux/kernel.h>
64476+#include <linux/module.h>
64477+#include <linux/sched.h>
64478+#include <linux/file.h>
64479+#include <linux/fs.h>
64480+#include <linux/mount.h>
64481+#include <linux/types.h>
64482+#include "../fs/mount.h"
64483+#include <linux/grsecurity.h>
64484+#include <linux/grinternal.h>
64485+
64486+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
64487+{
64488+#ifdef CONFIG_GRKERNSEC
64489+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
64490+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
64491+ task->gr_is_chrooted = 1;
64492+ else
64493+ task->gr_is_chrooted = 0;
64494+
64495+ task->gr_chroot_dentry = path->dentry;
64496+#endif
64497+ return;
64498+}
64499+
64500+void gr_clear_chroot_entries(struct task_struct *task)
64501+{
64502+#ifdef CONFIG_GRKERNSEC
64503+ task->gr_is_chrooted = 0;
64504+ task->gr_chroot_dentry = NULL;
64505+#endif
64506+ return;
64507+}
64508+
64509+int
64510+gr_handle_chroot_unix(const pid_t pid)
64511+{
64512+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
64513+ struct task_struct *p;
64514+
64515+ if (unlikely(!grsec_enable_chroot_unix))
64516+ return 1;
64517+
64518+ if (likely(!proc_is_chrooted(current)))
64519+ return 1;
64520+
64521+ rcu_read_lock();
64522+ read_lock(&tasklist_lock);
64523+ p = find_task_by_vpid_unrestricted(pid);
64524+ if (unlikely(p && !have_same_root(current, p))) {
64525+ read_unlock(&tasklist_lock);
64526+ rcu_read_unlock();
64527+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
64528+ return 0;
64529+ }
64530+ read_unlock(&tasklist_lock);
64531+ rcu_read_unlock();
64532+#endif
64533+ return 1;
64534+}
64535+
64536+int
64537+gr_handle_chroot_nice(void)
64538+{
64539+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
64540+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
64541+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
64542+ return -EPERM;
64543+ }
64544+#endif
64545+ return 0;
64546+}
64547+
64548+int
64549+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
64550+{
64551+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
64552+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
64553+ && proc_is_chrooted(current)) {
64554+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
64555+ return -EACCES;
64556+ }
64557+#endif
64558+ return 0;
64559+}
64560+
64561+int
64562+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
64563+{
64564+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64565+ struct task_struct *p;
64566+ int ret = 0;
64567+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
64568+ return ret;
64569+
64570+ read_lock(&tasklist_lock);
64571+ do_each_pid_task(pid, type, p) {
64572+ if (!have_same_root(current, p)) {
64573+ ret = 1;
64574+ goto out;
64575+ }
64576+ } while_each_pid_task(pid, type, p);
64577+out:
64578+ read_unlock(&tasklist_lock);
64579+ return ret;
64580+#endif
64581+ return 0;
64582+}
64583+
64584+int
64585+gr_pid_is_chrooted(struct task_struct *p)
64586+{
64587+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64588+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
64589+ return 0;
64590+
64591+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
64592+ !have_same_root(current, p)) {
64593+ return 1;
64594+ }
64595+#endif
64596+ return 0;
64597+}
64598+
64599+EXPORT_SYMBOL(gr_pid_is_chrooted);
64600+
64601+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
64602+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
64603+{
64604+ struct path path, currentroot;
64605+ int ret = 0;
64606+
64607+ path.dentry = (struct dentry *)u_dentry;
64608+ path.mnt = (struct vfsmount *)u_mnt;
64609+ get_fs_root(current->fs, &currentroot);
64610+ if (path_is_under(&path, &currentroot))
64611+ ret = 1;
64612+ path_put(&currentroot);
64613+
64614+ return ret;
64615+}
64616+#endif
64617+
64618+int
64619+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
64620+{
64621+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
64622+ if (!grsec_enable_chroot_fchdir)
64623+ return 1;
64624+
64625+ if (!proc_is_chrooted(current))
64626+ return 1;
64627+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
64628+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
64629+ return 0;
64630+ }
64631+#endif
64632+ return 1;
64633+}
64634+
64635+int
64636+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64637+ const time_t shm_createtime)
64638+{
64639+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
64640+ struct task_struct *p;
64641+ time_t starttime;
64642+
64643+ if (unlikely(!grsec_enable_chroot_shmat))
64644+ return 1;
64645+
64646+ if (likely(!proc_is_chrooted(current)))
64647+ return 1;
64648+
64649+ rcu_read_lock();
64650+ read_lock(&tasklist_lock);
64651+
64652+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
64653+ starttime = p->start_time.tv_sec;
64654+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
64655+ if (have_same_root(current, p)) {
64656+ goto allow;
64657+ } else {
64658+ read_unlock(&tasklist_lock);
64659+ rcu_read_unlock();
64660+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
64661+ return 0;
64662+ }
64663+ }
64664+ /* creator exited, pid reuse, fall through to next check */
64665+ }
64666+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
64667+ if (unlikely(!have_same_root(current, p))) {
64668+ read_unlock(&tasklist_lock);
64669+ rcu_read_unlock();
64670+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
64671+ return 0;
64672+ }
64673+ }
64674+
64675+allow:
64676+ read_unlock(&tasklist_lock);
64677+ rcu_read_unlock();
64678+#endif
64679+ return 1;
64680+}
64681+
64682+void
64683+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
64684+{
64685+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
64686+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
64687+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
64688+#endif
64689+ return;
64690+}
64691+
64692+int
64693+gr_handle_chroot_mknod(const struct dentry *dentry,
64694+ const struct vfsmount *mnt, const int mode)
64695+{
64696+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
64697+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
64698+ proc_is_chrooted(current)) {
64699+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
64700+ return -EPERM;
64701+ }
64702+#endif
64703+ return 0;
64704+}
64705+
64706+int
64707+gr_handle_chroot_mount(const struct dentry *dentry,
64708+ const struct vfsmount *mnt, const char *dev_name)
64709+{
64710+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
64711+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
64712+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
64713+ return -EPERM;
64714+ }
64715+#endif
64716+ return 0;
64717+}
64718+
64719+int
64720+gr_handle_chroot_pivot(void)
64721+{
64722+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
64723+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
64724+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
64725+ return -EPERM;
64726+ }
64727+#endif
64728+ return 0;
64729+}
64730+
64731+int
64732+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
64733+{
64734+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
64735+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
64736+ !gr_is_outside_chroot(dentry, mnt)) {
64737+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
64738+ return -EPERM;
64739+ }
64740+#endif
64741+ return 0;
64742+}
64743+
64744+extern const char *captab_log[];
64745+extern int captab_log_entries;
64746+
64747+int
64748+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
64749+{
64750+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64751+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
64752+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
64753+ if (cap_raised(chroot_caps, cap)) {
64754+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
64755+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
64756+ }
64757+ return 0;
64758+ }
64759+ }
64760+#endif
64761+ return 1;
64762+}
64763+
64764+int
64765+gr_chroot_is_capable(const int cap)
64766+{
64767+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64768+ return gr_task_chroot_is_capable(current, current_cred(), cap);
64769+#endif
64770+ return 1;
64771+}
64772+
64773+int
64774+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
64775+{
64776+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64777+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
64778+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
64779+ if (cap_raised(chroot_caps, cap)) {
64780+ return 0;
64781+ }
64782+ }
64783+#endif
64784+ return 1;
64785+}
64786+
64787+int
64788+gr_chroot_is_capable_nolog(const int cap)
64789+{
64790+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64791+ return gr_task_chroot_is_capable_nolog(current, cap);
64792+#endif
64793+ return 1;
64794+}
64795+
64796+int
64797+gr_handle_chroot_sysctl(const int op)
64798+{
64799+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
64800+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
64801+ proc_is_chrooted(current))
64802+ return -EACCES;
64803+#endif
64804+ return 0;
64805+}
64806+
64807+void
64808+gr_handle_chroot_chdir(struct path *path)
64809+{
64810+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
64811+ if (grsec_enable_chroot_chdir)
64812+ set_fs_pwd(current->fs, path);
64813+#endif
64814+ return;
64815+}
64816+
64817+int
64818+gr_handle_chroot_chmod(const struct dentry *dentry,
64819+ const struct vfsmount *mnt, const int mode)
64820+{
64821+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
64822+ /* allow chmod +s on directories, but not files */
64823+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
64824+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
64825+ proc_is_chrooted(current)) {
64826+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
64827+ return -EPERM;
64828+ }
64829+#endif
64830+ return 0;
64831+}
64832diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
64833new file mode 100644
64834index 0000000..207d409
64835--- /dev/null
64836+++ b/grsecurity/grsec_disabled.c
64837@@ -0,0 +1,434 @@
64838+#include <linux/kernel.h>
64839+#include <linux/module.h>
64840+#include <linux/sched.h>
64841+#include <linux/file.h>
64842+#include <linux/fs.h>
64843+#include <linux/kdev_t.h>
64844+#include <linux/net.h>
64845+#include <linux/in.h>
64846+#include <linux/ip.h>
64847+#include <linux/skbuff.h>
64848+#include <linux/sysctl.h>
64849+
64850+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
64851+void
64852+pax_set_initial_flags(struct linux_binprm *bprm)
64853+{
64854+ return;
64855+}
64856+#endif
64857+
64858+#ifdef CONFIG_SYSCTL
64859+__u32
64860+gr_handle_sysctl(const struct ctl_table * table, const int op)
64861+{
64862+ return 0;
64863+}
64864+#endif
64865+
64866+#ifdef CONFIG_TASKSTATS
64867+int gr_is_taskstats_denied(int pid)
64868+{
64869+ return 0;
64870+}
64871+#endif
64872+
64873+int
64874+gr_acl_is_enabled(void)
64875+{
64876+ return 0;
64877+}
64878+
64879+void
64880+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
64881+{
64882+ return;
64883+}
64884+
64885+int
64886+gr_handle_rawio(const struct inode *inode)
64887+{
64888+ return 0;
64889+}
64890+
64891+void
64892+gr_acl_handle_psacct(struct task_struct *task, const long code)
64893+{
64894+ return;
64895+}
64896+
64897+int
64898+gr_handle_ptrace(struct task_struct *task, const long request)
64899+{
64900+ return 0;
64901+}
64902+
64903+int
64904+gr_handle_proc_ptrace(struct task_struct *task)
64905+{
64906+ return 0;
64907+}
64908+
64909+int
64910+gr_set_acls(const int type)
64911+{
64912+ return 0;
64913+}
64914+
64915+int
64916+gr_check_hidden_task(const struct task_struct *tsk)
64917+{
64918+ return 0;
64919+}
64920+
64921+int
64922+gr_check_protected_task(const struct task_struct *task)
64923+{
64924+ return 0;
64925+}
64926+
64927+int
64928+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
64929+{
64930+ return 0;
64931+}
64932+
64933+void
64934+gr_copy_label(struct task_struct *tsk)
64935+{
64936+ return;
64937+}
64938+
64939+void
64940+gr_set_pax_flags(struct task_struct *task)
64941+{
64942+ return;
64943+}
64944+
64945+int
64946+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
64947+ const int unsafe_share)
64948+{
64949+ return 0;
64950+}
64951+
64952+void
64953+gr_handle_delete(const ino_t ino, const dev_t dev)
64954+{
64955+ return;
64956+}
64957+
64958+void
64959+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
64960+{
64961+ return;
64962+}
64963+
64964+void
64965+gr_handle_crash(struct task_struct *task, const int sig)
64966+{
64967+ return;
64968+}
64969+
64970+int
64971+gr_check_crash_exec(const struct file *filp)
64972+{
64973+ return 0;
64974+}
64975+
64976+int
64977+gr_check_crash_uid(const kuid_t uid)
64978+{
64979+ return 0;
64980+}
64981+
64982+void
64983+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
64984+ struct dentry *old_dentry,
64985+ struct dentry *new_dentry,
64986+ struct vfsmount *mnt, const __u8 replace)
64987+{
64988+ return;
64989+}
64990+
64991+int
64992+gr_search_socket(const int family, const int type, const int protocol)
64993+{
64994+ return 1;
64995+}
64996+
64997+int
64998+gr_search_connectbind(const int mode, const struct socket *sock,
64999+ const struct sockaddr_in *addr)
65000+{
65001+ return 0;
65002+}
65003+
65004+void
65005+gr_handle_alertkill(struct task_struct *task)
65006+{
65007+ return;
65008+}
65009+
65010+__u32
65011+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
65012+{
65013+ return 1;
65014+}
65015+
65016+__u32
65017+gr_acl_handle_hidden_file(const struct dentry * dentry,
65018+ const struct vfsmount * mnt)
65019+{
65020+ return 1;
65021+}
65022+
65023+__u32
65024+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
65025+ int acc_mode)
65026+{
65027+ return 1;
65028+}
65029+
65030+__u32
65031+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
65032+{
65033+ return 1;
65034+}
65035+
65036+__u32
65037+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
65038+{
65039+ return 1;
65040+}
65041+
65042+int
65043+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
65044+ unsigned int *vm_flags)
65045+{
65046+ return 1;
65047+}
65048+
65049+__u32
65050+gr_acl_handle_truncate(const struct dentry * dentry,
65051+ const struct vfsmount * mnt)
65052+{
65053+ return 1;
65054+}
65055+
65056+__u32
65057+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
65058+{
65059+ return 1;
65060+}
65061+
65062+__u32
65063+gr_acl_handle_access(const struct dentry * dentry,
65064+ const struct vfsmount * mnt, const int fmode)
65065+{
65066+ return 1;
65067+}
65068+
65069+__u32
65070+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
65071+ umode_t *mode)
65072+{
65073+ return 1;
65074+}
65075+
65076+__u32
65077+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
65078+{
65079+ return 1;
65080+}
65081+
65082+__u32
65083+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
65084+{
65085+ return 1;
65086+}
65087+
65088+void
65089+grsecurity_init(void)
65090+{
65091+ return;
65092+}
65093+
65094+umode_t gr_acl_umask(void)
65095+{
65096+ return 0;
65097+}
65098+
65099+__u32
65100+gr_acl_handle_mknod(const struct dentry * new_dentry,
65101+ const struct dentry * parent_dentry,
65102+ const struct vfsmount * parent_mnt,
65103+ const int mode)
65104+{
65105+ return 1;
65106+}
65107+
65108+__u32
65109+gr_acl_handle_mkdir(const struct dentry * new_dentry,
65110+ const struct dentry * parent_dentry,
65111+ const struct vfsmount * parent_mnt)
65112+{
65113+ return 1;
65114+}
65115+
65116+__u32
65117+gr_acl_handle_symlink(const struct dentry * new_dentry,
65118+ const struct dentry * parent_dentry,
65119+ const struct vfsmount * parent_mnt, const struct filename *from)
65120+{
65121+ return 1;
65122+}
65123+
65124+__u32
65125+gr_acl_handle_link(const struct dentry * new_dentry,
65126+ const struct dentry * parent_dentry,
65127+ const struct vfsmount * parent_mnt,
65128+ const struct dentry * old_dentry,
65129+ const struct vfsmount * old_mnt, const struct filename *to)
65130+{
65131+ return 1;
65132+}
65133+
65134+int
65135+gr_acl_handle_rename(const struct dentry *new_dentry,
65136+ const struct dentry *parent_dentry,
65137+ const struct vfsmount *parent_mnt,
65138+ const struct dentry *old_dentry,
65139+ const struct inode *old_parent_inode,
65140+ const struct vfsmount *old_mnt, const struct filename *newname)
65141+{
65142+ return 0;
65143+}
65144+
65145+int
65146+gr_acl_handle_filldir(const struct file *file, const char *name,
65147+ const int namelen, const ino_t ino)
65148+{
65149+ return 1;
65150+}
65151+
65152+int
65153+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65154+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
65155+{
65156+ return 1;
65157+}
65158+
65159+int
65160+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
65161+{
65162+ return 0;
65163+}
65164+
65165+int
65166+gr_search_accept(const struct socket *sock)
65167+{
65168+ return 0;
65169+}
65170+
65171+int
65172+gr_search_listen(const struct socket *sock)
65173+{
65174+ return 0;
65175+}
65176+
65177+int
65178+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
65179+{
65180+ return 0;
65181+}
65182+
65183+__u32
65184+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
65185+{
65186+ return 1;
65187+}
65188+
65189+__u32
65190+gr_acl_handle_creat(const struct dentry * dentry,
65191+ const struct dentry * p_dentry,
65192+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
65193+ const int imode)
65194+{
65195+ return 1;
65196+}
65197+
65198+void
65199+gr_acl_handle_exit(void)
65200+{
65201+ return;
65202+}
65203+
65204+int
65205+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
65206+{
65207+ return 1;
65208+}
65209+
65210+void
65211+gr_set_role_label(const kuid_t uid, const kgid_t gid)
65212+{
65213+ return;
65214+}
65215+
65216+int
65217+gr_acl_handle_procpidmem(const struct task_struct *task)
65218+{
65219+ return 0;
65220+}
65221+
65222+int
65223+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
65224+{
65225+ return 0;
65226+}
65227+
65228+int
65229+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
65230+{
65231+ return 0;
65232+}
65233+
65234+void
65235+gr_set_kernel_label(struct task_struct *task)
65236+{
65237+ return;
65238+}
65239+
65240+int
65241+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
65242+{
65243+ return 0;
65244+}
65245+
65246+int
65247+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
65248+{
65249+ return 0;
65250+}
65251+
65252+int gr_acl_enable_at_secure(void)
65253+{
65254+ return 0;
65255+}
65256+
65257+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
65258+{
65259+ return dentry->d_inode->i_sb->s_dev;
65260+}
65261+
65262+void gr_put_exec_file(struct task_struct *task)
65263+{
65264+ return;
65265+}
65266+
65267+EXPORT_SYMBOL(gr_set_kernel_label);
65268+#ifdef CONFIG_SECURITY
65269+EXPORT_SYMBOL(gr_check_user_change);
65270+EXPORT_SYMBOL(gr_check_group_change);
65271+#endif
65272diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
65273new file mode 100644
65274index 0000000..387032b
65275--- /dev/null
65276+++ b/grsecurity/grsec_exec.c
65277@@ -0,0 +1,187 @@
65278+#include <linux/kernel.h>
65279+#include <linux/sched.h>
65280+#include <linux/file.h>
65281+#include <linux/binfmts.h>
65282+#include <linux/fs.h>
65283+#include <linux/types.h>
65284+#include <linux/grdefs.h>
65285+#include <linux/grsecurity.h>
65286+#include <linux/grinternal.h>
65287+#include <linux/capability.h>
65288+#include <linux/module.h>
65289+#include <linux/compat.h>
65290+
65291+#include <asm/uaccess.h>
65292+
65293+#ifdef CONFIG_GRKERNSEC_EXECLOG
65294+static char gr_exec_arg_buf[132];
65295+static DEFINE_MUTEX(gr_exec_arg_mutex);
65296+#endif
65297+
65298+struct user_arg_ptr {
65299+#ifdef CONFIG_COMPAT
65300+ bool is_compat;
65301+#endif
65302+ union {
65303+ const char __user *const __user *native;
65304+#ifdef CONFIG_COMPAT
65305+ const compat_uptr_t __user *compat;
65306+#endif
65307+ } ptr;
65308+};
65309+
65310+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
65311+
65312+void
65313+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
65314+{
65315+#ifdef CONFIG_GRKERNSEC_EXECLOG
65316+ char *grarg = gr_exec_arg_buf;
65317+ unsigned int i, x, execlen = 0;
65318+ char c;
65319+
65320+ if (!((grsec_enable_execlog && grsec_enable_group &&
65321+ in_group_p(grsec_audit_gid))
65322+ || (grsec_enable_execlog && !grsec_enable_group)))
65323+ return;
65324+
65325+ mutex_lock(&gr_exec_arg_mutex);
65326+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
65327+
65328+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
65329+ const char __user *p;
65330+ unsigned int len;
65331+
65332+ p = get_user_arg_ptr(argv, i);
65333+ if (IS_ERR(p))
65334+ goto log;
65335+
65336+ len = strnlen_user(p, 128 - execlen);
65337+ if (len > 128 - execlen)
65338+ len = 128 - execlen;
65339+ else if (len > 0)
65340+ len--;
65341+ if (copy_from_user(grarg + execlen, p, len))
65342+ goto log;
65343+
65344+ /* rewrite unprintable characters */
65345+ for (x = 0; x < len; x++) {
65346+ c = *(grarg + execlen + x);
65347+ if (c < 32 || c > 126)
65348+ *(grarg + execlen + x) = ' ';
65349+ }
65350+
65351+ execlen += len;
65352+ *(grarg + execlen) = ' ';
65353+ *(grarg + execlen + 1) = '\0';
65354+ execlen++;
65355+ }
65356+
65357+ log:
65358+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
65359+ bprm->file->f_path.mnt, grarg);
65360+ mutex_unlock(&gr_exec_arg_mutex);
65361+#endif
65362+ return;
65363+}
65364+
65365+#ifdef CONFIG_GRKERNSEC
65366+extern int gr_acl_is_capable(const int cap);
65367+extern int gr_acl_is_capable_nolog(const int cap);
65368+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
65369+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
65370+extern int gr_chroot_is_capable(const int cap);
65371+extern int gr_chroot_is_capable_nolog(const int cap);
65372+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
65373+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
65374+#endif
65375+
65376+const char *captab_log[] = {
65377+ "CAP_CHOWN",
65378+ "CAP_DAC_OVERRIDE",
65379+ "CAP_DAC_READ_SEARCH",
65380+ "CAP_FOWNER",
65381+ "CAP_FSETID",
65382+ "CAP_KILL",
65383+ "CAP_SETGID",
65384+ "CAP_SETUID",
65385+ "CAP_SETPCAP",
65386+ "CAP_LINUX_IMMUTABLE",
65387+ "CAP_NET_BIND_SERVICE",
65388+ "CAP_NET_BROADCAST",
65389+ "CAP_NET_ADMIN",
65390+ "CAP_NET_RAW",
65391+ "CAP_IPC_LOCK",
65392+ "CAP_IPC_OWNER",
65393+ "CAP_SYS_MODULE",
65394+ "CAP_SYS_RAWIO",
65395+ "CAP_SYS_CHROOT",
65396+ "CAP_SYS_PTRACE",
65397+ "CAP_SYS_PACCT",
65398+ "CAP_SYS_ADMIN",
65399+ "CAP_SYS_BOOT",
65400+ "CAP_SYS_NICE",
65401+ "CAP_SYS_RESOURCE",
65402+ "CAP_SYS_TIME",
65403+ "CAP_SYS_TTY_CONFIG",
65404+ "CAP_MKNOD",
65405+ "CAP_LEASE",
65406+ "CAP_AUDIT_WRITE",
65407+ "CAP_AUDIT_CONTROL",
65408+ "CAP_SETFCAP",
65409+ "CAP_MAC_OVERRIDE",
65410+ "CAP_MAC_ADMIN",
65411+ "CAP_SYSLOG",
65412+ "CAP_WAKE_ALARM"
65413+};
65414+
65415+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
65416+
65417+int gr_is_capable(const int cap)
65418+{
65419+#ifdef CONFIG_GRKERNSEC
65420+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
65421+ return 1;
65422+ return 0;
65423+#else
65424+ return 1;
65425+#endif
65426+}
65427+
65428+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
65429+{
65430+#ifdef CONFIG_GRKERNSEC
65431+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
65432+ return 1;
65433+ return 0;
65434+#else
65435+ return 1;
65436+#endif
65437+}
65438+
65439+int gr_is_capable_nolog(const int cap)
65440+{
65441+#ifdef CONFIG_GRKERNSEC
65442+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
65443+ return 1;
65444+ return 0;
65445+#else
65446+ return 1;
65447+#endif
65448+}
65449+
65450+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
65451+{
65452+#ifdef CONFIG_GRKERNSEC
65453+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
65454+ return 1;
65455+ return 0;
65456+#else
65457+ return 1;
65458+#endif
65459+}
65460+
65461+EXPORT_SYMBOL(gr_is_capable);
65462+EXPORT_SYMBOL(gr_is_capable_nolog);
65463+EXPORT_SYMBOL(gr_task_is_capable);
65464+EXPORT_SYMBOL(gr_task_is_capable_nolog);
65465diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
65466new file mode 100644
65467index 0000000..06cc6ea
65468--- /dev/null
65469+++ b/grsecurity/grsec_fifo.c
65470@@ -0,0 +1,24 @@
65471+#include <linux/kernel.h>
65472+#include <linux/sched.h>
65473+#include <linux/fs.h>
65474+#include <linux/file.h>
65475+#include <linux/grinternal.h>
65476+
65477+int
65478+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
65479+ const struct dentry *dir, const int flag, const int acc_mode)
65480+{
65481+#ifdef CONFIG_GRKERNSEC_FIFO
65482+ const struct cred *cred = current_cred();
65483+
65484+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
65485+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
65486+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
65487+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
65488+ if (!inode_permission(dentry->d_inode, acc_mode))
65489+ 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));
65490+ return -EACCES;
65491+ }
65492+#endif
65493+ return 0;
65494+}
65495diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
65496new file mode 100644
65497index 0000000..8ca18bf
65498--- /dev/null
65499+++ b/grsecurity/grsec_fork.c
65500@@ -0,0 +1,23 @@
65501+#include <linux/kernel.h>
65502+#include <linux/sched.h>
65503+#include <linux/grsecurity.h>
65504+#include <linux/grinternal.h>
65505+#include <linux/errno.h>
65506+
65507+void
65508+gr_log_forkfail(const int retval)
65509+{
65510+#ifdef CONFIG_GRKERNSEC_FORKFAIL
65511+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
65512+ switch (retval) {
65513+ case -EAGAIN:
65514+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
65515+ break;
65516+ case -ENOMEM:
65517+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
65518+ break;
65519+ }
65520+ }
65521+#endif
65522+ return;
65523+}
65524diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
65525new file mode 100644
65526index 0000000..a862e9f
65527--- /dev/null
65528+++ b/grsecurity/grsec_init.c
65529@@ -0,0 +1,283 @@
65530+#include <linux/kernel.h>
65531+#include <linux/sched.h>
65532+#include <linux/mm.h>
65533+#include <linux/gracl.h>
65534+#include <linux/slab.h>
65535+#include <linux/vmalloc.h>
65536+#include <linux/percpu.h>
65537+#include <linux/module.h>
65538+
65539+int grsec_enable_ptrace_readexec;
65540+int grsec_enable_setxid;
65541+int grsec_enable_symlinkown;
65542+kgid_t grsec_symlinkown_gid;
65543+int grsec_enable_brute;
65544+int grsec_enable_link;
65545+int grsec_enable_dmesg;
65546+int grsec_enable_harden_ptrace;
65547+int grsec_enable_fifo;
65548+int grsec_enable_execlog;
65549+int grsec_enable_signal;
65550+int grsec_enable_forkfail;
65551+int grsec_enable_audit_ptrace;
65552+int grsec_enable_time;
65553+int grsec_enable_audit_textrel;
65554+int grsec_enable_group;
65555+kgid_t grsec_audit_gid;
65556+int grsec_enable_chdir;
65557+int grsec_enable_mount;
65558+int grsec_enable_rofs;
65559+int grsec_enable_chroot_findtask;
65560+int grsec_enable_chroot_mount;
65561+int grsec_enable_chroot_shmat;
65562+int grsec_enable_chroot_fchdir;
65563+int grsec_enable_chroot_double;
65564+int grsec_enable_chroot_pivot;
65565+int grsec_enable_chroot_chdir;
65566+int grsec_enable_chroot_chmod;
65567+int grsec_enable_chroot_mknod;
65568+int grsec_enable_chroot_nice;
65569+int grsec_enable_chroot_execlog;
65570+int grsec_enable_chroot_caps;
65571+int grsec_enable_chroot_sysctl;
65572+int grsec_enable_chroot_unix;
65573+int grsec_enable_tpe;
65574+kgid_t grsec_tpe_gid;
65575+int grsec_enable_blackhole;
65576+#ifdef CONFIG_IPV6_MODULE
65577+EXPORT_SYMBOL(grsec_enable_blackhole);
65578+#endif
65579+int grsec_lastack_retries;
65580+int grsec_enable_tpe_all;
65581+int grsec_enable_tpe_invert;
65582+int grsec_enable_socket_all;
65583+kgid_t grsec_socket_all_gid;
65584+int grsec_enable_socket_client;
65585+kgid_t grsec_socket_client_gid;
65586+int grsec_enable_socket_server;
65587+kgid_t grsec_socket_server_gid;
65588+int grsec_resource_logging;
65589+int grsec_disable_privio;
65590+int grsec_enable_log_rwxmaps;
65591+int grsec_lock;
65592+
65593+DEFINE_SPINLOCK(grsec_alert_lock);
65594+unsigned long grsec_alert_wtime = 0;
65595+unsigned long grsec_alert_fyet = 0;
65596+
65597+DEFINE_SPINLOCK(grsec_audit_lock);
65598+
65599+DEFINE_RWLOCK(grsec_exec_file_lock);
65600+
65601+char *gr_shared_page[4];
65602+
65603+char *gr_alert_log_fmt;
65604+char *gr_audit_log_fmt;
65605+char *gr_alert_log_buf;
65606+char *gr_audit_log_buf;
65607+
65608+extern struct gr_arg *gr_usermode;
65609+extern unsigned char *gr_system_salt;
65610+extern unsigned char *gr_system_sum;
65611+
65612+void __init
65613+grsecurity_init(void)
65614+{
65615+ int j;
65616+ /* create the per-cpu shared pages */
65617+
65618+#ifdef CONFIG_X86
65619+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
65620+#endif
65621+
65622+ for (j = 0; j < 4; j++) {
65623+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
65624+ if (gr_shared_page[j] == NULL) {
65625+ panic("Unable to allocate grsecurity shared page");
65626+ return;
65627+ }
65628+ }
65629+
65630+ /* allocate log buffers */
65631+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
65632+ if (!gr_alert_log_fmt) {
65633+ panic("Unable to allocate grsecurity alert log format buffer");
65634+ return;
65635+ }
65636+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
65637+ if (!gr_audit_log_fmt) {
65638+ panic("Unable to allocate grsecurity audit log format buffer");
65639+ return;
65640+ }
65641+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
65642+ if (!gr_alert_log_buf) {
65643+ panic("Unable to allocate grsecurity alert log buffer");
65644+ return;
65645+ }
65646+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
65647+ if (!gr_audit_log_buf) {
65648+ panic("Unable to allocate grsecurity audit log buffer");
65649+ return;
65650+ }
65651+
65652+ /* allocate memory for authentication structure */
65653+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
65654+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
65655+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
65656+
65657+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
65658+ panic("Unable to allocate grsecurity authentication structure");
65659+ return;
65660+ }
65661+
65662+
65663+#ifdef CONFIG_GRKERNSEC_IO
65664+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
65665+ grsec_disable_privio = 1;
65666+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
65667+ grsec_disable_privio = 1;
65668+#else
65669+ grsec_disable_privio = 0;
65670+#endif
65671+#endif
65672+
65673+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
65674+ /* for backward compatibility, tpe_invert always defaults to on if
65675+ enabled in the kernel
65676+ */
65677+ grsec_enable_tpe_invert = 1;
65678+#endif
65679+
65680+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
65681+#ifndef CONFIG_GRKERNSEC_SYSCTL
65682+ grsec_lock = 1;
65683+#endif
65684+
65685+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
65686+ grsec_enable_audit_textrel = 1;
65687+#endif
65688+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65689+ grsec_enable_log_rwxmaps = 1;
65690+#endif
65691+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
65692+ grsec_enable_group = 1;
65693+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
65694+#endif
65695+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
65696+ grsec_enable_ptrace_readexec = 1;
65697+#endif
65698+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
65699+ grsec_enable_chdir = 1;
65700+#endif
65701+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65702+ grsec_enable_harden_ptrace = 1;
65703+#endif
65704+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65705+ grsec_enable_mount = 1;
65706+#endif
65707+#ifdef CONFIG_GRKERNSEC_LINK
65708+ grsec_enable_link = 1;
65709+#endif
65710+#ifdef CONFIG_GRKERNSEC_BRUTE
65711+ grsec_enable_brute = 1;
65712+#endif
65713+#ifdef CONFIG_GRKERNSEC_DMESG
65714+ grsec_enable_dmesg = 1;
65715+#endif
65716+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
65717+ grsec_enable_blackhole = 1;
65718+ grsec_lastack_retries = 4;
65719+#endif
65720+#ifdef CONFIG_GRKERNSEC_FIFO
65721+ grsec_enable_fifo = 1;
65722+#endif
65723+#ifdef CONFIG_GRKERNSEC_EXECLOG
65724+ grsec_enable_execlog = 1;
65725+#endif
65726+#ifdef CONFIG_GRKERNSEC_SETXID
65727+ grsec_enable_setxid = 1;
65728+#endif
65729+#ifdef CONFIG_GRKERNSEC_SIGNAL
65730+ grsec_enable_signal = 1;
65731+#endif
65732+#ifdef CONFIG_GRKERNSEC_FORKFAIL
65733+ grsec_enable_forkfail = 1;
65734+#endif
65735+#ifdef CONFIG_GRKERNSEC_TIME
65736+ grsec_enable_time = 1;
65737+#endif
65738+#ifdef CONFIG_GRKERNSEC_RESLOG
65739+ grsec_resource_logging = 1;
65740+#endif
65741+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
65742+ grsec_enable_chroot_findtask = 1;
65743+#endif
65744+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
65745+ grsec_enable_chroot_unix = 1;
65746+#endif
65747+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
65748+ grsec_enable_chroot_mount = 1;
65749+#endif
65750+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
65751+ grsec_enable_chroot_fchdir = 1;
65752+#endif
65753+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
65754+ grsec_enable_chroot_shmat = 1;
65755+#endif
65756+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
65757+ grsec_enable_audit_ptrace = 1;
65758+#endif
65759+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
65760+ grsec_enable_chroot_double = 1;
65761+#endif
65762+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
65763+ grsec_enable_chroot_pivot = 1;
65764+#endif
65765+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
65766+ grsec_enable_chroot_chdir = 1;
65767+#endif
65768+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
65769+ grsec_enable_chroot_chmod = 1;
65770+#endif
65771+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
65772+ grsec_enable_chroot_mknod = 1;
65773+#endif
65774+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
65775+ grsec_enable_chroot_nice = 1;
65776+#endif
65777+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
65778+ grsec_enable_chroot_execlog = 1;
65779+#endif
65780+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
65781+ grsec_enable_chroot_caps = 1;
65782+#endif
65783+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
65784+ grsec_enable_chroot_sysctl = 1;
65785+#endif
65786+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
65787+ grsec_enable_symlinkown = 1;
65788+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
65789+#endif
65790+#ifdef CONFIG_GRKERNSEC_TPE
65791+ grsec_enable_tpe = 1;
65792+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
65793+#ifdef CONFIG_GRKERNSEC_TPE_ALL
65794+ grsec_enable_tpe_all = 1;
65795+#endif
65796+#endif
65797+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
65798+ grsec_enable_socket_all = 1;
65799+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
65800+#endif
65801+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
65802+ grsec_enable_socket_client = 1;
65803+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
65804+#endif
65805+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
65806+ grsec_enable_socket_server = 1;
65807+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
65808+#endif
65809+#endif
65810+
65811+ return;
65812+}
65813diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
65814new file mode 100644
65815index 0000000..5e05e20
65816--- /dev/null
65817+++ b/grsecurity/grsec_link.c
65818@@ -0,0 +1,58 @@
65819+#include <linux/kernel.h>
65820+#include <linux/sched.h>
65821+#include <linux/fs.h>
65822+#include <linux/file.h>
65823+#include <linux/grinternal.h>
65824+
65825+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
65826+{
65827+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
65828+ const struct inode *link_inode = link->dentry->d_inode;
65829+
65830+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
65831+ /* ignore root-owned links, e.g. /proc/self */
65832+ gr_is_global_nonroot(link_inode->i_uid) && target &&
65833+ !uid_eq(link_inode->i_uid, target->i_uid)) {
65834+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
65835+ return 1;
65836+ }
65837+#endif
65838+ return 0;
65839+}
65840+
65841+int
65842+gr_handle_follow_link(const struct inode *parent,
65843+ const struct inode *inode,
65844+ const struct dentry *dentry, const struct vfsmount *mnt)
65845+{
65846+#ifdef CONFIG_GRKERNSEC_LINK
65847+ const struct cred *cred = current_cred();
65848+
65849+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
65850+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
65851+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
65852+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
65853+ return -EACCES;
65854+ }
65855+#endif
65856+ return 0;
65857+}
65858+
65859+int
65860+gr_handle_hardlink(const struct dentry *dentry,
65861+ const struct vfsmount *mnt,
65862+ struct inode *inode, const int mode, const struct filename *to)
65863+{
65864+#ifdef CONFIG_GRKERNSEC_LINK
65865+ const struct cred *cred = current_cred();
65866+
65867+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
65868+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
65869+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
65870+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
65871+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
65872+ return -EPERM;
65873+ }
65874+#endif
65875+ return 0;
65876+}
65877diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
65878new file mode 100644
65879index 0000000..7c06085
65880--- /dev/null
65881+++ b/grsecurity/grsec_log.c
65882@@ -0,0 +1,326 @@
65883+#include <linux/kernel.h>
65884+#include <linux/sched.h>
65885+#include <linux/file.h>
65886+#include <linux/tty.h>
65887+#include <linux/fs.h>
65888+#include <linux/grinternal.h>
65889+
65890+#ifdef CONFIG_TREE_PREEMPT_RCU
65891+#define DISABLE_PREEMPT() preempt_disable()
65892+#define ENABLE_PREEMPT() preempt_enable()
65893+#else
65894+#define DISABLE_PREEMPT()
65895+#define ENABLE_PREEMPT()
65896+#endif
65897+
65898+#define BEGIN_LOCKS(x) \
65899+ DISABLE_PREEMPT(); \
65900+ rcu_read_lock(); \
65901+ read_lock(&tasklist_lock); \
65902+ read_lock(&grsec_exec_file_lock); \
65903+ if (x != GR_DO_AUDIT) \
65904+ spin_lock(&grsec_alert_lock); \
65905+ else \
65906+ spin_lock(&grsec_audit_lock)
65907+
65908+#define END_LOCKS(x) \
65909+ if (x != GR_DO_AUDIT) \
65910+ spin_unlock(&grsec_alert_lock); \
65911+ else \
65912+ spin_unlock(&grsec_audit_lock); \
65913+ read_unlock(&grsec_exec_file_lock); \
65914+ read_unlock(&tasklist_lock); \
65915+ rcu_read_unlock(); \
65916+ ENABLE_PREEMPT(); \
65917+ if (x == GR_DONT_AUDIT) \
65918+ gr_handle_alertkill(current)
65919+
65920+enum {
65921+ FLOODING,
65922+ NO_FLOODING
65923+};
65924+
65925+extern char *gr_alert_log_fmt;
65926+extern char *gr_audit_log_fmt;
65927+extern char *gr_alert_log_buf;
65928+extern char *gr_audit_log_buf;
65929+
65930+static int gr_log_start(int audit)
65931+{
65932+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
65933+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
65934+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65935+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
65936+ unsigned long curr_secs = get_seconds();
65937+
65938+ if (audit == GR_DO_AUDIT)
65939+ goto set_fmt;
65940+
65941+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
65942+ grsec_alert_wtime = curr_secs;
65943+ grsec_alert_fyet = 0;
65944+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
65945+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
65946+ grsec_alert_fyet++;
65947+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
65948+ grsec_alert_wtime = curr_secs;
65949+ grsec_alert_fyet++;
65950+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
65951+ return FLOODING;
65952+ }
65953+ else return FLOODING;
65954+
65955+set_fmt:
65956+#endif
65957+ memset(buf, 0, PAGE_SIZE);
65958+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
65959+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
65960+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
65961+ } else if (current->signal->curr_ip) {
65962+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
65963+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
65964+ } else if (gr_acl_is_enabled()) {
65965+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
65966+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
65967+ } else {
65968+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
65969+ strcpy(buf, fmt);
65970+ }
65971+
65972+ return NO_FLOODING;
65973+}
65974+
65975+static void gr_log_middle(int audit, const char *msg, va_list ap)
65976+ __attribute__ ((format (printf, 2, 0)));
65977+
65978+static void gr_log_middle(int audit, const char *msg, va_list ap)
65979+{
65980+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65981+ unsigned int len = strlen(buf);
65982+
65983+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
65984+
65985+ return;
65986+}
65987+
65988+static void gr_log_middle_varargs(int audit, const char *msg, ...)
65989+ __attribute__ ((format (printf, 2, 3)));
65990+
65991+static void gr_log_middle_varargs(int audit, const char *msg, ...)
65992+{
65993+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65994+ unsigned int len = strlen(buf);
65995+ va_list ap;
65996+
65997+ va_start(ap, msg);
65998+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
65999+ va_end(ap);
66000+
66001+ return;
66002+}
66003+
66004+static void gr_log_end(int audit, int append_default)
66005+{
66006+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
66007+ if (append_default) {
66008+ struct task_struct *task = current;
66009+ struct task_struct *parent = task->real_parent;
66010+ const struct cred *cred = __task_cred(task);
66011+ const struct cred *pcred = __task_cred(parent);
66012+ unsigned int len = strlen(buf);
66013+
66014+ 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));
66015+ }
66016+
66017+ printk("%s\n", buf);
66018+
66019+ return;
66020+}
66021+
66022+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
66023+{
66024+ int logtype;
66025+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
66026+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
66027+ void *voidptr = NULL;
66028+ int num1 = 0, num2 = 0;
66029+ unsigned long ulong1 = 0, ulong2 = 0;
66030+ struct dentry *dentry = NULL;
66031+ struct vfsmount *mnt = NULL;
66032+ struct file *file = NULL;
66033+ struct task_struct *task = NULL;
66034+ const struct cred *cred, *pcred;
66035+ va_list ap;
66036+
66037+ BEGIN_LOCKS(audit);
66038+ logtype = gr_log_start(audit);
66039+ if (logtype == FLOODING) {
66040+ END_LOCKS(audit);
66041+ return;
66042+ }
66043+ va_start(ap, argtypes);
66044+ switch (argtypes) {
66045+ case GR_TTYSNIFF:
66046+ task = va_arg(ap, struct task_struct *);
66047+ 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));
66048+ break;
66049+ case GR_SYSCTL_HIDDEN:
66050+ str1 = va_arg(ap, char *);
66051+ gr_log_middle_varargs(audit, msg, result, str1);
66052+ break;
66053+ case GR_RBAC:
66054+ dentry = va_arg(ap, struct dentry *);
66055+ mnt = va_arg(ap, struct vfsmount *);
66056+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
66057+ break;
66058+ case GR_RBAC_STR:
66059+ dentry = va_arg(ap, struct dentry *);
66060+ mnt = va_arg(ap, struct vfsmount *);
66061+ str1 = va_arg(ap, char *);
66062+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
66063+ break;
66064+ case GR_STR_RBAC:
66065+ str1 = va_arg(ap, char *);
66066+ dentry = va_arg(ap, struct dentry *);
66067+ mnt = va_arg(ap, struct vfsmount *);
66068+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
66069+ break;
66070+ case GR_RBAC_MODE2:
66071+ dentry = va_arg(ap, struct dentry *);
66072+ mnt = va_arg(ap, struct vfsmount *);
66073+ str1 = va_arg(ap, char *);
66074+ str2 = va_arg(ap, char *);
66075+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
66076+ break;
66077+ case GR_RBAC_MODE3:
66078+ dentry = va_arg(ap, struct dentry *);
66079+ mnt = va_arg(ap, struct vfsmount *);
66080+ str1 = va_arg(ap, char *);
66081+ str2 = va_arg(ap, char *);
66082+ str3 = va_arg(ap, char *);
66083+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
66084+ break;
66085+ case GR_FILENAME:
66086+ dentry = va_arg(ap, struct dentry *);
66087+ mnt = va_arg(ap, struct vfsmount *);
66088+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
66089+ break;
66090+ case GR_STR_FILENAME:
66091+ str1 = va_arg(ap, char *);
66092+ dentry = va_arg(ap, struct dentry *);
66093+ mnt = va_arg(ap, struct vfsmount *);
66094+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
66095+ break;
66096+ case GR_FILENAME_STR:
66097+ dentry = va_arg(ap, struct dentry *);
66098+ mnt = va_arg(ap, struct vfsmount *);
66099+ str1 = va_arg(ap, char *);
66100+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
66101+ break;
66102+ case GR_FILENAME_TWO_INT:
66103+ dentry = va_arg(ap, struct dentry *);
66104+ mnt = va_arg(ap, struct vfsmount *);
66105+ num1 = va_arg(ap, int);
66106+ num2 = va_arg(ap, int);
66107+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
66108+ break;
66109+ case GR_FILENAME_TWO_INT_STR:
66110+ dentry = va_arg(ap, struct dentry *);
66111+ mnt = va_arg(ap, struct vfsmount *);
66112+ num1 = va_arg(ap, int);
66113+ num2 = va_arg(ap, int);
66114+ str1 = va_arg(ap, char *);
66115+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
66116+ break;
66117+ case GR_TEXTREL:
66118+ file = va_arg(ap, struct file *);
66119+ ulong1 = va_arg(ap, unsigned long);
66120+ ulong2 = va_arg(ap, unsigned long);
66121+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
66122+ break;
66123+ case GR_PTRACE:
66124+ task = va_arg(ap, struct task_struct *);
66125+ 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));
66126+ break;
66127+ case GR_RESOURCE:
66128+ task = va_arg(ap, struct task_struct *);
66129+ cred = __task_cred(task);
66130+ pcred = __task_cred(task->real_parent);
66131+ ulong1 = va_arg(ap, unsigned long);
66132+ str1 = va_arg(ap, char *);
66133+ ulong2 = va_arg(ap, unsigned long);
66134+ 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));
66135+ break;
66136+ case GR_CAP:
66137+ task = va_arg(ap, struct task_struct *);
66138+ cred = __task_cred(task);
66139+ pcred = __task_cred(task->real_parent);
66140+ str1 = va_arg(ap, char *);
66141+ 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));
66142+ break;
66143+ case GR_SIG:
66144+ str1 = va_arg(ap, char *);
66145+ voidptr = va_arg(ap, void *);
66146+ gr_log_middle_varargs(audit, msg, str1, voidptr);
66147+ break;
66148+ case GR_SIG2:
66149+ task = va_arg(ap, struct task_struct *);
66150+ cred = __task_cred(task);
66151+ pcred = __task_cred(task->real_parent);
66152+ num1 = va_arg(ap, int);
66153+ 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));
66154+ break;
66155+ case GR_CRASH1:
66156+ task = va_arg(ap, struct task_struct *);
66157+ cred = __task_cred(task);
66158+ pcred = __task_cred(task->real_parent);
66159+ ulong1 = va_arg(ap, unsigned long);
66160+ 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);
66161+ break;
66162+ case GR_CRASH2:
66163+ task = va_arg(ap, struct task_struct *);
66164+ cred = __task_cred(task);
66165+ pcred = __task_cred(task->real_parent);
66166+ ulong1 = va_arg(ap, unsigned long);
66167+ 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);
66168+ break;
66169+ case GR_RWXMAP:
66170+ file = va_arg(ap, struct file *);
66171+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
66172+ break;
66173+ case GR_PSACCT:
66174+ {
66175+ unsigned int wday, cday;
66176+ __u8 whr, chr;
66177+ __u8 wmin, cmin;
66178+ __u8 wsec, csec;
66179+ char cur_tty[64] = { 0 };
66180+ char parent_tty[64] = { 0 };
66181+
66182+ task = va_arg(ap, struct task_struct *);
66183+ wday = va_arg(ap, unsigned int);
66184+ cday = va_arg(ap, unsigned int);
66185+ whr = va_arg(ap, int);
66186+ chr = va_arg(ap, int);
66187+ wmin = va_arg(ap, int);
66188+ cmin = va_arg(ap, int);
66189+ wsec = va_arg(ap, int);
66190+ csec = va_arg(ap, int);
66191+ ulong1 = va_arg(ap, unsigned long);
66192+ cred = __task_cred(task);
66193+ pcred = __task_cred(task->real_parent);
66194+
66195+ 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));
66196+ }
66197+ break;
66198+ default:
66199+ gr_log_middle(audit, msg, ap);
66200+ }
66201+ va_end(ap);
66202+ // these don't need DEFAULTSECARGS printed on the end
66203+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
66204+ gr_log_end(audit, 0);
66205+ else
66206+ gr_log_end(audit, 1);
66207+ END_LOCKS(audit);
66208+}
66209diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
66210new file mode 100644
66211index 0000000..f536303
66212--- /dev/null
66213+++ b/grsecurity/grsec_mem.c
66214@@ -0,0 +1,40 @@
66215+#include <linux/kernel.h>
66216+#include <linux/sched.h>
66217+#include <linux/mm.h>
66218+#include <linux/mman.h>
66219+#include <linux/grinternal.h>
66220+
66221+void
66222+gr_handle_ioperm(void)
66223+{
66224+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
66225+ return;
66226+}
66227+
66228+void
66229+gr_handle_iopl(void)
66230+{
66231+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
66232+ return;
66233+}
66234+
66235+void
66236+gr_handle_mem_readwrite(u64 from, u64 to)
66237+{
66238+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
66239+ return;
66240+}
66241+
66242+void
66243+gr_handle_vm86(void)
66244+{
66245+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
66246+ return;
66247+}
66248+
66249+void
66250+gr_log_badprocpid(const char *entry)
66251+{
66252+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
66253+ return;
66254+}
66255diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
66256new file mode 100644
66257index 0000000..2131422
66258--- /dev/null
66259+++ b/grsecurity/grsec_mount.c
66260@@ -0,0 +1,62 @@
66261+#include <linux/kernel.h>
66262+#include <linux/sched.h>
66263+#include <linux/mount.h>
66264+#include <linux/grsecurity.h>
66265+#include <linux/grinternal.h>
66266+
66267+void
66268+gr_log_remount(const char *devname, const int retval)
66269+{
66270+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
66271+ if (grsec_enable_mount && (retval >= 0))
66272+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
66273+#endif
66274+ return;
66275+}
66276+
66277+void
66278+gr_log_unmount(const char *devname, const int retval)
66279+{
66280+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
66281+ if (grsec_enable_mount && (retval >= 0))
66282+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
66283+#endif
66284+ return;
66285+}
66286+
66287+void
66288+gr_log_mount(const char *from, const char *to, const int retval)
66289+{
66290+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
66291+ if (grsec_enable_mount && (retval >= 0))
66292+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
66293+#endif
66294+ return;
66295+}
66296+
66297+int
66298+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
66299+{
66300+#ifdef CONFIG_GRKERNSEC_ROFS
66301+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
66302+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
66303+ return -EPERM;
66304+ } else
66305+ return 0;
66306+#endif
66307+ return 0;
66308+}
66309+
66310+int
66311+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
66312+{
66313+#ifdef CONFIG_GRKERNSEC_ROFS
66314+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
66315+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
66316+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
66317+ return -EPERM;
66318+ } else
66319+ return 0;
66320+#endif
66321+ return 0;
66322+}
66323diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
66324new file mode 100644
66325index 0000000..a3b12a0
66326--- /dev/null
66327+++ b/grsecurity/grsec_pax.c
66328@@ -0,0 +1,36 @@
66329+#include <linux/kernel.h>
66330+#include <linux/sched.h>
66331+#include <linux/mm.h>
66332+#include <linux/file.h>
66333+#include <linux/grinternal.h>
66334+#include <linux/grsecurity.h>
66335+
66336+void
66337+gr_log_textrel(struct vm_area_struct * vma)
66338+{
66339+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
66340+ if (grsec_enable_audit_textrel)
66341+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
66342+#endif
66343+ return;
66344+}
66345+
66346+void
66347+gr_log_rwxmmap(struct file *file)
66348+{
66349+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
66350+ if (grsec_enable_log_rwxmaps)
66351+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
66352+#endif
66353+ return;
66354+}
66355+
66356+void
66357+gr_log_rwxmprotect(struct file *file)
66358+{
66359+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
66360+ if (grsec_enable_log_rwxmaps)
66361+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
66362+#endif
66363+ return;
66364+}
66365diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
66366new file mode 100644
66367index 0000000..f7f29aa
66368--- /dev/null
66369+++ b/grsecurity/grsec_ptrace.c
66370@@ -0,0 +1,30 @@
66371+#include <linux/kernel.h>
66372+#include <linux/sched.h>
66373+#include <linux/grinternal.h>
66374+#include <linux/security.h>
66375+
66376+void
66377+gr_audit_ptrace(struct task_struct *task)
66378+{
66379+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
66380+ if (grsec_enable_audit_ptrace)
66381+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
66382+#endif
66383+ return;
66384+}
66385+
66386+int
66387+gr_ptrace_readexec(struct file *file, int unsafe_flags)
66388+{
66389+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
66390+ const struct dentry *dentry = file->f_path.dentry;
66391+ const struct vfsmount *mnt = file->f_path.mnt;
66392+
66393+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
66394+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
66395+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
66396+ return -EACCES;
66397+ }
66398+#endif
66399+ return 0;
66400+}
66401diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
66402new file mode 100644
66403index 0000000..e09715a
66404--- /dev/null
66405+++ b/grsecurity/grsec_sig.c
66406@@ -0,0 +1,222 @@
66407+#include <linux/kernel.h>
66408+#include <linux/sched.h>
66409+#include <linux/delay.h>
66410+#include <linux/grsecurity.h>
66411+#include <linux/grinternal.h>
66412+#include <linux/hardirq.h>
66413+
66414+char *signames[] = {
66415+ [SIGSEGV] = "Segmentation fault",
66416+ [SIGILL] = "Illegal instruction",
66417+ [SIGABRT] = "Abort",
66418+ [SIGBUS] = "Invalid alignment/Bus error"
66419+};
66420+
66421+void
66422+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
66423+{
66424+#ifdef CONFIG_GRKERNSEC_SIGNAL
66425+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
66426+ (sig == SIGABRT) || (sig == SIGBUS))) {
66427+ if (task_pid_nr(t) == task_pid_nr(current)) {
66428+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
66429+ } else {
66430+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
66431+ }
66432+ }
66433+#endif
66434+ return;
66435+}
66436+
66437+int
66438+gr_handle_signal(const struct task_struct *p, const int sig)
66439+{
66440+#ifdef CONFIG_GRKERNSEC
66441+ /* ignore the 0 signal for protected task checks */
66442+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
66443+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
66444+ return -EPERM;
66445+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
66446+ return -EPERM;
66447+ }
66448+#endif
66449+ return 0;
66450+}
66451+
66452+#ifdef CONFIG_GRKERNSEC
66453+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
66454+
66455+int gr_fake_force_sig(int sig, struct task_struct *t)
66456+{
66457+ unsigned long int flags;
66458+ int ret, blocked, ignored;
66459+ struct k_sigaction *action;
66460+
66461+ spin_lock_irqsave(&t->sighand->siglock, flags);
66462+ action = &t->sighand->action[sig-1];
66463+ ignored = action->sa.sa_handler == SIG_IGN;
66464+ blocked = sigismember(&t->blocked, sig);
66465+ if (blocked || ignored) {
66466+ action->sa.sa_handler = SIG_DFL;
66467+ if (blocked) {
66468+ sigdelset(&t->blocked, sig);
66469+ recalc_sigpending_and_wake(t);
66470+ }
66471+ }
66472+ if (action->sa.sa_handler == SIG_DFL)
66473+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
66474+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
66475+
66476+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
66477+
66478+ return ret;
66479+}
66480+#endif
66481+
66482+#ifdef CONFIG_GRKERNSEC_BRUTE
66483+#define GR_USER_BAN_TIME (15 * 60)
66484+#define GR_DAEMON_BRUTE_TIME (30 * 60)
66485+
66486+static int __get_dumpable(unsigned long mm_flags)
66487+{
66488+ int ret;
66489+
66490+ ret = mm_flags & MMF_DUMPABLE_MASK;
66491+ return (ret >= 2) ? 2 : ret;
66492+}
66493+#endif
66494+
66495+void gr_handle_brute_attach(unsigned long mm_flags)
66496+{
66497+#ifdef CONFIG_GRKERNSEC_BRUTE
66498+ struct task_struct *p = current;
66499+ kuid_t uid = GLOBAL_ROOT_UID;
66500+ int daemon = 0;
66501+
66502+ if (!grsec_enable_brute)
66503+ return;
66504+
66505+ rcu_read_lock();
66506+ read_lock(&tasklist_lock);
66507+ read_lock(&grsec_exec_file_lock);
66508+ if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
66509+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
66510+ p->real_parent->brute = 1;
66511+ daemon = 1;
66512+ } else {
66513+ const struct cred *cred = __task_cred(p), *cred2;
66514+ struct task_struct *tsk, *tsk2;
66515+
66516+ if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
66517+ struct user_struct *user;
66518+
66519+ uid = cred->uid;
66520+
66521+ /* this is put upon execution past expiration */
66522+ user = find_user(uid);
66523+ if (user == NULL)
66524+ goto unlock;
66525+ user->banned = 1;
66526+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
66527+ if (user->ban_expires == ~0UL)
66528+ user->ban_expires--;
66529+
66530+ do_each_thread(tsk2, tsk) {
66531+ cred2 = __task_cred(tsk);
66532+ if (tsk != p && uid_eq(cred2->uid, uid))
66533+ gr_fake_force_sig(SIGKILL, tsk);
66534+ } while_each_thread(tsk2, tsk);
66535+ }
66536+ }
66537+unlock:
66538+ read_unlock(&grsec_exec_file_lock);
66539+ read_unlock(&tasklist_lock);
66540+ rcu_read_unlock();
66541+
66542+ if (gr_is_global_nonroot(uid))
66543+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
66544+ GR_GLOBAL_UID(uid), GR_USER_BAN_TIME / 60);
66545+ else if (daemon)
66546+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
66547+
66548+#endif
66549+ return;
66550+}
66551+
66552+void gr_handle_brute_check(void)
66553+{
66554+#ifdef CONFIG_GRKERNSEC_BRUTE
66555+ struct task_struct *p = current;
66556+
66557+ if (unlikely(p->brute)) {
66558+ if (!grsec_enable_brute)
66559+ p->brute = 0;
66560+ else if (time_before(get_seconds(), p->brute_expires))
66561+ msleep(30 * 1000);
66562+ }
66563+#endif
66564+ return;
66565+}
66566+
66567+void gr_handle_kernel_exploit(void)
66568+{
66569+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
66570+ const struct cred *cred;
66571+ struct task_struct *tsk, *tsk2;
66572+ struct user_struct *user;
66573+ kuid_t uid;
66574+
66575+ if (in_irq() || in_serving_softirq() || in_nmi())
66576+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
66577+
66578+ uid = current_uid();
66579+
66580+ if (gr_is_global_root(uid))
66581+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
66582+ else {
66583+ /* kill all the processes of this user, hold a reference
66584+ to their creds struct, and prevent them from creating
66585+ another process until system reset
66586+ */
66587+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
66588+ GR_GLOBAL_UID(uid));
66589+ /* we intentionally leak this ref */
66590+ user = get_uid(current->cred->user);
66591+ if (user) {
66592+ user->banned = 1;
66593+ user->ban_expires = ~0UL;
66594+ }
66595+
66596+ read_lock(&tasklist_lock);
66597+ do_each_thread(tsk2, tsk) {
66598+ cred = __task_cred(tsk);
66599+ if (uid_eq(cred->uid, uid))
66600+ gr_fake_force_sig(SIGKILL, tsk);
66601+ } while_each_thread(tsk2, tsk);
66602+ read_unlock(&tasklist_lock);
66603+ }
66604+#endif
66605+}
66606+
66607+int __gr_process_user_ban(struct user_struct *user)
66608+{
66609+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
66610+ if (unlikely(user->banned)) {
66611+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
66612+ user->banned = 0;
66613+ user->ban_expires = 0;
66614+ free_uid(user);
66615+ } else
66616+ return -EPERM;
66617+ }
66618+#endif
66619+ return 0;
66620+}
66621+
66622+int gr_process_user_ban(void)
66623+{
66624+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
66625+ return __gr_process_user_ban(current->cred->user);
66626+#endif
66627+ return 0;
66628+}
66629diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
66630new file mode 100644
66631index 0000000..4030d57
66632--- /dev/null
66633+++ b/grsecurity/grsec_sock.c
66634@@ -0,0 +1,244 @@
66635+#include <linux/kernel.h>
66636+#include <linux/module.h>
66637+#include <linux/sched.h>
66638+#include <linux/file.h>
66639+#include <linux/net.h>
66640+#include <linux/in.h>
66641+#include <linux/ip.h>
66642+#include <net/sock.h>
66643+#include <net/inet_sock.h>
66644+#include <linux/grsecurity.h>
66645+#include <linux/grinternal.h>
66646+#include <linux/gracl.h>
66647+
66648+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
66649+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
66650+
66651+EXPORT_SYMBOL(gr_search_udp_recvmsg);
66652+EXPORT_SYMBOL(gr_search_udp_sendmsg);
66653+
66654+#ifdef CONFIG_UNIX_MODULE
66655+EXPORT_SYMBOL(gr_acl_handle_unix);
66656+EXPORT_SYMBOL(gr_acl_handle_mknod);
66657+EXPORT_SYMBOL(gr_handle_chroot_unix);
66658+EXPORT_SYMBOL(gr_handle_create);
66659+#endif
66660+
66661+#ifdef CONFIG_GRKERNSEC
66662+#define gr_conn_table_size 32749
66663+struct conn_table_entry {
66664+ struct conn_table_entry *next;
66665+ struct signal_struct *sig;
66666+};
66667+
66668+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
66669+DEFINE_SPINLOCK(gr_conn_table_lock);
66670+
66671+extern const char * gr_socktype_to_name(unsigned char type);
66672+extern const char * gr_proto_to_name(unsigned char proto);
66673+extern const char * gr_sockfamily_to_name(unsigned char family);
66674+
66675+static __inline__ int
66676+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
66677+{
66678+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
66679+}
66680+
66681+static __inline__ int
66682+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
66683+ __u16 sport, __u16 dport)
66684+{
66685+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
66686+ sig->gr_sport == sport && sig->gr_dport == dport))
66687+ return 1;
66688+ else
66689+ return 0;
66690+}
66691+
66692+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
66693+{
66694+ struct conn_table_entry **match;
66695+ unsigned int index;
66696+
66697+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
66698+ sig->gr_sport, sig->gr_dport,
66699+ gr_conn_table_size);
66700+
66701+ newent->sig = sig;
66702+
66703+ match = &gr_conn_table[index];
66704+ newent->next = *match;
66705+ *match = newent;
66706+
66707+ return;
66708+}
66709+
66710+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
66711+{
66712+ struct conn_table_entry *match, *last = NULL;
66713+ unsigned int index;
66714+
66715+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
66716+ sig->gr_sport, sig->gr_dport,
66717+ gr_conn_table_size);
66718+
66719+ match = gr_conn_table[index];
66720+ while (match && !conn_match(match->sig,
66721+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
66722+ sig->gr_dport)) {
66723+ last = match;
66724+ match = match->next;
66725+ }
66726+
66727+ if (match) {
66728+ if (last)
66729+ last->next = match->next;
66730+ else
66731+ gr_conn_table[index] = NULL;
66732+ kfree(match);
66733+ }
66734+
66735+ return;
66736+}
66737+
66738+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
66739+ __u16 sport, __u16 dport)
66740+{
66741+ struct conn_table_entry *match;
66742+ unsigned int index;
66743+
66744+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
66745+
66746+ match = gr_conn_table[index];
66747+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
66748+ match = match->next;
66749+
66750+ if (match)
66751+ return match->sig;
66752+ else
66753+ return NULL;
66754+}
66755+
66756+#endif
66757+
66758+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
66759+{
66760+#ifdef CONFIG_GRKERNSEC
66761+ struct signal_struct *sig = task->signal;
66762+ struct conn_table_entry *newent;
66763+
66764+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
66765+ if (newent == NULL)
66766+ return;
66767+ /* no bh lock needed since we are called with bh disabled */
66768+ spin_lock(&gr_conn_table_lock);
66769+ gr_del_task_from_ip_table_nolock(sig);
66770+ sig->gr_saddr = inet->inet_rcv_saddr;
66771+ sig->gr_daddr = inet->inet_daddr;
66772+ sig->gr_sport = inet->inet_sport;
66773+ sig->gr_dport = inet->inet_dport;
66774+ gr_add_to_task_ip_table_nolock(sig, newent);
66775+ spin_unlock(&gr_conn_table_lock);
66776+#endif
66777+ return;
66778+}
66779+
66780+void gr_del_task_from_ip_table(struct task_struct *task)
66781+{
66782+#ifdef CONFIG_GRKERNSEC
66783+ spin_lock_bh(&gr_conn_table_lock);
66784+ gr_del_task_from_ip_table_nolock(task->signal);
66785+ spin_unlock_bh(&gr_conn_table_lock);
66786+#endif
66787+ return;
66788+}
66789+
66790+void
66791+gr_attach_curr_ip(const struct sock *sk)
66792+{
66793+#ifdef CONFIG_GRKERNSEC
66794+ struct signal_struct *p, *set;
66795+ const struct inet_sock *inet = inet_sk(sk);
66796+
66797+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
66798+ return;
66799+
66800+ set = current->signal;
66801+
66802+ spin_lock_bh(&gr_conn_table_lock);
66803+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
66804+ inet->inet_dport, inet->inet_sport);
66805+ if (unlikely(p != NULL)) {
66806+ set->curr_ip = p->curr_ip;
66807+ set->used_accept = 1;
66808+ gr_del_task_from_ip_table_nolock(p);
66809+ spin_unlock_bh(&gr_conn_table_lock);
66810+ return;
66811+ }
66812+ spin_unlock_bh(&gr_conn_table_lock);
66813+
66814+ set->curr_ip = inet->inet_daddr;
66815+ set->used_accept = 1;
66816+#endif
66817+ return;
66818+}
66819+
66820+int
66821+gr_handle_sock_all(const int family, const int type, const int protocol)
66822+{
66823+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
66824+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
66825+ (family != AF_UNIX)) {
66826+ if (family == AF_INET)
66827+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
66828+ else
66829+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
66830+ return -EACCES;
66831+ }
66832+#endif
66833+ return 0;
66834+}
66835+
66836+int
66837+gr_handle_sock_server(const struct sockaddr *sck)
66838+{
66839+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
66840+ if (grsec_enable_socket_server &&
66841+ in_group_p(grsec_socket_server_gid) &&
66842+ sck && (sck->sa_family != AF_UNIX) &&
66843+ (sck->sa_family != AF_LOCAL)) {
66844+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
66845+ return -EACCES;
66846+ }
66847+#endif
66848+ return 0;
66849+}
66850+
66851+int
66852+gr_handle_sock_server_other(const struct sock *sck)
66853+{
66854+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
66855+ if (grsec_enable_socket_server &&
66856+ in_group_p(grsec_socket_server_gid) &&
66857+ sck && (sck->sk_family != AF_UNIX) &&
66858+ (sck->sk_family != AF_LOCAL)) {
66859+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
66860+ return -EACCES;
66861+ }
66862+#endif
66863+ return 0;
66864+}
66865+
66866+int
66867+gr_handle_sock_client(const struct sockaddr *sck)
66868+{
66869+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
66870+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
66871+ sck && (sck->sa_family != AF_UNIX) &&
66872+ (sck->sa_family != AF_LOCAL)) {
66873+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
66874+ return -EACCES;
66875+ }
66876+#endif
66877+ return 0;
66878+}
66879diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
66880new file mode 100644
66881index 0000000..f55ef0f
66882--- /dev/null
66883+++ b/grsecurity/grsec_sysctl.c
66884@@ -0,0 +1,469 @@
66885+#include <linux/kernel.h>
66886+#include <linux/sched.h>
66887+#include <linux/sysctl.h>
66888+#include <linux/grsecurity.h>
66889+#include <linux/grinternal.h>
66890+
66891+int
66892+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
66893+{
66894+#ifdef CONFIG_GRKERNSEC_SYSCTL
66895+ if (dirname == NULL || name == NULL)
66896+ return 0;
66897+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
66898+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
66899+ return -EACCES;
66900+ }
66901+#endif
66902+ return 0;
66903+}
66904+
66905+#ifdef CONFIG_GRKERNSEC_ROFS
66906+static int __maybe_unused one = 1;
66907+#endif
66908+
66909+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
66910+struct ctl_table grsecurity_table[] = {
66911+#ifdef CONFIG_GRKERNSEC_SYSCTL
66912+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
66913+#ifdef CONFIG_GRKERNSEC_IO
66914+ {
66915+ .procname = "disable_priv_io",
66916+ .data = &grsec_disable_privio,
66917+ .maxlen = sizeof(int),
66918+ .mode = 0600,
66919+ .proc_handler = &proc_dointvec,
66920+ },
66921+#endif
66922+#endif
66923+#ifdef CONFIG_GRKERNSEC_LINK
66924+ {
66925+ .procname = "linking_restrictions",
66926+ .data = &grsec_enable_link,
66927+ .maxlen = sizeof(int),
66928+ .mode = 0600,
66929+ .proc_handler = &proc_dointvec,
66930+ },
66931+#endif
66932+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
66933+ {
66934+ .procname = "enforce_symlinksifowner",
66935+ .data = &grsec_enable_symlinkown,
66936+ .maxlen = sizeof(int),
66937+ .mode = 0600,
66938+ .proc_handler = &proc_dointvec,
66939+ },
66940+ {
66941+ .procname = "symlinkown_gid",
66942+ .data = &grsec_symlinkown_gid,
66943+ .maxlen = sizeof(int),
66944+ .mode = 0600,
66945+ .proc_handler = &proc_dointvec,
66946+ },
66947+#endif
66948+#ifdef CONFIG_GRKERNSEC_BRUTE
66949+ {
66950+ .procname = "deter_bruteforce",
66951+ .data = &grsec_enable_brute,
66952+ .maxlen = sizeof(int),
66953+ .mode = 0600,
66954+ .proc_handler = &proc_dointvec,
66955+ },
66956+#endif
66957+#ifdef CONFIG_GRKERNSEC_FIFO
66958+ {
66959+ .procname = "fifo_restrictions",
66960+ .data = &grsec_enable_fifo,
66961+ .maxlen = sizeof(int),
66962+ .mode = 0600,
66963+ .proc_handler = &proc_dointvec,
66964+ },
66965+#endif
66966+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
66967+ {
66968+ .procname = "ptrace_readexec",
66969+ .data = &grsec_enable_ptrace_readexec,
66970+ .maxlen = sizeof(int),
66971+ .mode = 0600,
66972+ .proc_handler = &proc_dointvec,
66973+ },
66974+#endif
66975+#ifdef CONFIG_GRKERNSEC_SETXID
66976+ {
66977+ .procname = "consistent_setxid",
66978+ .data = &grsec_enable_setxid,
66979+ .maxlen = sizeof(int),
66980+ .mode = 0600,
66981+ .proc_handler = &proc_dointvec,
66982+ },
66983+#endif
66984+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
66985+ {
66986+ .procname = "ip_blackhole",
66987+ .data = &grsec_enable_blackhole,
66988+ .maxlen = sizeof(int),
66989+ .mode = 0600,
66990+ .proc_handler = &proc_dointvec,
66991+ },
66992+ {
66993+ .procname = "lastack_retries",
66994+ .data = &grsec_lastack_retries,
66995+ .maxlen = sizeof(int),
66996+ .mode = 0600,
66997+ .proc_handler = &proc_dointvec,
66998+ },
66999+#endif
67000+#ifdef CONFIG_GRKERNSEC_EXECLOG
67001+ {
67002+ .procname = "exec_logging",
67003+ .data = &grsec_enable_execlog,
67004+ .maxlen = sizeof(int),
67005+ .mode = 0600,
67006+ .proc_handler = &proc_dointvec,
67007+ },
67008+#endif
67009+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
67010+ {
67011+ .procname = "rwxmap_logging",
67012+ .data = &grsec_enable_log_rwxmaps,
67013+ .maxlen = sizeof(int),
67014+ .mode = 0600,
67015+ .proc_handler = &proc_dointvec,
67016+ },
67017+#endif
67018+#ifdef CONFIG_GRKERNSEC_SIGNAL
67019+ {
67020+ .procname = "signal_logging",
67021+ .data = &grsec_enable_signal,
67022+ .maxlen = sizeof(int),
67023+ .mode = 0600,
67024+ .proc_handler = &proc_dointvec,
67025+ },
67026+#endif
67027+#ifdef CONFIG_GRKERNSEC_FORKFAIL
67028+ {
67029+ .procname = "forkfail_logging",
67030+ .data = &grsec_enable_forkfail,
67031+ .maxlen = sizeof(int),
67032+ .mode = 0600,
67033+ .proc_handler = &proc_dointvec,
67034+ },
67035+#endif
67036+#ifdef CONFIG_GRKERNSEC_TIME
67037+ {
67038+ .procname = "timechange_logging",
67039+ .data = &grsec_enable_time,
67040+ .maxlen = sizeof(int),
67041+ .mode = 0600,
67042+ .proc_handler = &proc_dointvec,
67043+ },
67044+#endif
67045+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
67046+ {
67047+ .procname = "chroot_deny_shmat",
67048+ .data = &grsec_enable_chroot_shmat,
67049+ .maxlen = sizeof(int),
67050+ .mode = 0600,
67051+ .proc_handler = &proc_dointvec,
67052+ },
67053+#endif
67054+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
67055+ {
67056+ .procname = "chroot_deny_unix",
67057+ .data = &grsec_enable_chroot_unix,
67058+ .maxlen = sizeof(int),
67059+ .mode = 0600,
67060+ .proc_handler = &proc_dointvec,
67061+ },
67062+#endif
67063+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
67064+ {
67065+ .procname = "chroot_deny_mount",
67066+ .data = &grsec_enable_chroot_mount,
67067+ .maxlen = sizeof(int),
67068+ .mode = 0600,
67069+ .proc_handler = &proc_dointvec,
67070+ },
67071+#endif
67072+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
67073+ {
67074+ .procname = "chroot_deny_fchdir",
67075+ .data = &grsec_enable_chroot_fchdir,
67076+ .maxlen = sizeof(int),
67077+ .mode = 0600,
67078+ .proc_handler = &proc_dointvec,
67079+ },
67080+#endif
67081+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
67082+ {
67083+ .procname = "chroot_deny_chroot",
67084+ .data = &grsec_enable_chroot_double,
67085+ .maxlen = sizeof(int),
67086+ .mode = 0600,
67087+ .proc_handler = &proc_dointvec,
67088+ },
67089+#endif
67090+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
67091+ {
67092+ .procname = "chroot_deny_pivot",
67093+ .data = &grsec_enable_chroot_pivot,
67094+ .maxlen = sizeof(int),
67095+ .mode = 0600,
67096+ .proc_handler = &proc_dointvec,
67097+ },
67098+#endif
67099+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
67100+ {
67101+ .procname = "chroot_enforce_chdir",
67102+ .data = &grsec_enable_chroot_chdir,
67103+ .maxlen = sizeof(int),
67104+ .mode = 0600,
67105+ .proc_handler = &proc_dointvec,
67106+ },
67107+#endif
67108+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
67109+ {
67110+ .procname = "chroot_deny_chmod",
67111+ .data = &grsec_enable_chroot_chmod,
67112+ .maxlen = sizeof(int),
67113+ .mode = 0600,
67114+ .proc_handler = &proc_dointvec,
67115+ },
67116+#endif
67117+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
67118+ {
67119+ .procname = "chroot_deny_mknod",
67120+ .data = &grsec_enable_chroot_mknod,
67121+ .maxlen = sizeof(int),
67122+ .mode = 0600,
67123+ .proc_handler = &proc_dointvec,
67124+ },
67125+#endif
67126+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
67127+ {
67128+ .procname = "chroot_restrict_nice",
67129+ .data = &grsec_enable_chroot_nice,
67130+ .maxlen = sizeof(int),
67131+ .mode = 0600,
67132+ .proc_handler = &proc_dointvec,
67133+ },
67134+#endif
67135+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
67136+ {
67137+ .procname = "chroot_execlog",
67138+ .data = &grsec_enable_chroot_execlog,
67139+ .maxlen = sizeof(int),
67140+ .mode = 0600,
67141+ .proc_handler = &proc_dointvec,
67142+ },
67143+#endif
67144+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
67145+ {
67146+ .procname = "chroot_caps",
67147+ .data = &grsec_enable_chroot_caps,
67148+ .maxlen = sizeof(int),
67149+ .mode = 0600,
67150+ .proc_handler = &proc_dointvec,
67151+ },
67152+#endif
67153+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
67154+ {
67155+ .procname = "chroot_deny_sysctl",
67156+ .data = &grsec_enable_chroot_sysctl,
67157+ .maxlen = sizeof(int),
67158+ .mode = 0600,
67159+ .proc_handler = &proc_dointvec,
67160+ },
67161+#endif
67162+#ifdef CONFIG_GRKERNSEC_TPE
67163+ {
67164+ .procname = "tpe",
67165+ .data = &grsec_enable_tpe,
67166+ .maxlen = sizeof(int),
67167+ .mode = 0600,
67168+ .proc_handler = &proc_dointvec,
67169+ },
67170+ {
67171+ .procname = "tpe_gid",
67172+ .data = &grsec_tpe_gid,
67173+ .maxlen = sizeof(int),
67174+ .mode = 0600,
67175+ .proc_handler = &proc_dointvec,
67176+ },
67177+#endif
67178+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
67179+ {
67180+ .procname = "tpe_invert",
67181+ .data = &grsec_enable_tpe_invert,
67182+ .maxlen = sizeof(int),
67183+ .mode = 0600,
67184+ .proc_handler = &proc_dointvec,
67185+ },
67186+#endif
67187+#ifdef CONFIG_GRKERNSEC_TPE_ALL
67188+ {
67189+ .procname = "tpe_restrict_all",
67190+ .data = &grsec_enable_tpe_all,
67191+ .maxlen = sizeof(int),
67192+ .mode = 0600,
67193+ .proc_handler = &proc_dointvec,
67194+ },
67195+#endif
67196+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
67197+ {
67198+ .procname = "socket_all",
67199+ .data = &grsec_enable_socket_all,
67200+ .maxlen = sizeof(int),
67201+ .mode = 0600,
67202+ .proc_handler = &proc_dointvec,
67203+ },
67204+ {
67205+ .procname = "socket_all_gid",
67206+ .data = &grsec_socket_all_gid,
67207+ .maxlen = sizeof(int),
67208+ .mode = 0600,
67209+ .proc_handler = &proc_dointvec,
67210+ },
67211+#endif
67212+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
67213+ {
67214+ .procname = "socket_client",
67215+ .data = &grsec_enable_socket_client,
67216+ .maxlen = sizeof(int),
67217+ .mode = 0600,
67218+ .proc_handler = &proc_dointvec,
67219+ },
67220+ {
67221+ .procname = "socket_client_gid",
67222+ .data = &grsec_socket_client_gid,
67223+ .maxlen = sizeof(int),
67224+ .mode = 0600,
67225+ .proc_handler = &proc_dointvec,
67226+ },
67227+#endif
67228+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
67229+ {
67230+ .procname = "socket_server",
67231+ .data = &grsec_enable_socket_server,
67232+ .maxlen = sizeof(int),
67233+ .mode = 0600,
67234+ .proc_handler = &proc_dointvec,
67235+ },
67236+ {
67237+ .procname = "socket_server_gid",
67238+ .data = &grsec_socket_server_gid,
67239+ .maxlen = sizeof(int),
67240+ .mode = 0600,
67241+ .proc_handler = &proc_dointvec,
67242+ },
67243+#endif
67244+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
67245+ {
67246+ .procname = "audit_group",
67247+ .data = &grsec_enable_group,
67248+ .maxlen = sizeof(int),
67249+ .mode = 0600,
67250+ .proc_handler = &proc_dointvec,
67251+ },
67252+ {
67253+ .procname = "audit_gid",
67254+ .data = &grsec_audit_gid,
67255+ .maxlen = sizeof(int),
67256+ .mode = 0600,
67257+ .proc_handler = &proc_dointvec,
67258+ },
67259+#endif
67260+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
67261+ {
67262+ .procname = "audit_chdir",
67263+ .data = &grsec_enable_chdir,
67264+ .maxlen = sizeof(int),
67265+ .mode = 0600,
67266+ .proc_handler = &proc_dointvec,
67267+ },
67268+#endif
67269+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
67270+ {
67271+ .procname = "audit_mount",
67272+ .data = &grsec_enable_mount,
67273+ .maxlen = sizeof(int),
67274+ .mode = 0600,
67275+ .proc_handler = &proc_dointvec,
67276+ },
67277+#endif
67278+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
67279+ {
67280+ .procname = "audit_textrel",
67281+ .data = &grsec_enable_audit_textrel,
67282+ .maxlen = sizeof(int),
67283+ .mode = 0600,
67284+ .proc_handler = &proc_dointvec,
67285+ },
67286+#endif
67287+#ifdef CONFIG_GRKERNSEC_DMESG
67288+ {
67289+ .procname = "dmesg",
67290+ .data = &grsec_enable_dmesg,
67291+ .maxlen = sizeof(int),
67292+ .mode = 0600,
67293+ .proc_handler = &proc_dointvec,
67294+ },
67295+#endif
67296+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
67297+ {
67298+ .procname = "chroot_findtask",
67299+ .data = &grsec_enable_chroot_findtask,
67300+ .maxlen = sizeof(int),
67301+ .mode = 0600,
67302+ .proc_handler = &proc_dointvec,
67303+ },
67304+#endif
67305+#ifdef CONFIG_GRKERNSEC_RESLOG
67306+ {
67307+ .procname = "resource_logging",
67308+ .data = &grsec_resource_logging,
67309+ .maxlen = sizeof(int),
67310+ .mode = 0600,
67311+ .proc_handler = &proc_dointvec,
67312+ },
67313+#endif
67314+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
67315+ {
67316+ .procname = "audit_ptrace",
67317+ .data = &grsec_enable_audit_ptrace,
67318+ .maxlen = sizeof(int),
67319+ .mode = 0600,
67320+ .proc_handler = &proc_dointvec,
67321+ },
67322+#endif
67323+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
67324+ {
67325+ .procname = "harden_ptrace",
67326+ .data = &grsec_enable_harden_ptrace,
67327+ .maxlen = sizeof(int),
67328+ .mode = 0600,
67329+ .proc_handler = &proc_dointvec,
67330+ },
67331+#endif
67332+ {
67333+ .procname = "grsec_lock",
67334+ .data = &grsec_lock,
67335+ .maxlen = sizeof(int),
67336+ .mode = 0600,
67337+ .proc_handler = &proc_dointvec,
67338+ },
67339+#endif
67340+#ifdef CONFIG_GRKERNSEC_ROFS
67341+ {
67342+ .procname = "romount_protect",
67343+ .data = &grsec_enable_rofs,
67344+ .maxlen = sizeof(int),
67345+ .mode = 0600,
67346+ .proc_handler = &proc_dointvec_minmax,
67347+ .extra1 = &one,
67348+ .extra2 = &one,
67349+ },
67350+#endif
67351+ { }
67352+};
67353+#endif
67354diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
67355new file mode 100644
67356index 0000000..0dc13c3
67357--- /dev/null
67358+++ b/grsecurity/grsec_time.c
67359@@ -0,0 +1,16 @@
67360+#include <linux/kernel.h>
67361+#include <linux/sched.h>
67362+#include <linux/grinternal.h>
67363+#include <linux/module.h>
67364+
67365+void
67366+gr_log_timechange(void)
67367+{
67368+#ifdef CONFIG_GRKERNSEC_TIME
67369+ if (grsec_enable_time)
67370+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
67371+#endif
67372+ return;
67373+}
67374+
67375+EXPORT_SYMBOL(gr_log_timechange);
67376diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
67377new file mode 100644
67378index 0000000..ee57dcf
67379--- /dev/null
67380+++ b/grsecurity/grsec_tpe.c
67381@@ -0,0 +1,73 @@
67382+#include <linux/kernel.h>
67383+#include <linux/sched.h>
67384+#include <linux/file.h>
67385+#include <linux/fs.h>
67386+#include <linux/grinternal.h>
67387+
67388+extern int gr_acl_tpe_check(void);
67389+
67390+int
67391+gr_tpe_allow(const struct file *file)
67392+{
67393+#ifdef CONFIG_GRKERNSEC
67394+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
67395+ const struct cred *cred = current_cred();
67396+ char *msg = NULL;
67397+ char *msg2 = NULL;
67398+
67399+ // never restrict root
67400+ if (gr_is_global_root(cred->uid))
67401+ return 1;
67402+
67403+ if (grsec_enable_tpe) {
67404+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
67405+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
67406+ msg = "not being in trusted group";
67407+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
67408+ msg = "being in untrusted group";
67409+#else
67410+ if (in_group_p(grsec_tpe_gid))
67411+ msg = "being in untrusted group";
67412+#endif
67413+ }
67414+ if (!msg && gr_acl_tpe_check())
67415+ msg = "being in untrusted role";
67416+
67417+ // not in any affected group/role
67418+ if (!msg)
67419+ goto next_check;
67420+
67421+ if (gr_is_global_nonroot(inode->i_uid))
67422+ msg2 = "file in non-root-owned directory";
67423+ else if (inode->i_mode & S_IWOTH)
67424+ msg2 = "file in world-writable directory";
67425+ else if (inode->i_mode & S_IWGRP)
67426+ msg2 = "file in group-writable directory";
67427+
67428+ if (msg && msg2) {
67429+ char fullmsg[70] = {0};
67430+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
67431+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
67432+ return 0;
67433+ }
67434+ msg = NULL;
67435+next_check:
67436+#ifdef CONFIG_GRKERNSEC_TPE_ALL
67437+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
67438+ return 1;
67439+
67440+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
67441+ msg = "directory not owned by user";
67442+ else if (inode->i_mode & S_IWOTH)
67443+ msg = "file in world-writable directory";
67444+ else if (inode->i_mode & S_IWGRP)
67445+ msg = "file in group-writable directory";
67446+
67447+ if (msg) {
67448+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
67449+ return 0;
67450+ }
67451+#endif
67452+#endif
67453+ return 1;
67454+}
67455diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
67456new file mode 100644
67457index 0000000..9f7b1ac
67458--- /dev/null
67459+++ b/grsecurity/grsum.c
67460@@ -0,0 +1,61 @@
67461+#include <linux/err.h>
67462+#include <linux/kernel.h>
67463+#include <linux/sched.h>
67464+#include <linux/mm.h>
67465+#include <linux/scatterlist.h>
67466+#include <linux/crypto.h>
67467+#include <linux/gracl.h>
67468+
67469+
67470+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
67471+#error "crypto and sha256 must be built into the kernel"
67472+#endif
67473+
67474+int
67475+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
67476+{
67477+ char *p;
67478+ struct crypto_hash *tfm;
67479+ struct hash_desc desc;
67480+ struct scatterlist sg;
67481+ unsigned char temp_sum[GR_SHA_LEN];
67482+ volatile int retval = 0;
67483+ volatile int dummy = 0;
67484+ unsigned int i;
67485+
67486+ sg_init_table(&sg, 1);
67487+
67488+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
67489+ if (IS_ERR(tfm)) {
67490+ /* should never happen, since sha256 should be built in */
67491+ return 1;
67492+ }
67493+
67494+ desc.tfm = tfm;
67495+ desc.flags = 0;
67496+
67497+ crypto_hash_init(&desc);
67498+
67499+ p = salt;
67500+ sg_set_buf(&sg, p, GR_SALT_LEN);
67501+ crypto_hash_update(&desc, &sg, sg.length);
67502+
67503+ p = entry->pw;
67504+ sg_set_buf(&sg, p, strlen(p));
67505+
67506+ crypto_hash_update(&desc, &sg, sg.length);
67507+
67508+ crypto_hash_final(&desc, temp_sum);
67509+
67510+ memset(entry->pw, 0, GR_PW_LEN);
67511+
67512+ for (i = 0; i < GR_SHA_LEN; i++)
67513+ if (sum[i] != temp_sum[i])
67514+ retval = 1;
67515+ else
67516+ dummy = 1; // waste a cycle
67517+
67518+ crypto_free_hash(tfm);
67519+
67520+ return retval;
67521+}
67522diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
67523index 77ff547..181834f 100644
67524--- a/include/asm-generic/4level-fixup.h
67525+++ b/include/asm-generic/4level-fixup.h
67526@@ -13,8 +13,10 @@
67527 #define pmd_alloc(mm, pud, address) \
67528 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
67529 NULL: pmd_offset(pud, address))
67530+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
67531
67532 #define pud_alloc(mm, pgd, address) (pgd)
67533+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
67534 #define pud_offset(pgd, start) (pgd)
67535 #define pud_none(pud) 0
67536 #define pud_bad(pud) 0
67537diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
67538index b7babf0..04ad282 100644
67539--- a/include/asm-generic/atomic-long.h
67540+++ b/include/asm-generic/atomic-long.h
67541@@ -22,6 +22,12 @@
67542
67543 typedef atomic64_t atomic_long_t;
67544
67545+#ifdef CONFIG_PAX_REFCOUNT
67546+typedef atomic64_unchecked_t atomic_long_unchecked_t;
67547+#else
67548+typedef atomic64_t atomic_long_unchecked_t;
67549+#endif
67550+
67551 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
67552
67553 static inline long atomic_long_read(atomic_long_t *l)
67554@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
67555 return (long)atomic64_read(v);
67556 }
67557
67558+#ifdef CONFIG_PAX_REFCOUNT
67559+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
67560+{
67561+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67562+
67563+ return (long)atomic64_read_unchecked(v);
67564+}
67565+#endif
67566+
67567 static inline void atomic_long_set(atomic_long_t *l, long i)
67568 {
67569 atomic64_t *v = (atomic64_t *)l;
67570@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
67571 atomic64_set(v, i);
67572 }
67573
67574+#ifdef CONFIG_PAX_REFCOUNT
67575+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
67576+{
67577+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67578+
67579+ atomic64_set_unchecked(v, i);
67580+}
67581+#endif
67582+
67583 static inline void atomic_long_inc(atomic_long_t *l)
67584 {
67585 atomic64_t *v = (atomic64_t *)l;
67586@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
67587 atomic64_inc(v);
67588 }
67589
67590+#ifdef CONFIG_PAX_REFCOUNT
67591+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
67592+{
67593+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67594+
67595+ atomic64_inc_unchecked(v);
67596+}
67597+#endif
67598+
67599 static inline void atomic_long_dec(atomic_long_t *l)
67600 {
67601 atomic64_t *v = (atomic64_t *)l;
67602@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
67603 atomic64_dec(v);
67604 }
67605
67606+#ifdef CONFIG_PAX_REFCOUNT
67607+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
67608+{
67609+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67610+
67611+ atomic64_dec_unchecked(v);
67612+}
67613+#endif
67614+
67615 static inline void atomic_long_add(long i, atomic_long_t *l)
67616 {
67617 atomic64_t *v = (atomic64_t *)l;
67618@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
67619 atomic64_add(i, v);
67620 }
67621
67622+#ifdef CONFIG_PAX_REFCOUNT
67623+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
67624+{
67625+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67626+
67627+ atomic64_add_unchecked(i, v);
67628+}
67629+#endif
67630+
67631 static inline void atomic_long_sub(long i, atomic_long_t *l)
67632 {
67633 atomic64_t *v = (atomic64_t *)l;
67634@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
67635 atomic64_sub(i, v);
67636 }
67637
67638+#ifdef CONFIG_PAX_REFCOUNT
67639+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
67640+{
67641+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67642+
67643+ atomic64_sub_unchecked(i, v);
67644+}
67645+#endif
67646+
67647 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
67648 {
67649 atomic64_t *v = (atomic64_t *)l;
67650@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
67651 return (long)atomic64_add_return(i, v);
67652 }
67653
67654+#ifdef CONFIG_PAX_REFCOUNT
67655+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
67656+{
67657+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67658+
67659+ return (long)atomic64_add_return_unchecked(i, v);
67660+}
67661+#endif
67662+
67663 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
67664 {
67665 atomic64_t *v = (atomic64_t *)l;
67666@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
67667 return (long)atomic64_inc_return(v);
67668 }
67669
67670+#ifdef CONFIG_PAX_REFCOUNT
67671+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
67672+{
67673+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67674+
67675+ return (long)atomic64_inc_return_unchecked(v);
67676+}
67677+#endif
67678+
67679 static inline long atomic_long_dec_return(atomic_long_t *l)
67680 {
67681 atomic64_t *v = (atomic64_t *)l;
67682@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
67683
67684 typedef atomic_t atomic_long_t;
67685
67686+#ifdef CONFIG_PAX_REFCOUNT
67687+typedef atomic_unchecked_t atomic_long_unchecked_t;
67688+#else
67689+typedef atomic_t atomic_long_unchecked_t;
67690+#endif
67691+
67692 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
67693 static inline long atomic_long_read(atomic_long_t *l)
67694 {
67695@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
67696 return (long)atomic_read(v);
67697 }
67698
67699+#ifdef CONFIG_PAX_REFCOUNT
67700+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
67701+{
67702+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67703+
67704+ return (long)atomic_read_unchecked(v);
67705+}
67706+#endif
67707+
67708 static inline void atomic_long_set(atomic_long_t *l, long i)
67709 {
67710 atomic_t *v = (atomic_t *)l;
67711@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
67712 atomic_set(v, i);
67713 }
67714
67715+#ifdef CONFIG_PAX_REFCOUNT
67716+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
67717+{
67718+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67719+
67720+ atomic_set_unchecked(v, i);
67721+}
67722+#endif
67723+
67724 static inline void atomic_long_inc(atomic_long_t *l)
67725 {
67726 atomic_t *v = (atomic_t *)l;
67727@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
67728 atomic_inc(v);
67729 }
67730
67731+#ifdef CONFIG_PAX_REFCOUNT
67732+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
67733+{
67734+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67735+
67736+ atomic_inc_unchecked(v);
67737+}
67738+#endif
67739+
67740 static inline void atomic_long_dec(atomic_long_t *l)
67741 {
67742 atomic_t *v = (atomic_t *)l;
67743@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
67744 atomic_dec(v);
67745 }
67746
67747+#ifdef CONFIG_PAX_REFCOUNT
67748+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
67749+{
67750+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67751+
67752+ atomic_dec_unchecked(v);
67753+}
67754+#endif
67755+
67756 static inline void atomic_long_add(long i, atomic_long_t *l)
67757 {
67758 atomic_t *v = (atomic_t *)l;
67759@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
67760 atomic_add(i, v);
67761 }
67762
67763+#ifdef CONFIG_PAX_REFCOUNT
67764+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
67765+{
67766+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67767+
67768+ atomic_add_unchecked(i, v);
67769+}
67770+#endif
67771+
67772 static inline void atomic_long_sub(long i, atomic_long_t *l)
67773 {
67774 atomic_t *v = (atomic_t *)l;
67775@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
67776 atomic_sub(i, v);
67777 }
67778
67779+#ifdef CONFIG_PAX_REFCOUNT
67780+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
67781+{
67782+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67783+
67784+ atomic_sub_unchecked(i, v);
67785+}
67786+#endif
67787+
67788 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
67789 {
67790 atomic_t *v = (atomic_t *)l;
67791@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
67792 return (long)atomic_add_return(i, v);
67793 }
67794
67795+#ifdef CONFIG_PAX_REFCOUNT
67796+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
67797+{
67798+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67799+
67800+ return (long)atomic_add_return_unchecked(i, v);
67801+}
67802+
67803+#endif
67804+
67805 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
67806 {
67807 atomic_t *v = (atomic_t *)l;
67808@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
67809 return (long)atomic_inc_return(v);
67810 }
67811
67812+#ifdef CONFIG_PAX_REFCOUNT
67813+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
67814+{
67815+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67816+
67817+ return (long)atomic_inc_return_unchecked(v);
67818+}
67819+#endif
67820+
67821 static inline long atomic_long_dec_return(atomic_long_t *l)
67822 {
67823 atomic_t *v = (atomic_t *)l;
67824@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
67825
67826 #endif /* BITS_PER_LONG == 64 */
67827
67828+#ifdef CONFIG_PAX_REFCOUNT
67829+static inline void pax_refcount_needs_these_functions(void)
67830+{
67831+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
67832+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
67833+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
67834+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
67835+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
67836+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
67837+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
67838+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
67839+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
67840+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
67841+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
67842+#ifdef CONFIG_X86
67843+ atomic_clear_mask_unchecked(0, NULL);
67844+ atomic_set_mask_unchecked(0, NULL);
67845+#endif
67846+
67847+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
67848+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
67849+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
67850+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
67851+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
67852+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
67853+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
67854+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
67855+}
67856+#else
67857+#define atomic_read_unchecked(v) atomic_read(v)
67858+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
67859+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
67860+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
67861+#define atomic_inc_unchecked(v) atomic_inc(v)
67862+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
67863+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
67864+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
67865+#define atomic_dec_unchecked(v) atomic_dec(v)
67866+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
67867+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
67868+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
67869+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
67870+
67871+#define atomic_long_read_unchecked(v) atomic_long_read(v)
67872+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
67873+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
67874+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
67875+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
67876+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
67877+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
67878+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
67879+#endif
67880+
67881 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
67882diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
67883index 1ced641..c896ee8 100644
67884--- a/include/asm-generic/atomic.h
67885+++ b/include/asm-generic/atomic.h
67886@@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
67887 * Atomically clears the bits set in @mask from @v
67888 */
67889 #ifndef atomic_clear_mask
67890-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
67891+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
67892 {
67893 unsigned long flags;
67894
67895diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
67896index b18ce4f..2ee2843 100644
67897--- a/include/asm-generic/atomic64.h
67898+++ b/include/asm-generic/atomic64.h
67899@@ -16,6 +16,8 @@ typedef struct {
67900 long long counter;
67901 } atomic64_t;
67902
67903+typedef atomic64_t atomic64_unchecked_t;
67904+
67905 #define ATOMIC64_INIT(i) { (i) }
67906
67907 extern long long atomic64_read(const atomic64_t *v);
67908@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
67909 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
67910 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
67911
67912+#define atomic64_read_unchecked(v) atomic64_read(v)
67913+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
67914+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
67915+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
67916+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
67917+#define atomic64_inc_unchecked(v) atomic64_inc(v)
67918+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
67919+#define atomic64_dec_unchecked(v) atomic64_dec(v)
67920+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
67921+
67922 #endif /* _ASM_GENERIC_ATOMIC64_H */
67923diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
67924index 1bfcfe5..e04c5c9 100644
67925--- a/include/asm-generic/cache.h
67926+++ b/include/asm-generic/cache.h
67927@@ -6,7 +6,7 @@
67928 * cache lines need to provide their own cache.h.
67929 */
67930
67931-#define L1_CACHE_SHIFT 5
67932-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
67933+#define L1_CACHE_SHIFT 5UL
67934+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
67935
67936 #endif /* __ASM_GENERIC_CACHE_H */
67937diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
67938index 0d68a1e..b74a761 100644
67939--- a/include/asm-generic/emergency-restart.h
67940+++ b/include/asm-generic/emergency-restart.h
67941@@ -1,7 +1,7 @@
67942 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
67943 #define _ASM_GENERIC_EMERGENCY_RESTART_H
67944
67945-static inline void machine_emergency_restart(void)
67946+static inline __noreturn void machine_emergency_restart(void)
67947 {
67948 machine_restart(NULL);
67949 }
67950diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
67951index 90f99c7..00ce236 100644
67952--- a/include/asm-generic/kmap_types.h
67953+++ b/include/asm-generic/kmap_types.h
67954@@ -2,9 +2,9 @@
67955 #define _ASM_GENERIC_KMAP_TYPES_H
67956
67957 #ifdef __WITH_KM_FENCE
67958-# define KM_TYPE_NR 41
67959+# define KM_TYPE_NR 42
67960 #else
67961-# define KM_TYPE_NR 20
67962+# define KM_TYPE_NR 21
67963 #endif
67964
67965 #endif
67966diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
67967index 9ceb03b..62b0b8f 100644
67968--- a/include/asm-generic/local.h
67969+++ b/include/asm-generic/local.h
67970@@ -23,24 +23,37 @@ typedef struct
67971 atomic_long_t a;
67972 } local_t;
67973
67974+typedef struct {
67975+ atomic_long_unchecked_t a;
67976+} local_unchecked_t;
67977+
67978 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
67979
67980 #define local_read(l) atomic_long_read(&(l)->a)
67981+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
67982 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
67983+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
67984 #define local_inc(l) atomic_long_inc(&(l)->a)
67985+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
67986 #define local_dec(l) atomic_long_dec(&(l)->a)
67987+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
67988 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
67989+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
67990 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
67991+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
67992
67993 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
67994 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
67995 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
67996 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
67997 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
67998+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
67999 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
68000 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
68001+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
68002
68003 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
68004+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
68005 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
68006 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
68007 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
68008diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
68009index 725612b..9cc513a 100644
68010--- a/include/asm-generic/pgtable-nopmd.h
68011+++ b/include/asm-generic/pgtable-nopmd.h
68012@@ -1,14 +1,19 @@
68013 #ifndef _PGTABLE_NOPMD_H
68014 #define _PGTABLE_NOPMD_H
68015
68016-#ifndef __ASSEMBLY__
68017-
68018 #include <asm-generic/pgtable-nopud.h>
68019
68020-struct mm_struct;
68021-
68022 #define __PAGETABLE_PMD_FOLDED
68023
68024+#define PMD_SHIFT PUD_SHIFT
68025+#define PTRS_PER_PMD 1
68026+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
68027+#define PMD_MASK (~(PMD_SIZE-1))
68028+
68029+#ifndef __ASSEMBLY__
68030+
68031+struct mm_struct;
68032+
68033 /*
68034 * Having the pmd type consist of a pud gets the size right, and allows
68035 * us to conceptually access the pud entry that this pmd is folded into
68036@@ -16,11 +21,6 @@ struct mm_struct;
68037 */
68038 typedef struct { pud_t pud; } pmd_t;
68039
68040-#define PMD_SHIFT PUD_SHIFT
68041-#define PTRS_PER_PMD 1
68042-#define PMD_SIZE (1UL << PMD_SHIFT)
68043-#define PMD_MASK (~(PMD_SIZE-1))
68044-
68045 /*
68046 * The "pud_xxx()" functions here are trivial for a folded two-level
68047 * setup: the pmd is never bad, and a pmd always exists (as it's folded
68048diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
68049index 810431d..0ec4804f 100644
68050--- a/include/asm-generic/pgtable-nopud.h
68051+++ b/include/asm-generic/pgtable-nopud.h
68052@@ -1,10 +1,15 @@
68053 #ifndef _PGTABLE_NOPUD_H
68054 #define _PGTABLE_NOPUD_H
68055
68056-#ifndef __ASSEMBLY__
68057-
68058 #define __PAGETABLE_PUD_FOLDED
68059
68060+#define PUD_SHIFT PGDIR_SHIFT
68061+#define PTRS_PER_PUD 1
68062+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
68063+#define PUD_MASK (~(PUD_SIZE-1))
68064+
68065+#ifndef __ASSEMBLY__
68066+
68067 /*
68068 * Having the pud type consist of a pgd gets the size right, and allows
68069 * us to conceptually access the pgd entry that this pud is folded into
68070@@ -12,11 +17,6 @@
68071 */
68072 typedef struct { pgd_t pgd; } pud_t;
68073
68074-#define PUD_SHIFT PGDIR_SHIFT
68075-#define PTRS_PER_PUD 1
68076-#define PUD_SIZE (1UL << PUD_SHIFT)
68077-#define PUD_MASK (~(PUD_SIZE-1))
68078-
68079 /*
68080 * The "pgd_xxx()" functions here are trivial for a folded two-level
68081 * setup: the pud is never bad, and a pud always exists (as it's folded
68082@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
68083 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
68084
68085 #define pgd_populate(mm, pgd, pud) do { } while (0)
68086+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
68087 /*
68088 * (puds are folded into pgds so this doesn't get actually called,
68089 * but the define is needed for a generic inline function.)
68090diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
68091index 5cf680a..4b74d62 100644
68092--- a/include/asm-generic/pgtable.h
68093+++ b/include/asm-generic/pgtable.h
68094@@ -688,6 +688,14 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
68095 }
68096 #endif /* CONFIG_NUMA_BALANCING */
68097
68098+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
68099+static inline unsigned long pax_open_kernel(void) { return 0; }
68100+#endif
68101+
68102+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
68103+static inline unsigned long pax_close_kernel(void) { return 0; }
68104+#endif
68105+
68106 #endif /* CONFIG_MMU */
68107
68108 #endif /* !__ASSEMBLY__ */
68109diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
68110index d1ea7ce..b1ebf2a 100644
68111--- a/include/asm-generic/vmlinux.lds.h
68112+++ b/include/asm-generic/vmlinux.lds.h
68113@@ -218,6 +218,7 @@
68114 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
68115 VMLINUX_SYMBOL(__start_rodata) = .; \
68116 *(.rodata) *(.rodata.*) \
68117+ *(.data..read_only) \
68118 *(__vermagic) /* Kernel version magic */ \
68119 . = ALIGN(8); \
68120 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
68121@@ -725,17 +726,18 @@
68122 * section in the linker script will go there too. @phdr should have
68123 * a leading colon.
68124 *
68125- * Note that this macros defines __per_cpu_load as an absolute symbol.
68126+ * Note that this macros defines per_cpu_load as an absolute symbol.
68127 * If there is no need to put the percpu section at a predetermined
68128 * address, use PERCPU_SECTION.
68129 */
68130 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
68131- VMLINUX_SYMBOL(__per_cpu_load) = .; \
68132- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
68133+ per_cpu_load = .; \
68134+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
68135 - LOAD_OFFSET) { \
68136+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
68137 PERCPU_INPUT(cacheline) \
68138 } phdr \
68139- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
68140+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
68141
68142 /**
68143 * PERCPU_SECTION - define output section for percpu area, simple version
68144diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
68145index 418d270..bfd2794 100644
68146--- a/include/crypto/algapi.h
68147+++ b/include/crypto/algapi.h
68148@@ -34,7 +34,7 @@ struct crypto_type {
68149 unsigned int maskclear;
68150 unsigned int maskset;
68151 unsigned int tfmsize;
68152-};
68153+} __do_const;
68154
68155 struct crypto_instance {
68156 struct crypto_alg alg;
68157diff --git a/include/drm/drmP.h b/include/drm/drmP.h
68158index fad21c9..ab858bc 100644
68159--- a/include/drm/drmP.h
68160+++ b/include/drm/drmP.h
68161@@ -72,6 +72,7 @@
68162 #include <linux/workqueue.h>
68163 #include <linux/poll.h>
68164 #include <asm/pgalloc.h>
68165+#include <asm/local.h>
68166 #include <drm/drm.h>
68167 #include <drm/drm_sarea.h>
68168
68169@@ -293,10 +294,12 @@ do { \
68170 * \param cmd command.
68171 * \param arg argument.
68172 */
68173-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
68174+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
68175+ struct drm_file *file_priv);
68176+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
68177 struct drm_file *file_priv);
68178
68179-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
68180+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
68181 unsigned long arg);
68182
68183 #define DRM_IOCTL_NR(n) _IOC_NR(n)
68184@@ -311,9 +314,9 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
68185 struct drm_ioctl_desc {
68186 unsigned int cmd;
68187 int flags;
68188- drm_ioctl_t *func;
68189+ drm_ioctl_t func;
68190 unsigned int cmd_drv;
68191-};
68192+} __do_const;
68193
68194 /**
68195 * Creates a driver or general drm_ioctl_desc array entry for the given
68196@@ -995,7 +998,7 @@ struct drm_info_list {
68197 int (*show)(struct seq_file*, void*); /** show callback */
68198 u32 driver_features; /**< Required driver features for this entry */
68199 void *data;
68200-};
68201+} __do_const;
68202
68203 /**
68204 * debugfs node structure. This structure represents a debugfs file.
68205@@ -1068,7 +1071,7 @@ struct drm_device {
68206
68207 /** \name Usage Counters */
68208 /*@{ */
68209- int open_count; /**< Outstanding files open */
68210+ local_t open_count; /**< Outstanding files open */
68211 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
68212 atomic_t vma_count; /**< Outstanding vma areas open */
68213 int buf_use; /**< Buffers in use -- cannot alloc */
68214@@ -1079,7 +1082,7 @@ struct drm_device {
68215 /*@{ */
68216 unsigned long counters;
68217 enum drm_stat_type types[15];
68218- atomic_t counts[15];
68219+ atomic_unchecked_t counts[15];
68220 /*@} */
68221
68222 struct list_head filelist;
68223diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
68224index f43d556..94d9343 100644
68225--- a/include/drm/drm_crtc_helper.h
68226+++ b/include/drm/drm_crtc_helper.h
68227@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
68228 struct drm_connector *connector);
68229 /* disable encoder when not in use - more explicit than dpms off */
68230 void (*disable)(struct drm_encoder *encoder);
68231-};
68232+} __no_const;
68233
68234 /**
68235 * drm_connector_helper_funcs - helper operations for connectors
68236diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
68237index 72dcbe8..8db58d7 100644
68238--- a/include/drm/ttm/ttm_memory.h
68239+++ b/include/drm/ttm/ttm_memory.h
68240@@ -48,7 +48,7 @@
68241
68242 struct ttm_mem_shrink {
68243 int (*do_shrink) (struct ttm_mem_shrink *);
68244-};
68245+} __no_const;
68246
68247 /**
68248 * struct ttm_mem_global - Global memory accounting structure.
68249diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
68250index 4b840e8..155d235 100644
68251--- a/include/keys/asymmetric-subtype.h
68252+++ b/include/keys/asymmetric-subtype.h
68253@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
68254 /* Verify the signature on a key of this subtype (optional) */
68255 int (*verify_signature)(const struct key *key,
68256 const struct public_key_signature *sig);
68257-};
68258+} __do_const;
68259
68260 /**
68261 * asymmetric_key_subtype - Get the subtype from an asymmetric key
68262diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
68263index c1da539..1dcec55 100644
68264--- a/include/linux/atmdev.h
68265+++ b/include/linux/atmdev.h
68266@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
68267 #endif
68268
68269 struct k_atm_aal_stats {
68270-#define __HANDLE_ITEM(i) atomic_t i
68271+#define __HANDLE_ITEM(i) atomic_unchecked_t i
68272 __AAL_STAT_ITEMS
68273 #undef __HANDLE_ITEM
68274 };
68275@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
68276 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
68277 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
68278 struct module *owner;
68279-};
68280+} __do_const ;
68281
68282 struct atmphy_ops {
68283 int (*start)(struct atm_dev *dev);
68284diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
68285index 0530b98..96a8ac0 100644
68286--- a/include/linux/binfmts.h
68287+++ b/include/linux/binfmts.h
68288@@ -73,8 +73,9 @@ struct linux_binfmt {
68289 int (*load_binary)(struct linux_binprm *);
68290 int (*load_shlib)(struct file *);
68291 int (*core_dump)(struct coredump_params *cprm);
68292+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
68293 unsigned long min_coredump; /* minimal dump size */
68294-};
68295+} __do_const;
68296
68297 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
68298
68299diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
68300index f94bc83..62b9cfe 100644
68301--- a/include/linux/blkdev.h
68302+++ b/include/linux/blkdev.h
68303@@ -1498,7 +1498,7 @@ struct block_device_operations {
68304 /* this callback is with swap_lock and sometimes page table lock held */
68305 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
68306 struct module *owner;
68307-};
68308+} __do_const;
68309
68310 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
68311 unsigned long);
68312diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
68313index 7c2e030..b72475d 100644
68314--- a/include/linux/blktrace_api.h
68315+++ b/include/linux/blktrace_api.h
68316@@ -23,7 +23,7 @@ struct blk_trace {
68317 struct dentry *dir;
68318 struct dentry *dropped_file;
68319 struct dentry *msg_file;
68320- atomic_t dropped;
68321+ atomic_unchecked_t dropped;
68322 };
68323
68324 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
68325diff --git a/include/linux/cache.h b/include/linux/cache.h
68326index 4c57065..4307975 100644
68327--- a/include/linux/cache.h
68328+++ b/include/linux/cache.h
68329@@ -16,6 +16,10 @@
68330 #define __read_mostly
68331 #endif
68332
68333+#ifndef __read_only
68334+#define __read_only __read_mostly
68335+#endif
68336+
68337 #ifndef ____cacheline_aligned
68338 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
68339 #endif
68340diff --git a/include/linux/capability.h b/include/linux/capability.h
68341index 98503b7..cc36d18 100644
68342--- a/include/linux/capability.h
68343+++ b/include/linux/capability.h
68344@@ -211,8 +211,13 @@ extern bool capable(int cap);
68345 extern bool ns_capable(struct user_namespace *ns, int cap);
68346 extern bool nsown_capable(int cap);
68347 extern bool inode_capable(const struct inode *inode, int cap);
68348+extern bool capable_nolog(int cap);
68349+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
68350+extern bool inode_capable_nolog(const struct inode *inode, int cap);
68351
68352 /* audit system wants to get cap info from files as well */
68353 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
68354
68355+extern int is_privileged_binary(const struct dentry *dentry);
68356+
68357 #endif /* !_LINUX_CAPABILITY_H */
68358diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
68359index 8609d57..86e4d79 100644
68360--- a/include/linux/cdrom.h
68361+++ b/include/linux/cdrom.h
68362@@ -87,7 +87,6 @@ struct cdrom_device_ops {
68363
68364 /* driver specifications */
68365 const int capability; /* capability flags */
68366- int n_minors; /* number of active minor devices */
68367 /* handle uniform packets for scsi type devices (scsi,atapi) */
68368 int (*generic_packet) (struct cdrom_device_info *,
68369 struct packet_command *);
68370diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
68371index 42e55de..1cd0e66 100644
68372--- a/include/linux/cleancache.h
68373+++ b/include/linux/cleancache.h
68374@@ -31,7 +31,7 @@ struct cleancache_ops {
68375 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
68376 void (*invalidate_inode)(int, struct cleancache_filekey);
68377 void (*invalidate_fs)(int);
68378-};
68379+} __no_const;
68380
68381 extern struct cleancache_ops
68382 cleancache_register_ops(struct cleancache_ops *ops);
68383diff --git a/include/linux/compat.h b/include/linux/compat.h
68384index dec7e2d..45db13f 100644
68385--- a/include/linux/compat.h
68386+++ b/include/linux/compat.h
68387@@ -311,14 +311,14 @@ long compat_sys_msgsnd(int first, int second, int third, void __user *uptr);
68388 long compat_sys_msgrcv(int first, int second, int msgtyp, int third,
68389 int version, void __user *uptr);
68390 long compat_sys_shmat(int first, int second, compat_uptr_t third, int version,
68391- void __user *uptr);
68392+ void __user *uptr) __intentional_overflow(0);
68393 #else
68394 long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
68395 long compat_sys_msgsnd(int msqid, struct compat_msgbuf __user *msgp,
68396 compat_ssize_t msgsz, int msgflg);
68397 long compat_sys_msgrcv(int msqid, struct compat_msgbuf __user *msgp,
68398 compat_ssize_t msgsz, long msgtyp, int msgflg);
68399-long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
68400+long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
68401 #endif
68402 long compat_sys_msgctl(int first, int second, void __user *uptr);
68403 long compat_sys_shmctl(int first, int second, void __user *uptr);
68404@@ -414,7 +414,7 @@ extern int compat_ptrace_request(struct task_struct *child,
68405 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
68406 compat_ulong_t addr, compat_ulong_t data);
68407 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
68408- compat_long_t addr, compat_long_t data);
68409+ compat_ulong_t addr, compat_ulong_t data);
68410
68411 /*
68412 * epoll (fs/eventpoll.c) compat bits follow ...
68413diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
68414index 662fd1b..e801992 100644
68415--- a/include/linux/compiler-gcc4.h
68416+++ b/include/linux/compiler-gcc4.h
68417@@ -34,6 +34,21 @@
68418 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
68419
68420 #if __GNUC_MINOR__ >= 5
68421+
68422+#ifdef CONSTIFY_PLUGIN
68423+#define __no_const __attribute__((no_const))
68424+#define __do_const __attribute__((do_const))
68425+#endif
68426+
68427+#ifdef SIZE_OVERFLOW_PLUGIN
68428+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
68429+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
68430+#endif
68431+
68432+#ifdef LATENT_ENTROPY_PLUGIN
68433+#define __latent_entropy __attribute__((latent_entropy))
68434+#endif
68435+
68436 /*
68437 * Mark a position in code as unreachable. This can be used to
68438 * suppress control flow warnings after asm blocks that transfer
68439@@ -49,6 +64,11 @@
68440 #define __noclone __attribute__((__noclone__))
68441
68442 #endif
68443+
68444+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
68445+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
68446+#define __bos0(ptr) __bos((ptr), 0)
68447+#define __bos1(ptr) __bos((ptr), 1)
68448 #endif
68449
68450 #if __GNUC_MINOR__ >= 6
68451diff --git a/include/linux/compiler.h b/include/linux/compiler.h
68452index dd852b7..1ad5fba 100644
68453--- a/include/linux/compiler.h
68454+++ b/include/linux/compiler.h
68455@@ -5,11 +5,14 @@
68456
68457 #ifdef __CHECKER__
68458 # define __user __attribute__((noderef, address_space(1)))
68459+# define __force_user __force __user
68460 # define __kernel __attribute__((address_space(0)))
68461+# define __force_kernel __force __kernel
68462 # define __safe __attribute__((safe))
68463 # define __force __attribute__((force))
68464 # define __nocast __attribute__((nocast))
68465 # define __iomem __attribute__((noderef, address_space(2)))
68466+# define __force_iomem __force __iomem
68467 # define __must_hold(x) __attribute__((context(x,1,1)))
68468 # define __acquires(x) __attribute__((context(x,0,1)))
68469 # define __releases(x) __attribute__((context(x,1,0)))
68470@@ -17,20 +20,37 @@
68471 # define __release(x) __context__(x,-1)
68472 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
68473 # define __percpu __attribute__((noderef, address_space(3)))
68474+# define __force_percpu __force __percpu
68475 #ifdef CONFIG_SPARSE_RCU_POINTER
68476 # define __rcu __attribute__((noderef, address_space(4)))
68477+# define __force_rcu __force __rcu
68478 #else
68479 # define __rcu
68480+# define __force_rcu
68481 #endif
68482 extern void __chk_user_ptr(const volatile void __user *);
68483 extern void __chk_io_ptr(const volatile void __iomem *);
68484 #else
68485-# define __user
68486-# define __kernel
68487+# ifdef CHECKER_PLUGIN
68488+//# define __user
68489+//# define __force_user
68490+//# define __kernel
68491+//# define __force_kernel
68492+# else
68493+# ifdef STRUCTLEAK_PLUGIN
68494+# define __user __attribute__((user))
68495+# else
68496+# define __user
68497+# endif
68498+# define __force_user
68499+# define __kernel
68500+# define __force_kernel
68501+# endif
68502 # define __safe
68503 # define __force
68504 # define __nocast
68505 # define __iomem
68506+# define __force_iomem
68507 # define __chk_user_ptr(x) (void)0
68508 # define __chk_io_ptr(x) (void)0
68509 # define __builtin_warning(x, y...) (1)
68510@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
68511 # define __release(x) (void)0
68512 # define __cond_lock(x,c) (c)
68513 # define __percpu
68514+# define __force_percpu
68515 # define __rcu
68516+# define __force_rcu
68517 #endif
68518
68519 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
68520@@ -275,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
68521 # define __attribute_const__ /* unimplemented */
68522 #endif
68523
68524+#ifndef __no_const
68525+# define __no_const
68526+#endif
68527+
68528+#ifndef __do_const
68529+# define __do_const
68530+#endif
68531+
68532+#ifndef __size_overflow
68533+# define __size_overflow(...)
68534+#endif
68535+
68536+#ifndef __intentional_overflow
68537+# define __intentional_overflow(...)
68538+#endif
68539+
68540+#ifndef __latent_entropy
68541+# define __latent_entropy
68542+#endif
68543+
68544 /*
68545 * Tell gcc if a function is cold. The compiler will assume any path
68546 * directly leading to the call is unlikely.
68547@@ -284,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
68548 #define __cold
68549 #endif
68550
68551+#ifndef __alloc_size
68552+#define __alloc_size(...)
68553+#endif
68554+
68555+#ifndef __bos
68556+#define __bos(ptr, arg)
68557+#endif
68558+
68559+#ifndef __bos0
68560+#define __bos0(ptr)
68561+#endif
68562+
68563+#ifndef __bos1
68564+#define __bos1(ptr)
68565+#endif
68566+
68567 /* Simple shorthand for a section definition */
68568 #ifndef __section
68569 # define __section(S) __attribute__ ((__section__(#S)))
68570@@ -323,6 +381,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
68571 * use is to mediate communication between process-level code and irq/NMI
68572 * handlers, all running on the same CPU.
68573 */
68574-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
68575+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
68576+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
68577
68578 #endif /* __LINUX_COMPILER_H */
68579diff --git a/include/linux/completion.h b/include/linux/completion.h
68580index 51494e6..0fd1b61 100644
68581--- a/include/linux/completion.h
68582+++ b/include/linux/completion.h
68583@@ -78,13 +78,13 @@ static inline void init_completion(struct completion *x)
68584
68585 extern void wait_for_completion(struct completion *);
68586 extern int wait_for_completion_interruptible(struct completion *x);
68587-extern int wait_for_completion_killable(struct completion *x);
68588+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
68589 extern unsigned long wait_for_completion_timeout(struct completion *x,
68590 unsigned long timeout);
68591 extern long wait_for_completion_interruptible_timeout(
68592- struct completion *x, unsigned long timeout);
68593+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
68594 extern long wait_for_completion_killable_timeout(
68595- struct completion *x, unsigned long timeout);
68596+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
68597 extern bool try_wait_for_completion(struct completion *x);
68598 extern bool completion_done(struct completion *x);
68599
68600diff --git a/include/linux/configfs.h b/include/linux/configfs.h
68601index 34025df..d94bbbc 100644
68602--- a/include/linux/configfs.h
68603+++ b/include/linux/configfs.h
68604@@ -125,7 +125,7 @@ struct configfs_attribute {
68605 const char *ca_name;
68606 struct module *ca_owner;
68607 umode_t ca_mode;
68608-};
68609+} __do_const;
68610
68611 /*
68612 * Users often need to create attribute structures for their configurable
68613diff --git a/include/linux/cpu.h b/include/linux/cpu.h
68614index ce7a074..01ab8ac 100644
68615--- a/include/linux/cpu.h
68616+++ b/include/linux/cpu.h
68617@@ -115,7 +115,7 @@ enum {
68618 /* Need to know about CPUs going up/down? */
68619 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
68620 #define cpu_notifier(fn, pri) { \
68621- static struct notifier_block fn##_nb __cpuinitdata = \
68622+ static struct notifier_block fn##_nb = \
68623 { .notifier_call = fn, .priority = pri }; \
68624 register_cpu_notifier(&fn##_nb); \
68625 }
68626diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
68627index a55b88e..fba90c5 100644
68628--- a/include/linux/cpufreq.h
68629+++ b/include/linux/cpufreq.h
68630@@ -240,7 +240,7 @@ struct cpufreq_driver {
68631 int (*suspend) (struct cpufreq_policy *policy);
68632 int (*resume) (struct cpufreq_policy *policy);
68633 struct freq_attr **attr;
68634-};
68635+} __do_const;
68636
68637 /* flags */
68638
68639@@ -299,6 +299,7 @@ struct global_attr {
68640 ssize_t (*store)(struct kobject *a, struct attribute *b,
68641 const char *c, size_t count);
68642 };
68643+typedef struct global_attr __no_const global_attr_no_const;
68644
68645 #define define_one_global_ro(_name) \
68646 static struct global_attr _name = \
68647diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
68648index 24cd1037..20a63aae 100644
68649--- a/include/linux/cpuidle.h
68650+++ b/include/linux/cpuidle.h
68651@@ -54,7 +54,8 @@ struct cpuidle_state {
68652 int index);
68653
68654 int (*enter_dead) (struct cpuidle_device *dev, int index);
68655-};
68656+} __do_const;
68657+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
68658
68659 /* Idle State Flags */
68660 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
68661@@ -216,7 +217,7 @@ struct cpuidle_governor {
68662 void (*reflect) (struct cpuidle_device *dev, int index);
68663
68664 struct module *owner;
68665-};
68666+} __do_const;
68667
68668 #ifdef CONFIG_CPU_IDLE
68669
68670diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
68671index 0325602..5e9feff 100644
68672--- a/include/linux/cpumask.h
68673+++ b/include/linux/cpumask.h
68674@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
68675 }
68676
68677 /* Valid inputs for n are -1 and 0. */
68678-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
68679+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
68680 {
68681 return n+1;
68682 }
68683
68684-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
68685+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
68686 {
68687 return n+1;
68688 }
68689
68690-static inline unsigned int cpumask_next_and(int n,
68691+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
68692 const struct cpumask *srcp,
68693 const struct cpumask *andp)
68694 {
68695@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
68696 *
68697 * Returns >= nr_cpu_ids if no further cpus set.
68698 */
68699-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
68700+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
68701 {
68702 /* -1 is a legal arg here. */
68703 if (n != -1)
68704@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
68705 *
68706 * Returns >= nr_cpu_ids if no further cpus unset.
68707 */
68708-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
68709+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
68710 {
68711 /* -1 is a legal arg here. */
68712 if (n != -1)
68713@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
68714 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
68715 }
68716
68717-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
68718+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
68719 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
68720
68721 /**
68722diff --git a/include/linux/cred.h b/include/linux/cred.h
68723index 04421e8..6bce4ef 100644
68724--- a/include/linux/cred.h
68725+++ b/include/linux/cred.h
68726@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
68727 static inline void validate_process_creds(void)
68728 {
68729 }
68730+static inline void validate_task_creds(struct task_struct *task)
68731+{
68732+}
68733 #endif
68734
68735 /**
68736diff --git a/include/linux/crypto.h b/include/linux/crypto.h
68737index b92eadf..b4ecdc1 100644
68738--- a/include/linux/crypto.h
68739+++ b/include/linux/crypto.h
68740@@ -373,7 +373,7 @@ struct cipher_tfm {
68741 const u8 *key, unsigned int keylen);
68742 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
68743 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
68744-};
68745+} __no_const;
68746
68747 struct hash_tfm {
68748 int (*init)(struct hash_desc *desc);
68749@@ -394,13 +394,13 @@ struct compress_tfm {
68750 int (*cot_decompress)(struct crypto_tfm *tfm,
68751 const u8 *src, unsigned int slen,
68752 u8 *dst, unsigned int *dlen);
68753-};
68754+} __no_const;
68755
68756 struct rng_tfm {
68757 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
68758 unsigned int dlen);
68759 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
68760-};
68761+} __no_const;
68762
68763 #define crt_ablkcipher crt_u.ablkcipher
68764 #define crt_aead crt_u.aead
68765diff --git a/include/linux/ctype.h b/include/linux/ctype.h
68766index 8acfe31..6ffccd63 100644
68767--- a/include/linux/ctype.h
68768+++ b/include/linux/ctype.h
68769@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
68770 * Fast implementation of tolower() for internal usage. Do not use in your
68771 * code.
68772 */
68773-static inline char _tolower(const char c)
68774+static inline unsigned char _tolower(const unsigned char c)
68775 {
68776 return c | 0x20;
68777 }
68778diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
68779index 7925bf0..d5143d2 100644
68780--- a/include/linux/decompress/mm.h
68781+++ b/include/linux/decompress/mm.h
68782@@ -77,7 +77,7 @@ static void free(void *where)
68783 * warnings when not needed (indeed large_malloc / large_free are not
68784 * needed by inflate */
68785
68786-#define malloc(a) kmalloc(a, GFP_KERNEL)
68787+#define malloc(a) kmalloc((a), GFP_KERNEL)
68788 #define free(a) kfree(a)
68789
68790 #define large_malloc(a) vmalloc(a)
68791diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
68792index e83ef39..33e0eb3 100644
68793--- a/include/linux/devfreq.h
68794+++ b/include/linux/devfreq.h
68795@@ -114,7 +114,7 @@ struct devfreq_governor {
68796 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
68797 int (*event_handler)(struct devfreq *devfreq,
68798 unsigned int event, void *data);
68799-};
68800+} __do_const;
68801
68802 /**
68803 * struct devfreq - Device devfreq structure
68804diff --git a/include/linux/device.h b/include/linux/device.h
68805index 43dcda9..7a1fb65 100644
68806--- a/include/linux/device.h
68807+++ b/include/linux/device.h
68808@@ -294,7 +294,7 @@ struct subsys_interface {
68809 struct list_head node;
68810 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
68811 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
68812-};
68813+} __do_const;
68814
68815 int subsys_interface_register(struct subsys_interface *sif);
68816 void subsys_interface_unregister(struct subsys_interface *sif);
68817@@ -474,7 +474,7 @@ struct device_type {
68818 void (*release)(struct device *dev);
68819
68820 const struct dev_pm_ops *pm;
68821-};
68822+} __do_const;
68823
68824 /* interface for exporting device attributes */
68825 struct device_attribute {
68826@@ -484,11 +484,12 @@ struct device_attribute {
68827 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
68828 const char *buf, size_t count);
68829 };
68830+typedef struct device_attribute __no_const device_attribute_no_const;
68831
68832 struct dev_ext_attribute {
68833 struct device_attribute attr;
68834 void *var;
68835-};
68836+} __do_const;
68837
68838 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
68839 char *buf);
68840diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
68841index 94af418..b1ca7a2 100644
68842--- a/include/linux/dma-mapping.h
68843+++ b/include/linux/dma-mapping.h
68844@@ -54,7 +54,7 @@ struct dma_map_ops {
68845 u64 (*get_required_mask)(struct device *dev);
68846 #endif
68847 int is_phys;
68848-};
68849+} __do_const;
68850
68851 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
68852
68853diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
68854index d3201e4..8281e63 100644
68855--- a/include/linux/dmaengine.h
68856+++ b/include/linux/dmaengine.h
68857@@ -1018,9 +1018,9 @@ struct dma_pinned_list {
68858 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
68859 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
68860
68861-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
68862+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
68863 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
68864-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
68865+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
68866 struct dma_pinned_list *pinned_list, struct page *page,
68867 unsigned int offset, size_t len);
68868
68869diff --git a/include/linux/efi.h b/include/linux/efi.h
68870index 7a9498a..155713d 100644
68871--- a/include/linux/efi.h
68872+++ b/include/linux/efi.h
68873@@ -733,6 +733,7 @@ struct efivar_operations {
68874 efi_set_variable_t *set_variable;
68875 efi_query_variable_info_t *query_variable_info;
68876 };
68877+typedef struct efivar_operations __no_const efivar_operations_no_const;
68878
68879 struct efivars {
68880 /*
68881diff --git a/include/linux/elf.h b/include/linux/elf.h
68882index 8c9048e..16a4665 100644
68883--- a/include/linux/elf.h
68884+++ b/include/linux/elf.h
68885@@ -20,6 +20,7 @@ extern Elf32_Dyn _DYNAMIC [];
68886 #define elf_note elf32_note
68887 #define elf_addr_t Elf32_Off
68888 #define Elf_Half Elf32_Half
68889+#define elf_dyn Elf32_Dyn
68890
68891 #else
68892
68893@@ -30,6 +31,7 @@ extern Elf64_Dyn _DYNAMIC [];
68894 #define elf_note elf64_note
68895 #define elf_addr_t Elf64_Off
68896 #define Elf_Half Elf64_Half
68897+#define elf_dyn Elf64_Dyn
68898
68899 #endif
68900
68901diff --git a/include/linux/err.h b/include/linux/err.h
68902index f2edce2..cc2082c 100644
68903--- a/include/linux/err.h
68904+++ b/include/linux/err.h
68905@@ -19,12 +19,12 @@
68906
68907 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
68908
68909-static inline void * __must_check ERR_PTR(long error)
68910+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
68911 {
68912 return (void *) error;
68913 }
68914
68915-static inline long __must_check PTR_ERR(const void *ptr)
68916+static inline long __must_check __intentional_overflow(-1) PTR_ERR(const void *ptr)
68917 {
68918 return (long) ptr;
68919 }
68920diff --git a/include/linux/extcon.h b/include/linux/extcon.h
68921index fcb51c8..bdafcf6 100644
68922--- a/include/linux/extcon.h
68923+++ b/include/linux/extcon.h
68924@@ -134,7 +134,7 @@ struct extcon_dev {
68925 /* /sys/class/extcon/.../mutually_exclusive/... */
68926 struct attribute_group attr_g_muex;
68927 struct attribute **attrs_muex;
68928- struct device_attribute *d_attrs_muex;
68929+ device_attribute_no_const *d_attrs_muex;
68930 };
68931
68932 /**
68933diff --git a/include/linux/fb.h b/include/linux/fb.h
68934index c7a9571..02eeffe 100644
68935--- a/include/linux/fb.h
68936+++ b/include/linux/fb.h
68937@@ -302,7 +302,7 @@ struct fb_ops {
68938 /* called at KDB enter and leave time to prepare the console */
68939 int (*fb_debug_enter)(struct fb_info *info);
68940 int (*fb_debug_leave)(struct fb_info *info);
68941-};
68942+} __do_const;
68943
68944 #ifdef CONFIG_FB_TILEBLITTING
68945 #define FB_TILE_CURSOR_NONE 0
68946diff --git a/include/linux/filter.h b/include/linux/filter.h
68947index c45eabc..baa0be5 100644
68948--- a/include/linux/filter.h
68949+++ b/include/linux/filter.h
68950@@ -20,6 +20,7 @@ struct compat_sock_fprog {
68951
68952 struct sk_buff;
68953 struct sock;
68954+struct bpf_jit_work;
68955
68956 struct sk_filter
68957 {
68958@@ -27,6 +28,9 @@ struct sk_filter
68959 unsigned int len; /* Number of filter blocks */
68960 unsigned int (*bpf_func)(const struct sk_buff *skb,
68961 const struct sock_filter *filter);
68962+#ifdef CONFIG_BPF_JIT
68963+ struct bpf_jit_work *work;
68964+#endif
68965 struct rcu_head rcu;
68966 struct sock_filter insns[0];
68967 };
68968diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
68969index 3044254..9767f41 100644
68970--- a/include/linux/frontswap.h
68971+++ b/include/linux/frontswap.h
68972@@ -11,7 +11,7 @@ struct frontswap_ops {
68973 int (*load)(unsigned, pgoff_t, struct page *);
68974 void (*invalidate_page)(unsigned, pgoff_t);
68975 void (*invalidate_area)(unsigned);
68976-};
68977+} __no_const;
68978
68979 extern bool frontswap_enabled;
68980 extern struct frontswap_ops
68981diff --git a/include/linux/fs.h b/include/linux/fs.h
68982index 7617ee0..b575199 100644
68983--- a/include/linux/fs.h
68984+++ b/include/linux/fs.h
68985@@ -1541,7 +1541,8 @@ struct file_operations {
68986 long (*fallocate)(struct file *file, int mode, loff_t offset,
68987 loff_t len);
68988 int (*show_fdinfo)(struct seq_file *m, struct file *f);
68989-};
68990+} __do_const;
68991+typedef struct file_operations __no_const file_operations_no_const;
68992
68993 struct inode_operations {
68994 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
68995@@ -2665,4 +2666,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
68996 inode->i_flags |= S_NOSEC;
68997 }
68998
68999+static inline bool is_sidechannel_device(const struct inode *inode)
69000+{
69001+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
69002+ umode_t mode = inode->i_mode;
69003+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
69004+#else
69005+ return false;
69006+#endif
69007+}
69008+
69009 #endif /* _LINUX_FS_H */
69010diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
69011index 324f931..f292b65 100644
69012--- a/include/linux/fs_struct.h
69013+++ b/include/linux/fs_struct.h
69014@@ -6,7 +6,7 @@
69015 #include <linux/seqlock.h>
69016
69017 struct fs_struct {
69018- int users;
69019+ atomic_t users;
69020 spinlock_t lock;
69021 seqcount_t seq;
69022 int umask;
69023diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
69024index 5dfa0aa..6acf322 100644
69025--- a/include/linux/fscache-cache.h
69026+++ b/include/linux/fscache-cache.h
69027@@ -112,7 +112,7 @@ struct fscache_operation {
69028 fscache_operation_release_t release;
69029 };
69030
69031-extern atomic_t fscache_op_debug_id;
69032+extern atomic_unchecked_t fscache_op_debug_id;
69033 extern void fscache_op_work_func(struct work_struct *work);
69034
69035 extern void fscache_enqueue_operation(struct fscache_operation *);
69036@@ -134,7 +134,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
69037 INIT_WORK(&op->work, fscache_op_work_func);
69038 atomic_set(&op->usage, 1);
69039 op->state = FSCACHE_OP_ST_INITIALISED;
69040- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
69041+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
69042 op->processor = processor;
69043 op->release = release;
69044 INIT_LIST_HEAD(&op->pend_link);
69045diff --git a/include/linux/fscache.h b/include/linux/fscache.h
69046index 7a08623..4c07b0f 100644
69047--- a/include/linux/fscache.h
69048+++ b/include/linux/fscache.h
69049@@ -152,7 +152,7 @@ struct fscache_cookie_def {
69050 * - this is mandatory for any object that may have data
69051 */
69052 void (*now_uncached)(void *cookie_netfs_data);
69053-};
69054+} __do_const;
69055
69056 /*
69057 * fscache cached network filesystem type
69058diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
69059index 0fbfb46..508eb0d 100644
69060--- a/include/linux/fsnotify.h
69061+++ b/include/linux/fsnotify.h
69062@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
69063 struct inode *inode = path->dentry->d_inode;
69064 __u32 mask = FS_ACCESS;
69065
69066+ if (is_sidechannel_device(inode))
69067+ return;
69068+
69069 if (S_ISDIR(inode->i_mode))
69070 mask |= FS_ISDIR;
69071
69072@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
69073 struct inode *inode = path->dentry->d_inode;
69074 __u32 mask = FS_MODIFY;
69075
69076+ if (is_sidechannel_device(inode))
69077+ return;
69078+
69079 if (S_ISDIR(inode->i_mode))
69080 mask |= FS_ISDIR;
69081
69082@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
69083 */
69084 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
69085 {
69086- return kstrdup(name, GFP_KERNEL);
69087+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
69088 }
69089
69090 /*
69091diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
69092index a3d4895..ddd2a50 100644
69093--- a/include/linux/ftrace_event.h
69094+++ b/include/linux/ftrace_event.h
69095@@ -272,7 +272,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
69096 extern int trace_add_event_call(struct ftrace_event_call *call);
69097 extern void trace_remove_event_call(struct ftrace_event_call *call);
69098
69099-#define is_signed_type(type) (((type)(-1)) < 0)
69100+#define is_signed_type(type) (((type)(-1)) < (type)1)
69101
69102 int trace_set_clr_event(const char *system, const char *event, int set);
69103
69104diff --git a/include/linux/genhd.h b/include/linux/genhd.h
69105index 79b8bba..86b539e 100644
69106--- a/include/linux/genhd.h
69107+++ b/include/linux/genhd.h
69108@@ -194,7 +194,7 @@ struct gendisk {
69109 struct kobject *slave_dir;
69110
69111 struct timer_rand_state *random;
69112- atomic_t sync_io; /* RAID */
69113+ atomic_unchecked_t sync_io; /* RAID */
69114 struct disk_events *ev;
69115 #ifdef CONFIG_BLK_DEV_INTEGRITY
69116 struct blk_integrity *integrity;
69117diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
69118index 023bc34..b02b46a 100644
69119--- a/include/linux/genl_magic_func.h
69120+++ b/include/linux/genl_magic_func.h
69121@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
69122 },
69123
69124 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
69125-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
69126+static struct genl_ops ZZZ_genl_ops[] = {
69127 #include GENL_MAGIC_INCLUDE_FILE
69128 };
69129
69130diff --git a/include/linux/gfp.h b/include/linux/gfp.h
69131index 0f615eb..5c3832f 100644
69132--- a/include/linux/gfp.h
69133+++ b/include/linux/gfp.h
69134@@ -35,6 +35,13 @@ struct vm_area_struct;
69135 #define ___GFP_NO_KSWAPD 0x400000u
69136 #define ___GFP_OTHER_NODE 0x800000u
69137 #define ___GFP_WRITE 0x1000000u
69138+
69139+#ifdef CONFIG_PAX_USERCOPY_SLABS
69140+#define ___GFP_USERCOPY 0x2000000u
69141+#else
69142+#define ___GFP_USERCOPY 0
69143+#endif
69144+
69145 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
69146
69147 /*
69148@@ -92,6 +99,7 @@ struct vm_area_struct;
69149 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
69150 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
69151 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
69152+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
69153
69154 /*
69155 * This may seem redundant, but it's a way of annotating false positives vs.
69156@@ -99,7 +107,7 @@ struct vm_area_struct;
69157 */
69158 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
69159
69160-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
69161+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
69162 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
69163
69164 /* This equals 0, but use constants in case they ever change */
69165@@ -153,6 +161,8 @@ struct vm_area_struct;
69166 /* 4GB DMA on some platforms */
69167 #define GFP_DMA32 __GFP_DMA32
69168
69169+#define GFP_USERCOPY __GFP_USERCOPY
69170+
69171 /* Convert GFP flags to their corresponding migrate type */
69172 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
69173 {
69174diff --git a/include/linux/gracl.h b/include/linux/gracl.h
69175new file mode 100644
69176index 0000000..ebe6d72
69177--- /dev/null
69178+++ b/include/linux/gracl.h
69179@@ -0,0 +1,319 @@
69180+#ifndef GR_ACL_H
69181+#define GR_ACL_H
69182+
69183+#include <linux/grdefs.h>
69184+#include <linux/resource.h>
69185+#include <linux/capability.h>
69186+#include <linux/dcache.h>
69187+#include <asm/resource.h>
69188+
69189+/* Major status information */
69190+
69191+#define GR_VERSION "grsecurity 2.9.1"
69192+#define GRSECURITY_VERSION 0x2901
69193+
69194+enum {
69195+ GR_SHUTDOWN = 0,
69196+ GR_ENABLE = 1,
69197+ GR_SPROLE = 2,
69198+ GR_RELOAD = 3,
69199+ GR_SEGVMOD = 4,
69200+ GR_STATUS = 5,
69201+ GR_UNSPROLE = 6,
69202+ GR_PASSSET = 7,
69203+ GR_SPROLEPAM = 8,
69204+};
69205+
69206+/* Password setup definitions
69207+ * kernel/grhash.c */
69208+enum {
69209+ GR_PW_LEN = 128,
69210+ GR_SALT_LEN = 16,
69211+ GR_SHA_LEN = 32,
69212+};
69213+
69214+enum {
69215+ GR_SPROLE_LEN = 64,
69216+};
69217+
69218+enum {
69219+ GR_NO_GLOB = 0,
69220+ GR_REG_GLOB,
69221+ GR_CREATE_GLOB
69222+};
69223+
69224+#define GR_NLIMITS 32
69225+
69226+/* Begin Data Structures */
69227+
69228+struct sprole_pw {
69229+ unsigned char *rolename;
69230+ unsigned char salt[GR_SALT_LEN];
69231+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
69232+};
69233+
69234+struct name_entry {
69235+ __u32 key;
69236+ ino_t inode;
69237+ dev_t device;
69238+ char *name;
69239+ __u16 len;
69240+ __u8 deleted;
69241+ struct name_entry *prev;
69242+ struct name_entry *next;
69243+};
69244+
69245+struct inodev_entry {
69246+ struct name_entry *nentry;
69247+ struct inodev_entry *prev;
69248+ struct inodev_entry *next;
69249+};
69250+
69251+struct acl_role_db {
69252+ struct acl_role_label **r_hash;
69253+ __u32 r_size;
69254+};
69255+
69256+struct inodev_db {
69257+ struct inodev_entry **i_hash;
69258+ __u32 i_size;
69259+};
69260+
69261+struct name_db {
69262+ struct name_entry **n_hash;
69263+ __u32 n_size;
69264+};
69265+
69266+struct crash_uid {
69267+ uid_t uid;
69268+ unsigned long expires;
69269+};
69270+
69271+struct gr_hash_struct {
69272+ void **table;
69273+ void **nametable;
69274+ void *first;
69275+ __u32 table_size;
69276+ __u32 used_size;
69277+ int type;
69278+};
69279+
69280+/* Userspace Grsecurity ACL data structures */
69281+
69282+struct acl_subject_label {
69283+ char *filename;
69284+ ino_t inode;
69285+ dev_t device;
69286+ __u32 mode;
69287+ kernel_cap_t cap_mask;
69288+ kernel_cap_t cap_lower;
69289+ kernel_cap_t cap_invert_audit;
69290+
69291+ struct rlimit res[GR_NLIMITS];
69292+ __u32 resmask;
69293+
69294+ __u8 user_trans_type;
69295+ __u8 group_trans_type;
69296+ uid_t *user_transitions;
69297+ gid_t *group_transitions;
69298+ __u16 user_trans_num;
69299+ __u16 group_trans_num;
69300+
69301+ __u32 sock_families[2];
69302+ __u32 ip_proto[8];
69303+ __u32 ip_type;
69304+ struct acl_ip_label **ips;
69305+ __u32 ip_num;
69306+ __u32 inaddr_any_override;
69307+
69308+ __u32 crashes;
69309+ unsigned long expires;
69310+
69311+ struct acl_subject_label *parent_subject;
69312+ struct gr_hash_struct *hash;
69313+ struct acl_subject_label *prev;
69314+ struct acl_subject_label *next;
69315+
69316+ struct acl_object_label **obj_hash;
69317+ __u32 obj_hash_size;
69318+ __u16 pax_flags;
69319+};
69320+
69321+struct role_allowed_ip {
69322+ __u32 addr;
69323+ __u32 netmask;
69324+
69325+ struct role_allowed_ip *prev;
69326+ struct role_allowed_ip *next;
69327+};
69328+
69329+struct role_transition {
69330+ char *rolename;
69331+
69332+ struct role_transition *prev;
69333+ struct role_transition *next;
69334+};
69335+
69336+struct acl_role_label {
69337+ char *rolename;
69338+ uid_t uidgid;
69339+ __u16 roletype;
69340+
69341+ __u16 auth_attempts;
69342+ unsigned long expires;
69343+
69344+ struct acl_subject_label *root_label;
69345+ struct gr_hash_struct *hash;
69346+
69347+ struct acl_role_label *prev;
69348+ struct acl_role_label *next;
69349+
69350+ struct role_transition *transitions;
69351+ struct role_allowed_ip *allowed_ips;
69352+ uid_t *domain_children;
69353+ __u16 domain_child_num;
69354+
69355+ umode_t umask;
69356+
69357+ struct acl_subject_label **subj_hash;
69358+ __u32 subj_hash_size;
69359+};
69360+
69361+struct user_acl_role_db {
69362+ struct acl_role_label **r_table;
69363+ __u32 num_pointers; /* Number of allocations to track */
69364+ __u32 num_roles; /* Number of roles */
69365+ __u32 num_domain_children; /* Number of domain children */
69366+ __u32 num_subjects; /* Number of subjects */
69367+ __u32 num_objects; /* Number of objects */
69368+};
69369+
69370+struct acl_object_label {
69371+ char *filename;
69372+ ino_t inode;
69373+ dev_t device;
69374+ __u32 mode;
69375+
69376+ struct acl_subject_label *nested;
69377+ struct acl_object_label *globbed;
69378+
69379+ /* next two structures not used */
69380+
69381+ struct acl_object_label *prev;
69382+ struct acl_object_label *next;
69383+};
69384+
69385+struct acl_ip_label {
69386+ char *iface;
69387+ __u32 addr;
69388+ __u32 netmask;
69389+ __u16 low, high;
69390+ __u8 mode;
69391+ __u32 type;
69392+ __u32 proto[8];
69393+
69394+ /* next two structures not used */
69395+
69396+ struct acl_ip_label *prev;
69397+ struct acl_ip_label *next;
69398+};
69399+
69400+struct gr_arg {
69401+ struct user_acl_role_db role_db;
69402+ unsigned char pw[GR_PW_LEN];
69403+ unsigned char salt[GR_SALT_LEN];
69404+ unsigned char sum[GR_SHA_LEN];
69405+ unsigned char sp_role[GR_SPROLE_LEN];
69406+ struct sprole_pw *sprole_pws;
69407+ dev_t segv_device;
69408+ ino_t segv_inode;
69409+ uid_t segv_uid;
69410+ __u16 num_sprole_pws;
69411+ __u16 mode;
69412+};
69413+
69414+struct gr_arg_wrapper {
69415+ struct gr_arg *arg;
69416+ __u32 version;
69417+ __u32 size;
69418+};
69419+
69420+struct subject_map {
69421+ struct acl_subject_label *user;
69422+ struct acl_subject_label *kernel;
69423+ struct subject_map *prev;
69424+ struct subject_map *next;
69425+};
69426+
69427+struct acl_subj_map_db {
69428+ struct subject_map **s_hash;
69429+ __u32 s_size;
69430+};
69431+
69432+/* End Data Structures Section */
69433+
69434+/* Hash functions generated by empirical testing by Brad Spengler
69435+ Makes good use of the low bits of the inode. Generally 0-1 times
69436+ in loop for successful match. 0-3 for unsuccessful match.
69437+ Shift/add algorithm with modulus of table size and an XOR*/
69438+
69439+static __inline__ unsigned int
69440+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
69441+{
69442+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
69443+}
69444+
69445+ static __inline__ unsigned int
69446+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
69447+{
69448+ return ((const unsigned long)userp % sz);
69449+}
69450+
69451+static __inline__ unsigned int
69452+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
69453+{
69454+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
69455+}
69456+
69457+static __inline__ unsigned int
69458+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
69459+{
69460+ return full_name_hash((const unsigned char *)name, len) % sz;
69461+}
69462+
69463+#define FOR_EACH_ROLE_START(role) \
69464+ role = role_list; \
69465+ while (role) {
69466+
69467+#define FOR_EACH_ROLE_END(role) \
69468+ role = role->prev; \
69469+ }
69470+
69471+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
69472+ subj = NULL; \
69473+ iter = 0; \
69474+ while (iter < role->subj_hash_size) { \
69475+ if (subj == NULL) \
69476+ subj = role->subj_hash[iter]; \
69477+ if (subj == NULL) { \
69478+ iter++; \
69479+ continue; \
69480+ }
69481+
69482+#define FOR_EACH_SUBJECT_END(subj,iter) \
69483+ subj = subj->next; \
69484+ if (subj == NULL) \
69485+ iter++; \
69486+ }
69487+
69488+
69489+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
69490+ subj = role->hash->first; \
69491+ while (subj != NULL) {
69492+
69493+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
69494+ subj = subj->next; \
69495+ }
69496+
69497+#endif
69498+
69499diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
69500new file mode 100644
69501index 0000000..323ecf2
69502--- /dev/null
69503+++ b/include/linux/gralloc.h
69504@@ -0,0 +1,9 @@
69505+#ifndef __GRALLOC_H
69506+#define __GRALLOC_H
69507+
69508+void acl_free_all(void);
69509+int acl_alloc_stack_init(unsigned long size);
69510+void *acl_alloc(unsigned long len);
69511+void *acl_alloc_num(unsigned long num, unsigned long len);
69512+
69513+#endif
69514diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
69515new file mode 100644
69516index 0000000..be66033
69517--- /dev/null
69518+++ b/include/linux/grdefs.h
69519@@ -0,0 +1,140 @@
69520+#ifndef GRDEFS_H
69521+#define GRDEFS_H
69522+
69523+/* Begin grsecurity status declarations */
69524+
69525+enum {
69526+ GR_READY = 0x01,
69527+ GR_STATUS_INIT = 0x00 // disabled state
69528+};
69529+
69530+/* Begin ACL declarations */
69531+
69532+/* Role flags */
69533+
69534+enum {
69535+ GR_ROLE_USER = 0x0001,
69536+ GR_ROLE_GROUP = 0x0002,
69537+ GR_ROLE_DEFAULT = 0x0004,
69538+ GR_ROLE_SPECIAL = 0x0008,
69539+ GR_ROLE_AUTH = 0x0010,
69540+ GR_ROLE_NOPW = 0x0020,
69541+ GR_ROLE_GOD = 0x0040,
69542+ GR_ROLE_LEARN = 0x0080,
69543+ GR_ROLE_TPE = 0x0100,
69544+ GR_ROLE_DOMAIN = 0x0200,
69545+ GR_ROLE_PAM = 0x0400,
69546+ GR_ROLE_PERSIST = 0x0800
69547+};
69548+
69549+/* ACL Subject and Object mode flags */
69550+enum {
69551+ GR_DELETED = 0x80000000
69552+};
69553+
69554+/* ACL Object-only mode flags */
69555+enum {
69556+ GR_READ = 0x00000001,
69557+ GR_APPEND = 0x00000002,
69558+ GR_WRITE = 0x00000004,
69559+ GR_EXEC = 0x00000008,
69560+ GR_FIND = 0x00000010,
69561+ GR_INHERIT = 0x00000020,
69562+ GR_SETID = 0x00000040,
69563+ GR_CREATE = 0x00000080,
69564+ GR_DELETE = 0x00000100,
69565+ GR_LINK = 0x00000200,
69566+ GR_AUDIT_READ = 0x00000400,
69567+ GR_AUDIT_APPEND = 0x00000800,
69568+ GR_AUDIT_WRITE = 0x00001000,
69569+ GR_AUDIT_EXEC = 0x00002000,
69570+ GR_AUDIT_FIND = 0x00004000,
69571+ GR_AUDIT_INHERIT= 0x00008000,
69572+ GR_AUDIT_SETID = 0x00010000,
69573+ GR_AUDIT_CREATE = 0x00020000,
69574+ GR_AUDIT_DELETE = 0x00040000,
69575+ GR_AUDIT_LINK = 0x00080000,
69576+ GR_PTRACERD = 0x00100000,
69577+ GR_NOPTRACE = 0x00200000,
69578+ GR_SUPPRESS = 0x00400000,
69579+ GR_NOLEARN = 0x00800000,
69580+ GR_INIT_TRANSFER= 0x01000000
69581+};
69582+
69583+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
69584+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
69585+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
69586+
69587+/* ACL subject-only mode flags */
69588+enum {
69589+ GR_KILL = 0x00000001,
69590+ GR_VIEW = 0x00000002,
69591+ GR_PROTECTED = 0x00000004,
69592+ GR_LEARN = 0x00000008,
69593+ GR_OVERRIDE = 0x00000010,
69594+ /* just a placeholder, this mode is only used in userspace */
69595+ GR_DUMMY = 0x00000020,
69596+ GR_PROTSHM = 0x00000040,
69597+ GR_KILLPROC = 0x00000080,
69598+ GR_KILLIPPROC = 0x00000100,
69599+ /* just a placeholder, this mode is only used in userspace */
69600+ GR_NOTROJAN = 0x00000200,
69601+ GR_PROTPROCFD = 0x00000400,
69602+ GR_PROCACCT = 0x00000800,
69603+ GR_RELAXPTRACE = 0x00001000,
69604+ //GR_NESTED = 0x00002000,
69605+ GR_INHERITLEARN = 0x00004000,
69606+ GR_PROCFIND = 0x00008000,
69607+ GR_POVERRIDE = 0x00010000,
69608+ GR_KERNELAUTH = 0x00020000,
69609+ GR_ATSECURE = 0x00040000,
69610+ GR_SHMEXEC = 0x00080000
69611+};
69612+
69613+enum {
69614+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
69615+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
69616+ GR_PAX_ENABLE_MPROTECT = 0x0004,
69617+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
69618+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
69619+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
69620+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
69621+ GR_PAX_DISABLE_MPROTECT = 0x0400,
69622+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
69623+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
69624+};
69625+
69626+enum {
69627+ GR_ID_USER = 0x01,
69628+ GR_ID_GROUP = 0x02,
69629+};
69630+
69631+enum {
69632+ GR_ID_ALLOW = 0x01,
69633+ GR_ID_DENY = 0x02,
69634+};
69635+
69636+#define GR_CRASH_RES 31
69637+#define GR_UIDTABLE_MAX 500
69638+
69639+/* begin resource learning section */
69640+enum {
69641+ GR_RLIM_CPU_BUMP = 60,
69642+ GR_RLIM_FSIZE_BUMP = 50000,
69643+ GR_RLIM_DATA_BUMP = 10000,
69644+ GR_RLIM_STACK_BUMP = 1000,
69645+ GR_RLIM_CORE_BUMP = 10000,
69646+ GR_RLIM_RSS_BUMP = 500000,
69647+ GR_RLIM_NPROC_BUMP = 1,
69648+ GR_RLIM_NOFILE_BUMP = 5,
69649+ GR_RLIM_MEMLOCK_BUMP = 50000,
69650+ GR_RLIM_AS_BUMP = 500000,
69651+ GR_RLIM_LOCKS_BUMP = 2,
69652+ GR_RLIM_SIGPENDING_BUMP = 5,
69653+ GR_RLIM_MSGQUEUE_BUMP = 10000,
69654+ GR_RLIM_NICE_BUMP = 1,
69655+ GR_RLIM_RTPRIO_BUMP = 1,
69656+ GR_RLIM_RTTIME_BUMP = 1000000
69657+};
69658+
69659+#endif
69660diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
69661new file mode 100644
69662index 0000000..9bb6662
69663--- /dev/null
69664+++ b/include/linux/grinternal.h
69665@@ -0,0 +1,215 @@
69666+#ifndef __GRINTERNAL_H
69667+#define __GRINTERNAL_H
69668+
69669+#ifdef CONFIG_GRKERNSEC
69670+
69671+#include <linux/fs.h>
69672+#include <linux/mnt_namespace.h>
69673+#include <linux/nsproxy.h>
69674+#include <linux/gracl.h>
69675+#include <linux/grdefs.h>
69676+#include <linux/grmsg.h>
69677+
69678+void gr_add_learn_entry(const char *fmt, ...)
69679+ __attribute__ ((format (printf, 1, 2)));
69680+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
69681+ const struct vfsmount *mnt);
69682+__u32 gr_check_create(const struct dentry *new_dentry,
69683+ const struct dentry *parent,
69684+ const struct vfsmount *mnt, const __u32 mode);
69685+int gr_check_protected_task(const struct task_struct *task);
69686+__u32 to_gr_audit(const __u32 reqmode);
69687+int gr_set_acls(const int type);
69688+int gr_apply_subject_to_task(struct task_struct *task);
69689+int gr_acl_is_enabled(void);
69690+char gr_roletype_to_char(void);
69691+
69692+void gr_handle_alertkill(struct task_struct *task);
69693+char *gr_to_filename(const struct dentry *dentry,
69694+ const struct vfsmount *mnt);
69695+char *gr_to_filename1(const struct dentry *dentry,
69696+ const struct vfsmount *mnt);
69697+char *gr_to_filename2(const struct dentry *dentry,
69698+ const struct vfsmount *mnt);
69699+char *gr_to_filename3(const struct dentry *dentry,
69700+ const struct vfsmount *mnt);
69701+
69702+extern int grsec_enable_ptrace_readexec;
69703+extern int grsec_enable_harden_ptrace;
69704+extern int grsec_enable_link;
69705+extern int grsec_enable_fifo;
69706+extern int grsec_enable_execve;
69707+extern int grsec_enable_shm;
69708+extern int grsec_enable_execlog;
69709+extern int grsec_enable_signal;
69710+extern int grsec_enable_audit_ptrace;
69711+extern int grsec_enable_forkfail;
69712+extern int grsec_enable_time;
69713+extern int grsec_enable_rofs;
69714+extern int grsec_enable_chroot_shmat;
69715+extern int grsec_enable_chroot_mount;
69716+extern int grsec_enable_chroot_double;
69717+extern int grsec_enable_chroot_pivot;
69718+extern int grsec_enable_chroot_chdir;
69719+extern int grsec_enable_chroot_chmod;
69720+extern int grsec_enable_chroot_mknod;
69721+extern int grsec_enable_chroot_fchdir;
69722+extern int grsec_enable_chroot_nice;
69723+extern int grsec_enable_chroot_execlog;
69724+extern int grsec_enable_chroot_caps;
69725+extern int grsec_enable_chroot_sysctl;
69726+extern int grsec_enable_chroot_unix;
69727+extern int grsec_enable_symlinkown;
69728+extern kgid_t grsec_symlinkown_gid;
69729+extern int grsec_enable_tpe;
69730+extern kgid_t grsec_tpe_gid;
69731+extern int grsec_enable_tpe_all;
69732+extern int grsec_enable_tpe_invert;
69733+extern int grsec_enable_socket_all;
69734+extern kgid_t grsec_socket_all_gid;
69735+extern int grsec_enable_socket_client;
69736+extern kgid_t grsec_socket_client_gid;
69737+extern int grsec_enable_socket_server;
69738+extern kgid_t grsec_socket_server_gid;
69739+extern kgid_t grsec_audit_gid;
69740+extern int grsec_enable_group;
69741+extern int grsec_enable_audit_textrel;
69742+extern int grsec_enable_log_rwxmaps;
69743+extern int grsec_enable_mount;
69744+extern int grsec_enable_chdir;
69745+extern int grsec_resource_logging;
69746+extern int grsec_enable_blackhole;
69747+extern int grsec_lastack_retries;
69748+extern int grsec_enable_brute;
69749+extern int grsec_lock;
69750+
69751+extern spinlock_t grsec_alert_lock;
69752+extern unsigned long grsec_alert_wtime;
69753+extern unsigned long grsec_alert_fyet;
69754+
69755+extern spinlock_t grsec_audit_lock;
69756+
69757+extern rwlock_t grsec_exec_file_lock;
69758+
69759+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
69760+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
69761+ (tsk)->exec_file->f_vfsmnt) : "/")
69762+
69763+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
69764+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
69765+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
69766+
69767+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
69768+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
69769+ (tsk)->exec_file->f_vfsmnt) : "/")
69770+
69771+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
69772+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
69773+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
69774+
69775+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
69776+
69777+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
69778+
69779+#define GR_CHROOT_CAPS {{ \
69780+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
69781+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
69782+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
69783+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
69784+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
69785+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
69786+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
69787+
69788+#define security_learn(normal_msg,args...) \
69789+({ \
69790+ read_lock(&grsec_exec_file_lock); \
69791+ gr_add_learn_entry(normal_msg "\n", ## args); \
69792+ read_unlock(&grsec_exec_file_lock); \
69793+})
69794+
69795+enum {
69796+ GR_DO_AUDIT,
69797+ GR_DONT_AUDIT,
69798+ /* used for non-audit messages that we shouldn't kill the task on */
69799+ GR_DONT_AUDIT_GOOD
69800+};
69801+
69802+enum {
69803+ GR_TTYSNIFF,
69804+ GR_RBAC,
69805+ GR_RBAC_STR,
69806+ GR_STR_RBAC,
69807+ GR_RBAC_MODE2,
69808+ GR_RBAC_MODE3,
69809+ GR_FILENAME,
69810+ GR_SYSCTL_HIDDEN,
69811+ GR_NOARGS,
69812+ GR_ONE_INT,
69813+ GR_ONE_INT_TWO_STR,
69814+ GR_ONE_STR,
69815+ GR_STR_INT,
69816+ GR_TWO_STR_INT,
69817+ GR_TWO_INT,
69818+ GR_TWO_U64,
69819+ GR_THREE_INT,
69820+ GR_FIVE_INT_TWO_STR,
69821+ GR_TWO_STR,
69822+ GR_THREE_STR,
69823+ GR_FOUR_STR,
69824+ GR_STR_FILENAME,
69825+ GR_FILENAME_STR,
69826+ GR_FILENAME_TWO_INT,
69827+ GR_FILENAME_TWO_INT_STR,
69828+ GR_TEXTREL,
69829+ GR_PTRACE,
69830+ GR_RESOURCE,
69831+ GR_CAP,
69832+ GR_SIG,
69833+ GR_SIG2,
69834+ GR_CRASH1,
69835+ GR_CRASH2,
69836+ GR_PSACCT,
69837+ GR_RWXMAP
69838+};
69839+
69840+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
69841+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
69842+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
69843+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
69844+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
69845+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
69846+#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)
69847+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
69848+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
69849+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
69850+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
69851+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
69852+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
69853+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
69854+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
69855+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
69856+#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)
69857+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
69858+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
69859+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
69860+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
69861+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
69862+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
69863+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
69864+#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)
69865+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
69866+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
69867+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
69868+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
69869+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
69870+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
69871+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
69872+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
69873+#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)
69874+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
69875+
69876+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
69877+
69878+#endif
69879+
69880+#endif
69881diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
69882new file mode 100644
69883index 0000000..2bd4c8d
69884--- /dev/null
69885+++ b/include/linux/grmsg.h
69886@@ -0,0 +1,111 @@
69887+#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"
69888+#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"
69889+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
69890+#define GR_STOPMOD_MSG "denied modification of module state by "
69891+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
69892+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
69893+#define GR_IOPERM_MSG "denied use of ioperm() by "
69894+#define GR_IOPL_MSG "denied use of iopl() by "
69895+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
69896+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
69897+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
69898+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
69899+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
69900+#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"
69901+#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"
69902+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
69903+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
69904+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
69905+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
69906+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
69907+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
69908+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
69909+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
69910+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
69911+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
69912+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
69913+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
69914+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
69915+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
69916+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
69917+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
69918+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
69919+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
69920+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
69921+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
69922+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
69923+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
69924+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
69925+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
69926+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
69927+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
69928+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
69929+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
69930+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
69931+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
69932+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
69933+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
69934+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
69935+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
69936+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
69937+#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"
69938+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
69939+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
69940+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
69941+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
69942+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
69943+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
69944+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
69945+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
69946+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
69947+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
69948+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
69949+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
69950+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
69951+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
69952+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
69953+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
69954+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
69955+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
69956+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
69957+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
69958+#define GR_FAILFORK_MSG "failed fork with errno %s by "
69959+#define GR_NICE_CHROOT_MSG "denied priority change by "
69960+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
69961+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
69962+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
69963+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
69964+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
69965+#define GR_TIME_MSG "time set by "
69966+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
69967+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
69968+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
69969+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
69970+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
69971+#define GR_BIND_MSG "denied bind() by "
69972+#define GR_CONNECT_MSG "denied connect() by "
69973+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
69974+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
69975+#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"
69976+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
69977+#define GR_CAP_ACL_MSG "use of %s denied for "
69978+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
69979+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
69980+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
69981+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
69982+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
69983+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
69984+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
69985+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
69986+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
69987+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
69988+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
69989+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
69990+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
69991+#define GR_VM86_MSG "denied use of vm86 by "
69992+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
69993+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
69994+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
69995+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
69996+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
69997+#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 "
69998diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
69999new file mode 100644
70000index 0000000..8da63a4
70001--- /dev/null
70002+++ b/include/linux/grsecurity.h
70003@@ -0,0 +1,242 @@
70004+#ifndef GR_SECURITY_H
70005+#define GR_SECURITY_H
70006+#include <linux/fs.h>
70007+#include <linux/fs_struct.h>
70008+#include <linux/binfmts.h>
70009+#include <linux/gracl.h>
70010+
70011+/* notify of brain-dead configs */
70012+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70013+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
70014+#endif
70015+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
70016+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
70017+#endif
70018+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
70019+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
70020+#endif
70021+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
70022+#error "CONFIG_PAX enabled, but no PaX options are enabled."
70023+#endif
70024+
70025+void gr_handle_brute_attach(unsigned long mm_flags);
70026+void gr_handle_brute_check(void);
70027+void gr_handle_kernel_exploit(void);
70028+int gr_process_user_ban(void);
70029+
70030+char gr_roletype_to_char(void);
70031+
70032+int gr_acl_enable_at_secure(void);
70033+
70034+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
70035+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
70036+
70037+void gr_del_task_from_ip_table(struct task_struct *p);
70038+
70039+int gr_pid_is_chrooted(struct task_struct *p);
70040+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
70041+int gr_handle_chroot_nice(void);
70042+int gr_handle_chroot_sysctl(const int op);
70043+int gr_handle_chroot_setpriority(struct task_struct *p,
70044+ const int niceval);
70045+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
70046+int gr_handle_chroot_chroot(const struct dentry *dentry,
70047+ const struct vfsmount *mnt);
70048+void gr_handle_chroot_chdir(struct path *path);
70049+int gr_handle_chroot_chmod(const struct dentry *dentry,
70050+ const struct vfsmount *mnt, const int mode);
70051+int gr_handle_chroot_mknod(const struct dentry *dentry,
70052+ const struct vfsmount *mnt, const int mode);
70053+int gr_handle_chroot_mount(const struct dentry *dentry,
70054+ const struct vfsmount *mnt,
70055+ const char *dev_name);
70056+int gr_handle_chroot_pivot(void);
70057+int gr_handle_chroot_unix(const pid_t pid);
70058+
70059+int gr_handle_rawio(const struct inode *inode);
70060+
70061+void gr_handle_ioperm(void);
70062+void gr_handle_iopl(void);
70063+
70064+umode_t gr_acl_umask(void);
70065+
70066+int gr_tpe_allow(const struct file *file);
70067+
70068+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
70069+void gr_clear_chroot_entries(struct task_struct *task);
70070+
70071+void gr_log_forkfail(const int retval);
70072+void gr_log_timechange(void);
70073+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
70074+void gr_log_chdir(const struct dentry *dentry,
70075+ const struct vfsmount *mnt);
70076+void gr_log_chroot_exec(const struct dentry *dentry,
70077+ const struct vfsmount *mnt);
70078+void gr_log_remount(const char *devname, const int retval);
70079+void gr_log_unmount(const char *devname, const int retval);
70080+void gr_log_mount(const char *from, const char *to, const int retval);
70081+void gr_log_textrel(struct vm_area_struct *vma);
70082+void gr_log_rwxmmap(struct file *file);
70083+void gr_log_rwxmprotect(struct file *file);
70084+
70085+int gr_handle_follow_link(const struct inode *parent,
70086+ const struct inode *inode,
70087+ const struct dentry *dentry,
70088+ const struct vfsmount *mnt);
70089+int gr_handle_fifo(const struct dentry *dentry,
70090+ const struct vfsmount *mnt,
70091+ const struct dentry *dir, const int flag,
70092+ const int acc_mode);
70093+int gr_handle_hardlink(const struct dentry *dentry,
70094+ const struct vfsmount *mnt,
70095+ struct inode *inode,
70096+ const int mode, const struct filename *to);
70097+
70098+int gr_is_capable(const int cap);
70099+int gr_is_capable_nolog(const int cap);
70100+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
70101+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
70102+
70103+void gr_copy_label(struct task_struct *tsk);
70104+void gr_handle_crash(struct task_struct *task, const int sig);
70105+int gr_handle_signal(const struct task_struct *p, const int sig);
70106+int gr_check_crash_uid(const kuid_t uid);
70107+int gr_check_protected_task(const struct task_struct *task);
70108+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
70109+int gr_acl_handle_mmap(const struct file *file,
70110+ const unsigned long prot);
70111+int gr_acl_handle_mprotect(const struct file *file,
70112+ const unsigned long prot);
70113+int gr_check_hidden_task(const struct task_struct *tsk);
70114+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
70115+ const struct vfsmount *mnt);
70116+__u32 gr_acl_handle_utime(const struct dentry *dentry,
70117+ const struct vfsmount *mnt);
70118+__u32 gr_acl_handle_access(const struct dentry *dentry,
70119+ const struct vfsmount *mnt, const int fmode);
70120+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
70121+ const struct vfsmount *mnt, umode_t *mode);
70122+__u32 gr_acl_handle_chown(const struct dentry *dentry,
70123+ const struct vfsmount *mnt);
70124+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
70125+ const struct vfsmount *mnt);
70126+int gr_handle_ptrace(struct task_struct *task, const long request);
70127+int gr_handle_proc_ptrace(struct task_struct *task);
70128+__u32 gr_acl_handle_execve(const struct dentry *dentry,
70129+ const struct vfsmount *mnt);
70130+int gr_check_crash_exec(const struct file *filp);
70131+int gr_acl_is_enabled(void);
70132+void gr_set_kernel_label(struct task_struct *task);
70133+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
70134+ const kgid_t gid);
70135+int gr_set_proc_label(const struct dentry *dentry,
70136+ const struct vfsmount *mnt,
70137+ const int unsafe_flags);
70138+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
70139+ const struct vfsmount *mnt);
70140+__u32 gr_acl_handle_open(const struct dentry *dentry,
70141+ const struct vfsmount *mnt, int acc_mode);
70142+__u32 gr_acl_handle_creat(const struct dentry *dentry,
70143+ const struct dentry *p_dentry,
70144+ const struct vfsmount *p_mnt,
70145+ int open_flags, int acc_mode, const int imode);
70146+void gr_handle_create(const struct dentry *dentry,
70147+ const struct vfsmount *mnt);
70148+void gr_handle_proc_create(const struct dentry *dentry,
70149+ const struct inode *inode);
70150+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
70151+ const struct dentry *parent_dentry,
70152+ const struct vfsmount *parent_mnt,
70153+ const int mode);
70154+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
70155+ const struct dentry *parent_dentry,
70156+ const struct vfsmount *parent_mnt);
70157+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
70158+ const struct vfsmount *mnt);
70159+void gr_handle_delete(const ino_t ino, const dev_t dev);
70160+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
70161+ const struct vfsmount *mnt);
70162+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
70163+ const struct dentry *parent_dentry,
70164+ const struct vfsmount *parent_mnt,
70165+ const struct filename *from);
70166+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
70167+ const struct dentry *parent_dentry,
70168+ const struct vfsmount *parent_mnt,
70169+ const struct dentry *old_dentry,
70170+ const struct vfsmount *old_mnt, const struct filename *to);
70171+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
70172+int gr_acl_handle_rename(struct dentry *new_dentry,
70173+ struct dentry *parent_dentry,
70174+ const struct vfsmount *parent_mnt,
70175+ struct dentry *old_dentry,
70176+ struct inode *old_parent_inode,
70177+ struct vfsmount *old_mnt, const struct filename *newname);
70178+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
70179+ struct dentry *old_dentry,
70180+ struct dentry *new_dentry,
70181+ struct vfsmount *mnt, const __u8 replace);
70182+__u32 gr_check_link(const struct dentry *new_dentry,
70183+ const struct dentry *parent_dentry,
70184+ const struct vfsmount *parent_mnt,
70185+ const struct dentry *old_dentry,
70186+ const struct vfsmount *old_mnt);
70187+int gr_acl_handle_filldir(const struct file *file, const char *name,
70188+ const unsigned int namelen, const ino_t ino);
70189+
70190+__u32 gr_acl_handle_unix(const struct dentry *dentry,
70191+ const struct vfsmount *mnt);
70192+void gr_acl_handle_exit(void);
70193+void gr_acl_handle_psacct(struct task_struct *task, const long code);
70194+int gr_acl_handle_procpidmem(const struct task_struct *task);
70195+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
70196+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
70197+void gr_audit_ptrace(struct task_struct *task);
70198+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
70199+void gr_put_exec_file(struct task_struct *task);
70200+
70201+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
70202+
70203+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
70204+extern void gr_learn_resource(const struct task_struct *task, const int res,
70205+ const unsigned long wanted, const int gt);
70206+#else
70207+static inline void gr_learn_resource(const struct task_struct *task, const int res,
70208+ const unsigned long wanted, const int gt)
70209+{
70210+}
70211+#endif
70212+
70213+#ifdef CONFIG_GRKERNSEC_RESLOG
70214+extern void gr_log_resource(const struct task_struct *task, const int res,
70215+ const unsigned long wanted, const int gt);
70216+#else
70217+static inline void gr_log_resource(const struct task_struct *task, const int res,
70218+ const unsigned long wanted, const int gt)
70219+{
70220+}
70221+#endif
70222+
70223+#ifdef CONFIG_GRKERNSEC
70224+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
70225+void gr_handle_vm86(void);
70226+void gr_handle_mem_readwrite(u64 from, u64 to);
70227+
70228+void gr_log_badprocpid(const char *entry);
70229+
70230+extern int grsec_enable_dmesg;
70231+extern int grsec_disable_privio;
70232+
70233+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
70234+extern kgid_t grsec_proc_gid;
70235+#endif
70236+
70237+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
70238+extern int grsec_enable_chroot_findtask;
70239+#endif
70240+#ifdef CONFIG_GRKERNSEC_SETXID
70241+extern int grsec_enable_setxid;
70242+#endif
70243+#endif
70244+
70245+#endif
70246diff --git a/include/linux/grsock.h b/include/linux/grsock.h
70247new file mode 100644
70248index 0000000..e7ffaaf
70249--- /dev/null
70250+++ b/include/linux/grsock.h
70251@@ -0,0 +1,19 @@
70252+#ifndef __GRSOCK_H
70253+#define __GRSOCK_H
70254+
70255+extern void gr_attach_curr_ip(const struct sock *sk);
70256+extern int gr_handle_sock_all(const int family, const int type,
70257+ const int protocol);
70258+extern int gr_handle_sock_server(const struct sockaddr *sck);
70259+extern int gr_handle_sock_server_other(const struct sock *sck);
70260+extern int gr_handle_sock_client(const struct sockaddr *sck);
70261+extern int gr_search_connect(struct socket * sock,
70262+ struct sockaddr_in * addr);
70263+extern int gr_search_bind(struct socket * sock,
70264+ struct sockaddr_in * addr);
70265+extern int gr_search_listen(struct socket * sock);
70266+extern int gr_search_accept(struct socket * sock);
70267+extern int gr_search_socket(const int domain, const int type,
70268+ const int protocol);
70269+
70270+#endif
70271diff --git a/include/linux/highmem.h b/include/linux/highmem.h
70272index ef788b5..ac41b7b 100644
70273--- a/include/linux/highmem.h
70274+++ b/include/linux/highmem.h
70275@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
70276 kunmap_atomic(kaddr);
70277 }
70278
70279+static inline void sanitize_highpage(struct page *page)
70280+{
70281+ void *kaddr;
70282+ unsigned long flags;
70283+
70284+ local_irq_save(flags);
70285+ kaddr = kmap_atomic(page);
70286+ clear_page(kaddr);
70287+ kunmap_atomic(kaddr);
70288+ local_irq_restore(flags);
70289+}
70290+
70291 static inline void zero_user_segments(struct page *page,
70292 unsigned start1, unsigned end1,
70293 unsigned start2, unsigned end2)
70294diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
70295index 1c7b89a..7f52502 100644
70296--- a/include/linux/hwmon-sysfs.h
70297+++ b/include/linux/hwmon-sysfs.h
70298@@ -25,7 +25,8 @@
70299 struct sensor_device_attribute{
70300 struct device_attribute dev_attr;
70301 int index;
70302-};
70303+} __do_const;
70304+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
70305 #define to_sensor_dev_attr(_dev_attr) \
70306 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
70307
70308@@ -41,7 +42,7 @@ struct sensor_device_attribute_2 {
70309 struct device_attribute dev_attr;
70310 u8 index;
70311 u8 nr;
70312-};
70313+} __do_const;
70314 #define to_sensor_dev_attr_2(_dev_attr) \
70315 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
70316
70317diff --git a/include/linux/i2c.h b/include/linux/i2c.h
70318index d0c4db7..61b3577 100644
70319--- a/include/linux/i2c.h
70320+++ b/include/linux/i2c.h
70321@@ -369,6 +369,7 @@ struct i2c_algorithm {
70322 /* To determine what the adapter supports */
70323 u32 (*functionality) (struct i2c_adapter *);
70324 };
70325+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
70326
70327 /*
70328 * i2c_adapter is the structure used to identify a physical i2c bus along
70329diff --git a/include/linux/i2o.h b/include/linux/i2o.h
70330index d23c3c2..eb63c81 100644
70331--- a/include/linux/i2o.h
70332+++ b/include/linux/i2o.h
70333@@ -565,7 +565,7 @@ struct i2o_controller {
70334 struct i2o_device *exec; /* Executive */
70335 #if BITS_PER_LONG == 64
70336 spinlock_t context_list_lock; /* lock for context_list */
70337- atomic_t context_list_counter; /* needed for unique contexts */
70338+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
70339 struct list_head context_list; /* list of context id's
70340 and pointers */
70341 #endif
70342diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
70343index aff7ad8..3942bbd 100644
70344--- a/include/linux/if_pppox.h
70345+++ b/include/linux/if_pppox.h
70346@@ -76,7 +76,7 @@ struct pppox_proto {
70347 int (*ioctl)(struct socket *sock, unsigned int cmd,
70348 unsigned long arg);
70349 struct module *owner;
70350-};
70351+} __do_const;
70352
70353 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
70354 extern void unregister_pppox_proto(int proto_num);
70355diff --git a/include/linux/init.h b/include/linux/init.h
70356index 10ed4f4..8e8490d 100644
70357--- a/include/linux/init.h
70358+++ b/include/linux/init.h
70359@@ -39,9 +39,36 @@
70360 * Also note, that this data cannot be "const".
70361 */
70362
70363+#ifdef MODULE
70364+#define add_init_latent_entropy
70365+#define add_devinit_latent_entropy
70366+#define add_cpuinit_latent_entropy
70367+#define add_meminit_latent_entropy
70368+#else
70369+#define add_init_latent_entropy __latent_entropy
70370+
70371+#ifdef CONFIG_HOTPLUG
70372+#define add_devinit_latent_entropy
70373+#else
70374+#define add_devinit_latent_entropy __latent_entropy
70375+#endif
70376+
70377+#ifdef CONFIG_HOTPLUG_CPU
70378+#define add_cpuinit_latent_entropy
70379+#else
70380+#define add_cpuinit_latent_entropy __latent_entropy
70381+#endif
70382+
70383+#ifdef CONFIG_MEMORY_HOTPLUG
70384+#define add_meminit_latent_entropy
70385+#else
70386+#define add_meminit_latent_entropy __latent_entropy
70387+#endif
70388+#endif
70389+
70390 /* These are for everybody (although not all archs will actually
70391 discard it in modules) */
70392-#define __init __section(.init.text) __cold notrace
70393+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
70394 #define __initdata __section(.init.data)
70395 #define __initconst __constsection(.init.rodata)
70396 #define __exitdata __section(.exit.data)
70397@@ -94,7 +121,7 @@
70398 #define __exit __section(.exit.text) __exitused __cold notrace
70399
70400 /* Used for HOTPLUG_CPU */
70401-#define __cpuinit __section(.cpuinit.text) __cold notrace
70402+#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
70403 #define __cpuinitdata __section(.cpuinit.data)
70404 #define __cpuinitconst __constsection(.cpuinit.rodata)
70405 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
70406@@ -102,7 +129,7 @@
70407 #define __cpuexitconst __constsection(.cpuexit.rodata)
70408
70409 /* Used for MEMORY_HOTPLUG */
70410-#define __meminit __section(.meminit.text) __cold notrace
70411+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
70412 #define __meminitdata __section(.meminit.data)
70413 #define __meminitconst __constsection(.meminit.rodata)
70414 #define __memexit __section(.memexit.text) __exitused __cold notrace
70415diff --git a/include/linux/init_task.h b/include/linux/init_task.h
70416index 6d087c5..401cab8 100644
70417--- a/include/linux/init_task.h
70418+++ b/include/linux/init_task.h
70419@@ -143,6 +143,12 @@ extern struct task_group root_task_group;
70420
70421 #define INIT_TASK_COMM "swapper"
70422
70423+#ifdef CONFIG_X86
70424+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
70425+#else
70426+#define INIT_TASK_THREAD_INFO
70427+#endif
70428+
70429 /*
70430 * INIT_TASK is used to set up the first task table, touch at
70431 * your own risk!. Base=0, limit=0x1fffff (=2MB)
70432@@ -182,6 +188,7 @@ extern struct task_group root_task_group;
70433 RCU_POINTER_INITIALIZER(cred, &init_cred), \
70434 .comm = INIT_TASK_COMM, \
70435 .thread = INIT_THREAD, \
70436+ INIT_TASK_THREAD_INFO \
70437 .fs = &init_fs, \
70438 .files = &init_files, \
70439 .signal = &init_signals, \
70440diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
70441index 5fa5afe..ac55b25 100644
70442--- a/include/linux/interrupt.h
70443+++ b/include/linux/interrupt.h
70444@@ -430,7 +430,7 @@ enum
70445 /* map softirq index to softirq name. update 'softirq_to_name' in
70446 * kernel/softirq.c when adding a new softirq.
70447 */
70448-extern char *softirq_to_name[NR_SOFTIRQS];
70449+extern const char * const softirq_to_name[NR_SOFTIRQS];
70450
70451 /* softirq mask and active fields moved to irq_cpustat_t in
70452 * asm/hardirq.h to get better cache usage. KAO
70453@@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
70454
70455 struct softirq_action
70456 {
70457- void (*action)(struct softirq_action *);
70458-};
70459+ void (*action)(void);
70460+} __no_const;
70461
70462 asmlinkage void do_softirq(void);
70463 asmlinkage void __do_softirq(void);
70464-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
70465+extern void open_softirq(int nr, void (*action)(void));
70466 extern void softirq_init(void);
70467 extern void __raise_softirq_irqoff(unsigned int nr);
70468
70469diff --git a/include/linux/iommu.h b/include/linux/iommu.h
70470index f3b99e1..9b73cee 100644
70471--- a/include/linux/iommu.h
70472+++ b/include/linux/iommu.h
70473@@ -101,7 +101,7 @@ struct iommu_ops {
70474 int (*domain_set_attr)(struct iommu_domain *domain,
70475 enum iommu_attr attr, void *data);
70476 unsigned long pgsize_bitmap;
70477-};
70478+} __do_const;
70479
70480 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
70481 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
70482diff --git a/include/linux/ioport.h b/include/linux/ioport.h
70483index 85ac9b9b..e5759ab 100644
70484--- a/include/linux/ioport.h
70485+++ b/include/linux/ioport.h
70486@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
70487 int adjust_resource(struct resource *res, resource_size_t start,
70488 resource_size_t size);
70489 resource_size_t resource_alignment(struct resource *res);
70490-static inline resource_size_t resource_size(const struct resource *res)
70491+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
70492 {
70493 return res->end - res->start + 1;
70494 }
70495diff --git a/include/linux/irq.h b/include/linux/irq.h
70496index fdf2c4a..5332486 100644
70497--- a/include/linux/irq.h
70498+++ b/include/linux/irq.h
70499@@ -328,7 +328,8 @@ struct irq_chip {
70500 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
70501
70502 unsigned long flags;
70503-};
70504+} __do_const;
70505+typedef struct irq_chip __no_const irq_chip_no_const;
70506
70507 /*
70508 * irq_chip specific flags
70509diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
70510index 6883e19..06992b1 100644
70511--- a/include/linux/kallsyms.h
70512+++ b/include/linux/kallsyms.h
70513@@ -15,7 +15,8 @@
70514
70515 struct module;
70516
70517-#ifdef CONFIG_KALLSYMS
70518+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
70519+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
70520 /* Lookup the address for a symbol. Returns 0 if not found. */
70521 unsigned long kallsyms_lookup_name(const char *name);
70522
70523@@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
70524 /* Stupid that this does nothing, but I didn't create this mess. */
70525 #define __print_symbol(fmt, addr)
70526 #endif /*CONFIG_KALLSYMS*/
70527+#else /* when included by kallsyms.c, vsnprintf.c, or
70528+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
70529+extern void __print_symbol(const char *fmt, unsigned long address);
70530+extern int sprint_backtrace(char *buffer, unsigned long address);
70531+extern int sprint_symbol(char *buffer, unsigned long address);
70532+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
70533+const char *kallsyms_lookup(unsigned long addr,
70534+ unsigned long *symbolsize,
70535+ unsigned long *offset,
70536+ char **modname, char *namebuf);
70537+#endif
70538
70539 /* This macro allows us to keep printk typechecking */
70540 static __printf(1, 2)
70541diff --git a/include/linux/key-type.h b/include/linux/key-type.h
70542index 518a53a..5e28358 100644
70543--- a/include/linux/key-type.h
70544+++ b/include/linux/key-type.h
70545@@ -125,7 +125,7 @@ struct key_type {
70546 /* internal fields */
70547 struct list_head link; /* link in types list */
70548 struct lock_class_key lock_class; /* key->sem lock class */
70549-};
70550+} __do_const;
70551
70552 extern struct key_type key_type_keyring;
70553
70554diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
70555index 4dff0c6..1ca9b72 100644
70556--- a/include/linux/kgdb.h
70557+++ b/include/linux/kgdb.h
70558@@ -53,7 +53,7 @@ extern int kgdb_connected;
70559 extern int kgdb_io_module_registered;
70560
70561 extern atomic_t kgdb_setting_breakpoint;
70562-extern atomic_t kgdb_cpu_doing_single_step;
70563+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
70564
70565 extern struct task_struct *kgdb_usethread;
70566 extern struct task_struct *kgdb_contthread;
70567@@ -255,7 +255,7 @@ struct kgdb_arch {
70568 void (*correct_hw_break)(void);
70569
70570 void (*enable_nmi)(bool on);
70571-};
70572+} __do_const;
70573
70574 /**
70575 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
70576@@ -280,7 +280,7 @@ struct kgdb_io {
70577 void (*pre_exception) (void);
70578 void (*post_exception) (void);
70579 int is_console;
70580-};
70581+} __do_const;
70582
70583 extern struct kgdb_arch arch_kgdb_ops;
70584
70585diff --git a/include/linux/kmod.h b/include/linux/kmod.h
70586index 5398d58..5883a34 100644
70587--- a/include/linux/kmod.h
70588+++ b/include/linux/kmod.h
70589@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
70590 * usually useless though. */
70591 extern __printf(2, 3)
70592 int __request_module(bool wait, const char *name, ...);
70593+extern __printf(3, 4)
70594+int ___request_module(bool wait, char *param_name, const char *name, ...);
70595 #define request_module(mod...) __request_module(true, mod)
70596 #define request_module_nowait(mod...) __request_module(false, mod)
70597 #define try_then_request_module(x, mod...) \
70598diff --git a/include/linux/kobject.h b/include/linux/kobject.h
70599index 939b112..ed6ed51 100644
70600--- a/include/linux/kobject.h
70601+++ b/include/linux/kobject.h
70602@@ -111,7 +111,7 @@ struct kobj_type {
70603 struct attribute **default_attrs;
70604 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
70605 const void *(*namespace)(struct kobject *kobj);
70606-};
70607+} __do_const;
70608
70609 struct kobj_uevent_env {
70610 char *envp[UEVENT_NUM_ENVP];
70611@@ -134,6 +134,7 @@ struct kobj_attribute {
70612 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
70613 const char *buf, size_t count);
70614 };
70615+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
70616
70617 extern const struct sysfs_ops kobj_sysfs_ops;
70618
70619diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
70620index f66b065..c2c29b4 100644
70621--- a/include/linux/kobject_ns.h
70622+++ b/include/linux/kobject_ns.h
70623@@ -43,7 +43,7 @@ struct kobj_ns_type_operations {
70624 const void *(*netlink_ns)(struct sock *sk);
70625 const void *(*initial_ns)(void);
70626 void (*drop_ns)(void *);
70627-};
70628+} __do_const;
70629
70630 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
70631 int kobj_ns_type_registered(enum kobj_ns_type type);
70632diff --git a/include/linux/kref.h b/include/linux/kref.h
70633index 4972e6e..de4d19b 100644
70634--- a/include/linux/kref.h
70635+++ b/include/linux/kref.h
70636@@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
70637 static inline int kref_sub(struct kref *kref, unsigned int count,
70638 void (*release)(struct kref *kref))
70639 {
70640- WARN_ON(release == NULL);
70641+ BUG_ON(release == NULL);
70642
70643 if (atomic_sub_and_test((int) count, &kref->refcount)) {
70644 release(kref);
70645diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
70646index 2c497ab..afe32f5 100644
70647--- a/include/linux/kvm_host.h
70648+++ b/include/linux/kvm_host.h
70649@@ -418,7 +418,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
70650 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
70651 void vcpu_put(struct kvm_vcpu *vcpu);
70652
70653-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
70654+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
70655 struct module *module);
70656 void kvm_exit(void);
70657
70658@@ -574,7 +574,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
70659 struct kvm_guest_debug *dbg);
70660 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
70661
70662-int kvm_arch_init(void *opaque);
70663+int kvm_arch_init(const void *opaque);
70664 void kvm_arch_exit(void);
70665
70666 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
70667diff --git a/include/linux/libata.h b/include/linux/libata.h
70668index 0621bca..24d6851 100644
70669--- a/include/linux/libata.h
70670+++ b/include/linux/libata.h
70671@@ -916,7 +916,7 @@ struct ata_port_operations {
70672 * fields must be pointers.
70673 */
70674 const struct ata_port_operations *inherits;
70675-};
70676+} __do_const;
70677
70678 struct ata_port_info {
70679 unsigned long flags;
70680diff --git a/include/linux/list.h b/include/linux/list.h
70681index cc6d2aa..c10ee83 100644
70682--- a/include/linux/list.h
70683+++ b/include/linux/list.h
70684@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
70685 extern void list_del(struct list_head *entry);
70686 #endif
70687
70688+extern void __pax_list_add(struct list_head *new,
70689+ struct list_head *prev,
70690+ struct list_head *next);
70691+static inline void pax_list_add(struct list_head *new, struct list_head *head)
70692+{
70693+ __pax_list_add(new, head, head->next);
70694+}
70695+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
70696+{
70697+ __pax_list_add(new, head->prev, head);
70698+}
70699+extern void pax_list_del(struct list_head *entry);
70700+
70701 /**
70702 * list_replace - replace old entry by new one
70703 * @old : the element to be replaced
70704@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
70705 INIT_LIST_HEAD(entry);
70706 }
70707
70708+extern void pax_list_del_init(struct list_head *entry);
70709+
70710 /**
70711 * list_move - delete from one list and add as another's head
70712 * @list: the entry to move
70713diff --git a/include/linux/math64.h b/include/linux/math64.h
70714index b8ba855..0148090 100644
70715--- a/include/linux/math64.h
70716+++ b/include/linux/math64.h
70717@@ -14,7 +14,7 @@
70718 * This is commonly provided by 32bit archs to provide an optimized 64bit
70719 * divide.
70720 */
70721-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70722+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70723 {
70724 *remainder = dividend % divisor;
70725 return dividend / divisor;
70726@@ -50,7 +50,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
70727 #define div64_long(x,y) div_s64((x),(y))
70728
70729 #ifndef div_u64_rem
70730-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70731+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70732 {
70733 *remainder = do_div(dividend, divisor);
70734 return dividend;
70735@@ -79,7 +79,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
70736 * divide.
70737 */
70738 #ifndef div_u64
70739-static inline u64 div_u64(u64 dividend, u32 divisor)
70740+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
70741 {
70742 u32 remainder;
70743 return div_u64_rem(dividend, divisor, &remainder);
70744diff --git a/include/linux/mm.h b/include/linux/mm.h
70745index 66e2f7c..b916b9a 100644
70746--- a/include/linux/mm.h
70747+++ b/include/linux/mm.h
70748@@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
70749 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
70750 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
70751 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
70752+
70753+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
70754+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
70755+#endif
70756+
70757 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
70758
70759 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
70760@@ -200,8 +205,8 @@ struct vm_operations_struct {
70761 /* called by access_process_vm when get_user_pages() fails, typically
70762 * for use by special VMAs that can switch between memory and hardware
70763 */
70764- int (*access)(struct vm_area_struct *vma, unsigned long addr,
70765- void *buf, int len, int write);
70766+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
70767+ void *buf, size_t len, int write);
70768 #ifdef CONFIG_NUMA
70769 /*
70770 * set_policy() op must add a reference to any non-NULL @new mempolicy
70771@@ -231,6 +236,7 @@ struct vm_operations_struct {
70772 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
70773 unsigned long size, pgoff_t pgoff);
70774 };
70775+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
70776
70777 struct mmu_gather;
70778 struct inode;
70779@@ -995,8 +1001,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
70780 unsigned long *pfn);
70781 int follow_phys(struct vm_area_struct *vma, unsigned long address,
70782 unsigned int flags, unsigned long *prot, resource_size_t *phys);
70783-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
70784- void *buf, int len, int write);
70785+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
70786+ void *buf, size_t len, int write);
70787
70788 static inline void unmap_shared_mapping_range(struct address_space *mapping,
70789 loff_t const holebegin, loff_t const holelen)
70790@@ -1035,10 +1041,10 @@ static inline int fixup_user_fault(struct task_struct *tsk,
70791 }
70792 #endif
70793
70794-extern int make_pages_present(unsigned long addr, unsigned long end);
70795-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
70796-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
70797- void *buf, int len, int write);
70798+extern ssize_t make_pages_present(unsigned long addr, unsigned long end);
70799+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
70800+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
70801+ void *buf, size_t len, int write);
70802
70803 int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70804 unsigned long start, int len, unsigned int foll_flags,
70805@@ -1068,34 +1074,6 @@ int set_page_dirty(struct page *page);
70806 int set_page_dirty_lock(struct page *page);
70807 int clear_page_dirty_for_io(struct page *page);
70808
70809-/* Is the vma a continuation of the stack vma above it? */
70810-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
70811-{
70812- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
70813-}
70814-
70815-static inline int stack_guard_page_start(struct vm_area_struct *vma,
70816- unsigned long addr)
70817-{
70818- return (vma->vm_flags & VM_GROWSDOWN) &&
70819- (vma->vm_start == addr) &&
70820- !vma_growsdown(vma->vm_prev, addr);
70821-}
70822-
70823-/* Is the vma a continuation of the stack vma below it? */
70824-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
70825-{
70826- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
70827-}
70828-
70829-static inline int stack_guard_page_end(struct vm_area_struct *vma,
70830- unsigned long addr)
70831-{
70832- return (vma->vm_flags & VM_GROWSUP) &&
70833- (vma->vm_end == addr) &&
70834- !vma_growsup(vma->vm_next, addr);
70835-}
70836-
70837 extern pid_t
70838 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
70839
70840@@ -1198,6 +1176,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
70841 }
70842 #endif
70843
70844+#ifdef CONFIG_MMU
70845+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
70846+#else
70847+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
70848+{
70849+ return __pgprot(0);
70850+}
70851+#endif
70852+
70853 int vma_wants_writenotify(struct vm_area_struct *vma);
70854
70855 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
70856@@ -1216,8 +1203,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
70857 {
70858 return 0;
70859 }
70860+
70861+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
70862+ unsigned long address)
70863+{
70864+ return 0;
70865+}
70866 #else
70867 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
70868+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
70869 #endif
70870
70871 #ifdef __PAGETABLE_PMD_FOLDED
70872@@ -1226,8 +1220,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
70873 {
70874 return 0;
70875 }
70876+
70877+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
70878+ unsigned long address)
70879+{
70880+ return 0;
70881+}
70882 #else
70883 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
70884+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
70885 #endif
70886
70887 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
70888@@ -1245,11 +1246,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
70889 NULL: pud_offset(pgd, address);
70890 }
70891
70892+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
70893+{
70894+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
70895+ NULL: pud_offset(pgd, address);
70896+}
70897+
70898 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
70899 {
70900 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
70901 NULL: pmd_offset(pud, address);
70902 }
70903+
70904+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
70905+{
70906+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
70907+ NULL: pmd_offset(pud, address);
70908+}
70909 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
70910
70911 #if USE_SPLIT_PTLOCKS
70912@@ -1479,6 +1492,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
70913 unsigned long, unsigned long,
70914 unsigned long, unsigned long);
70915 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
70916+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
70917
70918 /* These take the mm semaphore themselves */
70919 extern unsigned long vm_brk(unsigned long, unsigned long);
70920@@ -1573,6 +1587,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
70921 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
70922 struct vm_area_struct **pprev);
70923
70924+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
70925+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
70926+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
70927+
70928 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
70929 NULL if none. Assume start_addr < end_addr. */
70930 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
70931@@ -1601,15 +1619,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
70932 return vma;
70933 }
70934
70935-#ifdef CONFIG_MMU
70936-pgprot_t vm_get_page_prot(unsigned long vm_flags);
70937-#else
70938-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
70939-{
70940- return __pgprot(0);
70941-}
70942-#endif
70943-
70944 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
70945 unsigned long change_prot_numa(struct vm_area_struct *vma,
70946 unsigned long start, unsigned long end);
70947@@ -1649,6 +1658,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
70948 static inline void vm_stat_account(struct mm_struct *mm,
70949 unsigned long flags, struct file *file, long pages)
70950 {
70951+
70952+#ifdef CONFIG_PAX_RANDMMAP
70953+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
70954+#endif
70955+
70956 mm->total_vm += pages;
70957 }
70958 #endif /* CONFIG_PROC_FS */
70959@@ -1721,7 +1735,7 @@ extern int unpoison_memory(unsigned long pfn);
70960 extern int sysctl_memory_failure_early_kill;
70961 extern int sysctl_memory_failure_recovery;
70962 extern void shake_page(struct page *p, int access);
70963-extern atomic_long_t mce_bad_pages;
70964+extern atomic_long_unchecked_t mce_bad_pages;
70965 extern int soft_offline_page(struct page *page, int flags);
70966
70967 extern void dump_page(struct page *page);
70968@@ -1752,5 +1766,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
70969 static inline bool page_is_guard(struct page *page) { return false; }
70970 #endif /* CONFIG_DEBUG_PAGEALLOC */
70971
70972+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
70973+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
70974+#else
70975+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
70976+#endif
70977+
70978 #endif /* __KERNEL__ */
70979 #endif /* _LINUX_MM_H */
70980diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
70981index f8f5162..3aaf20f 100644
70982--- a/include/linux/mm_types.h
70983+++ b/include/linux/mm_types.h
70984@@ -288,6 +288,8 @@ struct vm_area_struct {
70985 #ifdef CONFIG_NUMA
70986 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
70987 #endif
70988+
70989+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
70990 };
70991
70992 struct core_thread {
70993@@ -436,6 +438,24 @@ struct mm_struct {
70994 int first_nid;
70995 #endif
70996 struct uprobes_state uprobes_state;
70997+
70998+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
70999+ unsigned long pax_flags;
71000+#endif
71001+
71002+#ifdef CONFIG_PAX_DLRESOLVE
71003+ unsigned long call_dl_resolve;
71004+#endif
71005+
71006+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
71007+ unsigned long call_syscall;
71008+#endif
71009+
71010+#ifdef CONFIG_PAX_ASLR
71011+ unsigned long delta_mmap; /* randomized offset */
71012+ unsigned long delta_stack; /* randomized offset */
71013+#endif
71014+
71015 };
71016
71017 /* first nid will either be a valid NID or one of these values */
71018diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
71019index c5d5278..f0b68c8 100644
71020--- a/include/linux/mmiotrace.h
71021+++ b/include/linux/mmiotrace.h
71022@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
71023 /* Called from ioremap.c */
71024 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
71025 void __iomem *addr);
71026-extern void mmiotrace_iounmap(volatile void __iomem *addr);
71027+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
71028
71029 /* For anyone to insert markers. Remember trailing newline. */
71030 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
71031@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
71032 {
71033 }
71034
71035-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
71036+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
71037 {
71038 }
71039
71040diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
71041index 73b64a3..6562925 100644
71042--- a/include/linux/mmzone.h
71043+++ b/include/linux/mmzone.h
71044@@ -412,7 +412,7 @@ struct zone {
71045 unsigned long flags; /* zone flags, see below */
71046
71047 /* Zone statistics */
71048- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
71049+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
71050
71051 /*
71052 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
71053diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
71054index fed3def..c933f99 100644
71055--- a/include/linux/mod_devicetable.h
71056+++ b/include/linux/mod_devicetable.h
71057@@ -12,7 +12,7 @@
71058 typedef unsigned long kernel_ulong_t;
71059 #endif
71060
71061-#define PCI_ANY_ID (~0)
71062+#define PCI_ANY_ID ((__u16)~0)
71063
71064 struct pci_device_id {
71065 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
71066@@ -139,7 +139,7 @@ struct usb_device_id {
71067 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
71068 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
71069
71070-#define HID_ANY_ID (~0)
71071+#define HID_ANY_ID (~0U)
71072 #define HID_BUS_ANY 0xffff
71073 #define HID_GROUP_ANY 0x0000
71074
71075@@ -498,7 +498,7 @@ struct dmi_system_id {
71076 const char *ident;
71077 struct dmi_strmatch matches[4];
71078 void *driver_data;
71079-};
71080+} __do_const;
71081 /*
71082 * struct dmi_device_id appears during expansion of
71083 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
71084diff --git a/include/linux/module.h b/include/linux/module.h
71085index 1375ee3..ced8177 100644
71086--- a/include/linux/module.h
71087+++ b/include/linux/module.h
71088@@ -17,9 +17,11 @@
71089 #include <linux/moduleparam.h>
71090 #include <linux/tracepoint.h>
71091 #include <linux/export.h>
71092+#include <linux/fs.h>
71093
71094 #include <linux/percpu.h>
71095 #include <asm/module.h>
71096+#include <asm/pgtable.h>
71097
71098 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
71099 #define MODULE_SIG_STRING "~Module signature appended~\n"
71100@@ -54,12 +56,13 @@ struct module_attribute {
71101 int (*test)(struct module *);
71102 void (*free)(struct module *);
71103 };
71104+typedef struct module_attribute __no_const module_attribute_no_const;
71105
71106 struct module_version_attribute {
71107 struct module_attribute mattr;
71108 const char *module_name;
71109 const char *version;
71110-} __attribute__ ((__aligned__(sizeof(void *))));
71111+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
71112
71113 extern ssize_t __modver_version_show(struct module_attribute *,
71114 struct module_kobject *, char *);
71115@@ -232,7 +235,7 @@ struct module
71116
71117 /* Sysfs stuff. */
71118 struct module_kobject mkobj;
71119- struct module_attribute *modinfo_attrs;
71120+ module_attribute_no_const *modinfo_attrs;
71121 const char *version;
71122 const char *srcversion;
71123 struct kobject *holders_dir;
71124@@ -281,19 +284,16 @@ struct module
71125 int (*init)(void);
71126
71127 /* If this is non-NULL, vfree after init() returns */
71128- void *module_init;
71129+ void *module_init_rx, *module_init_rw;
71130
71131 /* Here is the actual code + data, vfree'd on unload. */
71132- void *module_core;
71133+ void *module_core_rx, *module_core_rw;
71134
71135 /* Here are the sizes of the init and core sections */
71136- unsigned int init_size, core_size;
71137+ unsigned int init_size_rw, core_size_rw;
71138
71139 /* The size of the executable code in each section. */
71140- unsigned int init_text_size, core_text_size;
71141-
71142- /* Size of RO sections of the module (text+rodata) */
71143- unsigned int init_ro_size, core_ro_size;
71144+ unsigned int init_size_rx, core_size_rx;
71145
71146 /* Arch-specific module values */
71147 struct mod_arch_specific arch;
71148@@ -349,6 +349,10 @@ struct module
71149 #ifdef CONFIG_EVENT_TRACING
71150 struct ftrace_event_call **trace_events;
71151 unsigned int num_trace_events;
71152+ struct file_operations trace_id;
71153+ struct file_operations trace_enable;
71154+ struct file_operations trace_format;
71155+ struct file_operations trace_filter;
71156 #endif
71157 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
71158 unsigned int num_ftrace_callsites;
71159@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
71160 bool is_module_percpu_address(unsigned long addr);
71161 bool is_module_text_address(unsigned long addr);
71162
71163+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
71164+{
71165+
71166+#ifdef CONFIG_PAX_KERNEXEC
71167+ if (ktla_ktva(addr) >= (unsigned long)start &&
71168+ ktla_ktva(addr) < (unsigned long)start + size)
71169+ return 1;
71170+#endif
71171+
71172+ return ((void *)addr >= start && (void *)addr < start + size);
71173+}
71174+
71175+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
71176+{
71177+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
71178+}
71179+
71180+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
71181+{
71182+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
71183+}
71184+
71185+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
71186+{
71187+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
71188+}
71189+
71190+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
71191+{
71192+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
71193+}
71194+
71195 static inline int within_module_core(unsigned long addr, struct module *mod)
71196 {
71197- return (unsigned long)mod->module_core <= addr &&
71198- addr < (unsigned long)mod->module_core + mod->core_size;
71199+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
71200 }
71201
71202 static inline int within_module_init(unsigned long addr, struct module *mod)
71203 {
71204- return (unsigned long)mod->module_init <= addr &&
71205- addr < (unsigned long)mod->module_init + mod->init_size;
71206+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
71207 }
71208
71209 /* Search for module by name: must hold module_mutex. */
71210diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
71211index 560ca53..ef621ef 100644
71212--- a/include/linux/moduleloader.h
71213+++ b/include/linux/moduleloader.h
71214@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
71215 sections. Returns NULL on failure. */
71216 void *module_alloc(unsigned long size);
71217
71218+#ifdef CONFIG_PAX_KERNEXEC
71219+void *module_alloc_exec(unsigned long size);
71220+#else
71221+#define module_alloc_exec(x) module_alloc(x)
71222+#endif
71223+
71224 /* Free memory returned from module_alloc. */
71225 void module_free(struct module *mod, void *module_region);
71226
71227+#ifdef CONFIG_PAX_KERNEXEC
71228+void module_free_exec(struct module *mod, void *module_region);
71229+#else
71230+#define module_free_exec(x, y) module_free((x), (y))
71231+#endif
71232+
71233 /*
71234 * Apply the given relocation to the (simplified) ELF. Return -error
71235 * or 0.
71236@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
71237 unsigned int relsec,
71238 struct module *me)
71239 {
71240+#ifdef CONFIG_MODULES
71241 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
71242+#endif
71243 return -ENOEXEC;
71244 }
71245 #endif
71246@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
71247 unsigned int relsec,
71248 struct module *me)
71249 {
71250+#ifdef CONFIG_MODULES
71251 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
71252+#endif
71253 return -ENOEXEC;
71254 }
71255 #endif
71256diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
71257index 137b419..fe663ec 100644
71258--- a/include/linux/moduleparam.h
71259+++ b/include/linux/moduleparam.h
71260@@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
71261 * @len is usually just sizeof(string).
71262 */
71263 #define module_param_string(name, string, len, perm) \
71264- static const struct kparam_string __param_string_##name \
71265+ static const struct kparam_string __param_string_##name __used \
71266 = { len, string }; \
71267 __module_param_call(MODULE_PARAM_PREFIX, name, \
71268 &param_ops_string, \
71269@@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
71270 */
71271 #define module_param_array_named(name, array, type, nump, perm) \
71272 param_check_##type(name, &(array)[0]); \
71273- static const struct kparam_array __param_arr_##name \
71274+ static const struct kparam_array __param_arr_##name __used \
71275 = { .max = ARRAY_SIZE(array), .num = nump, \
71276 .ops = &param_ops_##type, \
71277 .elemsize = sizeof(array[0]), .elem = array }; \
71278diff --git a/include/linux/namei.h b/include/linux/namei.h
71279index 5a5ff57..5ae5070 100644
71280--- a/include/linux/namei.h
71281+++ b/include/linux/namei.h
71282@@ -19,7 +19,7 @@ struct nameidata {
71283 unsigned seq;
71284 int last_type;
71285 unsigned depth;
71286- char *saved_names[MAX_NESTED_LINKS + 1];
71287+ const char *saved_names[MAX_NESTED_LINKS + 1];
71288 };
71289
71290 /*
71291@@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
71292
71293 extern void nd_jump_link(struct nameidata *nd, struct path *path);
71294
71295-static inline void nd_set_link(struct nameidata *nd, char *path)
71296+static inline void nd_set_link(struct nameidata *nd, const char *path)
71297 {
71298 nd->saved_names[nd->depth] = path;
71299 }
71300
71301-static inline char *nd_get_link(struct nameidata *nd)
71302+static inline const char *nd_get_link(const struct nameidata *nd)
71303 {
71304 return nd->saved_names[nd->depth];
71305 }
71306diff --git a/include/linux/net.h b/include/linux/net.h
71307index aa16731..514b875 100644
71308--- a/include/linux/net.h
71309+++ b/include/linux/net.h
71310@@ -183,7 +183,7 @@ struct net_proto_family {
71311 int (*create)(struct net *net, struct socket *sock,
71312 int protocol, int kern);
71313 struct module *owner;
71314-};
71315+} __do_const;
71316
71317 struct iovec;
71318 struct kvec;
71319diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
71320index 9ef07d0..130a5d9 100644
71321--- a/include/linux/netdevice.h
71322+++ b/include/linux/netdevice.h
71323@@ -1012,6 +1012,7 @@ struct net_device_ops {
71324 u32 pid, u32 seq,
71325 struct net_device *dev);
71326 };
71327+typedef struct net_device_ops __no_const net_device_ops_no_const;
71328
71329 /*
71330 * The DEVICE structure.
71331@@ -1078,7 +1079,7 @@ struct net_device {
71332 int iflink;
71333
71334 struct net_device_stats stats;
71335- atomic_long_t rx_dropped; /* dropped packets by core network
71336+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
71337 * Do not use this in drivers.
71338 */
71339
71340diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
71341index ee14284..bc65d63 100644
71342--- a/include/linux/netfilter.h
71343+++ b/include/linux/netfilter.h
71344@@ -82,7 +82,7 @@ struct nf_sockopt_ops {
71345 #endif
71346 /* Use the module struct to lock set/get code in place */
71347 struct module *owner;
71348-};
71349+} __do_const;
71350
71351 /* Function to register/unregister hook points. */
71352 int nf_register_hook(struct nf_hook_ops *reg);
71353diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
71354index 7958e84..ed74d7a 100644
71355--- a/include/linux/netfilter/ipset/ip_set.h
71356+++ b/include/linux/netfilter/ipset/ip_set.h
71357@@ -98,7 +98,7 @@ struct ip_set_type_variant {
71358 /* Return true if "b" set is the same as "a"
71359 * according to the create set parameters */
71360 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
71361-};
71362+} __do_const;
71363
71364 /* The core set type structure */
71365 struct ip_set_type {
71366diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
71367index 4966dde..7d8ce06 100644
71368--- a/include/linux/netfilter/nfnetlink.h
71369+++ b/include/linux/netfilter/nfnetlink.h
71370@@ -16,7 +16,7 @@ struct nfnl_callback {
71371 const struct nlattr * const cda[]);
71372 const struct nla_policy *policy; /* netlink attribute policy */
71373 const u_int16_t attr_count; /* number of nlattr's */
71374-};
71375+} __do_const;
71376
71377 struct nfnetlink_subsystem {
71378 const char *name;
71379diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
71380new file mode 100644
71381index 0000000..33f4af8
71382--- /dev/null
71383+++ b/include/linux/netfilter/xt_gradm.h
71384@@ -0,0 +1,9 @@
71385+#ifndef _LINUX_NETFILTER_XT_GRADM_H
71386+#define _LINUX_NETFILTER_XT_GRADM_H 1
71387+
71388+struct xt_gradm_mtinfo {
71389+ __u16 flags;
71390+ __u16 invflags;
71391+};
71392+
71393+#endif
71394diff --git a/include/linux/nls.h b/include/linux/nls.h
71395index 5dc635f..35f5e11 100644
71396--- a/include/linux/nls.h
71397+++ b/include/linux/nls.h
71398@@ -31,7 +31,7 @@ struct nls_table {
71399 const unsigned char *charset2upper;
71400 struct module *owner;
71401 struct nls_table *next;
71402-};
71403+} __do_const;
71404
71405 /* this value hold the maximum octet of charset */
71406 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
71407diff --git a/include/linux/notifier.h b/include/linux/notifier.h
71408index d65746e..62e72c2 100644
71409--- a/include/linux/notifier.h
71410+++ b/include/linux/notifier.h
71411@@ -51,7 +51,8 @@ struct notifier_block {
71412 int (*notifier_call)(struct notifier_block *, unsigned long, void *);
71413 struct notifier_block __rcu *next;
71414 int priority;
71415-};
71416+} __do_const;
71417+typedef struct notifier_block __no_const notifier_block_no_const;
71418
71419 struct atomic_notifier_head {
71420 spinlock_t lock;
71421diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
71422index a4c5624..79d6d88 100644
71423--- a/include/linux/oprofile.h
71424+++ b/include/linux/oprofile.h
71425@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
71426 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
71427 char const * name, ulong * val);
71428
71429-/** Create a file for read-only access to an atomic_t. */
71430+/** Create a file for read-only access to an atomic_unchecked_t. */
71431 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
71432- char const * name, atomic_t * val);
71433+ char const * name, atomic_unchecked_t * val);
71434
71435 /** create a directory */
71436 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
71437diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
71438index 45fc162..01a4068 100644
71439--- a/include/linux/pci_hotplug.h
71440+++ b/include/linux/pci_hotplug.h
71441@@ -80,7 +80,8 @@ struct hotplug_slot_ops {
71442 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
71443 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
71444 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
71445-};
71446+} __do_const;
71447+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
71448
71449 /**
71450 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
71451diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
71452index a280650..2b67b91 100644
71453--- a/include/linux/perf_event.h
71454+++ b/include/linux/perf_event.h
71455@@ -328,8 +328,8 @@ struct perf_event {
71456
71457 enum perf_event_active_state state;
71458 unsigned int attach_state;
71459- local64_t count;
71460- atomic64_t child_count;
71461+ local64_t count; /* PaX: fix it one day */
71462+ atomic64_unchecked_t child_count;
71463
71464 /*
71465 * These are the total time in nanoseconds that the event
71466@@ -380,8 +380,8 @@ struct perf_event {
71467 * These accumulate total time (in nanoseconds) that children
71468 * events have been enabled and running, respectively.
71469 */
71470- atomic64_t child_total_time_enabled;
71471- atomic64_t child_total_time_running;
71472+ atomic64_unchecked_t child_total_time_enabled;
71473+ atomic64_unchecked_t child_total_time_running;
71474
71475 /*
71476 * Protect attach/detach and child_list:
71477@@ -807,7 +807,7 @@ static inline void perf_restore_debug_store(void) { }
71478 */
71479 #define perf_cpu_notifier(fn) \
71480 do { \
71481- static struct notifier_block fn##_nb __cpuinitdata = \
71482+ static struct notifier_block fn##_nb = \
71483 { .notifier_call = fn, .priority = CPU_PRI_PERF }; \
71484 unsigned long cpu = smp_processor_id(); \
71485 unsigned long flags; \
71486diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
71487index ad1a427..6419649 100644
71488--- a/include/linux/pipe_fs_i.h
71489+++ b/include/linux/pipe_fs_i.h
71490@@ -45,9 +45,9 @@ struct pipe_buffer {
71491 struct pipe_inode_info {
71492 wait_queue_head_t wait;
71493 unsigned int nrbufs, curbuf, buffers;
71494- unsigned int readers;
71495- unsigned int writers;
71496- unsigned int waiting_writers;
71497+ atomic_t readers;
71498+ atomic_t writers;
71499+ atomic_t waiting_writers;
71500 unsigned int r_counter;
71501 unsigned int w_counter;
71502 struct page *tmp_page;
71503diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
71504index 5f28cae..3d23723 100644
71505--- a/include/linux/platform_data/usb-ehci-s5p.h
71506+++ b/include/linux/platform_data/usb-ehci-s5p.h
71507@@ -14,7 +14,7 @@
71508 struct s5p_ehci_platdata {
71509 int (*phy_init)(struct platform_device *pdev, int type);
71510 int (*phy_exit)(struct platform_device *pdev, int type);
71511-};
71512+} __no_const;
71513
71514 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
71515
71516diff --git a/include/linux/platform_data/usb-exynos.h b/include/linux/platform_data/usb-exynos.h
71517index c256c59..8ea94c7 100644
71518--- a/include/linux/platform_data/usb-exynos.h
71519+++ b/include/linux/platform_data/usb-exynos.h
71520@@ -14,7 +14,7 @@
71521 struct exynos4_ohci_platdata {
71522 int (*phy_init)(struct platform_device *pdev, int type);
71523 int (*phy_exit)(struct platform_device *pdev, int type);
71524-};
71525+} __no_const;
71526
71527 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
71528
71529diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
71530index 7c1d252..c5c773e 100644
71531--- a/include/linux/pm_domain.h
71532+++ b/include/linux/pm_domain.h
71533@@ -48,7 +48,7 @@ struct gpd_dev_ops {
71534
71535 struct gpd_cpu_data {
71536 unsigned int saved_exit_latency;
71537- struct cpuidle_state *idle_state;
71538+ cpuidle_state_no_const *idle_state;
71539 };
71540
71541 struct generic_pm_domain {
71542diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
71543index f271860..6b3bec5 100644
71544--- a/include/linux/pm_runtime.h
71545+++ b/include/linux/pm_runtime.h
71546@@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
71547
71548 static inline void pm_runtime_mark_last_busy(struct device *dev)
71549 {
71550- ACCESS_ONCE(dev->power.last_busy) = jiffies;
71551+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
71552 }
71553
71554 #else /* !CONFIG_PM_RUNTIME */
71555diff --git a/include/linux/pnp.h b/include/linux/pnp.h
71556index 195aafc..49a7bc2 100644
71557--- a/include/linux/pnp.h
71558+++ b/include/linux/pnp.h
71559@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
71560 struct pnp_fixup {
71561 char id[7];
71562 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
71563-};
71564+} __do_const;
71565
71566 /* config parameters */
71567 #define PNP_CONFIG_NORMAL 0x0001
71568diff --git a/include/linux/poison.h b/include/linux/poison.h
71569index 2110a81..13a11bb 100644
71570--- a/include/linux/poison.h
71571+++ b/include/linux/poison.h
71572@@ -19,8 +19,8 @@
71573 * under normal circumstances, used to verify that nobody uses
71574 * non-initialized list entries.
71575 */
71576-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
71577-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
71578+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
71579+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
71580
71581 /********** include/linux/timer.h **********/
71582 /*
71583diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
71584index c0f44c2..1572583 100644
71585--- a/include/linux/power/smartreflex.h
71586+++ b/include/linux/power/smartreflex.h
71587@@ -238,7 +238,7 @@ struct omap_sr_class_data {
71588 int (*notify)(struct omap_sr *sr, u32 status);
71589 u8 notify_flags;
71590 u8 class_type;
71591-};
71592+} __do_const;
71593
71594 /**
71595 * struct omap_sr_nvalue_table - Smartreflex n-target value info
71596diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
71597index 4ea1d37..80f4b33 100644
71598--- a/include/linux/ppp-comp.h
71599+++ b/include/linux/ppp-comp.h
71600@@ -84,7 +84,7 @@ struct compressor {
71601 struct module *owner;
71602 /* Extra skb space needed by the compressor algorithm */
71603 unsigned int comp_extra;
71604-};
71605+} __do_const;
71606
71607 /*
71608 * The return value from decompress routine is the length of the
71609diff --git a/include/linux/printk.h b/include/linux/printk.h
71610index 9afc01e..92c32e8 100644
71611--- a/include/linux/printk.h
71612+++ b/include/linux/printk.h
71613@@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
71614 extern int printk_needs_cpu(int cpu);
71615 extern void printk_tick(void);
71616
71617+extern int kptr_restrict;
71618+
71619 #ifdef CONFIG_PRINTK
71620 asmlinkage __printf(5, 0)
71621 int vprintk_emit(int facility, int level,
71622@@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
71623
71624 extern int printk_delay_msec;
71625 extern int dmesg_restrict;
71626-extern int kptr_restrict;
71627
71628 void log_buf_kexec_setup(void);
71629 void __init setup_log_buf(int early);
71630diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
71631index 32676b3..e46f2c0 100644
71632--- a/include/linux/proc_fs.h
71633+++ b/include/linux/proc_fs.h
71634@@ -159,6 +159,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
71635 return proc_create_data(name, mode, parent, proc_fops, NULL);
71636 }
71637
71638+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
71639+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
71640+{
71641+#ifdef CONFIG_GRKERNSEC_PROC_USER
71642+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
71643+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
71644+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
71645+#else
71646+ return proc_create_data(name, mode, parent, proc_fops, NULL);
71647+#endif
71648+}
71649+
71650 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
71651 umode_t mode, struct proc_dir_entry *base,
71652 read_proc_t *read_proc, void * data)
71653@@ -268,7 +280,7 @@ struct proc_ns_operations {
71654 void (*put)(void *ns);
71655 int (*install)(struct nsproxy *nsproxy, void *ns);
71656 unsigned int (*inum)(void *ns);
71657-};
71658+} __do_const;
71659 extern const struct proc_ns_operations netns_operations;
71660 extern const struct proc_ns_operations utsns_operations;
71661 extern const struct proc_ns_operations ipcns_operations;
71662diff --git a/include/linux/random.h b/include/linux/random.h
71663index d984608..d6f0042 100644
71664--- a/include/linux/random.h
71665+++ b/include/linux/random.h
71666@@ -39,6 +39,11 @@ void prandom_seed(u32 seed);
71667 u32 prandom_u32_state(struct rnd_state *);
71668 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
71669
71670+static inline unsigned long pax_get_random_long(void)
71671+{
71672+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
71673+}
71674+
71675 /*
71676 * Handle minimum values for seeds
71677 */
71678diff --git a/include/linux/rculist.h b/include/linux/rculist.h
71679index c92dd28..08f4eab 100644
71680--- a/include/linux/rculist.h
71681+++ b/include/linux/rculist.h
71682@@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
71683 struct list_head *prev, struct list_head *next);
71684 #endif
71685
71686+extern void __pax_list_add_rcu(struct list_head *new,
71687+ struct list_head *prev, struct list_head *next);
71688+
71689 /**
71690 * list_add_rcu - add a new entry to rcu-protected list
71691 * @new: new entry to be added
71692@@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
71693 __list_add_rcu(new, head, head->next);
71694 }
71695
71696+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
71697+{
71698+ __pax_list_add_rcu(new, head, head->next);
71699+}
71700+
71701 /**
71702 * list_add_tail_rcu - add a new entry to rcu-protected list
71703 * @new: new entry to be added
71704@@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
71705 __list_add_rcu(new, head->prev, head);
71706 }
71707
71708+static inline void pax_list_add_tail_rcu(struct list_head *new,
71709+ struct list_head *head)
71710+{
71711+ __pax_list_add_rcu(new, head->prev, head);
71712+}
71713+
71714 /**
71715 * list_del_rcu - deletes entry from list without re-initialization
71716 * @entry: the element to delete from the list.
71717@@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
71718 entry->prev = LIST_POISON2;
71719 }
71720
71721+extern void pax_list_del_rcu(struct list_head *entry);
71722+
71723 /**
71724 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
71725 * @n: the element to delete from the hash list.
71726diff --git a/include/linux/reboot.h b/include/linux/reboot.h
71727index 23b3630..e1bc12b 100644
71728--- a/include/linux/reboot.h
71729+++ b/include/linux/reboot.h
71730@@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
71731 * Architecture-specific implementations of sys_reboot commands.
71732 */
71733
71734-extern void machine_restart(char *cmd);
71735-extern void machine_halt(void);
71736-extern void machine_power_off(void);
71737+extern void machine_restart(char *cmd) __noreturn;
71738+extern void machine_halt(void) __noreturn;
71739+extern void machine_power_off(void) __noreturn;
71740
71741 extern void machine_shutdown(void);
71742 struct pt_regs;
71743@@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
71744 */
71745
71746 extern void kernel_restart_prepare(char *cmd);
71747-extern void kernel_restart(char *cmd);
71748-extern void kernel_halt(void);
71749-extern void kernel_power_off(void);
71750+extern void kernel_restart(char *cmd) __noreturn;
71751+extern void kernel_halt(void) __noreturn;
71752+extern void kernel_power_off(void) __noreturn;
71753
71754 extern int C_A_D; /* for sysctl */
71755 void ctrl_alt_del(void);
71756@@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
71757 * Emergency restart, callable from an interrupt handler.
71758 */
71759
71760-extern void emergency_restart(void);
71761+extern void emergency_restart(void) __noreturn;
71762 #include <asm/emergency-restart.h>
71763
71764 #endif /* _LINUX_REBOOT_H */
71765diff --git a/include/linux/regset.h b/include/linux/regset.h
71766index 8e0c9fe..ac4d221 100644
71767--- a/include/linux/regset.h
71768+++ b/include/linux/regset.h
71769@@ -161,7 +161,8 @@ struct user_regset {
71770 unsigned int align;
71771 unsigned int bias;
71772 unsigned int core_note_type;
71773-};
71774+} __do_const;
71775+typedef struct user_regset __no_const user_regset_no_const;
71776
71777 /**
71778 * struct user_regset_view - available regsets
71779diff --git a/include/linux/relay.h b/include/linux/relay.h
71780index 91cacc3..b55ff74 100644
71781--- a/include/linux/relay.h
71782+++ b/include/linux/relay.h
71783@@ -160,7 +160,7 @@ struct rchan_callbacks
71784 * The callback should return 0 if successful, negative if not.
71785 */
71786 int (*remove_buf_file)(struct dentry *dentry);
71787-};
71788+} __no_const;
71789
71790 /*
71791 * CONFIG_RELAY kernel API, kernel/relay.c
71792diff --git a/include/linux/rio.h b/include/linux/rio.h
71793index a3e7842..d973ca6 100644
71794--- a/include/linux/rio.h
71795+++ b/include/linux/rio.h
71796@@ -339,7 +339,7 @@ struct rio_ops {
71797 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
71798 u64 rstart, u32 size, u32 flags);
71799 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
71800-};
71801+} __no_const;
71802
71803 #define RIO_RESOURCE_MEM 0x00000100
71804 #define RIO_RESOURCE_DOORBELL 0x00000200
71805diff --git a/include/linux/rmap.h b/include/linux/rmap.h
71806index c20635c..2f5def4 100644
71807--- a/include/linux/rmap.h
71808+++ b/include/linux/rmap.h
71809@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
71810 void anon_vma_init(void); /* create anon_vma_cachep */
71811 int anon_vma_prepare(struct vm_area_struct *);
71812 void unlink_anon_vmas(struct vm_area_struct *);
71813-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
71814-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
71815+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
71816+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
71817
71818 static inline void anon_vma_merge(struct vm_area_struct *vma,
71819 struct vm_area_struct *next)
71820diff --git a/include/linux/sched.h b/include/linux/sched.h
71821index d211247..eac6c2c 100644
71822--- a/include/linux/sched.h
71823+++ b/include/linux/sched.h
71824@@ -61,6 +61,7 @@ struct bio_list;
71825 struct fs_struct;
71826 struct perf_event_context;
71827 struct blk_plug;
71828+struct linux_binprm;
71829
71830 /*
71831 * List of flags we want to share for kernel threads,
71832@@ -327,7 +328,7 @@ extern char __sched_text_start[], __sched_text_end[];
71833 extern int in_sched_functions(unsigned long addr);
71834
71835 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
71836-extern signed long schedule_timeout(signed long timeout);
71837+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
71838 extern signed long schedule_timeout_interruptible(signed long timeout);
71839 extern signed long schedule_timeout_killable(signed long timeout);
71840 extern signed long schedule_timeout_uninterruptible(signed long timeout);
71841@@ -354,10 +355,23 @@ struct user_namespace;
71842 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
71843
71844 extern int sysctl_max_map_count;
71845+extern unsigned long sysctl_heap_stack_gap;
71846
71847 #include <linux/aio.h>
71848
71849 #ifdef CONFIG_MMU
71850+
71851+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
71852+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
71853+#else
71854+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
71855+{
71856+ return 0;
71857+}
71858+#endif
71859+
71860+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
71861+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
71862 extern void arch_pick_mmap_layout(struct mm_struct *mm);
71863 extern unsigned long
71864 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
71865@@ -639,6 +653,17 @@ struct signal_struct {
71866 #ifdef CONFIG_TASKSTATS
71867 struct taskstats *stats;
71868 #endif
71869+
71870+#ifdef CONFIG_GRKERNSEC
71871+ u32 curr_ip;
71872+ u32 saved_ip;
71873+ u32 gr_saddr;
71874+ u32 gr_daddr;
71875+ u16 gr_sport;
71876+ u16 gr_dport;
71877+ u8 used_accept:1;
71878+#endif
71879+
71880 #ifdef CONFIG_AUDIT
71881 unsigned audit_tty;
71882 struct tty_audit_buf *tty_audit_buf;
71883@@ -717,6 +742,11 @@ struct user_struct {
71884 struct key *session_keyring; /* UID's default session keyring */
71885 #endif
71886
71887+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
71888+ unsigned int banned;
71889+ unsigned long ban_expires;
71890+#endif
71891+
71892 /* Hash table maintenance information */
71893 struct hlist_node uidhash_node;
71894 kuid_t uid;
71895@@ -1116,7 +1146,7 @@ struct sched_class {
71896 #ifdef CONFIG_FAIR_GROUP_SCHED
71897 void (*task_move_group) (struct task_struct *p, int on_rq);
71898 #endif
71899-};
71900+} __do_const;
71901
71902 struct load_weight {
71903 unsigned long weight, inv_weight;
71904@@ -1360,8 +1390,8 @@ struct task_struct {
71905 struct list_head thread_group;
71906
71907 struct completion *vfork_done; /* for vfork() */
71908- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
71909- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
71910+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
71911+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
71912
71913 cputime_t utime, stime, utimescaled, stimescaled;
71914 cputime_t gtime;
71915@@ -1377,11 +1407,6 @@ struct task_struct {
71916 struct task_cputime cputime_expires;
71917 struct list_head cpu_timers[3];
71918
71919-/* process credentials */
71920- const struct cred __rcu *real_cred; /* objective and real subjective task
71921- * credentials (COW) */
71922- const struct cred __rcu *cred; /* effective (overridable) subjective task
71923- * credentials (COW) */
71924 char comm[TASK_COMM_LEN]; /* executable name excluding path
71925 - access with [gs]et_task_comm (which lock
71926 it with task_lock())
71927@@ -1398,6 +1423,10 @@ struct task_struct {
71928 #endif
71929 /* CPU-specific state of this task */
71930 struct thread_struct thread;
71931+/* thread_info moved to task_struct */
71932+#ifdef CONFIG_X86
71933+ struct thread_info tinfo;
71934+#endif
71935 /* filesystem information */
71936 struct fs_struct *fs;
71937 /* open file information */
71938@@ -1471,6 +1500,10 @@ struct task_struct {
71939 gfp_t lockdep_reclaim_gfp;
71940 #endif
71941
71942+/* process credentials */
71943+ const struct cred __rcu *real_cred; /* objective and real subjective task
71944+ * credentials (COW) */
71945+
71946 /* journalling filesystem info */
71947 void *journal_info;
71948
71949@@ -1509,6 +1542,10 @@ struct task_struct {
71950 /* cg_list protected by css_set_lock and tsk->alloc_lock */
71951 struct list_head cg_list;
71952 #endif
71953+
71954+ const struct cred __rcu *cred; /* effective (overridable) subjective task
71955+ * credentials (COW) */
71956+
71957 #ifdef CONFIG_FUTEX
71958 struct robust_list_head __user *robust_list;
71959 #ifdef CONFIG_COMPAT
71960@@ -1605,8 +1642,74 @@ struct task_struct {
71961 #ifdef CONFIG_UPROBES
71962 struct uprobe_task *utask;
71963 #endif
71964+
71965+#ifdef CONFIG_GRKERNSEC
71966+ /* grsecurity */
71967+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71968+ u64 exec_id;
71969+#endif
71970+#ifdef CONFIG_GRKERNSEC_SETXID
71971+ const struct cred *delayed_cred;
71972+#endif
71973+ struct dentry *gr_chroot_dentry;
71974+ struct acl_subject_label *acl;
71975+ struct acl_role_label *role;
71976+ struct file *exec_file;
71977+ unsigned long brute_expires;
71978+ u16 acl_role_id;
71979+ /* is this the task that authenticated to the special role */
71980+ u8 acl_sp_role;
71981+ u8 is_writable;
71982+ u8 brute;
71983+ u8 gr_is_chrooted;
71984+#endif
71985+
71986 };
71987
71988+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
71989+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
71990+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
71991+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
71992+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
71993+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
71994+
71995+#ifdef CONFIG_PAX_SOFTMODE
71996+extern int pax_softmode;
71997+#endif
71998+
71999+extern int pax_check_flags(unsigned long *);
72000+
72001+/* if tsk != current then task_lock must be held on it */
72002+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
72003+static inline unsigned long pax_get_flags(struct task_struct *tsk)
72004+{
72005+ if (likely(tsk->mm))
72006+ return tsk->mm->pax_flags;
72007+ else
72008+ return 0UL;
72009+}
72010+
72011+/* if tsk != current then task_lock must be held on it */
72012+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
72013+{
72014+ if (likely(tsk->mm)) {
72015+ tsk->mm->pax_flags = flags;
72016+ return 0;
72017+ }
72018+ return -EINVAL;
72019+}
72020+#endif
72021+
72022+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
72023+extern void pax_set_initial_flags(struct linux_binprm *bprm);
72024+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
72025+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
72026+#endif
72027+
72028+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
72029+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
72030+extern void pax_report_refcount_overflow(struct pt_regs *regs);
72031+
72032 /* Future-safe accessor for struct task_struct's cpus_allowed. */
72033 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
72034
72035@@ -1696,7 +1799,7 @@ struct pid_namespace;
72036 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
72037 struct pid_namespace *ns);
72038
72039-static inline pid_t task_pid_nr(struct task_struct *tsk)
72040+static inline pid_t task_pid_nr(const struct task_struct *tsk)
72041 {
72042 return tsk->pid;
72043 }
72044@@ -2155,7 +2258,9 @@ void yield(void);
72045 extern struct exec_domain default_exec_domain;
72046
72047 union thread_union {
72048+#ifndef CONFIG_X86
72049 struct thread_info thread_info;
72050+#endif
72051 unsigned long stack[THREAD_SIZE/sizeof(long)];
72052 };
72053
72054@@ -2188,6 +2293,7 @@ extern struct pid_namespace init_pid_ns;
72055 */
72056
72057 extern struct task_struct *find_task_by_vpid(pid_t nr);
72058+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
72059 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
72060 struct pid_namespace *ns);
72061
72062@@ -2344,7 +2450,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
72063 extern void exit_itimers(struct signal_struct *);
72064 extern void flush_itimer_signals(void);
72065
72066-extern void do_group_exit(int);
72067+extern __noreturn void do_group_exit(int);
72068
72069 extern int allow_signal(int);
72070 extern int disallow_signal(int);
72071@@ -2545,9 +2651,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
72072
72073 #endif
72074
72075-static inline int object_is_on_stack(void *obj)
72076+static inline int object_starts_on_stack(void *obj)
72077 {
72078- void *stack = task_stack_page(current);
72079+ const void *stack = task_stack_page(current);
72080
72081 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
72082 }
72083diff --git a/include/linux/security.h b/include/linux/security.h
72084index eee7478..290f7ba 100644
72085--- a/include/linux/security.h
72086+++ b/include/linux/security.h
72087@@ -26,6 +26,7 @@
72088 #include <linux/capability.h>
72089 #include <linux/slab.h>
72090 #include <linux/err.h>
72091+#include <linux/grsecurity.h>
72092
72093 struct linux_binprm;
72094 struct cred;
72095diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
72096index 68a04a3..866e6a1 100644
72097--- a/include/linux/seq_file.h
72098+++ b/include/linux/seq_file.h
72099@@ -26,6 +26,9 @@ struct seq_file {
72100 struct mutex lock;
72101 const struct seq_operations *op;
72102 int poll_event;
72103+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
72104+ u64 exec_id;
72105+#endif
72106 #ifdef CONFIG_USER_NS
72107 struct user_namespace *user_ns;
72108 #endif
72109@@ -38,6 +41,7 @@ struct seq_operations {
72110 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
72111 int (*show) (struct seq_file *m, void *v);
72112 };
72113+typedef struct seq_operations __no_const seq_operations_no_const;
72114
72115 #define SEQ_SKIP 1
72116
72117diff --git a/include/linux/shm.h b/include/linux/shm.h
72118index 429c199..4d42e38 100644
72119--- a/include/linux/shm.h
72120+++ b/include/linux/shm.h
72121@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
72122
72123 /* The task created the shm object. NULL if the task is dead. */
72124 struct task_struct *shm_creator;
72125+#ifdef CONFIG_GRKERNSEC
72126+ time_t shm_createtime;
72127+ pid_t shm_lapid;
72128+#endif
72129 };
72130
72131 /* shm_mode upper byte flags */
72132diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
72133index 98399e2..7c74c41 100644
72134--- a/include/linux/skbuff.h
72135+++ b/include/linux/skbuff.h
72136@@ -590,7 +590,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
72137 extern struct sk_buff *__alloc_skb(unsigned int size,
72138 gfp_t priority, int flags, int node);
72139 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
72140-static inline struct sk_buff *alloc_skb(unsigned int size,
72141+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
72142 gfp_t priority)
72143 {
72144 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
72145@@ -700,7 +700,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
72146 */
72147 static inline int skb_queue_empty(const struct sk_buff_head *list)
72148 {
72149- return list->next == (struct sk_buff *)list;
72150+ return list->next == (const struct sk_buff *)list;
72151 }
72152
72153 /**
72154@@ -713,7 +713,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
72155 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
72156 const struct sk_buff *skb)
72157 {
72158- return skb->next == (struct sk_buff *)list;
72159+ return skb->next == (const struct sk_buff *)list;
72160 }
72161
72162 /**
72163@@ -726,7 +726,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
72164 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
72165 const struct sk_buff *skb)
72166 {
72167- return skb->prev == (struct sk_buff *)list;
72168+ return skb->prev == (const struct sk_buff *)list;
72169 }
72170
72171 /**
72172@@ -1727,7 +1727,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
72173 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
72174 */
72175 #ifndef NET_SKB_PAD
72176-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
72177+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
72178 #endif
72179
72180 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
72181@@ -2305,7 +2305,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
72182 int noblock, int *err);
72183 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
72184 struct poll_table_struct *wait);
72185-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
72186+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
72187 int offset, struct iovec *to,
72188 int size);
72189 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
72190@@ -2595,6 +2595,9 @@ static inline void nf_reset(struct sk_buff *skb)
72191 nf_bridge_put(skb->nf_bridge);
72192 skb->nf_bridge = NULL;
72193 #endif
72194+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
72195+ skb->nf_trace = 0;
72196+#endif
72197 }
72198
72199 /* Note: This doesn't put any conntrack and bridge info in dst. */
72200diff --git a/include/linux/slab.h b/include/linux/slab.h
72201index 5d168d7..720bff3 100644
72202--- a/include/linux/slab.h
72203+++ b/include/linux/slab.h
72204@@ -12,13 +12,20 @@
72205 #include <linux/gfp.h>
72206 #include <linux/types.h>
72207 #include <linux/workqueue.h>
72208-
72209+#include <linux/err.h>
72210
72211 /*
72212 * Flags to pass to kmem_cache_create().
72213 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
72214 */
72215 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
72216+
72217+#ifdef CONFIG_PAX_USERCOPY_SLABS
72218+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
72219+#else
72220+#define SLAB_USERCOPY 0x00000000UL
72221+#endif
72222+
72223 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
72224 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
72225 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
72226@@ -89,10 +96,13 @@
72227 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
72228 * Both make kfree a no-op.
72229 */
72230-#define ZERO_SIZE_PTR ((void *)16)
72231+#define ZERO_SIZE_PTR \
72232+({ \
72233+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
72234+ (void *)(-MAX_ERRNO-1L); \
72235+})
72236
72237-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
72238- (unsigned long)ZERO_SIZE_PTR)
72239+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
72240
72241 /*
72242 * Common fields provided in kmem_cache by all slab allocators
72243@@ -112,7 +122,7 @@ struct kmem_cache {
72244 unsigned int align; /* Alignment as calculated */
72245 unsigned long flags; /* Active flags on the slab */
72246 const char *name; /* Slab name for sysfs */
72247- int refcount; /* Use counter */
72248+ atomic_t refcount; /* Use counter */
72249 void (*ctor)(void *); /* Called on object slot creation */
72250 struct list_head list; /* List of all slab caches on the system */
72251 };
72252@@ -232,6 +242,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
72253 void kfree(const void *);
72254 void kzfree(const void *);
72255 size_t ksize(const void *);
72256+const char *check_heap_object(const void *ptr, unsigned long n);
72257+bool is_usercopy_object(const void *ptr);
72258
72259 /*
72260 * Allocator specific definitions. These are mainly used to establish optimized
72261@@ -311,6 +323,7 @@ size_t ksize(const void *);
72262 * for general use, and so are not documented here. For a full list of
72263 * potential flags, always refer to linux/gfp.h.
72264 */
72265+
72266 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
72267 {
72268 if (size != 0 && n > SIZE_MAX / size)
72269@@ -370,7 +383,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
72270 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
72271 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
72272 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
72273-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
72274+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
72275 #define kmalloc_track_caller(size, flags) \
72276 __kmalloc_track_caller(size, flags, _RET_IP_)
72277 #else
72278@@ -390,7 +403,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
72279 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
72280 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
72281 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
72282-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
72283+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
72284 #define kmalloc_node_track_caller(size, flags, node) \
72285 __kmalloc_node_track_caller(size, flags, node, \
72286 _RET_IP_)
72287diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
72288index 8bb6e0e..8eb0dbe 100644
72289--- a/include/linux/slab_def.h
72290+++ b/include/linux/slab_def.h
72291@@ -52,7 +52,7 @@ struct kmem_cache {
72292 /* 4) cache creation/removal */
72293 const char *name;
72294 struct list_head list;
72295- int refcount;
72296+ atomic_t refcount;
72297 int object_size;
72298 int align;
72299
72300@@ -68,10 +68,10 @@ struct kmem_cache {
72301 unsigned long node_allocs;
72302 unsigned long node_frees;
72303 unsigned long node_overflow;
72304- atomic_t allochit;
72305- atomic_t allocmiss;
72306- atomic_t freehit;
72307- atomic_t freemiss;
72308+ atomic_unchecked_t allochit;
72309+ atomic_unchecked_t allocmiss;
72310+ atomic_unchecked_t freehit;
72311+ atomic_unchecked_t freemiss;
72312
72313 /*
72314 * If debugging is enabled, then the allocator can add additional
72315@@ -111,11 +111,16 @@ struct cache_sizes {
72316 #ifdef CONFIG_ZONE_DMA
72317 struct kmem_cache *cs_dmacachep;
72318 #endif
72319+
72320+#ifdef CONFIG_PAX_USERCOPY_SLABS
72321+ struct kmem_cache *cs_usercopycachep;
72322+#endif
72323+
72324 };
72325 extern struct cache_sizes malloc_sizes[];
72326
72327 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
72328-void *__kmalloc(size_t size, gfp_t flags);
72329+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
72330
72331 #ifdef CONFIG_TRACING
72332 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
72333@@ -152,6 +157,13 @@ found:
72334 cachep = malloc_sizes[i].cs_dmacachep;
72335 else
72336 #endif
72337+
72338+#ifdef CONFIG_PAX_USERCOPY_SLABS
72339+ if (flags & GFP_USERCOPY)
72340+ cachep = malloc_sizes[i].cs_usercopycachep;
72341+ else
72342+#endif
72343+
72344 cachep = malloc_sizes[i].cs_cachep;
72345
72346 ret = kmem_cache_alloc_trace(cachep, flags, size);
72347@@ -162,7 +174,7 @@ found:
72348 }
72349
72350 #ifdef CONFIG_NUMA
72351-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
72352+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
72353 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
72354
72355 #ifdef CONFIG_TRACING
72356@@ -205,6 +217,13 @@ found:
72357 cachep = malloc_sizes[i].cs_dmacachep;
72358 else
72359 #endif
72360+
72361+#ifdef CONFIG_PAX_USERCOPY_SLABS
72362+ if (flags & GFP_USERCOPY)
72363+ cachep = malloc_sizes[i].cs_usercopycachep;
72364+ else
72365+#endif
72366+
72367 cachep = malloc_sizes[i].cs_cachep;
72368
72369 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
72370diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
72371index f28e14a..7831211 100644
72372--- a/include/linux/slob_def.h
72373+++ b/include/linux/slob_def.h
72374@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
72375 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
72376 }
72377
72378-void *__kmalloc_node(size_t size, gfp_t flags, int node);
72379+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
72380
72381 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
72382 {
72383@@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
72384 return __kmalloc_node(size, flags, NUMA_NO_NODE);
72385 }
72386
72387-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
72388+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
72389 {
72390 return kmalloc(size, flags);
72391 }
72392diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
72393index 9db4825..ed42fb5 100644
72394--- a/include/linux/slub_def.h
72395+++ b/include/linux/slub_def.h
72396@@ -91,7 +91,7 @@ struct kmem_cache {
72397 struct kmem_cache_order_objects max;
72398 struct kmem_cache_order_objects min;
72399 gfp_t allocflags; /* gfp flags to use on each alloc */
72400- int refcount; /* Refcount for slab cache destroy */
72401+ atomic_t refcount; /* Refcount for slab cache destroy */
72402 void (*ctor)(void *);
72403 int inuse; /* Offset to metadata */
72404 int align; /* Alignment */
72405@@ -156,7 +156,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
72406 * Sorry that the following has to be that ugly but some versions of GCC
72407 * have trouble with constant propagation and loops.
72408 */
72409-static __always_inline int kmalloc_index(size_t size)
72410+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
72411 {
72412 if (!size)
72413 return 0;
72414@@ -221,7 +221,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
72415 }
72416
72417 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
72418-void *__kmalloc(size_t size, gfp_t flags);
72419+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
72420
72421 static __always_inline void *
72422 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
72423@@ -265,7 +265,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
72424 }
72425 #endif
72426
72427-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
72428+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
72429 {
72430 unsigned int order = get_order(size);
72431 return kmalloc_order_trace(size, flags, order);
72432@@ -290,7 +290,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
72433 }
72434
72435 #ifdef CONFIG_NUMA
72436-void *__kmalloc_node(size_t size, gfp_t flags, int node);
72437+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
72438 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
72439
72440 #ifdef CONFIG_TRACING
72441diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
72442index e8d702e..0a56eb4 100644
72443--- a/include/linux/sock_diag.h
72444+++ b/include/linux/sock_diag.h
72445@@ -10,7 +10,7 @@ struct sock;
72446 struct sock_diag_handler {
72447 __u8 family;
72448 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
72449-};
72450+} __do_const;
72451
72452 int sock_diag_register(const struct sock_diag_handler *h);
72453 void sock_diag_unregister(const struct sock_diag_handler *h);
72454diff --git a/include/linux/sonet.h b/include/linux/sonet.h
72455index 680f9a3..f13aeb0 100644
72456--- a/include/linux/sonet.h
72457+++ b/include/linux/sonet.h
72458@@ -7,7 +7,7 @@
72459 #include <uapi/linux/sonet.h>
72460
72461 struct k_sonet_stats {
72462-#define __HANDLE_ITEM(i) atomic_t i
72463+#define __HANDLE_ITEM(i) atomic_unchecked_t i
72464 __SONET_ITEMS
72465 #undef __HANDLE_ITEM
72466 };
72467diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
72468index 34206b8..3db7f1c 100644
72469--- a/include/linux/sunrpc/clnt.h
72470+++ b/include/linux/sunrpc/clnt.h
72471@@ -96,7 +96,7 @@ struct rpc_procinfo {
72472 unsigned int p_timer; /* Which RTT timer to use */
72473 u32 p_statidx; /* Which procedure to account */
72474 const char * p_name; /* name of procedure */
72475-};
72476+} __do_const;
72477
72478 #ifdef __KERNEL__
72479
72480@@ -176,9 +176,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
72481 {
72482 switch (sap->sa_family) {
72483 case AF_INET:
72484- return ntohs(((struct sockaddr_in *)sap)->sin_port);
72485+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
72486 case AF_INET6:
72487- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
72488+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
72489 }
72490 return 0;
72491 }
72492@@ -211,7 +211,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
72493 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
72494 const struct sockaddr *src)
72495 {
72496- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
72497+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
72498 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
72499
72500 dsin->sin_family = ssin->sin_family;
72501@@ -314,7 +314,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
72502 if (sa->sa_family != AF_INET6)
72503 return 0;
72504
72505- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
72506+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
72507 }
72508
72509 #endif /* __KERNEL__ */
72510diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
72511index 676ddf5..4c519a1 100644
72512--- a/include/linux/sunrpc/svc.h
72513+++ b/include/linux/sunrpc/svc.h
72514@@ -410,7 +410,7 @@ struct svc_procedure {
72515 unsigned int pc_count; /* call count */
72516 unsigned int pc_cachetype; /* cache info (NFS) */
72517 unsigned int pc_xdrressize; /* maximum size of XDR reply */
72518-};
72519+} __do_const;
72520
72521 /*
72522 * Function prototypes.
72523diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
72524index 0b8e3e6..33e0a01 100644
72525--- a/include/linux/sunrpc/svc_rdma.h
72526+++ b/include/linux/sunrpc/svc_rdma.h
72527@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
72528 extern unsigned int svcrdma_max_requests;
72529 extern unsigned int svcrdma_max_req_size;
72530
72531-extern atomic_t rdma_stat_recv;
72532-extern atomic_t rdma_stat_read;
72533-extern atomic_t rdma_stat_write;
72534-extern atomic_t rdma_stat_sq_starve;
72535-extern atomic_t rdma_stat_rq_starve;
72536-extern atomic_t rdma_stat_rq_poll;
72537-extern atomic_t rdma_stat_rq_prod;
72538-extern atomic_t rdma_stat_sq_poll;
72539-extern atomic_t rdma_stat_sq_prod;
72540+extern atomic_unchecked_t rdma_stat_recv;
72541+extern atomic_unchecked_t rdma_stat_read;
72542+extern atomic_unchecked_t rdma_stat_write;
72543+extern atomic_unchecked_t rdma_stat_sq_starve;
72544+extern atomic_unchecked_t rdma_stat_rq_starve;
72545+extern atomic_unchecked_t rdma_stat_rq_poll;
72546+extern atomic_unchecked_t rdma_stat_rq_prod;
72547+extern atomic_unchecked_t rdma_stat_sq_poll;
72548+extern atomic_unchecked_t rdma_stat_sq_prod;
72549
72550 #define RPCRDMA_VERSION 1
72551
72552diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
72553index dd74084a..7f509d5 100644
72554--- a/include/linux/sunrpc/svcauth.h
72555+++ b/include/linux/sunrpc/svcauth.h
72556@@ -109,7 +109,7 @@ struct auth_ops {
72557 int (*release)(struct svc_rqst *rq);
72558 void (*domain_release)(struct auth_domain *);
72559 int (*set_client)(struct svc_rqst *rq);
72560-};
72561+} __do_const;
72562
72563 #define SVC_GARBAGE 1
72564 #define SVC_SYSERR 2
72565diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
72566index 071d62c..4ccc7ac 100644
72567--- a/include/linux/swiotlb.h
72568+++ b/include/linux/swiotlb.h
72569@@ -59,7 +59,8 @@ extern void
72570
72571 extern void
72572 swiotlb_free_coherent(struct device *hwdev, size_t size,
72573- void *vaddr, dma_addr_t dma_handle);
72574+ void *vaddr, dma_addr_t dma_handle,
72575+ struct dma_attrs *attrs);
72576
72577 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
72578 unsigned long offset, size_t size,
72579diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
72580index 45e2db2..1635156a 100644
72581--- a/include/linux/syscalls.h
72582+++ b/include/linux/syscalls.h
72583@@ -615,7 +615,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
72584 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
72585 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
72586 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
72587- struct sockaddr __user *, int);
72588+ struct sockaddr __user *, int) __intentional_overflow(0);
72589 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
72590 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
72591 unsigned int vlen, unsigned flags);
72592diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
72593index 27b3b0b..e093dd9 100644
72594--- a/include/linux/syscore_ops.h
72595+++ b/include/linux/syscore_ops.h
72596@@ -16,7 +16,7 @@ struct syscore_ops {
72597 int (*suspend)(void);
72598 void (*resume)(void);
72599 void (*shutdown)(void);
72600-};
72601+} __do_const;
72602
72603 extern void register_syscore_ops(struct syscore_ops *ops);
72604 extern void unregister_syscore_ops(struct syscore_ops *ops);
72605diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
72606index 14a8ff2..af52bad 100644
72607--- a/include/linux/sysctl.h
72608+++ b/include/linux/sysctl.h
72609@@ -34,13 +34,13 @@ struct ctl_table_root;
72610 struct ctl_table_header;
72611 struct ctl_dir;
72612
72613-typedef struct ctl_table ctl_table;
72614-
72615 typedef int proc_handler (struct ctl_table *ctl, int write,
72616 void __user *buffer, size_t *lenp, loff_t *ppos);
72617
72618 extern int proc_dostring(struct ctl_table *, int,
72619 void __user *, size_t *, loff_t *);
72620+extern int proc_dostring_modpriv(struct ctl_table *, int,
72621+ void __user *, size_t *, loff_t *);
72622 extern int proc_dointvec(struct ctl_table *, int,
72623 void __user *, size_t *, loff_t *);
72624 extern int proc_dointvec_minmax(struct ctl_table *, int,
72625@@ -115,7 +115,9 @@ struct ctl_table
72626 struct ctl_table_poll *poll;
72627 void *extra1;
72628 void *extra2;
72629-};
72630+} __do_const;
72631+typedef struct ctl_table __no_const ctl_table_no_const;
72632+typedef struct ctl_table ctl_table;
72633
72634 struct ctl_node {
72635 struct rb_node node;
72636diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
72637index 381f06d..dc16cc7 100644
72638--- a/include/linux/sysfs.h
72639+++ b/include/linux/sysfs.h
72640@@ -31,7 +31,8 @@ struct attribute {
72641 struct lock_class_key *key;
72642 struct lock_class_key skey;
72643 #endif
72644-};
72645+} __do_const;
72646+typedef struct attribute __no_const attribute_no_const;
72647
72648 /**
72649 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
72650@@ -59,8 +60,8 @@ struct attribute_group {
72651 umode_t (*is_visible)(struct kobject *,
72652 struct attribute *, int);
72653 struct attribute **attrs;
72654-};
72655-
72656+} __do_const;
72657+typedef struct attribute_group __no_const attribute_group_no_const;
72658
72659
72660 /**
72661@@ -107,7 +108,8 @@ struct bin_attribute {
72662 char *, loff_t, size_t);
72663 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
72664 struct vm_area_struct *vma);
72665-};
72666+} __do_const;
72667+typedef struct bin_attribute __no_const bin_attribute_no_const;
72668
72669 /**
72670 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
72671diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
72672index 7faf933..9b85a0c 100644
72673--- a/include/linux/sysrq.h
72674+++ b/include/linux/sysrq.h
72675@@ -16,6 +16,7 @@
72676
72677 #include <linux/errno.h>
72678 #include <linux/types.h>
72679+#include <linux/compiler.h>
72680
72681 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
72682 #define SYSRQ_DEFAULT_ENABLE 1
72683@@ -36,7 +37,7 @@ struct sysrq_key_op {
72684 char *help_msg;
72685 char *action_msg;
72686 int enable_mask;
72687-};
72688+} __do_const;
72689
72690 #ifdef CONFIG_MAGIC_SYSRQ
72691
72692diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
72693index e7e0473..7989295 100644
72694--- a/include/linux/thread_info.h
72695+++ b/include/linux/thread_info.h
72696@@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
72697 #error "no set_restore_sigmask() provided and default one won't work"
72698 #endif
72699
72700+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
72701+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
72702+{
72703+#ifndef CONFIG_PAX_USERCOPY_DEBUG
72704+ if (!__builtin_constant_p(n))
72705+#endif
72706+ __check_object_size(ptr, n, to_user);
72707+}
72708+
72709 #endif /* __KERNEL__ */
72710
72711 #endif /* _LINUX_THREAD_INFO_H */
72712diff --git a/include/linux/tty.h b/include/linux/tty.h
72713index 8db1b56..c16a040 100644
72714--- a/include/linux/tty.h
72715+++ b/include/linux/tty.h
72716@@ -194,7 +194,7 @@ struct tty_port {
72717 const struct tty_port_operations *ops; /* Port operations */
72718 spinlock_t lock; /* Lock protecting tty field */
72719 int blocked_open; /* Waiting to open */
72720- int count; /* Usage count */
72721+ atomic_t count; /* Usage count */
72722 wait_queue_head_t open_wait; /* Open waiters */
72723 wait_queue_head_t close_wait; /* Close waiters */
72724 wait_queue_head_t delta_msr_wait; /* Modem status change */
72725@@ -490,7 +490,7 @@ extern int tty_port_open(struct tty_port *port,
72726 struct tty_struct *tty, struct file *filp);
72727 static inline int tty_port_users(struct tty_port *port)
72728 {
72729- return port->count + port->blocked_open;
72730+ return atomic_read(&port->count) + port->blocked_open;
72731 }
72732
72733 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
72734diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
72735index dd976cf..e272742 100644
72736--- a/include/linux/tty_driver.h
72737+++ b/include/linux/tty_driver.h
72738@@ -284,7 +284,7 @@ struct tty_operations {
72739 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
72740 #endif
72741 const struct file_operations *proc_fops;
72742-};
72743+} __do_const;
72744
72745 struct tty_driver {
72746 int magic; /* magic number for this structure */
72747diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
72748index fb79dd8d..07d4773 100644
72749--- a/include/linux/tty_ldisc.h
72750+++ b/include/linux/tty_ldisc.h
72751@@ -149,7 +149,7 @@ struct tty_ldisc_ops {
72752
72753 struct module *owner;
72754
72755- int refcount;
72756+ atomic_t refcount;
72757 };
72758
72759 struct tty_ldisc {
72760diff --git a/include/linux/types.h b/include/linux/types.h
72761index 4d118ba..c3ee9bf 100644
72762--- a/include/linux/types.h
72763+++ b/include/linux/types.h
72764@@ -176,10 +176,26 @@ typedef struct {
72765 int counter;
72766 } atomic_t;
72767
72768+#ifdef CONFIG_PAX_REFCOUNT
72769+typedef struct {
72770+ int counter;
72771+} atomic_unchecked_t;
72772+#else
72773+typedef atomic_t atomic_unchecked_t;
72774+#endif
72775+
72776 #ifdef CONFIG_64BIT
72777 typedef struct {
72778 long counter;
72779 } atomic64_t;
72780+
72781+#ifdef CONFIG_PAX_REFCOUNT
72782+typedef struct {
72783+ long counter;
72784+} atomic64_unchecked_t;
72785+#else
72786+typedef atomic64_t atomic64_unchecked_t;
72787+#endif
72788 #endif
72789
72790 struct list_head {
72791diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
72792index 5ca0951..ab496a5 100644
72793--- a/include/linux/uaccess.h
72794+++ b/include/linux/uaccess.h
72795@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
72796 long ret; \
72797 mm_segment_t old_fs = get_fs(); \
72798 \
72799- set_fs(KERNEL_DS); \
72800 pagefault_disable(); \
72801- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
72802- pagefault_enable(); \
72803+ set_fs(KERNEL_DS); \
72804+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
72805 set_fs(old_fs); \
72806+ pagefault_enable(); \
72807 ret; \
72808 })
72809
72810diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
72811index 8e522cbc..aa8572d 100644
72812--- a/include/linux/uidgid.h
72813+++ b/include/linux/uidgid.h
72814@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
72815
72816 #endif /* CONFIG_USER_NS */
72817
72818+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
72819+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
72820+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
72821+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
72822+
72823 #endif /* _LINUX_UIDGID_H */
72824diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
72825index 99c1b4d..562e6f3 100644
72826--- a/include/linux/unaligned/access_ok.h
72827+++ b/include/linux/unaligned/access_ok.h
72828@@ -4,34 +4,34 @@
72829 #include <linux/kernel.h>
72830 #include <asm/byteorder.h>
72831
72832-static inline u16 get_unaligned_le16(const void *p)
72833+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
72834 {
72835- return le16_to_cpup((__le16 *)p);
72836+ return le16_to_cpup((const __le16 *)p);
72837 }
72838
72839-static inline u32 get_unaligned_le32(const void *p)
72840+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
72841 {
72842- return le32_to_cpup((__le32 *)p);
72843+ return le32_to_cpup((const __le32 *)p);
72844 }
72845
72846-static inline u64 get_unaligned_le64(const void *p)
72847+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
72848 {
72849- return le64_to_cpup((__le64 *)p);
72850+ return le64_to_cpup((const __le64 *)p);
72851 }
72852
72853-static inline u16 get_unaligned_be16(const void *p)
72854+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
72855 {
72856- return be16_to_cpup((__be16 *)p);
72857+ return be16_to_cpup((const __be16 *)p);
72858 }
72859
72860-static inline u32 get_unaligned_be32(const void *p)
72861+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
72862 {
72863- return be32_to_cpup((__be32 *)p);
72864+ return be32_to_cpup((const __be32 *)p);
72865 }
72866
72867-static inline u64 get_unaligned_be64(const void *p)
72868+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
72869 {
72870- return be64_to_cpup((__be64 *)p);
72871+ return be64_to_cpup((const __be64 *)p);
72872 }
72873
72874 static inline void put_unaligned_le16(u16 val, void *p)
72875diff --git a/include/linux/usb.h b/include/linux/usb.h
72876index 4d22d0f..8d0e8f8 100644
72877--- a/include/linux/usb.h
72878+++ b/include/linux/usb.h
72879@@ -554,7 +554,7 @@ struct usb_device {
72880 int maxchild;
72881
72882 u32 quirks;
72883- atomic_t urbnum;
72884+ atomic_unchecked_t urbnum;
72885
72886 unsigned long active_duration;
72887
72888@@ -1604,7 +1604,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
72889
72890 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
72891 __u8 request, __u8 requesttype, __u16 value, __u16 index,
72892- void *data, __u16 size, int timeout);
72893+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
72894 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
72895 void *data, int len, int *actual_length, int timeout);
72896 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
72897diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
72898index c5d36c6..108f4f9 100644
72899--- a/include/linux/usb/renesas_usbhs.h
72900+++ b/include/linux/usb/renesas_usbhs.h
72901@@ -39,7 +39,7 @@ enum {
72902 */
72903 struct renesas_usbhs_driver_callback {
72904 int (*notify_hotplug)(struct platform_device *pdev);
72905-};
72906+} __no_const;
72907
72908 /*
72909 * callback functions for platform
72910diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
72911index 5209cfe..b6b215f 100644
72912--- a/include/linux/user_namespace.h
72913+++ b/include/linux/user_namespace.h
72914@@ -21,7 +21,7 @@ struct user_namespace {
72915 struct uid_gid_map uid_map;
72916 struct uid_gid_map gid_map;
72917 struct uid_gid_map projid_map;
72918- struct kref kref;
72919+ atomic_t count;
72920 struct user_namespace *parent;
72921 kuid_t owner;
72922 kgid_t group;
72923@@ -37,18 +37,18 @@ extern struct user_namespace init_user_ns;
72924 static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
72925 {
72926 if (ns)
72927- kref_get(&ns->kref);
72928+ atomic_inc(&ns->count);
72929 return ns;
72930 }
72931
72932 extern int create_user_ns(struct cred *new);
72933 extern int unshare_userns(unsigned long unshare_flags, struct cred **new_cred);
72934-extern void free_user_ns(struct kref *kref);
72935+extern void free_user_ns(struct user_namespace *ns);
72936
72937 static inline void put_user_ns(struct user_namespace *ns)
72938 {
72939- if (ns)
72940- kref_put(&ns->kref, free_user_ns);
72941+ if (ns && atomic_dec_and_test(&ns->count))
72942+ free_user_ns(ns);
72943 }
72944
72945 struct seq_operations;
72946diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
72947index 6f8fbcf..8259001 100644
72948--- a/include/linux/vermagic.h
72949+++ b/include/linux/vermagic.h
72950@@ -25,9 +25,35 @@
72951 #define MODULE_ARCH_VERMAGIC ""
72952 #endif
72953
72954+#ifdef CONFIG_PAX_REFCOUNT
72955+#define MODULE_PAX_REFCOUNT "REFCOUNT "
72956+#else
72957+#define MODULE_PAX_REFCOUNT ""
72958+#endif
72959+
72960+#ifdef CONSTIFY_PLUGIN
72961+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
72962+#else
72963+#define MODULE_CONSTIFY_PLUGIN ""
72964+#endif
72965+
72966+#ifdef STACKLEAK_PLUGIN
72967+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
72968+#else
72969+#define MODULE_STACKLEAK_PLUGIN ""
72970+#endif
72971+
72972+#ifdef CONFIG_GRKERNSEC
72973+#define MODULE_GRSEC "GRSEC "
72974+#else
72975+#define MODULE_GRSEC ""
72976+#endif
72977+
72978 #define VERMAGIC_STRING \
72979 UTS_RELEASE " " \
72980 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
72981 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
72982- MODULE_ARCH_VERMAGIC
72983+ MODULE_ARCH_VERMAGIC \
72984+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
72985+ MODULE_GRSEC
72986
72987diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
72988index 6071e91..ca6a489 100644
72989--- a/include/linux/vmalloc.h
72990+++ b/include/linux/vmalloc.h
72991@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
72992 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
72993 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
72994 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
72995+
72996+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
72997+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
72998+#endif
72999+
73000 /* bits [20..32] reserved for arch specific ioremap internals */
73001
73002 /*
73003@@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
73004 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
73005 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
73006 unsigned long start, unsigned long end, gfp_t gfp_mask,
73007- pgprot_t prot, int node, const void *caller);
73008+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
73009 extern void vfree(const void *addr);
73010
73011 extern void *vmap(struct page **pages, unsigned int count,
73012@@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
73013 extern void free_vm_area(struct vm_struct *area);
73014
73015 /* for /dev/kmem */
73016-extern long vread(char *buf, char *addr, unsigned long count);
73017-extern long vwrite(char *buf, char *addr, unsigned long count);
73018+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
73019+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
73020
73021 /*
73022 * Internals. Dont't use..
73023diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
73024index a13291f..af51fa3 100644
73025--- a/include/linux/vmstat.h
73026+++ b/include/linux/vmstat.h
73027@@ -95,18 +95,18 @@ static inline void vm_events_fold_cpu(int cpu)
73028 /*
73029 * Zone based page accounting with per cpu differentials.
73030 */
73031-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
73032+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
73033
73034 static inline void zone_page_state_add(long x, struct zone *zone,
73035 enum zone_stat_item item)
73036 {
73037- atomic_long_add(x, &zone->vm_stat[item]);
73038- atomic_long_add(x, &vm_stat[item]);
73039+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
73040+ atomic_long_add_unchecked(x, &vm_stat[item]);
73041 }
73042
73043 static inline unsigned long global_page_state(enum zone_stat_item item)
73044 {
73045- long x = atomic_long_read(&vm_stat[item]);
73046+ long x = atomic_long_read_unchecked(&vm_stat[item]);
73047 #ifdef CONFIG_SMP
73048 if (x < 0)
73049 x = 0;
73050@@ -117,7 +117,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
73051 static inline unsigned long zone_page_state(struct zone *zone,
73052 enum zone_stat_item item)
73053 {
73054- long x = atomic_long_read(&zone->vm_stat[item]);
73055+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
73056 #ifdef CONFIG_SMP
73057 if (x < 0)
73058 x = 0;
73059@@ -134,7 +134,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
73060 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
73061 enum zone_stat_item item)
73062 {
73063- long x = atomic_long_read(&zone->vm_stat[item]);
73064+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
73065
73066 #ifdef CONFIG_SMP
73067 int cpu;
73068@@ -226,8 +226,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
73069
73070 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
73071 {
73072- atomic_long_inc(&zone->vm_stat[item]);
73073- atomic_long_inc(&vm_stat[item]);
73074+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
73075+ atomic_long_inc_unchecked(&vm_stat[item]);
73076 }
73077
73078 static inline void __inc_zone_page_state(struct page *page,
73079@@ -238,8 +238,8 @@ static inline void __inc_zone_page_state(struct page *page,
73080
73081 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
73082 {
73083- atomic_long_dec(&zone->vm_stat[item]);
73084- atomic_long_dec(&vm_stat[item]);
73085+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
73086+ atomic_long_dec_unchecked(&vm_stat[item]);
73087 }
73088
73089 static inline void __dec_zone_page_state(struct page *page,
73090diff --git a/include/linux/xattr.h b/include/linux/xattr.h
73091index fdbafc6..b7ffd47 100644
73092--- a/include/linux/xattr.h
73093+++ b/include/linux/xattr.h
73094@@ -28,7 +28,7 @@ struct xattr_handler {
73095 size_t size, int handler_flags);
73096 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
73097 size_t size, int flags, int handler_flags);
73098-};
73099+} __do_const;
73100
73101 struct xattr {
73102 char *name;
73103diff --git a/include/linux/zlib.h b/include/linux/zlib.h
73104index 9c5a6b4..09c9438 100644
73105--- a/include/linux/zlib.h
73106+++ b/include/linux/zlib.h
73107@@ -31,6 +31,7 @@
73108 #define _ZLIB_H
73109
73110 #include <linux/zconf.h>
73111+#include <linux/compiler.h>
73112
73113 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
73114 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
73115@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
73116
73117 /* basic functions */
73118
73119-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
73120+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
73121 /*
73122 Returns the number of bytes that needs to be allocated for a per-
73123 stream workspace with the specified parameters. A pointer to this
73124diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
73125index 95d1c91..6798cca 100644
73126--- a/include/media/v4l2-dev.h
73127+++ b/include/media/v4l2-dev.h
73128@@ -76,7 +76,7 @@ struct v4l2_file_operations {
73129 int (*mmap) (struct file *, struct vm_area_struct *);
73130 int (*open) (struct file *);
73131 int (*release) (struct file *);
73132-};
73133+} __do_const;
73134
73135 /*
73136 * Newer version of video_device, handled by videodev2.c
73137diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
73138index 4118ad1..cb7e25f 100644
73139--- a/include/media/v4l2-ioctl.h
73140+++ b/include/media/v4l2-ioctl.h
73141@@ -284,7 +284,6 @@ struct v4l2_ioctl_ops {
73142 bool valid_prio, int cmd, void *arg);
73143 };
73144
73145-
73146 /* v4l debugging and diagnostics */
73147
73148 /* Debug bitmask flags to be used on V4L2 */
73149diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
73150index adcbb20..62c2559 100644
73151--- a/include/net/9p/transport.h
73152+++ b/include/net/9p/transport.h
73153@@ -57,7 +57,7 @@ struct p9_trans_module {
73154 int (*cancel) (struct p9_client *, struct p9_req_t *req);
73155 int (*zc_request)(struct p9_client *, struct p9_req_t *,
73156 char *, char *, int , int, int, int);
73157-};
73158+} __do_const;
73159
73160 void v9fs_register_trans(struct p9_trans_module *m);
73161 void v9fs_unregister_trans(struct p9_trans_module *m);
73162diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
73163index 7588ef4..e62d35f 100644
73164--- a/include/net/bluetooth/l2cap.h
73165+++ b/include/net/bluetooth/l2cap.h
73166@@ -552,7 +552,7 @@ struct l2cap_ops {
73167 void (*defer) (struct l2cap_chan *chan);
73168 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
73169 unsigned long len, int nb);
73170-};
73171+} __do_const;
73172
73173 struct l2cap_conn {
73174 struct hci_conn *hcon;
73175diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
73176index 9e5425b..8136ffc 100644
73177--- a/include/net/caif/cfctrl.h
73178+++ b/include/net/caif/cfctrl.h
73179@@ -52,7 +52,7 @@ struct cfctrl_rsp {
73180 void (*radioset_rsp)(void);
73181 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
73182 struct cflayer *client_layer);
73183-};
73184+} __no_const;
73185
73186 /* Link Setup Parameters for CAIF-Links. */
73187 struct cfctrl_link_param {
73188@@ -101,8 +101,8 @@ struct cfctrl_request_info {
73189 struct cfctrl {
73190 struct cfsrvl serv;
73191 struct cfctrl_rsp res;
73192- atomic_t req_seq_no;
73193- atomic_t rsp_seq_no;
73194+ atomic_unchecked_t req_seq_no;
73195+ atomic_unchecked_t rsp_seq_no;
73196 struct list_head list;
73197 /* Protects from simultaneous access to first_req list */
73198 spinlock_t info_list_lock;
73199diff --git a/include/net/flow.h b/include/net/flow.h
73200index 628e11b..4c475df 100644
73201--- a/include/net/flow.h
73202+++ b/include/net/flow.h
73203@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
73204
73205 extern void flow_cache_flush(void);
73206 extern void flow_cache_flush_deferred(void);
73207-extern atomic_t flow_cache_genid;
73208+extern atomic_unchecked_t flow_cache_genid;
73209
73210 #endif
73211diff --git a/include/net/genetlink.h b/include/net/genetlink.h
73212index bdfbe68..4402ebe 100644
73213--- a/include/net/genetlink.h
73214+++ b/include/net/genetlink.h
73215@@ -118,7 +118,7 @@ struct genl_ops {
73216 struct netlink_callback *cb);
73217 int (*done)(struct netlink_callback *cb);
73218 struct list_head ops_list;
73219-};
73220+} __do_const;
73221
73222 extern int genl_register_family(struct genl_family *family);
73223 extern int genl_register_family_with_ops(struct genl_family *family,
73224diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
73225index e5062c9..48a9a4b 100644
73226--- a/include/net/gro_cells.h
73227+++ b/include/net/gro_cells.h
73228@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
73229 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
73230
73231 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
73232- atomic_long_inc(&dev->rx_dropped);
73233+ atomic_long_inc_unchecked(&dev->rx_dropped);
73234 kfree_skb(skb);
73235 return;
73236 }
73237@@ -73,8 +73,8 @@ static inline int gro_cells_init(struct gro_cells *gcells, struct net_device *de
73238 int i;
73239
73240 gcells->gro_cells_mask = roundup_pow_of_two(netif_get_num_default_rss_queues()) - 1;
73241- gcells->cells = kcalloc(sizeof(struct gro_cell),
73242- gcells->gro_cells_mask + 1,
73243+ gcells->cells = kcalloc(gcells->gro_cells_mask + 1,
73244+ sizeof(struct gro_cell),
73245 GFP_KERNEL);
73246 if (!gcells->cells)
73247 return -ENOMEM;
73248diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
73249index 1832927..ce39aea 100644
73250--- a/include/net/inet_connection_sock.h
73251+++ b/include/net/inet_connection_sock.h
73252@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
73253 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
73254 int (*bind_conflict)(const struct sock *sk,
73255 const struct inet_bind_bucket *tb, bool relax);
73256-};
73257+} __do_const;
73258
73259 /** inet_connection_sock - INET connection oriented sock
73260 *
73261diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
73262index 53f464d..ba76aaa 100644
73263--- a/include/net/inetpeer.h
73264+++ b/include/net/inetpeer.h
73265@@ -47,8 +47,8 @@ struct inet_peer {
73266 */
73267 union {
73268 struct {
73269- atomic_t rid; /* Frag reception counter */
73270- atomic_t ip_id_count; /* IP ID for the next packet */
73271+ atomic_unchecked_t rid; /* Frag reception counter */
73272+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
73273 };
73274 struct rcu_head rcu;
73275 struct inet_peer *gc_next;
73276@@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
73277 more++;
73278 inet_peer_refcheck(p);
73279 do {
73280- old = atomic_read(&p->ip_id_count);
73281+ old = atomic_read_unchecked(&p->ip_id_count);
73282 new = old + more;
73283 if (!new)
73284 new = 1;
73285- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
73286+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
73287 return new;
73288 }
73289
73290diff --git a/include/net/ip.h b/include/net/ip.h
73291index a68f838..74518ab 100644
73292--- a/include/net/ip.h
73293+++ b/include/net/ip.h
73294@@ -202,7 +202,7 @@ extern struct local_ports {
73295 } sysctl_local_ports;
73296 extern void inet_get_local_port_range(int *low, int *high);
73297
73298-extern unsigned long *sysctl_local_reserved_ports;
73299+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
73300 static inline int inet_is_reserved_local_port(int port)
73301 {
73302 return test_bit(port, sysctl_local_reserved_ports);
73303diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
73304index e49db91..76a81de 100644
73305--- a/include/net/ip_fib.h
73306+++ b/include/net/ip_fib.h
73307@@ -167,7 +167,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
73308
73309 #define FIB_RES_SADDR(net, res) \
73310 ((FIB_RES_NH(res).nh_saddr_genid == \
73311- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
73312+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
73313 FIB_RES_NH(res).nh_saddr : \
73314 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
73315 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
73316diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
73317index 68c69d5..bdab192 100644
73318--- a/include/net/ip_vs.h
73319+++ b/include/net/ip_vs.h
73320@@ -599,7 +599,7 @@ struct ip_vs_conn {
73321 struct ip_vs_conn *control; /* Master control connection */
73322 atomic_t n_control; /* Number of controlled ones */
73323 struct ip_vs_dest *dest; /* real server */
73324- atomic_t in_pkts; /* incoming packet counter */
73325+ atomic_unchecked_t in_pkts; /* incoming packet counter */
73326
73327 /* packet transmitter for different forwarding methods. If it
73328 mangles the packet, it must return NF_DROP or better NF_STOLEN,
73329@@ -737,7 +737,7 @@ struct ip_vs_dest {
73330 __be16 port; /* port number of the server */
73331 union nf_inet_addr addr; /* IP address of the server */
73332 volatile unsigned int flags; /* dest status flags */
73333- atomic_t conn_flags; /* flags to copy to conn */
73334+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
73335 atomic_t weight; /* server weight */
73336
73337 atomic_t refcnt; /* reference counter */
73338@@ -980,11 +980,11 @@ struct netns_ipvs {
73339 /* ip_vs_lblc */
73340 int sysctl_lblc_expiration;
73341 struct ctl_table_header *lblc_ctl_header;
73342- struct ctl_table *lblc_ctl_table;
73343+ ctl_table_no_const *lblc_ctl_table;
73344 /* ip_vs_lblcr */
73345 int sysctl_lblcr_expiration;
73346 struct ctl_table_header *lblcr_ctl_header;
73347- struct ctl_table *lblcr_ctl_table;
73348+ ctl_table_no_const *lblcr_ctl_table;
73349 /* ip_vs_est */
73350 struct list_head est_list; /* estimator list */
73351 spinlock_t est_lock;
73352diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
73353index 80ffde3..968b0f4 100644
73354--- a/include/net/irda/ircomm_tty.h
73355+++ b/include/net/irda/ircomm_tty.h
73356@@ -35,6 +35,7 @@
73357 #include <linux/termios.h>
73358 #include <linux/timer.h>
73359 #include <linux/tty.h> /* struct tty_struct */
73360+#include <asm/local.h>
73361
73362 #include <net/irda/irias_object.h>
73363 #include <net/irda/ircomm_core.h>
73364diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
73365index cc7c197..9f2da2a 100644
73366--- a/include/net/iucv/af_iucv.h
73367+++ b/include/net/iucv/af_iucv.h
73368@@ -141,7 +141,7 @@ struct iucv_sock {
73369 struct iucv_sock_list {
73370 struct hlist_head head;
73371 rwlock_t lock;
73372- atomic_t autobind_name;
73373+ atomic_unchecked_t autobind_name;
73374 };
73375
73376 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
73377diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
73378index df83f69..9b640b8 100644
73379--- a/include/net/llc_c_ac.h
73380+++ b/include/net/llc_c_ac.h
73381@@ -87,7 +87,7 @@
73382 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
73383 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
73384
73385-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
73386+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
73387
73388 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
73389 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
73390diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
73391index 6ca3113..f8026dd 100644
73392--- a/include/net/llc_c_ev.h
73393+++ b/include/net/llc_c_ev.h
73394@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
73395 return (struct llc_conn_state_ev *)skb->cb;
73396 }
73397
73398-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
73399-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
73400+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
73401+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
73402
73403 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
73404 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
73405diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
73406index 0e79cfb..f46db31 100644
73407--- a/include/net/llc_c_st.h
73408+++ b/include/net/llc_c_st.h
73409@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
73410 u8 next_state;
73411 llc_conn_ev_qfyr_t *ev_qualifiers;
73412 llc_conn_action_t *ev_actions;
73413-};
73414+} __do_const;
73415
73416 struct llc_conn_state {
73417 u8 current_state;
73418diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
73419index 37a3bbd..55a4241 100644
73420--- a/include/net/llc_s_ac.h
73421+++ b/include/net/llc_s_ac.h
73422@@ -23,7 +23,7 @@
73423 #define SAP_ACT_TEST_IND 9
73424
73425 /* All action functions must look like this */
73426-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
73427+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
73428
73429 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
73430 struct sk_buff *skb);
73431diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
73432index 567c681..cd73ac0 100644
73433--- a/include/net/llc_s_st.h
73434+++ b/include/net/llc_s_st.h
73435@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
73436 llc_sap_ev_t ev;
73437 u8 next_state;
73438 llc_sap_action_t *ev_actions;
73439-};
73440+} __do_const;
73441
73442 struct llc_sap_state {
73443 u8 curr_state;
73444diff --git a/include/net/mac80211.h b/include/net/mac80211.h
73445index ee50c5e..1bc3b1a 100644
73446--- a/include/net/mac80211.h
73447+++ b/include/net/mac80211.h
73448@@ -3996,7 +3996,7 @@ struct rate_control_ops {
73449 void (*add_sta_debugfs)(void *priv, void *priv_sta,
73450 struct dentry *dir);
73451 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
73452-};
73453+} __do_const;
73454
73455 static inline int rate_supported(struct ieee80211_sta *sta,
73456 enum ieee80211_band band,
73457diff --git a/include/net/neighbour.h b/include/net/neighbour.h
73458index 0dab173..1b76af0 100644
73459--- a/include/net/neighbour.h
73460+++ b/include/net/neighbour.h
73461@@ -123,7 +123,7 @@ struct neigh_ops {
73462 void (*error_report)(struct neighbour *, struct sk_buff *);
73463 int (*output)(struct neighbour *, struct sk_buff *);
73464 int (*connected_output)(struct neighbour *, struct sk_buff *);
73465-};
73466+} __do_const;
73467
73468 struct pneigh_entry {
73469 struct pneigh_entry *next;
73470diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
73471index de644bc..dfbcc4c 100644
73472--- a/include/net/net_namespace.h
73473+++ b/include/net/net_namespace.h
73474@@ -115,7 +115,7 @@ struct net {
73475 #endif
73476 struct netns_ipvs *ipvs;
73477 struct sock *diag_nlsk;
73478- atomic_t rt_genid;
73479+ atomic_unchecked_t rt_genid;
73480 };
73481
73482 /*
73483@@ -272,7 +272,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
73484 #define __net_init __init
73485 #define __net_exit __exit_refok
73486 #define __net_initdata __initdata
73487+#ifdef CONSTIFY_PLUGIN
73488 #define __net_initconst __initconst
73489+#else
73490+#define __net_initconst __initdata
73491+#endif
73492 #endif
73493
73494 struct pernet_operations {
73495@@ -282,7 +286,7 @@ struct pernet_operations {
73496 void (*exit_batch)(struct list_head *net_exit_list);
73497 int *id;
73498 size_t size;
73499-};
73500+} __do_const;
73501
73502 /*
73503 * Use these carefully. If you implement a network device and it
73504@@ -330,12 +334,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
73505
73506 static inline int rt_genid(struct net *net)
73507 {
73508- return atomic_read(&net->rt_genid);
73509+ return atomic_read_unchecked(&net->rt_genid);
73510 }
73511
73512 static inline void rt_genid_bump(struct net *net)
73513 {
73514- atomic_inc(&net->rt_genid);
73515+ atomic_inc_unchecked(&net->rt_genid);
73516 }
73517
73518 #endif /* __NET_NET_NAMESPACE_H */
73519diff --git a/include/net/netdma.h b/include/net/netdma.h
73520index 8ba8ce2..99b7fff 100644
73521--- a/include/net/netdma.h
73522+++ b/include/net/netdma.h
73523@@ -24,7 +24,7 @@
73524 #include <linux/dmaengine.h>
73525 #include <linux/skbuff.h>
73526
73527-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
73528+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
73529 struct sk_buff *skb, int offset, struct iovec *to,
73530 size_t len, struct dma_pinned_list *pinned_list);
73531
73532diff --git a/include/net/netlink.h b/include/net/netlink.h
73533index 9690b0f..87aded7 100644
73534--- a/include/net/netlink.h
73535+++ b/include/net/netlink.h
73536@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
73537 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
73538 {
73539 if (mark)
73540- skb_trim(skb, (unsigned char *) mark - skb->data);
73541+ skb_trim(skb, (const unsigned char *) mark - skb->data);
73542 }
73543
73544 /**
73545diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
73546index 923cb20..deae816 100644
73547--- a/include/net/netns/conntrack.h
73548+++ b/include/net/netns/conntrack.h
73549@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
73550 struct nf_proto_net {
73551 #ifdef CONFIG_SYSCTL
73552 struct ctl_table_header *ctl_table_header;
73553- struct ctl_table *ctl_table;
73554+ ctl_table_no_const *ctl_table;
73555 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
73556 struct ctl_table_header *ctl_compat_header;
73557- struct ctl_table *ctl_compat_table;
73558+ ctl_table_no_const *ctl_compat_table;
73559 #endif
73560 #endif
73561 unsigned int users;
73562@@ -58,7 +58,7 @@ struct nf_ip_net {
73563 struct nf_icmp_net icmpv6;
73564 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
73565 struct ctl_table_header *ctl_table_header;
73566- struct ctl_table *ctl_table;
73567+ ctl_table_no_const *ctl_table;
73568 #endif
73569 };
73570
73571diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
73572index 2ae2b83..dbdc85e 100644
73573--- a/include/net/netns/ipv4.h
73574+++ b/include/net/netns/ipv4.h
73575@@ -64,7 +64,7 @@ struct netns_ipv4 {
73576 kgid_t sysctl_ping_group_range[2];
73577 long sysctl_tcp_mem[3];
73578
73579- atomic_t dev_addr_genid;
73580+ atomic_unchecked_t dev_addr_genid;
73581
73582 #ifdef CONFIG_IP_MROUTE
73583 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
73584diff --git a/include/net/protocol.h b/include/net/protocol.h
73585index 047c047..b9dad15 100644
73586--- a/include/net/protocol.h
73587+++ b/include/net/protocol.h
73588@@ -44,7 +44,7 @@ struct net_protocol {
73589 void (*err_handler)(struct sk_buff *skb, u32 info);
73590 unsigned int no_policy:1,
73591 netns_ok:1;
73592-};
73593+} __do_const;
73594
73595 #if IS_ENABLED(CONFIG_IPV6)
73596 struct inet6_protocol {
73597@@ -57,7 +57,7 @@ struct inet6_protocol {
73598 u8 type, u8 code, int offset,
73599 __be32 info);
73600 unsigned int flags; /* INET6_PROTO_xxx */
73601-};
73602+} __do_const;
73603
73604 #define INET6_PROTO_NOPOLICY 0x1
73605 #define INET6_PROTO_FINAL 0x2
73606diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
73607index 5a15fab..d799ea7 100644
73608--- a/include/net/rtnetlink.h
73609+++ b/include/net/rtnetlink.h
73610@@ -81,7 +81,7 @@ struct rtnl_link_ops {
73611 const struct net_device *dev);
73612 unsigned int (*get_num_tx_queues)(void);
73613 unsigned int (*get_num_rx_queues)(void);
73614-};
73615+} __do_const;
73616
73617 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
73618 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
73619diff --git a/include/net/scm.h b/include/net/scm.h
73620index 975cca0..b117081 100644
73621--- a/include/net/scm.h
73622+++ b/include/net/scm.h
73623@@ -56,8 +56,8 @@ static __inline__ void scm_set_cred(struct scm_cookie *scm,
73624 scm->pid = get_pid(pid);
73625 scm->cred = cred ? get_cred(cred) : NULL;
73626 scm->creds.pid = pid_vnr(pid);
73627- scm->creds.uid = cred ? cred->euid : INVALID_UID;
73628- scm->creds.gid = cred ? cred->egid : INVALID_GID;
73629+ scm->creds.uid = cred ? cred->uid : INVALID_UID;
73630+ scm->creds.gid = cred ? cred->gid : INVALID_GID;
73631 }
73632
73633 static __inline__ void scm_destroy_cred(struct scm_cookie *scm)
73634diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
73635index 7fdf298..197e9f7 100644
73636--- a/include/net/sctp/sctp.h
73637+++ b/include/net/sctp/sctp.h
73638@@ -330,9 +330,9 @@ do { \
73639
73640 #else /* SCTP_DEBUG */
73641
73642-#define SCTP_DEBUG_PRINTK(whatever...)
73643-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
73644-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
73645+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
73646+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
73647+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
73648 #define SCTP_ENABLE_DEBUG
73649 #define SCTP_DISABLE_DEBUG
73650 #define SCTP_ASSERT(expr, str, func)
73651diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
73652index 2a82d13..62a31c2 100644
73653--- a/include/net/sctp/sm.h
73654+++ b/include/net/sctp/sm.h
73655@@ -87,7 +87,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
73656 typedef struct {
73657 sctp_state_fn_t *fn;
73658 const char *name;
73659-} sctp_sm_table_entry_t;
73660+} __do_const sctp_sm_table_entry_t;
73661
73662 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
73663 * currently in use.
73664@@ -299,7 +299,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
73665 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
73666
73667 /* Extern declarations for major data structures. */
73668-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
73669+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
73670
73671
73672 /* Get the size of a DATA chunk payload. */
73673diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
73674index fdeb85a..1329d95 100644
73675--- a/include/net/sctp/structs.h
73676+++ b/include/net/sctp/structs.h
73677@@ -517,7 +517,7 @@ struct sctp_pf {
73678 struct sctp_association *asoc);
73679 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
73680 struct sctp_af *af;
73681-};
73682+} __do_const;
73683
73684
73685 /* Structure to track chunk fragments that have been acked, but peer
73686diff --git a/include/net/sock.h b/include/net/sock.h
73687index 25afaa0..8bb0070 100644
73688--- a/include/net/sock.h
73689+++ b/include/net/sock.h
73690@@ -322,7 +322,7 @@ struct sock {
73691 #ifdef CONFIG_RPS
73692 __u32 sk_rxhash;
73693 #endif
73694- atomic_t sk_drops;
73695+ atomic_unchecked_t sk_drops;
73696 int sk_rcvbuf;
73697
73698 struct sk_filter __rcu *sk_filter;
73699@@ -1781,7 +1781,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
73700 }
73701
73702 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
73703- char __user *from, char *to,
73704+ char __user *from, unsigned char *to,
73705 int copy, int offset)
73706 {
73707 if (skb->ip_summed == CHECKSUM_NONE) {
73708@@ -2040,7 +2040,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
73709 }
73710 }
73711
73712-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
73713+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
73714
73715 /**
73716 * sk_page_frag - return an appropriate page_frag
73717diff --git a/include/net/tcp.h b/include/net/tcp.h
73718index aed42c7..43890c6 100644
73719--- a/include/net/tcp.h
73720+++ b/include/net/tcp.h
73721@@ -530,7 +530,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
73722 extern void tcp_xmit_retransmit_queue(struct sock *);
73723 extern void tcp_simple_retransmit(struct sock *);
73724 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
73725-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
73726+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
73727
73728 extern void tcp_send_probe0(struct sock *);
73729 extern void tcp_send_partial(struct sock *);
73730@@ -701,8 +701,8 @@ struct tcp_skb_cb {
73731 struct inet6_skb_parm h6;
73732 #endif
73733 } header; /* For incoming frames */
73734- __u32 seq; /* Starting sequence number */
73735- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
73736+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
73737+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
73738 __u32 when; /* used to compute rtt's */
73739 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
73740
73741@@ -716,7 +716,7 @@ struct tcp_skb_cb {
73742
73743 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
73744 /* 1 byte hole */
73745- __u32 ack_seq; /* Sequence number ACK'd */
73746+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
73747 };
73748
73749 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
73750diff --git a/include/net/xfrm.h b/include/net/xfrm.h
73751index 63445ed..d6fc34f 100644
73752--- a/include/net/xfrm.h
73753+++ b/include/net/xfrm.h
73754@@ -304,7 +304,7 @@ struct xfrm_policy_afinfo {
73755 struct net_device *dev,
73756 const struct flowi *fl);
73757 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
73758-};
73759+} __do_const;
73760
73761 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
73762 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
73763@@ -340,7 +340,7 @@ struct xfrm_state_afinfo {
73764 struct sk_buff *skb);
73765 int (*transport_finish)(struct sk_buff *skb,
73766 int async);
73767-};
73768+} __do_const;
73769
73770 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
73771 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
73772@@ -423,7 +423,7 @@ struct xfrm_mode {
73773 struct module *owner;
73774 unsigned int encap;
73775 int flags;
73776-};
73777+} __do_const;
73778
73779 /* Flags for xfrm_mode. */
73780 enum {
73781@@ -514,7 +514,7 @@ struct xfrm_policy {
73782 struct timer_list timer;
73783
73784 struct flow_cache_object flo;
73785- atomic_t genid;
73786+ atomic_unchecked_t genid;
73787 u32 priority;
73788 u32 index;
73789 struct xfrm_mark mark;
73790diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
73791index 1a046b1..ee0bef0 100644
73792--- a/include/rdma/iw_cm.h
73793+++ b/include/rdma/iw_cm.h
73794@@ -122,7 +122,7 @@ struct iw_cm_verbs {
73795 int backlog);
73796
73797 int (*destroy_listen)(struct iw_cm_id *cm_id);
73798-};
73799+} __no_const;
73800
73801 /**
73802 * iw_create_cm_id - Create an IW CM identifier.
73803diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
73804index 399162b..b337f1a 100644
73805--- a/include/scsi/libfc.h
73806+++ b/include/scsi/libfc.h
73807@@ -762,6 +762,7 @@ struct libfc_function_template {
73808 */
73809 void (*disc_stop_final) (struct fc_lport *);
73810 };
73811+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
73812
73813 /**
73814 * struct fc_disc - Discovery context
73815@@ -866,7 +867,7 @@ struct fc_lport {
73816 struct fc_vport *vport;
73817
73818 /* Operational Information */
73819- struct libfc_function_template tt;
73820+ libfc_function_template_no_const tt;
73821 u8 link_up;
73822 u8 qfull;
73823 enum fc_lport_state state;
73824diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
73825index e65c62e..aa2e5a2 100644
73826--- a/include/scsi/scsi_device.h
73827+++ b/include/scsi/scsi_device.h
73828@@ -170,9 +170,9 @@ struct scsi_device {
73829 unsigned int max_device_blocked; /* what device_blocked counts down from */
73830 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
73831
73832- atomic_t iorequest_cnt;
73833- atomic_t iodone_cnt;
73834- atomic_t ioerr_cnt;
73835+ atomic_unchecked_t iorequest_cnt;
73836+ atomic_unchecked_t iodone_cnt;
73837+ atomic_unchecked_t ioerr_cnt;
73838
73839 struct device sdev_gendev,
73840 sdev_dev;
73841diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
73842index b797e8f..8e2c3aa 100644
73843--- a/include/scsi/scsi_transport_fc.h
73844+++ b/include/scsi/scsi_transport_fc.h
73845@@ -751,7 +751,8 @@ struct fc_function_template {
73846 unsigned long show_host_system_hostname:1;
73847
73848 unsigned long disable_target_scan:1;
73849-};
73850+} __do_const;
73851+typedef struct fc_function_template __no_const fc_function_template_no_const;
73852
73853
73854 /**
73855diff --git a/include/sound/soc.h b/include/sound/soc.h
73856index bc56738..a4be132 100644
73857--- a/include/sound/soc.h
73858+++ b/include/sound/soc.h
73859@@ -771,7 +771,7 @@ struct snd_soc_codec_driver {
73860 /* probe ordering - for components with runtime dependencies */
73861 int probe_order;
73862 int remove_order;
73863-};
73864+} __do_const;
73865
73866 /* SoC platform interface */
73867 struct snd_soc_platform_driver {
73868@@ -817,7 +817,7 @@ struct snd_soc_platform_driver {
73869 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
73870 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
73871 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
73872-};
73873+} __do_const;
73874
73875 struct snd_soc_platform {
73876 const char *name;
73877diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
73878index 663e34a..91b306a 100644
73879--- a/include/target/target_core_base.h
73880+++ b/include/target/target_core_base.h
73881@@ -654,7 +654,7 @@ struct se_device {
73882 spinlock_t stats_lock;
73883 /* Active commands on this virtual SE device */
73884 atomic_t simple_cmds;
73885- atomic_t dev_ordered_id;
73886+ atomic_unchecked_t dev_ordered_id;
73887 atomic_t dev_ordered_sync;
73888 atomic_t dev_qf_count;
73889 int export_count;
73890diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
73891new file mode 100644
73892index 0000000..fb634b7
73893--- /dev/null
73894+++ b/include/trace/events/fs.h
73895@@ -0,0 +1,53 @@
73896+#undef TRACE_SYSTEM
73897+#define TRACE_SYSTEM fs
73898+
73899+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
73900+#define _TRACE_FS_H
73901+
73902+#include <linux/fs.h>
73903+#include <linux/tracepoint.h>
73904+
73905+TRACE_EVENT(do_sys_open,
73906+
73907+ TP_PROTO(const char *filename, int flags, int mode),
73908+
73909+ TP_ARGS(filename, flags, mode),
73910+
73911+ TP_STRUCT__entry(
73912+ __string( filename, filename )
73913+ __field( int, flags )
73914+ __field( int, mode )
73915+ ),
73916+
73917+ TP_fast_assign(
73918+ __assign_str(filename, filename);
73919+ __entry->flags = flags;
73920+ __entry->mode = mode;
73921+ ),
73922+
73923+ TP_printk("\"%s\" %x %o",
73924+ __get_str(filename), __entry->flags, __entry->mode)
73925+);
73926+
73927+TRACE_EVENT(open_exec,
73928+
73929+ TP_PROTO(const char *filename),
73930+
73931+ TP_ARGS(filename),
73932+
73933+ TP_STRUCT__entry(
73934+ __string( filename, filename )
73935+ ),
73936+
73937+ TP_fast_assign(
73938+ __assign_str(filename, filename);
73939+ ),
73940+
73941+ TP_printk("\"%s\"",
73942+ __get_str(filename))
73943+);
73944+
73945+#endif /* _TRACE_FS_H */
73946+
73947+/* This part must be outside protection */
73948+#include <trace/define_trace.h>
73949diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
73950index 1c09820..7f5ec79 100644
73951--- a/include/trace/events/irq.h
73952+++ b/include/trace/events/irq.h
73953@@ -36,7 +36,7 @@ struct softirq_action;
73954 */
73955 TRACE_EVENT(irq_handler_entry,
73956
73957- TP_PROTO(int irq, struct irqaction *action),
73958+ TP_PROTO(int irq, const struct irqaction *action),
73959
73960 TP_ARGS(irq, action),
73961
73962@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
73963 */
73964 TRACE_EVENT(irq_handler_exit,
73965
73966- TP_PROTO(int irq, struct irqaction *action, int ret),
73967+ TP_PROTO(int irq, const struct irqaction *action, int ret),
73968
73969 TP_ARGS(irq, action, ret),
73970
73971diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
73972index 7caf44c..23c6f27 100644
73973--- a/include/uapi/linux/a.out.h
73974+++ b/include/uapi/linux/a.out.h
73975@@ -39,6 +39,14 @@ enum machine_type {
73976 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
73977 };
73978
73979+/* Constants for the N_FLAGS field */
73980+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
73981+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
73982+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
73983+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
73984+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
73985+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
73986+
73987 #if !defined (N_MAGIC)
73988 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
73989 #endif
73990diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
73991index d876736..ccce5c0 100644
73992--- a/include/uapi/linux/byteorder/little_endian.h
73993+++ b/include/uapi/linux/byteorder/little_endian.h
73994@@ -42,51 +42,51 @@
73995
73996 static inline __le64 __cpu_to_le64p(const __u64 *p)
73997 {
73998- return (__force __le64)*p;
73999+ return (__force const __le64)*p;
74000 }
74001-static inline __u64 __le64_to_cpup(const __le64 *p)
74002+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
74003 {
74004- return (__force __u64)*p;
74005+ return (__force const __u64)*p;
74006 }
74007 static inline __le32 __cpu_to_le32p(const __u32 *p)
74008 {
74009- return (__force __le32)*p;
74010+ return (__force const __le32)*p;
74011 }
74012 static inline __u32 __le32_to_cpup(const __le32 *p)
74013 {
74014- return (__force __u32)*p;
74015+ return (__force const __u32)*p;
74016 }
74017 static inline __le16 __cpu_to_le16p(const __u16 *p)
74018 {
74019- return (__force __le16)*p;
74020+ return (__force const __le16)*p;
74021 }
74022 static inline __u16 __le16_to_cpup(const __le16 *p)
74023 {
74024- return (__force __u16)*p;
74025+ return (__force const __u16)*p;
74026 }
74027 static inline __be64 __cpu_to_be64p(const __u64 *p)
74028 {
74029- return (__force __be64)__swab64p(p);
74030+ return (__force const __be64)__swab64p(p);
74031 }
74032 static inline __u64 __be64_to_cpup(const __be64 *p)
74033 {
74034- return __swab64p((__u64 *)p);
74035+ return __swab64p((const __u64 *)p);
74036 }
74037 static inline __be32 __cpu_to_be32p(const __u32 *p)
74038 {
74039- return (__force __be32)__swab32p(p);
74040+ return (__force const __be32)__swab32p(p);
74041 }
74042-static inline __u32 __be32_to_cpup(const __be32 *p)
74043+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
74044 {
74045- return __swab32p((__u32 *)p);
74046+ return __swab32p((const __u32 *)p);
74047 }
74048 static inline __be16 __cpu_to_be16p(const __u16 *p)
74049 {
74050- return (__force __be16)__swab16p(p);
74051+ return (__force const __be16)__swab16p(p);
74052 }
74053 static inline __u16 __be16_to_cpup(const __be16 *p)
74054 {
74055- return __swab16p((__u16 *)p);
74056+ return __swab16p((const __u16 *)p);
74057 }
74058 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
74059 #define __le64_to_cpus(x) do { (void)(x); } while (0)
74060diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
74061index 126a817..d522bd1 100644
74062--- a/include/uapi/linux/elf.h
74063+++ b/include/uapi/linux/elf.h
74064@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
74065 #define PT_GNU_EH_FRAME 0x6474e550
74066
74067 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
74068+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
74069+
74070+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
74071+
74072+/* Constants for the e_flags field */
74073+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
74074+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
74075+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
74076+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
74077+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
74078+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
74079
74080 /*
74081 * Extended Numbering
74082@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
74083 #define DT_DEBUG 21
74084 #define DT_TEXTREL 22
74085 #define DT_JMPREL 23
74086+#define DT_FLAGS 30
74087+ #define DF_TEXTREL 0x00000004
74088 #define DT_ENCODING 32
74089 #define OLD_DT_LOOS 0x60000000
74090 #define DT_LOOS 0x6000000d
74091@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
74092 #define PF_W 0x2
74093 #define PF_X 0x1
74094
74095+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
74096+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
74097+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
74098+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
74099+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
74100+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
74101+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
74102+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
74103+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
74104+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
74105+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
74106+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
74107+
74108 typedef struct elf32_phdr{
74109 Elf32_Word p_type;
74110 Elf32_Off p_offset;
74111@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
74112 #define EI_OSABI 7
74113 #define EI_PAD 8
74114
74115+#define EI_PAX 14
74116+
74117 #define ELFMAG0 0x7f /* EI_MAG */
74118 #define ELFMAG1 'E'
74119 #define ELFMAG2 'L'
74120diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
74121index aa169c4..6a2771d 100644
74122--- a/include/uapi/linux/personality.h
74123+++ b/include/uapi/linux/personality.h
74124@@ -30,6 +30,7 @@ enum {
74125 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
74126 ADDR_NO_RANDOMIZE | \
74127 ADDR_COMPAT_LAYOUT | \
74128+ ADDR_LIMIT_3GB | \
74129 MMAP_PAGE_ZERO)
74130
74131 /*
74132diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
74133index 7530e74..e714828 100644
74134--- a/include/uapi/linux/screen_info.h
74135+++ b/include/uapi/linux/screen_info.h
74136@@ -43,7 +43,8 @@ struct screen_info {
74137 __u16 pages; /* 0x32 */
74138 __u16 vesa_attributes; /* 0x34 */
74139 __u32 capabilities; /* 0x36 */
74140- __u8 _reserved[6]; /* 0x3a */
74141+ __u16 vesapm_size; /* 0x3a */
74142+ __u8 _reserved[4]; /* 0x3c */
74143 } __attribute__((packed));
74144
74145 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
74146diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
74147index 0e011eb..82681b1 100644
74148--- a/include/uapi/linux/swab.h
74149+++ b/include/uapi/linux/swab.h
74150@@ -43,7 +43,7 @@
74151 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
74152 */
74153
74154-static inline __attribute_const__ __u16 __fswab16(__u16 val)
74155+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
74156 {
74157 #ifdef __HAVE_BUILTIN_BSWAP16__
74158 return __builtin_bswap16(val);
74159@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
74160 #endif
74161 }
74162
74163-static inline __attribute_const__ __u32 __fswab32(__u32 val)
74164+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
74165 {
74166 #ifdef __HAVE_BUILTIN_BSWAP32__
74167 return __builtin_bswap32(val);
74168@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
74169 #endif
74170 }
74171
74172-static inline __attribute_const__ __u64 __fswab64(__u64 val)
74173+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
74174 {
74175 #ifdef __HAVE_BUILTIN_BSWAP64__
74176 return __builtin_bswap64(val);
74177diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
74178index 6d67213..8dab561 100644
74179--- a/include/uapi/linux/sysctl.h
74180+++ b/include/uapi/linux/sysctl.h
74181@@ -155,7 +155,11 @@ enum
74182 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
74183 };
74184
74185-
74186+#ifdef CONFIG_PAX_SOFTMODE
74187+enum {
74188+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
74189+};
74190+#endif
74191
74192 /* CTL_VM names: */
74193 enum
74194diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
74195index 26607bd..588b65f 100644
74196--- a/include/uapi/linux/xattr.h
74197+++ b/include/uapi/linux/xattr.h
74198@@ -60,5 +60,9 @@
74199 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
74200 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
74201
74202+/* User namespace */
74203+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
74204+#define XATTR_PAX_FLAGS_SUFFIX "flags"
74205+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
74206
74207 #endif /* _UAPI_LINUX_XATTR_H */
74208diff --git a/include/video/udlfb.h b/include/video/udlfb.h
74209index f9466fa..f4e2b81 100644
74210--- a/include/video/udlfb.h
74211+++ b/include/video/udlfb.h
74212@@ -53,10 +53,10 @@ struct dlfb_data {
74213 u32 pseudo_palette[256];
74214 int blank_mode; /*one of FB_BLANK_ */
74215 /* blit-only rendering path metrics, exposed through sysfs */
74216- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
74217- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
74218- atomic_t bytes_sent; /* to usb, after compression including overhead */
74219- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
74220+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
74221+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
74222+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
74223+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
74224 };
74225
74226 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
74227diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
74228index 0993a22..32ba2fe 100644
74229--- a/include/video/uvesafb.h
74230+++ b/include/video/uvesafb.h
74231@@ -177,6 +177,7 @@ struct uvesafb_par {
74232 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
74233 u8 pmi_setpal; /* PMI for palette changes */
74234 u16 *pmi_base; /* protected mode interface location */
74235+ u8 *pmi_code; /* protected mode code location */
74236 void *pmi_start;
74237 void *pmi_pal;
74238 u8 *vbe_state_orig; /*
74239diff --git a/init/Kconfig b/init/Kconfig
74240index be8b7f5..1eeca9b 100644
74241--- a/init/Kconfig
74242+++ b/init/Kconfig
74243@@ -990,6 +990,7 @@ endif # CGROUPS
74244
74245 config CHECKPOINT_RESTORE
74246 bool "Checkpoint/restore support" if EXPERT
74247+ depends on !GRKERNSEC
74248 default n
74249 help
74250 Enables additional kernel features in a sake of checkpoint/restore.
74251@@ -1468,7 +1469,7 @@ config SLUB_DEBUG
74252
74253 config COMPAT_BRK
74254 bool "Disable heap randomization"
74255- default y
74256+ default n
74257 help
74258 Randomizing heap placement makes heap exploits harder, but it
74259 also breaks ancient binaries (including anything libc5 based).
74260@@ -1711,7 +1712,7 @@ config INIT_ALL_POSSIBLE
74261 config STOP_MACHINE
74262 bool
74263 default y
74264- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
74265+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
74266 help
74267 Need stop_machine() primitive.
74268
74269diff --git a/init/Makefile b/init/Makefile
74270index 7bc47ee..6da2dc7 100644
74271--- a/init/Makefile
74272+++ b/init/Makefile
74273@@ -2,6 +2,9 @@
74274 # Makefile for the linux kernel.
74275 #
74276
74277+ccflags-y := $(GCC_PLUGINS_CFLAGS)
74278+asflags-y := $(GCC_PLUGINS_AFLAGS)
74279+
74280 obj-y := main.o version.o mounts.o
74281 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
74282 obj-y += noinitramfs.o
74283diff --git a/init/do_mounts.c b/init/do_mounts.c
74284index 1d1b634..a1c810f 100644
74285--- a/init/do_mounts.c
74286+++ b/init/do_mounts.c
74287@@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
74288 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
74289 {
74290 struct super_block *s;
74291- int err = sys_mount(name, "/root", fs, flags, data);
74292+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
74293 if (err)
74294 return err;
74295
74296- sys_chdir("/root");
74297+ sys_chdir((const char __force_user *)"/root");
74298 s = current->fs->pwd.dentry->d_sb;
74299 ROOT_DEV = s->s_dev;
74300 printk(KERN_INFO
74301@@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
74302 va_start(args, fmt);
74303 vsprintf(buf, fmt, args);
74304 va_end(args);
74305- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
74306+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
74307 if (fd >= 0) {
74308 sys_ioctl(fd, FDEJECT, 0);
74309 sys_close(fd);
74310 }
74311 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
74312- fd = sys_open("/dev/console", O_RDWR, 0);
74313+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
74314 if (fd >= 0) {
74315 sys_ioctl(fd, TCGETS, (long)&termios);
74316 termios.c_lflag &= ~ICANON;
74317 sys_ioctl(fd, TCSETSF, (long)&termios);
74318- sys_read(fd, &c, 1);
74319+ sys_read(fd, (char __user *)&c, 1);
74320 termios.c_lflag |= ICANON;
74321 sys_ioctl(fd, TCSETSF, (long)&termios);
74322 sys_close(fd);
74323@@ -585,6 +585,6 @@ void __init prepare_namespace(void)
74324 mount_root();
74325 out:
74326 devtmpfs_mount("dev");
74327- sys_mount(".", "/", NULL, MS_MOVE, NULL);
74328- sys_chroot(".");
74329+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
74330+ sys_chroot((const char __force_user *)".");
74331 }
74332diff --git a/init/do_mounts.h b/init/do_mounts.h
74333index f5b978a..69dbfe8 100644
74334--- a/init/do_mounts.h
74335+++ b/init/do_mounts.h
74336@@ -15,15 +15,15 @@ extern int root_mountflags;
74337
74338 static inline int create_dev(char *name, dev_t dev)
74339 {
74340- sys_unlink(name);
74341- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
74342+ sys_unlink((char __force_user *)name);
74343+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
74344 }
74345
74346 #if BITS_PER_LONG == 32
74347 static inline u32 bstat(char *name)
74348 {
74349 struct stat64 stat;
74350- if (sys_stat64(name, &stat) != 0)
74351+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
74352 return 0;
74353 if (!S_ISBLK(stat.st_mode))
74354 return 0;
74355@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
74356 static inline u32 bstat(char *name)
74357 {
74358 struct stat stat;
74359- if (sys_newstat(name, &stat) != 0)
74360+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
74361 return 0;
74362 if (!S_ISBLK(stat.st_mode))
74363 return 0;
74364diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
74365index f9acf71..1e19144 100644
74366--- a/init/do_mounts_initrd.c
74367+++ b/init/do_mounts_initrd.c
74368@@ -58,8 +58,8 @@ static void __init handle_initrd(void)
74369 create_dev("/dev/root.old", Root_RAM0);
74370 /* mount initrd on rootfs' /root */
74371 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
74372- sys_mkdir("/old", 0700);
74373- sys_chdir("/old");
74374+ sys_mkdir((const char __force_user *)"/old", 0700);
74375+ sys_chdir((const char __force_user *)"/old");
74376
74377 /*
74378 * In case that a resume from disk is carried out by linuxrc or one of
74379@@ -73,31 +73,31 @@ static void __init handle_initrd(void)
74380 current->flags &= ~PF_FREEZER_SKIP;
74381
74382 /* move initrd to rootfs' /old */
74383- sys_mount("..", ".", NULL, MS_MOVE, NULL);
74384+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
74385 /* switch root and cwd back to / of rootfs */
74386- sys_chroot("..");
74387+ sys_chroot((const char __force_user *)"..");
74388
74389 if (new_decode_dev(real_root_dev) == Root_RAM0) {
74390- sys_chdir("/old");
74391+ sys_chdir((const char __force_user *)"/old");
74392 return;
74393 }
74394
74395- sys_chdir("/");
74396+ sys_chdir((const char __force_user *)"/");
74397 ROOT_DEV = new_decode_dev(real_root_dev);
74398 mount_root();
74399
74400 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
74401- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
74402+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
74403 if (!error)
74404 printk("okay\n");
74405 else {
74406- int fd = sys_open("/dev/root.old", O_RDWR, 0);
74407+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
74408 if (error == -ENOENT)
74409 printk("/initrd does not exist. Ignored.\n");
74410 else
74411 printk("failed\n");
74412 printk(KERN_NOTICE "Unmounting old root\n");
74413- sys_umount("/old", MNT_DETACH);
74414+ sys_umount((char __force_user *)"/old", MNT_DETACH);
74415 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
74416 if (fd < 0) {
74417 error = fd;
74418@@ -120,11 +120,11 @@ int __init initrd_load(void)
74419 * mounted in the normal path.
74420 */
74421 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
74422- sys_unlink("/initrd.image");
74423+ sys_unlink((const char __force_user *)"/initrd.image");
74424 handle_initrd();
74425 return 1;
74426 }
74427 }
74428- sys_unlink("/initrd.image");
74429+ sys_unlink((const char __force_user *)"/initrd.image");
74430 return 0;
74431 }
74432diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
74433index 8cb6db5..d729f50 100644
74434--- a/init/do_mounts_md.c
74435+++ b/init/do_mounts_md.c
74436@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
74437 partitioned ? "_d" : "", minor,
74438 md_setup_args[ent].device_names);
74439
74440- fd = sys_open(name, 0, 0);
74441+ fd = sys_open((char __force_user *)name, 0, 0);
74442 if (fd < 0) {
74443 printk(KERN_ERR "md: open failed - cannot start "
74444 "array %s\n", name);
74445@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
74446 * array without it
74447 */
74448 sys_close(fd);
74449- fd = sys_open(name, 0, 0);
74450+ fd = sys_open((char __force_user *)name, 0, 0);
74451 sys_ioctl(fd, BLKRRPART, 0);
74452 }
74453 sys_close(fd);
74454@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
74455
74456 wait_for_device_probe();
74457
74458- fd = sys_open("/dev/md0", 0, 0);
74459+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
74460 if (fd >= 0) {
74461 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
74462 sys_close(fd);
74463diff --git a/init/init_task.c b/init/init_task.c
74464index 8b2f399..f0797c9 100644
74465--- a/init/init_task.c
74466+++ b/init/init_task.c
74467@@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
74468 * Initial thread structure. Alignment of this is handled by a special
74469 * linker map entry.
74470 */
74471+#ifdef CONFIG_X86
74472+union thread_union init_thread_union __init_task_data;
74473+#else
74474 union thread_union init_thread_union __init_task_data =
74475 { INIT_THREAD_INFO(init_task) };
74476+#endif
74477diff --git a/init/initramfs.c b/init/initramfs.c
74478index 84c6bf1..8899338 100644
74479--- a/init/initramfs.c
74480+++ b/init/initramfs.c
74481@@ -84,7 +84,7 @@ static void __init free_hash(void)
74482 }
74483 }
74484
74485-static long __init do_utime(char *filename, time_t mtime)
74486+static long __init do_utime(char __force_user *filename, time_t mtime)
74487 {
74488 struct timespec t[2];
74489
74490@@ -119,7 +119,7 @@ static void __init dir_utime(void)
74491 struct dir_entry *de, *tmp;
74492 list_for_each_entry_safe(de, tmp, &dir_list, list) {
74493 list_del(&de->list);
74494- do_utime(de->name, de->mtime);
74495+ do_utime((char __force_user *)de->name, de->mtime);
74496 kfree(de->name);
74497 kfree(de);
74498 }
74499@@ -281,7 +281,7 @@ static int __init maybe_link(void)
74500 if (nlink >= 2) {
74501 char *old = find_link(major, minor, ino, mode, collected);
74502 if (old)
74503- return (sys_link(old, collected) < 0) ? -1 : 1;
74504+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
74505 }
74506 return 0;
74507 }
74508@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
74509 {
74510 struct stat st;
74511
74512- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
74513+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
74514 if (S_ISDIR(st.st_mode))
74515- sys_rmdir(path);
74516+ sys_rmdir((char __force_user *)path);
74517 else
74518- sys_unlink(path);
74519+ sys_unlink((char __force_user *)path);
74520 }
74521 }
74522
74523@@ -315,7 +315,7 @@ static int __init do_name(void)
74524 int openflags = O_WRONLY|O_CREAT;
74525 if (ml != 1)
74526 openflags |= O_TRUNC;
74527- wfd = sys_open(collected, openflags, mode);
74528+ wfd = sys_open((char __force_user *)collected, openflags, mode);
74529
74530 if (wfd >= 0) {
74531 sys_fchown(wfd, uid, gid);
74532@@ -327,17 +327,17 @@ static int __init do_name(void)
74533 }
74534 }
74535 } else if (S_ISDIR(mode)) {
74536- sys_mkdir(collected, mode);
74537- sys_chown(collected, uid, gid);
74538- sys_chmod(collected, mode);
74539+ sys_mkdir((char __force_user *)collected, mode);
74540+ sys_chown((char __force_user *)collected, uid, gid);
74541+ sys_chmod((char __force_user *)collected, mode);
74542 dir_add(collected, mtime);
74543 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
74544 S_ISFIFO(mode) || S_ISSOCK(mode)) {
74545 if (maybe_link() == 0) {
74546- sys_mknod(collected, mode, rdev);
74547- sys_chown(collected, uid, gid);
74548- sys_chmod(collected, mode);
74549- do_utime(collected, mtime);
74550+ sys_mknod((char __force_user *)collected, mode, rdev);
74551+ sys_chown((char __force_user *)collected, uid, gid);
74552+ sys_chmod((char __force_user *)collected, mode);
74553+ do_utime((char __force_user *)collected, mtime);
74554 }
74555 }
74556 return 0;
74557@@ -346,15 +346,15 @@ static int __init do_name(void)
74558 static int __init do_copy(void)
74559 {
74560 if (count >= body_len) {
74561- sys_write(wfd, victim, body_len);
74562+ sys_write(wfd, (char __force_user *)victim, body_len);
74563 sys_close(wfd);
74564- do_utime(vcollected, mtime);
74565+ do_utime((char __force_user *)vcollected, mtime);
74566 kfree(vcollected);
74567 eat(body_len);
74568 state = SkipIt;
74569 return 0;
74570 } else {
74571- sys_write(wfd, victim, count);
74572+ sys_write(wfd, (char __force_user *)victim, count);
74573 body_len -= count;
74574 eat(count);
74575 return 1;
74576@@ -365,9 +365,9 @@ static int __init do_symlink(void)
74577 {
74578 collected[N_ALIGN(name_len) + body_len] = '\0';
74579 clean_path(collected, 0);
74580- sys_symlink(collected + N_ALIGN(name_len), collected);
74581- sys_lchown(collected, uid, gid);
74582- do_utime(collected, mtime);
74583+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
74584+ sys_lchown((char __force_user *)collected, uid, gid);
74585+ do_utime((char __force_user *)collected, mtime);
74586 state = SkipIt;
74587 next_state = Reset;
74588 return 0;
74589diff --git a/init/main.c b/init/main.c
74590index cee4b5c..360e10a 100644
74591--- a/init/main.c
74592+++ b/init/main.c
74593@@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
74594 extern void tc_init(void);
74595 #endif
74596
74597+extern void grsecurity_init(void);
74598+
74599 /*
74600 * Debug helper: via this flag we know that we are in 'early bootup code'
74601 * where only the boot processor is running with IRQ disabled. This means
74602@@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
74603
74604 __setup("reset_devices", set_reset_devices);
74605
74606+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
74607+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
74608+static int __init setup_grsec_proc_gid(char *str)
74609+{
74610+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
74611+ return 1;
74612+}
74613+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
74614+#endif
74615+
74616+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
74617+extern char pax_enter_kernel_user[];
74618+extern char pax_exit_kernel_user[];
74619+extern pgdval_t clone_pgd_mask;
74620+#endif
74621+
74622+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
74623+static int __init setup_pax_nouderef(char *str)
74624+{
74625+#ifdef CONFIG_X86_32
74626+ unsigned int cpu;
74627+ struct desc_struct *gdt;
74628+
74629+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
74630+ gdt = get_cpu_gdt_table(cpu);
74631+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
74632+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
74633+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
74634+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
74635+ }
74636+ loadsegment(ds, __KERNEL_DS);
74637+ loadsegment(es, __KERNEL_DS);
74638+ loadsegment(ss, __KERNEL_DS);
74639+#else
74640+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
74641+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
74642+ clone_pgd_mask = ~(pgdval_t)0UL;
74643+#endif
74644+
74645+ return 0;
74646+}
74647+early_param("pax_nouderef", setup_pax_nouderef);
74648+#endif
74649+
74650+#ifdef CONFIG_PAX_SOFTMODE
74651+int pax_softmode;
74652+
74653+static int __init setup_pax_softmode(char *str)
74654+{
74655+ get_option(&str, &pax_softmode);
74656+ return 1;
74657+}
74658+__setup("pax_softmode=", setup_pax_softmode);
74659+#endif
74660+
74661 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
74662 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
74663 static const char *panic_later, *panic_param;
74664@@ -681,6 +738,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
74665 {
74666 int count = preempt_count();
74667 int ret;
74668+ const char *msg1 = "", *msg2 = "";
74669
74670 if (initcall_debug)
74671 ret = do_one_initcall_debug(fn);
74672@@ -693,15 +751,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
74673 sprintf(msgbuf, "error code %d ", ret);
74674
74675 if (preempt_count() != count) {
74676- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
74677+ msg1 = " preemption imbalance";
74678 preempt_count() = count;
74679 }
74680 if (irqs_disabled()) {
74681- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
74682+ msg2 = " disabled interrupts";
74683 local_irq_enable();
74684 }
74685- if (msgbuf[0]) {
74686- printk("initcall %pF returned with %s\n", fn, msgbuf);
74687+ if (msgbuf[0] || *msg1 || *msg2) {
74688+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
74689 }
74690
74691 return ret;
74692@@ -755,8 +813,14 @@ static void __init do_initcall_level(int level)
74693 level, level,
74694 &repair_env_string);
74695
74696- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
74697+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
74698 do_one_initcall(*fn);
74699+
74700+#ifdef LATENT_ENTROPY_PLUGIN
74701+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
74702+#endif
74703+
74704+ }
74705 }
74706
74707 static void __init do_initcalls(void)
74708@@ -790,8 +854,14 @@ static void __init do_pre_smp_initcalls(void)
74709 {
74710 initcall_t *fn;
74711
74712- for (fn = __initcall_start; fn < __initcall0_start; fn++)
74713+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
74714 do_one_initcall(*fn);
74715+
74716+#ifdef LATENT_ENTROPY_PLUGIN
74717+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
74718+#endif
74719+
74720+ }
74721 }
74722
74723 static int run_init_process(const char *init_filename)
74724@@ -877,7 +947,7 @@ static noinline void __init kernel_init_freeable(void)
74725 do_basic_setup();
74726
74727 /* Open the /dev/console on the rootfs, this should never fail */
74728- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
74729+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
74730 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
74731
74732 (void) sys_dup(0);
74733@@ -890,11 +960,13 @@ static noinline void __init kernel_init_freeable(void)
74734 if (!ramdisk_execute_command)
74735 ramdisk_execute_command = "/init";
74736
74737- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
74738+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
74739 ramdisk_execute_command = NULL;
74740 prepare_namespace();
74741 }
74742
74743+ grsecurity_init();
74744+
74745 /*
74746 * Ok, we have completed the initial bootup, and
74747 * we're essentially up and running. Get rid of the
74748diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
74749index 130dfec..cc88451 100644
74750--- a/ipc/ipc_sysctl.c
74751+++ b/ipc/ipc_sysctl.c
74752@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
74753 static int proc_ipc_dointvec(ctl_table *table, int write,
74754 void __user *buffer, size_t *lenp, loff_t *ppos)
74755 {
74756- struct ctl_table ipc_table;
74757+ ctl_table_no_const ipc_table;
74758
74759 memcpy(&ipc_table, table, sizeof(ipc_table));
74760 ipc_table.data = get_ipc(table);
74761@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
74762 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
74763 void __user *buffer, size_t *lenp, loff_t *ppos)
74764 {
74765- struct ctl_table ipc_table;
74766+ ctl_table_no_const ipc_table;
74767
74768 memcpy(&ipc_table, table, sizeof(ipc_table));
74769 ipc_table.data = get_ipc(table);
74770@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
74771 static int proc_ipc_callback_dointvec(ctl_table *table, int write,
74772 void __user *buffer, size_t *lenp, loff_t *ppos)
74773 {
74774- struct ctl_table ipc_table;
74775+ ctl_table_no_const ipc_table;
74776 size_t lenp_bef = *lenp;
74777 int rc;
74778
74779@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
74780 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
74781 void __user *buffer, size_t *lenp, loff_t *ppos)
74782 {
74783- struct ctl_table ipc_table;
74784+ ctl_table_no_const ipc_table;
74785 memcpy(&ipc_table, table, sizeof(ipc_table));
74786 ipc_table.data = get_ipc(table);
74787
74788@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
74789 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
74790 void __user *buffer, size_t *lenp, loff_t *ppos)
74791 {
74792- struct ctl_table ipc_table;
74793+ ctl_table_no_const ipc_table;
74794 size_t lenp_bef = *lenp;
74795 int oldval;
74796 int rc;
74797diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
74798index 383d638..943fdbb 100644
74799--- a/ipc/mq_sysctl.c
74800+++ b/ipc/mq_sysctl.c
74801@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
74802 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
74803 void __user *buffer, size_t *lenp, loff_t *ppos)
74804 {
74805- struct ctl_table mq_table;
74806+ ctl_table_no_const mq_table;
74807 memcpy(&mq_table, table, sizeof(mq_table));
74808 mq_table.data = get_mq(table);
74809
74810diff --git a/ipc/mqueue.c b/ipc/mqueue.c
74811index f3f40dc..ffe5a3a 100644
74812--- a/ipc/mqueue.c
74813+++ b/ipc/mqueue.c
74814@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
74815 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
74816 info->attr.mq_msgsize);
74817
74818+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
74819 spin_lock(&mq_lock);
74820 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
74821 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
74822diff --git a/ipc/msg.c b/ipc/msg.c
74823index fede1d0..9778e0f8 100644
74824--- a/ipc/msg.c
74825+++ b/ipc/msg.c
74826@@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
74827 return security_msg_queue_associate(msq, msgflg);
74828 }
74829
74830+static struct ipc_ops msg_ops = {
74831+ .getnew = newque,
74832+ .associate = msg_security,
74833+ .more_checks = NULL
74834+};
74835+
74836 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
74837 {
74838 struct ipc_namespace *ns;
74839- struct ipc_ops msg_ops;
74840 struct ipc_params msg_params;
74841
74842 ns = current->nsproxy->ipc_ns;
74843
74844- msg_ops.getnew = newque;
74845- msg_ops.associate = msg_security;
74846- msg_ops.more_checks = NULL;
74847-
74848 msg_params.key = key;
74849 msg_params.flg = msgflg;
74850
74851diff --git a/ipc/sem.c b/ipc/sem.c
74852index 58d31f1..cce7a55 100644
74853--- a/ipc/sem.c
74854+++ b/ipc/sem.c
74855@@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
74856 return 0;
74857 }
74858
74859+static struct ipc_ops sem_ops = {
74860+ .getnew = newary,
74861+ .associate = sem_security,
74862+ .more_checks = sem_more_checks
74863+};
74864+
74865 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
74866 {
74867 struct ipc_namespace *ns;
74868- struct ipc_ops sem_ops;
74869 struct ipc_params sem_params;
74870
74871 ns = current->nsproxy->ipc_ns;
74872@@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
74873 if (nsems < 0 || nsems > ns->sc_semmsl)
74874 return -EINVAL;
74875
74876- sem_ops.getnew = newary;
74877- sem_ops.associate = sem_security;
74878- sem_ops.more_checks = sem_more_checks;
74879-
74880 sem_params.key = key;
74881 sem_params.flg = semflg;
74882 sem_params.u.nsems = nsems;
74883diff --git a/ipc/shm.c b/ipc/shm.c
74884index 4fa6d8f..55cff14 100644
74885--- a/ipc/shm.c
74886+++ b/ipc/shm.c
74887@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
74888 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
74889 #endif
74890
74891+#ifdef CONFIG_GRKERNSEC
74892+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74893+ const time_t shm_createtime, const kuid_t cuid,
74894+ const int shmid);
74895+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74896+ const time_t shm_createtime);
74897+#endif
74898+
74899 void shm_init_ns(struct ipc_namespace *ns)
74900 {
74901 ns->shm_ctlmax = SHMMAX;
74902@@ -521,6 +529,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
74903 shp->shm_lprid = 0;
74904 shp->shm_atim = shp->shm_dtim = 0;
74905 shp->shm_ctim = get_seconds();
74906+#ifdef CONFIG_GRKERNSEC
74907+ {
74908+ struct timespec timeval;
74909+ do_posix_clock_monotonic_gettime(&timeval);
74910+
74911+ shp->shm_createtime = timeval.tv_sec;
74912+ }
74913+#endif
74914 shp->shm_segsz = size;
74915 shp->shm_nattch = 0;
74916 shp->shm_file = file;
74917@@ -572,18 +588,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
74918 return 0;
74919 }
74920
74921+static struct ipc_ops shm_ops = {
74922+ .getnew = newseg,
74923+ .associate = shm_security,
74924+ .more_checks = shm_more_checks
74925+};
74926+
74927 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
74928 {
74929 struct ipc_namespace *ns;
74930- struct ipc_ops shm_ops;
74931 struct ipc_params shm_params;
74932
74933 ns = current->nsproxy->ipc_ns;
74934
74935- shm_ops.getnew = newseg;
74936- shm_ops.associate = shm_security;
74937- shm_ops.more_checks = shm_more_checks;
74938-
74939 shm_params.key = key;
74940 shm_params.flg = shmflg;
74941 shm_params.u.size = size;
74942@@ -1004,6 +1021,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
74943 f_mode = FMODE_READ | FMODE_WRITE;
74944 }
74945 if (shmflg & SHM_EXEC) {
74946+
74947+#ifdef CONFIG_PAX_MPROTECT
74948+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
74949+ goto out;
74950+#endif
74951+
74952 prot |= PROT_EXEC;
74953 acc_mode |= S_IXUGO;
74954 }
74955@@ -1027,9 +1050,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
74956 if (err)
74957 goto out_unlock;
74958
74959+#ifdef CONFIG_GRKERNSEC
74960+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
74961+ shp->shm_perm.cuid, shmid) ||
74962+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
74963+ err = -EACCES;
74964+ goto out_unlock;
74965+ }
74966+#endif
74967+
74968 path = shp->shm_file->f_path;
74969 path_get(&path);
74970 shp->shm_nattch++;
74971+#ifdef CONFIG_GRKERNSEC
74972+ shp->shm_lapid = current->pid;
74973+#endif
74974 size = i_size_read(path.dentry->d_inode);
74975 shm_unlock(shp);
74976
74977diff --git a/kernel/acct.c b/kernel/acct.c
74978index 051e071..15e0920 100644
74979--- a/kernel/acct.c
74980+++ b/kernel/acct.c
74981@@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
74982 */
74983 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
74984 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
74985- file->f_op->write(file, (char *)&ac,
74986+ file->f_op->write(file, (char __force_user *)&ac,
74987 sizeof(acct_t), &file->f_pos);
74988 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
74989 set_fs(fs);
74990diff --git a/kernel/audit.c b/kernel/audit.c
74991index d596e53..dbef3c3 100644
74992--- a/kernel/audit.c
74993+++ b/kernel/audit.c
74994@@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
74995 3) suppressed due to audit_rate_limit
74996 4) suppressed due to audit_backlog_limit
74997 */
74998-static atomic_t audit_lost = ATOMIC_INIT(0);
74999+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
75000
75001 /* The netlink socket. */
75002 static struct sock *audit_sock;
75003@@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
75004 unsigned long now;
75005 int print;
75006
75007- atomic_inc(&audit_lost);
75008+ atomic_inc_unchecked(&audit_lost);
75009
75010 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
75011
75012@@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
75013 printk(KERN_WARNING
75014 "audit: audit_lost=%d audit_rate_limit=%d "
75015 "audit_backlog_limit=%d\n",
75016- atomic_read(&audit_lost),
75017+ atomic_read_unchecked(&audit_lost),
75018 audit_rate_limit,
75019 audit_backlog_limit);
75020 audit_panic(message);
75021@@ -681,7 +681,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
75022 status_set.pid = audit_pid;
75023 status_set.rate_limit = audit_rate_limit;
75024 status_set.backlog_limit = audit_backlog_limit;
75025- status_set.lost = atomic_read(&audit_lost);
75026+ status_set.lost = atomic_read_unchecked(&audit_lost);
75027 status_set.backlog = skb_queue_len(&audit_skb_queue);
75028 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
75029 &status_set, sizeof(status_set));
75030diff --git a/kernel/auditsc.c b/kernel/auditsc.c
75031index a371f85..da826c1 100644
75032--- a/kernel/auditsc.c
75033+++ b/kernel/auditsc.c
75034@@ -2292,7 +2292,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
75035 }
75036
75037 /* global counter which is incremented every time something logs in */
75038-static atomic_t session_id = ATOMIC_INIT(0);
75039+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
75040
75041 /**
75042 * audit_set_loginuid - set current task's audit_context loginuid
75043@@ -2316,7 +2316,7 @@ int audit_set_loginuid(kuid_t loginuid)
75044 return -EPERM;
75045 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
75046
75047- sessionid = atomic_inc_return(&session_id);
75048+ sessionid = atomic_inc_return_unchecked(&session_id);
75049 if (context && context->in_syscall) {
75050 struct audit_buffer *ab;
75051
75052diff --git a/kernel/capability.c b/kernel/capability.c
75053index 493d972..f87dfbd 100644
75054--- a/kernel/capability.c
75055+++ b/kernel/capability.c
75056@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
75057 * before modification is attempted and the application
75058 * fails.
75059 */
75060+ if (tocopy > ARRAY_SIZE(kdata))
75061+ return -EFAULT;
75062+
75063 if (copy_to_user(dataptr, kdata, tocopy
75064 * sizeof(struct __user_cap_data_struct))) {
75065 return -EFAULT;
75066@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
75067 int ret;
75068
75069 rcu_read_lock();
75070- ret = security_capable(__task_cred(t), ns, cap);
75071+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
75072+ gr_task_is_capable(t, __task_cred(t), cap);
75073 rcu_read_unlock();
75074
75075- return (ret == 0);
75076+ return ret;
75077 }
75078
75079 /**
75080@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
75081 int ret;
75082
75083 rcu_read_lock();
75084- ret = security_capable_noaudit(__task_cred(t), ns, cap);
75085+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
75086 rcu_read_unlock();
75087
75088- return (ret == 0);
75089+ return ret;
75090 }
75091
75092 /**
75093@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
75094 BUG();
75095 }
75096
75097- if (security_capable(current_cred(), ns, cap) == 0) {
75098+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
75099 current->flags |= PF_SUPERPRIV;
75100 return true;
75101 }
75102@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
75103 }
75104 EXPORT_SYMBOL(ns_capable);
75105
75106+bool ns_capable_nolog(struct user_namespace *ns, int cap)
75107+{
75108+ if (unlikely(!cap_valid(cap))) {
75109+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
75110+ BUG();
75111+ }
75112+
75113+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
75114+ current->flags |= PF_SUPERPRIV;
75115+ return true;
75116+ }
75117+ return false;
75118+}
75119+EXPORT_SYMBOL(ns_capable_nolog);
75120+
75121 /**
75122 * capable - Determine if the current task has a superior capability in effect
75123 * @cap: The capability to be tested for
75124@@ -408,6 +427,12 @@ bool capable(int cap)
75125 }
75126 EXPORT_SYMBOL(capable);
75127
75128+bool capable_nolog(int cap)
75129+{
75130+ return ns_capable_nolog(&init_user_ns, cap);
75131+}
75132+EXPORT_SYMBOL(capable_nolog);
75133+
75134 /**
75135 * nsown_capable - Check superior capability to one's own user_ns
75136 * @cap: The capability in question
75137@@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
75138
75139 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
75140 }
75141+
75142+bool inode_capable_nolog(const struct inode *inode, int cap)
75143+{
75144+ struct user_namespace *ns = current_user_ns();
75145+
75146+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
75147+}
75148diff --git a/kernel/cgroup.c b/kernel/cgroup.c
75149index 1e23664..570a83d 100644
75150--- a/kernel/cgroup.c
75151+++ b/kernel/cgroup.c
75152@@ -5543,7 +5543,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
75153 struct css_set *cg = link->cg;
75154 struct task_struct *task;
75155 int count = 0;
75156- seq_printf(seq, "css_set %p\n", cg);
75157+ seq_printf(seq, "css_set %pK\n", cg);
75158 list_for_each_entry(task, &cg->tasks, cg_list) {
75159 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
75160 seq_puts(seq, " ...\n");
75161diff --git a/kernel/compat.c b/kernel/compat.c
75162index 36700e9..73d770c 100644
75163--- a/kernel/compat.c
75164+++ b/kernel/compat.c
75165@@ -13,6 +13,7 @@
75166
75167 #include <linux/linkage.h>
75168 #include <linux/compat.h>
75169+#include <linux/module.h>
75170 #include <linux/errno.h>
75171 #include <linux/time.h>
75172 #include <linux/signal.h>
75173@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
75174 mm_segment_t oldfs;
75175 long ret;
75176
75177- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
75178+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
75179 oldfs = get_fs();
75180 set_fs(KERNEL_DS);
75181 ret = hrtimer_nanosleep_restart(restart);
75182@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
75183 oldfs = get_fs();
75184 set_fs(KERNEL_DS);
75185 ret = hrtimer_nanosleep(&tu,
75186- rmtp ? (struct timespec __user *)&rmt : NULL,
75187+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
75188 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
75189 set_fs(oldfs);
75190
75191@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
75192 mm_segment_t old_fs = get_fs();
75193
75194 set_fs(KERNEL_DS);
75195- ret = sys_sigpending((old_sigset_t __user *) &s);
75196+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
75197 set_fs(old_fs);
75198 if (ret == 0)
75199 ret = put_user(s, set);
75200@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
75201 mm_segment_t old_fs = get_fs();
75202
75203 set_fs(KERNEL_DS);
75204- ret = sys_old_getrlimit(resource, &r);
75205+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
75206 set_fs(old_fs);
75207
75208 if (!ret) {
75209@@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
75210 mm_segment_t old_fs = get_fs();
75211
75212 set_fs(KERNEL_DS);
75213- ret = sys_getrusage(who, (struct rusage __user *) &r);
75214+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
75215 set_fs(old_fs);
75216
75217 if (ret)
75218@@ -552,8 +553,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
75219 set_fs (KERNEL_DS);
75220 ret = sys_wait4(pid,
75221 (stat_addr ?
75222- (unsigned int __user *) &status : NULL),
75223- options, (struct rusage __user *) &r);
75224+ (unsigned int __force_user *) &status : NULL),
75225+ options, (struct rusage __force_user *) &r);
75226 set_fs (old_fs);
75227
75228 if (ret > 0) {
75229@@ -579,8 +580,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
75230 memset(&info, 0, sizeof(info));
75231
75232 set_fs(KERNEL_DS);
75233- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
75234- uru ? (struct rusage __user *)&ru : NULL);
75235+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
75236+ uru ? (struct rusage __force_user *)&ru : NULL);
75237 set_fs(old_fs);
75238
75239 if ((ret < 0) || (info.si_signo == 0))
75240@@ -714,8 +715,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
75241 oldfs = get_fs();
75242 set_fs(KERNEL_DS);
75243 err = sys_timer_settime(timer_id, flags,
75244- (struct itimerspec __user *) &newts,
75245- (struct itimerspec __user *) &oldts);
75246+ (struct itimerspec __force_user *) &newts,
75247+ (struct itimerspec __force_user *) &oldts);
75248 set_fs(oldfs);
75249 if (!err && old && put_compat_itimerspec(old, &oldts))
75250 return -EFAULT;
75251@@ -732,7 +733,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
75252 oldfs = get_fs();
75253 set_fs(KERNEL_DS);
75254 err = sys_timer_gettime(timer_id,
75255- (struct itimerspec __user *) &ts);
75256+ (struct itimerspec __force_user *) &ts);
75257 set_fs(oldfs);
75258 if (!err && put_compat_itimerspec(setting, &ts))
75259 return -EFAULT;
75260@@ -751,7 +752,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
75261 oldfs = get_fs();
75262 set_fs(KERNEL_DS);
75263 err = sys_clock_settime(which_clock,
75264- (struct timespec __user *) &ts);
75265+ (struct timespec __force_user *) &ts);
75266 set_fs(oldfs);
75267 return err;
75268 }
75269@@ -766,7 +767,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
75270 oldfs = get_fs();
75271 set_fs(KERNEL_DS);
75272 err = sys_clock_gettime(which_clock,
75273- (struct timespec __user *) &ts);
75274+ (struct timespec __force_user *) &ts);
75275 set_fs(oldfs);
75276 if (!err && put_compat_timespec(&ts, tp))
75277 return -EFAULT;
75278@@ -786,7 +787,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
75279
75280 oldfs = get_fs();
75281 set_fs(KERNEL_DS);
75282- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
75283+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
75284 set_fs(oldfs);
75285
75286 err = compat_put_timex(utp, &txc);
75287@@ -806,7 +807,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
75288 oldfs = get_fs();
75289 set_fs(KERNEL_DS);
75290 err = sys_clock_getres(which_clock,
75291- (struct timespec __user *) &ts);
75292+ (struct timespec __force_user *) &ts);
75293 set_fs(oldfs);
75294 if (!err && tp && put_compat_timespec(&ts, tp))
75295 return -EFAULT;
75296@@ -818,9 +819,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
75297 long err;
75298 mm_segment_t oldfs;
75299 struct timespec tu;
75300- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
75301+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
75302
75303- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
75304+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
75305 oldfs = get_fs();
75306 set_fs(KERNEL_DS);
75307 err = clock_nanosleep_restart(restart);
75308@@ -852,8 +853,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
75309 oldfs = get_fs();
75310 set_fs(KERNEL_DS);
75311 err = sys_clock_nanosleep(which_clock, flags,
75312- (struct timespec __user *) &in,
75313- (struct timespec __user *) &out);
75314+ (struct timespec __force_user *) &in,
75315+ (struct timespec __force_user *) &out);
75316 set_fs(oldfs);
75317
75318 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
75319diff --git a/kernel/configs.c b/kernel/configs.c
75320index 42e8fa0..9e7406b 100644
75321--- a/kernel/configs.c
75322+++ b/kernel/configs.c
75323@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
75324 struct proc_dir_entry *entry;
75325
75326 /* create the current config file */
75327+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
75328+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
75329+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
75330+ &ikconfig_file_ops);
75331+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75332+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
75333+ &ikconfig_file_ops);
75334+#endif
75335+#else
75336 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
75337 &ikconfig_file_ops);
75338+#endif
75339+
75340 if (!entry)
75341 return -ENOMEM;
75342
75343diff --git a/kernel/cred.c b/kernel/cred.c
75344index e0573a4..3874e41 100644
75345--- a/kernel/cred.c
75346+++ b/kernel/cred.c
75347@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
75348 validate_creds(cred);
75349 alter_cred_subscribers(cred, -1);
75350 put_cred(cred);
75351+
75352+#ifdef CONFIG_GRKERNSEC_SETXID
75353+ cred = (struct cred *) tsk->delayed_cred;
75354+ if (cred != NULL) {
75355+ tsk->delayed_cred = NULL;
75356+ validate_creds(cred);
75357+ alter_cred_subscribers(cred, -1);
75358+ put_cred(cred);
75359+ }
75360+#endif
75361 }
75362
75363 /**
75364@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
75365 * Always returns 0 thus allowing this function to be tail-called at the end
75366 * of, say, sys_setgid().
75367 */
75368-int commit_creds(struct cred *new)
75369+static int __commit_creds(struct cred *new)
75370 {
75371 struct task_struct *task = current;
75372 const struct cred *old = task->real_cred;
75373@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
75374
75375 get_cred(new); /* we will require a ref for the subj creds too */
75376
75377+ gr_set_role_label(task, new->uid, new->gid);
75378+
75379 /* dumpability changes */
75380 if (!uid_eq(old->euid, new->euid) ||
75381 !gid_eq(old->egid, new->egid) ||
75382@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
75383 put_cred(old);
75384 return 0;
75385 }
75386+#ifdef CONFIG_GRKERNSEC_SETXID
75387+extern int set_user(struct cred *new);
75388+
75389+void gr_delayed_cred_worker(void)
75390+{
75391+ const struct cred *new = current->delayed_cred;
75392+ struct cred *ncred;
75393+
75394+ current->delayed_cred = NULL;
75395+
75396+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
75397+ // from doing get_cred on it when queueing this
75398+ put_cred(new);
75399+ return;
75400+ } else if (new == NULL)
75401+ return;
75402+
75403+ ncred = prepare_creds();
75404+ if (!ncred)
75405+ goto die;
75406+ // uids
75407+ ncred->uid = new->uid;
75408+ ncred->euid = new->euid;
75409+ ncred->suid = new->suid;
75410+ ncred->fsuid = new->fsuid;
75411+ // gids
75412+ ncred->gid = new->gid;
75413+ ncred->egid = new->egid;
75414+ ncred->sgid = new->sgid;
75415+ ncred->fsgid = new->fsgid;
75416+ // groups
75417+ if (set_groups(ncred, new->group_info) < 0) {
75418+ abort_creds(ncred);
75419+ goto die;
75420+ }
75421+ // caps
75422+ ncred->securebits = new->securebits;
75423+ ncred->cap_inheritable = new->cap_inheritable;
75424+ ncred->cap_permitted = new->cap_permitted;
75425+ ncred->cap_effective = new->cap_effective;
75426+ ncred->cap_bset = new->cap_bset;
75427+
75428+ if (set_user(ncred)) {
75429+ abort_creds(ncred);
75430+ goto die;
75431+ }
75432+
75433+ // from doing get_cred on it when queueing this
75434+ put_cred(new);
75435+
75436+ __commit_creds(ncred);
75437+ return;
75438+die:
75439+ // from doing get_cred on it when queueing this
75440+ put_cred(new);
75441+ do_group_exit(SIGKILL);
75442+}
75443+#endif
75444+
75445+int commit_creds(struct cred *new)
75446+{
75447+#ifdef CONFIG_GRKERNSEC_SETXID
75448+ int ret;
75449+ int schedule_it = 0;
75450+ struct task_struct *t;
75451+
75452+ /* we won't get called with tasklist_lock held for writing
75453+ and interrupts disabled as the cred struct in that case is
75454+ init_cred
75455+ */
75456+ if (grsec_enable_setxid && !current_is_single_threaded() &&
75457+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
75458+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
75459+ schedule_it = 1;
75460+ }
75461+ ret = __commit_creds(new);
75462+ if (schedule_it) {
75463+ rcu_read_lock();
75464+ read_lock(&tasklist_lock);
75465+ for (t = next_thread(current); t != current;
75466+ t = next_thread(t)) {
75467+ if (t->delayed_cred == NULL) {
75468+ t->delayed_cred = get_cred(new);
75469+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
75470+ set_tsk_need_resched(t);
75471+ }
75472+ }
75473+ read_unlock(&tasklist_lock);
75474+ rcu_read_unlock();
75475+ }
75476+ return ret;
75477+#else
75478+ return __commit_creds(new);
75479+#endif
75480+}
75481+
75482 EXPORT_SYMBOL(commit_creds);
75483
75484 /**
75485diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
75486index 9a61738..c5c8f3a 100644
75487--- a/kernel/debug/debug_core.c
75488+++ b/kernel/debug/debug_core.c
75489@@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
75490 */
75491 static atomic_t masters_in_kgdb;
75492 static atomic_t slaves_in_kgdb;
75493-static atomic_t kgdb_break_tasklet_var;
75494+static atomic_unchecked_t kgdb_break_tasklet_var;
75495 atomic_t kgdb_setting_breakpoint;
75496
75497 struct task_struct *kgdb_usethread;
75498@@ -132,7 +132,7 @@ int kgdb_single_step;
75499 static pid_t kgdb_sstep_pid;
75500
75501 /* to keep track of the CPU which is doing the single stepping*/
75502-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
75503+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
75504
75505 /*
75506 * If you are debugging a problem where roundup (the collection of
75507@@ -540,7 +540,7 @@ return_normal:
75508 * kernel will only try for the value of sstep_tries before
75509 * giving up and continuing on.
75510 */
75511- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
75512+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
75513 (kgdb_info[cpu].task &&
75514 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
75515 atomic_set(&kgdb_active, -1);
75516@@ -634,8 +634,8 @@ cpu_master_loop:
75517 }
75518
75519 kgdb_restore:
75520- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
75521- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
75522+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
75523+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
75524 if (kgdb_info[sstep_cpu].task)
75525 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
75526 else
75527@@ -887,18 +887,18 @@ static void kgdb_unregister_callbacks(void)
75528 static void kgdb_tasklet_bpt(unsigned long ing)
75529 {
75530 kgdb_breakpoint();
75531- atomic_set(&kgdb_break_tasklet_var, 0);
75532+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
75533 }
75534
75535 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
75536
75537 void kgdb_schedule_breakpoint(void)
75538 {
75539- if (atomic_read(&kgdb_break_tasklet_var) ||
75540+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
75541 atomic_read(&kgdb_active) != -1 ||
75542 atomic_read(&kgdb_setting_breakpoint))
75543 return;
75544- atomic_inc(&kgdb_break_tasklet_var);
75545+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
75546 tasklet_schedule(&kgdb_tasklet_breakpoint);
75547 }
75548 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
75549diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
75550index 8875254..7cf4928 100644
75551--- a/kernel/debug/kdb/kdb_main.c
75552+++ b/kernel/debug/kdb/kdb_main.c
75553@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
75554 continue;
75555
75556 kdb_printf("%-20s%8u 0x%p ", mod->name,
75557- mod->core_size, (void *)mod);
75558+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
75559 #ifdef CONFIG_MODULE_UNLOAD
75560 kdb_printf("%4ld ", module_refcount(mod));
75561 #endif
75562@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
75563 kdb_printf(" (Loading)");
75564 else
75565 kdb_printf(" (Live)");
75566- kdb_printf(" 0x%p", mod->module_core);
75567+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
75568
75569 #ifdef CONFIG_MODULE_UNLOAD
75570 {
75571diff --git a/kernel/events/core.c b/kernel/events/core.c
75572index 7b6646a..3cb1135 100644
75573--- a/kernel/events/core.c
75574+++ b/kernel/events/core.c
75575@@ -182,7 +182,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
75576 return 0;
75577 }
75578
75579-static atomic64_t perf_event_id;
75580+static atomic64_unchecked_t perf_event_id;
75581
75582 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
75583 enum event_type_t event_type);
75584@@ -2677,7 +2677,7 @@ static void __perf_event_read(void *info)
75585
75586 static inline u64 perf_event_count(struct perf_event *event)
75587 {
75588- return local64_read(&event->count) + atomic64_read(&event->child_count);
75589+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
75590 }
75591
75592 static u64 perf_event_read(struct perf_event *event)
75593@@ -3007,9 +3007,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
75594 mutex_lock(&event->child_mutex);
75595 total += perf_event_read(event);
75596 *enabled += event->total_time_enabled +
75597- atomic64_read(&event->child_total_time_enabled);
75598+ atomic64_read_unchecked(&event->child_total_time_enabled);
75599 *running += event->total_time_running +
75600- atomic64_read(&event->child_total_time_running);
75601+ atomic64_read_unchecked(&event->child_total_time_running);
75602
75603 list_for_each_entry(child, &event->child_list, child_list) {
75604 total += perf_event_read(child);
75605@@ -3412,10 +3412,10 @@ void perf_event_update_userpage(struct perf_event *event)
75606 userpg->offset -= local64_read(&event->hw.prev_count);
75607
75608 userpg->time_enabled = enabled +
75609- atomic64_read(&event->child_total_time_enabled);
75610+ atomic64_read_unchecked(&event->child_total_time_enabled);
75611
75612 userpg->time_running = running +
75613- atomic64_read(&event->child_total_time_running);
75614+ atomic64_read_unchecked(&event->child_total_time_running);
75615
75616 arch_perf_update_userpage(userpg, now);
75617
75618@@ -3974,11 +3974,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
75619 values[n++] = perf_event_count(event);
75620 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
75621 values[n++] = enabled +
75622- atomic64_read(&event->child_total_time_enabled);
75623+ atomic64_read_unchecked(&event->child_total_time_enabled);
75624 }
75625 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
75626 values[n++] = running +
75627- atomic64_read(&event->child_total_time_running);
75628+ atomic64_read_unchecked(&event->child_total_time_running);
75629 }
75630 if (read_format & PERF_FORMAT_ID)
75631 values[n++] = primary_event_id(event);
75632@@ -4721,12 +4721,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
75633 * need to add enough zero bytes after the string to handle
75634 * the 64bit alignment we do later.
75635 */
75636- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
75637+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
75638 if (!buf) {
75639 name = strncpy(tmp, "//enomem", sizeof(tmp));
75640 goto got_name;
75641 }
75642- name = d_path(&file->f_path, buf, PATH_MAX);
75643+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
75644 if (IS_ERR(name)) {
75645 name = strncpy(tmp, "//toolong", sizeof(tmp));
75646 goto got_name;
75647@@ -6165,7 +6165,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
75648 event->parent = parent_event;
75649
75650 event->ns = get_pid_ns(task_active_pid_ns(current));
75651- event->id = atomic64_inc_return(&perf_event_id);
75652+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
75653
75654 event->state = PERF_EVENT_STATE_INACTIVE;
75655
75656@@ -6790,10 +6790,10 @@ static void sync_child_event(struct perf_event *child_event,
75657 /*
75658 * Add back the child's count to the parent's count:
75659 */
75660- atomic64_add(child_val, &parent_event->child_count);
75661- atomic64_add(child_event->total_time_enabled,
75662+ atomic64_add_unchecked(child_val, &parent_event->child_count);
75663+ atomic64_add_unchecked(child_event->total_time_enabled,
75664 &parent_event->child_total_time_enabled);
75665- atomic64_add(child_event->total_time_running,
75666+ atomic64_add_unchecked(child_event->total_time_running,
75667 &parent_event->child_total_time_running);
75668
75669 /*
75670diff --git a/kernel/exit.c b/kernel/exit.c
75671index b4df219..f13c02d 100644
75672--- a/kernel/exit.c
75673+++ b/kernel/exit.c
75674@@ -170,6 +170,10 @@ void release_task(struct task_struct * p)
75675 struct task_struct *leader;
75676 int zap_leader;
75677 repeat:
75678+#ifdef CONFIG_NET
75679+ gr_del_task_from_ip_table(p);
75680+#endif
75681+
75682 /* don't need to get the RCU readlock here - the process is dead and
75683 * can't be modifying its own credentials. But shut RCU-lockdep up */
75684 rcu_read_lock();
75685@@ -338,7 +342,7 @@ int allow_signal(int sig)
75686 * know it'll be handled, so that they don't get converted to
75687 * SIGKILL or just silently dropped.
75688 */
75689- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
75690+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
75691 recalc_sigpending();
75692 spin_unlock_irq(&current->sighand->siglock);
75693 return 0;
75694@@ -708,6 +712,8 @@ void do_exit(long code)
75695 struct task_struct *tsk = current;
75696 int group_dead;
75697
75698+ set_fs(USER_DS);
75699+
75700 profile_task_exit(tsk);
75701
75702 WARN_ON(blk_needs_flush_plug(tsk));
75703@@ -724,7 +730,6 @@ void do_exit(long code)
75704 * mm_release()->clear_child_tid() from writing to a user-controlled
75705 * kernel address.
75706 */
75707- set_fs(USER_DS);
75708
75709 ptrace_event(PTRACE_EVENT_EXIT, code);
75710
75711@@ -783,6 +788,9 @@ void do_exit(long code)
75712 tsk->exit_code = code;
75713 taskstats_exit(tsk, group_dead);
75714
75715+ gr_acl_handle_psacct(tsk, code);
75716+ gr_acl_handle_exit();
75717+
75718 exit_mm(tsk);
75719
75720 if (group_dead)
75721@@ -903,7 +911,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
75722 * Take down every thread in the group. This is called by fatal signals
75723 * as well as by sys_exit_group (below).
75724 */
75725-void
75726+__noreturn void
75727 do_group_exit(int exit_code)
75728 {
75729 struct signal_struct *sig = current->signal;
75730diff --git a/kernel/fork.c b/kernel/fork.c
75731index 5630e52..0cee608 100644
75732--- a/kernel/fork.c
75733+++ b/kernel/fork.c
75734@@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
75735 *stackend = STACK_END_MAGIC; /* for overflow detection */
75736
75737 #ifdef CONFIG_CC_STACKPROTECTOR
75738- tsk->stack_canary = get_random_int();
75739+ tsk->stack_canary = pax_get_random_long();
75740 #endif
75741
75742 /*
75743@@ -344,13 +344,81 @@ free_tsk:
75744 }
75745
75746 #ifdef CONFIG_MMU
75747+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
75748+{
75749+ struct vm_area_struct *tmp;
75750+ unsigned long charge;
75751+ struct mempolicy *pol;
75752+ struct file *file;
75753+
75754+ charge = 0;
75755+ if (mpnt->vm_flags & VM_ACCOUNT) {
75756+ unsigned long len = vma_pages(mpnt);
75757+
75758+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
75759+ goto fail_nomem;
75760+ charge = len;
75761+ }
75762+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
75763+ if (!tmp)
75764+ goto fail_nomem;
75765+ *tmp = *mpnt;
75766+ tmp->vm_mm = mm;
75767+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
75768+ pol = mpol_dup(vma_policy(mpnt));
75769+ if (IS_ERR(pol))
75770+ goto fail_nomem_policy;
75771+ vma_set_policy(tmp, pol);
75772+ if (anon_vma_fork(tmp, mpnt))
75773+ goto fail_nomem_anon_vma_fork;
75774+ tmp->vm_flags &= ~VM_LOCKED;
75775+ tmp->vm_next = tmp->vm_prev = NULL;
75776+ tmp->vm_mirror = NULL;
75777+ file = tmp->vm_file;
75778+ if (file) {
75779+ struct inode *inode = file->f_path.dentry->d_inode;
75780+ struct address_space *mapping = file->f_mapping;
75781+
75782+ get_file(file);
75783+ if (tmp->vm_flags & VM_DENYWRITE)
75784+ atomic_dec(&inode->i_writecount);
75785+ mutex_lock(&mapping->i_mmap_mutex);
75786+ if (tmp->vm_flags & VM_SHARED)
75787+ mapping->i_mmap_writable++;
75788+ flush_dcache_mmap_lock(mapping);
75789+ /* insert tmp into the share list, just after mpnt */
75790+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
75791+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
75792+ else
75793+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
75794+ flush_dcache_mmap_unlock(mapping);
75795+ mutex_unlock(&mapping->i_mmap_mutex);
75796+ }
75797+
75798+ /*
75799+ * Clear hugetlb-related page reserves for children. This only
75800+ * affects MAP_PRIVATE mappings. Faults generated by the child
75801+ * are not guaranteed to succeed, even if read-only
75802+ */
75803+ if (is_vm_hugetlb_page(tmp))
75804+ reset_vma_resv_huge_pages(tmp);
75805+
75806+ return tmp;
75807+
75808+fail_nomem_anon_vma_fork:
75809+ mpol_put(pol);
75810+fail_nomem_policy:
75811+ kmem_cache_free(vm_area_cachep, tmp);
75812+fail_nomem:
75813+ vm_unacct_memory(charge);
75814+ return NULL;
75815+}
75816+
75817 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75818 {
75819 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
75820 struct rb_node **rb_link, *rb_parent;
75821 int retval;
75822- unsigned long charge;
75823- struct mempolicy *pol;
75824
75825 uprobe_start_dup_mmap();
75826 down_write(&oldmm->mmap_sem);
75827@@ -364,8 +432,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75828 mm->locked_vm = 0;
75829 mm->mmap = NULL;
75830 mm->mmap_cache = NULL;
75831- mm->free_area_cache = oldmm->mmap_base;
75832- mm->cached_hole_size = ~0UL;
75833+ mm->free_area_cache = oldmm->free_area_cache;
75834+ mm->cached_hole_size = oldmm->cached_hole_size;
75835 mm->map_count = 0;
75836 cpumask_clear(mm_cpumask(mm));
75837 mm->mm_rb = RB_ROOT;
75838@@ -381,57 +449,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75839
75840 prev = NULL;
75841 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
75842- struct file *file;
75843-
75844 if (mpnt->vm_flags & VM_DONTCOPY) {
75845 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
75846 -vma_pages(mpnt));
75847 continue;
75848 }
75849- charge = 0;
75850- if (mpnt->vm_flags & VM_ACCOUNT) {
75851- unsigned long len = vma_pages(mpnt);
75852-
75853- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
75854- goto fail_nomem;
75855- charge = len;
75856- }
75857- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
75858- if (!tmp)
75859- goto fail_nomem;
75860- *tmp = *mpnt;
75861- INIT_LIST_HEAD(&tmp->anon_vma_chain);
75862- pol = mpol_dup(vma_policy(mpnt));
75863- retval = PTR_ERR(pol);
75864- if (IS_ERR(pol))
75865- goto fail_nomem_policy;
75866- vma_set_policy(tmp, pol);
75867- tmp->vm_mm = mm;
75868- if (anon_vma_fork(tmp, mpnt))
75869- goto fail_nomem_anon_vma_fork;
75870- tmp->vm_flags &= ~VM_LOCKED;
75871- tmp->vm_next = tmp->vm_prev = NULL;
75872- file = tmp->vm_file;
75873- if (file) {
75874- struct inode *inode = file->f_path.dentry->d_inode;
75875- struct address_space *mapping = file->f_mapping;
75876-
75877- get_file(file);
75878- if (tmp->vm_flags & VM_DENYWRITE)
75879- atomic_dec(&inode->i_writecount);
75880- mutex_lock(&mapping->i_mmap_mutex);
75881- if (tmp->vm_flags & VM_SHARED)
75882- mapping->i_mmap_writable++;
75883- flush_dcache_mmap_lock(mapping);
75884- /* insert tmp into the share list, just after mpnt */
75885- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
75886- vma_nonlinear_insert(tmp,
75887- &mapping->i_mmap_nonlinear);
75888- else
75889- vma_interval_tree_insert_after(tmp, mpnt,
75890- &mapping->i_mmap);
75891- flush_dcache_mmap_unlock(mapping);
75892- mutex_unlock(&mapping->i_mmap_mutex);
75893+ tmp = dup_vma(mm, oldmm, mpnt);
75894+ if (!tmp) {
75895+ retval = -ENOMEM;
75896+ goto out;
75897 }
75898
75899 /*
75900@@ -463,6 +489,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75901 if (retval)
75902 goto out;
75903 }
75904+
75905+#ifdef CONFIG_PAX_SEGMEXEC
75906+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
75907+ struct vm_area_struct *mpnt_m;
75908+
75909+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
75910+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
75911+
75912+ if (!mpnt->vm_mirror)
75913+ continue;
75914+
75915+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
75916+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
75917+ mpnt->vm_mirror = mpnt_m;
75918+ } else {
75919+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
75920+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
75921+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
75922+ mpnt->vm_mirror->vm_mirror = mpnt;
75923+ }
75924+ }
75925+ BUG_ON(mpnt_m);
75926+ }
75927+#endif
75928+
75929 /* a new mm has just been created */
75930 arch_dup_mmap(oldmm, mm);
75931 retval = 0;
75932@@ -472,14 +523,6 @@ out:
75933 up_write(&oldmm->mmap_sem);
75934 uprobe_end_dup_mmap();
75935 return retval;
75936-fail_nomem_anon_vma_fork:
75937- mpol_put(pol);
75938-fail_nomem_policy:
75939- kmem_cache_free(vm_area_cachep, tmp);
75940-fail_nomem:
75941- retval = -ENOMEM;
75942- vm_unacct_memory(charge);
75943- goto out;
75944 }
75945
75946 static inline int mm_alloc_pgd(struct mm_struct *mm)
75947@@ -694,8 +737,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
75948 return ERR_PTR(err);
75949
75950 mm = get_task_mm(task);
75951- if (mm && mm != current->mm &&
75952- !ptrace_may_access(task, mode)) {
75953+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
75954+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
75955 mmput(mm);
75956 mm = ERR_PTR(-EACCES);
75957 }
75958@@ -917,13 +960,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
75959 spin_unlock(&fs->lock);
75960 return -EAGAIN;
75961 }
75962- fs->users++;
75963+ atomic_inc(&fs->users);
75964 spin_unlock(&fs->lock);
75965 return 0;
75966 }
75967 tsk->fs = copy_fs_struct(fs);
75968 if (!tsk->fs)
75969 return -ENOMEM;
75970+ /* Carry through gr_chroot_dentry and is_chrooted instead
75971+ of recomputing it here. Already copied when the task struct
75972+ is duplicated. This allows pivot_root to not be treated as
75973+ a chroot
75974+ */
75975+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
75976+
75977 return 0;
75978 }
75979
75980@@ -1196,6 +1246,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
75981 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
75982 #endif
75983 retval = -EAGAIN;
75984+
75985+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
75986+
75987 if (atomic_read(&p->real_cred->user->processes) >=
75988 task_rlimit(p, RLIMIT_NPROC)) {
75989 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
75990@@ -1435,6 +1488,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
75991 goto bad_fork_free_pid;
75992 }
75993
75994+ /* synchronizes with gr_set_acls()
75995+ we need to call this past the point of no return for fork()
75996+ */
75997+ gr_copy_label(p);
75998+
75999 if (clone_flags & CLONE_THREAD) {
76000 current->signal->nr_threads++;
76001 atomic_inc(&current->signal->live);
76002@@ -1518,6 +1576,8 @@ bad_fork_cleanup_count:
76003 bad_fork_free:
76004 free_task(p);
76005 fork_out:
76006+ gr_log_forkfail(retval);
76007+
76008 return ERR_PTR(retval);
76009 }
76010
76011@@ -1568,6 +1628,23 @@ long do_fork(unsigned long clone_flags,
76012 return -EINVAL;
76013 }
76014
76015+#ifdef CONFIG_GRKERNSEC
76016+ if (clone_flags & CLONE_NEWUSER) {
76017+ /*
76018+ * This doesn't really inspire confidence:
76019+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
76020+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
76021+ * Increases kernel attack surface in areas developers
76022+ * previously cared little about ("low importance due
76023+ * to requiring "root" capability")
76024+ * To be removed when this code receives *proper* review
76025+ */
76026+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
76027+ !capable(CAP_SETGID))
76028+ return -EPERM;
76029+ }
76030+#endif
76031+
76032 /*
76033 * Determine whether and which event to report to ptracer. When
76034 * called from kernel_thread or CLONE_UNTRACED is explicitly
76035@@ -1602,6 +1679,8 @@ long do_fork(unsigned long clone_flags,
76036 if (clone_flags & CLONE_PARENT_SETTID)
76037 put_user(nr, parent_tidptr);
76038
76039+ gr_handle_brute_check();
76040+
76041 if (clone_flags & CLONE_VFORK) {
76042 p->vfork_done = &vfork;
76043 init_completion(&vfork);
76044@@ -1755,7 +1834,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
76045 return 0;
76046
76047 /* don't need lock here; in the worst case we'll do useless copy */
76048- if (fs->users == 1)
76049+ if (atomic_read(&fs->users) == 1)
76050 return 0;
76051
76052 *new_fsp = copy_fs_struct(fs);
76053@@ -1869,7 +1948,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
76054 fs = current->fs;
76055 spin_lock(&fs->lock);
76056 current->fs = new_fs;
76057- if (--fs->users)
76058+ gr_set_chroot_entries(current, &current->fs->root);
76059+ if (atomic_dec_return(&fs->users))
76060 new_fs = NULL;
76061 else
76062 new_fs = fs;
76063diff --git a/kernel/futex.c b/kernel/futex.c
76064index 8879430..31696f1 100644
76065--- a/kernel/futex.c
76066+++ b/kernel/futex.c
76067@@ -54,6 +54,7 @@
76068 #include <linux/mount.h>
76069 #include <linux/pagemap.h>
76070 #include <linux/syscalls.h>
76071+#include <linux/ptrace.h>
76072 #include <linux/signal.h>
76073 #include <linux/export.h>
76074 #include <linux/magic.h>
76075@@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
76076 struct page *page, *page_head;
76077 int err, ro = 0;
76078
76079+#ifdef CONFIG_PAX_SEGMEXEC
76080+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
76081+ return -EFAULT;
76082+#endif
76083+
76084 /*
76085 * The futex address must be "naturally" aligned.
76086 */
76087@@ -2731,6 +2737,7 @@ static int __init futex_init(void)
76088 {
76089 u32 curval;
76090 int i;
76091+ mm_segment_t oldfs;
76092
76093 /*
76094 * This will fail and we want it. Some arch implementations do
76095@@ -2742,8 +2749,11 @@ static int __init futex_init(void)
76096 * implementation, the non-functional ones will return
76097 * -ENOSYS.
76098 */
76099+ oldfs = get_fs();
76100+ set_fs(USER_DS);
76101 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
76102 futex_cmpxchg_enabled = 1;
76103+ set_fs(oldfs);
76104
76105 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
76106 plist_head_init(&futex_queues[i].chain);
76107diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
76108index a9642d5..51eb98c 100644
76109--- a/kernel/futex_compat.c
76110+++ b/kernel/futex_compat.c
76111@@ -31,7 +31,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
76112 return 0;
76113 }
76114
76115-static void __user *futex_uaddr(struct robust_list __user *entry,
76116+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
76117 compat_long_t futex_offset)
76118 {
76119 compat_uptr_t base = ptr_to_compat(entry);
76120diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
76121index 9b22d03..6295b62 100644
76122--- a/kernel/gcov/base.c
76123+++ b/kernel/gcov/base.c
76124@@ -102,11 +102,6 @@ void gcov_enable_events(void)
76125 }
76126
76127 #ifdef CONFIG_MODULES
76128-static inline int within(void *addr, void *start, unsigned long size)
76129-{
76130- return ((addr >= start) && (addr < start + size));
76131-}
76132-
76133 /* Update list and generate events when modules are unloaded. */
76134 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
76135 void *data)
76136@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
76137 prev = NULL;
76138 /* Remove entries located in module from linked list. */
76139 for (info = gcov_info_head; info; info = info->next) {
76140- if (within(info, mod->module_core, mod->core_size)) {
76141+ if (within_module_core_rw((unsigned long)info, mod)) {
76142 if (prev)
76143 prev->next = info->next;
76144 else
76145diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
76146index cdd5607..c3fc919 100644
76147--- a/kernel/hrtimer.c
76148+++ b/kernel/hrtimer.c
76149@@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
76150 local_irq_restore(flags);
76151 }
76152
76153-static void run_hrtimer_softirq(struct softirq_action *h)
76154+static void run_hrtimer_softirq(void)
76155 {
76156 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
76157
76158@@ -1751,7 +1751,7 @@ static int __cpuinit hrtimer_cpu_notify(struct notifier_block *self,
76159 return NOTIFY_OK;
76160 }
76161
76162-static struct notifier_block __cpuinitdata hrtimers_nb = {
76163+static struct notifier_block hrtimers_nb = {
76164 .notifier_call = hrtimer_cpu_notify,
76165 };
76166
76167diff --git a/kernel/jump_label.c b/kernel/jump_label.c
76168index 60f48fa..7f3a770 100644
76169--- a/kernel/jump_label.c
76170+++ b/kernel/jump_label.c
76171@@ -13,6 +13,7 @@
76172 #include <linux/sort.h>
76173 #include <linux/err.h>
76174 #include <linux/static_key.h>
76175+#include <linux/mm.h>
76176
76177 #ifdef HAVE_JUMP_LABEL
76178
76179@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
76180
76181 size = (((unsigned long)stop - (unsigned long)start)
76182 / sizeof(struct jump_entry));
76183+ pax_open_kernel();
76184 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
76185+ pax_close_kernel();
76186 }
76187
76188 static void jump_label_update(struct static_key *key, int enable);
76189@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
76190 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
76191 struct jump_entry *iter;
76192
76193+ pax_open_kernel();
76194 for (iter = iter_start; iter < iter_stop; iter++) {
76195 if (within_module_init(iter->code, mod))
76196 iter->code = 0;
76197 }
76198+ pax_close_kernel();
76199 }
76200
76201 static int
76202diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
76203index 2169fee..706ccca 100644
76204--- a/kernel/kallsyms.c
76205+++ b/kernel/kallsyms.c
76206@@ -11,6 +11,9 @@
76207 * Changed the compression method from stem compression to "table lookup"
76208 * compression (see scripts/kallsyms.c for a more complete description)
76209 */
76210+#ifdef CONFIG_GRKERNSEC_HIDESYM
76211+#define __INCLUDED_BY_HIDESYM 1
76212+#endif
76213 #include <linux/kallsyms.h>
76214 #include <linux/module.h>
76215 #include <linux/init.h>
76216@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
76217
76218 static inline int is_kernel_inittext(unsigned long addr)
76219 {
76220+ if (system_state != SYSTEM_BOOTING)
76221+ return 0;
76222+
76223 if (addr >= (unsigned long)_sinittext
76224 && addr <= (unsigned long)_einittext)
76225 return 1;
76226 return 0;
76227 }
76228
76229+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76230+#ifdef CONFIG_MODULES
76231+static inline int is_module_text(unsigned long addr)
76232+{
76233+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
76234+ return 1;
76235+
76236+ addr = ktla_ktva(addr);
76237+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
76238+}
76239+#else
76240+static inline int is_module_text(unsigned long addr)
76241+{
76242+ return 0;
76243+}
76244+#endif
76245+#endif
76246+
76247 static inline int is_kernel_text(unsigned long addr)
76248 {
76249 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
76250@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
76251
76252 static inline int is_kernel(unsigned long addr)
76253 {
76254+
76255+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76256+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
76257+ return 1;
76258+
76259+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
76260+#else
76261 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
76262+#endif
76263+
76264 return 1;
76265 return in_gate_area_no_mm(addr);
76266 }
76267
76268 static int is_ksym_addr(unsigned long addr)
76269 {
76270+
76271+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76272+ if (is_module_text(addr))
76273+ return 0;
76274+#endif
76275+
76276 if (all_var)
76277 return is_kernel(addr);
76278
76279@@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
76280
76281 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
76282 {
76283- iter->name[0] = '\0';
76284 iter->nameoff = get_symbol_offset(new_pos);
76285 iter->pos = new_pos;
76286 }
76287@@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
76288 {
76289 struct kallsym_iter *iter = m->private;
76290
76291+#ifdef CONFIG_GRKERNSEC_HIDESYM
76292+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
76293+ return 0;
76294+#endif
76295+
76296 /* Some debugging symbols have no name. Ignore them. */
76297 if (!iter->name[0])
76298 return 0;
76299@@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
76300 */
76301 type = iter->exported ? toupper(iter->type) :
76302 tolower(iter->type);
76303+
76304 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
76305 type, iter->name, iter->module_name);
76306 } else
76307@@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
76308 struct kallsym_iter *iter;
76309 int ret;
76310
76311- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
76312+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
76313 if (!iter)
76314 return -ENOMEM;
76315 reset_iter(iter, 0);
76316diff --git a/kernel/kcmp.c b/kernel/kcmp.c
76317index e30ac0f..3528cac 100644
76318--- a/kernel/kcmp.c
76319+++ b/kernel/kcmp.c
76320@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
76321 struct task_struct *task1, *task2;
76322 int ret;
76323
76324+#ifdef CONFIG_GRKERNSEC
76325+ return -ENOSYS;
76326+#endif
76327+
76328 rcu_read_lock();
76329
76330 /*
76331diff --git a/kernel/kexec.c b/kernel/kexec.c
76332index 5e4bd78..00c5b91 100644
76333--- a/kernel/kexec.c
76334+++ b/kernel/kexec.c
76335@@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
76336 unsigned long flags)
76337 {
76338 struct compat_kexec_segment in;
76339- struct kexec_segment out, __user *ksegments;
76340+ struct kexec_segment out;
76341+ struct kexec_segment __user *ksegments;
76342 unsigned long i, result;
76343
76344 /* Don't allow clients that don't understand the native
76345diff --git a/kernel/kmod.c b/kernel/kmod.c
76346index 0023a87..9c0c068 100644
76347--- a/kernel/kmod.c
76348+++ b/kernel/kmod.c
76349@@ -74,7 +74,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
76350 kfree(info->argv);
76351 }
76352
76353-static int call_modprobe(char *module_name, int wait)
76354+static int call_modprobe(char *module_name, char *module_param, int wait)
76355 {
76356 static char *envp[] = {
76357 "HOME=/",
76358@@ -83,7 +83,7 @@ static int call_modprobe(char *module_name, int wait)
76359 NULL
76360 };
76361
76362- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
76363+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
76364 if (!argv)
76365 goto out;
76366
76367@@ -95,7 +95,8 @@ static int call_modprobe(char *module_name, int wait)
76368 argv[1] = "-q";
76369 argv[2] = "--";
76370 argv[3] = module_name; /* check free_modprobe_argv() */
76371- argv[4] = NULL;
76372+ argv[4] = module_param;
76373+ argv[5] = NULL;
76374
76375 return call_usermodehelper_fns(modprobe_path, argv, envp,
76376 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
76377@@ -120,9 +121,8 @@ out:
76378 * If module auto-loading support is disabled then this function
76379 * becomes a no-operation.
76380 */
76381-int __request_module(bool wait, const char *fmt, ...)
76382+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
76383 {
76384- va_list args;
76385 char module_name[MODULE_NAME_LEN];
76386 unsigned int max_modprobes;
76387 int ret;
76388@@ -130,9 +130,7 @@ int __request_module(bool wait, const char *fmt, ...)
76389 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
76390 static int kmod_loop_msg;
76391
76392- va_start(args, fmt);
76393- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
76394- va_end(args);
76395+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
76396 if (ret >= MODULE_NAME_LEN)
76397 return -ENAMETOOLONG;
76398
76399@@ -140,6 +138,20 @@ int __request_module(bool wait, const char *fmt, ...)
76400 if (ret)
76401 return ret;
76402
76403+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76404+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
76405+ /* hack to workaround consolekit/udisks stupidity */
76406+ read_lock(&tasklist_lock);
76407+ if (!strcmp(current->comm, "mount") &&
76408+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
76409+ read_unlock(&tasklist_lock);
76410+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
76411+ return -EPERM;
76412+ }
76413+ read_unlock(&tasklist_lock);
76414+ }
76415+#endif
76416+
76417 /* If modprobe needs a service that is in a module, we get a recursive
76418 * loop. Limit the number of running kmod threads to max_threads/2 or
76419 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
76420@@ -168,11 +180,52 @@ int __request_module(bool wait, const char *fmt, ...)
76421
76422 trace_module_request(module_name, wait, _RET_IP_);
76423
76424- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
76425+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
76426
76427 atomic_dec(&kmod_concurrent);
76428 return ret;
76429 }
76430+
76431+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
76432+{
76433+ va_list args;
76434+ int ret;
76435+
76436+ va_start(args, fmt);
76437+ ret = ____request_module(wait, module_param, fmt, args);
76438+ va_end(args);
76439+
76440+ return ret;
76441+}
76442+
76443+int __request_module(bool wait, const char *fmt, ...)
76444+{
76445+ va_list args;
76446+ int ret;
76447+
76448+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76449+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
76450+ char module_param[MODULE_NAME_LEN];
76451+
76452+ memset(module_param, 0, sizeof(module_param));
76453+
76454+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
76455+
76456+ va_start(args, fmt);
76457+ ret = ____request_module(wait, module_param, fmt, args);
76458+ va_end(args);
76459+
76460+ return ret;
76461+ }
76462+#endif
76463+
76464+ va_start(args, fmt);
76465+ ret = ____request_module(wait, NULL, fmt, args);
76466+ va_end(args);
76467+
76468+ return ret;
76469+}
76470+
76471 EXPORT_SYMBOL(__request_module);
76472 #endif /* CONFIG_MODULES */
76473
76474@@ -283,7 +336,7 @@ static int wait_for_helper(void *data)
76475 *
76476 * Thus the __user pointer cast is valid here.
76477 */
76478- sys_wait4(pid, (int __user *)&ret, 0, NULL);
76479+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
76480
76481 /*
76482 * If ret is 0, either ____call_usermodehelper failed and the
76483@@ -635,7 +688,7 @@ EXPORT_SYMBOL(call_usermodehelper_fns);
76484 static int proc_cap_handler(struct ctl_table *table, int write,
76485 void __user *buffer, size_t *lenp, loff_t *ppos)
76486 {
76487- struct ctl_table t;
76488+ ctl_table_no_const t;
76489 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
76490 kernel_cap_t new_cap;
76491 int err, i;
76492diff --git a/kernel/kprobes.c b/kernel/kprobes.c
76493index 098f396..fe85ff1 100644
76494--- a/kernel/kprobes.c
76495+++ b/kernel/kprobes.c
76496@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
76497 * kernel image and loaded module images reside. This is required
76498 * so x86_64 can correctly handle the %rip-relative fixups.
76499 */
76500- kip->insns = module_alloc(PAGE_SIZE);
76501+ kip->insns = module_alloc_exec(PAGE_SIZE);
76502 if (!kip->insns) {
76503 kfree(kip);
76504 return NULL;
76505@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
76506 */
76507 if (!list_is_singular(&kip->list)) {
76508 list_del(&kip->list);
76509- module_free(NULL, kip->insns);
76510+ module_free_exec(NULL, kip->insns);
76511 kfree(kip);
76512 }
76513 return 1;
76514@@ -2063,7 +2063,7 @@ static int __init init_kprobes(void)
76515 {
76516 int i, err = 0;
76517 unsigned long offset = 0, size = 0;
76518- char *modname, namebuf[128];
76519+ char *modname, namebuf[KSYM_NAME_LEN];
76520 const char *symbol_name;
76521 void *addr;
76522 struct kprobe_blackpoint *kb;
76523@@ -2148,11 +2148,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
76524 kprobe_type = "k";
76525
76526 if (sym)
76527- seq_printf(pi, "%p %s %s+0x%x %s ",
76528+ seq_printf(pi, "%pK %s %s+0x%x %s ",
76529 p->addr, kprobe_type, sym, offset,
76530 (modname ? modname : " "));
76531 else
76532- seq_printf(pi, "%p %s %p ",
76533+ seq_printf(pi, "%pK %s %pK ",
76534 p->addr, kprobe_type, p->addr);
76535
76536 if (!pp)
76537@@ -2190,7 +2190,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
76538 const char *sym = NULL;
76539 unsigned int i = *(loff_t *) v;
76540 unsigned long offset = 0;
76541- char *modname, namebuf[128];
76542+ char *modname, namebuf[KSYM_NAME_LEN];
76543
76544 head = &kprobe_table[i];
76545 preempt_disable();
76546diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
76547index 6ada93c..dce7d5d 100644
76548--- a/kernel/ksysfs.c
76549+++ b/kernel/ksysfs.c
76550@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
76551 {
76552 if (count+1 > UEVENT_HELPER_PATH_LEN)
76553 return -ENOENT;
76554+ if (!capable(CAP_SYS_ADMIN))
76555+ return -EPERM;
76556 memcpy(uevent_helper, buf, count);
76557 uevent_helper[count] = '\0';
76558 if (count && uevent_helper[count-1] == '\n')
76559@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
76560 return count;
76561 }
76562
76563-static struct bin_attribute notes_attr = {
76564+static bin_attribute_no_const notes_attr __read_only = {
76565 .attr = {
76566 .name = "notes",
76567 .mode = S_IRUGO,
76568diff --git a/kernel/lockdep.c b/kernel/lockdep.c
76569index 7981e5b..7f2105c 100644
76570--- a/kernel/lockdep.c
76571+++ b/kernel/lockdep.c
76572@@ -590,6 +590,10 @@ static int static_obj(void *obj)
76573 end = (unsigned long) &_end,
76574 addr = (unsigned long) obj;
76575
76576+#ifdef CONFIG_PAX_KERNEXEC
76577+ start = ktla_ktva(start);
76578+#endif
76579+
76580 /*
76581 * static variable?
76582 */
76583@@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
76584 if (!static_obj(lock->key)) {
76585 debug_locks_off();
76586 printk("INFO: trying to register non-static key.\n");
76587+ printk("lock:%pS key:%pS.\n", lock, lock->key);
76588 printk("the code is fine but needs lockdep annotation.\n");
76589 printk("turning off the locking correctness validator.\n");
76590 dump_stack();
76591@@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
76592 if (!class)
76593 return 0;
76594 }
76595- atomic_inc((atomic_t *)&class->ops);
76596+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
76597 if (very_verbose(class)) {
76598 printk("\nacquire class [%p] %s", class->key, class->name);
76599 if (class->name_version > 1)
76600diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
76601index b2c71c5..7b88d63 100644
76602--- a/kernel/lockdep_proc.c
76603+++ b/kernel/lockdep_proc.c
76604@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
76605 return 0;
76606 }
76607
76608- seq_printf(m, "%p", class->key);
76609+ seq_printf(m, "%pK", class->key);
76610 #ifdef CONFIG_DEBUG_LOCKDEP
76611 seq_printf(m, " OPS:%8ld", class->ops);
76612 #endif
76613@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
76614
76615 list_for_each_entry(entry, &class->locks_after, entry) {
76616 if (entry->distance == 1) {
76617- seq_printf(m, " -> [%p] ", entry->class->key);
76618+ seq_printf(m, " -> [%pK] ", entry->class->key);
76619 print_name(m, entry->class);
76620 seq_puts(m, "\n");
76621 }
76622@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
76623 if (!class->key)
76624 continue;
76625
76626- seq_printf(m, "[%p] ", class->key);
76627+ seq_printf(m, "[%pK] ", class->key);
76628 print_name(m, class);
76629 seq_puts(m, "\n");
76630 }
76631@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
76632 if (!i)
76633 seq_line(m, '-', 40-namelen, namelen);
76634
76635- snprintf(ip, sizeof(ip), "[<%p>]",
76636+ snprintf(ip, sizeof(ip), "[<%pK>]",
76637 (void *)class->contention_point[i]);
76638 seq_printf(m, "%40s %14lu %29s %pS\n",
76639 name, stats->contention_point[i],
76640@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
76641 if (!i)
76642 seq_line(m, '-', 40-namelen, namelen);
76643
76644- snprintf(ip, sizeof(ip), "[<%p>]",
76645+ snprintf(ip, sizeof(ip), "[<%pK>]",
76646 (void *)class->contending_point[i]);
76647 seq_printf(m, "%40s %14lu %29s %pS\n",
76648 name, stats->contending_point[i],
76649diff --git a/kernel/module.c b/kernel/module.c
76650index eab0827..f488603 100644
76651--- a/kernel/module.c
76652+++ b/kernel/module.c
76653@@ -61,6 +61,7 @@
76654 #include <linux/pfn.h>
76655 #include <linux/bsearch.h>
76656 #include <linux/fips.h>
76657+#include <linux/grsecurity.h>
76658 #include <uapi/linux/module.h>
76659 #include "module-internal.h"
76660
76661@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
76662
76663 /* Bounds of module allocation, for speeding __module_address.
76664 * Protected by module_mutex. */
76665-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
76666+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
76667+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
76668
76669 int register_module_notifier(struct notifier_block * nb)
76670 {
76671@@ -322,7 +324,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
76672 return true;
76673
76674 list_for_each_entry_rcu(mod, &modules, list) {
76675- struct symsearch arr[] = {
76676+ struct symsearch modarr[] = {
76677 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
76678 NOT_GPL_ONLY, false },
76679 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
76680@@ -347,7 +349,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
76681 if (mod->state == MODULE_STATE_UNFORMED)
76682 continue;
76683
76684- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
76685+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
76686 return true;
76687 }
76688 return false;
76689@@ -484,7 +486,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
76690 static int percpu_modalloc(struct module *mod,
76691 unsigned long size, unsigned long align)
76692 {
76693- if (align > PAGE_SIZE) {
76694+ if (align-1 >= PAGE_SIZE) {
76695 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
76696 mod->name, align, PAGE_SIZE);
76697 align = PAGE_SIZE;
76698@@ -1088,7 +1090,7 @@ struct module_attribute module_uevent =
76699 static ssize_t show_coresize(struct module_attribute *mattr,
76700 struct module_kobject *mk, char *buffer)
76701 {
76702- return sprintf(buffer, "%u\n", mk->mod->core_size);
76703+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
76704 }
76705
76706 static struct module_attribute modinfo_coresize =
76707@@ -1097,7 +1099,7 @@ static struct module_attribute modinfo_coresize =
76708 static ssize_t show_initsize(struct module_attribute *mattr,
76709 struct module_kobject *mk, char *buffer)
76710 {
76711- return sprintf(buffer, "%u\n", mk->mod->init_size);
76712+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
76713 }
76714
76715 static struct module_attribute modinfo_initsize =
76716@@ -1311,7 +1313,7 @@ resolve_symbol_wait(struct module *mod,
76717 */
76718 #ifdef CONFIG_SYSFS
76719
76720-#ifdef CONFIG_KALLSYMS
76721+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
76722 static inline bool sect_empty(const Elf_Shdr *sect)
76723 {
76724 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
76725@@ -1451,7 +1453,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
76726 {
76727 unsigned int notes, loaded, i;
76728 struct module_notes_attrs *notes_attrs;
76729- struct bin_attribute *nattr;
76730+ bin_attribute_no_const *nattr;
76731
76732 /* failed to create section attributes, so can't create notes */
76733 if (!mod->sect_attrs)
76734@@ -1563,7 +1565,7 @@ static void del_usage_links(struct module *mod)
76735 static int module_add_modinfo_attrs(struct module *mod)
76736 {
76737 struct module_attribute *attr;
76738- struct module_attribute *temp_attr;
76739+ module_attribute_no_const *temp_attr;
76740 int error = 0;
76741 int i;
76742
76743@@ -1777,21 +1779,21 @@ static void set_section_ro_nx(void *base,
76744
76745 static void unset_module_core_ro_nx(struct module *mod)
76746 {
76747- set_page_attributes(mod->module_core + mod->core_text_size,
76748- mod->module_core + mod->core_size,
76749+ set_page_attributes(mod->module_core_rw,
76750+ mod->module_core_rw + mod->core_size_rw,
76751 set_memory_x);
76752- set_page_attributes(mod->module_core,
76753- mod->module_core + mod->core_ro_size,
76754+ set_page_attributes(mod->module_core_rx,
76755+ mod->module_core_rx + mod->core_size_rx,
76756 set_memory_rw);
76757 }
76758
76759 static void unset_module_init_ro_nx(struct module *mod)
76760 {
76761- set_page_attributes(mod->module_init + mod->init_text_size,
76762- mod->module_init + mod->init_size,
76763+ set_page_attributes(mod->module_init_rw,
76764+ mod->module_init_rw + mod->init_size_rw,
76765 set_memory_x);
76766- set_page_attributes(mod->module_init,
76767- mod->module_init + mod->init_ro_size,
76768+ set_page_attributes(mod->module_init_rx,
76769+ mod->module_init_rx + mod->init_size_rx,
76770 set_memory_rw);
76771 }
76772
76773@@ -1804,14 +1806,14 @@ void set_all_modules_text_rw(void)
76774 list_for_each_entry_rcu(mod, &modules, list) {
76775 if (mod->state == MODULE_STATE_UNFORMED)
76776 continue;
76777- if ((mod->module_core) && (mod->core_text_size)) {
76778- set_page_attributes(mod->module_core,
76779- mod->module_core + mod->core_text_size,
76780+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
76781+ set_page_attributes(mod->module_core_rx,
76782+ mod->module_core_rx + mod->core_size_rx,
76783 set_memory_rw);
76784 }
76785- if ((mod->module_init) && (mod->init_text_size)) {
76786- set_page_attributes(mod->module_init,
76787- mod->module_init + mod->init_text_size,
76788+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
76789+ set_page_attributes(mod->module_init_rx,
76790+ mod->module_init_rx + mod->init_size_rx,
76791 set_memory_rw);
76792 }
76793 }
76794@@ -1827,14 +1829,14 @@ void set_all_modules_text_ro(void)
76795 list_for_each_entry_rcu(mod, &modules, list) {
76796 if (mod->state == MODULE_STATE_UNFORMED)
76797 continue;
76798- if ((mod->module_core) && (mod->core_text_size)) {
76799- set_page_attributes(mod->module_core,
76800- mod->module_core + mod->core_text_size,
76801+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
76802+ set_page_attributes(mod->module_core_rx,
76803+ mod->module_core_rx + mod->core_size_rx,
76804 set_memory_ro);
76805 }
76806- if ((mod->module_init) && (mod->init_text_size)) {
76807- set_page_attributes(mod->module_init,
76808- mod->module_init + mod->init_text_size,
76809+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
76810+ set_page_attributes(mod->module_init_rx,
76811+ mod->module_init_rx + mod->init_size_rx,
76812 set_memory_ro);
76813 }
76814 }
76815@@ -1880,16 +1882,19 @@ static void free_module(struct module *mod)
76816
76817 /* This may be NULL, but that's OK */
76818 unset_module_init_ro_nx(mod);
76819- module_free(mod, mod->module_init);
76820+ module_free(mod, mod->module_init_rw);
76821+ module_free_exec(mod, mod->module_init_rx);
76822 kfree(mod->args);
76823 percpu_modfree(mod);
76824
76825 /* Free lock-classes: */
76826- lockdep_free_key_range(mod->module_core, mod->core_size);
76827+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
76828+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
76829
76830 /* Finally, free the core (containing the module structure) */
76831 unset_module_core_ro_nx(mod);
76832- module_free(mod, mod->module_core);
76833+ module_free_exec(mod, mod->module_core_rx);
76834+ module_free(mod, mod->module_core_rw);
76835
76836 #ifdef CONFIG_MPU
76837 update_protections(current->mm);
76838@@ -1959,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
76839 int ret = 0;
76840 const struct kernel_symbol *ksym;
76841
76842+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76843+ int is_fs_load = 0;
76844+ int register_filesystem_found = 0;
76845+ char *p;
76846+
76847+ p = strstr(mod->args, "grsec_modharden_fs");
76848+ if (p) {
76849+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
76850+ /* copy \0 as well */
76851+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
76852+ is_fs_load = 1;
76853+ }
76854+#endif
76855+
76856 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
76857 const char *name = info->strtab + sym[i].st_name;
76858
76859+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76860+ /* it's a real shame this will never get ripped and copied
76861+ upstream! ;(
76862+ */
76863+ if (is_fs_load && !strcmp(name, "register_filesystem"))
76864+ register_filesystem_found = 1;
76865+#endif
76866+
76867 switch (sym[i].st_shndx) {
76868 case SHN_COMMON:
76869 /* We compiled with -fno-common. These are not
76870@@ -1982,7 +2009,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
76871 ksym = resolve_symbol_wait(mod, info, name);
76872 /* Ok if resolved. */
76873 if (ksym && !IS_ERR(ksym)) {
76874+ pax_open_kernel();
76875 sym[i].st_value = ksym->value;
76876+ pax_close_kernel();
76877 break;
76878 }
76879
76880@@ -2001,11 +2030,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
76881 secbase = (unsigned long)mod_percpu(mod);
76882 else
76883 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
76884+ pax_open_kernel();
76885 sym[i].st_value += secbase;
76886+ pax_close_kernel();
76887 break;
76888 }
76889 }
76890
76891+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76892+ if (is_fs_load && !register_filesystem_found) {
76893+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
76894+ ret = -EPERM;
76895+ }
76896+#endif
76897+
76898 return ret;
76899 }
76900
76901@@ -2089,22 +2127,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
76902 || s->sh_entsize != ~0UL
76903 || strstarts(sname, ".init"))
76904 continue;
76905- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
76906+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
76907+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
76908+ else
76909+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
76910 pr_debug("\t%s\n", sname);
76911 }
76912- switch (m) {
76913- case 0: /* executable */
76914- mod->core_size = debug_align(mod->core_size);
76915- mod->core_text_size = mod->core_size;
76916- break;
76917- case 1: /* RO: text and ro-data */
76918- mod->core_size = debug_align(mod->core_size);
76919- mod->core_ro_size = mod->core_size;
76920- break;
76921- case 3: /* whole core */
76922- mod->core_size = debug_align(mod->core_size);
76923- break;
76924- }
76925 }
76926
76927 pr_debug("Init section allocation order:\n");
76928@@ -2118,23 +2146,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
76929 || s->sh_entsize != ~0UL
76930 || !strstarts(sname, ".init"))
76931 continue;
76932- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
76933- | INIT_OFFSET_MASK);
76934+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
76935+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
76936+ else
76937+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
76938+ s->sh_entsize |= INIT_OFFSET_MASK;
76939 pr_debug("\t%s\n", sname);
76940 }
76941- switch (m) {
76942- case 0: /* executable */
76943- mod->init_size = debug_align(mod->init_size);
76944- mod->init_text_size = mod->init_size;
76945- break;
76946- case 1: /* RO: text and ro-data */
76947- mod->init_size = debug_align(mod->init_size);
76948- mod->init_ro_size = mod->init_size;
76949- break;
76950- case 3: /* whole init */
76951- mod->init_size = debug_align(mod->init_size);
76952- break;
76953- }
76954 }
76955 }
76956
76957@@ -2306,7 +2324,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
76958
76959 /* Put symbol section at end of init part of module. */
76960 symsect->sh_flags |= SHF_ALLOC;
76961- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
76962+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
76963 info->index.sym) | INIT_OFFSET_MASK;
76964 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
76965
76966@@ -2323,13 +2341,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
76967 }
76968
76969 /* Append room for core symbols at end of core part. */
76970- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
76971- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
76972- mod->core_size += strtab_size;
76973+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
76974+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
76975+ mod->core_size_rx += strtab_size;
76976
76977 /* Put string table section at end of init part of module. */
76978 strsect->sh_flags |= SHF_ALLOC;
76979- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
76980+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
76981 info->index.str) | INIT_OFFSET_MASK;
76982 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
76983 }
76984@@ -2347,12 +2365,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
76985 /* Make sure we get permanent strtab: don't use info->strtab. */
76986 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
76987
76988+ pax_open_kernel();
76989+
76990 /* Set types up while we still have access to sections. */
76991 for (i = 0; i < mod->num_symtab; i++)
76992 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
76993
76994- mod->core_symtab = dst = mod->module_core + info->symoffs;
76995- mod->core_strtab = s = mod->module_core + info->stroffs;
76996+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
76997+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
76998 src = mod->symtab;
76999 for (ndst = i = 0; i < mod->num_symtab; i++) {
77000 if (i == 0 ||
77001@@ -2364,6 +2384,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
77002 }
77003 }
77004 mod->core_num_syms = ndst;
77005+
77006+ pax_close_kernel();
77007 }
77008 #else
77009 static inline void layout_symtab(struct module *mod, struct load_info *info)
77010@@ -2397,17 +2419,33 @@ void * __weak module_alloc(unsigned long size)
77011 return vmalloc_exec(size);
77012 }
77013
77014-static void *module_alloc_update_bounds(unsigned long size)
77015+static void *module_alloc_update_bounds_rw(unsigned long size)
77016 {
77017 void *ret = module_alloc(size);
77018
77019 if (ret) {
77020 mutex_lock(&module_mutex);
77021 /* Update module bounds. */
77022- if ((unsigned long)ret < module_addr_min)
77023- module_addr_min = (unsigned long)ret;
77024- if ((unsigned long)ret + size > module_addr_max)
77025- module_addr_max = (unsigned long)ret + size;
77026+ if ((unsigned long)ret < module_addr_min_rw)
77027+ module_addr_min_rw = (unsigned long)ret;
77028+ if ((unsigned long)ret + size > module_addr_max_rw)
77029+ module_addr_max_rw = (unsigned long)ret + size;
77030+ mutex_unlock(&module_mutex);
77031+ }
77032+ return ret;
77033+}
77034+
77035+static void *module_alloc_update_bounds_rx(unsigned long size)
77036+{
77037+ void *ret = module_alloc_exec(size);
77038+
77039+ if (ret) {
77040+ mutex_lock(&module_mutex);
77041+ /* Update module bounds. */
77042+ if ((unsigned long)ret < module_addr_min_rx)
77043+ module_addr_min_rx = (unsigned long)ret;
77044+ if ((unsigned long)ret + size > module_addr_max_rx)
77045+ module_addr_max_rx = (unsigned long)ret + size;
77046 mutex_unlock(&module_mutex);
77047 }
77048 return ret;
77049@@ -2683,8 +2721,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
77050 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
77051 {
77052 const char *modmagic = get_modinfo(info, "vermagic");
77053+ const char *license = get_modinfo(info, "license");
77054 int err;
77055
77056+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
77057+ if (!license || !license_is_gpl_compatible(license))
77058+ return -ENOEXEC;
77059+#endif
77060+
77061 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
77062 modmagic = NULL;
77063
77064@@ -2710,7 +2754,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
77065 }
77066
77067 /* Set up license info based on the info section */
77068- set_license(mod, get_modinfo(info, "license"));
77069+ set_license(mod, license);
77070
77071 return 0;
77072 }
77073@@ -2804,7 +2848,7 @@ static int move_module(struct module *mod, struct load_info *info)
77074 void *ptr;
77075
77076 /* Do the allocs. */
77077- ptr = module_alloc_update_bounds(mod->core_size);
77078+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
77079 /*
77080 * The pointer to this block is stored in the module structure
77081 * which is inside the block. Just mark it as not being a
77082@@ -2814,11 +2858,11 @@ static int move_module(struct module *mod, struct load_info *info)
77083 if (!ptr)
77084 return -ENOMEM;
77085
77086- memset(ptr, 0, mod->core_size);
77087- mod->module_core = ptr;
77088+ memset(ptr, 0, mod->core_size_rw);
77089+ mod->module_core_rw = ptr;
77090
77091- if (mod->init_size) {
77092- ptr = module_alloc_update_bounds(mod->init_size);
77093+ if (mod->init_size_rw) {
77094+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
77095 /*
77096 * The pointer to this block is stored in the module structure
77097 * which is inside the block. This block doesn't need to be
77098@@ -2827,13 +2871,45 @@ static int move_module(struct module *mod, struct load_info *info)
77099 */
77100 kmemleak_ignore(ptr);
77101 if (!ptr) {
77102- module_free(mod, mod->module_core);
77103+ module_free(mod, mod->module_core_rw);
77104 return -ENOMEM;
77105 }
77106- memset(ptr, 0, mod->init_size);
77107- mod->module_init = ptr;
77108+ memset(ptr, 0, mod->init_size_rw);
77109+ mod->module_init_rw = ptr;
77110 } else
77111- mod->module_init = NULL;
77112+ mod->module_init_rw = NULL;
77113+
77114+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
77115+ kmemleak_not_leak(ptr);
77116+ if (!ptr) {
77117+ if (mod->module_init_rw)
77118+ module_free(mod, mod->module_init_rw);
77119+ module_free(mod, mod->module_core_rw);
77120+ return -ENOMEM;
77121+ }
77122+
77123+ pax_open_kernel();
77124+ memset(ptr, 0, mod->core_size_rx);
77125+ pax_close_kernel();
77126+ mod->module_core_rx = ptr;
77127+
77128+ if (mod->init_size_rx) {
77129+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
77130+ kmemleak_ignore(ptr);
77131+ if (!ptr && mod->init_size_rx) {
77132+ module_free_exec(mod, mod->module_core_rx);
77133+ if (mod->module_init_rw)
77134+ module_free(mod, mod->module_init_rw);
77135+ module_free(mod, mod->module_core_rw);
77136+ return -ENOMEM;
77137+ }
77138+
77139+ pax_open_kernel();
77140+ memset(ptr, 0, mod->init_size_rx);
77141+ pax_close_kernel();
77142+ mod->module_init_rx = ptr;
77143+ } else
77144+ mod->module_init_rx = NULL;
77145
77146 /* Transfer each section which specifies SHF_ALLOC */
77147 pr_debug("final section addresses:\n");
77148@@ -2844,16 +2920,45 @@ static int move_module(struct module *mod, struct load_info *info)
77149 if (!(shdr->sh_flags & SHF_ALLOC))
77150 continue;
77151
77152- if (shdr->sh_entsize & INIT_OFFSET_MASK)
77153- dest = mod->module_init
77154- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
77155- else
77156- dest = mod->module_core + shdr->sh_entsize;
77157+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
77158+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
77159+ dest = mod->module_init_rw
77160+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
77161+ else
77162+ dest = mod->module_init_rx
77163+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
77164+ } else {
77165+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
77166+ dest = mod->module_core_rw + shdr->sh_entsize;
77167+ else
77168+ dest = mod->module_core_rx + shdr->sh_entsize;
77169+ }
77170+
77171+ if (shdr->sh_type != SHT_NOBITS) {
77172+
77173+#ifdef CONFIG_PAX_KERNEXEC
77174+#ifdef CONFIG_X86_64
77175+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
77176+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
77177+#endif
77178+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
77179+ pax_open_kernel();
77180+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
77181+ pax_close_kernel();
77182+ } else
77183+#endif
77184
77185- if (shdr->sh_type != SHT_NOBITS)
77186 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
77187+ }
77188 /* Update sh_addr to point to copy in image. */
77189- shdr->sh_addr = (unsigned long)dest;
77190+
77191+#ifdef CONFIG_PAX_KERNEXEC
77192+ if (shdr->sh_flags & SHF_EXECINSTR)
77193+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
77194+ else
77195+#endif
77196+
77197+ shdr->sh_addr = (unsigned long)dest;
77198 pr_debug("\t0x%lx %s\n",
77199 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
77200 }
77201@@ -2908,12 +3013,12 @@ static void flush_module_icache(const struct module *mod)
77202 * Do it before processing of module parameters, so the module
77203 * can provide parameter accessor functions of its own.
77204 */
77205- if (mod->module_init)
77206- flush_icache_range((unsigned long)mod->module_init,
77207- (unsigned long)mod->module_init
77208- + mod->init_size);
77209- flush_icache_range((unsigned long)mod->module_core,
77210- (unsigned long)mod->module_core + mod->core_size);
77211+ if (mod->module_init_rx)
77212+ flush_icache_range((unsigned long)mod->module_init_rx,
77213+ (unsigned long)mod->module_init_rx
77214+ + mod->init_size_rx);
77215+ flush_icache_range((unsigned long)mod->module_core_rx,
77216+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
77217
77218 set_fs(old_fs);
77219 }
77220@@ -2983,8 +3088,10 @@ out:
77221 static void module_deallocate(struct module *mod, struct load_info *info)
77222 {
77223 percpu_modfree(mod);
77224- module_free(mod, mod->module_init);
77225- module_free(mod, mod->module_core);
77226+ module_free_exec(mod, mod->module_init_rx);
77227+ module_free_exec(mod, mod->module_core_rx);
77228+ module_free(mod, mod->module_init_rw);
77229+ module_free(mod, mod->module_core_rw);
77230 }
77231
77232 int __weak module_finalize(const Elf_Ehdr *hdr,
77233@@ -2997,7 +3104,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
77234 static int post_relocation(struct module *mod, const struct load_info *info)
77235 {
77236 /* Sort exception table now relocations are done. */
77237+ pax_open_kernel();
77238 sort_extable(mod->extable, mod->extable + mod->num_exentries);
77239+ pax_close_kernel();
77240
77241 /* Copy relocated percpu area over. */
77242 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
77243@@ -3051,16 +3160,16 @@ static int do_init_module(struct module *mod)
77244 MODULE_STATE_COMING, mod);
77245
77246 /* Set RO and NX regions for core */
77247- set_section_ro_nx(mod->module_core,
77248- mod->core_text_size,
77249- mod->core_ro_size,
77250- mod->core_size);
77251+ set_section_ro_nx(mod->module_core_rx,
77252+ mod->core_size_rx,
77253+ mod->core_size_rx,
77254+ mod->core_size_rx);
77255
77256 /* Set RO and NX regions for init */
77257- set_section_ro_nx(mod->module_init,
77258- mod->init_text_size,
77259- mod->init_ro_size,
77260- mod->init_size);
77261+ set_section_ro_nx(mod->module_init_rx,
77262+ mod->init_size_rx,
77263+ mod->init_size_rx,
77264+ mod->init_size_rx);
77265
77266 do_mod_ctors(mod);
77267 /* Start the module */
77268@@ -3122,11 +3231,12 @@ static int do_init_module(struct module *mod)
77269 mod->strtab = mod->core_strtab;
77270 #endif
77271 unset_module_init_ro_nx(mod);
77272- module_free(mod, mod->module_init);
77273- mod->module_init = NULL;
77274- mod->init_size = 0;
77275- mod->init_ro_size = 0;
77276- mod->init_text_size = 0;
77277+ module_free(mod, mod->module_init_rw);
77278+ module_free_exec(mod, mod->module_init_rx);
77279+ mod->module_init_rw = NULL;
77280+ mod->module_init_rx = NULL;
77281+ mod->init_size_rw = 0;
77282+ mod->init_size_rx = 0;
77283 mutex_unlock(&module_mutex);
77284 wake_up_all(&module_wq);
77285
77286@@ -3209,9 +3319,38 @@ again:
77287 if (err)
77288 goto free_unload;
77289
77290+ /* Now copy in args */
77291+ mod->args = strndup_user(uargs, ~0UL >> 1);
77292+ if (IS_ERR(mod->args)) {
77293+ err = PTR_ERR(mod->args);
77294+ goto free_unload;
77295+ }
77296+
77297 /* Set up MODINFO_ATTR fields */
77298 setup_modinfo(mod, info);
77299
77300+#ifdef CONFIG_GRKERNSEC_MODHARDEN
77301+ {
77302+ char *p, *p2;
77303+
77304+ if (strstr(mod->args, "grsec_modharden_netdev")) {
77305+ 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);
77306+ err = -EPERM;
77307+ goto free_modinfo;
77308+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
77309+ p += sizeof("grsec_modharden_normal") - 1;
77310+ p2 = strstr(p, "_");
77311+ if (p2) {
77312+ *p2 = '\0';
77313+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
77314+ *p2 = '_';
77315+ }
77316+ err = -EPERM;
77317+ goto free_modinfo;
77318+ }
77319+ }
77320+#endif
77321+
77322 /* Fix up syms, so that st_value is a pointer to location. */
77323 err = simplify_symbols(mod, info);
77324 if (err < 0)
77325@@ -3227,13 +3366,6 @@ again:
77326
77327 flush_module_icache(mod);
77328
77329- /* Now copy in args */
77330- mod->args = strndup_user(uargs, ~0UL >> 1);
77331- if (IS_ERR(mod->args)) {
77332- err = PTR_ERR(mod->args);
77333- goto free_arch_cleanup;
77334- }
77335-
77336 dynamic_debug_setup(info->debug, info->num_debug);
77337
77338 mutex_lock(&module_mutex);
77339@@ -3278,11 +3410,10 @@ again:
77340 mutex_unlock(&module_mutex);
77341 dynamic_debug_remove(info->debug);
77342 synchronize_sched();
77343- kfree(mod->args);
77344- free_arch_cleanup:
77345 module_arch_cleanup(mod);
77346 free_modinfo:
77347 free_modinfo(mod);
77348+ kfree(mod->args);
77349 free_unload:
77350 module_unload_free(mod);
77351 unlink_mod:
77352@@ -3365,10 +3496,16 @@ static const char *get_ksymbol(struct module *mod,
77353 unsigned long nextval;
77354
77355 /* At worse, next value is at end of module */
77356- if (within_module_init(addr, mod))
77357- nextval = (unsigned long)mod->module_init+mod->init_text_size;
77358+ if (within_module_init_rx(addr, mod))
77359+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
77360+ else if (within_module_init_rw(addr, mod))
77361+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
77362+ else if (within_module_core_rx(addr, mod))
77363+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
77364+ else if (within_module_core_rw(addr, mod))
77365+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
77366 else
77367- nextval = (unsigned long)mod->module_core+mod->core_text_size;
77368+ return NULL;
77369
77370 /* Scan for closest preceding symbol, and next symbol. (ELF
77371 starts real symbols at 1). */
77372@@ -3621,7 +3758,7 @@ static int m_show(struct seq_file *m, void *p)
77373 return 0;
77374
77375 seq_printf(m, "%s %u",
77376- mod->name, mod->init_size + mod->core_size);
77377+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
77378 print_unload_info(m, mod);
77379
77380 /* Informative for users. */
77381@@ -3630,7 +3767,7 @@ static int m_show(struct seq_file *m, void *p)
77382 mod->state == MODULE_STATE_COMING ? "Loading":
77383 "Live");
77384 /* Used by oprofile and other similar tools. */
77385- seq_printf(m, " 0x%pK", mod->module_core);
77386+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
77387
77388 /* Taints info */
77389 if (mod->taints)
77390@@ -3666,7 +3803,17 @@ static const struct file_operations proc_modules_operations = {
77391
77392 static int __init proc_modules_init(void)
77393 {
77394+#ifndef CONFIG_GRKERNSEC_HIDESYM
77395+#ifdef CONFIG_GRKERNSEC_PROC_USER
77396+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
77397+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
77398+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
77399+#else
77400 proc_create("modules", 0, NULL, &proc_modules_operations);
77401+#endif
77402+#else
77403+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
77404+#endif
77405 return 0;
77406 }
77407 module_init(proc_modules_init);
77408@@ -3727,14 +3874,14 @@ struct module *__module_address(unsigned long addr)
77409 {
77410 struct module *mod;
77411
77412- if (addr < module_addr_min || addr > module_addr_max)
77413+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
77414+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
77415 return NULL;
77416
77417 list_for_each_entry_rcu(mod, &modules, list) {
77418 if (mod->state == MODULE_STATE_UNFORMED)
77419 continue;
77420- if (within_module_core(addr, mod)
77421- || within_module_init(addr, mod))
77422+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
77423 return mod;
77424 }
77425 return NULL;
77426@@ -3769,11 +3916,20 @@ bool is_module_text_address(unsigned long addr)
77427 */
77428 struct module *__module_text_address(unsigned long addr)
77429 {
77430- struct module *mod = __module_address(addr);
77431+ struct module *mod;
77432+
77433+#ifdef CONFIG_X86_32
77434+ addr = ktla_ktva(addr);
77435+#endif
77436+
77437+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
77438+ return NULL;
77439+
77440+ mod = __module_address(addr);
77441+
77442 if (mod) {
77443 /* Make sure it's within the text section. */
77444- if (!within(addr, mod->module_init, mod->init_text_size)
77445- && !within(addr, mod->module_core, mod->core_text_size))
77446+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
77447 mod = NULL;
77448 }
77449 return mod;
77450diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
77451index 7e3443f..b2a1e6b 100644
77452--- a/kernel/mutex-debug.c
77453+++ b/kernel/mutex-debug.c
77454@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
77455 }
77456
77457 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
77458- struct thread_info *ti)
77459+ struct task_struct *task)
77460 {
77461 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
77462
77463 /* Mark the current thread as blocked on the lock: */
77464- ti->task->blocked_on = waiter;
77465+ task->blocked_on = waiter;
77466 }
77467
77468 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
77469- struct thread_info *ti)
77470+ struct task_struct *task)
77471 {
77472 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
77473- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
77474- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
77475- ti->task->blocked_on = NULL;
77476+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
77477+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
77478+ task->blocked_on = NULL;
77479
77480 list_del_init(&waiter->list);
77481 waiter->task = NULL;
77482diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
77483index 0799fd3..d06ae3b 100644
77484--- a/kernel/mutex-debug.h
77485+++ b/kernel/mutex-debug.h
77486@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
77487 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
77488 extern void debug_mutex_add_waiter(struct mutex *lock,
77489 struct mutex_waiter *waiter,
77490- struct thread_info *ti);
77491+ struct task_struct *task);
77492 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
77493- struct thread_info *ti);
77494+ struct task_struct *task);
77495 extern void debug_mutex_unlock(struct mutex *lock);
77496 extern void debug_mutex_init(struct mutex *lock, const char *name,
77497 struct lock_class_key *key);
77498diff --git a/kernel/mutex.c b/kernel/mutex.c
77499index a307cc9..27fd2e9 100644
77500--- a/kernel/mutex.c
77501+++ b/kernel/mutex.c
77502@@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
77503 spin_lock_mutex(&lock->wait_lock, flags);
77504
77505 debug_mutex_lock_common(lock, &waiter);
77506- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
77507+ debug_mutex_add_waiter(lock, &waiter, task);
77508
77509 /* add waiting tasks to the end of the waitqueue (FIFO): */
77510 list_add_tail(&waiter.list, &lock->wait_list);
77511@@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
77512 * TASK_UNINTERRUPTIBLE case.)
77513 */
77514 if (unlikely(signal_pending_state(state, task))) {
77515- mutex_remove_waiter(lock, &waiter,
77516- task_thread_info(task));
77517+ mutex_remove_waiter(lock, &waiter, task);
77518 mutex_release(&lock->dep_map, 1, ip);
77519 spin_unlock_mutex(&lock->wait_lock, flags);
77520
77521@@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
77522 done:
77523 lock_acquired(&lock->dep_map, ip);
77524 /* got the lock - rejoice! */
77525- mutex_remove_waiter(lock, &waiter, current_thread_info());
77526+ mutex_remove_waiter(lock, &waiter, task);
77527 mutex_set_owner(lock);
77528
77529 /* set it to 0 if there are no waiters left: */
77530diff --git a/kernel/notifier.c b/kernel/notifier.c
77531index 2d5cc4c..d9ea600 100644
77532--- a/kernel/notifier.c
77533+++ b/kernel/notifier.c
77534@@ -5,6 +5,7 @@
77535 #include <linux/rcupdate.h>
77536 #include <linux/vmalloc.h>
77537 #include <linux/reboot.h>
77538+#include <linux/mm.h>
77539
77540 /*
77541 * Notifier list for kernel code which wants to be called
77542@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
77543 while ((*nl) != NULL) {
77544 if (n->priority > (*nl)->priority)
77545 break;
77546- nl = &((*nl)->next);
77547+ nl = (struct notifier_block **)&((*nl)->next);
77548 }
77549- n->next = *nl;
77550+ pax_open_kernel();
77551+ *(const void **)&n->next = *nl;
77552 rcu_assign_pointer(*nl, n);
77553+ pax_close_kernel();
77554 return 0;
77555 }
77556
77557@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
77558 return 0;
77559 if (n->priority > (*nl)->priority)
77560 break;
77561- nl = &((*nl)->next);
77562+ nl = (struct notifier_block **)&((*nl)->next);
77563 }
77564- n->next = *nl;
77565+ pax_open_kernel();
77566+ *(const void **)&n->next = *nl;
77567 rcu_assign_pointer(*nl, n);
77568+ pax_close_kernel();
77569 return 0;
77570 }
77571
77572@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
77573 {
77574 while ((*nl) != NULL) {
77575 if ((*nl) == n) {
77576+ pax_open_kernel();
77577 rcu_assign_pointer(*nl, n->next);
77578+ pax_close_kernel();
77579 return 0;
77580 }
77581- nl = &((*nl)->next);
77582+ nl = (struct notifier_block **)&((*nl)->next);
77583 }
77584 return -ENOENT;
77585 }
77586diff --git a/kernel/panic.c b/kernel/panic.c
77587index e1b2822..5edc1d9 100644
77588--- a/kernel/panic.c
77589+++ b/kernel/panic.c
77590@@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
77591 const char *board;
77592
77593 printk(KERN_WARNING "------------[ cut here ]------------\n");
77594- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
77595+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
77596 board = dmi_get_system_info(DMI_PRODUCT_NAME);
77597 if (board)
77598 printk(KERN_WARNING "Hardware name: %s\n", board);
77599@@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
77600 */
77601 void __stack_chk_fail(void)
77602 {
77603- panic("stack-protector: Kernel stack is corrupted in: %p\n",
77604+ dump_stack();
77605+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
77606 __builtin_return_address(0));
77607 }
77608 EXPORT_SYMBOL(__stack_chk_fail);
77609diff --git a/kernel/pid.c b/kernel/pid.c
77610index f2c6a68..4922d97 100644
77611--- a/kernel/pid.c
77612+++ b/kernel/pid.c
77613@@ -33,6 +33,7 @@
77614 #include <linux/rculist.h>
77615 #include <linux/bootmem.h>
77616 #include <linux/hash.h>
77617+#include <linux/security.h>
77618 #include <linux/pid_namespace.h>
77619 #include <linux/init_task.h>
77620 #include <linux/syscalls.h>
77621@@ -46,7 +47,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
77622
77623 int pid_max = PID_MAX_DEFAULT;
77624
77625-#define RESERVED_PIDS 300
77626+#define RESERVED_PIDS 500
77627
77628 int pid_max_min = RESERVED_PIDS + 1;
77629 int pid_max_max = PID_MAX_LIMIT;
77630@@ -441,10 +442,18 @@ EXPORT_SYMBOL(pid_task);
77631 */
77632 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
77633 {
77634+ struct task_struct *task;
77635+
77636 rcu_lockdep_assert(rcu_read_lock_held(),
77637 "find_task_by_pid_ns() needs rcu_read_lock()"
77638 " protection");
77639- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
77640+
77641+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
77642+
77643+ if (gr_pid_is_chrooted(task))
77644+ return NULL;
77645+
77646+ return task;
77647 }
77648
77649 struct task_struct *find_task_by_vpid(pid_t vnr)
77650@@ -452,6 +461,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
77651 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
77652 }
77653
77654+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
77655+{
77656+ rcu_lockdep_assert(rcu_read_lock_held(),
77657+ "find_task_by_pid_ns() needs rcu_read_lock()"
77658+ " protection");
77659+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
77660+}
77661+
77662 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
77663 {
77664 struct pid *pid;
77665diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
77666index bea15bd..789f3d0 100644
77667--- a/kernel/pid_namespace.c
77668+++ b/kernel/pid_namespace.c
77669@@ -249,7 +249,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
77670 void __user *buffer, size_t *lenp, loff_t *ppos)
77671 {
77672 struct pid_namespace *pid_ns = task_active_pid_ns(current);
77673- struct ctl_table tmp = *table;
77674+ ctl_table_no_const tmp = *table;
77675
77676 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
77677 return -EPERM;
77678diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
77679index 942ca27..111e609 100644
77680--- a/kernel/posix-cpu-timers.c
77681+++ b/kernel/posix-cpu-timers.c
77682@@ -1576,14 +1576,14 @@ struct k_clock clock_posix_cpu = {
77683
77684 static __init int init_posix_cpu_timers(void)
77685 {
77686- struct k_clock process = {
77687+ static struct k_clock process = {
77688 .clock_getres = process_cpu_clock_getres,
77689 .clock_get = process_cpu_clock_get,
77690 .timer_create = process_cpu_timer_create,
77691 .nsleep = process_cpu_nsleep,
77692 .nsleep_restart = process_cpu_nsleep_restart,
77693 };
77694- struct k_clock thread = {
77695+ static struct k_clock thread = {
77696 .clock_getres = thread_cpu_clock_getres,
77697 .clock_get = thread_cpu_clock_get,
77698 .timer_create = thread_cpu_timer_create,
77699diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
77700index e885be1..380fe76 100644
77701--- a/kernel/posix-timers.c
77702+++ b/kernel/posix-timers.c
77703@@ -43,6 +43,7 @@
77704 #include <linux/idr.h>
77705 #include <linux/posix-clock.h>
77706 #include <linux/posix-timers.h>
77707+#include <linux/grsecurity.h>
77708 #include <linux/syscalls.h>
77709 #include <linux/wait.h>
77710 #include <linux/workqueue.h>
77711@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
77712 * which we beg off on and pass to do_sys_settimeofday().
77713 */
77714
77715-static struct k_clock posix_clocks[MAX_CLOCKS];
77716+static struct k_clock *posix_clocks[MAX_CLOCKS];
77717
77718 /*
77719 * These ones are defined below.
77720@@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
77721 */
77722 static __init int init_posix_timers(void)
77723 {
77724- struct k_clock clock_realtime = {
77725+ static struct k_clock clock_realtime = {
77726 .clock_getres = hrtimer_get_res,
77727 .clock_get = posix_clock_realtime_get,
77728 .clock_set = posix_clock_realtime_set,
77729@@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
77730 .timer_get = common_timer_get,
77731 .timer_del = common_timer_del,
77732 };
77733- struct k_clock clock_monotonic = {
77734+ static struct k_clock clock_monotonic = {
77735 .clock_getres = hrtimer_get_res,
77736 .clock_get = posix_ktime_get_ts,
77737 .nsleep = common_nsleep,
77738@@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
77739 .timer_get = common_timer_get,
77740 .timer_del = common_timer_del,
77741 };
77742- struct k_clock clock_monotonic_raw = {
77743+ static struct k_clock clock_monotonic_raw = {
77744 .clock_getres = hrtimer_get_res,
77745 .clock_get = posix_get_monotonic_raw,
77746 };
77747- struct k_clock clock_realtime_coarse = {
77748+ static struct k_clock clock_realtime_coarse = {
77749 .clock_getres = posix_get_coarse_res,
77750 .clock_get = posix_get_realtime_coarse,
77751 };
77752- struct k_clock clock_monotonic_coarse = {
77753+ static struct k_clock clock_monotonic_coarse = {
77754 .clock_getres = posix_get_coarse_res,
77755 .clock_get = posix_get_monotonic_coarse,
77756 };
77757- struct k_clock clock_boottime = {
77758+ static struct k_clock clock_boottime = {
77759 .clock_getres = hrtimer_get_res,
77760 .clock_get = posix_get_boottime,
77761 .nsleep = common_nsleep,
77762@@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
77763 return;
77764 }
77765
77766- posix_clocks[clock_id] = *new_clock;
77767+ posix_clocks[clock_id] = new_clock;
77768 }
77769 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
77770
77771@@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
77772 return (id & CLOCKFD_MASK) == CLOCKFD ?
77773 &clock_posix_dynamic : &clock_posix_cpu;
77774
77775- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
77776+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
77777 return NULL;
77778- return &posix_clocks[id];
77779+ return posix_clocks[id];
77780 }
77781
77782 static int common_timer_create(struct k_itimer *new_timer)
77783@@ -966,6 +967,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
77784 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
77785 return -EFAULT;
77786
77787+ /* only the CLOCK_REALTIME clock can be set, all other clocks
77788+ have their clock_set fptr set to a nosettime dummy function
77789+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
77790+ call common_clock_set, which calls do_sys_settimeofday, which
77791+ we hook
77792+ */
77793+
77794 return kc->clock_set(which_clock, &new_tp);
77795 }
77796
77797diff --git a/kernel/power/process.c b/kernel/power/process.c
77798index d5a258b..4271191 100644
77799--- a/kernel/power/process.c
77800+++ b/kernel/power/process.c
77801@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
77802 u64 elapsed_csecs64;
77803 unsigned int elapsed_csecs;
77804 bool wakeup = false;
77805+ bool timedout = false;
77806
77807 do_gettimeofday(&start);
77808
77809@@ -43,13 +44,20 @@ static int try_to_freeze_tasks(bool user_only)
77810
77811 while (true) {
77812 todo = 0;
77813+ if (time_after(jiffies, end_time))
77814+ timedout = true;
77815 read_lock(&tasklist_lock);
77816 do_each_thread(g, p) {
77817 if (p == current || !freeze_task(p))
77818 continue;
77819
77820- if (!freezer_should_skip(p))
77821+ if (!freezer_should_skip(p)) {
77822 todo++;
77823+ if (timedout) {
77824+ printk(KERN_ERR "Task refusing to freeze:\n");
77825+ sched_show_task(p);
77826+ }
77827+ }
77828 } while_each_thread(g, p);
77829 read_unlock(&tasklist_lock);
77830
77831@@ -58,7 +66,7 @@ static int try_to_freeze_tasks(bool user_only)
77832 todo += wq_busy;
77833 }
77834
77835- if (!todo || time_after(jiffies, end_time))
77836+ if (!todo || timedout)
77837 break;
77838
77839 if (pm_wakeup_pending()) {
77840diff --git a/kernel/printk.c b/kernel/printk.c
77841index 267ce78..2487112 100644
77842--- a/kernel/printk.c
77843+++ b/kernel/printk.c
77844@@ -609,11 +609,17 @@ static unsigned int devkmsg_poll(struct file *file, poll_table *wait)
77845 return ret;
77846 }
77847
77848+static int check_syslog_permissions(int type, bool from_file);
77849+
77850 static int devkmsg_open(struct inode *inode, struct file *file)
77851 {
77852 struct devkmsg_user *user;
77853 int err;
77854
77855+ err = check_syslog_permissions(SYSLOG_ACTION_OPEN, SYSLOG_FROM_FILE);
77856+ if (err)
77857+ return err;
77858+
77859 /* write-only does not need any file context */
77860 if ((file->f_flags & O_ACCMODE) == O_WRONLY)
77861 return 0;
77862@@ -822,7 +828,7 @@ static int syslog_action_restricted(int type)
77863 if (dmesg_restrict)
77864 return 1;
77865 /* Unless restricted, we allow "read all" and "get buffer size" for everybody */
77866- return type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
77867+ return type != SYSLOG_ACTION_OPEN && type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
77868 }
77869
77870 static int check_syslog_permissions(int type, bool from_file)
77871@@ -834,6 +840,11 @@ static int check_syslog_permissions(int type, bool from_file)
77872 if (from_file && type != SYSLOG_ACTION_OPEN)
77873 return 0;
77874
77875+#ifdef CONFIG_GRKERNSEC_DMESG
77876+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
77877+ return -EPERM;
77878+#endif
77879+
77880 if (syslog_action_restricted(type)) {
77881 if (capable(CAP_SYSLOG))
77882 return 0;
77883diff --git a/kernel/profile.c b/kernel/profile.c
77884index 1f39181..86093471 100644
77885--- a/kernel/profile.c
77886+++ b/kernel/profile.c
77887@@ -40,7 +40,7 @@ struct profile_hit {
77888 /* Oprofile timer tick hook */
77889 static int (*timer_hook)(struct pt_regs *) __read_mostly;
77890
77891-static atomic_t *prof_buffer;
77892+static atomic_unchecked_t *prof_buffer;
77893 static unsigned long prof_len, prof_shift;
77894
77895 int prof_on __read_mostly;
77896@@ -282,7 +282,7 @@ static void profile_flip_buffers(void)
77897 hits[i].pc = 0;
77898 continue;
77899 }
77900- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
77901+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
77902 hits[i].hits = hits[i].pc = 0;
77903 }
77904 }
77905@@ -343,9 +343,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
77906 * Add the current hit(s) and flush the write-queue out
77907 * to the global buffer:
77908 */
77909- atomic_add(nr_hits, &prof_buffer[pc]);
77910+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
77911 for (i = 0; i < NR_PROFILE_HIT; ++i) {
77912- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
77913+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
77914 hits[i].pc = hits[i].hits = 0;
77915 }
77916 out:
77917@@ -420,7 +420,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
77918 {
77919 unsigned long pc;
77920 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
77921- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
77922+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
77923 }
77924 #endif /* !CONFIG_SMP */
77925
77926@@ -518,7 +518,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
77927 return -EFAULT;
77928 buf++; p++; count--; read++;
77929 }
77930- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
77931+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
77932 if (copy_to_user(buf, (void *)pnt, count))
77933 return -EFAULT;
77934 read += count;
77935@@ -549,7 +549,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
77936 }
77937 #endif
77938 profile_discard_flip_buffers();
77939- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
77940+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
77941 return count;
77942 }
77943
77944diff --git a/kernel/ptrace.c b/kernel/ptrace.c
77945index 6cbeaae..cfe7ff0 100644
77946--- a/kernel/ptrace.c
77947+++ b/kernel/ptrace.c
77948@@ -324,7 +324,7 @@ static int ptrace_attach(struct task_struct *task, long request,
77949 if (seize)
77950 flags |= PT_SEIZED;
77951 rcu_read_lock();
77952- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
77953+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
77954 flags |= PT_PTRACE_CAP;
77955 rcu_read_unlock();
77956 task->ptrace = flags;
77957@@ -535,7 +535,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
77958 break;
77959 return -EIO;
77960 }
77961- if (copy_to_user(dst, buf, retval))
77962+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
77963 return -EFAULT;
77964 copied += retval;
77965 src += retval;
77966@@ -720,7 +720,7 @@ int ptrace_request(struct task_struct *child, long request,
77967 bool seized = child->ptrace & PT_SEIZED;
77968 int ret = -EIO;
77969 siginfo_t siginfo, *si;
77970- void __user *datavp = (void __user *) data;
77971+ void __user *datavp = (__force void __user *) data;
77972 unsigned long __user *datalp = datavp;
77973 unsigned long flags;
77974
77975@@ -922,14 +922,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
77976 goto out;
77977 }
77978
77979+ if (gr_handle_ptrace(child, request)) {
77980+ ret = -EPERM;
77981+ goto out_put_task_struct;
77982+ }
77983+
77984 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
77985 ret = ptrace_attach(child, request, addr, data);
77986 /*
77987 * Some architectures need to do book-keeping after
77988 * a ptrace attach.
77989 */
77990- if (!ret)
77991+ if (!ret) {
77992 arch_ptrace_attach(child);
77993+ gr_audit_ptrace(child);
77994+ }
77995 goto out_put_task_struct;
77996 }
77997
77998@@ -957,7 +964,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
77999 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
78000 if (copied != sizeof(tmp))
78001 return -EIO;
78002- return put_user(tmp, (unsigned long __user *)data);
78003+ return put_user(tmp, (__force unsigned long __user *)data);
78004 }
78005
78006 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
78007@@ -1051,7 +1058,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
78008 }
78009
78010 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
78011- compat_long_t addr, compat_long_t data)
78012+ compat_ulong_t addr, compat_ulong_t data)
78013 {
78014 struct task_struct *child;
78015 long ret;
78016@@ -1067,14 +1074,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
78017 goto out;
78018 }
78019
78020+ if (gr_handle_ptrace(child, request)) {
78021+ ret = -EPERM;
78022+ goto out_put_task_struct;
78023+ }
78024+
78025 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
78026 ret = ptrace_attach(child, request, addr, data);
78027 /*
78028 * Some architectures need to do book-keeping after
78029 * a ptrace attach.
78030 */
78031- if (!ret)
78032+ if (!ret) {
78033 arch_ptrace_attach(child);
78034+ gr_audit_ptrace(child);
78035+ }
78036 goto out_put_task_struct;
78037 }
78038
78039diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
78040index e7dce58..ad0d7b7 100644
78041--- a/kernel/rcutiny.c
78042+++ b/kernel/rcutiny.c
78043@@ -46,7 +46,7 @@
78044 struct rcu_ctrlblk;
78045 static void invoke_rcu_callbacks(void);
78046 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
78047-static void rcu_process_callbacks(struct softirq_action *unused);
78048+static void rcu_process_callbacks(void);
78049 static void __call_rcu(struct rcu_head *head,
78050 void (*func)(struct rcu_head *rcu),
78051 struct rcu_ctrlblk *rcp);
78052@@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
78053 rcu_is_callbacks_kthread()));
78054 }
78055
78056-static void rcu_process_callbacks(struct softirq_action *unused)
78057+static void rcu_process_callbacks(void)
78058 {
78059 __rcu_process_callbacks(&rcu_sched_ctrlblk);
78060 __rcu_process_callbacks(&rcu_bh_ctrlblk);
78061diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
78062index f85016a..91cb03b 100644
78063--- a/kernel/rcutiny_plugin.h
78064+++ b/kernel/rcutiny_plugin.h
78065@@ -896,7 +896,7 @@ static int rcu_kthread(void *arg)
78066 have_rcu_kthread_work = morework;
78067 local_irq_restore(flags);
78068 if (work)
78069- rcu_process_callbacks(NULL);
78070+ rcu_process_callbacks();
78071 schedule_timeout_interruptible(1); /* Leave CPU for others. */
78072 }
78073
78074diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
78075index 31dea01..ad91ffb 100644
78076--- a/kernel/rcutorture.c
78077+++ b/kernel/rcutorture.c
78078@@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
78079 { 0 };
78080 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
78081 { 0 };
78082-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
78083-static atomic_t n_rcu_torture_alloc;
78084-static atomic_t n_rcu_torture_alloc_fail;
78085-static atomic_t n_rcu_torture_free;
78086-static atomic_t n_rcu_torture_mberror;
78087-static atomic_t n_rcu_torture_error;
78088+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
78089+static atomic_unchecked_t n_rcu_torture_alloc;
78090+static atomic_unchecked_t n_rcu_torture_alloc_fail;
78091+static atomic_unchecked_t n_rcu_torture_free;
78092+static atomic_unchecked_t n_rcu_torture_mberror;
78093+static atomic_unchecked_t n_rcu_torture_error;
78094 static long n_rcu_torture_barrier_error;
78095 static long n_rcu_torture_boost_ktrerror;
78096 static long n_rcu_torture_boost_rterror;
78097@@ -272,11 +272,11 @@ rcu_torture_alloc(void)
78098
78099 spin_lock_bh(&rcu_torture_lock);
78100 if (list_empty(&rcu_torture_freelist)) {
78101- atomic_inc(&n_rcu_torture_alloc_fail);
78102+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
78103 spin_unlock_bh(&rcu_torture_lock);
78104 return NULL;
78105 }
78106- atomic_inc(&n_rcu_torture_alloc);
78107+ atomic_inc_unchecked(&n_rcu_torture_alloc);
78108 p = rcu_torture_freelist.next;
78109 list_del_init(p);
78110 spin_unlock_bh(&rcu_torture_lock);
78111@@ -289,7 +289,7 @@ rcu_torture_alloc(void)
78112 static void
78113 rcu_torture_free(struct rcu_torture *p)
78114 {
78115- atomic_inc(&n_rcu_torture_free);
78116+ atomic_inc_unchecked(&n_rcu_torture_free);
78117 spin_lock_bh(&rcu_torture_lock);
78118 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
78119 spin_unlock_bh(&rcu_torture_lock);
78120@@ -409,7 +409,7 @@ rcu_torture_cb(struct rcu_head *p)
78121 i = rp->rtort_pipe_count;
78122 if (i > RCU_TORTURE_PIPE_LEN)
78123 i = RCU_TORTURE_PIPE_LEN;
78124- atomic_inc(&rcu_torture_wcount[i]);
78125+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
78126 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
78127 rp->rtort_mbtest = 0;
78128 rcu_torture_free(rp);
78129@@ -457,7 +457,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
78130 i = rp->rtort_pipe_count;
78131 if (i > RCU_TORTURE_PIPE_LEN)
78132 i = RCU_TORTURE_PIPE_LEN;
78133- atomic_inc(&rcu_torture_wcount[i]);
78134+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
78135 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
78136 rp->rtort_mbtest = 0;
78137 list_del(&rp->rtort_free);
78138@@ -975,7 +975,7 @@ rcu_torture_writer(void *arg)
78139 i = old_rp->rtort_pipe_count;
78140 if (i > RCU_TORTURE_PIPE_LEN)
78141 i = RCU_TORTURE_PIPE_LEN;
78142- atomic_inc(&rcu_torture_wcount[i]);
78143+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
78144 old_rp->rtort_pipe_count++;
78145 cur_ops->deferred_free(old_rp);
78146 }
78147@@ -1060,7 +1060,7 @@ static void rcu_torture_timer(unsigned long unused)
78148 }
78149 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
78150 if (p->rtort_mbtest == 0)
78151- atomic_inc(&n_rcu_torture_mberror);
78152+ atomic_inc_unchecked(&n_rcu_torture_mberror);
78153 spin_lock(&rand_lock);
78154 cur_ops->read_delay(&rand);
78155 n_rcu_torture_timers++;
78156@@ -1124,7 +1124,7 @@ rcu_torture_reader(void *arg)
78157 }
78158 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
78159 if (p->rtort_mbtest == 0)
78160- atomic_inc(&n_rcu_torture_mberror);
78161+ atomic_inc_unchecked(&n_rcu_torture_mberror);
78162 cur_ops->read_delay(&rand);
78163 preempt_disable();
78164 pipe_count = p->rtort_pipe_count;
78165@@ -1183,11 +1183,11 @@ rcu_torture_printk(char *page)
78166 rcu_torture_current,
78167 rcu_torture_current_version,
78168 list_empty(&rcu_torture_freelist),
78169- atomic_read(&n_rcu_torture_alloc),
78170- atomic_read(&n_rcu_torture_alloc_fail),
78171- atomic_read(&n_rcu_torture_free));
78172+ atomic_read_unchecked(&n_rcu_torture_alloc),
78173+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
78174+ atomic_read_unchecked(&n_rcu_torture_free));
78175 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
78176- atomic_read(&n_rcu_torture_mberror),
78177+ atomic_read_unchecked(&n_rcu_torture_mberror),
78178 n_rcu_torture_boost_ktrerror,
78179 n_rcu_torture_boost_rterror);
78180 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
78181@@ -1206,14 +1206,14 @@ rcu_torture_printk(char *page)
78182 n_barrier_attempts,
78183 n_rcu_torture_barrier_error);
78184 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
78185- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
78186+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
78187 n_rcu_torture_barrier_error != 0 ||
78188 n_rcu_torture_boost_ktrerror != 0 ||
78189 n_rcu_torture_boost_rterror != 0 ||
78190 n_rcu_torture_boost_failure != 0 ||
78191 i > 1) {
78192 cnt += sprintf(&page[cnt], "!!! ");
78193- atomic_inc(&n_rcu_torture_error);
78194+ atomic_inc_unchecked(&n_rcu_torture_error);
78195 WARN_ON_ONCE(1);
78196 }
78197 cnt += sprintf(&page[cnt], "Reader Pipe: ");
78198@@ -1227,7 +1227,7 @@ rcu_torture_printk(char *page)
78199 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
78200 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
78201 cnt += sprintf(&page[cnt], " %d",
78202- atomic_read(&rcu_torture_wcount[i]));
78203+ atomic_read_unchecked(&rcu_torture_wcount[i]));
78204 }
78205 cnt += sprintf(&page[cnt], "\n");
78206 if (cur_ops->stats)
78207@@ -1920,7 +1920,7 @@ rcu_torture_cleanup(void)
78208
78209 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
78210
78211- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
78212+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
78213 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
78214 else if (n_online_successes != n_online_attempts ||
78215 n_offline_successes != n_offline_attempts)
78216@@ -1989,18 +1989,18 @@ rcu_torture_init(void)
78217
78218 rcu_torture_current = NULL;
78219 rcu_torture_current_version = 0;
78220- atomic_set(&n_rcu_torture_alloc, 0);
78221- atomic_set(&n_rcu_torture_alloc_fail, 0);
78222- atomic_set(&n_rcu_torture_free, 0);
78223- atomic_set(&n_rcu_torture_mberror, 0);
78224- atomic_set(&n_rcu_torture_error, 0);
78225+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
78226+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
78227+ atomic_set_unchecked(&n_rcu_torture_free, 0);
78228+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
78229+ atomic_set_unchecked(&n_rcu_torture_error, 0);
78230 n_rcu_torture_barrier_error = 0;
78231 n_rcu_torture_boost_ktrerror = 0;
78232 n_rcu_torture_boost_rterror = 0;
78233 n_rcu_torture_boost_failure = 0;
78234 n_rcu_torture_boosts = 0;
78235 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
78236- atomic_set(&rcu_torture_wcount[i], 0);
78237+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
78238 for_each_possible_cpu(cpu) {
78239 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
78240 per_cpu(rcu_torture_count, cpu)[i] = 0;
78241diff --git a/kernel/rcutree.c b/kernel/rcutree.c
78242index e441b77..dd54f17 100644
78243--- a/kernel/rcutree.c
78244+++ b/kernel/rcutree.c
78245@@ -349,9 +349,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
78246 rcu_prepare_for_idle(smp_processor_id());
78247 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
78248 smp_mb__before_atomic_inc(); /* See above. */
78249- atomic_inc(&rdtp->dynticks);
78250+ atomic_inc_unchecked(&rdtp->dynticks);
78251 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
78252- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
78253+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
78254
78255 /*
78256 * It is illegal to enter an extended quiescent state while
78257@@ -487,10 +487,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
78258 int user)
78259 {
78260 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
78261- atomic_inc(&rdtp->dynticks);
78262+ atomic_inc_unchecked(&rdtp->dynticks);
78263 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
78264 smp_mb__after_atomic_inc(); /* See above. */
78265- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
78266+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
78267 rcu_cleanup_after_idle(smp_processor_id());
78268 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
78269 if (!user && !is_idle_task(current)) {
78270@@ -629,14 +629,14 @@ void rcu_nmi_enter(void)
78271 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
78272
78273 if (rdtp->dynticks_nmi_nesting == 0 &&
78274- (atomic_read(&rdtp->dynticks) & 0x1))
78275+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
78276 return;
78277 rdtp->dynticks_nmi_nesting++;
78278 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
78279- atomic_inc(&rdtp->dynticks);
78280+ atomic_inc_unchecked(&rdtp->dynticks);
78281 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
78282 smp_mb__after_atomic_inc(); /* See above. */
78283- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
78284+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
78285 }
78286
78287 /**
78288@@ -655,9 +655,9 @@ void rcu_nmi_exit(void)
78289 return;
78290 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
78291 smp_mb__before_atomic_inc(); /* See above. */
78292- atomic_inc(&rdtp->dynticks);
78293+ atomic_inc_unchecked(&rdtp->dynticks);
78294 smp_mb__after_atomic_inc(); /* Force delay to next write. */
78295- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
78296+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
78297 }
78298
78299 /**
78300@@ -671,7 +671,7 @@ int rcu_is_cpu_idle(void)
78301 int ret;
78302
78303 preempt_disable();
78304- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
78305+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
78306 preempt_enable();
78307 return ret;
78308 }
78309@@ -739,7 +739,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
78310 */
78311 static int dyntick_save_progress_counter(struct rcu_data *rdp)
78312 {
78313- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
78314+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
78315 return (rdp->dynticks_snap & 0x1) == 0;
78316 }
78317
78318@@ -754,7 +754,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
78319 unsigned int curr;
78320 unsigned int snap;
78321
78322- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
78323+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
78324 snap = (unsigned int)rdp->dynticks_snap;
78325
78326 /*
78327@@ -802,10 +802,10 @@ static int jiffies_till_stall_check(void)
78328 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
78329 */
78330 if (till_stall_check < 3) {
78331- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
78332+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
78333 till_stall_check = 3;
78334 } else if (till_stall_check > 300) {
78335- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
78336+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
78337 till_stall_check = 300;
78338 }
78339 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
78340@@ -1592,7 +1592,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
78341 rsp->qlen += rdp->qlen;
78342 rdp->n_cbs_orphaned += rdp->qlen;
78343 rdp->qlen_lazy = 0;
78344- ACCESS_ONCE(rdp->qlen) = 0;
78345+ ACCESS_ONCE_RW(rdp->qlen) = 0;
78346 }
78347
78348 /*
78349@@ -1838,7 +1838,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
78350 }
78351 smp_mb(); /* List handling before counting for rcu_barrier(). */
78352 rdp->qlen_lazy -= count_lazy;
78353- ACCESS_ONCE(rdp->qlen) -= count;
78354+ ACCESS_ONCE_RW(rdp->qlen) -= count;
78355 rdp->n_cbs_invoked += count;
78356
78357 /* Reinstate batch limit if we have worked down the excess. */
78358@@ -2031,7 +2031,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
78359 /*
78360 * Do RCU core processing for the current CPU.
78361 */
78362-static void rcu_process_callbacks(struct softirq_action *unused)
78363+static void rcu_process_callbacks(void)
78364 {
78365 struct rcu_state *rsp;
78366
78367@@ -2154,7 +2154,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
78368 local_irq_restore(flags);
78369 return;
78370 }
78371- ACCESS_ONCE(rdp->qlen)++;
78372+ ACCESS_ONCE_RW(rdp->qlen)++;
78373 if (lazy)
78374 rdp->qlen_lazy++;
78375 else
78376@@ -2363,11 +2363,11 @@ void synchronize_sched_expedited(void)
78377 * counter wrap on a 32-bit system. Quite a few more CPUs would of
78378 * course be required on a 64-bit system.
78379 */
78380- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
78381+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
78382 (ulong)atomic_long_read(&rsp->expedited_done) +
78383 ULONG_MAX / 8)) {
78384 synchronize_sched();
78385- atomic_long_inc(&rsp->expedited_wrap);
78386+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
78387 return;
78388 }
78389
78390@@ -2375,7 +2375,7 @@ void synchronize_sched_expedited(void)
78391 * Take a ticket. Note that atomic_inc_return() implies a
78392 * full memory barrier.
78393 */
78394- snap = atomic_long_inc_return(&rsp->expedited_start);
78395+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
78396 firstsnap = snap;
78397 get_online_cpus();
78398 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
78399@@ -2388,14 +2388,14 @@ void synchronize_sched_expedited(void)
78400 synchronize_sched_expedited_cpu_stop,
78401 NULL) == -EAGAIN) {
78402 put_online_cpus();
78403- atomic_long_inc(&rsp->expedited_tryfail);
78404+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
78405
78406 /* Check to see if someone else did our work for us. */
78407 s = atomic_long_read(&rsp->expedited_done);
78408 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
78409 /* ensure test happens before caller kfree */
78410 smp_mb__before_atomic_inc(); /* ^^^ */
78411- atomic_long_inc(&rsp->expedited_workdone1);
78412+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
78413 return;
78414 }
78415
78416@@ -2404,7 +2404,7 @@ void synchronize_sched_expedited(void)
78417 udelay(trycount * num_online_cpus());
78418 } else {
78419 wait_rcu_gp(call_rcu_sched);
78420- atomic_long_inc(&rsp->expedited_normal);
78421+ atomic_long_inc_unchecked(&rsp->expedited_normal);
78422 return;
78423 }
78424
78425@@ -2413,7 +2413,7 @@ void synchronize_sched_expedited(void)
78426 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
78427 /* ensure test happens before caller kfree */
78428 smp_mb__before_atomic_inc(); /* ^^^ */
78429- atomic_long_inc(&rsp->expedited_workdone2);
78430+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
78431 return;
78432 }
78433
78434@@ -2425,10 +2425,10 @@ void synchronize_sched_expedited(void)
78435 * period works for us.
78436 */
78437 get_online_cpus();
78438- snap = atomic_long_read(&rsp->expedited_start);
78439+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
78440 smp_mb(); /* ensure read is before try_stop_cpus(). */
78441 }
78442- atomic_long_inc(&rsp->expedited_stoppedcpus);
78443+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
78444
78445 /*
78446 * Everyone up to our most recent fetch is covered by our grace
78447@@ -2437,16 +2437,16 @@ void synchronize_sched_expedited(void)
78448 * than we did already did their update.
78449 */
78450 do {
78451- atomic_long_inc(&rsp->expedited_done_tries);
78452+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
78453 s = atomic_long_read(&rsp->expedited_done);
78454 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
78455 /* ensure test happens before caller kfree */
78456 smp_mb__before_atomic_inc(); /* ^^^ */
78457- atomic_long_inc(&rsp->expedited_done_lost);
78458+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
78459 break;
78460 }
78461 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
78462- atomic_long_inc(&rsp->expedited_done_exit);
78463+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
78464
78465 put_online_cpus();
78466 }
78467@@ -2620,7 +2620,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
78468 * ACCESS_ONCE() to prevent the compiler from speculating
78469 * the increment to precede the early-exit check.
78470 */
78471- ACCESS_ONCE(rsp->n_barrier_done)++;
78472+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
78473 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
78474 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
78475 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
78476@@ -2670,7 +2670,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
78477
78478 /* Increment ->n_barrier_done to prevent duplicate work. */
78479 smp_mb(); /* Keep increment after above mechanism. */
78480- ACCESS_ONCE(rsp->n_barrier_done)++;
78481+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
78482 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
78483 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
78484 smp_mb(); /* Keep increment before caller's subsequent code. */
78485@@ -2715,10 +2715,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
78486 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
78487 init_callback_list(rdp);
78488 rdp->qlen_lazy = 0;
78489- ACCESS_ONCE(rdp->qlen) = 0;
78490+ ACCESS_ONCE_RW(rdp->qlen) = 0;
78491 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
78492 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
78493- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
78494+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
78495 #ifdef CONFIG_RCU_USER_QS
78496 WARN_ON_ONCE(rdp->dynticks->in_user);
78497 #endif
78498@@ -2754,8 +2754,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
78499 rdp->blimit = blimit;
78500 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
78501 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
78502- atomic_set(&rdp->dynticks->dynticks,
78503- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
78504+ atomic_set_unchecked(&rdp->dynticks->dynticks,
78505+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
78506 rcu_prepare_for_idle_init(cpu);
78507 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
78508
78509diff --git a/kernel/rcutree.h b/kernel/rcutree.h
78510index 4b69291..704c92e 100644
78511--- a/kernel/rcutree.h
78512+++ b/kernel/rcutree.h
78513@@ -86,7 +86,7 @@ struct rcu_dynticks {
78514 long long dynticks_nesting; /* Track irq/process nesting level. */
78515 /* Process level is worth LLONG_MAX/2. */
78516 int dynticks_nmi_nesting; /* Track NMI nesting level. */
78517- atomic_t dynticks; /* Even value for idle, else odd. */
78518+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
78519 #ifdef CONFIG_RCU_FAST_NO_HZ
78520 int dyntick_drain; /* Prepare-for-idle state variable. */
78521 unsigned long dyntick_holdoff;
78522@@ -423,17 +423,17 @@ struct rcu_state {
78523 /* _rcu_barrier(). */
78524 /* End of fields guarded by barrier_mutex. */
78525
78526- atomic_long_t expedited_start; /* Starting ticket. */
78527- atomic_long_t expedited_done; /* Done ticket. */
78528- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
78529- atomic_long_t expedited_tryfail; /* # acquisition failures. */
78530- atomic_long_t expedited_workdone1; /* # done by others #1. */
78531- atomic_long_t expedited_workdone2; /* # done by others #2. */
78532- atomic_long_t expedited_normal; /* # fallbacks to normal. */
78533- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
78534- atomic_long_t expedited_done_tries; /* # tries to update _done. */
78535- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
78536- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
78537+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
78538+ atomic_long_t expedited_done; /* Done ticket. */
78539+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
78540+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
78541+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
78542+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
78543+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
78544+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
78545+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
78546+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
78547+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
78548
78549 unsigned long jiffies_force_qs; /* Time at which to invoke */
78550 /* force_quiescent_state(). */
78551diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
78552index c1cc7e1..f62e436 100644
78553--- a/kernel/rcutree_plugin.h
78554+++ b/kernel/rcutree_plugin.h
78555@@ -892,7 +892,7 @@ void synchronize_rcu_expedited(void)
78556
78557 /* Clean up and exit. */
78558 smp_mb(); /* ensure expedited GP seen before counter increment. */
78559- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
78560+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
78561 unlock_mb_ret:
78562 mutex_unlock(&sync_rcu_preempt_exp_mutex);
78563 mb_ret:
78564@@ -1440,7 +1440,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
78565 free_cpumask_var(cm);
78566 }
78567
78568-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
78569+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
78570 .store = &rcu_cpu_kthread_task,
78571 .thread_should_run = rcu_cpu_kthread_should_run,
78572 .thread_fn = rcu_cpu_kthread,
78573@@ -2072,7 +2072,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
78574 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
78575 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
78576 cpu, ticks_value, ticks_title,
78577- atomic_read(&rdtp->dynticks) & 0xfff,
78578+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
78579 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
78580 fast_no_hz);
78581 }
78582@@ -2192,7 +2192,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
78583
78584 /* Enqueue the callback on the nocb list and update counts. */
78585 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
78586- ACCESS_ONCE(*old_rhpp) = rhp;
78587+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
78588 atomic_long_add(rhcount, &rdp->nocb_q_count);
78589 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
78590
78591@@ -2384,12 +2384,12 @@ static int rcu_nocb_kthread(void *arg)
78592 * Extract queued callbacks, update counts, and wait
78593 * for a grace period to elapse.
78594 */
78595- ACCESS_ONCE(rdp->nocb_head) = NULL;
78596+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
78597 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
78598 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
78599 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
78600- ACCESS_ONCE(rdp->nocb_p_count) += c;
78601- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
78602+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
78603+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
78604 wait_rcu_gp(rdp->rsp->call_remote);
78605
78606 /* Each pass through the following loop invokes a callback. */
78607@@ -2411,8 +2411,8 @@ static int rcu_nocb_kthread(void *arg)
78608 list = next;
78609 }
78610 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
78611- ACCESS_ONCE(rdp->nocb_p_count) -= c;
78612- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
78613+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
78614+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
78615 rdp->n_nocbs_invoked += c;
78616 }
78617 return 0;
78618@@ -2438,7 +2438,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
78619 rdp = per_cpu_ptr(rsp->rda, cpu);
78620 t = kthread_run(rcu_nocb_kthread, rdp, "rcuo%d", cpu);
78621 BUG_ON(IS_ERR(t));
78622- ACCESS_ONCE(rdp->nocb_kthread) = t;
78623+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
78624 }
78625 }
78626
78627diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
78628index 0d095dc..1985b19 100644
78629--- a/kernel/rcutree_trace.c
78630+++ b/kernel/rcutree_trace.c
78631@@ -123,7 +123,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
78632 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
78633 rdp->passed_quiesce, rdp->qs_pending);
78634 seq_printf(m, " dt=%d/%llx/%d df=%lu",
78635- atomic_read(&rdp->dynticks->dynticks),
78636+ atomic_read_unchecked(&rdp->dynticks->dynticks),
78637 rdp->dynticks->dynticks_nesting,
78638 rdp->dynticks->dynticks_nmi_nesting,
78639 rdp->dynticks_fqs);
78640@@ -184,17 +184,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
78641 struct rcu_state *rsp = (struct rcu_state *)m->private;
78642
78643 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",
78644- atomic_long_read(&rsp->expedited_start),
78645+ atomic_long_read_unchecked(&rsp->expedited_start),
78646 atomic_long_read(&rsp->expedited_done),
78647- atomic_long_read(&rsp->expedited_wrap),
78648- atomic_long_read(&rsp->expedited_tryfail),
78649- atomic_long_read(&rsp->expedited_workdone1),
78650- atomic_long_read(&rsp->expedited_workdone2),
78651- atomic_long_read(&rsp->expedited_normal),
78652- atomic_long_read(&rsp->expedited_stoppedcpus),
78653- atomic_long_read(&rsp->expedited_done_tries),
78654- atomic_long_read(&rsp->expedited_done_lost),
78655- atomic_long_read(&rsp->expedited_done_exit));
78656+ atomic_long_read_unchecked(&rsp->expedited_wrap),
78657+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
78658+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
78659+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
78660+ atomic_long_read_unchecked(&rsp->expedited_normal),
78661+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
78662+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
78663+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
78664+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
78665 return 0;
78666 }
78667
78668diff --git a/kernel/resource.c b/kernel/resource.c
78669index 73f35d4..4684fc4 100644
78670--- a/kernel/resource.c
78671+++ b/kernel/resource.c
78672@@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
78673
78674 static int __init ioresources_init(void)
78675 {
78676+#ifdef CONFIG_GRKERNSEC_PROC_ADD
78677+#ifdef CONFIG_GRKERNSEC_PROC_USER
78678+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
78679+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
78680+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78681+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
78682+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
78683+#endif
78684+#else
78685 proc_create("ioports", 0, NULL, &proc_ioports_operations);
78686 proc_create("iomem", 0, NULL, &proc_iomem_operations);
78687+#endif
78688 return 0;
78689 }
78690 __initcall(ioresources_init);
78691diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
78692index 98ec494..4241d6d 100644
78693--- a/kernel/rtmutex-tester.c
78694+++ b/kernel/rtmutex-tester.c
78695@@ -20,7 +20,7 @@
78696 #define MAX_RT_TEST_MUTEXES 8
78697
78698 static spinlock_t rttest_lock;
78699-static atomic_t rttest_event;
78700+static atomic_unchecked_t rttest_event;
78701
78702 struct test_thread_data {
78703 int opcode;
78704@@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78705
78706 case RTTEST_LOCKCONT:
78707 td->mutexes[td->opdata] = 1;
78708- td->event = atomic_add_return(1, &rttest_event);
78709+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78710 return 0;
78711
78712 case RTTEST_RESET:
78713@@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78714 return 0;
78715
78716 case RTTEST_RESETEVENT:
78717- atomic_set(&rttest_event, 0);
78718+ atomic_set_unchecked(&rttest_event, 0);
78719 return 0;
78720
78721 default:
78722@@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78723 return ret;
78724
78725 td->mutexes[id] = 1;
78726- td->event = atomic_add_return(1, &rttest_event);
78727+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78728 rt_mutex_lock(&mutexes[id]);
78729- td->event = atomic_add_return(1, &rttest_event);
78730+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78731 td->mutexes[id] = 4;
78732 return 0;
78733
78734@@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78735 return ret;
78736
78737 td->mutexes[id] = 1;
78738- td->event = atomic_add_return(1, &rttest_event);
78739+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78740 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
78741- td->event = atomic_add_return(1, &rttest_event);
78742+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78743 td->mutexes[id] = ret ? 0 : 4;
78744 return ret ? -EINTR : 0;
78745
78746@@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78747 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
78748 return ret;
78749
78750- td->event = atomic_add_return(1, &rttest_event);
78751+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78752 rt_mutex_unlock(&mutexes[id]);
78753- td->event = atomic_add_return(1, &rttest_event);
78754+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78755 td->mutexes[id] = 0;
78756 return 0;
78757
78758@@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
78759 break;
78760
78761 td->mutexes[dat] = 2;
78762- td->event = atomic_add_return(1, &rttest_event);
78763+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78764 break;
78765
78766 default:
78767@@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
78768 return;
78769
78770 td->mutexes[dat] = 3;
78771- td->event = atomic_add_return(1, &rttest_event);
78772+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78773 break;
78774
78775 case RTTEST_LOCKNOWAIT:
78776@@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
78777 return;
78778
78779 td->mutexes[dat] = 1;
78780- td->event = atomic_add_return(1, &rttest_event);
78781+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78782 return;
78783
78784 default:
78785diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
78786index 0984a21..939f183 100644
78787--- a/kernel/sched/auto_group.c
78788+++ b/kernel/sched/auto_group.c
78789@@ -11,7 +11,7 @@
78790
78791 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
78792 static struct autogroup autogroup_default;
78793-static atomic_t autogroup_seq_nr;
78794+static atomic_unchecked_t autogroup_seq_nr;
78795
78796 void __init autogroup_init(struct task_struct *init_task)
78797 {
78798@@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
78799
78800 kref_init(&ag->kref);
78801 init_rwsem(&ag->lock);
78802- ag->id = atomic_inc_return(&autogroup_seq_nr);
78803+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
78804 ag->tg = tg;
78805 #ifdef CONFIG_RT_GROUP_SCHED
78806 /*
78807diff --git a/kernel/sched/core.c b/kernel/sched/core.c
78808index 26058d0..e315889 100644
78809--- a/kernel/sched/core.c
78810+++ b/kernel/sched/core.c
78811@@ -3367,7 +3367,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
78812 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
78813 * positive (at least 1, or number of jiffies left till timeout) if completed.
78814 */
78815-long __sched
78816+long __sched __intentional_overflow(-1)
78817 wait_for_completion_interruptible_timeout(struct completion *x,
78818 unsigned long timeout)
78819 {
78820@@ -3384,7 +3384,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
78821 *
78822 * The return value is -ERESTARTSYS if interrupted, 0 if completed.
78823 */
78824-int __sched wait_for_completion_killable(struct completion *x)
78825+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
78826 {
78827 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
78828 if (t == -ERESTARTSYS)
78829@@ -3405,7 +3405,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
78830 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
78831 * positive (at least 1, or number of jiffies left till timeout) if completed.
78832 */
78833-long __sched
78834+long __sched __intentional_overflow(-1)
78835 wait_for_completion_killable_timeout(struct completion *x,
78836 unsigned long timeout)
78837 {
78838@@ -3631,6 +3631,8 @@ int can_nice(const struct task_struct *p, const int nice)
78839 /* convert nice value [19,-20] to rlimit style value [1,40] */
78840 int nice_rlim = 20 - nice;
78841
78842+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
78843+
78844 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
78845 capable(CAP_SYS_NICE));
78846 }
78847@@ -3664,7 +3666,8 @@ SYSCALL_DEFINE1(nice, int, increment)
78848 if (nice > 19)
78849 nice = 19;
78850
78851- if (increment < 0 && !can_nice(current, nice))
78852+ if (increment < 0 && (!can_nice(current, nice) ||
78853+ gr_handle_chroot_nice()))
78854 return -EPERM;
78855
78856 retval = security_task_setnice(current, nice);
78857@@ -3818,6 +3821,7 @@ recheck:
78858 unsigned long rlim_rtprio =
78859 task_rlimit(p, RLIMIT_RTPRIO);
78860
78861+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
78862 /* can't set/change the rt policy */
78863 if (policy != p->policy && !rlim_rtprio)
78864 return -EPERM;
78865@@ -4901,7 +4905,7 @@ static void migrate_tasks(unsigned int dead_cpu)
78866
78867 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
78868
78869-static struct ctl_table sd_ctl_dir[] = {
78870+static ctl_table_no_const sd_ctl_dir[] __read_only = {
78871 {
78872 .procname = "sched_domain",
78873 .mode = 0555,
78874@@ -4918,17 +4922,17 @@ static struct ctl_table sd_ctl_root[] = {
78875 {}
78876 };
78877
78878-static struct ctl_table *sd_alloc_ctl_entry(int n)
78879+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
78880 {
78881- struct ctl_table *entry =
78882+ ctl_table_no_const *entry =
78883 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
78884
78885 return entry;
78886 }
78887
78888-static void sd_free_ctl_entry(struct ctl_table **tablep)
78889+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
78890 {
78891- struct ctl_table *entry;
78892+ ctl_table_no_const *entry;
78893
78894 /*
78895 * In the intermediate directories, both the child directory and
78896@@ -4936,22 +4940,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
78897 * will always be set. In the lowest directory the names are
78898 * static strings and all have proc handlers.
78899 */
78900- for (entry = *tablep; entry->mode; entry++) {
78901- if (entry->child)
78902- sd_free_ctl_entry(&entry->child);
78903+ for (entry = tablep; entry->mode; entry++) {
78904+ if (entry->child) {
78905+ sd_free_ctl_entry(entry->child);
78906+ pax_open_kernel();
78907+ entry->child = NULL;
78908+ pax_close_kernel();
78909+ }
78910 if (entry->proc_handler == NULL)
78911 kfree(entry->procname);
78912 }
78913
78914- kfree(*tablep);
78915- *tablep = NULL;
78916+ kfree(tablep);
78917 }
78918
78919 static int min_load_idx = 0;
78920 static int max_load_idx = CPU_LOAD_IDX_MAX;
78921
78922 static void
78923-set_table_entry(struct ctl_table *entry,
78924+set_table_entry(ctl_table_no_const *entry,
78925 const char *procname, void *data, int maxlen,
78926 umode_t mode, proc_handler *proc_handler,
78927 bool load_idx)
78928@@ -4971,7 +4978,7 @@ set_table_entry(struct ctl_table *entry,
78929 static struct ctl_table *
78930 sd_alloc_ctl_domain_table(struct sched_domain *sd)
78931 {
78932- struct ctl_table *table = sd_alloc_ctl_entry(13);
78933+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
78934
78935 if (table == NULL)
78936 return NULL;
78937@@ -5006,9 +5013,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
78938 return table;
78939 }
78940
78941-static ctl_table *sd_alloc_ctl_cpu_table(int cpu)
78942+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
78943 {
78944- struct ctl_table *entry, *table;
78945+ ctl_table_no_const *entry, *table;
78946 struct sched_domain *sd;
78947 int domain_num = 0, i;
78948 char buf[32];
78949@@ -5035,11 +5042,13 @@ static struct ctl_table_header *sd_sysctl_header;
78950 static void register_sched_domain_sysctl(void)
78951 {
78952 int i, cpu_num = num_possible_cpus();
78953- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
78954+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
78955 char buf[32];
78956
78957 WARN_ON(sd_ctl_dir[0].child);
78958+ pax_open_kernel();
78959 sd_ctl_dir[0].child = entry;
78960+ pax_close_kernel();
78961
78962 if (entry == NULL)
78963 return;
78964@@ -5062,8 +5071,12 @@ static void unregister_sched_domain_sysctl(void)
78965 if (sd_sysctl_header)
78966 unregister_sysctl_table(sd_sysctl_header);
78967 sd_sysctl_header = NULL;
78968- if (sd_ctl_dir[0].child)
78969- sd_free_ctl_entry(&sd_ctl_dir[0].child);
78970+ if (sd_ctl_dir[0].child) {
78971+ sd_free_ctl_entry(sd_ctl_dir[0].child);
78972+ pax_open_kernel();
78973+ sd_ctl_dir[0].child = NULL;
78974+ pax_close_kernel();
78975+ }
78976 }
78977 #else
78978 static void register_sched_domain_sysctl(void)
78979@@ -5162,7 +5175,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
78980 * happens before everything else. This has to be lower priority than
78981 * the notifier in the perf_event subsystem, though.
78982 */
78983-static struct notifier_block __cpuinitdata migration_notifier = {
78984+static struct notifier_block migration_notifier = {
78985 .notifier_call = migration_call,
78986 .priority = CPU_PRI_MIGRATION,
78987 };
78988diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
78989index 81fa536..6ccf96a 100644
78990--- a/kernel/sched/fair.c
78991+++ b/kernel/sched/fair.c
78992@@ -830,7 +830,7 @@ void task_numa_fault(int node, int pages, bool migrated)
78993
78994 static void reset_ptenuma_scan(struct task_struct *p)
78995 {
78996- ACCESS_ONCE(p->mm->numa_scan_seq)++;
78997+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
78998 p->mm->numa_scan_offset = 0;
78999 }
79000
79001@@ -3254,25 +3254,18 @@ find_idlest_cpu(struct sched_group *group, struct task_struct *p, int this_cpu)
79002 */
79003 static int select_idle_sibling(struct task_struct *p, int target)
79004 {
79005- int cpu = smp_processor_id();
79006- int prev_cpu = task_cpu(p);
79007 struct sched_domain *sd;
79008 struct sched_group *sg;
79009- int i;
79010+ int i = task_cpu(p);
79011
79012- /*
79013- * If the task is going to be woken-up on this cpu and if it is
79014- * already idle, then it is the right target.
79015- */
79016- if (target == cpu && idle_cpu(cpu))
79017- return cpu;
79018+ if (idle_cpu(target))
79019+ return target;
79020
79021 /*
79022- * If the task is going to be woken-up on the cpu where it previously
79023- * ran and if it is currently idle, then it the right target.
79024+ * If the prevous cpu is cache affine and idle, don't be stupid.
79025 */
79026- if (target == prev_cpu && idle_cpu(prev_cpu))
79027- return prev_cpu;
79028+ if (i != target && cpus_share_cache(i, target) && idle_cpu(i))
79029+ return i;
79030
79031 /*
79032 * Otherwise, iterate the domains and find an elegible idle cpu.
79033@@ -3286,7 +3279,7 @@ static int select_idle_sibling(struct task_struct *p, int target)
79034 goto next;
79035
79036 for_each_cpu(i, sched_group_cpus(sg)) {
79037- if (!idle_cpu(i))
79038+ if (i == target || !idle_cpu(i))
79039 goto next;
79040 }
79041
79042@@ -5663,7 +5656,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
79043 * run_rebalance_domains is triggered when needed from the scheduler tick.
79044 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
79045 */
79046-static void run_rebalance_domains(struct softirq_action *h)
79047+static void run_rebalance_domains(void)
79048 {
79049 int this_cpu = smp_processor_id();
79050 struct rq *this_rq = cpu_rq(this_cpu);
79051diff --git a/kernel/signal.c b/kernel/signal.c
79052index dec9c30..92c8f65 100644
79053--- a/kernel/signal.c
79054+++ b/kernel/signal.c
79055@@ -50,12 +50,12 @@ static struct kmem_cache *sigqueue_cachep;
79056
79057 int print_fatal_signals __read_mostly;
79058
79059-static void __user *sig_handler(struct task_struct *t, int sig)
79060+static __sighandler_t sig_handler(struct task_struct *t, int sig)
79061 {
79062 return t->sighand->action[sig - 1].sa.sa_handler;
79063 }
79064
79065-static int sig_handler_ignored(void __user *handler, int sig)
79066+static int sig_handler_ignored(__sighandler_t handler, int sig)
79067 {
79068 /* Is it explicitly or implicitly ignored? */
79069 return handler == SIG_IGN ||
79070@@ -64,7 +64,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
79071
79072 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
79073 {
79074- void __user *handler;
79075+ __sighandler_t handler;
79076
79077 handler = sig_handler(t, sig);
79078
79079@@ -368,6 +368,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
79080 atomic_inc(&user->sigpending);
79081 rcu_read_unlock();
79082
79083+ if (!override_rlimit)
79084+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
79085+
79086 if (override_rlimit ||
79087 atomic_read(&user->sigpending) <=
79088 task_rlimit(t, RLIMIT_SIGPENDING)) {
79089@@ -495,7 +498,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
79090
79091 int unhandled_signal(struct task_struct *tsk, int sig)
79092 {
79093- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
79094+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
79095 if (is_global_init(tsk))
79096 return 1;
79097 if (handler != SIG_IGN && handler != SIG_DFL)
79098@@ -815,6 +818,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
79099 }
79100 }
79101
79102+ /* allow glibc communication via tgkill to other threads in our
79103+ thread group */
79104+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
79105+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
79106+ && gr_handle_signal(t, sig))
79107+ return -EPERM;
79108+
79109 return security_task_kill(t, info, sig, 0);
79110 }
79111
79112@@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
79113 return send_signal(sig, info, p, 1);
79114 }
79115
79116-static int
79117+int
79118 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
79119 {
79120 return send_signal(sig, info, t, 0);
79121@@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
79122 unsigned long int flags;
79123 int ret, blocked, ignored;
79124 struct k_sigaction *action;
79125+ int is_unhandled = 0;
79126
79127 spin_lock_irqsave(&t->sighand->siglock, flags);
79128 action = &t->sighand->action[sig-1];
79129@@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
79130 }
79131 if (action->sa.sa_handler == SIG_DFL)
79132 t->signal->flags &= ~SIGNAL_UNKILLABLE;
79133+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
79134+ is_unhandled = 1;
79135 ret = specific_send_sig_info(sig, info, t);
79136 spin_unlock_irqrestore(&t->sighand->siglock, flags);
79137
79138+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
79139+ normal operation */
79140+ if (is_unhandled) {
79141+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
79142+ gr_handle_crash(t, sig);
79143+ }
79144+
79145 return ret;
79146 }
79147
79148@@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
79149 ret = check_kill_permission(sig, info, p);
79150 rcu_read_unlock();
79151
79152- if (!ret && sig)
79153+ if (!ret && sig) {
79154 ret = do_send_sig_info(sig, info, p, true);
79155+ if (!ret)
79156+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
79157+ }
79158
79159 return ret;
79160 }
79161@@ -2855,7 +2878,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
79162 int error = -ESRCH;
79163
79164 rcu_read_lock();
79165- p = find_task_by_vpid(pid);
79166+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
79167+ /* allow glibc communication via tgkill to other threads in our
79168+ thread group */
79169+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
79170+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
79171+ p = find_task_by_vpid_unrestricted(pid);
79172+ else
79173+#endif
79174+ p = find_task_by_vpid(pid);
79175 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
79176 error = check_kill_permission(sig, info, p);
79177 /*
79178@@ -2880,7 +2911,7 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
79179
79180 static int do_tkill(pid_t tgid, pid_t pid, int sig)
79181 {
79182- struct siginfo info;
79183+ struct siginfo info = {};
79184
79185 info.si_signo = sig;
79186 info.si_errno = 0;
79187@@ -3138,8 +3169,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
79188 }
79189 seg = get_fs();
79190 set_fs(KERNEL_DS);
79191- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
79192- (stack_t __force __user *) &uoss,
79193+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
79194+ (stack_t __force_user *) &uoss,
79195 compat_user_stack_pointer());
79196 set_fs(seg);
79197 if (ret >= 0 && uoss_ptr) {
79198diff --git a/kernel/smp.c b/kernel/smp.c
79199index 69f38bd..77bbf12 100644
79200--- a/kernel/smp.c
79201+++ b/kernel/smp.c
79202@@ -77,7 +77,7 @@ hotplug_cfd(struct notifier_block *nfb, unsigned long action, void *hcpu)
79203 return NOTIFY_OK;
79204 }
79205
79206-static struct notifier_block __cpuinitdata hotplug_cfd_notifier = {
79207+static struct notifier_block hotplug_cfd_notifier = {
79208 .notifier_call = hotplug_cfd,
79209 };
79210
79211diff --git a/kernel/smpboot.c b/kernel/smpboot.c
79212index d6c5fc0..530560c 100644
79213--- a/kernel/smpboot.c
79214+++ b/kernel/smpboot.c
79215@@ -275,7 +275,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
79216 }
79217 smpboot_unpark_thread(plug_thread, cpu);
79218 }
79219- list_add(&plug_thread->list, &hotplug_threads);
79220+ pax_list_add(&plug_thread->list, &hotplug_threads);
79221 out:
79222 mutex_unlock(&smpboot_threads_lock);
79223 return ret;
79224@@ -292,7 +292,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
79225 {
79226 get_online_cpus();
79227 mutex_lock(&smpboot_threads_lock);
79228- list_del(&plug_thread->list);
79229+ pax_list_del(&plug_thread->list);
79230 smpboot_destroy_threads(plug_thread);
79231 mutex_unlock(&smpboot_threads_lock);
79232 put_online_cpus();
79233diff --git a/kernel/softirq.c b/kernel/softirq.c
79234index ed567ba..e71dabf 100644
79235--- a/kernel/softirq.c
79236+++ b/kernel/softirq.c
79237@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
79238 EXPORT_SYMBOL(irq_stat);
79239 #endif
79240
79241-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
79242+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
79243
79244 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
79245
79246-char *softirq_to_name[NR_SOFTIRQS] = {
79247+const char * const softirq_to_name[NR_SOFTIRQS] = {
79248 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
79249 "TASKLET", "SCHED", "HRTIMER", "RCU"
79250 };
79251@@ -244,7 +244,7 @@ restart:
79252 kstat_incr_softirqs_this_cpu(vec_nr);
79253
79254 trace_softirq_entry(vec_nr);
79255- h->action(h);
79256+ h->action();
79257 trace_softirq_exit(vec_nr);
79258 if (unlikely(prev_count != preempt_count())) {
79259 printk(KERN_ERR "huh, entered softirq %u %s %p"
79260@@ -391,7 +391,7 @@ void __raise_softirq_irqoff(unsigned int nr)
79261 or_softirq_pending(1UL << nr);
79262 }
79263
79264-void open_softirq(int nr, void (*action)(struct softirq_action *))
79265+void __init open_softirq(int nr, void (*action)(void))
79266 {
79267 softirq_vec[nr].action = action;
79268 }
79269@@ -447,7 +447,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
79270
79271 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
79272
79273-static void tasklet_action(struct softirq_action *a)
79274+static void tasklet_action(void)
79275 {
79276 struct tasklet_struct *list;
79277
79278@@ -482,7 +482,7 @@ static void tasklet_action(struct softirq_action *a)
79279 }
79280 }
79281
79282-static void tasklet_hi_action(struct softirq_action *a)
79283+static void tasklet_hi_action(void)
79284 {
79285 struct tasklet_struct *list;
79286
79287@@ -718,7 +718,7 @@ static int __cpuinit remote_softirq_cpu_notify(struct notifier_block *self,
79288 return NOTIFY_OK;
79289 }
79290
79291-static struct notifier_block __cpuinitdata remote_softirq_cpu_notifier = {
79292+static struct notifier_block remote_softirq_cpu_notifier = {
79293 .notifier_call = remote_softirq_cpu_notify,
79294 };
79295
79296@@ -835,11 +835,11 @@ static int __cpuinit cpu_callback(struct notifier_block *nfb,
79297 return NOTIFY_OK;
79298 }
79299
79300-static struct notifier_block __cpuinitdata cpu_nfb = {
79301+static struct notifier_block cpu_nfb = {
79302 .notifier_call = cpu_callback
79303 };
79304
79305-static struct smp_hotplug_thread softirq_threads = {
79306+static struct smp_hotplug_thread softirq_threads __read_only = {
79307 .store = &ksoftirqd,
79308 .thread_should_run = ksoftirqd_should_run,
79309 .thread_fn = run_ksoftirqd,
79310diff --git a/kernel/srcu.c b/kernel/srcu.c
79311index 2b85982..d52ab26 100644
79312--- a/kernel/srcu.c
79313+++ b/kernel/srcu.c
79314@@ -305,9 +305,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
79315 preempt_disable();
79316 idx = rcu_dereference_index_check(sp->completed,
79317 rcu_read_lock_sched_held()) & 0x1;
79318- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
79319+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
79320 smp_mb(); /* B */ /* Avoid leaking the critical section. */
79321- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
79322+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
79323 preempt_enable();
79324 return idx;
79325 }
79326@@ -323,7 +323,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
79327 {
79328 preempt_disable();
79329 smp_mb(); /* C */ /* Avoid leaking the critical section. */
79330- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
79331+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
79332 preempt_enable();
79333 }
79334 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
79335diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c
79336index 2f194e9..2c05ea9 100644
79337--- a/kernel/stop_machine.c
79338+++ b/kernel/stop_machine.c
79339@@ -362,7 +362,7 @@ static int __cpuinit cpu_stop_cpu_callback(struct notifier_block *nfb,
79340 * cpu notifiers. It currently shares the same priority as sched
79341 * migration_notifier.
79342 */
79343-static struct notifier_block __cpuinitdata cpu_stop_cpu_notifier = {
79344+static struct notifier_block cpu_stop_cpu_notifier = {
79345 .notifier_call = cpu_stop_cpu_callback,
79346 .priority = 10,
79347 };
79348diff --git a/kernel/sys.c b/kernel/sys.c
79349index 47f1d1b..04c769e 100644
79350--- a/kernel/sys.c
79351+++ b/kernel/sys.c
79352@@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
79353 error = -EACCES;
79354 goto out;
79355 }
79356+
79357+ if (gr_handle_chroot_setpriority(p, niceval)) {
79358+ error = -EACCES;
79359+ goto out;
79360+ }
79361+
79362 no_nice = security_task_setnice(p, niceval);
79363 if (no_nice) {
79364 error = no_nice;
79365@@ -596,6 +602,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
79366 goto error;
79367 }
79368
79369+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
79370+ goto error;
79371+
79372 if (rgid != (gid_t) -1 ||
79373 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
79374 new->sgid = new->egid;
79375@@ -631,6 +640,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
79376 old = current_cred();
79377
79378 retval = -EPERM;
79379+
79380+ if (gr_check_group_change(kgid, kgid, kgid))
79381+ goto error;
79382+
79383 if (nsown_capable(CAP_SETGID))
79384 new->gid = new->egid = new->sgid = new->fsgid = kgid;
79385 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
79386@@ -648,7 +661,7 @@ error:
79387 /*
79388 * change the user struct in a credentials set to match the new UID
79389 */
79390-static int set_user(struct cred *new)
79391+int set_user(struct cred *new)
79392 {
79393 struct user_struct *new_user;
79394
79395@@ -728,6 +741,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
79396 goto error;
79397 }
79398
79399+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
79400+ goto error;
79401+
79402 if (!uid_eq(new->uid, old->uid)) {
79403 retval = set_user(new);
79404 if (retval < 0)
79405@@ -778,6 +794,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
79406 old = current_cred();
79407
79408 retval = -EPERM;
79409+
79410+ if (gr_check_crash_uid(kuid))
79411+ goto error;
79412+ if (gr_check_user_change(kuid, kuid, kuid))
79413+ goto error;
79414+
79415 if (nsown_capable(CAP_SETUID)) {
79416 new->suid = new->uid = kuid;
79417 if (!uid_eq(kuid, old->uid)) {
79418@@ -847,6 +869,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
79419 goto error;
79420 }
79421
79422+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
79423+ goto error;
79424+
79425 if (ruid != (uid_t) -1) {
79426 new->uid = kruid;
79427 if (!uid_eq(kruid, old->uid)) {
79428@@ -929,6 +954,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
79429 goto error;
79430 }
79431
79432+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
79433+ goto error;
79434+
79435 if (rgid != (gid_t) -1)
79436 new->gid = krgid;
79437 if (egid != (gid_t) -1)
79438@@ -990,12 +1018,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
79439 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
79440 nsown_capable(CAP_SETUID)) {
79441 if (!uid_eq(kuid, old->fsuid)) {
79442+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
79443+ goto error;
79444+
79445 new->fsuid = kuid;
79446 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
79447 goto change_okay;
79448 }
79449 }
79450
79451+error:
79452 abort_creds(new);
79453 return old_fsuid;
79454
79455@@ -1028,12 +1060,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
79456 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
79457 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
79458 nsown_capable(CAP_SETGID)) {
79459+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
79460+ goto error;
79461+
79462 if (!gid_eq(kgid, old->fsgid)) {
79463 new->fsgid = kgid;
79464 goto change_okay;
79465 }
79466 }
79467
79468+error:
79469 abort_creds(new);
79470 return old_fsgid;
79471
79472@@ -1341,19 +1377,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
79473 return -EFAULT;
79474
79475 down_read(&uts_sem);
79476- error = __copy_to_user(&name->sysname, &utsname()->sysname,
79477+ error = __copy_to_user(name->sysname, &utsname()->sysname,
79478 __OLD_UTS_LEN);
79479 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
79480- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
79481+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
79482 __OLD_UTS_LEN);
79483 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
79484- error |= __copy_to_user(&name->release, &utsname()->release,
79485+ error |= __copy_to_user(name->release, &utsname()->release,
79486 __OLD_UTS_LEN);
79487 error |= __put_user(0, name->release + __OLD_UTS_LEN);
79488- error |= __copy_to_user(&name->version, &utsname()->version,
79489+ error |= __copy_to_user(name->version, &utsname()->version,
79490 __OLD_UTS_LEN);
79491 error |= __put_user(0, name->version + __OLD_UTS_LEN);
79492- error |= __copy_to_user(&name->machine, &utsname()->machine,
79493+ error |= __copy_to_user(name->machine, &utsname()->machine,
79494 __OLD_UTS_LEN);
79495 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
79496 up_read(&uts_sem);
79497@@ -2027,7 +2063,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
79498 error = get_dumpable(me->mm);
79499 break;
79500 case PR_SET_DUMPABLE:
79501- if (arg2 < 0 || arg2 > 1) {
79502+ if (arg2 > 1) {
79503 error = -EINVAL;
79504 break;
79505 }
79506diff --git a/kernel/sysctl.c b/kernel/sysctl.c
79507index c88878d..e4fa5d1 100644
79508--- a/kernel/sysctl.c
79509+++ b/kernel/sysctl.c
79510@@ -92,7 +92,6 @@
79511
79512
79513 #if defined(CONFIG_SYSCTL)
79514-
79515 /* External variables not in a header file. */
79516 extern int sysctl_overcommit_memory;
79517 extern int sysctl_overcommit_ratio;
79518@@ -172,10 +171,8 @@ static int proc_taint(struct ctl_table *table, int write,
79519 void __user *buffer, size_t *lenp, loff_t *ppos);
79520 #endif
79521
79522-#ifdef CONFIG_PRINTK
79523 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
79524 void __user *buffer, size_t *lenp, loff_t *ppos);
79525-#endif
79526
79527 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
79528 void __user *buffer, size_t *lenp, loff_t *ppos);
79529@@ -206,6 +203,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
79530
79531 #endif
79532
79533+extern struct ctl_table grsecurity_table[];
79534+
79535 static struct ctl_table kern_table[];
79536 static struct ctl_table vm_table[];
79537 static struct ctl_table fs_table[];
79538@@ -220,6 +219,20 @@ extern struct ctl_table epoll_table[];
79539 int sysctl_legacy_va_layout;
79540 #endif
79541
79542+#ifdef CONFIG_PAX_SOFTMODE
79543+static ctl_table pax_table[] = {
79544+ {
79545+ .procname = "softmode",
79546+ .data = &pax_softmode,
79547+ .maxlen = sizeof(unsigned int),
79548+ .mode = 0600,
79549+ .proc_handler = &proc_dointvec,
79550+ },
79551+
79552+ { }
79553+};
79554+#endif
79555+
79556 /* The default sysctl tables: */
79557
79558 static struct ctl_table sysctl_base_table[] = {
79559@@ -268,6 +281,22 @@ static int max_extfrag_threshold = 1000;
79560 #endif
79561
79562 static struct ctl_table kern_table[] = {
79563+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
79564+ {
79565+ .procname = "grsecurity",
79566+ .mode = 0500,
79567+ .child = grsecurity_table,
79568+ },
79569+#endif
79570+
79571+#ifdef CONFIG_PAX_SOFTMODE
79572+ {
79573+ .procname = "pax",
79574+ .mode = 0500,
79575+ .child = pax_table,
79576+ },
79577+#endif
79578+
79579 {
79580 .procname = "sched_child_runs_first",
79581 .data = &sysctl_sched_child_runs_first,
79582@@ -593,7 +622,7 @@ static struct ctl_table kern_table[] = {
79583 .data = &modprobe_path,
79584 .maxlen = KMOD_PATH_LEN,
79585 .mode = 0644,
79586- .proc_handler = proc_dostring,
79587+ .proc_handler = proc_dostring_modpriv,
79588 },
79589 {
79590 .procname = "modules_disabled",
79591@@ -760,16 +789,20 @@ static struct ctl_table kern_table[] = {
79592 .extra1 = &zero,
79593 .extra2 = &one,
79594 },
79595+#endif
79596 {
79597 .procname = "kptr_restrict",
79598 .data = &kptr_restrict,
79599 .maxlen = sizeof(int),
79600 .mode = 0644,
79601 .proc_handler = proc_dointvec_minmax_sysadmin,
79602+#ifdef CONFIG_GRKERNSEC_HIDESYM
79603+ .extra1 = &two,
79604+#else
79605 .extra1 = &zero,
79606+#endif
79607 .extra2 = &two,
79608 },
79609-#endif
79610 {
79611 .procname = "ngroups_max",
79612 .data = &ngroups_max,
79613@@ -1266,6 +1299,13 @@ static struct ctl_table vm_table[] = {
79614 .proc_handler = proc_dointvec_minmax,
79615 .extra1 = &zero,
79616 },
79617+ {
79618+ .procname = "heap_stack_gap",
79619+ .data = &sysctl_heap_stack_gap,
79620+ .maxlen = sizeof(sysctl_heap_stack_gap),
79621+ .mode = 0644,
79622+ .proc_handler = proc_doulongvec_minmax,
79623+ },
79624 #else
79625 {
79626 .procname = "nr_trim_pages",
79627@@ -1716,6 +1756,16 @@ int proc_dostring(struct ctl_table *table, int write,
79628 buffer, lenp, ppos);
79629 }
79630
79631+int proc_dostring_modpriv(struct ctl_table *table, int write,
79632+ void __user *buffer, size_t *lenp, loff_t *ppos)
79633+{
79634+ if (write && !capable(CAP_SYS_MODULE))
79635+ return -EPERM;
79636+
79637+ return _proc_do_string(table->data, table->maxlen, write,
79638+ buffer, lenp, ppos);
79639+}
79640+
79641 static size_t proc_skip_spaces(char **buf)
79642 {
79643 size_t ret;
79644@@ -1821,6 +1871,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
79645 len = strlen(tmp);
79646 if (len > *size)
79647 len = *size;
79648+ if (len > sizeof(tmp))
79649+ len = sizeof(tmp);
79650 if (copy_to_user(*buf, tmp, len))
79651 return -EFAULT;
79652 *size -= len;
79653@@ -1985,7 +2037,7 @@ int proc_dointvec(struct ctl_table *table, int write,
79654 static int proc_taint(struct ctl_table *table, int write,
79655 void __user *buffer, size_t *lenp, loff_t *ppos)
79656 {
79657- struct ctl_table t;
79658+ ctl_table_no_const t;
79659 unsigned long tmptaint = get_taint();
79660 int err;
79661
79662@@ -2013,7 +2065,6 @@ static int proc_taint(struct ctl_table *table, int write,
79663 return err;
79664 }
79665
79666-#ifdef CONFIG_PRINTK
79667 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
79668 void __user *buffer, size_t *lenp, loff_t *ppos)
79669 {
79670@@ -2022,7 +2073,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
79671
79672 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
79673 }
79674-#endif
79675
79676 struct do_proc_dointvec_minmax_conv_param {
79677 int *min;
79678@@ -2169,8 +2219,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
79679 *i = val;
79680 } else {
79681 val = convdiv * (*i) / convmul;
79682- if (!first)
79683+ if (!first) {
79684 err = proc_put_char(&buffer, &left, '\t');
79685+ if (err)
79686+ break;
79687+ }
79688 err = proc_put_long(&buffer, &left, val, false);
79689 if (err)
79690 break;
79691@@ -2562,6 +2615,12 @@ int proc_dostring(struct ctl_table *table, int write,
79692 return -ENOSYS;
79693 }
79694
79695+int proc_dostring_modpriv(struct ctl_table *table, int write,
79696+ void __user *buffer, size_t *lenp, loff_t *ppos)
79697+{
79698+ return -ENOSYS;
79699+}
79700+
79701 int proc_dointvec(struct ctl_table *table, int write,
79702 void __user *buffer, size_t *lenp, loff_t *ppos)
79703 {
79704@@ -2618,5 +2677,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
79705 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
79706 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
79707 EXPORT_SYMBOL(proc_dostring);
79708+EXPORT_SYMBOL(proc_dostring_modpriv);
79709 EXPORT_SYMBOL(proc_doulongvec_minmax);
79710 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
79711diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
79712index 0ddf3a0..a199f50 100644
79713--- a/kernel/sysctl_binary.c
79714+++ b/kernel/sysctl_binary.c
79715@@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
79716 int i;
79717
79718 set_fs(KERNEL_DS);
79719- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
79720+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
79721 set_fs(old_fs);
79722 if (result < 0)
79723 goto out_kfree;
79724@@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
79725 }
79726
79727 set_fs(KERNEL_DS);
79728- result = vfs_write(file, buffer, str - buffer, &pos);
79729+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
79730 set_fs(old_fs);
79731 if (result < 0)
79732 goto out_kfree;
79733@@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
79734 int i;
79735
79736 set_fs(KERNEL_DS);
79737- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
79738+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
79739 set_fs(old_fs);
79740 if (result < 0)
79741 goto out_kfree;
79742@@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
79743 }
79744
79745 set_fs(KERNEL_DS);
79746- result = vfs_write(file, buffer, str - buffer, &pos);
79747+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
79748 set_fs(old_fs);
79749 if (result < 0)
79750 goto out_kfree;
79751@@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
79752 int i;
79753
79754 set_fs(KERNEL_DS);
79755- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
79756+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
79757 set_fs(old_fs);
79758 if (result < 0)
79759 goto out;
79760@@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
79761 __le16 dnaddr;
79762
79763 set_fs(KERNEL_DS);
79764- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
79765+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
79766 set_fs(old_fs);
79767 if (result < 0)
79768 goto out;
79769@@ -1234,7 +1234,7 @@ static ssize_t bin_dn_node_address(struct file *file,
79770 le16_to_cpu(dnaddr) & 0x3ff);
79771
79772 set_fs(KERNEL_DS);
79773- result = vfs_write(file, buf, len, &pos);
79774+ result = vfs_write(file, (const char __force_user *)buf, len, &pos);
79775 set_fs(old_fs);
79776 if (result < 0)
79777 goto out;
79778diff --git a/kernel/taskstats.c b/kernel/taskstats.c
79779index 145bb4d..b2aa969 100644
79780--- a/kernel/taskstats.c
79781+++ b/kernel/taskstats.c
79782@@ -28,9 +28,12 @@
79783 #include <linux/fs.h>
79784 #include <linux/file.h>
79785 #include <linux/pid_namespace.h>
79786+#include <linux/grsecurity.h>
79787 #include <net/genetlink.h>
79788 #include <linux/atomic.h>
79789
79790+extern int gr_is_taskstats_denied(int pid);
79791+
79792 /*
79793 * Maximum length of a cpumask that can be specified in
79794 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
79795@@ -570,6 +573,9 @@ err:
79796
79797 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
79798 {
79799+ if (gr_is_taskstats_denied(current->pid))
79800+ return -EACCES;
79801+
79802 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
79803 return cmd_attr_register_cpumask(info);
79804 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
79805diff --git a/kernel/time.c b/kernel/time.c
79806index d226c6a..2f0d217 100644
79807--- a/kernel/time.c
79808+++ b/kernel/time.c
79809@@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
79810 return error;
79811
79812 if (tz) {
79813+ /* we log in do_settimeofday called below, so don't log twice
79814+ */
79815+ if (!tv)
79816+ gr_log_timechange();
79817+
79818 sys_tz = *tz;
79819 update_vsyscall_tz();
79820 if (firsttime) {
79821@@ -493,7 +498,7 @@ EXPORT_SYMBOL(usecs_to_jiffies);
79822 * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec
79823 * value to a scaled second value.
79824 */
79825-unsigned long
79826+unsigned long __intentional_overflow(-1)
79827 timespec_to_jiffies(const struct timespec *value)
79828 {
79829 unsigned long sec = value->tv_sec;
79830diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
79831index f11d83b..d016d91 100644
79832--- a/kernel/time/alarmtimer.c
79833+++ b/kernel/time/alarmtimer.c
79834@@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
79835 struct platform_device *pdev;
79836 int error = 0;
79837 int i;
79838- struct k_clock alarm_clock = {
79839+ static struct k_clock alarm_clock = {
79840 .clock_getres = alarm_clock_getres,
79841 .clock_get = alarm_clock_get,
79842 .timer_create = alarm_timer_create,
79843diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
79844index a13987a..36cd791 100644
79845--- a/kernel/time/tick-broadcast.c
79846+++ b/kernel/time/tick-broadcast.c
79847@@ -116,7 +116,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
79848 * then clear the broadcast bit.
79849 */
79850 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
79851- int cpu = smp_processor_id();
79852+ cpu = smp_processor_id();
79853
79854 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
79855 tick_broadcast_clear_oneshot(cpu);
79856diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
79857index cbc6acb..3a77191 100644
79858--- a/kernel/time/timekeeping.c
79859+++ b/kernel/time/timekeeping.c
79860@@ -15,6 +15,7 @@
79861 #include <linux/init.h>
79862 #include <linux/mm.h>
79863 #include <linux/sched.h>
79864+#include <linux/grsecurity.h>
79865 #include <linux/syscore_ops.h>
79866 #include <linux/clocksource.h>
79867 #include <linux/jiffies.h>
79868@@ -412,6 +413,8 @@ int do_settimeofday(const struct timespec *tv)
79869 if (!timespec_valid_strict(tv))
79870 return -EINVAL;
79871
79872+ gr_log_timechange();
79873+
79874 write_seqlock_irqsave(&tk->lock, flags);
79875
79876 timekeeping_forward_now(tk);
79877diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
79878index af5a7e9..715611a 100644
79879--- a/kernel/time/timer_list.c
79880+++ b/kernel/time/timer_list.c
79881@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
79882
79883 static void print_name_offset(struct seq_file *m, void *sym)
79884 {
79885+#ifdef CONFIG_GRKERNSEC_HIDESYM
79886+ SEQ_printf(m, "<%p>", NULL);
79887+#else
79888 char symname[KSYM_NAME_LEN];
79889
79890 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
79891 SEQ_printf(m, "<%pK>", sym);
79892 else
79893 SEQ_printf(m, "%s", symname);
79894+#endif
79895 }
79896
79897 static void
79898@@ -112,7 +116,11 @@ next_one:
79899 static void
79900 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
79901 {
79902+#ifdef CONFIG_GRKERNSEC_HIDESYM
79903+ SEQ_printf(m, " .base: %p\n", NULL);
79904+#else
79905 SEQ_printf(m, " .base: %pK\n", base);
79906+#endif
79907 SEQ_printf(m, " .index: %d\n",
79908 base->index);
79909 SEQ_printf(m, " .resolution: %Lu nsecs\n",
79910@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
79911 {
79912 struct proc_dir_entry *pe;
79913
79914+#ifdef CONFIG_GRKERNSEC_PROC_ADD
79915+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
79916+#else
79917 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
79918+#endif
79919 if (!pe)
79920 return -ENOMEM;
79921 return 0;
79922diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
79923index 0b537f2..40d6c20 100644
79924--- a/kernel/time/timer_stats.c
79925+++ b/kernel/time/timer_stats.c
79926@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
79927 static unsigned long nr_entries;
79928 static struct entry entries[MAX_ENTRIES];
79929
79930-static atomic_t overflow_count;
79931+static atomic_unchecked_t overflow_count;
79932
79933 /*
79934 * The entries are in a hash-table, for fast lookup:
79935@@ -140,7 +140,7 @@ static void reset_entries(void)
79936 nr_entries = 0;
79937 memset(entries, 0, sizeof(entries));
79938 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
79939- atomic_set(&overflow_count, 0);
79940+ atomic_set_unchecked(&overflow_count, 0);
79941 }
79942
79943 static struct entry *alloc_entry(void)
79944@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
79945 if (likely(entry))
79946 entry->count++;
79947 else
79948- atomic_inc(&overflow_count);
79949+ atomic_inc_unchecked(&overflow_count);
79950
79951 out_unlock:
79952 raw_spin_unlock_irqrestore(lock, flags);
79953@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
79954
79955 static void print_name_offset(struct seq_file *m, unsigned long addr)
79956 {
79957+#ifdef CONFIG_GRKERNSEC_HIDESYM
79958+ seq_printf(m, "<%p>", NULL);
79959+#else
79960 char symname[KSYM_NAME_LEN];
79961
79962 if (lookup_symbol_name(addr, symname) < 0)
79963- seq_printf(m, "<%p>", (void *)addr);
79964+ seq_printf(m, "<%pK>", (void *)addr);
79965 else
79966 seq_printf(m, "%s", symname);
79967+#endif
79968 }
79969
79970 static int tstats_show(struct seq_file *m, void *v)
79971@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
79972
79973 seq_puts(m, "Timer Stats Version: v0.2\n");
79974 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
79975- if (atomic_read(&overflow_count))
79976+ if (atomic_read_unchecked(&overflow_count))
79977 seq_printf(m, "Overflow: %d entries\n",
79978- atomic_read(&overflow_count));
79979+ atomic_read_unchecked(&overflow_count));
79980
79981 for (i = 0; i < nr_entries; i++) {
79982 entry = entries + i;
79983@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
79984 {
79985 struct proc_dir_entry *pe;
79986
79987+#ifdef CONFIG_GRKERNSEC_PROC_ADD
79988+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
79989+#else
79990 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
79991+#endif
79992 if (!pe)
79993 return -ENOMEM;
79994 return 0;
79995diff --git a/kernel/timer.c b/kernel/timer.c
79996index 367d008..5dee98f 100644
79997--- a/kernel/timer.c
79998+++ b/kernel/timer.c
79999@@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
80000 /*
80001 * This function runs timers and the timer-tq in bottom half context.
80002 */
80003-static void run_timer_softirq(struct softirq_action *h)
80004+static void run_timer_softirq(void)
80005 {
80006 struct tvec_base *base = __this_cpu_read(tvec_bases);
80007
80008@@ -1481,7 +1481,7 @@ static void process_timeout(unsigned long __data)
80009 *
80010 * In all cases the return value is guaranteed to be non-negative.
80011 */
80012-signed long __sched schedule_timeout(signed long timeout)
80013+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
80014 {
80015 struct timer_list timer;
80016 unsigned long expire;
80017@@ -1772,7 +1772,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
80018 return NOTIFY_OK;
80019 }
80020
80021-static struct notifier_block __cpuinitdata timers_nb = {
80022+static struct notifier_block timers_nb = {
80023 .notifier_call = timer_cpu_notify,
80024 };
80025
80026diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
80027index c0bd030..62a1927 100644
80028--- a/kernel/trace/blktrace.c
80029+++ b/kernel/trace/blktrace.c
80030@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
80031 struct blk_trace *bt = filp->private_data;
80032 char buf[16];
80033
80034- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
80035+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
80036
80037 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
80038 }
80039@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
80040 return 1;
80041
80042 bt = buf->chan->private_data;
80043- atomic_inc(&bt->dropped);
80044+ atomic_inc_unchecked(&bt->dropped);
80045 return 0;
80046 }
80047
80048@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
80049
80050 bt->dir = dir;
80051 bt->dev = dev;
80052- atomic_set(&bt->dropped, 0);
80053+ atomic_set_unchecked(&bt->dropped, 0);
80054
80055 ret = -EIO;
80056 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
80057diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
80058index 35cc3a8..2a47da3 100644
80059--- a/kernel/trace/ftrace.c
80060+++ b/kernel/trace/ftrace.c
80061@@ -1886,12 +1886,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
80062 if (unlikely(ftrace_disabled))
80063 return 0;
80064
80065+ ret = ftrace_arch_code_modify_prepare();
80066+ FTRACE_WARN_ON(ret);
80067+ if (ret)
80068+ return 0;
80069+
80070 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
80071+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
80072 if (ret) {
80073 ftrace_bug(ret, ip);
80074- return 0;
80075 }
80076- return 1;
80077+ return ret ? 0 : 1;
80078 }
80079
80080 /*
80081@@ -2964,7 +2969,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
80082
80083 int
80084 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
80085- void *data)
80086+ void *data)
80087 {
80088 struct ftrace_func_probe *entry;
80089 struct ftrace_page *pg;
80090@@ -3831,8 +3836,10 @@ static int ftrace_process_locs(struct module *mod,
80091 if (!count)
80092 return 0;
80093
80094+ pax_open_kernel();
80095 sort(start, count, sizeof(*start),
80096 ftrace_cmp_ips, ftrace_swap_ips);
80097+ pax_close_kernel();
80098
80099 start_pg = ftrace_allocate_pages(count);
80100 if (!start_pg)
80101@@ -4554,8 +4561,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
80102 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
80103
80104 static int ftrace_graph_active;
80105-static struct notifier_block ftrace_suspend_notifier;
80106-
80107 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
80108 {
80109 return 0;
80110@@ -4699,6 +4704,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
80111 return NOTIFY_DONE;
80112 }
80113
80114+static struct notifier_block ftrace_suspend_notifier = {
80115+ .notifier_call = ftrace_suspend_notifier_call
80116+};
80117+
80118 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
80119 trace_func_graph_ent_t entryfunc)
80120 {
80121@@ -4712,7 +4721,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
80122 goto out;
80123 }
80124
80125- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
80126 register_pm_notifier(&ftrace_suspend_notifier);
80127
80128 ftrace_graph_active++;
80129diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
80130index ce8514f..8233573 100644
80131--- a/kernel/trace/ring_buffer.c
80132+++ b/kernel/trace/ring_buffer.c
80133@@ -346,9 +346,9 @@ struct buffer_data_page {
80134 */
80135 struct buffer_page {
80136 struct list_head list; /* list of buffer pages */
80137- local_t write; /* index for next write */
80138+ local_unchecked_t write; /* index for next write */
80139 unsigned read; /* index for next read */
80140- local_t entries; /* entries on this page */
80141+ local_unchecked_t entries; /* entries on this page */
80142 unsigned long real_end; /* real end of data */
80143 struct buffer_data_page *page; /* Actual data page */
80144 };
80145@@ -461,8 +461,8 @@ struct ring_buffer_per_cpu {
80146 unsigned long last_overrun;
80147 local_t entries_bytes;
80148 local_t entries;
80149- local_t overrun;
80150- local_t commit_overrun;
80151+ local_unchecked_t overrun;
80152+ local_unchecked_t commit_overrun;
80153 local_t dropped_events;
80154 local_t committing;
80155 local_t commits;
80156@@ -861,8 +861,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
80157 *
80158 * We add a counter to the write field to denote this.
80159 */
80160- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
80161- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
80162+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
80163+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
80164
80165 /*
80166 * Just make sure we have seen our old_write and synchronize
80167@@ -890,8 +890,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
80168 * cmpxchg to only update if an interrupt did not already
80169 * do it for us. If the cmpxchg fails, we don't care.
80170 */
80171- (void)local_cmpxchg(&next_page->write, old_write, val);
80172- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
80173+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
80174+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
80175
80176 /*
80177 * No need to worry about races with clearing out the commit.
80178@@ -1250,12 +1250,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
80179
80180 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
80181 {
80182- return local_read(&bpage->entries) & RB_WRITE_MASK;
80183+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
80184 }
80185
80186 static inline unsigned long rb_page_write(struct buffer_page *bpage)
80187 {
80188- return local_read(&bpage->write) & RB_WRITE_MASK;
80189+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
80190 }
80191
80192 static int
80193@@ -1350,7 +1350,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
80194 * bytes consumed in ring buffer from here.
80195 * Increment overrun to account for the lost events.
80196 */
80197- local_add(page_entries, &cpu_buffer->overrun);
80198+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
80199 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
80200 }
80201
80202@@ -1906,7 +1906,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
80203 * it is our responsibility to update
80204 * the counters.
80205 */
80206- local_add(entries, &cpu_buffer->overrun);
80207+ local_add_unchecked(entries, &cpu_buffer->overrun);
80208 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
80209
80210 /*
80211@@ -2056,7 +2056,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
80212 if (tail == BUF_PAGE_SIZE)
80213 tail_page->real_end = 0;
80214
80215- local_sub(length, &tail_page->write);
80216+ local_sub_unchecked(length, &tail_page->write);
80217 return;
80218 }
80219
80220@@ -2091,7 +2091,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
80221 rb_event_set_padding(event);
80222
80223 /* Set the write back to the previous setting */
80224- local_sub(length, &tail_page->write);
80225+ local_sub_unchecked(length, &tail_page->write);
80226 return;
80227 }
80228
80229@@ -2103,7 +2103,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
80230
80231 /* Set write to end of buffer */
80232 length = (tail + length) - BUF_PAGE_SIZE;
80233- local_sub(length, &tail_page->write);
80234+ local_sub_unchecked(length, &tail_page->write);
80235 }
80236
80237 /*
80238@@ -2129,7 +2129,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
80239 * about it.
80240 */
80241 if (unlikely(next_page == commit_page)) {
80242- local_inc(&cpu_buffer->commit_overrun);
80243+ local_inc_unchecked(&cpu_buffer->commit_overrun);
80244 goto out_reset;
80245 }
80246
80247@@ -2185,7 +2185,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
80248 cpu_buffer->tail_page) &&
80249 (cpu_buffer->commit_page ==
80250 cpu_buffer->reader_page))) {
80251- local_inc(&cpu_buffer->commit_overrun);
80252+ local_inc_unchecked(&cpu_buffer->commit_overrun);
80253 goto out_reset;
80254 }
80255 }
80256@@ -2233,7 +2233,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
80257 length += RB_LEN_TIME_EXTEND;
80258
80259 tail_page = cpu_buffer->tail_page;
80260- write = local_add_return(length, &tail_page->write);
80261+ write = local_add_return_unchecked(length, &tail_page->write);
80262
80263 /* set write to only the index of the write */
80264 write &= RB_WRITE_MASK;
80265@@ -2250,7 +2250,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
80266 kmemcheck_annotate_bitfield(event, bitfield);
80267 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
80268
80269- local_inc(&tail_page->entries);
80270+ local_inc_unchecked(&tail_page->entries);
80271
80272 /*
80273 * If this is the first commit on the page, then update
80274@@ -2283,7 +2283,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
80275
80276 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
80277 unsigned long write_mask =
80278- local_read(&bpage->write) & ~RB_WRITE_MASK;
80279+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
80280 unsigned long event_length = rb_event_length(event);
80281 /*
80282 * This is on the tail page. It is possible that
80283@@ -2293,7 +2293,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
80284 */
80285 old_index += write_mask;
80286 new_index += write_mask;
80287- index = local_cmpxchg(&bpage->write, old_index, new_index);
80288+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
80289 if (index == old_index) {
80290 /* update counters */
80291 local_sub(event_length, &cpu_buffer->entries_bytes);
80292@@ -2632,7 +2632,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
80293
80294 /* Do the likely case first */
80295 if (likely(bpage->page == (void *)addr)) {
80296- local_dec(&bpage->entries);
80297+ local_dec_unchecked(&bpage->entries);
80298 return;
80299 }
80300
80301@@ -2644,7 +2644,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
80302 start = bpage;
80303 do {
80304 if (bpage->page == (void *)addr) {
80305- local_dec(&bpage->entries);
80306+ local_dec_unchecked(&bpage->entries);
80307 return;
80308 }
80309 rb_inc_page(cpu_buffer, &bpage);
80310@@ -2926,7 +2926,7 @@ static inline unsigned long
80311 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
80312 {
80313 return local_read(&cpu_buffer->entries) -
80314- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
80315+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
80316 }
80317
80318 /**
80319@@ -3015,7 +3015,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
80320 return 0;
80321
80322 cpu_buffer = buffer->buffers[cpu];
80323- ret = local_read(&cpu_buffer->overrun);
80324+ ret = local_read_unchecked(&cpu_buffer->overrun);
80325
80326 return ret;
80327 }
80328@@ -3038,7 +3038,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
80329 return 0;
80330
80331 cpu_buffer = buffer->buffers[cpu];
80332- ret = local_read(&cpu_buffer->commit_overrun);
80333+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
80334
80335 return ret;
80336 }
80337@@ -3105,7 +3105,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
80338 /* if you care about this being correct, lock the buffer */
80339 for_each_buffer_cpu(buffer, cpu) {
80340 cpu_buffer = buffer->buffers[cpu];
80341- overruns += local_read(&cpu_buffer->overrun);
80342+ overruns += local_read_unchecked(&cpu_buffer->overrun);
80343 }
80344
80345 return overruns;
80346@@ -3281,8 +3281,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
80347 /*
80348 * Reset the reader page to size zero.
80349 */
80350- local_set(&cpu_buffer->reader_page->write, 0);
80351- local_set(&cpu_buffer->reader_page->entries, 0);
80352+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
80353+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
80354 local_set(&cpu_buffer->reader_page->page->commit, 0);
80355 cpu_buffer->reader_page->real_end = 0;
80356
80357@@ -3316,7 +3316,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
80358 * want to compare with the last_overrun.
80359 */
80360 smp_mb();
80361- overwrite = local_read(&(cpu_buffer->overrun));
80362+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
80363
80364 /*
80365 * Here's the tricky part.
80366@@ -3886,8 +3886,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
80367
80368 cpu_buffer->head_page
80369 = list_entry(cpu_buffer->pages, struct buffer_page, list);
80370- local_set(&cpu_buffer->head_page->write, 0);
80371- local_set(&cpu_buffer->head_page->entries, 0);
80372+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
80373+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
80374 local_set(&cpu_buffer->head_page->page->commit, 0);
80375
80376 cpu_buffer->head_page->read = 0;
80377@@ -3897,14 +3897,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
80378
80379 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
80380 INIT_LIST_HEAD(&cpu_buffer->new_pages);
80381- local_set(&cpu_buffer->reader_page->write, 0);
80382- local_set(&cpu_buffer->reader_page->entries, 0);
80383+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
80384+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
80385 local_set(&cpu_buffer->reader_page->page->commit, 0);
80386 cpu_buffer->reader_page->read = 0;
80387
80388 local_set(&cpu_buffer->entries_bytes, 0);
80389- local_set(&cpu_buffer->overrun, 0);
80390- local_set(&cpu_buffer->commit_overrun, 0);
80391+ local_set_unchecked(&cpu_buffer->overrun, 0);
80392+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
80393 local_set(&cpu_buffer->dropped_events, 0);
80394 local_set(&cpu_buffer->entries, 0);
80395 local_set(&cpu_buffer->committing, 0);
80396@@ -4308,8 +4308,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
80397 rb_init_page(bpage);
80398 bpage = reader->page;
80399 reader->page = *data_page;
80400- local_set(&reader->write, 0);
80401- local_set(&reader->entries, 0);
80402+ local_set_unchecked(&reader->write, 0);
80403+ local_set_unchecked(&reader->entries, 0);
80404 reader->read = 0;
80405 *data_page = bpage;
80406
80407diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
80408index fe1d581..43a0f38 100644
80409--- a/kernel/trace/trace.c
80410+++ b/kernel/trace/trace.c
80411@@ -4494,10 +4494,9 @@ static const struct file_operations tracing_dyn_info_fops = {
80412 };
80413 #endif
80414
80415-static struct dentry *d_tracer;
80416-
80417 struct dentry *tracing_init_dentry(void)
80418 {
80419+ static struct dentry *d_tracer;
80420 static int once;
80421
80422 if (d_tracer)
80423@@ -4517,10 +4516,9 @@ struct dentry *tracing_init_dentry(void)
80424 return d_tracer;
80425 }
80426
80427-static struct dentry *d_percpu;
80428-
80429 struct dentry *tracing_dentry_percpu(void)
80430 {
80431+ static struct dentry *d_percpu;
80432 static int once;
80433 struct dentry *d_tracer;
80434
80435diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
80436index 880073d..42db7c3 100644
80437--- a/kernel/trace/trace_events.c
80438+++ b/kernel/trace/trace_events.c
80439@@ -1330,10 +1330,6 @@ static LIST_HEAD(ftrace_module_file_list);
80440 struct ftrace_module_file_ops {
80441 struct list_head list;
80442 struct module *mod;
80443- struct file_operations id;
80444- struct file_operations enable;
80445- struct file_operations format;
80446- struct file_operations filter;
80447 };
80448
80449 static struct ftrace_module_file_ops *
80450@@ -1354,17 +1350,12 @@ trace_create_file_ops(struct module *mod)
80451
80452 file_ops->mod = mod;
80453
80454- file_ops->id = ftrace_event_id_fops;
80455- file_ops->id.owner = mod;
80456-
80457- file_ops->enable = ftrace_enable_fops;
80458- file_ops->enable.owner = mod;
80459-
80460- file_ops->filter = ftrace_event_filter_fops;
80461- file_ops->filter.owner = mod;
80462-
80463- file_ops->format = ftrace_event_format_fops;
80464- file_ops->format.owner = mod;
80465+ pax_open_kernel();
80466+ mod->trace_id.owner = mod;
80467+ mod->trace_enable.owner = mod;
80468+ mod->trace_filter.owner = mod;
80469+ mod->trace_format.owner = mod;
80470+ pax_close_kernel();
80471
80472 list_add(&file_ops->list, &ftrace_module_file_list);
80473
80474@@ -1388,8 +1379,8 @@ static void trace_module_add_events(struct module *mod)
80475
80476 for_each_event(call, start, end) {
80477 __trace_add_event_call(*call, mod,
80478- &file_ops->id, &file_ops->enable,
80479- &file_ops->filter, &file_ops->format);
80480+ &mod->trace_id, &mod->trace_enable,
80481+ &mod->trace_filter, &mod->trace_format);
80482 }
80483 }
80484
80485diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
80486index fd3c8aa..5f324a6 100644
80487--- a/kernel/trace/trace_mmiotrace.c
80488+++ b/kernel/trace/trace_mmiotrace.c
80489@@ -24,7 +24,7 @@ struct header_iter {
80490 static struct trace_array *mmio_trace_array;
80491 static bool overrun_detected;
80492 static unsigned long prev_overruns;
80493-static atomic_t dropped_count;
80494+static atomic_unchecked_t dropped_count;
80495
80496 static void mmio_reset_data(struct trace_array *tr)
80497 {
80498@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
80499
80500 static unsigned long count_overruns(struct trace_iterator *iter)
80501 {
80502- unsigned long cnt = atomic_xchg(&dropped_count, 0);
80503+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
80504 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
80505
80506 if (over > prev_overruns)
80507@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
80508 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
80509 sizeof(*entry), 0, pc);
80510 if (!event) {
80511- atomic_inc(&dropped_count);
80512+ atomic_inc_unchecked(&dropped_count);
80513 return;
80514 }
80515 entry = ring_buffer_event_data(event);
80516@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
80517 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
80518 sizeof(*entry), 0, pc);
80519 if (!event) {
80520- atomic_inc(&dropped_count);
80521+ atomic_inc_unchecked(&dropped_count);
80522 return;
80523 }
80524 entry = ring_buffer_event_data(event);
80525diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
80526index 194d796..76edb8f 100644
80527--- a/kernel/trace/trace_output.c
80528+++ b/kernel/trace/trace_output.c
80529@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
80530
80531 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
80532 if (!IS_ERR(p)) {
80533- p = mangle_path(s->buffer + s->len, p, "\n");
80534+ p = mangle_path(s->buffer + s->len, p, "\n\\");
80535 if (p) {
80536 s->len = p - s->buffer;
80537 return 1;
80538@@ -852,14 +852,16 @@ int register_ftrace_event(struct trace_event *event)
80539 goto out;
80540 }
80541
80542+ pax_open_kernel();
80543 if (event->funcs->trace == NULL)
80544- event->funcs->trace = trace_nop_print;
80545+ *(void **)&event->funcs->trace = trace_nop_print;
80546 if (event->funcs->raw == NULL)
80547- event->funcs->raw = trace_nop_print;
80548+ *(void **)&event->funcs->raw = trace_nop_print;
80549 if (event->funcs->hex == NULL)
80550- event->funcs->hex = trace_nop_print;
80551+ *(void **)&event->funcs->hex = trace_nop_print;
80552 if (event->funcs->binary == NULL)
80553- event->funcs->binary = trace_nop_print;
80554+ *(void **)&event->funcs->binary = trace_nop_print;
80555+ pax_close_kernel();
80556
80557 key = event->type & (EVENT_HASHSIZE - 1);
80558
80559diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
80560index 83a8b5b..0bf39a9 100644
80561--- a/kernel/trace/trace_stack.c
80562+++ b/kernel/trace/trace_stack.c
80563@@ -52,7 +52,7 @@ static inline void check_stack(void)
80564 return;
80565
80566 /* we do not handle interrupt stacks yet */
80567- if (!object_is_on_stack(&this_size))
80568+ if (!object_starts_on_stack(&this_size))
80569 return;
80570
80571 local_irq_save(flags);
80572diff --git a/kernel/user.c b/kernel/user.c
80573index 7f6ff2b..1ac8f18 100644
80574--- a/kernel/user.c
80575+++ b/kernel/user.c
80576@@ -47,9 +47,7 @@ struct user_namespace init_user_ns = {
80577 .count = 4294967295U,
80578 },
80579 },
80580- .kref = {
80581- .refcount = ATOMIC_INIT(3),
80582- },
80583+ .count = ATOMIC_INIT(3),
80584 .owner = GLOBAL_ROOT_UID,
80585 .group = GLOBAL_ROOT_GID,
80586 .proc_inum = PROC_USER_INIT_INO,
80587diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
80588index f45e128..a5a5fb6 100644
80589--- a/kernel/user_namespace.c
80590+++ b/kernel/user_namespace.c
80591@@ -88,7 +88,7 @@ int create_user_ns(struct cred *new)
80592 return ret;
80593 }
80594
80595- kref_init(&ns->kref);
80596+ atomic_set(&ns->count, 1);
80597 /* Leave the new->user_ns reference with the new user namespace. */
80598 ns->parent = parent_ns;
80599 ns->owner = owner;
80600@@ -116,15 +116,16 @@ int unshare_userns(unsigned long unshare_flags, struct cred **new_cred)
80601 return create_user_ns(cred);
80602 }
80603
80604-void free_user_ns(struct kref *kref)
80605+void free_user_ns(struct user_namespace *ns)
80606 {
80607- struct user_namespace *parent, *ns =
80608- container_of(kref, struct user_namespace, kref);
80609+ struct user_namespace *parent;
80610
80611- parent = ns->parent;
80612- proc_free_inum(ns->proc_inum);
80613- kmem_cache_free(user_ns_cachep, ns);
80614- put_user_ns(parent);
80615+ do {
80616+ parent = ns->parent;
80617+ proc_free_inum(ns->proc_inum);
80618+ kmem_cache_free(user_ns_cachep, ns);
80619+ ns = parent;
80620+ } while (atomic_dec_and_test(&parent->count));
80621 }
80622 EXPORT_SYMBOL(free_user_ns);
80623
80624@@ -815,7 +816,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
80625 if (atomic_read(&current->mm->mm_users) > 1)
80626 return -EINVAL;
80627
80628- if (current->fs->users != 1)
80629+ if (atomic_read(&current->fs->users) != 1)
80630 return -EINVAL;
80631
80632 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
80633diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
80634index 63da38c..639904e 100644
80635--- a/kernel/utsname_sysctl.c
80636+++ b/kernel/utsname_sysctl.c
80637@@ -46,7 +46,7 @@ static void put_uts(ctl_table *table, int write, void *which)
80638 static int proc_do_uts_string(ctl_table *table, int write,
80639 void __user *buffer, size_t *lenp, loff_t *ppos)
80640 {
80641- struct ctl_table uts_table;
80642+ ctl_table_no_const uts_table;
80643 int r;
80644 memcpy(&uts_table, table, sizeof(uts_table));
80645 uts_table.data = get_uts(table, write);
80646diff --git a/kernel/watchdog.c b/kernel/watchdog.c
80647index 75a2ab3..5961da7 100644
80648--- a/kernel/watchdog.c
80649+++ b/kernel/watchdog.c
80650@@ -527,7 +527,7 @@ int proc_dowatchdog(struct ctl_table *table, int write,
80651 }
80652 #endif /* CONFIG_SYSCTL */
80653
80654-static struct smp_hotplug_thread watchdog_threads = {
80655+static struct smp_hotplug_thread watchdog_threads __read_only = {
80656 .store = &softlockup_watchdog,
80657 .thread_should_run = watchdog_should_run,
80658 .thread_fn = watchdog,
80659diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
80660index 67604e5..fe94fb1 100644
80661--- a/lib/Kconfig.debug
80662+++ b/lib/Kconfig.debug
80663@@ -550,7 +550,7 @@ config DEBUG_MUTEXES
80664
80665 config DEBUG_LOCK_ALLOC
80666 bool "Lock debugging: detect incorrect freeing of live locks"
80667- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
80668+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
80669 select DEBUG_SPINLOCK
80670 select DEBUG_MUTEXES
80671 select LOCKDEP
80672@@ -564,7 +564,7 @@ config DEBUG_LOCK_ALLOC
80673
80674 config PROVE_LOCKING
80675 bool "Lock debugging: prove locking correctness"
80676- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
80677+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
80678 select LOCKDEP
80679 select DEBUG_SPINLOCK
80680 select DEBUG_MUTEXES
80681@@ -670,7 +670,7 @@ config LOCKDEP
80682
80683 config LOCK_STAT
80684 bool "Lock usage statistics"
80685- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
80686+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
80687 select LOCKDEP
80688 select DEBUG_SPINLOCK
80689 select DEBUG_MUTEXES
80690@@ -1278,6 +1278,7 @@ config LATENCYTOP
80691 depends on DEBUG_KERNEL
80692 depends on STACKTRACE_SUPPORT
80693 depends on PROC_FS
80694+ depends on !GRKERNSEC_HIDESYM
80695 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
80696 select KALLSYMS
80697 select KALLSYMS_ALL
80698@@ -1306,7 +1307,7 @@ config INTERVAL_TREE_TEST
80699
80700 config PROVIDE_OHCI1394_DMA_INIT
80701 bool "Remote debugging over FireWire early on boot"
80702- depends on PCI && X86
80703+ depends on PCI && X86 && !GRKERNSEC
80704 help
80705 If you want to debug problems which hang or crash the kernel early
80706 on boot and the crashing machine has a FireWire port, you can use
80707@@ -1335,7 +1336,7 @@ config PROVIDE_OHCI1394_DMA_INIT
80708
80709 config FIREWIRE_OHCI_REMOTE_DMA
80710 bool "Remote debugging over FireWire with firewire-ohci"
80711- depends on FIREWIRE_OHCI
80712+ depends on FIREWIRE_OHCI && !GRKERNSEC
80713 help
80714 This option lets you use the FireWire bus for remote debugging
80715 with help of the firewire-ohci driver. It enables unfiltered
80716diff --git a/lib/Makefile b/lib/Makefile
80717index 02ed6c0..bd243da 100644
80718--- a/lib/Makefile
80719+++ b/lib/Makefile
80720@@ -47,7 +47,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
80721
80722 obj-$(CONFIG_BTREE) += btree.o
80723 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
80724-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
80725+obj-y += list_debug.o
80726 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
80727
80728 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
80729diff --git a/lib/bitmap.c b/lib/bitmap.c
80730index 06f7e4f..f3cf2b0 100644
80731--- a/lib/bitmap.c
80732+++ b/lib/bitmap.c
80733@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
80734 {
80735 int c, old_c, totaldigits, ndigits, nchunks, nbits;
80736 u32 chunk;
80737- const char __user __force *ubuf = (const char __user __force *)buf;
80738+ const char __user *ubuf = (const char __force_user *)buf;
80739
80740 bitmap_zero(maskp, nmaskbits);
80741
80742@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
80743 {
80744 if (!access_ok(VERIFY_READ, ubuf, ulen))
80745 return -EFAULT;
80746- return __bitmap_parse((const char __force *)ubuf,
80747+ return __bitmap_parse((const char __force_kernel *)ubuf,
80748 ulen, 1, maskp, nmaskbits);
80749
80750 }
80751@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
80752 {
80753 unsigned a, b;
80754 int c, old_c, totaldigits;
80755- const char __user __force *ubuf = (const char __user __force *)buf;
80756+ const char __user *ubuf = (const char __force_user *)buf;
80757 int exp_digit, in_range;
80758
80759 totaldigits = c = 0;
80760@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
80761 {
80762 if (!access_ok(VERIFY_READ, ubuf, ulen))
80763 return -EFAULT;
80764- return __bitmap_parselist((const char __force *)ubuf,
80765+ return __bitmap_parselist((const char __force_kernel *)ubuf,
80766 ulen, 1, maskp, nmaskbits);
80767 }
80768 EXPORT_SYMBOL(bitmap_parselist_user);
80769diff --git a/lib/bug.c b/lib/bug.c
80770index d0cdf14..4d07bd2 100644
80771--- a/lib/bug.c
80772+++ b/lib/bug.c
80773@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
80774 return BUG_TRAP_TYPE_NONE;
80775
80776 bug = find_bug(bugaddr);
80777+ if (!bug)
80778+ return BUG_TRAP_TYPE_NONE;
80779
80780 file = NULL;
80781 line = 0;
80782diff --git a/lib/debugobjects.c b/lib/debugobjects.c
80783index d11808c..dc2d6f8 100644
80784--- a/lib/debugobjects.c
80785+++ b/lib/debugobjects.c
80786@@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
80787 if (limit > 4)
80788 return;
80789
80790- is_on_stack = object_is_on_stack(addr);
80791+ is_on_stack = object_starts_on_stack(addr);
80792 if (is_on_stack == onstack)
80793 return;
80794
80795diff --git a/lib/devres.c b/lib/devres.c
80796index 80b9c76..9e32279 100644
80797--- a/lib/devres.c
80798+++ b/lib/devres.c
80799@@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
80800 void devm_iounmap(struct device *dev, void __iomem *addr)
80801 {
80802 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
80803- (void *)addr));
80804+ (void __force *)addr));
80805 iounmap(addr);
80806 }
80807 EXPORT_SYMBOL(devm_iounmap);
80808@@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
80809 {
80810 ioport_unmap(addr);
80811 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
80812- devm_ioport_map_match, (void *)addr));
80813+ devm_ioport_map_match, (void __force *)addr));
80814 }
80815 EXPORT_SYMBOL(devm_ioport_unmap);
80816
80817diff --git a/lib/div64.c b/lib/div64.c
80818index a163b6c..9618fa5 100644
80819--- a/lib/div64.c
80820+++ b/lib/div64.c
80821@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
80822 EXPORT_SYMBOL(__div64_32);
80823
80824 #ifndef div_s64_rem
80825-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
80826+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
80827 {
80828 u64 quotient;
80829
80830@@ -90,7 +90,7 @@ EXPORT_SYMBOL(div_s64_rem);
80831 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
80832 */
80833 #ifndef div64_u64
80834-u64 div64_u64(u64 dividend, u64 divisor)
80835+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
80836 {
80837 u32 high = divisor >> 32;
80838 u64 quot;
80839diff --git a/lib/dma-debug.c b/lib/dma-debug.c
80840index 5e396ac..58d5de1 100644
80841--- a/lib/dma-debug.c
80842+++ b/lib/dma-debug.c
80843@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
80844
80845 void dma_debug_add_bus(struct bus_type *bus)
80846 {
80847- struct notifier_block *nb;
80848+ notifier_block_no_const *nb;
80849
80850 if (global_disable)
80851 return;
80852@@ -942,7 +942,7 @@ out:
80853
80854 static void check_for_stack(struct device *dev, void *addr)
80855 {
80856- if (object_is_on_stack(addr))
80857+ if (object_starts_on_stack(addr))
80858 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
80859 "stack [addr=%p]\n", addr);
80860 }
80861diff --git a/lib/inflate.c b/lib/inflate.c
80862index 013a761..c28f3fc 100644
80863--- a/lib/inflate.c
80864+++ b/lib/inflate.c
80865@@ -269,7 +269,7 @@ static void free(void *where)
80866 malloc_ptr = free_mem_ptr;
80867 }
80868 #else
80869-#define malloc(a) kmalloc(a, GFP_KERNEL)
80870+#define malloc(a) kmalloc((a), GFP_KERNEL)
80871 #define free(a) kfree(a)
80872 #endif
80873
80874diff --git a/lib/ioremap.c b/lib/ioremap.c
80875index 0c9216c..863bd89 100644
80876--- a/lib/ioremap.c
80877+++ b/lib/ioremap.c
80878@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
80879 unsigned long next;
80880
80881 phys_addr -= addr;
80882- pmd = pmd_alloc(&init_mm, pud, addr);
80883+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
80884 if (!pmd)
80885 return -ENOMEM;
80886 do {
80887@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
80888 unsigned long next;
80889
80890 phys_addr -= addr;
80891- pud = pud_alloc(&init_mm, pgd, addr);
80892+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
80893 if (!pud)
80894 return -ENOMEM;
80895 do {
80896diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
80897index bd2bea9..6b3c95e 100644
80898--- a/lib/is_single_threaded.c
80899+++ b/lib/is_single_threaded.c
80900@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
80901 struct task_struct *p, *t;
80902 bool ret;
80903
80904+ if (!mm)
80905+ return true;
80906+
80907 if (atomic_read(&task->signal->live) != 1)
80908 return false;
80909
80910diff --git a/lib/kobject.c b/lib/kobject.c
80911index a654866..a4fd13d 100644
80912--- a/lib/kobject.c
80913+++ b/lib/kobject.c
80914@@ -859,9 +859,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
80915
80916
80917 static DEFINE_SPINLOCK(kobj_ns_type_lock);
80918-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
80919+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
80920
80921-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
80922+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
80923 {
80924 enum kobj_ns_type type = ops->type;
80925 int error;
80926diff --git a/lib/list_debug.c b/lib/list_debug.c
80927index c24c2f7..06e070b 100644
80928--- a/lib/list_debug.c
80929+++ b/lib/list_debug.c
80930@@ -11,7 +11,9 @@
80931 #include <linux/bug.h>
80932 #include <linux/kernel.h>
80933 #include <linux/rculist.h>
80934+#include <linux/mm.h>
80935
80936+#ifdef CONFIG_DEBUG_LIST
80937 /*
80938 * Insert a new entry between two known consecutive entries.
80939 *
80940@@ -19,21 +21,32 @@
80941 * the prev/next entries already!
80942 */
80943
80944-void __list_add(struct list_head *new,
80945- struct list_head *prev,
80946- struct list_head *next)
80947+static bool __list_add_debug(struct list_head *new,
80948+ struct list_head *prev,
80949+ struct list_head *next)
80950 {
80951- WARN(next->prev != prev,
80952+ if (WARN(next->prev != prev,
80953 "list_add corruption. next->prev should be "
80954 "prev (%p), but was %p. (next=%p).\n",
80955- prev, next->prev, next);
80956- WARN(prev->next != next,
80957+ prev, next->prev, next) ||
80958+ WARN(prev->next != next,
80959 "list_add corruption. prev->next should be "
80960 "next (%p), but was %p. (prev=%p).\n",
80961- next, prev->next, prev);
80962- WARN(new == prev || new == next,
80963- "list_add double add: new=%p, prev=%p, next=%p.\n",
80964- new, prev, next);
80965+ next, prev->next, prev) ||
80966+ WARN(new == prev || new == next,
80967+ "list_add double add: new=%p, prev=%p, next=%p.\n",
80968+ new, prev, next))
80969+ return false;
80970+ return true;
80971+}
80972+
80973+void __list_add(struct list_head *new,
80974+ struct list_head *prev,
80975+ struct list_head *next)
80976+{
80977+ if (!__list_add_debug(new, prev, next))
80978+ return;
80979+
80980 next->prev = new;
80981 new->next = next;
80982 new->prev = prev;
80983@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
80984 }
80985 EXPORT_SYMBOL(__list_add);
80986
80987-void __list_del_entry(struct list_head *entry)
80988+static bool __list_del_entry_debug(struct list_head *entry)
80989 {
80990 struct list_head *prev, *next;
80991
80992@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
80993 WARN(next->prev != entry,
80994 "list_del corruption. next->prev should be %p, "
80995 "but was %p\n", entry, next->prev))
80996+ return false;
80997+ return true;
80998+}
80999+
81000+void __list_del_entry(struct list_head *entry)
81001+{
81002+ if (!__list_del_entry_debug(entry))
81003 return;
81004
81005- __list_del(prev, next);
81006+ __list_del(entry->prev, entry->next);
81007 }
81008 EXPORT_SYMBOL(__list_del_entry);
81009
81010@@ -86,15 +106,85 @@ EXPORT_SYMBOL(list_del);
81011 void __list_add_rcu(struct list_head *new,
81012 struct list_head *prev, struct list_head *next)
81013 {
81014- WARN(next->prev != prev,
81015- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
81016- prev, next->prev, next);
81017- WARN(prev->next != next,
81018- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
81019- next, prev->next, prev);
81020+ if (!__list_add_debug(new, prev, next))
81021+ return;
81022+
81023 new->next = next;
81024 new->prev = prev;
81025 rcu_assign_pointer(list_next_rcu(prev), new);
81026 next->prev = new;
81027 }
81028 EXPORT_SYMBOL(__list_add_rcu);
81029+#endif
81030+
81031+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
81032+{
81033+#ifdef CONFIG_DEBUG_LIST
81034+ if (!__list_add_debug(new, prev, next))
81035+ return;
81036+#endif
81037+
81038+ pax_open_kernel();
81039+ next->prev = new;
81040+ new->next = next;
81041+ new->prev = prev;
81042+ prev->next = new;
81043+ pax_close_kernel();
81044+}
81045+EXPORT_SYMBOL(__pax_list_add);
81046+
81047+void pax_list_del(struct list_head *entry)
81048+{
81049+#ifdef CONFIG_DEBUG_LIST
81050+ if (!__list_del_entry_debug(entry))
81051+ return;
81052+#endif
81053+
81054+ pax_open_kernel();
81055+ __list_del(entry->prev, entry->next);
81056+ entry->next = LIST_POISON1;
81057+ entry->prev = LIST_POISON2;
81058+ pax_close_kernel();
81059+}
81060+EXPORT_SYMBOL(pax_list_del);
81061+
81062+void pax_list_del_init(struct list_head *entry)
81063+{
81064+ pax_open_kernel();
81065+ __list_del(entry->prev, entry->next);
81066+ INIT_LIST_HEAD(entry);
81067+ pax_close_kernel();
81068+}
81069+EXPORT_SYMBOL(pax_list_del_init);
81070+
81071+void __pax_list_add_rcu(struct list_head *new,
81072+ struct list_head *prev, struct list_head *next)
81073+{
81074+#ifdef CONFIG_DEBUG_LIST
81075+ if (!__list_add_debug(new, prev, next))
81076+ return;
81077+#endif
81078+
81079+ pax_open_kernel();
81080+ new->next = next;
81081+ new->prev = prev;
81082+ rcu_assign_pointer(list_next_rcu(prev), new);
81083+ next->prev = new;
81084+ pax_close_kernel();
81085+}
81086+EXPORT_SYMBOL(__pax_list_add_rcu);
81087+
81088+void pax_list_del_rcu(struct list_head *entry)
81089+{
81090+#ifdef CONFIG_DEBUG_LIST
81091+ if (!__list_del_entry_debug(entry))
81092+ return;
81093+#endif
81094+
81095+ pax_open_kernel();
81096+ __list_del(entry->prev, entry->next);
81097+ entry->next = LIST_POISON1;
81098+ entry->prev = LIST_POISON2;
81099+ pax_close_kernel();
81100+}
81101+EXPORT_SYMBOL(pax_list_del_rcu);
81102diff --git a/lib/radix-tree.c b/lib/radix-tree.c
81103index e796429..6e38f9f 100644
81104--- a/lib/radix-tree.c
81105+++ b/lib/radix-tree.c
81106@@ -92,7 +92,7 @@ struct radix_tree_preload {
81107 int nr;
81108 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
81109 };
81110-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
81111+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
81112
81113 static inline void *ptr_to_indirect(void *ptr)
81114 {
81115diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
81116index bb2b201..46abaf9 100644
81117--- a/lib/strncpy_from_user.c
81118+++ b/lib/strncpy_from_user.c
81119@@ -21,7 +21,7 @@
81120 */
81121 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
81122 {
81123- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
81124+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
81125 long res = 0;
81126
81127 /*
81128diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
81129index a28df52..3d55877 100644
81130--- a/lib/strnlen_user.c
81131+++ b/lib/strnlen_user.c
81132@@ -26,7 +26,7 @@
81133 */
81134 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
81135 {
81136- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
81137+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
81138 long align, res = 0;
81139 unsigned long c;
81140
81141diff --git a/lib/swiotlb.c b/lib/swiotlb.c
81142index 196b069..358f342 100644
81143--- a/lib/swiotlb.c
81144+++ b/lib/swiotlb.c
81145@@ -642,7 +642,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
81146
81147 void
81148 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
81149- dma_addr_t dev_addr)
81150+ dma_addr_t dev_addr, struct dma_attrs *attrs)
81151 {
81152 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
81153
81154diff --git a/lib/vsprintf.c b/lib/vsprintf.c
81155index fab33a9..3b5fe68 100644
81156--- a/lib/vsprintf.c
81157+++ b/lib/vsprintf.c
81158@@ -16,6 +16,9 @@
81159 * - scnprintf and vscnprintf
81160 */
81161
81162+#ifdef CONFIG_GRKERNSEC_HIDESYM
81163+#define __INCLUDED_BY_HIDESYM 1
81164+#endif
81165 #include <stdarg.h>
81166 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
81167 #include <linux/types.h>
81168@@ -541,7 +544,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
81169 char sym[KSYM_SYMBOL_LEN];
81170 if (ext == 'B')
81171 sprint_backtrace(sym, value);
81172- else if (ext != 'f' && ext != 's')
81173+ else if (ext != 'f' && ext != 's' && ext != 'a')
81174 sprint_symbol(sym, value);
81175 else
81176 sprint_symbol_no_offset(sym, value);
81177@@ -974,7 +977,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
81178 return number(buf, end, *(const netdev_features_t *)addr, spec);
81179 }
81180
81181+#ifdef CONFIG_GRKERNSEC_HIDESYM
81182+int kptr_restrict __read_mostly = 2;
81183+#else
81184 int kptr_restrict __read_mostly;
81185+#endif
81186
81187 /*
81188 * Show a '%p' thing. A kernel extension is that the '%p' is followed
81189@@ -988,6 +995,8 @@ int kptr_restrict __read_mostly;
81190 * - 'S' For symbolic direct pointers with offset
81191 * - 's' For symbolic direct pointers without offset
81192 * - 'B' For backtraced symbolic direct pointers with offset
81193+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
81194+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
81195 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
81196 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
81197 * - 'M' For a 6-byte MAC address, it prints the address in the
81198@@ -1043,12 +1052,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
81199
81200 if (!ptr && *fmt != 'K') {
81201 /*
81202- * Print (null) with the same width as a pointer so it makes
81203+ * Print (nil) with the same width as a pointer so it makes
81204 * tabular output look nice.
81205 */
81206 if (spec.field_width == -1)
81207 spec.field_width = default_width;
81208- return string(buf, end, "(null)", spec);
81209+ return string(buf, end, "(nil)", spec);
81210 }
81211
81212 switch (*fmt) {
81213@@ -1058,6 +1067,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
81214 /* Fallthrough */
81215 case 'S':
81216 case 's':
81217+#ifdef CONFIG_GRKERNSEC_HIDESYM
81218+ break;
81219+#else
81220+ return symbol_string(buf, end, ptr, spec, *fmt);
81221+#endif
81222+ case 'A':
81223+ case 'a':
81224 case 'B':
81225 return symbol_string(buf, end, ptr, spec, *fmt);
81226 case 'R':
81227@@ -1098,6 +1114,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
81228 va_end(va);
81229 return buf;
81230 }
81231+ case 'P':
81232+ break;
81233 case 'K':
81234 /*
81235 * %pK cannot be used in IRQ context because its test
81236@@ -1121,6 +1139,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
81237 }
81238 break;
81239 }
81240+
81241+#ifdef CONFIG_GRKERNSEC_HIDESYM
81242+ /* 'P' = approved pointers to copy to userland,
81243+ as in the /proc/kallsyms case, as we make it display nothing
81244+ for non-root users, and the real contents for root users
81245+ Also ignore 'K' pointers, since we force their NULLing for non-root users
81246+ above
81247+ */
81248+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
81249+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
81250+ dump_stack();
81251+ ptr = NULL;
81252+ }
81253+#endif
81254+
81255 spec.flags |= SMALL;
81256 if (spec.field_width == -1) {
81257 spec.field_width = default_width;
81258@@ -1842,11 +1875,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
81259 typeof(type) value; \
81260 if (sizeof(type) == 8) { \
81261 args = PTR_ALIGN(args, sizeof(u32)); \
81262- *(u32 *)&value = *(u32 *)args; \
81263- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
81264+ *(u32 *)&value = *(const u32 *)args; \
81265+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
81266 } else { \
81267 args = PTR_ALIGN(args, sizeof(type)); \
81268- value = *(typeof(type) *)args; \
81269+ value = *(const typeof(type) *)args; \
81270 } \
81271 args += sizeof(type); \
81272 value; \
81273@@ -1909,7 +1942,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
81274 case FORMAT_TYPE_STR: {
81275 const char *str_arg = args;
81276 args += strlen(str_arg) + 1;
81277- str = string(str, end, (char *)str_arg, spec);
81278+ str = string(str, end, str_arg, spec);
81279 break;
81280 }
81281
81282diff --git a/localversion-grsec b/localversion-grsec
81283new file mode 100644
81284index 0000000..7cd6065
81285--- /dev/null
81286+++ b/localversion-grsec
81287@@ -0,0 +1 @@
81288+-grsec
81289diff --git a/mm/Kconfig b/mm/Kconfig
81290index 278e3ab..87c384d 100644
81291--- a/mm/Kconfig
81292+++ b/mm/Kconfig
81293@@ -286,10 +286,10 @@ config KSM
81294 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
81295
81296 config DEFAULT_MMAP_MIN_ADDR
81297- int "Low address space to protect from user allocation"
81298+ int "Low address space to protect from user allocation"
81299 depends on MMU
81300- default 4096
81301- help
81302+ default 65536
81303+ help
81304 This is the portion of low virtual memory which should be protected
81305 from userspace allocation. Keeping a user from writing to low pages
81306 can help reduce the impact of kernel NULL pointer bugs.
81307@@ -320,7 +320,7 @@ config MEMORY_FAILURE
81308
81309 config HWPOISON_INJECT
81310 tristate "HWPoison pages injector"
81311- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
81312+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
81313 select PROC_PAGE_MONITOR
81314
81315 config NOMMU_INITIAL_TRIM_EXCESS
81316diff --git a/mm/filemap.c b/mm/filemap.c
81317index 83efee7..3f99381 100644
81318--- a/mm/filemap.c
81319+++ b/mm/filemap.c
81320@@ -1747,7 +1747,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
81321 struct address_space *mapping = file->f_mapping;
81322
81323 if (!mapping->a_ops->readpage)
81324- return -ENOEXEC;
81325+ return -ENODEV;
81326 file_accessed(file);
81327 vma->vm_ops = &generic_file_vm_ops;
81328 return 0;
81329@@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
81330 *pos = i_size_read(inode);
81331
81332 if (limit != RLIM_INFINITY) {
81333+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
81334 if (*pos >= limit) {
81335 send_sig(SIGXFSZ, current, 0);
81336 return -EFBIG;
81337diff --git a/mm/fremap.c b/mm/fremap.c
81338index a0aaf0e..20325c3 100644
81339--- a/mm/fremap.c
81340+++ b/mm/fremap.c
81341@@ -157,6 +157,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
81342 retry:
81343 vma = find_vma(mm, start);
81344
81345+#ifdef CONFIG_PAX_SEGMEXEC
81346+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
81347+ goto out;
81348+#endif
81349+
81350 /*
81351 * Make sure the vma is shared, that it supports prefaulting,
81352 * and that the remapped range is valid and fully within
81353diff --git a/mm/highmem.c b/mm/highmem.c
81354index b32b70c..e512eb0 100644
81355--- a/mm/highmem.c
81356+++ b/mm/highmem.c
81357@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
81358 * So no dangers, even with speculative execution.
81359 */
81360 page = pte_page(pkmap_page_table[i]);
81361+ pax_open_kernel();
81362 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
81363-
81364+ pax_close_kernel();
81365 set_page_address(page, NULL);
81366 need_flush = 1;
81367 }
81368@@ -198,9 +199,11 @@ start:
81369 }
81370 }
81371 vaddr = PKMAP_ADDR(last_pkmap_nr);
81372+
81373+ pax_open_kernel();
81374 set_pte_at(&init_mm, vaddr,
81375 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
81376-
81377+ pax_close_kernel();
81378 pkmap_count[last_pkmap_nr] = 1;
81379 set_page_address(page, (void *)vaddr);
81380
81381diff --git a/mm/hugetlb.c b/mm/hugetlb.c
81382index d7cec92..b05cc33 100644
81383--- a/mm/hugetlb.c
81384+++ b/mm/hugetlb.c
81385@@ -2008,15 +2008,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
81386 struct hstate *h = &default_hstate;
81387 unsigned long tmp;
81388 int ret;
81389+ ctl_table_no_const hugetlb_table;
81390
81391 tmp = h->max_huge_pages;
81392
81393 if (write && h->order >= MAX_ORDER)
81394 return -EINVAL;
81395
81396- table->data = &tmp;
81397- table->maxlen = sizeof(unsigned long);
81398- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
81399+ hugetlb_table = *table;
81400+ hugetlb_table.data = &tmp;
81401+ hugetlb_table.maxlen = sizeof(unsigned long);
81402+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
81403 if (ret)
81404 goto out;
81405
81406@@ -2073,15 +2075,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
81407 struct hstate *h = &default_hstate;
81408 unsigned long tmp;
81409 int ret;
81410+ ctl_table_no_const hugetlb_table;
81411
81412 tmp = h->nr_overcommit_huge_pages;
81413
81414 if (write && h->order >= MAX_ORDER)
81415 return -EINVAL;
81416
81417- table->data = &tmp;
81418- table->maxlen = sizeof(unsigned long);
81419- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
81420+ hugetlb_table = *table;
81421+ hugetlb_table.data = &tmp;
81422+ hugetlb_table.maxlen = sizeof(unsigned long);
81423+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
81424 if (ret)
81425 goto out;
81426
81427@@ -2515,6 +2519,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
81428 return 1;
81429 }
81430
81431+#ifdef CONFIG_PAX_SEGMEXEC
81432+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
81433+{
81434+ struct mm_struct *mm = vma->vm_mm;
81435+ struct vm_area_struct *vma_m;
81436+ unsigned long address_m;
81437+ pte_t *ptep_m;
81438+
81439+ vma_m = pax_find_mirror_vma(vma);
81440+ if (!vma_m)
81441+ return;
81442+
81443+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
81444+ address_m = address + SEGMEXEC_TASK_SIZE;
81445+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
81446+ get_page(page_m);
81447+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
81448+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
81449+}
81450+#endif
81451+
81452 /*
81453 * Hugetlb_cow() should be called with page lock of the original hugepage held.
81454 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
81455@@ -2633,6 +2658,11 @@ retry_avoidcopy:
81456 make_huge_pte(vma, new_page, 1));
81457 page_remove_rmap(old_page);
81458 hugepage_add_new_anon_rmap(new_page, vma, address);
81459+
81460+#ifdef CONFIG_PAX_SEGMEXEC
81461+ pax_mirror_huge_pte(vma, address, new_page);
81462+#endif
81463+
81464 /* Make the old page be freed below */
81465 new_page = old_page;
81466 }
81467@@ -2792,6 +2822,10 @@ retry:
81468 && (vma->vm_flags & VM_SHARED)));
81469 set_huge_pte_at(mm, address, ptep, new_pte);
81470
81471+#ifdef CONFIG_PAX_SEGMEXEC
81472+ pax_mirror_huge_pte(vma, address, page);
81473+#endif
81474+
81475 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
81476 /* Optimization, do the COW without a second fault */
81477 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
81478@@ -2821,6 +2855,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81479 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
81480 struct hstate *h = hstate_vma(vma);
81481
81482+#ifdef CONFIG_PAX_SEGMEXEC
81483+ struct vm_area_struct *vma_m;
81484+#endif
81485+
81486 address &= huge_page_mask(h);
81487
81488 ptep = huge_pte_offset(mm, address);
81489@@ -2834,6 +2872,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81490 VM_FAULT_SET_HINDEX(hstate_index(h));
81491 }
81492
81493+#ifdef CONFIG_PAX_SEGMEXEC
81494+ vma_m = pax_find_mirror_vma(vma);
81495+ if (vma_m) {
81496+ unsigned long address_m;
81497+
81498+ if (vma->vm_start > vma_m->vm_start) {
81499+ address_m = address;
81500+ address -= SEGMEXEC_TASK_SIZE;
81501+ vma = vma_m;
81502+ h = hstate_vma(vma);
81503+ } else
81504+ address_m = address + SEGMEXEC_TASK_SIZE;
81505+
81506+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
81507+ return VM_FAULT_OOM;
81508+ address_m &= HPAGE_MASK;
81509+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
81510+ }
81511+#endif
81512+
81513 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
81514 if (!ptep)
81515 return VM_FAULT_OOM;
81516diff --git a/mm/internal.h b/mm/internal.h
81517index 9ba2110..eaf0674 100644
81518--- a/mm/internal.h
81519+++ b/mm/internal.h
81520@@ -100,6 +100,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
81521 * in mm/page_alloc.c
81522 */
81523 extern void __free_pages_bootmem(struct page *page, unsigned int order);
81524+extern void free_compound_page(struct page *page);
81525 extern void prep_compound_page(struct page *page, unsigned long order);
81526 #ifdef CONFIG_MEMORY_FAILURE
81527 extern bool is_free_buddy_page(struct page *page);
81528diff --git a/mm/kmemleak.c b/mm/kmemleak.c
81529index 752a705..6c3102e 100644
81530--- a/mm/kmemleak.c
81531+++ b/mm/kmemleak.c
81532@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
81533
81534 for (i = 0; i < object->trace_len; i++) {
81535 void *ptr = (void *)object->trace[i];
81536- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
81537+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
81538 }
81539 }
81540
81541@@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
81542 return -ENOMEM;
81543 }
81544
81545- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
81546+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
81547 &kmemleak_fops);
81548 if (!dentry)
81549 pr_warning("Failed to create the debugfs kmemleak file\n");
81550diff --git a/mm/maccess.c b/mm/maccess.c
81551index d53adf9..03a24bf 100644
81552--- a/mm/maccess.c
81553+++ b/mm/maccess.c
81554@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
81555 set_fs(KERNEL_DS);
81556 pagefault_disable();
81557 ret = __copy_from_user_inatomic(dst,
81558- (__force const void __user *)src, size);
81559+ (const void __force_user *)src, size);
81560 pagefault_enable();
81561 set_fs(old_fs);
81562
81563@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
81564
81565 set_fs(KERNEL_DS);
81566 pagefault_disable();
81567- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
81568+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
81569 pagefault_enable();
81570 set_fs(old_fs);
81571
81572diff --git a/mm/madvise.c b/mm/madvise.c
81573index 03dfa5c..b032917 100644
81574--- a/mm/madvise.c
81575+++ b/mm/madvise.c
81576@@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
81577 pgoff_t pgoff;
81578 unsigned long new_flags = vma->vm_flags;
81579
81580+#ifdef CONFIG_PAX_SEGMEXEC
81581+ struct vm_area_struct *vma_m;
81582+#endif
81583+
81584 switch (behavior) {
81585 case MADV_NORMAL:
81586 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
81587@@ -123,6 +127,13 @@ success:
81588 /*
81589 * vm_flags is protected by the mmap_sem held in write mode.
81590 */
81591+
81592+#ifdef CONFIG_PAX_SEGMEXEC
81593+ vma_m = pax_find_mirror_vma(vma);
81594+ if (vma_m)
81595+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
81596+#endif
81597+
81598 vma->vm_flags = new_flags;
81599
81600 out:
81601@@ -181,6 +192,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
81602 struct vm_area_struct ** prev,
81603 unsigned long start, unsigned long end)
81604 {
81605+
81606+#ifdef CONFIG_PAX_SEGMEXEC
81607+ struct vm_area_struct *vma_m;
81608+#endif
81609+
81610 *prev = vma;
81611 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
81612 return -EINVAL;
81613@@ -193,6 +209,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
81614 zap_page_range(vma, start, end - start, &details);
81615 } else
81616 zap_page_range(vma, start, end - start, NULL);
81617+
81618+#ifdef CONFIG_PAX_SEGMEXEC
81619+ vma_m = pax_find_mirror_vma(vma);
81620+ if (vma_m) {
81621+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
81622+ struct zap_details details = {
81623+ .nonlinear_vma = vma_m,
81624+ .last_index = ULONG_MAX,
81625+ };
81626+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
81627+ } else
81628+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
81629+ }
81630+#endif
81631+
81632 return 0;
81633 }
81634
81635@@ -397,6 +428,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
81636 if (end < start)
81637 goto out;
81638
81639+#ifdef CONFIG_PAX_SEGMEXEC
81640+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
81641+ if (end > SEGMEXEC_TASK_SIZE)
81642+ goto out;
81643+ } else
81644+#endif
81645+
81646+ if (end > TASK_SIZE)
81647+ goto out;
81648+
81649 error = 0;
81650 if (end == start)
81651 goto out;
81652diff --git a/mm/memory-failure.c b/mm/memory-failure.c
81653index c6e4dd3..1f41988 100644
81654--- a/mm/memory-failure.c
81655+++ b/mm/memory-failure.c
81656@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
81657
81658 int sysctl_memory_failure_recovery __read_mostly = 1;
81659
81660-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
81661+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
81662
81663 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
81664
81665@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
81666 pfn, t->comm, t->pid);
81667 si.si_signo = SIGBUS;
81668 si.si_errno = 0;
81669- si.si_addr = (void *)addr;
81670+ si.si_addr = (void __user *)addr;
81671 #ifdef __ARCH_SI_TRAPNO
81672 si.si_trapno = trapno;
81673 #endif
81674@@ -760,7 +760,7 @@ static struct page_state {
81675 unsigned long res;
81676 char *msg;
81677 int (*action)(struct page *p, unsigned long pfn);
81678-} error_states[] = {
81679+} __do_const error_states[] = {
81680 { reserved, reserved, "reserved kernel", me_kernel },
81681 /*
81682 * free pages are specially detected outside this table:
81683@@ -1040,7 +1040,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
81684 }
81685
81686 nr_pages = 1 << compound_trans_order(hpage);
81687- atomic_long_add(nr_pages, &mce_bad_pages);
81688+ atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
81689
81690 /*
81691 * We need/can do nothing about count=0 pages.
81692@@ -1070,7 +1070,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
81693 if (!PageHWPoison(hpage)
81694 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
81695 || (p != hpage && TestSetPageHWPoison(hpage))) {
81696- atomic_long_sub(nr_pages, &mce_bad_pages);
81697+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
81698 return 0;
81699 }
81700 set_page_hwpoison_huge_page(hpage);
81701@@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
81702 }
81703 if (hwpoison_filter(p)) {
81704 if (TestClearPageHWPoison(p))
81705- atomic_long_sub(nr_pages, &mce_bad_pages);
81706+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
81707 unlock_page(hpage);
81708 put_page(hpage);
81709 return 0;
81710@@ -1323,7 +1323,7 @@ int unpoison_memory(unsigned long pfn)
81711 return 0;
81712 }
81713 if (TestClearPageHWPoison(p))
81714- atomic_long_sub(nr_pages, &mce_bad_pages);
81715+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
81716 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
81717 return 0;
81718 }
81719@@ -1337,7 +1337,7 @@ int unpoison_memory(unsigned long pfn)
81720 */
81721 if (TestClearPageHWPoison(page)) {
81722 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
81723- atomic_long_sub(nr_pages, &mce_bad_pages);
81724+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
81725 freeit = 1;
81726 if (PageHuge(page))
81727 clear_page_hwpoison_huge_page(page);
81728@@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
81729 }
81730 done:
81731 if (!PageHWPoison(hpage))
81732- atomic_long_add(1 << compound_trans_order(hpage),
81733+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
81734 &mce_bad_pages);
81735 set_page_hwpoison_huge_page(hpage);
81736 dequeue_hwpoisoned_huge_page(hpage);
81737@@ -1583,7 +1583,7 @@ int soft_offline_page(struct page *page, int flags)
81738 return ret;
81739
81740 done:
81741- atomic_long_add(1, &mce_bad_pages);
81742+ atomic_long_add_unchecked(1, &mce_bad_pages);
81743 SetPageHWPoison(page);
81744 /* keep elevated page count for bad page */
81745 return ret;
81746diff --git a/mm/memory.c b/mm/memory.c
81747index f8b734a..38014f5 100644
81748--- a/mm/memory.c
81749+++ b/mm/memory.c
81750@@ -434,6 +434,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
81751 free_pte_range(tlb, pmd, addr);
81752 } while (pmd++, addr = next, addr != end);
81753
81754+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
81755 start &= PUD_MASK;
81756 if (start < floor)
81757 return;
81758@@ -448,6 +449,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
81759 pmd = pmd_offset(pud, start);
81760 pud_clear(pud);
81761 pmd_free_tlb(tlb, pmd, start);
81762+#endif
81763+
81764 }
81765
81766 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
81767@@ -467,6 +470,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
81768 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
81769 } while (pud++, addr = next, addr != end);
81770
81771+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
81772 start &= PGDIR_MASK;
81773 if (start < floor)
81774 return;
81775@@ -481,6 +485,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
81776 pud = pud_offset(pgd, start);
81777 pgd_clear(pgd);
81778 pud_free_tlb(tlb, pud, start);
81779+#endif
81780+
81781 }
81782
81783 /*
81784@@ -1619,12 +1625,6 @@ no_page_table:
81785 return page;
81786 }
81787
81788-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
81789-{
81790- return stack_guard_page_start(vma, addr) ||
81791- stack_guard_page_end(vma, addr+PAGE_SIZE);
81792-}
81793-
81794 /**
81795 * __get_user_pages() - pin user pages in memory
81796 * @tsk: task_struct of target task
81797@@ -1710,10 +1710,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
81798
81799 i = 0;
81800
81801- do {
81802+ while (nr_pages) {
81803 struct vm_area_struct *vma;
81804
81805- vma = find_extend_vma(mm, start);
81806+ vma = find_vma(mm, start);
81807 if (!vma && in_gate_area(mm, start)) {
81808 unsigned long pg = start & PAGE_MASK;
81809 pgd_t *pgd;
81810@@ -1761,7 +1761,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
81811 goto next_page;
81812 }
81813
81814- if (!vma ||
81815+ if (!vma || start < vma->vm_start ||
81816 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
81817 !(vm_flags & vma->vm_flags))
81818 return i ? : -EFAULT;
81819@@ -1788,11 +1788,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
81820 int ret;
81821 unsigned int fault_flags = 0;
81822
81823- /* For mlock, just skip the stack guard page. */
81824- if (foll_flags & FOLL_MLOCK) {
81825- if (stack_guard_page(vma, start))
81826- goto next_page;
81827- }
81828 if (foll_flags & FOLL_WRITE)
81829 fault_flags |= FAULT_FLAG_WRITE;
81830 if (nonblocking)
81831@@ -1866,7 +1861,7 @@ next_page:
81832 start += PAGE_SIZE;
81833 nr_pages--;
81834 } while (nr_pages && start < vma->vm_end);
81835- } while (nr_pages);
81836+ }
81837 return i;
81838 }
81839 EXPORT_SYMBOL(__get_user_pages);
81840@@ -2073,6 +2068,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
81841 page_add_file_rmap(page);
81842 set_pte_at(mm, addr, pte, mk_pte(page, prot));
81843
81844+#ifdef CONFIG_PAX_SEGMEXEC
81845+ pax_mirror_file_pte(vma, addr, page, ptl);
81846+#endif
81847+
81848 retval = 0;
81849 pte_unmap_unlock(pte, ptl);
81850 return retval;
81851@@ -2117,9 +2116,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
81852 if (!page_count(page))
81853 return -EINVAL;
81854 if (!(vma->vm_flags & VM_MIXEDMAP)) {
81855+
81856+#ifdef CONFIG_PAX_SEGMEXEC
81857+ struct vm_area_struct *vma_m;
81858+#endif
81859+
81860 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
81861 BUG_ON(vma->vm_flags & VM_PFNMAP);
81862 vma->vm_flags |= VM_MIXEDMAP;
81863+
81864+#ifdef CONFIG_PAX_SEGMEXEC
81865+ vma_m = pax_find_mirror_vma(vma);
81866+ if (vma_m)
81867+ vma_m->vm_flags |= VM_MIXEDMAP;
81868+#endif
81869+
81870 }
81871 return insert_page(vma, addr, page, vma->vm_page_prot);
81872 }
81873@@ -2202,6 +2213,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
81874 unsigned long pfn)
81875 {
81876 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
81877+ BUG_ON(vma->vm_mirror);
81878
81879 if (addr < vma->vm_start || addr >= vma->vm_end)
81880 return -EFAULT;
81881@@ -2402,7 +2414,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
81882
81883 BUG_ON(pud_huge(*pud));
81884
81885- pmd = pmd_alloc(mm, pud, addr);
81886+ pmd = (mm == &init_mm) ?
81887+ pmd_alloc_kernel(mm, pud, addr) :
81888+ pmd_alloc(mm, pud, addr);
81889 if (!pmd)
81890 return -ENOMEM;
81891 do {
81892@@ -2422,7 +2436,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
81893 unsigned long next;
81894 int err;
81895
81896- pud = pud_alloc(mm, pgd, addr);
81897+ pud = (mm == &init_mm) ?
81898+ pud_alloc_kernel(mm, pgd, addr) :
81899+ pud_alloc(mm, pgd, addr);
81900 if (!pud)
81901 return -ENOMEM;
81902 do {
81903@@ -2510,6 +2526,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
81904 copy_user_highpage(dst, src, va, vma);
81905 }
81906
81907+#ifdef CONFIG_PAX_SEGMEXEC
81908+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
81909+{
81910+ struct mm_struct *mm = vma->vm_mm;
81911+ spinlock_t *ptl;
81912+ pte_t *pte, entry;
81913+
81914+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
81915+ entry = *pte;
81916+ if (!pte_present(entry)) {
81917+ if (!pte_none(entry)) {
81918+ BUG_ON(pte_file(entry));
81919+ free_swap_and_cache(pte_to_swp_entry(entry));
81920+ pte_clear_not_present_full(mm, address, pte, 0);
81921+ }
81922+ } else {
81923+ struct page *page;
81924+
81925+ flush_cache_page(vma, address, pte_pfn(entry));
81926+ entry = ptep_clear_flush(vma, address, pte);
81927+ BUG_ON(pte_dirty(entry));
81928+ page = vm_normal_page(vma, address, entry);
81929+ if (page) {
81930+ update_hiwater_rss(mm);
81931+ if (PageAnon(page))
81932+ dec_mm_counter_fast(mm, MM_ANONPAGES);
81933+ else
81934+ dec_mm_counter_fast(mm, MM_FILEPAGES);
81935+ page_remove_rmap(page);
81936+ page_cache_release(page);
81937+ }
81938+ }
81939+ pte_unmap_unlock(pte, ptl);
81940+}
81941+
81942+/* PaX: if vma is mirrored, synchronize the mirror's PTE
81943+ *
81944+ * the ptl of the lower mapped page is held on entry and is not released on exit
81945+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
81946+ */
81947+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
81948+{
81949+ struct mm_struct *mm = vma->vm_mm;
81950+ unsigned long address_m;
81951+ spinlock_t *ptl_m;
81952+ struct vm_area_struct *vma_m;
81953+ pmd_t *pmd_m;
81954+ pte_t *pte_m, entry_m;
81955+
81956+ BUG_ON(!page_m || !PageAnon(page_m));
81957+
81958+ vma_m = pax_find_mirror_vma(vma);
81959+ if (!vma_m)
81960+ return;
81961+
81962+ BUG_ON(!PageLocked(page_m));
81963+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
81964+ address_m = address + SEGMEXEC_TASK_SIZE;
81965+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
81966+ pte_m = pte_offset_map(pmd_m, address_m);
81967+ ptl_m = pte_lockptr(mm, pmd_m);
81968+ if (ptl != ptl_m) {
81969+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
81970+ if (!pte_none(*pte_m))
81971+ goto out;
81972+ }
81973+
81974+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
81975+ page_cache_get(page_m);
81976+ page_add_anon_rmap(page_m, vma_m, address_m);
81977+ inc_mm_counter_fast(mm, MM_ANONPAGES);
81978+ set_pte_at(mm, address_m, pte_m, entry_m);
81979+ update_mmu_cache(vma_m, address_m, entry_m);
81980+out:
81981+ if (ptl != ptl_m)
81982+ spin_unlock(ptl_m);
81983+ pte_unmap(pte_m);
81984+ unlock_page(page_m);
81985+}
81986+
81987+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
81988+{
81989+ struct mm_struct *mm = vma->vm_mm;
81990+ unsigned long address_m;
81991+ spinlock_t *ptl_m;
81992+ struct vm_area_struct *vma_m;
81993+ pmd_t *pmd_m;
81994+ pte_t *pte_m, entry_m;
81995+
81996+ BUG_ON(!page_m || PageAnon(page_m));
81997+
81998+ vma_m = pax_find_mirror_vma(vma);
81999+ if (!vma_m)
82000+ return;
82001+
82002+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
82003+ address_m = address + SEGMEXEC_TASK_SIZE;
82004+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
82005+ pte_m = pte_offset_map(pmd_m, address_m);
82006+ ptl_m = pte_lockptr(mm, pmd_m);
82007+ if (ptl != ptl_m) {
82008+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
82009+ if (!pte_none(*pte_m))
82010+ goto out;
82011+ }
82012+
82013+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
82014+ page_cache_get(page_m);
82015+ page_add_file_rmap(page_m);
82016+ inc_mm_counter_fast(mm, MM_FILEPAGES);
82017+ set_pte_at(mm, address_m, pte_m, entry_m);
82018+ update_mmu_cache(vma_m, address_m, entry_m);
82019+out:
82020+ if (ptl != ptl_m)
82021+ spin_unlock(ptl_m);
82022+ pte_unmap(pte_m);
82023+}
82024+
82025+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
82026+{
82027+ struct mm_struct *mm = vma->vm_mm;
82028+ unsigned long address_m;
82029+ spinlock_t *ptl_m;
82030+ struct vm_area_struct *vma_m;
82031+ pmd_t *pmd_m;
82032+ pte_t *pte_m, entry_m;
82033+
82034+ vma_m = pax_find_mirror_vma(vma);
82035+ if (!vma_m)
82036+ return;
82037+
82038+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
82039+ address_m = address + SEGMEXEC_TASK_SIZE;
82040+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
82041+ pte_m = pte_offset_map(pmd_m, address_m);
82042+ ptl_m = pte_lockptr(mm, pmd_m);
82043+ if (ptl != ptl_m) {
82044+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
82045+ if (!pte_none(*pte_m))
82046+ goto out;
82047+ }
82048+
82049+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
82050+ set_pte_at(mm, address_m, pte_m, entry_m);
82051+out:
82052+ if (ptl != ptl_m)
82053+ spin_unlock(ptl_m);
82054+ pte_unmap(pte_m);
82055+}
82056+
82057+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
82058+{
82059+ struct page *page_m;
82060+ pte_t entry;
82061+
82062+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
82063+ goto out;
82064+
82065+ entry = *pte;
82066+ page_m = vm_normal_page(vma, address, entry);
82067+ if (!page_m)
82068+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
82069+ else if (PageAnon(page_m)) {
82070+ if (pax_find_mirror_vma(vma)) {
82071+ pte_unmap_unlock(pte, ptl);
82072+ lock_page(page_m);
82073+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
82074+ if (pte_same(entry, *pte))
82075+ pax_mirror_anon_pte(vma, address, page_m, ptl);
82076+ else
82077+ unlock_page(page_m);
82078+ }
82079+ } else
82080+ pax_mirror_file_pte(vma, address, page_m, ptl);
82081+
82082+out:
82083+ pte_unmap_unlock(pte, ptl);
82084+}
82085+#endif
82086+
82087 /*
82088 * This routine handles present pages, when users try to write
82089 * to a shared page. It is done by copying the page to a new address
82090@@ -2726,6 +2922,12 @@ gotten:
82091 */
82092 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
82093 if (likely(pte_same(*page_table, orig_pte))) {
82094+
82095+#ifdef CONFIG_PAX_SEGMEXEC
82096+ if (pax_find_mirror_vma(vma))
82097+ BUG_ON(!trylock_page(new_page));
82098+#endif
82099+
82100 if (old_page) {
82101 if (!PageAnon(old_page)) {
82102 dec_mm_counter_fast(mm, MM_FILEPAGES);
82103@@ -2777,6 +2979,10 @@ gotten:
82104 page_remove_rmap(old_page);
82105 }
82106
82107+#ifdef CONFIG_PAX_SEGMEXEC
82108+ pax_mirror_anon_pte(vma, address, new_page, ptl);
82109+#endif
82110+
82111 /* Free the old page.. */
82112 new_page = old_page;
82113 ret |= VM_FAULT_WRITE;
82114@@ -3052,6 +3258,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
82115 swap_free(entry);
82116 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
82117 try_to_free_swap(page);
82118+
82119+#ifdef CONFIG_PAX_SEGMEXEC
82120+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
82121+#endif
82122+
82123 unlock_page(page);
82124 if (swapcache) {
82125 /*
82126@@ -3075,6 +3286,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
82127
82128 /* No need to invalidate - it was non-present before */
82129 update_mmu_cache(vma, address, page_table);
82130+
82131+#ifdef CONFIG_PAX_SEGMEXEC
82132+ pax_mirror_anon_pte(vma, address, page, ptl);
82133+#endif
82134+
82135 unlock:
82136 pte_unmap_unlock(page_table, ptl);
82137 out:
82138@@ -3094,40 +3310,6 @@ out_release:
82139 }
82140
82141 /*
82142- * This is like a special single-page "expand_{down|up}wards()",
82143- * except we must first make sure that 'address{-|+}PAGE_SIZE'
82144- * doesn't hit another vma.
82145- */
82146-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
82147-{
82148- address &= PAGE_MASK;
82149- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
82150- struct vm_area_struct *prev = vma->vm_prev;
82151-
82152- /*
82153- * Is there a mapping abutting this one below?
82154- *
82155- * That's only ok if it's the same stack mapping
82156- * that has gotten split..
82157- */
82158- if (prev && prev->vm_end == address)
82159- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
82160-
82161- expand_downwards(vma, address - PAGE_SIZE);
82162- }
82163- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
82164- struct vm_area_struct *next = vma->vm_next;
82165-
82166- /* As VM_GROWSDOWN but s/below/above/ */
82167- if (next && next->vm_start == address + PAGE_SIZE)
82168- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
82169-
82170- expand_upwards(vma, address + PAGE_SIZE);
82171- }
82172- return 0;
82173-}
82174-
82175-/*
82176 * We enter with non-exclusive mmap_sem (to exclude vma changes,
82177 * but allow concurrent faults), and pte mapped but not yet locked.
82178 * We return with mmap_sem still held, but pte unmapped and unlocked.
82179@@ -3136,27 +3318,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
82180 unsigned long address, pte_t *page_table, pmd_t *pmd,
82181 unsigned int flags)
82182 {
82183- struct page *page;
82184+ struct page *page = NULL;
82185 spinlock_t *ptl;
82186 pte_t entry;
82187
82188- pte_unmap(page_table);
82189-
82190- /* Check if we need to add a guard page to the stack */
82191- if (check_stack_guard_page(vma, address) < 0)
82192- return VM_FAULT_SIGBUS;
82193-
82194- /* Use the zero-page for reads */
82195 if (!(flags & FAULT_FLAG_WRITE)) {
82196 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
82197 vma->vm_page_prot));
82198- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
82199+ ptl = pte_lockptr(mm, pmd);
82200+ spin_lock(ptl);
82201 if (!pte_none(*page_table))
82202 goto unlock;
82203 goto setpte;
82204 }
82205
82206 /* Allocate our own private page. */
82207+ pte_unmap(page_table);
82208+
82209 if (unlikely(anon_vma_prepare(vma)))
82210 goto oom;
82211 page = alloc_zeroed_user_highpage_movable(vma, address);
82212@@ -3175,6 +3353,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
82213 if (!pte_none(*page_table))
82214 goto release;
82215
82216+#ifdef CONFIG_PAX_SEGMEXEC
82217+ if (pax_find_mirror_vma(vma))
82218+ BUG_ON(!trylock_page(page));
82219+#endif
82220+
82221 inc_mm_counter_fast(mm, MM_ANONPAGES);
82222 page_add_new_anon_rmap(page, vma, address);
82223 setpte:
82224@@ -3182,6 +3365,12 @@ setpte:
82225
82226 /* No need to invalidate - it was non-present before */
82227 update_mmu_cache(vma, address, page_table);
82228+
82229+#ifdef CONFIG_PAX_SEGMEXEC
82230+ if (page)
82231+ pax_mirror_anon_pte(vma, address, page, ptl);
82232+#endif
82233+
82234 unlock:
82235 pte_unmap_unlock(page_table, ptl);
82236 return 0;
82237@@ -3325,6 +3514,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
82238 */
82239 /* Only go through if we didn't race with anybody else... */
82240 if (likely(pte_same(*page_table, orig_pte))) {
82241+
82242+#ifdef CONFIG_PAX_SEGMEXEC
82243+ if (anon && pax_find_mirror_vma(vma))
82244+ BUG_ON(!trylock_page(page));
82245+#endif
82246+
82247 flush_icache_page(vma, page);
82248 entry = mk_pte(page, vma->vm_page_prot);
82249 if (flags & FAULT_FLAG_WRITE)
82250@@ -3344,6 +3539,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
82251
82252 /* no need to invalidate: a not-present page won't be cached */
82253 update_mmu_cache(vma, address, page_table);
82254+
82255+#ifdef CONFIG_PAX_SEGMEXEC
82256+ if (anon)
82257+ pax_mirror_anon_pte(vma, address, page, ptl);
82258+ else
82259+ pax_mirror_file_pte(vma, address, page, ptl);
82260+#endif
82261+
82262 } else {
82263 if (cow_page)
82264 mem_cgroup_uncharge_page(cow_page);
82265@@ -3665,6 +3868,12 @@ int handle_pte_fault(struct mm_struct *mm,
82266 if (flags & FAULT_FLAG_WRITE)
82267 flush_tlb_fix_spurious_fault(vma, address);
82268 }
82269+
82270+#ifdef CONFIG_PAX_SEGMEXEC
82271+ pax_mirror_pte(vma, address, pte, pmd, ptl);
82272+ return 0;
82273+#endif
82274+
82275 unlock:
82276 pte_unmap_unlock(pte, ptl);
82277 return 0;
82278@@ -3681,6 +3890,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
82279 pmd_t *pmd;
82280 pte_t *pte;
82281
82282+#ifdef CONFIG_PAX_SEGMEXEC
82283+ struct vm_area_struct *vma_m;
82284+#endif
82285+
82286 __set_current_state(TASK_RUNNING);
82287
82288 count_vm_event(PGFAULT);
82289@@ -3692,6 +3905,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
82290 if (unlikely(is_vm_hugetlb_page(vma)))
82291 return hugetlb_fault(mm, vma, address, flags);
82292
82293+#ifdef CONFIG_PAX_SEGMEXEC
82294+ vma_m = pax_find_mirror_vma(vma);
82295+ if (vma_m) {
82296+ unsigned long address_m;
82297+ pgd_t *pgd_m;
82298+ pud_t *pud_m;
82299+ pmd_t *pmd_m;
82300+
82301+ if (vma->vm_start > vma_m->vm_start) {
82302+ address_m = address;
82303+ address -= SEGMEXEC_TASK_SIZE;
82304+ vma = vma_m;
82305+ } else
82306+ address_m = address + SEGMEXEC_TASK_SIZE;
82307+
82308+ pgd_m = pgd_offset(mm, address_m);
82309+ pud_m = pud_alloc(mm, pgd_m, address_m);
82310+ if (!pud_m)
82311+ return VM_FAULT_OOM;
82312+ pmd_m = pmd_alloc(mm, pud_m, address_m);
82313+ if (!pmd_m)
82314+ return VM_FAULT_OOM;
82315+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
82316+ return VM_FAULT_OOM;
82317+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
82318+ }
82319+#endif
82320+
82321 retry:
82322 pgd = pgd_offset(mm, address);
82323 pud = pud_alloc(mm, pgd, address);
82324@@ -3790,6 +4031,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
82325 spin_unlock(&mm->page_table_lock);
82326 return 0;
82327 }
82328+
82329+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
82330+{
82331+ pud_t *new = pud_alloc_one(mm, address);
82332+ if (!new)
82333+ return -ENOMEM;
82334+
82335+ smp_wmb(); /* See comment in __pte_alloc */
82336+
82337+ spin_lock(&mm->page_table_lock);
82338+ if (pgd_present(*pgd)) /* Another has populated it */
82339+ pud_free(mm, new);
82340+ else
82341+ pgd_populate_kernel(mm, pgd, new);
82342+ spin_unlock(&mm->page_table_lock);
82343+ return 0;
82344+}
82345 #endif /* __PAGETABLE_PUD_FOLDED */
82346
82347 #ifndef __PAGETABLE_PMD_FOLDED
82348@@ -3820,11 +4078,35 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
82349 spin_unlock(&mm->page_table_lock);
82350 return 0;
82351 }
82352+
82353+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
82354+{
82355+ pmd_t *new = pmd_alloc_one(mm, address);
82356+ if (!new)
82357+ return -ENOMEM;
82358+
82359+ smp_wmb(); /* See comment in __pte_alloc */
82360+
82361+ spin_lock(&mm->page_table_lock);
82362+#ifndef __ARCH_HAS_4LEVEL_HACK
82363+ if (pud_present(*pud)) /* Another has populated it */
82364+ pmd_free(mm, new);
82365+ else
82366+ pud_populate_kernel(mm, pud, new);
82367+#else
82368+ if (pgd_present(*pud)) /* Another has populated it */
82369+ pmd_free(mm, new);
82370+ else
82371+ pgd_populate_kernel(mm, pud, new);
82372+#endif /* __ARCH_HAS_4LEVEL_HACK */
82373+ spin_unlock(&mm->page_table_lock);
82374+ return 0;
82375+}
82376 #endif /* __PAGETABLE_PMD_FOLDED */
82377
82378-int make_pages_present(unsigned long addr, unsigned long end)
82379+ssize_t make_pages_present(unsigned long addr, unsigned long end)
82380 {
82381- int ret, len, write;
82382+ ssize_t ret, len, write;
82383 struct vm_area_struct * vma;
82384
82385 vma = find_vma(current->mm, addr);
82386@@ -3857,7 +4139,7 @@ static int __init gate_vma_init(void)
82387 gate_vma.vm_start = FIXADDR_USER_START;
82388 gate_vma.vm_end = FIXADDR_USER_END;
82389 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
82390- gate_vma.vm_page_prot = __P101;
82391+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
82392
82393 return 0;
82394 }
82395@@ -3991,8 +4273,8 @@ out:
82396 return ret;
82397 }
82398
82399-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
82400- void *buf, int len, int write)
82401+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
82402+ void *buf, size_t len, int write)
82403 {
82404 resource_size_t phys_addr;
82405 unsigned long prot = 0;
82406@@ -4017,8 +4299,8 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
82407 * Access another process' address space as given in mm. If non-NULL, use the
82408 * given task for page fault accounting.
82409 */
82410-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
82411- unsigned long addr, void *buf, int len, int write)
82412+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
82413+ unsigned long addr, void *buf, size_t len, int write)
82414 {
82415 struct vm_area_struct *vma;
82416 void *old_buf = buf;
82417@@ -4026,7 +4308,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
82418 down_read(&mm->mmap_sem);
82419 /* ignore errors, just check how much was successfully transferred */
82420 while (len) {
82421- int bytes, ret, offset;
82422+ ssize_t bytes, ret, offset;
82423 void *maddr;
82424 struct page *page = NULL;
82425
82426@@ -4085,8 +4367,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
82427 *
82428 * The caller must hold a reference on @mm.
82429 */
82430-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
82431- void *buf, int len, int write)
82432+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
82433+ void *buf, size_t len, int write)
82434 {
82435 return __access_remote_vm(NULL, mm, addr, buf, len, write);
82436 }
82437@@ -4096,11 +4378,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
82438 * Source/target buffer must be kernel space,
82439 * Do not walk the page table directly, use get_user_pages
82440 */
82441-int access_process_vm(struct task_struct *tsk, unsigned long addr,
82442- void *buf, int len, int write)
82443+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
82444+ void *buf, size_t len, int write)
82445 {
82446 struct mm_struct *mm;
82447- int ret;
82448+ ssize_t ret;
82449
82450 mm = get_task_mm(tsk);
82451 if (!mm)
82452diff --git a/mm/mempolicy.c b/mm/mempolicy.c
82453index 3df6d12..a11056a 100644
82454--- a/mm/mempolicy.c
82455+++ b/mm/mempolicy.c
82456@@ -721,6 +721,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
82457 unsigned long vmstart;
82458 unsigned long vmend;
82459
82460+#ifdef CONFIG_PAX_SEGMEXEC
82461+ struct vm_area_struct *vma_m;
82462+#endif
82463+
82464 vma = find_vma(mm, start);
82465 if (!vma || vma->vm_start > start)
82466 return -EFAULT;
82467@@ -757,9 +761,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
82468 if (err)
82469 goto out;
82470 }
82471+
82472 err = vma_replace_policy(vma, new_pol);
82473 if (err)
82474 goto out;
82475+
82476+#ifdef CONFIG_PAX_SEGMEXEC
82477+ vma_m = pax_find_mirror_vma(vma);
82478+ if (vma_m) {
82479+ err = vma_replace_policy(vma_m, new_pol);
82480+ if (err)
82481+ goto out;
82482+ }
82483+#endif
82484+
82485 }
82486
82487 out:
82488@@ -1216,6 +1231,17 @@ static long do_mbind(unsigned long start, unsigned long len,
82489
82490 if (end < start)
82491 return -EINVAL;
82492+
82493+#ifdef CONFIG_PAX_SEGMEXEC
82494+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
82495+ if (end > SEGMEXEC_TASK_SIZE)
82496+ return -EINVAL;
82497+ } else
82498+#endif
82499+
82500+ if (end > TASK_SIZE)
82501+ return -EINVAL;
82502+
82503 if (end == start)
82504 return 0;
82505
82506@@ -1445,8 +1471,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
82507 */
82508 tcred = __task_cred(task);
82509 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
82510- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
82511- !capable(CAP_SYS_NICE)) {
82512+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
82513 rcu_read_unlock();
82514 err = -EPERM;
82515 goto out_put;
82516@@ -1477,6 +1502,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
82517 goto out;
82518 }
82519
82520+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
82521+ if (mm != current->mm &&
82522+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
82523+ mmput(mm);
82524+ err = -EPERM;
82525+ goto out;
82526+ }
82527+#endif
82528+
82529 err = do_migrate_pages(mm, old, new,
82530 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
82531
82532diff --git a/mm/migrate.c b/mm/migrate.c
82533index 2fd8b4a..d70358f 100644
82534--- a/mm/migrate.c
82535+++ b/mm/migrate.c
82536@@ -1401,8 +1401,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
82537 */
82538 tcred = __task_cred(task);
82539 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
82540- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
82541- !capable(CAP_SYS_NICE)) {
82542+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
82543 rcu_read_unlock();
82544 err = -EPERM;
82545 goto out;
82546diff --git a/mm/mlock.c b/mm/mlock.c
82547index c9bd528..da8d069 100644
82548--- a/mm/mlock.c
82549+++ b/mm/mlock.c
82550@@ -13,6 +13,7 @@
82551 #include <linux/pagemap.h>
82552 #include <linux/mempolicy.h>
82553 #include <linux/syscalls.h>
82554+#include <linux/security.h>
82555 #include <linux/sched.h>
82556 #include <linux/export.h>
82557 #include <linux/rmap.h>
82558@@ -369,7 +370,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
82559 {
82560 unsigned long nstart, end, tmp;
82561 struct vm_area_struct * vma, * prev;
82562- int error;
82563+ int error = 0;
82564
82565 VM_BUG_ON(start & ~PAGE_MASK);
82566 VM_BUG_ON(len != PAGE_ALIGN(len));
82567@@ -378,6 +379,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
82568 return -EINVAL;
82569 if (end == start)
82570 return 0;
82571+ if (end > TASK_SIZE)
82572+ return -EINVAL;
82573+
82574 vma = find_vma(current->mm, start);
82575 if (!vma || vma->vm_start > start)
82576 return -ENOMEM;
82577@@ -389,6 +393,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
82578 for (nstart = start ; ; ) {
82579 vm_flags_t newflags;
82580
82581+#ifdef CONFIG_PAX_SEGMEXEC
82582+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
82583+ break;
82584+#endif
82585+
82586 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
82587
82588 newflags = vma->vm_flags | VM_LOCKED;
82589@@ -494,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
82590 lock_limit >>= PAGE_SHIFT;
82591
82592 /* check against resource limits */
82593+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
82594 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
82595 error = do_mlock(start, len, 1);
82596 up_write(&current->mm->mmap_sem);
82597@@ -528,6 +538,12 @@ static int do_mlockall(int flags)
82598 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
82599 vm_flags_t newflags;
82600
82601+#ifdef CONFIG_PAX_SEGMEXEC
82602+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
82603+ break;
82604+#endif
82605+
82606+ BUG_ON(vma->vm_end > TASK_SIZE);
82607 newflags = vma->vm_flags | VM_LOCKED;
82608 if (!(flags & MCL_CURRENT))
82609 newflags &= ~VM_LOCKED;
82610@@ -560,6 +576,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
82611 lock_limit >>= PAGE_SHIFT;
82612
82613 ret = -ENOMEM;
82614+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
82615 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
82616 capable(CAP_IPC_LOCK))
82617 ret = do_mlockall(flags);
82618diff --git a/mm/mmap.c b/mm/mmap.c
82619index 90db251..04240d1 100644
82620--- a/mm/mmap.c
82621+++ b/mm/mmap.c
82622@@ -32,6 +32,7 @@
82623 #include <linux/khugepaged.h>
82624 #include <linux/uprobes.h>
82625 #include <linux/rbtree_augmented.h>
82626+#include <linux/random.h>
82627
82628 #include <asm/uaccess.h>
82629 #include <asm/cacheflush.h>
82630@@ -48,6 +49,16 @@
82631 #define arch_rebalance_pgtables(addr, len) (addr)
82632 #endif
82633
82634+static inline void verify_mm_writelocked(struct mm_struct *mm)
82635+{
82636+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
82637+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
82638+ up_read(&mm->mmap_sem);
82639+ BUG();
82640+ }
82641+#endif
82642+}
82643+
82644 static void unmap_region(struct mm_struct *mm,
82645 struct vm_area_struct *vma, struct vm_area_struct *prev,
82646 unsigned long start, unsigned long end);
82647@@ -67,22 +78,32 @@ static void unmap_region(struct mm_struct *mm,
82648 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
82649 *
82650 */
82651-pgprot_t protection_map[16] = {
82652+pgprot_t protection_map[16] __read_only = {
82653 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
82654 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
82655 };
82656
82657-pgprot_t vm_get_page_prot(unsigned long vm_flags)
82658+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
82659 {
82660- return __pgprot(pgprot_val(protection_map[vm_flags &
82661+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
82662 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
82663 pgprot_val(arch_vm_get_page_prot(vm_flags)));
82664+
82665+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
82666+ if (!(__supported_pte_mask & _PAGE_NX) &&
82667+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
82668+ (vm_flags & (VM_READ | VM_WRITE)))
82669+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
82670+#endif
82671+
82672+ return prot;
82673 }
82674 EXPORT_SYMBOL(vm_get_page_prot);
82675
82676 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
82677 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
82678 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
82679+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
82680 /*
82681 * Make sure vm_committed_as in one cacheline and not cacheline shared with
82682 * other variables. It can be updated by several CPUs frequently.
82683@@ -238,6 +259,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
82684 struct vm_area_struct *next = vma->vm_next;
82685
82686 might_sleep();
82687+ BUG_ON(vma->vm_mirror);
82688 if (vma->vm_ops && vma->vm_ops->close)
82689 vma->vm_ops->close(vma);
82690 if (vma->vm_file)
82691@@ -281,6 +303,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
82692 * not page aligned -Ram Gupta
82693 */
82694 rlim = rlimit(RLIMIT_DATA);
82695+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
82696 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
82697 (mm->end_data - mm->start_data) > rlim)
82698 goto out;
82699@@ -888,6 +911,12 @@ static int
82700 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
82701 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
82702 {
82703+
82704+#ifdef CONFIG_PAX_SEGMEXEC
82705+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
82706+ return 0;
82707+#endif
82708+
82709 if (is_mergeable_vma(vma, file, vm_flags) &&
82710 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
82711 if (vma->vm_pgoff == vm_pgoff)
82712@@ -907,6 +936,12 @@ static int
82713 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
82714 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
82715 {
82716+
82717+#ifdef CONFIG_PAX_SEGMEXEC
82718+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
82719+ return 0;
82720+#endif
82721+
82722 if (is_mergeable_vma(vma, file, vm_flags) &&
82723 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
82724 pgoff_t vm_pglen;
82725@@ -949,13 +984,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
82726 struct vm_area_struct *vma_merge(struct mm_struct *mm,
82727 struct vm_area_struct *prev, unsigned long addr,
82728 unsigned long end, unsigned long vm_flags,
82729- struct anon_vma *anon_vma, struct file *file,
82730+ struct anon_vma *anon_vma, struct file *file,
82731 pgoff_t pgoff, struct mempolicy *policy)
82732 {
82733 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
82734 struct vm_area_struct *area, *next;
82735 int err;
82736
82737+#ifdef CONFIG_PAX_SEGMEXEC
82738+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
82739+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
82740+
82741+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
82742+#endif
82743+
82744 /*
82745 * We later require that vma->vm_flags == vm_flags,
82746 * so this tests vma->vm_flags & VM_SPECIAL, too.
82747@@ -971,6 +1013,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
82748 if (next && next->vm_end == end) /* cases 6, 7, 8 */
82749 next = next->vm_next;
82750
82751+#ifdef CONFIG_PAX_SEGMEXEC
82752+ if (prev)
82753+ prev_m = pax_find_mirror_vma(prev);
82754+ if (area)
82755+ area_m = pax_find_mirror_vma(area);
82756+ if (next)
82757+ next_m = pax_find_mirror_vma(next);
82758+#endif
82759+
82760 /*
82761 * Can it merge with the predecessor?
82762 */
82763@@ -990,9 +1041,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
82764 /* cases 1, 6 */
82765 err = vma_adjust(prev, prev->vm_start,
82766 next->vm_end, prev->vm_pgoff, NULL);
82767- } else /* cases 2, 5, 7 */
82768+
82769+#ifdef CONFIG_PAX_SEGMEXEC
82770+ if (!err && prev_m)
82771+ err = vma_adjust(prev_m, prev_m->vm_start,
82772+ next_m->vm_end, prev_m->vm_pgoff, NULL);
82773+#endif
82774+
82775+ } else { /* cases 2, 5, 7 */
82776 err = vma_adjust(prev, prev->vm_start,
82777 end, prev->vm_pgoff, NULL);
82778+
82779+#ifdef CONFIG_PAX_SEGMEXEC
82780+ if (!err && prev_m)
82781+ err = vma_adjust(prev_m, prev_m->vm_start,
82782+ end_m, prev_m->vm_pgoff, NULL);
82783+#endif
82784+
82785+ }
82786 if (err)
82787 return NULL;
82788 khugepaged_enter_vma_merge(prev);
82789@@ -1006,12 +1072,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
82790 mpol_equal(policy, vma_policy(next)) &&
82791 can_vma_merge_before(next, vm_flags,
82792 anon_vma, file, pgoff+pglen)) {
82793- if (prev && addr < prev->vm_end) /* case 4 */
82794+ if (prev && addr < prev->vm_end) { /* case 4 */
82795 err = vma_adjust(prev, prev->vm_start,
82796 addr, prev->vm_pgoff, NULL);
82797- else /* cases 3, 8 */
82798+
82799+#ifdef CONFIG_PAX_SEGMEXEC
82800+ if (!err && prev_m)
82801+ err = vma_adjust(prev_m, prev_m->vm_start,
82802+ addr_m, prev_m->vm_pgoff, NULL);
82803+#endif
82804+
82805+ } else { /* cases 3, 8 */
82806 err = vma_adjust(area, addr, next->vm_end,
82807 next->vm_pgoff - pglen, NULL);
82808+
82809+#ifdef CONFIG_PAX_SEGMEXEC
82810+ if (!err && area_m)
82811+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
82812+ next_m->vm_pgoff - pglen, NULL);
82813+#endif
82814+
82815+ }
82816 if (err)
82817 return NULL;
82818 khugepaged_enter_vma_merge(area);
82819@@ -1120,8 +1201,10 @@ none:
82820 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
82821 struct file *file, long pages)
82822 {
82823- const unsigned long stack_flags
82824- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
82825+
82826+#ifdef CONFIG_PAX_RANDMMAP
82827+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
82828+#endif
82829
82830 mm->total_vm += pages;
82831
82832@@ -1129,7 +1212,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
82833 mm->shared_vm += pages;
82834 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
82835 mm->exec_vm += pages;
82836- } else if (flags & stack_flags)
82837+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
82838 mm->stack_vm += pages;
82839 }
82840 #endif /* CONFIG_PROC_FS */
82841@@ -1165,7 +1248,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82842 * (the exception is when the underlying filesystem is noexec
82843 * mounted, in which case we dont add PROT_EXEC.)
82844 */
82845- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
82846+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
82847 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
82848 prot |= PROT_EXEC;
82849
82850@@ -1191,7 +1274,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82851 /* Obtain the address to map to. we verify (or select) it and ensure
82852 * that it represents a valid section of the address space.
82853 */
82854- addr = get_unmapped_area(file, addr, len, pgoff, flags);
82855+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
82856 if (addr & ~PAGE_MASK)
82857 return addr;
82858
82859@@ -1202,6 +1285,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82860 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
82861 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
82862
82863+#ifdef CONFIG_PAX_MPROTECT
82864+ if (mm->pax_flags & MF_PAX_MPROTECT) {
82865+#ifndef CONFIG_PAX_MPROTECT_COMPAT
82866+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
82867+ gr_log_rwxmmap(file);
82868+
82869+#ifdef CONFIG_PAX_EMUPLT
82870+ vm_flags &= ~VM_EXEC;
82871+#else
82872+ return -EPERM;
82873+#endif
82874+
82875+ }
82876+
82877+ if (!(vm_flags & VM_EXEC))
82878+ vm_flags &= ~VM_MAYEXEC;
82879+#else
82880+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
82881+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
82882+#endif
82883+ else
82884+ vm_flags &= ~VM_MAYWRITE;
82885+ }
82886+#endif
82887+
82888+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
82889+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
82890+ vm_flags &= ~VM_PAGEEXEC;
82891+#endif
82892+
82893 if (flags & MAP_LOCKED)
82894 if (!can_do_mlock())
82895 return -EPERM;
82896@@ -1213,6 +1326,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82897 locked += mm->locked_vm;
82898 lock_limit = rlimit(RLIMIT_MEMLOCK);
82899 lock_limit >>= PAGE_SHIFT;
82900+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
82901 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
82902 return -EAGAIN;
82903 }
82904@@ -1279,6 +1393,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82905 }
82906 }
82907
82908+ if (!gr_acl_handle_mmap(file, prot))
82909+ return -EACCES;
82910+
82911 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
82912 }
82913
82914@@ -1356,7 +1473,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
82915 vm_flags_t vm_flags = vma->vm_flags;
82916
82917 /* If it was private or non-writable, the write bit is already clear */
82918- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
82919+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
82920 return 0;
82921
82922 /* The backer wishes to know when pages are first written to? */
82923@@ -1405,16 +1522,30 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
82924 unsigned long charged = 0;
82925 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
82926
82927+#ifdef CONFIG_PAX_SEGMEXEC
82928+ struct vm_area_struct *vma_m = NULL;
82929+#endif
82930+
82931+ /*
82932+ * mm->mmap_sem is required to protect against another thread
82933+ * changing the mappings in case we sleep.
82934+ */
82935+ verify_mm_writelocked(mm);
82936+
82937 /* Clear old maps */
82938 error = -ENOMEM;
82939-munmap_back:
82940 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
82941 if (do_munmap(mm, addr, len))
82942 return -ENOMEM;
82943- goto munmap_back;
82944+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
82945 }
82946
82947 /* Check against address space limit. */
82948+
82949+#ifdef CONFIG_PAX_RANDMMAP
82950+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
82951+#endif
82952+
82953 if (!may_expand_vm(mm, len >> PAGE_SHIFT))
82954 return -ENOMEM;
82955
82956@@ -1460,6 +1591,16 @@ munmap_back:
82957 goto unacct_error;
82958 }
82959
82960+#ifdef CONFIG_PAX_SEGMEXEC
82961+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
82962+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
82963+ if (!vma_m) {
82964+ error = -ENOMEM;
82965+ goto free_vma;
82966+ }
82967+ }
82968+#endif
82969+
82970 vma->vm_mm = mm;
82971 vma->vm_start = addr;
82972 vma->vm_end = addr + len;
82973@@ -1484,6 +1625,13 @@ munmap_back:
82974 if (error)
82975 goto unmap_and_free_vma;
82976
82977+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
82978+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
82979+ vma->vm_flags |= VM_PAGEEXEC;
82980+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
82981+ }
82982+#endif
82983+
82984 /* Can addr have changed??
82985 *
82986 * Answer: Yes, several device drivers can do it in their
82987@@ -1522,6 +1670,11 @@ munmap_back:
82988 vma_link(mm, vma, prev, rb_link, rb_parent);
82989 file = vma->vm_file;
82990
82991+#ifdef CONFIG_PAX_SEGMEXEC
82992+ if (vma_m)
82993+ BUG_ON(pax_mirror_vma(vma_m, vma));
82994+#endif
82995+
82996 /* Once vma denies write, undo our temporary denial count */
82997 if (correct_wcount)
82998 atomic_inc(&inode->i_writecount);
82999@@ -1529,6 +1682,7 @@ out:
83000 perf_event_mmap(vma);
83001
83002 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
83003+ track_exec_limit(mm, addr, addr + len, vm_flags);
83004 if (vm_flags & VM_LOCKED) {
83005 if (!mlock_vma_pages_range(vma, addr, addr + len))
83006 mm->locked_vm += (len >> PAGE_SHIFT);
83007@@ -1550,6 +1704,12 @@ unmap_and_free_vma:
83008 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
83009 charged = 0;
83010 free_vma:
83011+
83012+#ifdef CONFIG_PAX_SEGMEXEC
83013+ if (vma_m)
83014+ kmem_cache_free(vm_area_cachep, vma_m);
83015+#endif
83016+
83017 kmem_cache_free(vm_area_cachep, vma);
83018 unacct_error:
83019 if (charged)
83020@@ -1557,6 +1717,62 @@ unacct_error:
83021 return error;
83022 }
83023
83024+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
83025+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
83026+{
83027+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
83028+ return (random32() & 0xFF) << PAGE_SHIFT;
83029+
83030+ return 0;
83031+}
83032+#endif
83033+
83034+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
83035+{
83036+ if (!vma) {
83037+#ifdef CONFIG_STACK_GROWSUP
83038+ if (addr > sysctl_heap_stack_gap)
83039+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
83040+ else
83041+ vma = find_vma(current->mm, 0);
83042+ if (vma && (vma->vm_flags & VM_GROWSUP))
83043+ return false;
83044+#endif
83045+ return true;
83046+ }
83047+
83048+ if (addr + len > vma->vm_start)
83049+ return false;
83050+
83051+ if (vma->vm_flags & VM_GROWSDOWN)
83052+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
83053+#ifdef CONFIG_STACK_GROWSUP
83054+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
83055+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
83056+#endif
83057+ else if (offset)
83058+ return offset <= vma->vm_start - addr - len;
83059+
83060+ return true;
83061+}
83062+
83063+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
83064+{
83065+ if (vma->vm_start < len)
83066+ return -ENOMEM;
83067+
83068+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
83069+ if (offset <= vma->vm_start - len)
83070+ return vma->vm_start - len - offset;
83071+ else
83072+ return -ENOMEM;
83073+ }
83074+
83075+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
83076+ return vma->vm_start - len - sysctl_heap_stack_gap;
83077+ return -ENOMEM;
83078+}
83079+
83080 unsigned long unmapped_area(struct vm_unmapped_area_info *info)
83081 {
83082 /*
83083@@ -1776,6 +1992,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
83084 struct mm_struct *mm = current->mm;
83085 struct vm_area_struct *vma;
83086 struct vm_unmapped_area_info info;
83087+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
83088
83089 if (len > TASK_SIZE)
83090 return -ENOMEM;
83091@@ -1783,17 +2000,26 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
83092 if (flags & MAP_FIXED)
83093 return addr;
83094
83095+#ifdef CONFIG_PAX_RANDMMAP
83096+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
83097+#endif
83098+
83099 if (addr) {
83100 addr = PAGE_ALIGN(addr);
83101 vma = find_vma(mm, addr);
83102- if (TASK_SIZE - len >= addr &&
83103- (!vma || addr + len <= vma->vm_start))
83104+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
83105 return addr;
83106 }
83107
83108 info.flags = 0;
83109 info.length = len;
83110 info.low_limit = TASK_UNMAPPED_BASE;
83111+
83112+#ifdef CONFIG_PAX_RANDMMAP
83113+ if (mm->pax_flags & MF_PAX_RANDMMAP)
83114+ info.low_limit += mm->delta_mmap;
83115+#endif
83116+
83117 info.high_limit = TASK_SIZE;
83118 info.align_mask = 0;
83119 return vm_unmapped_area(&info);
83120@@ -1802,10 +2028,16 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
83121
83122 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
83123 {
83124+
83125+#ifdef CONFIG_PAX_SEGMEXEC
83126+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
83127+ return;
83128+#endif
83129+
83130 /*
83131 * Is this a new hole at the lowest possible address?
83132 */
83133- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
83134+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
83135 mm->free_area_cache = addr;
83136 }
83137
83138@@ -1823,6 +2055,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
83139 struct mm_struct *mm = current->mm;
83140 unsigned long addr = addr0;
83141 struct vm_unmapped_area_info info;
83142+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
83143
83144 /* requested length too big for entire address space */
83145 if (len > TASK_SIZE)
83146@@ -1831,12 +2064,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
83147 if (flags & MAP_FIXED)
83148 return addr;
83149
83150+#ifdef CONFIG_PAX_RANDMMAP
83151+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
83152+#endif
83153+
83154 /* requesting a specific address */
83155 if (addr) {
83156 addr = PAGE_ALIGN(addr);
83157 vma = find_vma(mm, addr);
83158- if (TASK_SIZE - len >= addr &&
83159- (!vma || addr + len <= vma->vm_start))
83160+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
83161 return addr;
83162 }
83163
83164@@ -1857,6 +2093,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
83165 VM_BUG_ON(addr != -ENOMEM);
83166 info.flags = 0;
83167 info.low_limit = TASK_UNMAPPED_BASE;
83168+
83169+#ifdef CONFIG_PAX_RANDMMAP
83170+ if (mm->pax_flags & MF_PAX_RANDMMAP)
83171+ info.low_limit += mm->delta_mmap;
83172+#endif
83173+
83174 info.high_limit = TASK_SIZE;
83175 addr = vm_unmapped_area(&info);
83176 }
83177@@ -1867,6 +2109,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
83178
83179 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
83180 {
83181+
83182+#ifdef CONFIG_PAX_SEGMEXEC
83183+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
83184+ return;
83185+#endif
83186+
83187 /*
83188 * Is this a new hole at the highest possible address?
83189 */
83190@@ -1874,8 +2122,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
83191 mm->free_area_cache = addr;
83192
83193 /* dont allow allocations above current base */
83194- if (mm->free_area_cache > mm->mmap_base)
83195+ if (mm->free_area_cache > mm->mmap_base) {
83196 mm->free_area_cache = mm->mmap_base;
83197+ mm->cached_hole_size = ~0UL;
83198+ }
83199 }
83200
83201 unsigned long
83202@@ -1974,6 +2224,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
83203 return vma;
83204 }
83205
83206+#ifdef CONFIG_PAX_SEGMEXEC
83207+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
83208+{
83209+ struct vm_area_struct *vma_m;
83210+
83211+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
83212+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
83213+ BUG_ON(vma->vm_mirror);
83214+ return NULL;
83215+ }
83216+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
83217+ vma_m = vma->vm_mirror;
83218+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
83219+ BUG_ON(vma->vm_file != vma_m->vm_file);
83220+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
83221+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
83222+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
83223+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
83224+ return vma_m;
83225+}
83226+#endif
83227+
83228 /*
83229 * Verify that the stack growth is acceptable and
83230 * update accounting. This is shared with both the
83231@@ -1990,6 +2262,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
83232 return -ENOMEM;
83233
83234 /* Stack limit test */
83235+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
83236 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
83237 return -ENOMEM;
83238
83239@@ -2000,6 +2273,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
83240 locked = mm->locked_vm + grow;
83241 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
83242 limit >>= PAGE_SHIFT;
83243+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
83244 if (locked > limit && !capable(CAP_IPC_LOCK))
83245 return -ENOMEM;
83246 }
83247@@ -2029,37 +2303,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
83248 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
83249 * vma is the last one with address > vma->vm_end. Have to extend vma.
83250 */
83251+#ifndef CONFIG_IA64
83252+static
83253+#endif
83254 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
83255 {
83256 int error;
83257+ bool locknext;
83258
83259 if (!(vma->vm_flags & VM_GROWSUP))
83260 return -EFAULT;
83261
83262+ /* Also guard against wrapping around to address 0. */
83263+ if (address < PAGE_ALIGN(address+1))
83264+ address = PAGE_ALIGN(address+1);
83265+ else
83266+ return -ENOMEM;
83267+
83268 /*
83269 * We must make sure the anon_vma is allocated
83270 * so that the anon_vma locking is not a noop.
83271 */
83272 if (unlikely(anon_vma_prepare(vma)))
83273 return -ENOMEM;
83274+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
83275+ if (locknext && anon_vma_prepare(vma->vm_next))
83276+ return -ENOMEM;
83277 vma_lock_anon_vma(vma);
83278+ if (locknext)
83279+ vma_lock_anon_vma(vma->vm_next);
83280
83281 /*
83282 * vma->vm_start/vm_end cannot change under us because the caller
83283 * is required to hold the mmap_sem in read mode. We need the
83284- * anon_vma lock to serialize against concurrent expand_stacks.
83285- * Also guard against wrapping around to address 0.
83286+ * anon_vma locks to serialize against concurrent expand_stacks
83287+ * and expand_upwards.
83288 */
83289- if (address < PAGE_ALIGN(address+4))
83290- address = PAGE_ALIGN(address+4);
83291- else {
83292- vma_unlock_anon_vma(vma);
83293- return -ENOMEM;
83294- }
83295 error = 0;
83296
83297 /* Somebody else might have raced and expanded it already */
83298- if (address > vma->vm_end) {
83299+ 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)
83300+ error = -ENOMEM;
83301+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
83302 unsigned long size, grow;
83303
83304 size = address - vma->vm_start;
83305@@ -2094,6 +2379,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
83306 }
83307 }
83308 }
83309+ if (locknext)
83310+ vma_unlock_anon_vma(vma->vm_next);
83311 vma_unlock_anon_vma(vma);
83312 khugepaged_enter_vma_merge(vma);
83313 validate_mm(vma->vm_mm);
83314@@ -2108,6 +2395,8 @@ int expand_downwards(struct vm_area_struct *vma,
83315 unsigned long address)
83316 {
83317 int error;
83318+ bool lockprev = false;
83319+ struct vm_area_struct *prev;
83320
83321 /*
83322 * We must make sure the anon_vma is allocated
83323@@ -2121,6 +2410,15 @@ int expand_downwards(struct vm_area_struct *vma,
83324 if (error)
83325 return error;
83326
83327+ prev = vma->vm_prev;
83328+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
83329+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
83330+#endif
83331+ if (lockprev && anon_vma_prepare(prev))
83332+ return -ENOMEM;
83333+ if (lockprev)
83334+ vma_lock_anon_vma(prev);
83335+
83336 vma_lock_anon_vma(vma);
83337
83338 /*
83339@@ -2130,9 +2428,17 @@ int expand_downwards(struct vm_area_struct *vma,
83340 */
83341
83342 /* Somebody else might have raced and expanded it already */
83343- if (address < vma->vm_start) {
83344+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
83345+ error = -ENOMEM;
83346+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
83347 unsigned long size, grow;
83348
83349+#ifdef CONFIG_PAX_SEGMEXEC
83350+ struct vm_area_struct *vma_m;
83351+
83352+ vma_m = pax_find_mirror_vma(vma);
83353+#endif
83354+
83355 size = vma->vm_end - address;
83356 grow = (vma->vm_start - address) >> PAGE_SHIFT;
83357
83358@@ -2157,6 +2463,18 @@ int expand_downwards(struct vm_area_struct *vma,
83359 vma->vm_pgoff -= grow;
83360 anon_vma_interval_tree_post_update_vma(vma);
83361 vma_gap_update(vma);
83362+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
83363+
83364+#ifdef CONFIG_PAX_SEGMEXEC
83365+ if (vma_m) {
83366+ anon_vma_interval_tree_pre_update_vma(vma_m);
83367+ vma_m->vm_start -= grow << PAGE_SHIFT;
83368+ vma_m->vm_pgoff -= grow;
83369+ anon_vma_interval_tree_post_update_vma(vma_m);
83370+ vma_gap_update(vma_m);
83371+ }
83372+#endif
83373+
83374 spin_unlock(&vma->vm_mm->page_table_lock);
83375
83376 perf_event_mmap(vma);
83377@@ -2263,6 +2581,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
83378 do {
83379 long nrpages = vma_pages(vma);
83380
83381+#ifdef CONFIG_PAX_SEGMEXEC
83382+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
83383+ vma = remove_vma(vma);
83384+ continue;
83385+ }
83386+#endif
83387+
83388 if (vma->vm_flags & VM_ACCOUNT)
83389 nr_accounted += nrpages;
83390 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
83391@@ -2308,6 +2633,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
83392 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
83393 vma->vm_prev = NULL;
83394 do {
83395+
83396+#ifdef CONFIG_PAX_SEGMEXEC
83397+ if (vma->vm_mirror) {
83398+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
83399+ vma->vm_mirror->vm_mirror = NULL;
83400+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
83401+ vma->vm_mirror = NULL;
83402+ }
83403+#endif
83404+
83405 vma_rb_erase(vma, &mm->mm_rb);
83406 mm->map_count--;
83407 tail_vma = vma;
83408@@ -2339,14 +2674,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
83409 struct vm_area_struct *new;
83410 int err = -ENOMEM;
83411
83412+#ifdef CONFIG_PAX_SEGMEXEC
83413+ struct vm_area_struct *vma_m, *new_m = NULL;
83414+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
83415+#endif
83416+
83417 if (is_vm_hugetlb_page(vma) && (addr &
83418 ~(huge_page_mask(hstate_vma(vma)))))
83419 return -EINVAL;
83420
83421+#ifdef CONFIG_PAX_SEGMEXEC
83422+ vma_m = pax_find_mirror_vma(vma);
83423+#endif
83424+
83425 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
83426 if (!new)
83427 goto out_err;
83428
83429+#ifdef CONFIG_PAX_SEGMEXEC
83430+ if (vma_m) {
83431+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
83432+ if (!new_m) {
83433+ kmem_cache_free(vm_area_cachep, new);
83434+ goto out_err;
83435+ }
83436+ }
83437+#endif
83438+
83439 /* most fields are the same, copy all, and then fixup */
83440 *new = *vma;
83441
83442@@ -2359,6 +2713,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
83443 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
83444 }
83445
83446+#ifdef CONFIG_PAX_SEGMEXEC
83447+ if (vma_m) {
83448+ *new_m = *vma_m;
83449+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
83450+ new_m->vm_mirror = new;
83451+ new->vm_mirror = new_m;
83452+
83453+ if (new_below)
83454+ new_m->vm_end = addr_m;
83455+ else {
83456+ new_m->vm_start = addr_m;
83457+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
83458+ }
83459+ }
83460+#endif
83461+
83462 pol = mpol_dup(vma_policy(vma));
83463 if (IS_ERR(pol)) {
83464 err = PTR_ERR(pol);
83465@@ -2381,6 +2751,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
83466 else
83467 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
83468
83469+#ifdef CONFIG_PAX_SEGMEXEC
83470+ if (!err && vma_m) {
83471+ if (anon_vma_clone(new_m, vma_m))
83472+ goto out_free_mpol;
83473+
83474+ mpol_get(pol);
83475+ vma_set_policy(new_m, pol);
83476+
83477+ if (new_m->vm_file)
83478+ get_file(new_m->vm_file);
83479+
83480+ if (new_m->vm_ops && new_m->vm_ops->open)
83481+ new_m->vm_ops->open(new_m);
83482+
83483+ if (new_below)
83484+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
83485+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
83486+ else
83487+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
83488+
83489+ if (err) {
83490+ if (new_m->vm_ops && new_m->vm_ops->close)
83491+ new_m->vm_ops->close(new_m);
83492+ if (new_m->vm_file)
83493+ fput(new_m->vm_file);
83494+ mpol_put(pol);
83495+ }
83496+ }
83497+#endif
83498+
83499 /* Success. */
83500 if (!err)
83501 return 0;
83502@@ -2390,10 +2790,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
83503 new->vm_ops->close(new);
83504 if (new->vm_file)
83505 fput(new->vm_file);
83506- unlink_anon_vmas(new);
83507 out_free_mpol:
83508 mpol_put(pol);
83509 out_free_vma:
83510+
83511+#ifdef CONFIG_PAX_SEGMEXEC
83512+ if (new_m) {
83513+ unlink_anon_vmas(new_m);
83514+ kmem_cache_free(vm_area_cachep, new_m);
83515+ }
83516+#endif
83517+
83518+ unlink_anon_vmas(new);
83519 kmem_cache_free(vm_area_cachep, new);
83520 out_err:
83521 return err;
83522@@ -2406,6 +2814,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
83523 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
83524 unsigned long addr, int new_below)
83525 {
83526+
83527+#ifdef CONFIG_PAX_SEGMEXEC
83528+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
83529+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
83530+ if (mm->map_count >= sysctl_max_map_count-1)
83531+ return -ENOMEM;
83532+ } else
83533+#endif
83534+
83535 if (mm->map_count >= sysctl_max_map_count)
83536 return -ENOMEM;
83537
83538@@ -2417,11 +2834,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
83539 * work. This now handles partial unmappings.
83540 * Jeremy Fitzhardinge <jeremy@goop.org>
83541 */
83542+#ifdef CONFIG_PAX_SEGMEXEC
83543 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
83544 {
83545+ int ret = __do_munmap(mm, start, len);
83546+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
83547+ return ret;
83548+
83549+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
83550+}
83551+
83552+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
83553+#else
83554+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
83555+#endif
83556+{
83557 unsigned long end;
83558 struct vm_area_struct *vma, *prev, *last;
83559
83560+ /*
83561+ * mm->mmap_sem is required to protect against another thread
83562+ * changing the mappings in case we sleep.
83563+ */
83564+ verify_mm_writelocked(mm);
83565+
83566 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
83567 return -EINVAL;
83568
83569@@ -2496,6 +2932,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
83570 /* Fix up all other VM information */
83571 remove_vma_list(mm, vma);
83572
83573+ track_exec_limit(mm, start, end, 0UL);
83574+
83575 return 0;
83576 }
83577
83578@@ -2504,6 +2942,13 @@ int vm_munmap(unsigned long start, size_t len)
83579 int ret;
83580 struct mm_struct *mm = current->mm;
83581
83582+
83583+#ifdef CONFIG_PAX_SEGMEXEC
83584+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
83585+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
83586+ return -EINVAL;
83587+#endif
83588+
83589 down_write(&mm->mmap_sem);
83590 ret = do_munmap(mm, start, len);
83591 up_write(&mm->mmap_sem);
83592@@ -2517,16 +2962,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
83593 return vm_munmap(addr, len);
83594 }
83595
83596-static inline void verify_mm_writelocked(struct mm_struct *mm)
83597-{
83598-#ifdef CONFIG_DEBUG_VM
83599- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
83600- WARN_ON(1);
83601- up_read(&mm->mmap_sem);
83602- }
83603-#endif
83604-}
83605-
83606 /*
83607 * this is really a simplified "do_mmap". it only handles
83608 * anonymous maps. eventually we may be able to do some
83609@@ -2540,6 +2975,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83610 struct rb_node ** rb_link, * rb_parent;
83611 pgoff_t pgoff = addr >> PAGE_SHIFT;
83612 int error;
83613+ unsigned long charged;
83614
83615 len = PAGE_ALIGN(len);
83616 if (!len)
83617@@ -2547,16 +2983,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83618
83619 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
83620
83621+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
83622+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
83623+ flags &= ~VM_EXEC;
83624+
83625+#ifdef CONFIG_PAX_MPROTECT
83626+ if (mm->pax_flags & MF_PAX_MPROTECT)
83627+ flags &= ~VM_MAYEXEC;
83628+#endif
83629+
83630+ }
83631+#endif
83632+
83633 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
83634 if (error & ~PAGE_MASK)
83635 return error;
83636
83637+ charged = len >> PAGE_SHIFT;
83638+
83639 /*
83640 * mlock MCL_FUTURE?
83641 */
83642 if (mm->def_flags & VM_LOCKED) {
83643 unsigned long locked, lock_limit;
83644- locked = len >> PAGE_SHIFT;
83645+ locked = charged;
83646 locked += mm->locked_vm;
83647 lock_limit = rlimit(RLIMIT_MEMLOCK);
83648 lock_limit >>= PAGE_SHIFT;
83649@@ -2573,21 +3023,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83650 /*
83651 * Clear old maps. this also does some error checking for us
83652 */
83653- munmap_back:
83654 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
83655 if (do_munmap(mm, addr, len))
83656 return -ENOMEM;
83657- goto munmap_back;
83658+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
83659 }
83660
83661 /* Check against address space limits *after* clearing old maps... */
83662- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
83663+ if (!may_expand_vm(mm, charged))
83664 return -ENOMEM;
83665
83666 if (mm->map_count > sysctl_max_map_count)
83667 return -ENOMEM;
83668
83669- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
83670+ if (security_vm_enough_memory_mm(mm, charged))
83671 return -ENOMEM;
83672
83673 /* Can we just expand an old private anonymous mapping? */
83674@@ -2601,7 +3050,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83675 */
83676 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
83677 if (!vma) {
83678- vm_unacct_memory(len >> PAGE_SHIFT);
83679+ vm_unacct_memory(charged);
83680 return -ENOMEM;
83681 }
83682
83683@@ -2615,11 +3064,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83684 vma_link(mm, vma, prev, rb_link, rb_parent);
83685 out:
83686 perf_event_mmap(vma);
83687- mm->total_vm += len >> PAGE_SHIFT;
83688+ mm->total_vm += charged;
83689 if (flags & VM_LOCKED) {
83690 if (!mlock_vma_pages_range(vma, addr, addr + len))
83691- mm->locked_vm += (len >> PAGE_SHIFT);
83692+ mm->locked_vm += charged;
83693 }
83694+ track_exec_limit(mm, addr, addr + len, flags);
83695 return addr;
83696 }
83697
83698@@ -2677,6 +3127,7 @@ void exit_mmap(struct mm_struct *mm)
83699 while (vma) {
83700 if (vma->vm_flags & VM_ACCOUNT)
83701 nr_accounted += vma_pages(vma);
83702+ vma->vm_mirror = NULL;
83703 vma = remove_vma(vma);
83704 }
83705 vm_unacct_memory(nr_accounted);
83706@@ -2693,6 +3144,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
83707 struct vm_area_struct *prev;
83708 struct rb_node **rb_link, *rb_parent;
83709
83710+#ifdef CONFIG_PAX_SEGMEXEC
83711+ struct vm_area_struct *vma_m = NULL;
83712+#endif
83713+
83714+ if (security_mmap_addr(vma->vm_start))
83715+ return -EPERM;
83716+
83717 /*
83718 * The vm_pgoff of a purely anonymous vma should be irrelevant
83719 * until its first write fault, when page's anon_vma and index
83720@@ -2716,7 +3174,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
83721 security_vm_enough_memory_mm(mm, vma_pages(vma)))
83722 return -ENOMEM;
83723
83724+#ifdef CONFIG_PAX_SEGMEXEC
83725+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
83726+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
83727+ if (!vma_m)
83728+ return -ENOMEM;
83729+ }
83730+#endif
83731+
83732 vma_link(mm, vma, prev, rb_link, rb_parent);
83733+
83734+#ifdef CONFIG_PAX_SEGMEXEC
83735+ if (vma_m)
83736+ BUG_ON(pax_mirror_vma(vma_m, vma));
83737+#endif
83738+
83739 return 0;
83740 }
83741
83742@@ -2736,6 +3208,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
83743 struct mempolicy *pol;
83744 bool faulted_in_anon_vma = true;
83745
83746+ BUG_ON(vma->vm_mirror);
83747+
83748 /*
83749 * If anonymous vma has not yet been faulted, update new pgoff
83750 * to match new location, to increase its chance of merging.
83751@@ -2802,6 +3276,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
83752 return NULL;
83753 }
83754
83755+#ifdef CONFIG_PAX_SEGMEXEC
83756+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
83757+{
83758+ struct vm_area_struct *prev_m;
83759+ struct rb_node **rb_link_m, *rb_parent_m;
83760+ struct mempolicy *pol_m;
83761+
83762+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
83763+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
83764+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
83765+ *vma_m = *vma;
83766+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
83767+ if (anon_vma_clone(vma_m, vma))
83768+ return -ENOMEM;
83769+ pol_m = vma_policy(vma_m);
83770+ mpol_get(pol_m);
83771+ vma_set_policy(vma_m, pol_m);
83772+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
83773+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
83774+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
83775+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
83776+ if (vma_m->vm_file)
83777+ get_file(vma_m->vm_file);
83778+ if (vma_m->vm_ops && vma_m->vm_ops->open)
83779+ vma_m->vm_ops->open(vma_m);
83780+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
83781+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
83782+ vma_m->vm_mirror = vma;
83783+ vma->vm_mirror = vma_m;
83784+ return 0;
83785+}
83786+#endif
83787+
83788 /*
83789 * Return true if the calling process may expand its vm space by the passed
83790 * number of pages
83791@@ -2813,6 +3320,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
83792
83793 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
83794
83795+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
83796 if (cur + npages > lim)
83797 return 0;
83798 return 1;
83799@@ -2883,6 +3391,22 @@ int install_special_mapping(struct mm_struct *mm,
83800 vma->vm_start = addr;
83801 vma->vm_end = addr + len;
83802
83803+#ifdef CONFIG_PAX_MPROTECT
83804+ if (mm->pax_flags & MF_PAX_MPROTECT) {
83805+#ifndef CONFIG_PAX_MPROTECT_COMPAT
83806+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
83807+ return -EPERM;
83808+ if (!(vm_flags & VM_EXEC))
83809+ vm_flags &= ~VM_MAYEXEC;
83810+#else
83811+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
83812+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
83813+#endif
83814+ else
83815+ vm_flags &= ~VM_MAYWRITE;
83816+ }
83817+#endif
83818+
83819 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
83820 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
83821
83822diff --git a/mm/mprotect.c b/mm/mprotect.c
83823index 94722a4..9837984 100644
83824--- a/mm/mprotect.c
83825+++ b/mm/mprotect.c
83826@@ -23,10 +23,17 @@
83827 #include <linux/mmu_notifier.h>
83828 #include <linux/migrate.h>
83829 #include <linux/perf_event.h>
83830+
83831+#ifdef CONFIG_PAX_MPROTECT
83832+#include <linux/elf.h>
83833+#include <linux/binfmts.h>
83834+#endif
83835+
83836 #include <asm/uaccess.h>
83837 #include <asm/pgtable.h>
83838 #include <asm/cacheflush.h>
83839 #include <asm/tlbflush.h>
83840+#include <asm/mmu_context.h>
83841
83842 #ifndef pgprot_modify
83843 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
83844@@ -233,6 +240,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
83845 return pages;
83846 }
83847
83848+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
83849+/* called while holding the mmap semaphor for writing except stack expansion */
83850+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
83851+{
83852+ unsigned long oldlimit, newlimit = 0UL;
83853+
83854+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
83855+ return;
83856+
83857+ spin_lock(&mm->page_table_lock);
83858+ oldlimit = mm->context.user_cs_limit;
83859+ if ((prot & VM_EXEC) && oldlimit < end)
83860+ /* USER_CS limit moved up */
83861+ newlimit = end;
83862+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
83863+ /* USER_CS limit moved down */
83864+ newlimit = start;
83865+
83866+ if (newlimit) {
83867+ mm->context.user_cs_limit = newlimit;
83868+
83869+#ifdef CONFIG_SMP
83870+ wmb();
83871+ cpus_clear(mm->context.cpu_user_cs_mask);
83872+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
83873+#endif
83874+
83875+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
83876+ }
83877+ spin_unlock(&mm->page_table_lock);
83878+ if (newlimit == end) {
83879+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
83880+
83881+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
83882+ if (is_vm_hugetlb_page(vma))
83883+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
83884+ else
83885+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
83886+ }
83887+}
83888+#endif
83889+
83890 int
83891 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
83892 unsigned long start, unsigned long end, unsigned long newflags)
83893@@ -245,11 +294,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
83894 int error;
83895 int dirty_accountable = 0;
83896
83897+#ifdef CONFIG_PAX_SEGMEXEC
83898+ struct vm_area_struct *vma_m = NULL;
83899+ unsigned long start_m, end_m;
83900+
83901+ start_m = start + SEGMEXEC_TASK_SIZE;
83902+ end_m = end + SEGMEXEC_TASK_SIZE;
83903+#endif
83904+
83905 if (newflags == oldflags) {
83906 *pprev = vma;
83907 return 0;
83908 }
83909
83910+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
83911+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
83912+
83913+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
83914+ return -ENOMEM;
83915+
83916+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
83917+ return -ENOMEM;
83918+ }
83919+
83920 /*
83921 * If we make a private mapping writable we increase our commit;
83922 * but (without finer accounting) cannot reduce our commit if we
83923@@ -266,6 +333,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
83924 }
83925 }
83926
83927+#ifdef CONFIG_PAX_SEGMEXEC
83928+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
83929+ if (start != vma->vm_start) {
83930+ error = split_vma(mm, vma, start, 1);
83931+ if (error)
83932+ goto fail;
83933+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
83934+ *pprev = (*pprev)->vm_next;
83935+ }
83936+
83937+ if (end != vma->vm_end) {
83938+ error = split_vma(mm, vma, end, 0);
83939+ if (error)
83940+ goto fail;
83941+ }
83942+
83943+ if (pax_find_mirror_vma(vma)) {
83944+ error = __do_munmap(mm, start_m, end_m - start_m);
83945+ if (error)
83946+ goto fail;
83947+ } else {
83948+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
83949+ if (!vma_m) {
83950+ error = -ENOMEM;
83951+ goto fail;
83952+ }
83953+ vma->vm_flags = newflags;
83954+ error = pax_mirror_vma(vma_m, vma);
83955+ if (error) {
83956+ vma->vm_flags = oldflags;
83957+ goto fail;
83958+ }
83959+ }
83960+ }
83961+#endif
83962+
83963 /*
83964 * First try to merge with previous and/or next vma.
83965 */
83966@@ -296,9 +399,21 @@ success:
83967 * vm_flags and vm_page_prot are protected by the mmap_sem
83968 * held in write mode.
83969 */
83970+
83971+#ifdef CONFIG_PAX_SEGMEXEC
83972+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
83973+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
83974+#endif
83975+
83976 vma->vm_flags = newflags;
83977+
83978+#ifdef CONFIG_PAX_MPROTECT
83979+ if (mm->binfmt && mm->binfmt->handle_mprotect)
83980+ mm->binfmt->handle_mprotect(vma, newflags);
83981+#endif
83982+
83983 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
83984- vm_get_page_prot(newflags));
83985+ vm_get_page_prot(vma->vm_flags));
83986
83987 if (vma_wants_writenotify(vma)) {
83988 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
83989@@ -337,6 +452,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83990 end = start + len;
83991 if (end <= start)
83992 return -ENOMEM;
83993+
83994+#ifdef CONFIG_PAX_SEGMEXEC
83995+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
83996+ if (end > SEGMEXEC_TASK_SIZE)
83997+ return -EINVAL;
83998+ } else
83999+#endif
84000+
84001+ if (end > TASK_SIZE)
84002+ return -EINVAL;
84003+
84004 if (!arch_validate_prot(prot))
84005 return -EINVAL;
84006
84007@@ -344,7 +470,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
84008 /*
84009 * Does the application expect PROT_READ to imply PROT_EXEC:
84010 */
84011- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
84012+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
84013 prot |= PROT_EXEC;
84014
84015 vm_flags = calc_vm_prot_bits(prot);
84016@@ -376,6 +502,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
84017 if (start > vma->vm_start)
84018 prev = vma;
84019
84020+#ifdef CONFIG_PAX_MPROTECT
84021+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
84022+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
84023+#endif
84024+
84025 for (nstart = start ; ; ) {
84026 unsigned long newflags;
84027
84028@@ -386,6 +517,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
84029
84030 /* newflags >> 4 shift VM_MAY% in place of VM_% */
84031 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
84032+ if (prot & (PROT_WRITE | PROT_EXEC))
84033+ gr_log_rwxmprotect(vma->vm_file);
84034+
84035+ error = -EACCES;
84036+ goto out;
84037+ }
84038+
84039+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
84040 error = -EACCES;
84041 goto out;
84042 }
84043@@ -400,6 +539,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
84044 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
84045 if (error)
84046 goto out;
84047+
84048+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
84049+
84050 nstart = tmp;
84051
84052 if (nstart < prev->vm_end)
84053diff --git a/mm/mremap.c b/mm/mremap.c
84054index e1031e1..1f2a0a1 100644
84055--- a/mm/mremap.c
84056+++ b/mm/mremap.c
84057@@ -125,6 +125,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
84058 continue;
84059 pte = ptep_get_and_clear(mm, old_addr, old_pte);
84060 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
84061+
84062+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
84063+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
84064+ pte = pte_exprotect(pte);
84065+#endif
84066+
84067 set_pte_at(mm, new_addr, new_pte, pte);
84068 }
84069
84070@@ -319,6 +325,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
84071 if (is_vm_hugetlb_page(vma))
84072 goto Einval;
84073
84074+#ifdef CONFIG_PAX_SEGMEXEC
84075+ if (pax_find_mirror_vma(vma))
84076+ goto Einval;
84077+#endif
84078+
84079 /* We can't remap across vm area boundaries */
84080 if (old_len > vma->vm_end - addr)
84081 goto Efault;
84082@@ -375,20 +386,25 @@ static unsigned long mremap_to(unsigned long addr,
84083 unsigned long ret = -EINVAL;
84084 unsigned long charged = 0;
84085 unsigned long map_flags;
84086+ unsigned long pax_task_size = TASK_SIZE;
84087
84088 if (new_addr & ~PAGE_MASK)
84089 goto out;
84090
84091- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
84092+#ifdef CONFIG_PAX_SEGMEXEC
84093+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
84094+ pax_task_size = SEGMEXEC_TASK_SIZE;
84095+#endif
84096+
84097+ pax_task_size -= PAGE_SIZE;
84098+
84099+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
84100 goto out;
84101
84102 /* Check if the location we're moving into overlaps the
84103 * old location at all, and fail if it does.
84104 */
84105- if ((new_addr <= addr) && (new_addr+new_len) > addr)
84106- goto out;
84107-
84108- if ((addr <= new_addr) && (addr+old_len) > new_addr)
84109+ if (addr + old_len > new_addr && new_addr + new_len > addr)
84110 goto out;
84111
84112 ret = do_munmap(mm, new_addr, new_len);
84113@@ -456,6 +472,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
84114 struct vm_area_struct *vma;
84115 unsigned long ret = -EINVAL;
84116 unsigned long charged = 0;
84117+ unsigned long pax_task_size = TASK_SIZE;
84118
84119 down_write(&current->mm->mmap_sem);
84120
84121@@ -476,6 +493,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
84122 if (!new_len)
84123 goto out;
84124
84125+#ifdef CONFIG_PAX_SEGMEXEC
84126+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
84127+ pax_task_size = SEGMEXEC_TASK_SIZE;
84128+#endif
84129+
84130+ pax_task_size -= PAGE_SIZE;
84131+
84132+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
84133+ old_len > pax_task_size || addr > pax_task_size-old_len)
84134+ goto out;
84135+
84136 if (flags & MREMAP_FIXED) {
84137 if (flags & MREMAP_MAYMOVE)
84138 ret = mremap_to(addr, old_len, new_addr, new_len);
84139@@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
84140 addr + new_len);
84141 }
84142 ret = addr;
84143+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
84144 goto out;
84145 }
84146 }
84147@@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
84148 goto out;
84149 }
84150
84151+ map_flags = vma->vm_flags;
84152 ret = move_vma(vma, addr, old_len, new_len, new_addr);
84153+ if (!(ret & ~PAGE_MASK)) {
84154+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
84155+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
84156+ }
84157 }
84158 out:
84159 if (ret & ~PAGE_MASK)
84160diff --git a/mm/nommu.c b/mm/nommu.c
84161index bbe1f3f..b2601ea 100644
84162--- a/mm/nommu.c
84163+++ b/mm/nommu.c
84164@@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
84165 int sysctl_overcommit_ratio = 50; /* default is 50% */
84166 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
84167 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
84168-int heap_stack_gap = 0;
84169
84170 atomic_long_t mmap_pages_allocated;
84171
84172@@ -839,15 +838,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
84173 EXPORT_SYMBOL(find_vma);
84174
84175 /*
84176- * find a VMA
84177- * - we don't extend stack VMAs under NOMMU conditions
84178- */
84179-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
84180-{
84181- return find_vma(mm, addr);
84182-}
84183-
84184-/*
84185 * expand a stack to a given address
84186 * - not supported under NOMMU conditions
84187 */
84188@@ -1555,6 +1545,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
84189
84190 /* most fields are the same, copy all, and then fixup */
84191 *new = *vma;
84192+ INIT_LIST_HEAD(&new->anon_vma_chain);
84193 *region = *vma->vm_region;
84194 new->vm_region = region;
84195
84196@@ -1975,8 +1966,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
84197 }
84198 EXPORT_SYMBOL(generic_file_remap_pages);
84199
84200-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
84201- unsigned long addr, void *buf, int len, int write)
84202+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
84203+ unsigned long addr, void *buf, size_t len, int write)
84204 {
84205 struct vm_area_struct *vma;
84206
84207@@ -2017,8 +2008,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
84208 *
84209 * The caller must hold a reference on @mm.
84210 */
84211-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
84212- void *buf, int len, int write)
84213+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
84214+ void *buf, size_t len, int write)
84215 {
84216 return __access_remote_vm(NULL, mm, addr, buf, len, write);
84217 }
84218@@ -2027,7 +2018,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
84219 * Access another process' address space.
84220 * - source/target buffer must be kernel space
84221 */
84222-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
84223+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
84224 {
84225 struct mm_struct *mm;
84226
84227diff --git a/mm/page-writeback.c b/mm/page-writeback.c
84228index 0713bfb..b95bb87 100644
84229--- a/mm/page-writeback.c
84230+++ b/mm/page-writeback.c
84231@@ -655,7 +655,7 @@ unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)
84232 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
84233 * - the bdi dirty thresh drops quickly due to change of JBOD workload
84234 */
84235-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
84236+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
84237 unsigned long thresh,
84238 unsigned long bg_thresh,
84239 unsigned long dirty,
84240@@ -1630,7 +1630,7 @@ ratelimit_handler(struct notifier_block *self, unsigned long action,
84241 }
84242 }
84243
84244-static struct notifier_block __cpuinitdata ratelimit_nb = {
84245+static struct notifier_block ratelimit_nb = {
84246 .notifier_call = ratelimit_handler,
84247 .next = NULL,
84248 };
84249diff --git a/mm/page_alloc.c b/mm/page_alloc.c
84250index 6a83cd3..3ab04ef 100644
84251--- a/mm/page_alloc.c
84252+++ b/mm/page_alloc.c
84253@@ -58,6 +58,7 @@
84254 #include <linux/prefetch.h>
84255 #include <linux/migrate.h>
84256 #include <linux/page-debug-flags.h>
84257+#include <linux/random.h>
84258
84259 #include <asm/tlbflush.h>
84260 #include <asm/div64.h>
84261@@ -338,7 +339,7 @@ out:
84262 * This usage means that zero-order pages may not be compound.
84263 */
84264
84265-static void free_compound_page(struct page *page)
84266+void free_compound_page(struct page *page)
84267 {
84268 __free_pages_ok(page, compound_order(page));
84269 }
84270@@ -693,6 +694,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
84271 int i;
84272 int bad = 0;
84273
84274+#ifdef CONFIG_PAX_MEMORY_SANITIZE
84275+ unsigned long index = 1UL << order;
84276+#endif
84277+
84278 trace_mm_page_free(page, order);
84279 kmemcheck_free_shadow(page, order);
84280
84281@@ -708,6 +713,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
84282 debug_check_no_obj_freed(page_address(page),
84283 PAGE_SIZE << order);
84284 }
84285+
84286+#ifdef CONFIG_PAX_MEMORY_SANITIZE
84287+ for (; index; --index)
84288+ sanitize_highpage(page + index - 1);
84289+#endif
84290+
84291 arch_free_page(page, order);
84292 kernel_map_pages(page, 1 << order, 0);
84293
84294@@ -730,6 +741,19 @@ static void __free_pages_ok(struct page *page, unsigned int order)
84295 local_irq_restore(flags);
84296 }
84297
84298+#ifdef CONFIG_PAX_LATENT_ENTROPY
84299+bool __meminitdata extra_latent_entropy;
84300+
84301+static int __init setup_pax_extra_latent_entropy(char *str)
84302+{
84303+ extra_latent_entropy = true;
84304+ return 0;
84305+}
84306+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
84307+
84308+volatile u64 latent_entropy;
84309+#endif
84310+
84311 /*
84312 * Read access to zone->managed_pages is safe because it's unsigned long,
84313 * but we still need to serialize writers. Currently all callers of
84314@@ -752,6 +776,19 @@ void __meminit __free_pages_bootmem(struct page *page, unsigned int order)
84315 set_page_count(p, 0);
84316 }
84317
84318+#ifdef CONFIG_PAX_LATENT_ENTROPY
84319+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
84320+ u64 hash = 0;
84321+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
84322+ const u64 *data = lowmem_page_address(page);
84323+
84324+ for (index = 0; index < end; index++)
84325+ hash ^= hash + data[index];
84326+ latent_entropy ^= hash;
84327+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
84328+ }
84329+#endif
84330+
84331 page_zone(page)->managed_pages += 1 << order;
84332 set_page_refcounted(page);
84333 __free_pages(page, order);
84334@@ -861,8 +898,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
84335 arch_alloc_page(page, order);
84336 kernel_map_pages(page, 1 << order, 1);
84337
84338+#ifndef CONFIG_PAX_MEMORY_SANITIZE
84339 if (gfp_flags & __GFP_ZERO)
84340 prep_zero_page(page, order, gfp_flags);
84341+#endif
84342
84343 if (order && (gfp_flags & __GFP_COMP))
84344 prep_compound_page(page, order);
84345@@ -3752,7 +3791,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
84346 unsigned long pfn;
84347
84348 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
84349+#ifdef CONFIG_X86_32
84350+ /* boot failures in VMware 8 on 32bit vanilla since
84351+ this change */
84352+ if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
84353+#else
84354 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
84355+#endif
84356 return 1;
84357 }
84358 return 0;
84359diff --git a/mm/percpu.c b/mm/percpu.c
84360index 8c8e08f..73a5cda 100644
84361--- a/mm/percpu.c
84362+++ b/mm/percpu.c
84363@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
84364 static unsigned int pcpu_high_unit_cpu __read_mostly;
84365
84366 /* the address of the first chunk which starts with the kernel static area */
84367-void *pcpu_base_addr __read_mostly;
84368+void *pcpu_base_addr __read_only;
84369 EXPORT_SYMBOL_GPL(pcpu_base_addr);
84370
84371 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
84372diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
84373index fd26d04..0cea1b0 100644
84374--- a/mm/process_vm_access.c
84375+++ b/mm/process_vm_access.c
84376@@ -13,6 +13,7 @@
84377 #include <linux/uio.h>
84378 #include <linux/sched.h>
84379 #include <linux/highmem.h>
84380+#include <linux/security.h>
84381 #include <linux/ptrace.h>
84382 #include <linux/slab.h>
84383 #include <linux/syscalls.h>
84384@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
84385 size_t iov_l_curr_offset = 0;
84386 ssize_t iov_len;
84387
84388+ return -ENOSYS; // PaX: until properly audited
84389+
84390 /*
84391 * Work out how many pages of struct pages we're going to need
84392 * when eventually calling get_user_pages
84393 */
84394 for (i = 0; i < riovcnt; i++) {
84395 iov_len = rvec[i].iov_len;
84396- if (iov_len > 0) {
84397- nr_pages_iov = ((unsigned long)rvec[i].iov_base
84398- + iov_len)
84399- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
84400- / PAGE_SIZE + 1;
84401- nr_pages = max(nr_pages, nr_pages_iov);
84402- }
84403+ if (iov_len <= 0)
84404+ continue;
84405+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
84406+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
84407+ nr_pages = max(nr_pages, nr_pages_iov);
84408 }
84409
84410 if (nr_pages == 0)
84411@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
84412 goto free_proc_pages;
84413 }
84414
84415+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
84416+ rc = -EPERM;
84417+ goto put_task_struct;
84418+ }
84419+
84420 mm = mm_access(task, PTRACE_MODE_ATTACH);
84421 if (!mm || IS_ERR(mm)) {
84422 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
84423diff --git a/mm/rmap.c b/mm/rmap.c
84424index 2c78f8c..9e9c624 100644
84425--- a/mm/rmap.c
84426+++ b/mm/rmap.c
84427@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
84428 struct anon_vma *anon_vma = vma->anon_vma;
84429 struct anon_vma_chain *avc;
84430
84431+#ifdef CONFIG_PAX_SEGMEXEC
84432+ struct anon_vma_chain *avc_m = NULL;
84433+#endif
84434+
84435 might_sleep();
84436 if (unlikely(!anon_vma)) {
84437 struct mm_struct *mm = vma->vm_mm;
84438@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
84439 if (!avc)
84440 goto out_enomem;
84441
84442+#ifdef CONFIG_PAX_SEGMEXEC
84443+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
84444+ if (!avc_m)
84445+ goto out_enomem_free_avc;
84446+#endif
84447+
84448 anon_vma = find_mergeable_anon_vma(vma);
84449 allocated = NULL;
84450 if (!anon_vma) {
84451@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
84452 /* page_table_lock to protect against threads */
84453 spin_lock(&mm->page_table_lock);
84454 if (likely(!vma->anon_vma)) {
84455+
84456+#ifdef CONFIG_PAX_SEGMEXEC
84457+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
84458+
84459+ if (vma_m) {
84460+ BUG_ON(vma_m->anon_vma);
84461+ vma_m->anon_vma = anon_vma;
84462+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
84463+ avc_m = NULL;
84464+ }
84465+#endif
84466+
84467 vma->anon_vma = anon_vma;
84468 anon_vma_chain_link(vma, avc, anon_vma);
84469 allocated = NULL;
84470@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
84471
84472 if (unlikely(allocated))
84473 put_anon_vma(allocated);
84474+
84475+#ifdef CONFIG_PAX_SEGMEXEC
84476+ if (unlikely(avc_m))
84477+ anon_vma_chain_free(avc_m);
84478+#endif
84479+
84480 if (unlikely(avc))
84481 anon_vma_chain_free(avc);
84482 }
84483 return 0;
84484
84485 out_enomem_free_avc:
84486+
84487+#ifdef CONFIG_PAX_SEGMEXEC
84488+ if (avc_m)
84489+ anon_vma_chain_free(avc_m);
84490+#endif
84491+
84492 anon_vma_chain_free(avc);
84493 out_enomem:
84494 return -ENOMEM;
84495@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
84496 * Attach the anon_vmas from src to dst.
84497 * Returns 0 on success, -ENOMEM on failure.
84498 */
84499-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
84500+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
84501 {
84502 struct anon_vma_chain *avc, *pavc;
84503 struct anon_vma *root = NULL;
84504@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
84505 * the corresponding VMA in the parent process is attached to.
84506 * Returns 0 on success, non-zero on failure.
84507 */
84508-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
84509+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
84510 {
84511 struct anon_vma_chain *avc;
84512 struct anon_vma *anon_vma;
84513diff --git a/mm/shmem.c b/mm/shmem.c
84514index efd0b3a..994b702 100644
84515--- a/mm/shmem.c
84516+++ b/mm/shmem.c
84517@@ -31,7 +31,7 @@
84518 #include <linux/export.h>
84519 #include <linux/swap.h>
84520
84521-static struct vfsmount *shm_mnt;
84522+struct vfsmount *shm_mnt;
84523
84524 #ifdef CONFIG_SHMEM
84525 /*
84526@@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
84527 #define BOGO_DIRENT_SIZE 20
84528
84529 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
84530-#define SHORT_SYMLINK_LEN 128
84531+#define SHORT_SYMLINK_LEN 64
84532
84533 /*
84534 * shmem_fallocate and shmem_writepage communicate via inode->i_private
84535@@ -2202,6 +2202,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
84536 static int shmem_xattr_validate(const char *name)
84537 {
84538 struct { const char *prefix; size_t len; } arr[] = {
84539+
84540+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
84541+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
84542+#endif
84543+
84544 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
84545 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
84546 };
84547@@ -2257,6 +2262,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
84548 if (err)
84549 return err;
84550
84551+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
84552+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
84553+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
84554+ return -EOPNOTSUPP;
84555+ if (size > 8)
84556+ return -EINVAL;
84557+ }
84558+#endif
84559+
84560 return simple_xattr_set(&info->xattrs, name, value, size, flags);
84561 }
84562
84563@@ -2562,8 +2576,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
84564 int err = -ENOMEM;
84565
84566 /* Round up to L1_CACHE_BYTES to resist false sharing */
84567- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
84568- L1_CACHE_BYTES), GFP_KERNEL);
84569+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
84570 if (!sbinfo)
84571 return -ENOMEM;
84572
84573diff --git a/mm/slab.c b/mm/slab.c
84574index e7667a3..a48e73b 100644
84575--- a/mm/slab.c
84576+++ b/mm/slab.c
84577@@ -306,7 +306,7 @@ struct kmem_list3 {
84578 * Need this for bootstrapping a per node allocator.
84579 */
84580 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
84581-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
84582+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
84583 #define CACHE_CACHE 0
84584 #define SIZE_AC MAX_NUMNODES
84585 #define SIZE_L3 (2 * MAX_NUMNODES)
84586@@ -407,10 +407,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
84587 if ((x)->max_freeable < i) \
84588 (x)->max_freeable = i; \
84589 } while (0)
84590-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
84591-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
84592-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
84593-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
84594+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
84595+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
84596+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
84597+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
84598 #else
84599 #define STATS_INC_ACTIVE(x) do { } while (0)
84600 #define STATS_DEC_ACTIVE(x) do { } while (0)
84601@@ -518,7 +518,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
84602 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
84603 */
84604 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
84605- const struct slab *slab, void *obj)
84606+ const struct slab *slab, const void *obj)
84607 {
84608 u32 offset = (obj - slab->s_mem);
84609 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
84610@@ -539,12 +539,13 @@ EXPORT_SYMBOL(malloc_sizes);
84611 struct cache_names {
84612 char *name;
84613 char *name_dma;
84614+ char *name_usercopy;
84615 };
84616
84617 static struct cache_names __initdata cache_names[] = {
84618-#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
84619+#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
84620 #include <linux/kmalloc_sizes.h>
84621- {NULL,}
84622+ {NULL}
84623 #undef CACHE
84624 };
84625
84626@@ -729,6 +730,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
84627 if (unlikely(gfpflags & GFP_DMA))
84628 return csizep->cs_dmacachep;
84629 #endif
84630+
84631+#ifdef CONFIG_PAX_USERCOPY_SLABS
84632+ if (unlikely(gfpflags & GFP_USERCOPY))
84633+ return csizep->cs_usercopycachep;
84634+#endif
84635+
84636 return csizep->cs_cachep;
84637 }
84638
84639@@ -1482,7 +1489,7 @@ static int __cpuinit cpuup_callback(struct notifier_block *nfb,
84640 return notifier_from_errno(err);
84641 }
84642
84643-static struct notifier_block __cpuinitdata cpucache_notifier = {
84644+static struct notifier_block cpucache_notifier = {
84645 &cpuup_callback, NULL, 0
84646 };
84647
84648@@ -1667,12 +1674,12 @@ void __init kmem_cache_init(void)
84649 */
84650
84651 sizes[INDEX_AC].cs_cachep = create_kmalloc_cache(names[INDEX_AC].name,
84652- sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS);
84653+ sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
84654
84655 if (INDEX_AC != INDEX_L3)
84656 sizes[INDEX_L3].cs_cachep =
84657 create_kmalloc_cache(names[INDEX_L3].name,
84658- sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS);
84659+ sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
84660
84661 slab_early_init = 0;
84662
84663@@ -1686,13 +1693,20 @@ void __init kmem_cache_init(void)
84664 */
84665 if (!sizes->cs_cachep)
84666 sizes->cs_cachep = create_kmalloc_cache(names->name,
84667- sizes->cs_size, ARCH_KMALLOC_FLAGS);
84668+ sizes->cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
84669
84670 #ifdef CONFIG_ZONE_DMA
84671 sizes->cs_dmacachep = create_kmalloc_cache(
84672 names->name_dma, sizes->cs_size,
84673 SLAB_CACHE_DMA|ARCH_KMALLOC_FLAGS);
84674 #endif
84675+
84676+#ifdef CONFIG_PAX_USERCOPY_SLABS
84677+ sizes->cs_usercopycachep = create_kmalloc_cache(
84678+ names->name_usercopy, sizes->cs_size,
84679+ ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
84680+#endif
84681+
84682 sizes++;
84683 names++;
84684 }
84685@@ -3924,6 +3938,7 @@ void kfree(const void *objp)
84686
84687 if (unlikely(ZERO_OR_NULL_PTR(objp)))
84688 return;
84689+ VM_BUG_ON(!virt_addr_valid(objp));
84690 local_irq_save(flags);
84691 kfree_debugcheck(objp);
84692 c = virt_to_cache(objp);
84693@@ -4365,10 +4380,10 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
84694 }
84695 /* cpu stats */
84696 {
84697- unsigned long allochit = atomic_read(&cachep->allochit);
84698- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
84699- unsigned long freehit = atomic_read(&cachep->freehit);
84700- unsigned long freemiss = atomic_read(&cachep->freemiss);
84701+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
84702+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
84703+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
84704+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
84705
84706 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
84707 allochit, allocmiss, freehit, freemiss);
84708@@ -4600,13 +4615,71 @@ static const struct file_operations proc_slabstats_operations = {
84709 static int __init slab_proc_init(void)
84710 {
84711 #ifdef CONFIG_DEBUG_SLAB_LEAK
84712- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
84713+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
84714 #endif
84715 return 0;
84716 }
84717 module_init(slab_proc_init);
84718 #endif
84719
84720+bool is_usercopy_object(const void *ptr)
84721+{
84722+ struct page *page;
84723+ struct kmem_cache *cachep;
84724+
84725+ if (ZERO_OR_NULL_PTR(ptr))
84726+ return false;
84727+
84728+ if (!slab_is_available())
84729+ return false;
84730+
84731+ if (!virt_addr_valid(ptr))
84732+ return false;
84733+
84734+ page = virt_to_head_page(ptr);
84735+
84736+ if (!PageSlab(page))
84737+ return false;
84738+
84739+ cachep = page->slab_cache;
84740+ return cachep->flags & SLAB_USERCOPY;
84741+}
84742+
84743+#ifdef CONFIG_PAX_USERCOPY
84744+const char *check_heap_object(const void *ptr, unsigned long n)
84745+{
84746+ struct page *page;
84747+ struct kmem_cache *cachep;
84748+ struct slab *slabp;
84749+ unsigned int objnr;
84750+ unsigned long offset;
84751+
84752+ if (ZERO_OR_NULL_PTR(ptr))
84753+ return "<null>";
84754+
84755+ if (!virt_addr_valid(ptr))
84756+ return NULL;
84757+
84758+ page = virt_to_head_page(ptr);
84759+
84760+ if (!PageSlab(page))
84761+ return NULL;
84762+
84763+ cachep = page->slab_cache;
84764+ if (!(cachep->flags & SLAB_USERCOPY))
84765+ return cachep->name;
84766+
84767+ slabp = page->slab_page;
84768+ objnr = obj_to_index(cachep, slabp, ptr);
84769+ BUG_ON(objnr >= cachep->num);
84770+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
84771+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
84772+ return NULL;
84773+
84774+ return cachep->name;
84775+}
84776+#endif
84777+
84778 /**
84779 * ksize - get the actual amount of memory allocated for a given object
84780 * @objp: Pointer to the object
84781diff --git a/mm/slab.h b/mm/slab.h
84782index 34a98d6..73633d1 100644
84783--- a/mm/slab.h
84784+++ b/mm/slab.h
84785@@ -58,7 +58,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
84786
84787 /* Legal flag mask for kmem_cache_create(), for various configurations */
84788 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
84789- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
84790+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | SLAB_USERCOPY)
84791
84792 #if defined(CONFIG_DEBUG_SLAB)
84793 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
84794@@ -220,6 +220,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
84795 return s;
84796
84797 page = virt_to_head_page(x);
84798+
84799+ BUG_ON(!PageSlab(page));
84800+
84801 cachep = page->slab_cache;
84802 if (slab_equal_or_root(cachep, s))
84803 return cachep;
84804diff --git a/mm/slab_common.c b/mm/slab_common.c
84805index 3f3cd97..93b0236 100644
84806--- a/mm/slab_common.c
84807+++ b/mm/slab_common.c
84808@@ -22,7 +22,7 @@
84809
84810 #include "slab.h"
84811
84812-enum slab_state slab_state;
84813+enum slab_state slab_state __read_only;
84814 LIST_HEAD(slab_caches);
84815 DEFINE_MUTEX(slab_mutex);
84816 struct kmem_cache *kmem_cache;
84817@@ -209,7 +209,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
84818
84819 err = __kmem_cache_create(s, flags);
84820 if (!err) {
84821- s->refcount = 1;
84822+ atomic_set(&s->refcount, 1);
84823 list_add(&s->list, &slab_caches);
84824 memcg_cache_list_add(memcg, s);
84825 } else {
84826@@ -255,8 +255,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
84827
84828 get_online_cpus();
84829 mutex_lock(&slab_mutex);
84830- s->refcount--;
84831- if (!s->refcount) {
84832+ if (atomic_dec_and_test(&s->refcount)) {
84833 list_del(&s->list);
84834
84835 if (!__kmem_cache_shutdown(s)) {
84836@@ -302,7 +301,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
84837 panic("Creation of kmalloc slab %s size=%zd failed. Reason %d\n",
84838 name, size, err);
84839
84840- s->refcount = -1; /* Exempt from merging for now */
84841+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
84842 }
84843
84844 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
84845@@ -315,7 +314,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
84846
84847 create_boot_cache(s, name, size, flags);
84848 list_add(&s->list, &slab_caches);
84849- s->refcount = 1;
84850+ atomic_set(&s->refcount, 1);
84851 return s;
84852 }
84853
84854diff --git a/mm/slob.c b/mm/slob.c
84855index a99fdf7..6ee34ec 100644
84856--- a/mm/slob.c
84857+++ b/mm/slob.c
84858@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
84859 /*
84860 * Return the size of a slob block.
84861 */
84862-static slobidx_t slob_units(slob_t *s)
84863+static slobidx_t slob_units(const slob_t *s)
84864 {
84865 if (s->units > 0)
84866 return s->units;
84867@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
84868 /*
84869 * Return the next free slob block pointer after this one.
84870 */
84871-static slob_t *slob_next(slob_t *s)
84872+static slob_t *slob_next(const slob_t *s)
84873 {
84874 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
84875 slobidx_t next;
84876@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
84877 /*
84878 * Returns true if s is the last free block in its page.
84879 */
84880-static int slob_last(slob_t *s)
84881+static int slob_last(const slob_t *s)
84882 {
84883 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
84884 }
84885
84886-static void *slob_new_pages(gfp_t gfp, int order, int node)
84887+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
84888 {
84889- void *page;
84890+ struct page *page;
84891
84892 #ifdef CONFIG_NUMA
84893 if (node != NUMA_NO_NODE)
84894@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
84895 if (!page)
84896 return NULL;
84897
84898- return page_address(page);
84899+ __SetPageSlab(page);
84900+ return page;
84901 }
84902
84903-static void slob_free_pages(void *b, int order)
84904+static void slob_free_pages(struct page *sp, int order)
84905 {
84906 if (current->reclaim_state)
84907 current->reclaim_state->reclaimed_slab += 1 << order;
84908- free_pages((unsigned long)b, order);
84909+ __ClearPageSlab(sp);
84910+ reset_page_mapcount(sp);
84911+ sp->private = 0;
84912+ __free_pages(sp, order);
84913 }
84914
84915 /*
84916@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
84917
84918 /* Not enough space: must allocate a new page */
84919 if (!b) {
84920- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
84921- if (!b)
84922+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
84923+ if (!sp)
84924 return NULL;
84925- sp = virt_to_page(b);
84926- __SetPageSlab(sp);
84927+ b = page_address(sp);
84928
84929 spin_lock_irqsave(&slob_lock, flags);
84930 sp->units = SLOB_UNITS(PAGE_SIZE);
84931 sp->freelist = b;
84932+ sp->private = 0;
84933 INIT_LIST_HEAD(&sp->list);
84934 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
84935 set_slob_page_free(sp, slob_list);
84936@@ -359,9 +363,7 @@ static void slob_free(void *block, int size)
84937 if (slob_page_free(sp))
84938 clear_slob_page_free(sp);
84939 spin_unlock_irqrestore(&slob_lock, flags);
84940- __ClearPageSlab(sp);
84941- reset_page_mapcount(sp);
84942- slob_free_pages(b, 0);
84943+ slob_free_pages(sp, 0);
84944 return;
84945 }
84946
84947@@ -424,11 +426,10 @@ out:
84948 */
84949
84950 static __always_inline void *
84951-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
84952+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
84953 {
84954- unsigned int *m;
84955- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
84956- void *ret;
84957+ slob_t *m;
84958+ void *ret = NULL;
84959
84960 gfp &= gfp_allowed_mask;
84961
84962@@ -442,23 +443,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
84963
84964 if (!m)
84965 return NULL;
84966- *m = size;
84967+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
84968+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
84969+ m[0].units = size;
84970+ m[1].units = align;
84971 ret = (void *)m + align;
84972
84973 trace_kmalloc_node(caller, ret,
84974 size, size + align, gfp, node);
84975 } else {
84976 unsigned int order = get_order(size);
84977+ struct page *page;
84978
84979 if (likely(order))
84980 gfp |= __GFP_COMP;
84981- ret = slob_new_pages(gfp, order, node);
84982+ page = slob_new_pages(gfp, order, node);
84983+ if (page) {
84984+ ret = page_address(page);
84985+ page->private = size;
84986+ }
84987
84988 trace_kmalloc_node(caller, ret,
84989 size, PAGE_SIZE << order, gfp, node);
84990 }
84991
84992- kmemleak_alloc(ret, size, 1, gfp);
84993+ return ret;
84994+}
84995+
84996+static __always_inline void *
84997+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
84998+{
84999+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
85000+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
85001+
85002+ if (!ZERO_OR_NULL_PTR(ret))
85003+ kmemleak_alloc(ret, size, 1, gfp);
85004 return ret;
85005 }
85006
85007@@ -493,34 +512,112 @@ void kfree(const void *block)
85008 return;
85009 kmemleak_free(block);
85010
85011+ VM_BUG_ON(!virt_addr_valid(block));
85012 sp = virt_to_page(block);
85013- if (PageSlab(sp)) {
85014+ VM_BUG_ON(!PageSlab(sp));
85015+ if (!sp->private) {
85016 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
85017- unsigned int *m = (unsigned int *)(block - align);
85018- slob_free(m, *m + align);
85019- } else
85020+ slob_t *m = (slob_t *)(block - align);
85021+ slob_free(m, m[0].units + align);
85022+ } else {
85023+ __ClearPageSlab(sp);
85024+ reset_page_mapcount(sp);
85025+ sp->private = 0;
85026 __free_pages(sp, compound_order(sp));
85027+ }
85028 }
85029 EXPORT_SYMBOL(kfree);
85030
85031+bool is_usercopy_object(const void *ptr)
85032+{
85033+ if (!slab_is_available())
85034+ return false;
85035+
85036+ // PAX: TODO
85037+
85038+ return false;
85039+}
85040+
85041+#ifdef CONFIG_PAX_USERCOPY
85042+const char *check_heap_object(const void *ptr, unsigned long n)
85043+{
85044+ struct page *page;
85045+ const slob_t *free;
85046+ const void *base;
85047+ unsigned long flags;
85048+
85049+ if (ZERO_OR_NULL_PTR(ptr))
85050+ return "<null>";
85051+
85052+ if (!virt_addr_valid(ptr))
85053+ return NULL;
85054+
85055+ page = virt_to_head_page(ptr);
85056+ if (!PageSlab(page))
85057+ return NULL;
85058+
85059+ if (page->private) {
85060+ base = page;
85061+ if (base <= ptr && n <= page->private - (ptr - base))
85062+ return NULL;
85063+ return "<slob>";
85064+ }
85065+
85066+ /* some tricky double walking to find the chunk */
85067+ spin_lock_irqsave(&slob_lock, flags);
85068+ base = (void *)((unsigned long)ptr & PAGE_MASK);
85069+ free = page->freelist;
85070+
85071+ while (!slob_last(free) && (void *)free <= ptr) {
85072+ base = free + slob_units(free);
85073+ free = slob_next(free);
85074+ }
85075+
85076+ while (base < (void *)free) {
85077+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
85078+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
85079+ int offset;
85080+
85081+ if (ptr < base + align)
85082+ break;
85083+
85084+ offset = ptr - base - align;
85085+ if (offset >= m) {
85086+ base += size;
85087+ continue;
85088+ }
85089+
85090+ if (n > m - offset)
85091+ break;
85092+
85093+ spin_unlock_irqrestore(&slob_lock, flags);
85094+ return NULL;
85095+ }
85096+
85097+ spin_unlock_irqrestore(&slob_lock, flags);
85098+ return "<slob>";
85099+}
85100+#endif
85101+
85102 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
85103 size_t ksize(const void *block)
85104 {
85105 struct page *sp;
85106 int align;
85107- unsigned int *m;
85108+ slob_t *m;
85109
85110 BUG_ON(!block);
85111 if (unlikely(block == ZERO_SIZE_PTR))
85112 return 0;
85113
85114 sp = virt_to_page(block);
85115- if (unlikely(!PageSlab(sp)))
85116- return PAGE_SIZE << compound_order(sp);
85117+ VM_BUG_ON(!PageSlab(sp));
85118+ if (sp->private)
85119+ return sp->private;
85120
85121 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
85122- m = (unsigned int *)(block - align);
85123- return SLOB_UNITS(*m) * SLOB_UNIT;
85124+ m = (slob_t *)(block - align);
85125+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
85126 }
85127 EXPORT_SYMBOL(ksize);
85128
85129@@ -536,23 +633,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
85130
85131 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
85132 {
85133- void *b;
85134+ void *b = NULL;
85135
85136 flags &= gfp_allowed_mask;
85137
85138 lockdep_trace_alloc(flags);
85139
85140+#ifdef CONFIG_PAX_USERCOPY_SLABS
85141+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
85142+#else
85143 if (c->size < PAGE_SIZE) {
85144 b = slob_alloc(c->size, flags, c->align, node);
85145 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
85146 SLOB_UNITS(c->size) * SLOB_UNIT,
85147 flags, node);
85148 } else {
85149- b = slob_new_pages(flags, get_order(c->size), node);
85150+ struct page *sp;
85151+
85152+ sp = slob_new_pages(flags, get_order(c->size), node);
85153+ if (sp) {
85154+ b = page_address(sp);
85155+ sp->private = c->size;
85156+ }
85157 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
85158 PAGE_SIZE << get_order(c->size),
85159 flags, node);
85160 }
85161+#endif
85162
85163 if (c->ctor)
85164 c->ctor(b);
85165@@ -564,10 +671,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
85166
85167 static void __kmem_cache_free(void *b, int size)
85168 {
85169- if (size < PAGE_SIZE)
85170+ struct page *sp;
85171+
85172+ sp = virt_to_page(b);
85173+ BUG_ON(!PageSlab(sp));
85174+ if (!sp->private)
85175 slob_free(b, size);
85176 else
85177- slob_free_pages(b, get_order(size));
85178+ slob_free_pages(sp, get_order(size));
85179 }
85180
85181 static void kmem_rcu_free(struct rcu_head *head)
85182@@ -580,17 +691,31 @@ static void kmem_rcu_free(struct rcu_head *head)
85183
85184 void kmem_cache_free(struct kmem_cache *c, void *b)
85185 {
85186+ int size = c->size;
85187+
85188+#ifdef CONFIG_PAX_USERCOPY_SLABS
85189+ if (size + c->align < PAGE_SIZE) {
85190+ size += c->align;
85191+ b -= c->align;
85192+ }
85193+#endif
85194+
85195 kmemleak_free_recursive(b, c->flags);
85196 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
85197 struct slob_rcu *slob_rcu;
85198- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
85199- slob_rcu->size = c->size;
85200+ slob_rcu = b + (size - sizeof(struct slob_rcu));
85201+ slob_rcu->size = size;
85202 call_rcu(&slob_rcu->head, kmem_rcu_free);
85203 } else {
85204- __kmem_cache_free(b, c->size);
85205+ __kmem_cache_free(b, size);
85206 }
85207
85208+#ifdef CONFIG_PAX_USERCOPY_SLABS
85209+ trace_kfree(_RET_IP_, b);
85210+#else
85211 trace_kmem_cache_free(_RET_IP_, b);
85212+#endif
85213+
85214 }
85215 EXPORT_SYMBOL(kmem_cache_free);
85216
85217diff --git a/mm/slub.c b/mm/slub.c
85218index ba2ca53..991c4f7 100644
85219--- a/mm/slub.c
85220+++ b/mm/slub.c
85221@@ -197,7 +197,7 @@ struct track {
85222
85223 enum track_item { TRACK_ALLOC, TRACK_FREE };
85224
85225-#ifdef CONFIG_SYSFS
85226+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
85227 static int sysfs_slab_add(struct kmem_cache *);
85228 static int sysfs_slab_alias(struct kmem_cache *, const char *);
85229 static void sysfs_slab_remove(struct kmem_cache *);
85230@@ -518,7 +518,7 @@ static void print_track(const char *s, struct track *t)
85231 if (!t->addr)
85232 return;
85233
85234- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
85235+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
85236 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
85237 #ifdef CONFIG_STACKTRACE
85238 {
85239@@ -2653,7 +2653,7 @@ static int slub_min_objects;
85240 * Merge control. If this is set then no merging of slab caches will occur.
85241 * (Could be removed. This was introduced to pacify the merge skeptics.)
85242 */
85243-static int slub_nomerge;
85244+static int slub_nomerge = 1;
85245
85246 /*
85247 * Calculate the order of allocation given an slab object size.
85248@@ -3181,6 +3181,10 @@ EXPORT_SYMBOL(kmalloc_caches);
85249 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
85250 #endif
85251
85252+#ifdef CONFIG_PAX_USERCOPY_SLABS
85253+static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
85254+#endif
85255+
85256 static int __init setup_slub_min_order(char *str)
85257 {
85258 get_option(&str, &slub_min_order);
85259@@ -3272,6 +3276,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
85260 return kmalloc_dma_caches[index];
85261
85262 #endif
85263+
85264+#ifdef CONFIG_PAX_USERCOPY_SLABS
85265+ if (flags & SLAB_USERCOPY)
85266+ return kmalloc_usercopy_caches[index];
85267+
85268+#endif
85269+
85270 return kmalloc_caches[index];
85271 }
85272
85273@@ -3340,6 +3351,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
85274 EXPORT_SYMBOL(__kmalloc_node);
85275 #endif
85276
85277+bool is_usercopy_object(const void *ptr)
85278+{
85279+ struct page *page;
85280+ struct kmem_cache *s;
85281+
85282+ if (ZERO_OR_NULL_PTR(ptr))
85283+ return false;
85284+
85285+ if (!slab_is_available())
85286+ return false;
85287+
85288+ if (!virt_addr_valid(ptr))
85289+ return false;
85290+
85291+ page = virt_to_head_page(ptr);
85292+
85293+ if (!PageSlab(page))
85294+ return false;
85295+
85296+ s = page->slab_cache;
85297+ return s->flags & SLAB_USERCOPY;
85298+}
85299+
85300+#ifdef CONFIG_PAX_USERCOPY
85301+const char *check_heap_object(const void *ptr, unsigned long n)
85302+{
85303+ struct page *page;
85304+ struct kmem_cache *s;
85305+ unsigned long offset;
85306+
85307+ if (ZERO_OR_NULL_PTR(ptr))
85308+ return "<null>";
85309+
85310+ if (!virt_addr_valid(ptr))
85311+ return NULL;
85312+
85313+ page = virt_to_head_page(ptr);
85314+
85315+ if (!PageSlab(page))
85316+ return NULL;
85317+
85318+ s = page->slab_cache;
85319+ if (!(s->flags & SLAB_USERCOPY))
85320+ return s->name;
85321+
85322+ offset = (ptr - page_address(page)) % s->size;
85323+ if (offset <= s->object_size && n <= s->object_size - offset)
85324+ return NULL;
85325+
85326+ return s->name;
85327+}
85328+#endif
85329+
85330 size_t ksize(const void *object)
85331 {
85332 struct page *page;
85333@@ -3404,6 +3468,7 @@ void kfree(const void *x)
85334 if (unlikely(ZERO_OR_NULL_PTR(x)))
85335 return;
85336
85337+ VM_BUG_ON(!virt_addr_valid(x));
85338 page = virt_to_head_page(x);
85339 if (unlikely(!PageSlab(page))) {
85340 BUG_ON(!PageCompound(page));
85341@@ -3712,17 +3777,17 @@ void __init kmem_cache_init(void)
85342
85343 /* Caches that are not of the two-to-the-power-of size */
85344 if (KMALLOC_MIN_SIZE <= 32) {
85345- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
85346+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
85347 caches++;
85348 }
85349
85350 if (KMALLOC_MIN_SIZE <= 64) {
85351- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
85352+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
85353 caches++;
85354 }
85355
85356 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
85357- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
85358+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
85359 caches++;
85360 }
85361
85362@@ -3764,6 +3829,22 @@ void __init kmem_cache_init(void)
85363 }
85364 }
85365 #endif
85366+
85367+#ifdef CONFIG_PAX_USERCOPY_SLABS
85368+ for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
85369+ struct kmem_cache *s = kmalloc_caches[i];
85370+
85371+ if (s && s->size) {
85372+ char *name = kasprintf(GFP_NOWAIT,
85373+ "usercopy-kmalloc-%d", s->object_size);
85374+
85375+ BUG_ON(!name);
85376+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
85377+ s->object_size, SLAB_USERCOPY);
85378+ }
85379+ }
85380+#endif
85381+
85382 printk(KERN_INFO
85383 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
85384 " CPUs=%d, Nodes=%d\n",
85385@@ -3790,7 +3871,7 @@ static int slab_unmergeable(struct kmem_cache *s)
85386 /*
85387 * We may have set a slab to be unmergeable during bootstrap.
85388 */
85389- if (s->refcount < 0)
85390+ if (atomic_read(&s->refcount) < 0)
85391 return 1;
85392
85393 return 0;
85394@@ -3848,7 +3929,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
85395
85396 s = find_mergeable(memcg, size, align, flags, name, ctor);
85397 if (s) {
85398- s->refcount++;
85399+ atomic_inc(&s->refcount);
85400 /*
85401 * Adjust the object sizes so that we clear
85402 * the complete object on kzalloc.
85403@@ -3857,7 +3938,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
85404 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
85405
85406 if (sysfs_slab_alias(s, name)) {
85407- s->refcount--;
85408+ atomic_dec(&s->refcount);
85409 s = NULL;
85410 }
85411 }
85412@@ -3919,7 +4000,7 @@ static int __cpuinit slab_cpuup_callback(struct notifier_block *nfb,
85413 return NOTIFY_OK;
85414 }
85415
85416-static struct notifier_block __cpuinitdata slab_notifier = {
85417+static struct notifier_block slab_notifier = {
85418 .notifier_call = slab_cpuup_callback
85419 };
85420
85421@@ -3977,7 +4058,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
85422 }
85423 #endif
85424
85425-#ifdef CONFIG_SYSFS
85426+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
85427 static int count_inuse(struct page *page)
85428 {
85429 return page->inuse;
85430@@ -4364,12 +4445,12 @@ static void resiliency_test(void)
85431 validate_slab_cache(kmalloc_caches[9]);
85432 }
85433 #else
85434-#ifdef CONFIG_SYSFS
85435+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
85436 static void resiliency_test(void) {};
85437 #endif
85438 #endif
85439
85440-#ifdef CONFIG_SYSFS
85441+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
85442 enum slab_stat_type {
85443 SL_ALL, /* All slabs */
85444 SL_PARTIAL, /* Only partially allocated slabs */
85445@@ -4613,7 +4694,7 @@ SLAB_ATTR_RO(ctor);
85446
85447 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
85448 {
85449- return sprintf(buf, "%d\n", s->refcount - 1);
85450+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
85451 }
85452 SLAB_ATTR_RO(aliases);
85453
85454@@ -5266,6 +5347,7 @@ static char *create_unique_id(struct kmem_cache *s)
85455 return name;
85456 }
85457
85458+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
85459 static int sysfs_slab_add(struct kmem_cache *s)
85460 {
85461 int err;
85462@@ -5323,6 +5405,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
85463 kobject_del(&s->kobj);
85464 kobject_put(&s->kobj);
85465 }
85466+#endif
85467
85468 /*
85469 * Need to buffer aliases during bootup until sysfs becomes
85470@@ -5336,6 +5419,7 @@ struct saved_alias {
85471
85472 static struct saved_alias *alias_list;
85473
85474+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
85475 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
85476 {
85477 struct saved_alias *al;
85478@@ -5358,6 +5442,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
85479 alias_list = al;
85480 return 0;
85481 }
85482+#endif
85483
85484 static int __init slab_sysfs_init(void)
85485 {
85486diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
85487index 1b7e22a..3fcd4f3 100644
85488--- a/mm/sparse-vmemmap.c
85489+++ b/mm/sparse-vmemmap.c
85490@@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
85491 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
85492 if (!p)
85493 return NULL;
85494- pud_populate(&init_mm, pud, p);
85495+ pud_populate_kernel(&init_mm, pud, p);
85496 }
85497 return pud;
85498 }
85499@@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
85500 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
85501 if (!p)
85502 return NULL;
85503- pgd_populate(&init_mm, pgd, p);
85504+ pgd_populate_kernel(&init_mm, pgd, p);
85505 }
85506 return pgd;
85507 }
85508diff --git a/mm/sparse.c b/mm/sparse.c
85509index 6b5fb76..db0c190 100644
85510--- a/mm/sparse.c
85511+++ b/mm/sparse.c
85512@@ -782,7 +782,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
85513
85514 for (i = 0; i < PAGES_PER_SECTION; i++) {
85515 if (PageHWPoison(&memmap[i])) {
85516- atomic_long_sub(1, &mce_bad_pages);
85517+ atomic_long_sub_unchecked(1, &mce_bad_pages);
85518 ClearPageHWPoison(&memmap[i]);
85519 }
85520 }
85521diff --git a/mm/swap.c b/mm/swap.c
85522index 6310dc2..3662b3f 100644
85523--- a/mm/swap.c
85524+++ b/mm/swap.c
85525@@ -30,6 +30,7 @@
85526 #include <linux/backing-dev.h>
85527 #include <linux/memcontrol.h>
85528 #include <linux/gfp.h>
85529+#include <linux/hugetlb.h>
85530
85531 #include "internal.h"
85532
85533@@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
85534
85535 __page_cache_release(page);
85536 dtor = get_compound_page_dtor(page);
85537+ if (!PageHuge(page))
85538+ BUG_ON(dtor != free_compound_page);
85539 (*dtor)(page);
85540 }
85541
85542diff --git a/mm/swapfile.c b/mm/swapfile.c
85543index e97a0e5..b50e796 100644
85544--- a/mm/swapfile.c
85545+++ b/mm/swapfile.c
85546@@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
85547
85548 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
85549 /* Activity counter to indicate that a swapon or swapoff has occurred */
85550-static atomic_t proc_poll_event = ATOMIC_INIT(0);
85551+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
85552
85553 static inline unsigned char swap_count(unsigned char ent)
85554 {
85555@@ -1608,7 +1608,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
85556 }
85557 filp_close(swap_file, NULL);
85558 err = 0;
85559- atomic_inc(&proc_poll_event);
85560+ atomic_inc_unchecked(&proc_poll_event);
85561 wake_up_interruptible(&proc_poll_wait);
85562
85563 out_dput:
85564@@ -1625,8 +1625,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
85565
85566 poll_wait(file, &proc_poll_wait, wait);
85567
85568- if (seq->poll_event != atomic_read(&proc_poll_event)) {
85569- seq->poll_event = atomic_read(&proc_poll_event);
85570+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
85571+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
85572 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
85573 }
85574
85575@@ -1724,7 +1724,7 @@ static int swaps_open(struct inode *inode, struct file *file)
85576 return ret;
85577
85578 seq = file->private_data;
85579- seq->poll_event = atomic_read(&proc_poll_event);
85580+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
85581 return 0;
85582 }
85583
85584@@ -2066,7 +2066,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
85585 (frontswap_map) ? "FS" : "");
85586
85587 mutex_unlock(&swapon_mutex);
85588- atomic_inc(&proc_poll_event);
85589+ atomic_inc_unchecked(&proc_poll_event);
85590 wake_up_interruptible(&proc_poll_wait);
85591
85592 if (S_ISREG(inode->i_mode))
85593diff --git a/mm/util.c b/mm/util.c
85594index c55e26b..3f913a9 100644
85595--- a/mm/util.c
85596+++ b/mm/util.c
85597@@ -292,6 +292,12 @@ done:
85598 void arch_pick_mmap_layout(struct mm_struct *mm)
85599 {
85600 mm->mmap_base = TASK_UNMAPPED_BASE;
85601+
85602+#ifdef CONFIG_PAX_RANDMMAP
85603+ if (mm->pax_flags & MF_PAX_RANDMMAP)
85604+ mm->mmap_base += mm->delta_mmap;
85605+#endif
85606+
85607 mm->get_unmapped_area = arch_get_unmapped_area;
85608 mm->unmap_area = arch_unmap_area;
85609 }
85610diff --git a/mm/vmalloc.c b/mm/vmalloc.c
85611index 5123a16..f234a48 100644
85612--- a/mm/vmalloc.c
85613+++ b/mm/vmalloc.c
85614@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
85615
85616 pte = pte_offset_kernel(pmd, addr);
85617 do {
85618- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
85619- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
85620+
85621+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85622+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
85623+ BUG_ON(!pte_exec(*pte));
85624+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
85625+ continue;
85626+ }
85627+#endif
85628+
85629+ {
85630+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
85631+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
85632+ }
85633 } while (pte++, addr += PAGE_SIZE, addr != end);
85634 }
85635
85636@@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
85637 pte = pte_alloc_kernel(pmd, addr);
85638 if (!pte)
85639 return -ENOMEM;
85640+
85641+ pax_open_kernel();
85642 do {
85643 struct page *page = pages[*nr];
85644
85645- if (WARN_ON(!pte_none(*pte)))
85646+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85647+ if (pgprot_val(prot) & _PAGE_NX)
85648+#endif
85649+
85650+ if (!pte_none(*pte)) {
85651+ pax_close_kernel();
85652+ WARN_ON(1);
85653 return -EBUSY;
85654- if (WARN_ON(!page))
85655+ }
85656+ if (!page) {
85657+ pax_close_kernel();
85658+ WARN_ON(1);
85659 return -ENOMEM;
85660+ }
85661 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
85662 (*nr)++;
85663 } while (pte++, addr += PAGE_SIZE, addr != end);
85664+ pax_close_kernel();
85665 return 0;
85666 }
85667
85668@@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
85669 pmd_t *pmd;
85670 unsigned long next;
85671
85672- pmd = pmd_alloc(&init_mm, pud, addr);
85673+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
85674 if (!pmd)
85675 return -ENOMEM;
85676 do {
85677@@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
85678 pud_t *pud;
85679 unsigned long next;
85680
85681- pud = pud_alloc(&init_mm, pgd, addr);
85682+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
85683 if (!pud)
85684 return -ENOMEM;
85685 do {
85686@@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
85687 * and fall back on vmalloc() if that fails. Others
85688 * just put it in the vmalloc space.
85689 */
85690-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
85691+#ifdef CONFIG_MODULES
85692+#ifdef MODULES_VADDR
85693 unsigned long addr = (unsigned long)x;
85694 if (addr >= MODULES_VADDR && addr < MODULES_END)
85695 return 1;
85696 #endif
85697+
85698+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85699+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
85700+ return 1;
85701+#endif
85702+
85703+#endif
85704+
85705 return is_vmalloc_addr(x);
85706 }
85707
85708@@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
85709
85710 if (!pgd_none(*pgd)) {
85711 pud_t *pud = pud_offset(pgd, addr);
85712+#ifdef CONFIG_X86
85713+ if (!pud_large(*pud))
85714+#endif
85715 if (!pud_none(*pud)) {
85716 pmd_t *pmd = pmd_offset(pud, addr);
85717+#ifdef CONFIG_X86
85718+ if (!pmd_large(*pmd))
85719+#endif
85720 if (!pmd_none(*pmd)) {
85721 pte_t *ptep, pte;
85722
85723@@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
85724 * Allocate a region of KVA of the specified size and alignment, within the
85725 * vstart and vend.
85726 */
85727-static struct vmap_area *alloc_vmap_area(unsigned long size,
85728+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
85729 unsigned long align,
85730 unsigned long vstart, unsigned long vend,
85731 int node, gfp_t gfp_mask)
85732@@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
85733 struct vm_struct *area;
85734
85735 BUG_ON(in_interrupt());
85736+
85737+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
85738+ if (flags & VM_KERNEXEC) {
85739+ if (start != VMALLOC_START || end != VMALLOC_END)
85740+ return NULL;
85741+ start = (unsigned long)MODULES_EXEC_VADDR;
85742+ end = (unsigned long)MODULES_EXEC_END;
85743+ }
85744+#endif
85745+
85746 if (flags & VM_IOREMAP) {
85747 int bit = fls(size);
85748
85749@@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
85750 if (count > totalram_pages)
85751 return NULL;
85752
85753+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
85754+ if (!(pgprot_val(prot) & _PAGE_NX))
85755+ flags |= VM_KERNEXEC;
85756+#endif
85757+
85758 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
85759 __builtin_return_address(0));
85760 if (!area)
85761@@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
85762 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
85763 goto fail;
85764
85765+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
85766+ if (!(pgprot_val(prot) & _PAGE_NX))
85767+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
85768+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
85769+ else
85770+#endif
85771+
85772 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
85773 start, end, node, gfp_mask, caller);
85774 if (!area)
85775@@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
85776 * For tight control over page level allocator and protection flags
85777 * use __vmalloc() instead.
85778 */
85779-
85780 void *vmalloc_exec(unsigned long size)
85781 {
85782- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
85783+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
85784 -1, __builtin_return_address(0));
85785 }
85786
85787@@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
85788 unsigned long uaddr = vma->vm_start;
85789 unsigned long usize = vma->vm_end - vma->vm_start;
85790
85791+ BUG_ON(vma->vm_mirror);
85792+
85793 if ((PAGE_SIZE-1) & (unsigned long)addr)
85794 return -EINVAL;
85795
85796@@ -2575,7 +2637,11 @@ static int s_show(struct seq_file *m, void *p)
85797 v->addr, v->addr + v->size, v->size);
85798
85799 if (v->caller)
85800+#ifdef CONFIG_GRKERNSEC_HIDESYM
85801+ seq_printf(m, " %pK", v->caller);
85802+#else
85803 seq_printf(m, " %pS", v->caller);
85804+#endif
85805
85806 if (v->nr_pages)
85807 seq_printf(m, " pages=%d", v->nr_pages);
85808diff --git a/mm/vmstat.c b/mm/vmstat.c
85809index 9800306..76b4b27 100644
85810--- a/mm/vmstat.c
85811+++ b/mm/vmstat.c
85812@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
85813 *
85814 * vm_stat contains the global counters
85815 */
85816-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
85817+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
85818 EXPORT_SYMBOL(vm_stat);
85819
85820 #ifdef CONFIG_SMP
85821@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
85822 v = p->vm_stat_diff[i];
85823 p->vm_stat_diff[i] = 0;
85824 local_irq_restore(flags);
85825- atomic_long_add(v, &zone->vm_stat[i]);
85826+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
85827 global_diff[i] += v;
85828 #ifdef CONFIG_NUMA
85829 /* 3 seconds idle till flush */
85830@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
85831
85832 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
85833 if (global_diff[i])
85834- atomic_long_add(global_diff[i], &vm_stat[i]);
85835+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
85836 }
85837
85838 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
85839@@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
85840 if (pset->vm_stat_diff[i]) {
85841 int v = pset->vm_stat_diff[i];
85842 pset->vm_stat_diff[i] = 0;
85843- atomic_long_add(v, &zone->vm_stat[i]);
85844- atomic_long_add(v, &vm_stat[i]);
85845+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
85846+ atomic_long_add_unchecked(v, &vm_stat[i]);
85847 }
85848 }
85849 #endif
85850@@ -1223,7 +1223,7 @@ static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb,
85851 return NOTIFY_OK;
85852 }
85853
85854-static struct notifier_block __cpuinitdata vmstat_notifier =
85855+static struct notifier_block vmstat_notifier =
85856 { &vmstat_cpuup_callback, NULL, 0 };
85857 #endif
85858
85859@@ -1238,10 +1238,20 @@ static int __init setup_vmstat(void)
85860 start_cpu_timer(cpu);
85861 #endif
85862 #ifdef CONFIG_PROC_FS
85863- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
85864- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
85865- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
85866- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
85867+ {
85868+ mode_t gr_mode = S_IRUGO;
85869+#ifdef CONFIG_GRKERNSEC_PROC_ADD
85870+ gr_mode = S_IRUSR;
85871+#endif
85872+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
85873+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
85874+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
85875+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
85876+#else
85877+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
85878+#endif
85879+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
85880+ }
85881 #endif
85882 return 0;
85883 }
85884diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
85885index acc74ad..be02639 100644
85886--- a/net/8021q/vlan.c
85887+++ b/net/8021q/vlan.c
85888@@ -108,6 +108,13 @@ void unregister_vlan_dev(struct net_device *dev, struct list_head *head)
85889 if (vlan_id)
85890 vlan_vid_del(real_dev, vlan_id);
85891
85892+ /* Take it out of our own structures, but be sure to interlock with
85893+ * HW accelerating devices or SW vlan input packet processing if
85894+ * VLAN is not 0 (leave it there for 802.1p).
85895+ */
85896+ if (vlan_id)
85897+ vlan_vid_del(real_dev, vlan_id);
85898+
85899 /* Get rid of the vlan's reference to real_dev */
85900 dev_put(real_dev);
85901 }
85902@@ -485,7 +492,7 @@ out:
85903 return NOTIFY_DONE;
85904 }
85905
85906-static struct notifier_block vlan_notifier_block __read_mostly = {
85907+static struct notifier_block vlan_notifier_block = {
85908 .notifier_call = vlan_device_event,
85909 };
85910
85911@@ -560,8 +567,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
85912 err = -EPERM;
85913 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
85914 break;
85915- if ((args.u.name_type >= 0) &&
85916- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
85917+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
85918 struct vlan_net *vn;
85919
85920 vn = net_generic(net, vlan_net_id);
85921diff --git a/net/9p/mod.c b/net/9p/mod.c
85922index 6ab36ae..6f1841b 100644
85923--- a/net/9p/mod.c
85924+++ b/net/9p/mod.c
85925@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
85926 void v9fs_register_trans(struct p9_trans_module *m)
85927 {
85928 spin_lock(&v9fs_trans_lock);
85929- list_add_tail(&m->list, &v9fs_trans_list);
85930+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
85931 spin_unlock(&v9fs_trans_lock);
85932 }
85933 EXPORT_SYMBOL(v9fs_register_trans);
85934@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
85935 void v9fs_unregister_trans(struct p9_trans_module *m)
85936 {
85937 spin_lock(&v9fs_trans_lock);
85938- list_del_init(&m->list);
85939+ pax_list_del_init((struct list_head *)&m->list);
85940 spin_unlock(&v9fs_trans_lock);
85941 }
85942 EXPORT_SYMBOL(v9fs_unregister_trans);
85943diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
85944index 02efb25..41541a9 100644
85945--- a/net/9p/trans_fd.c
85946+++ b/net/9p/trans_fd.c
85947@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
85948 oldfs = get_fs();
85949 set_fs(get_ds());
85950 /* The cast to a user pointer is valid due to the set_fs() */
85951- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
85952+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
85953 set_fs(oldfs);
85954
85955 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
85956diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
85957index 876fbe8..8bbea9f 100644
85958--- a/net/atm/atm_misc.c
85959+++ b/net/atm/atm_misc.c
85960@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
85961 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
85962 return 1;
85963 atm_return(vcc, truesize);
85964- atomic_inc(&vcc->stats->rx_drop);
85965+ atomic_inc_unchecked(&vcc->stats->rx_drop);
85966 return 0;
85967 }
85968 EXPORT_SYMBOL(atm_charge);
85969@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
85970 }
85971 }
85972 atm_return(vcc, guess);
85973- atomic_inc(&vcc->stats->rx_drop);
85974+ atomic_inc_unchecked(&vcc->stats->rx_drop);
85975 return NULL;
85976 }
85977 EXPORT_SYMBOL(atm_alloc_charge);
85978@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
85979
85980 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
85981 {
85982-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
85983+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
85984 __SONET_ITEMS
85985 #undef __HANDLE_ITEM
85986 }
85987@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
85988
85989 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
85990 {
85991-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
85992+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
85993 __SONET_ITEMS
85994 #undef __HANDLE_ITEM
85995 }
85996diff --git a/net/atm/lec.h b/net/atm/lec.h
85997index a86aff9..3a0d6f6 100644
85998--- a/net/atm/lec.h
85999+++ b/net/atm/lec.h
86000@@ -48,7 +48,7 @@ struct lane2_ops {
86001 const u8 *tlvs, u32 sizeoftlvs);
86002 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
86003 const u8 *tlvs, u32 sizeoftlvs);
86004-};
86005+} __no_const;
86006
86007 /*
86008 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
86009diff --git a/net/atm/proc.c b/net/atm/proc.c
86010index 0d020de..011c7bb 100644
86011--- a/net/atm/proc.c
86012+++ b/net/atm/proc.c
86013@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
86014 const struct k_atm_aal_stats *stats)
86015 {
86016 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
86017- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
86018- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
86019- atomic_read(&stats->rx_drop));
86020+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
86021+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
86022+ atomic_read_unchecked(&stats->rx_drop));
86023 }
86024
86025 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
86026diff --git a/net/atm/resources.c b/net/atm/resources.c
86027index 0447d5d..3cf4728 100644
86028--- a/net/atm/resources.c
86029+++ b/net/atm/resources.c
86030@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
86031 static void copy_aal_stats(struct k_atm_aal_stats *from,
86032 struct atm_aal_stats *to)
86033 {
86034-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
86035+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
86036 __AAL_STAT_ITEMS
86037 #undef __HANDLE_ITEM
86038 }
86039@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
86040 static void subtract_aal_stats(struct k_atm_aal_stats *from,
86041 struct atm_aal_stats *to)
86042 {
86043-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
86044+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
86045 __AAL_STAT_ITEMS
86046 #undef __HANDLE_ITEM
86047 }
86048diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
86049index d5744b7..506bae3 100644
86050--- a/net/ax25/sysctl_net_ax25.c
86051+++ b/net/ax25/sysctl_net_ax25.c
86052@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
86053 {
86054 char path[sizeof("net/ax25/") + IFNAMSIZ];
86055 int k;
86056- struct ctl_table *table;
86057+ ctl_table_no_const *table;
86058
86059 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
86060 if (!table)
86061diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
86062index 1ee94d0..14beea2 100644
86063--- a/net/batman-adv/bat_iv_ogm.c
86064+++ b/net/batman-adv/bat_iv_ogm.c
86065@@ -63,7 +63,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
86066
86067 /* randomize initial seqno to avoid collision */
86068 get_random_bytes(&random_seqno, sizeof(random_seqno));
86069- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
86070+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
86071
86072 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
86073 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
86074@@ -615,9 +615,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
86075 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
86076
86077 /* change sequence number to network order */
86078- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
86079+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
86080 batadv_ogm_packet->seqno = htonl(seqno);
86081- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
86082+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
86083
86084 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
86085 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
86086@@ -1022,7 +1022,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
86087 return;
86088
86089 /* could be changed by schedule_own_packet() */
86090- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
86091+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
86092
86093 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
86094 has_directlink_flag = 1;
86095diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
86096index f1d37cd..4190879 100644
86097--- a/net/batman-adv/hard-interface.c
86098+++ b/net/batman-adv/hard-interface.c
86099@@ -370,7 +370,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
86100 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
86101 dev_add_pack(&hard_iface->batman_adv_ptype);
86102
86103- atomic_set(&hard_iface->frag_seqno, 1);
86104+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
86105 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
86106 hard_iface->net_dev->name);
86107
86108@@ -493,7 +493,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
86109 /* This can't be called via a bat_priv callback because
86110 * we have no bat_priv yet.
86111 */
86112- atomic_set(&hard_iface->bat_iv.ogm_seqno, 1);
86113+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, 1);
86114 hard_iface->bat_iv.ogm_buff = NULL;
86115
86116 return hard_iface;
86117diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
86118index 6b548fd..fc32c8d 100644
86119--- a/net/batman-adv/soft-interface.c
86120+++ b/net/batman-adv/soft-interface.c
86121@@ -252,7 +252,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
86122 primary_if->net_dev->dev_addr, ETH_ALEN);
86123
86124 /* set broadcast sequence number */
86125- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
86126+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
86127 bcast_packet->seqno = htonl(seqno);
86128
86129 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
86130@@ -497,7 +497,7 @@ struct net_device *batadv_softif_create(const char *name)
86131 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
86132
86133 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
86134- atomic_set(&bat_priv->bcast_seqno, 1);
86135+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
86136 atomic_set(&bat_priv->tt.vn, 0);
86137 atomic_set(&bat_priv->tt.local_changes, 0);
86138 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
86139diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
86140index ae9ac9a..11e0fe7 100644
86141--- a/net/batman-adv/types.h
86142+++ b/net/batman-adv/types.h
86143@@ -48,7 +48,7 @@
86144 struct batadv_hard_iface_bat_iv {
86145 unsigned char *ogm_buff;
86146 int ogm_buff_len;
86147- atomic_t ogm_seqno;
86148+ atomic_unchecked_t ogm_seqno;
86149 };
86150
86151 struct batadv_hard_iface {
86152@@ -56,7 +56,7 @@ struct batadv_hard_iface {
86153 int16_t if_num;
86154 char if_status;
86155 struct net_device *net_dev;
86156- atomic_t frag_seqno;
86157+ atomic_unchecked_t frag_seqno;
86158 struct kobject *hardif_obj;
86159 atomic_t refcount;
86160 struct packet_type batman_adv_ptype;
86161@@ -284,7 +284,7 @@ struct batadv_priv {
86162 atomic_t orig_interval; /* uint */
86163 atomic_t hop_penalty; /* uint */
86164 atomic_t log_level; /* uint */
86165- atomic_t bcast_seqno;
86166+ atomic_unchecked_t bcast_seqno;
86167 atomic_t bcast_queue_left;
86168 atomic_t batman_queue_left;
86169 char num_ifaces;
86170diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
86171index 10aff49..ea8e021 100644
86172--- a/net/batman-adv/unicast.c
86173+++ b/net/batman-adv/unicast.c
86174@@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
86175 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
86176 frag2->flags = large_tail;
86177
86178- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
86179+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
86180 frag1->seqno = htons(seqno - 1);
86181 frag2->seqno = htons(seqno);
86182
86183diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
86184index 07f0739..3c42e34 100644
86185--- a/net/bluetooth/hci_sock.c
86186+++ b/net/bluetooth/hci_sock.c
86187@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
86188 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
86189 }
86190
86191- len = min_t(unsigned int, len, sizeof(uf));
86192+ len = min((size_t)len, sizeof(uf));
86193 if (copy_from_user(&uf, optval, len)) {
86194 err = -EFAULT;
86195 break;
86196diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
86197index 22e6583..426e2f3 100644
86198--- a/net/bluetooth/l2cap_core.c
86199+++ b/net/bluetooth/l2cap_core.c
86200@@ -3400,8 +3400,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
86201 break;
86202
86203 case L2CAP_CONF_RFC:
86204- if (olen == sizeof(rfc))
86205- memcpy(&rfc, (void *)val, olen);
86206+ if (olen != sizeof(rfc))
86207+ break;
86208+
86209+ memcpy(&rfc, (void *)val, olen);
86210
86211 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
86212 rfc.mode != chan->mode)
86213diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
86214index 1bcfb84..dad9f98 100644
86215--- a/net/bluetooth/l2cap_sock.c
86216+++ b/net/bluetooth/l2cap_sock.c
86217@@ -479,7 +479,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
86218 struct sock *sk = sock->sk;
86219 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
86220 struct l2cap_options opts;
86221- int len, err = 0;
86222+ int err = 0;
86223+ size_t len = optlen;
86224 u32 opt;
86225
86226 BT_DBG("sk %p", sk);
86227@@ -501,7 +502,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
86228 opts.max_tx = chan->max_tx;
86229 opts.txwin_size = chan->tx_win;
86230
86231- len = min_t(unsigned int, sizeof(opts), optlen);
86232+ len = min(sizeof(opts), len);
86233 if (copy_from_user((char *) &opts, optval, len)) {
86234 err = -EFAULT;
86235 break;
86236@@ -581,7 +582,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
86237 struct bt_security sec;
86238 struct bt_power pwr;
86239 struct l2cap_conn *conn;
86240- int len, err = 0;
86241+ int err = 0;
86242+ size_t len = optlen;
86243 u32 opt;
86244
86245 BT_DBG("sk %p", sk);
86246@@ -604,7 +606,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
86247
86248 sec.level = BT_SECURITY_LOW;
86249
86250- len = min_t(unsigned int, sizeof(sec), optlen);
86251+ len = min(sizeof(sec), len);
86252 if (copy_from_user((char *) &sec, optval, len)) {
86253 err = -EFAULT;
86254 break;
86255@@ -701,7 +703,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
86256
86257 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
86258
86259- len = min_t(unsigned int, sizeof(pwr), optlen);
86260+ len = min(sizeof(pwr), len);
86261 if (copy_from_user((char *) &pwr, optval, len)) {
86262 err = -EFAULT;
86263 break;
86264diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
86265index ce3f665..2c7d08f 100644
86266--- a/net/bluetooth/rfcomm/sock.c
86267+++ b/net/bluetooth/rfcomm/sock.c
86268@@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
86269 struct sock *sk = sock->sk;
86270 struct bt_security sec;
86271 int err = 0;
86272- size_t len;
86273+ size_t len = optlen;
86274 u32 opt;
86275
86276 BT_DBG("sk %p", sk);
86277@@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
86278
86279 sec.level = BT_SECURITY_LOW;
86280
86281- len = min_t(unsigned int, sizeof(sec), optlen);
86282+ len = min(sizeof(sec), len);
86283 if (copy_from_user((char *) &sec, optval, len)) {
86284 err = -EFAULT;
86285 break;
86286diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
86287index bd6fd0f..6492cba 100644
86288--- a/net/bluetooth/rfcomm/tty.c
86289+++ b/net/bluetooth/rfcomm/tty.c
86290@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
86291 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
86292
86293 spin_lock_irqsave(&dev->port.lock, flags);
86294- if (dev->port.count > 0) {
86295+ if (atomic_read(&dev->port.count) > 0) {
86296 spin_unlock_irqrestore(&dev->port.lock, flags);
86297 return;
86298 }
86299@@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
86300 return -ENODEV;
86301
86302 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
86303- dev->channel, dev->port.count);
86304+ dev->channel, atomic_read(&dev->port.count));
86305
86306 spin_lock_irqsave(&dev->port.lock, flags);
86307- if (++dev->port.count > 1) {
86308+ if (atomic_inc_return(&dev->port.count) > 1) {
86309 spin_unlock_irqrestore(&dev->port.lock, flags);
86310 return 0;
86311 }
86312@@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
86313 return;
86314
86315 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
86316- dev->port.count);
86317+ atomic_read(&dev->port.count));
86318
86319 spin_lock_irqsave(&dev->port.lock, flags);
86320- if (!--dev->port.count) {
86321+ if (!atomic_dec_return(&dev->port.count)) {
86322 spin_unlock_irqrestore(&dev->port.lock, flags);
86323 if (dev->tty_dev->parent)
86324 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
86325diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c
86326index d9576e6..85f4f4e 100644
86327--- a/net/bridge/br_fdb.c
86328+++ b/net/bridge/br_fdb.c
86329@@ -386,7 +386,7 @@ static int fdb_insert(struct net_bridge *br, struct net_bridge_port *source,
86330 return 0;
86331 br_warn(br, "adding interface %s with same address "
86332 "as a received packet\n",
86333- source->dev->name);
86334+ source ? source->dev->name : br->dev->name);
86335 fdb_delete(br, fdb);
86336 }
86337
86338diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
86339index 5fe2ff3..121d696 100644
86340--- a/net/bridge/netfilter/ebtables.c
86341+++ b/net/bridge/netfilter/ebtables.c
86342@@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
86343 tmp.valid_hooks = t->table->valid_hooks;
86344 }
86345 mutex_unlock(&ebt_mutex);
86346- if (copy_to_user(user, &tmp, *len) != 0){
86347+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
86348 BUGPRINT("c2u Didn't work\n");
86349 ret = -EFAULT;
86350 break;
86351@@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
86352 goto out;
86353 tmp.valid_hooks = t->valid_hooks;
86354
86355- if (copy_to_user(user, &tmp, *len) != 0) {
86356+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
86357 ret = -EFAULT;
86358 break;
86359 }
86360@@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
86361 tmp.entries_size = t->table->entries_size;
86362 tmp.valid_hooks = t->table->valid_hooks;
86363
86364- if (copy_to_user(user, &tmp, *len) != 0) {
86365+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
86366 ret = -EFAULT;
86367 break;
86368 }
86369diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
86370index a376ec1..1fbd6be 100644
86371--- a/net/caif/cfctrl.c
86372+++ b/net/caif/cfctrl.c
86373@@ -10,6 +10,7 @@
86374 #include <linux/spinlock.h>
86375 #include <linux/slab.h>
86376 #include <linux/pkt_sched.h>
86377+#include <linux/sched.h>
86378 #include <net/caif/caif_layer.h>
86379 #include <net/caif/cfpkt.h>
86380 #include <net/caif/cfctrl.h>
86381@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
86382 memset(&dev_info, 0, sizeof(dev_info));
86383 dev_info.id = 0xff;
86384 cfsrvl_init(&this->serv, 0, &dev_info, false);
86385- atomic_set(&this->req_seq_no, 1);
86386- atomic_set(&this->rsp_seq_no, 1);
86387+ atomic_set_unchecked(&this->req_seq_no, 1);
86388+ atomic_set_unchecked(&this->rsp_seq_no, 1);
86389 this->serv.layer.receive = cfctrl_recv;
86390 sprintf(this->serv.layer.name, "ctrl");
86391 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
86392@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
86393 struct cfctrl_request_info *req)
86394 {
86395 spin_lock_bh(&ctrl->info_list_lock);
86396- atomic_inc(&ctrl->req_seq_no);
86397- req->sequence_no = atomic_read(&ctrl->req_seq_no);
86398+ atomic_inc_unchecked(&ctrl->req_seq_no);
86399+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
86400 list_add_tail(&req->list, &ctrl->list);
86401 spin_unlock_bh(&ctrl->info_list_lock);
86402 }
86403@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
86404 if (p != first)
86405 pr_warn("Requests are not received in order\n");
86406
86407- atomic_set(&ctrl->rsp_seq_no,
86408+ atomic_set_unchecked(&ctrl->rsp_seq_no,
86409 p->sequence_no);
86410 list_del(&p->list);
86411 goto out;
86412diff --git a/net/can/af_can.c b/net/can/af_can.c
86413index ddac1ee..3ee0a78 100644
86414--- a/net/can/af_can.c
86415+++ b/net/can/af_can.c
86416@@ -872,7 +872,7 @@ static const struct net_proto_family can_family_ops = {
86417 };
86418
86419 /* notifier block for netdevice event */
86420-static struct notifier_block can_netdev_notifier __read_mostly = {
86421+static struct notifier_block can_netdev_notifier = {
86422 .notifier_call = can_notifier,
86423 };
86424
86425diff --git a/net/can/gw.c b/net/can/gw.c
86426index 28e7bdc..d42c4cd 100644
86427--- a/net/can/gw.c
86428+++ b/net/can/gw.c
86429@@ -67,7 +67,6 @@ MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
86430 MODULE_ALIAS("can-gw");
86431
86432 static HLIST_HEAD(cgw_list);
86433-static struct notifier_block notifier;
86434
86435 static struct kmem_cache *cgw_cache __read_mostly;
86436
86437@@ -893,6 +892,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
86438 return err;
86439 }
86440
86441+static struct notifier_block notifier = {
86442+ .notifier_call = cgw_notifier
86443+};
86444+
86445 static __init int cgw_module_init(void)
86446 {
86447 printk(banner);
86448@@ -904,7 +907,6 @@ static __init int cgw_module_init(void)
86449 return -ENOMEM;
86450
86451 /* set notifier */
86452- notifier.notifier_call = cgw_notifier;
86453 register_netdevice_notifier(&notifier);
86454
86455 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
86456diff --git a/net/compat.c b/net/compat.c
86457index 79ae884..17c5c09 100644
86458--- a/net/compat.c
86459+++ b/net/compat.c
86460@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
86461 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
86462 __get_user(kmsg->msg_flags, &umsg->msg_flags))
86463 return -EFAULT;
86464- kmsg->msg_name = compat_ptr(tmp1);
86465- kmsg->msg_iov = compat_ptr(tmp2);
86466- kmsg->msg_control = compat_ptr(tmp3);
86467+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
86468+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
86469+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
86470 return 0;
86471 }
86472
86473@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
86474
86475 if (kern_msg->msg_namelen) {
86476 if (mode == VERIFY_READ) {
86477- int err = move_addr_to_kernel(kern_msg->msg_name,
86478+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
86479 kern_msg->msg_namelen,
86480 kern_address);
86481 if (err < 0)
86482@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
86483 kern_msg->msg_name = NULL;
86484
86485 tot_len = iov_from_user_compat_to_kern(kern_iov,
86486- (struct compat_iovec __user *)kern_msg->msg_iov,
86487+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
86488 kern_msg->msg_iovlen);
86489 if (tot_len >= 0)
86490 kern_msg->msg_iov = kern_iov;
86491@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
86492
86493 #define CMSG_COMPAT_FIRSTHDR(msg) \
86494 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
86495- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
86496+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
86497 (struct compat_cmsghdr __user *)NULL)
86498
86499 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
86500 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
86501 (ucmlen) <= (unsigned long) \
86502 ((mhdr)->msg_controllen - \
86503- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
86504+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
86505
86506 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
86507 struct compat_cmsghdr __user *cmsg, int cmsg_len)
86508 {
86509 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
86510- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
86511+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
86512 msg->msg_controllen)
86513 return NULL;
86514 return (struct compat_cmsghdr __user *)ptr;
86515@@ -219,7 +219,7 @@ Efault:
86516
86517 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
86518 {
86519- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
86520+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
86521 struct compat_cmsghdr cmhdr;
86522 struct compat_timeval ctv;
86523 struct compat_timespec cts[3];
86524@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
86525
86526 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
86527 {
86528- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
86529+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
86530 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
86531 int fdnum = scm->fp->count;
86532 struct file **fp = scm->fp->fp;
86533@@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
86534 return -EFAULT;
86535 old_fs = get_fs();
86536 set_fs(KERNEL_DS);
86537- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
86538+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
86539 set_fs(old_fs);
86540
86541 return err;
86542@@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
86543 len = sizeof(ktime);
86544 old_fs = get_fs();
86545 set_fs(KERNEL_DS);
86546- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
86547+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
86548 set_fs(old_fs);
86549
86550 if (!err) {
86551@@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
86552 case MCAST_JOIN_GROUP:
86553 case MCAST_LEAVE_GROUP:
86554 {
86555- struct compat_group_req __user *gr32 = (void *)optval;
86556+ struct compat_group_req __user *gr32 = (void __user *)optval;
86557 struct group_req __user *kgr =
86558 compat_alloc_user_space(sizeof(struct group_req));
86559 u32 interface;
86560@@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
86561 case MCAST_BLOCK_SOURCE:
86562 case MCAST_UNBLOCK_SOURCE:
86563 {
86564- struct compat_group_source_req __user *gsr32 = (void *)optval;
86565+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
86566 struct group_source_req __user *kgsr = compat_alloc_user_space(
86567 sizeof(struct group_source_req));
86568 u32 interface;
86569@@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
86570 }
86571 case MCAST_MSFILTER:
86572 {
86573- struct compat_group_filter __user *gf32 = (void *)optval;
86574+ struct compat_group_filter __user *gf32 = (void __user *)optval;
86575 struct group_filter __user *kgf;
86576 u32 interface, fmode, numsrc;
86577
86578@@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
86579 char __user *optval, int __user *optlen,
86580 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
86581 {
86582- struct compat_group_filter __user *gf32 = (void *)optval;
86583+ struct compat_group_filter __user *gf32 = (void __user *)optval;
86584 struct group_filter __user *kgf;
86585 int __user *koptlen;
86586 u32 interface, fmode, numsrc;
86587@@ -796,7 +796,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
86588
86589 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
86590 return -EINVAL;
86591- if (copy_from_user(a, args, nas[call]))
86592+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
86593 return -EFAULT;
86594 a0 = a[0];
86595 a1 = a[1];
86596diff --git a/net/core/datagram.c b/net/core/datagram.c
86597index 368f9c3..f82d4a3 100644
86598--- a/net/core/datagram.c
86599+++ b/net/core/datagram.c
86600@@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
86601 }
86602
86603 kfree_skb(skb);
86604- atomic_inc(&sk->sk_drops);
86605+ atomic_inc_unchecked(&sk->sk_drops);
86606 sk_mem_reclaim_partial(sk);
86607
86608 return err;
86609diff --git a/net/core/dev.c b/net/core/dev.c
86610index 5d9c43d..b471558 100644
86611--- a/net/core/dev.c
86612+++ b/net/core/dev.c
86613@@ -1250,9 +1250,13 @@ void dev_load(struct net *net, const char *name)
86614 if (no_module && capable(CAP_NET_ADMIN))
86615 no_module = request_module("netdev-%s", name);
86616 if (no_module && capable(CAP_SYS_MODULE)) {
86617+#ifdef CONFIG_GRKERNSEC_MODHARDEN
86618+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
86619+#else
86620 if (!request_module("%s", name))
86621 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
86622 name);
86623+#endif
86624 }
86625 }
86626 EXPORT_SYMBOL(dev_load);
86627@@ -1714,7 +1718,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
86628 {
86629 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
86630 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
86631- atomic_long_inc(&dev->rx_dropped);
86632+ atomic_long_inc_unchecked(&dev->rx_dropped);
86633 kfree_skb(skb);
86634 return NET_RX_DROP;
86635 }
86636@@ -1724,7 +1728,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
86637 nf_reset(skb);
86638
86639 if (unlikely(!is_skb_forwardable(dev, skb))) {
86640- atomic_long_inc(&dev->rx_dropped);
86641+ atomic_long_inc_unchecked(&dev->rx_dropped);
86642 kfree_skb(skb);
86643 return NET_RX_DROP;
86644 }
86645@@ -2179,7 +2183,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
86646
86647 struct dev_gso_cb {
86648 void (*destructor)(struct sk_buff *skb);
86649-};
86650+} __no_const;
86651
86652 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
86653
86654@@ -3052,7 +3056,7 @@ enqueue:
86655
86656 local_irq_restore(flags);
86657
86658- atomic_long_inc(&skb->dev->rx_dropped);
86659+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
86660 kfree_skb(skb);
86661 return NET_RX_DROP;
86662 }
86663@@ -3124,7 +3128,7 @@ int netif_rx_ni(struct sk_buff *skb)
86664 }
86665 EXPORT_SYMBOL(netif_rx_ni);
86666
86667-static void net_tx_action(struct softirq_action *h)
86668+static void net_tx_action(void)
86669 {
86670 struct softnet_data *sd = &__get_cpu_var(softnet_data);
86671
86672@@ -3462,7 +3466,7 @@ ncls:
86673 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
86674 } else {
86675 drop:
86676- atomic_long_inc(&skb->dev->rx_dropped);
86677+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
86678 kfree_skb(skb);
86679 /* Jamal, now you will not able to escape explaining
86680 * me how you were going to use this. :-)
86681@@ -4045,7 +4049,7 @@ void netif_napi_del(struct napi_struct *napi)
86682 }
86683 EXPORT_SYMBOL(netif_napi_del);
86684
86685-static void net_rx_action(struct softirq_action *h)
86686+static void net_rx_action(void)
86687 {
86688 struct softnet_data *sd = &__get_cpu_var(softnet_data);
86689 unsigned long time_limit = jiffies + 2;
86690@@ -4529,8 +4533,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
86691 else
86692 seq_printf(seq, "%04x", ntohs(pt->type));
86693
86694+#ifdef CONFIG_GRKERNSEC_HIDESYM
86695+ seq_printf(seq, " %-8s %p\n",
86696+ pt->dev ? pt->dev->name : "", NULL);
86697+#else
86698 seq_printf(seq, " %-8s %pF\n",
86699 pt->dev ? pt->dev->name : "", pt->func);
86700+#endif
86701 }
86702
86703 return 0;
86704@@ -6102,7 +6111,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
86705 } else {
86706 netdev_stats_to_stats64(storage, &dev->stats);
86707 }
86708- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
86709+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
86710 return storage;
86711 }
86712 EXPORT_SYMBOL(dev_get_stats);
86713diff --git a/net/core/flow.c b/net/core/flow.c
86714index 3bad824..2071a55 100644
86715--- a/net/core/flow.c
86716+++ b/net/core/flow.c
86717@@ -61,7 +61,7 @@ struct flow_cache {
86718 struct timer_list rnd_timer;
86719 };
86720
86721-atomic_t flow_cache_genid = ATOMIC_INIT(0);
86722+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
86723 EXPORT_SYMBOL(flow_cache_genid);
86724 static struct flow_cache flow_cache_global;
86725 static struct kmem_cache *flow_cachep __read_mostly;
86726@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
86727
86728 static int flow_entry_valid(struct flow_cache_entry *fle)
86729 {
86730- if (atomic_read(&flow_cache_genid) != fle->genid)
86731+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
86732 return 0;
86733 if (fle->object && !fle->object->ops->check(fle->object))
86734 return 0;
86735@@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
86736 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
86737 fcp->hash_count++;
86738 }
86739- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
86740+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
86741 flo = fle->object;
86742 if (!flo)
86743 goto ret_object;
86744@@ -280,7 +280,7 @@ nocache:
86745 }
86746 flo = resolver(net, key, family, dir, flo, ctx);
86747 if (fle) {
86748- fle->genid = atomic_read(&flow_cache_genid);
86749+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
86750 if (!IS_ERR(flo))
86751 fle->object = flo;
86752 else
86753diff --git a/net/core/iovec.c b/net/core/iovec.c
86754index 7e7aeb0..2a998cb 100644
86755--- a/net/core/iovec.c
86756+++ b/net/core/iovec.c
86757@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
86758 if (m->msg_namelen) {
86759 if (mode == VERIFY_READ) {
86760 void __user *namep;
86761- namep = (void __user __force *) m->msg_name;
86762+ namep = (void __force_user *) m->msg_name;
86763 err = move_addr_to_kernel(namep, m->msg_namelen,
86764 address);
86765 if (err < 0)
86766@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
86767 }
86768
86769 size = m->msg_iovlen * sizeof(struct iovec);
86770- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
86771+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
86772 return -EFAULT;
86773
86774 m->msg_iov = iov;
86775diff --git a/net/core/neighbour.c b/net/core/neighbour.c
86776index c815f28..e6403f2 100644
86777--- a/net/core/neighbour.c
86778+++ b/net/core/neighbour.c
86779@@ -2776,7 +2776,7 @@ static int proc_unres_qlen(ctl_table *ctl, int write, void __user *buffer,
86780 size_t *lenp, loff_t *ppos)
86781 {
86782 int size, ret;
86783- ctl_table tmp = *ctl;
86784+ ctl_table_no_const tmp = *ctl;
86785
86786 tmp.extra1 = &zero;
86787 tmp.extra2 = &unres_qlen_max;
86788diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
86789index 28c5f5a..7edf2e2 100644
86790--- a/net/core/net-sysfs.c
86791+++ b/net/core/net-sysfs.c
86792@@ -1455,7 +1455,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
86793 }
86794 EXPORT_SYMBOL(netdev_class_remove_file);
86795
86796-int netdev_kobject_init(void)
86797+int __init netdev_kobject_init(void)
86798 {
86799 kobj_ns_type_register(&net_ns_type_operations);
86800 return class_register(&net_class);
86801diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
86802index 8acce01..2e306bb 100644
86803--- a/net/core/net_namespace.c
86804+++ b/net/core/net_namespace.c
86805@@ -442,7 +442,7 @@ static int __register_pernet_operations(struct list_head *list,
86806 int error;
86807 LIST_HEAD(net_exit_list);
86808
86809- list_add_tail(&ops->list, list);
86810+ pax_list_add_tail((struct list_head *)&ops->list, list);
86811 if (ops->init || (ops->id && ops->size)) {
86812 for_each_net(net) {
86813 error = ops_init(ops, net);
86814@@ -455,7 +455,7 @@ static int __register_pernet_operations(struct list_head *list,
86815
86816 out_undo:
86817 /* If I have an error cleanup all namespaces I initialized */
86818- list_del(&ops->list);
86819+ pax_list_del((struct list_head *)&ops->list);
86820 ops_exit_list(ops, &net_exit_list);
86821 ops_free_list(ops, &net_exit_list);
86822 return error;
86823@@ -466,7 +466,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
86824 struct net *net;
86825 LIST_HEAD(net_exit_list);
86826
86827- list_del(&ops->list);
86828+ pax_list_del((struct list_head *)&ops->list);
86829 for_each_net(net)
86830 list_add_tail(&net->exit_list, &net_exit_list);
86831 ops_exit_list(ops, &net_exit_list);
86832@@ -600,7 +600,7 @@ int register_pernet_device(struct pernet_operations *ops)
86833 mutex_lock(&net_mutex);
86834 error = register_pernet_operations(&pernet_list, ops);
86835 if (!error && (first_device == &pernet_list))
86836- first_device = &ops->list;
86837+ first_device = (struct list_head *)&ops->list;
86838 mutex_unlock(&net_mutex);
86839 return error;
86840 }
86841diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
86842index 6212ec9..5ee16b2 100644
86843--- a/net/core/rtnetlink.c
86844+++ b/net/core/rtnetlink.c
86845@@ -58,7 +58,7 @@ struct rtnl_link {
86846 rtnl_doit_func doit;
86847 rtnl_dumpit_func dumpit;
86848 rtnl_calcit_func calcit;
86849-};
86850+} __no_const;
86851
86852 static DEFINE_MUTEX(rtnl_mutex);
86853
86854@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
86855 if (rtnl_link_ops_get(ops->kind))
86856 return -EEXIST;
86857
86858- if (!ops->dellink)
86859- ops->dellink = unregister_netdevice_queue;
86860+ if (!ops->dellink) {
86861+ pax_open_kernel();
86862+ *(void **)&ops->dellink = unregister_netdevice_queue;
86863+ pax_close_kernel();
86864+ }
86865
86866- list_add_tail(&ops->list, &link_ops);
86867+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
86868 return 0;
86869 }
86870 EXPORT_SYMBOL_GPL(__rtnl_link_register);
86871@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
86872 for_each_net(net) {
86873 __rtnl_kill_links(net, ops);
86874 }
86875- list_del(&ops->list);
86876+ pax_list_del((struct list_head *)&ops->list);
86877 }
86878 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
86879
86880@@ -1068,7 +1071,7 @@ static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
86881 rcu_read_lock();
86882 cb->seq = net->dev_base_seq;
86883
86884- if (nlmsg_parse(cb->nlh, sizeof(struct rtgenmsg), tb, IFLA_MAX,
86885+ if (nlmsg_parse(cb->nlh, sizeof(struct ifinfomsg), tb, IFLA_MAX,
86886 ifla_policy) >= 0) {
86887
86888 if (tb[IFLA_EXT_MASK])
86889@@ -1924,7 +1927,7 @@ static u16 rtnl_calcit(struct sk_buff *skb, struct nlmsghdr *nlh)
86890 u32 ext_filter_mask = 0;
86891 u16 min_ifinfo_dump_size = 0;
86892
86893- if (nlmsg_parse(nlh, sizeof(struct rtgenmsg), tb, IFLA_MAX,
86894+ if (nlmsg_parse(nlh, sizeof(struct ifinfomsg), tb, IFLA_MAX,
86895 ifla_policy) >= 0) {
86896 if (tb[IFLA_EXT_MASK])
86897 ext_filter_mask = nla_get_u32(tb[IFLA_EXT_MASK]);
86898diff --git a/net/core/scm.c b/net/core/scm.c
86899index 2dc6cda..2159524 100644
86900--- a/net/core/scm.c
86901+++ b/net/core/scm.c
86902@@ -226,7 +226,7 @@ EXPORT_SYMBOL(__scm_send);
86903 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
86904 {
86905 struct cmsghdr __user *cm
86906- = (__force struct cmsghdr __user *)msg->msg_control;
86907+ = (struct cmsghdr __force_user *)msg->msg_control;
86908 struct cmsghdr cmhdr;
86909 int cmlen = CMSG_LEN(len);
86910 int err;
86911@@ -249,7 +249,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
86912 err = -EFAULT;
86913 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
86914 goto out;
86915- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
86916+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
86917 goto out;
86918 cmlen = CMSG_SPACE(len);
86919 if (msg->msg_controllen < cmlen)
86920@@ -265,7 +265,7 @@ EXPORT_SYMBOL(put_cmsg);
86921 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
86922 {
86923 struct cmsghdr __user *cm
86924- = (__force struct cmsghdr __user*)msg->msg_control;
86925+ = (struct cmsghdr __force_user *)msg->msg_control;
86926
86927 int fdmax = 0;
86928 int fdnum = scm->fp->count;
86929@@ -285,7 +285,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
86930 if (fdnum < fdmax)
86931 fdmax = fdnum;
86932
86933- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
86934+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
86935 i++, cmfptr++)
86936 {
86937 struct socket *sock;
86938diff --git a/net/core/sock.c b/net/core/sock.c
86939index bc131d4..029e378 100644
86940--- a/net/core/sock.c
86941+++ b/net/core/sock.c
86942@@ -388,7 +388,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86943 struct sk_buff_head *list = &sk->sk_receive_queue;
86944
86945 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
86946- atomic_inc(&sk->sk_drops);
86947+ atomic_inc_unchecked(&sk->sk_drops);
86948 trace_sock_rcvqueue_full(sk, skb);
86949 return -ENOMEM;
86950 }
86951@@ -398,7 +398,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86952 return err;
86953
86954 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
86955- atomic_inc(&sk->sk_drops);
86956+ atomic_inc_unchecked(&sk->sk_drops);
86957 return -ENOBUFS;
86958 }
86959
86960@@ -418,7 +418,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86961 skb_dst_force(skb);
86962
86963 spin_lock_irqsave(&list->lock, flags);
86964- skb->dropcount = atomic_read(&sk->sk_drops);
86965+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
86966 __skb_queue_tail(list, skb);
86967 spin_unlock_irqrestore(&list->lock, flags);
86968
86969@@ -438,7 +438,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
86970 skb->dev = NULL;
86971
86972 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
86973- atomic_inc(&sk->sk_drops);
86974+ atomic_inc_unchecked(&sk->sk_drops);
86975 goto discard_and_relse;
86976 }
86977 if (nested)
86978@@ -456,7 +456,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
86979 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
86980 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
86981 bh_unlock_sock(sk);
86982- atomic_inc(&sk->sk_drops);
86983+ atomic_inc_unchecked(&sk->sk_drops);
86984 goto discard_and_relse;
86985 }
86986
86987@@ -930,12 +930,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
86988 struct timeval tm;
86989 } v;
86990
86991- int lv = sizeof(int);
86992- int len;
86993+ unsigned int lv = sizeof(int);
86994+ unsigned int len;
86995
86996 if (get_user(len, optlen))
86997 return -EFAULT;
86998- if (len < 0)
86999+ if (len > INT_MAX)
87000 return -EINVAL;
87001
87002 memset(&v, 0, sizeof(v));
87003@@ -1083,11 +1083,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
87004
87005 case SO_PEERNAME:
87006 {
87007- char address[128];
87008+ char address[_K_SS_MAXSIZE];
87009
87010 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
87011 return -ENOTCONN;
87012- if (lv < len)
87013+ if (lv < len || sizeof address < len)
87014 return -EINVAL;
87015 if (copy_to_user(optval, address, len))
87016 return -EFAULT;
87017@@ -1146,7 +1146,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
87018
87019 if (len > lv)
87020 len = lv;
87021- if (copy_to_user(optval, &v, len))
87022+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
87023 return -EFAULT;
87024 lenout:
87025 if (put_user(len, optlen))
87026@@ -2276,7 +2276,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
87027 */
87028 smp_wmb();
87029 atomic_set(&sk->sk_refcnt, 1);
87030- atomic_set(&sk->sk_drops, 0);
87031+ atomic_set_unchecked(&sk->sk_drops, 0);
87032 }
87033 EXPORT_SYMBOL(sock_init_data);
87034
87035diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
87036index 750f44f..922399c 100644
87037--- a/net/core/sock_diag.c
87038+++ b/net/core/sock_diag.c
87039@@ -9,26 +9,33 @@
87040 #include <linux/inet_diag.h>
87041 #include <linux/sock_diag.h>
87042
87043-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
87044+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
87045 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
87046 static DEFINE_MUTEX(sock_diag_table_mutex);
87047
87048 int sock_diag_check_cookie(void *sk, __u32 *cookie)
87049 {
87050+#ifndef CONFIG_GRKERNSEC_HIDESYM
87051 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
87052 cookie[1] != INET_DIAG_NOCOOKIE) &&
87053 ((u32)(unsigned long)sk != cookie[0] ||
87054 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
87055 return -ESTALE;
87056 else
87057+#endif
87058 return 0;
87059 }
87060 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
87061
87062 void sock_diag_save_cookie(void *sk, __u32 *cookie)
87063 {
87064+#ifdef CONFIG_GRKERNSEC_HIDESYM
87065+ cookie[0] = 0;
87066+ cookie[1] = 0;
87067+#else
87068 cookie[0] = (u32)(unsigned long)sk;
87069 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
87070+#endif
87071 }
87072 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
87073
87074@@ -75,8 +82,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
87075 mutex_lock(&sock_diag_table_mutex);
87076 if (sock_diag_handlers[hndl->family])
87077 err = -EBUSY;
87078- else
87079+ else {
87080+ pax_open_kernel();
87081 sock_diag_handlers[hndl->family] = hndl;
87082+ pax_close_kernel();
87083+ }
87084 mutex_unlock(&sock_diag_table_mutex);
87085
87086 return err;
87087@@ -92,26 +102,13 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
87088
87089 mutex_lock(&sock_diag_table_mutex);
87090 BUG_ON(sock_diag_handlers[family] != hnld);
87091+ pax_open_kernel();
87092 sock_diag_handlers[family] = NULL;
87093+ pax_close_kernel();
87094 mutex_unlock(&sock_diag_table_mutex);
87095 }
87096 EXPORT_SYMBOL_GPL(sock_diag_unregister);
87097
87098-static const inline struct sock_diag_handler *sock_diag_lock_handler(int family)
87099-{
87100- if (sock_diag_handlers[family] == NULL)
87101- request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
87102- NETLINK_SOCK_DIAG, family);
87103-
87104- mutex_lock(&sock_diag_table_mutex);
87105- return sock_diag_handlers[family];
87106-}
87107-
87108-static inline void sock_diag_unlock_handler(const struct sock_diag_handler *h)
87109-{
87110- mutex_unlock(&sock_diag_table_mutex);
87111-}
87112-
87113 static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
87114 {
87115 int err;
87116@@ -124,12 +121,17 @@ static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
87117 if (req->sdiag_family >= AF_MAX)
87118 return -EINVAL;
87119
87120- hndl = sock_diag_lock_handler(req->sdiag_family);
87121+ if (sock_diag_handlers[req->sdiag_family] == NULL)
87122+ request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
87123+ NETLINK_SOCK_DIAG, req->sdiag_family);
87124+
87125+ mutex_lock(&sock_diag_table_mutex);
87126+ hndl = sock_diag_handlers[req->sdiag_family];
87127 if (hndl == NULL)
87128 err = -ENOENT;
87129 else
87130 err = hndl->dump(skb, nlh);
87131- sock_diag_unlock_handler(hndl);
87132+ mutex_unlock(&sock_diag_table_mutex);
87133
87134 return err;
87135 }
87136diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
87137index d1b0804..98cf5f7 100644
87138--- a/net/core/sysctl_net_core.c
87139+++ b/net/core/sysctl_net_core.c
87140@@ -26,7 +26,7 @@ static int rps_sock_flow_sysctl(ctl_table *table, int write,
87141 {
87142 unsigned int orig_size, size;
87143 int ret, i;
87144- ctl_table tmp = {
87145+ ctl_table_no_const tmp = {
87146 .data = &size,
87147 .maxlen = sizeof(size),
87148 .mode = table->mode
87149@@ -205,13 +205,12 @@ static struct ctl_table netns_core_table[] = {
87150
87151 static __net_init int sysctl_core_net_init(struct net *net)
87152 {
87153- struct ctl_table *tbl;
87154+ ctl_table_no_const *tbl = NULL;
87155
87156 net->core.sysctl_somaxconn = SOMAXCONN;
87157
87158- tbl = netns_core_table;
87159 if (!net_eq(net, &init_net)) {
87160- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
87161+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
87162 if (tbl == NULL)
87163 goto err_dup;
87164
87165@@ -221,17 +220,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
87166 if (net->user_ns != &init_user_ns) {
87167 tbl[0].procname = NULL;
87168 }
87169- }
87170-
87171- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
87172+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
87173+ } else
87174+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
87175 if (net->core.sysctl_hdr == NULL)
87176 goto err_reg;
87177
87178 return 0;
87179
87180 err_reg:
87181- if (tbl != netns_core_table)
87182- kfree(tbl);
87183+ kfree(tbl);
87184 err_dup:
87185 return -ENOMEM;
87186 }
87187@@ -246,7 +244,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
87188 kfree(tbl);
87189 }
87190
87191-static __net_initdata struct pernet_operations sysctl_core_ops = {
87192+static __net_initconst struct pernet_operations sysctl_core_ops = {
87193 .init = sysctl_core_net_init,
87194 .exit = sysctl_core_net_exit,
87195 };
87196diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
87197index 307c322..78a4c6f 100644
87198--- a/net/decnet/af_decnet.c
87199+++ b/net/decnet/af_decnet.c
87200@@ -468,6 +468,7 @@ static struct proto dn_proto = {
87201 .sysctl_rmem = sysctl_decnet_rmem,
87202 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
87203 .obj_size = sizeof(struct dn_sock),
87204+ .slab_flags = SLAB_USERCOPY,
87205 };
87206
87207 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
87208diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
87209index a55eecc..dd8428c 100644
87210--- a/net/decnet/sysctl_net_decnet.c
87211+++ b/net/decnet/sysctl_net_decnet.c
87212@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
87213
87214 if (len > *lenp) len = *lenp;
87215
87216- if (copy_to_user(buffer, addr, len))
87217+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
87218 return -EFAULT;
87219
87220 *lenp = len;
87221@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
87222
87223 if (len > *lenp) len = *lenp;
87224
87225- if (copy_to_user(buffer, devname, len))
87226+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
87227 return -EFAULT;
87228
87229 *lenp = len;
87230diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
87231index fcf104e..95552d4 100644
87232--- a/net/ipv4/af_inet.c
87233+++ b/net/ipv4/af_inet.c
87234@@ -1717,13 +1717,9 @@ static int __init inet_init(void)
87235
87236 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > sizeof(dummy_skb->cb));
87237
87238- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
87239- if (!sysctl_local_reserved_ports)
87240- goto out;
87241-
87242 rc = proto_register(&tcp_prot, 1);
87243 if (rc)
87244- goto out_free_reserved_ports;
87245+ goto out;
87246
87247 rc = proto_register(&udp_prot, 1);
87248 if (rc)
87249@@ -1832,8 +1828,6 @@ out_unregister_udp_proto:
87250 proto_unregister(&udp_prot);
87251 out_unregister_tcp_proto:
87252 proto_unregister(&tcp_prot);
87253-out_free_reserved_ports:
87254- kfree(sysctl_local_reserved_ports);
87255 goto out;
87256 }
87257
87258diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
87259index a69b4e4..dbccba5 100644
87260--- a/net/ipv4/ah4.c
87261+++ b/net/ipv4/ah4.c
87262@@ -421,7 +421,7 @@ static void ah4_err(struct sk_buff *skb, u32 info)
87263 return;
87264
87265 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
87266- atomic_inc(&flow_cache_genid);
87267+ atomic_inc_unchecked(&flow_cache_genid);
87268 rt_genid_bump(net);
87269
87270 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_AH, 0);
87271diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
87272index a8e4f26..25e5f40 100644
87273--- a/net/ipv4/devinet.c
87274+++ b/net/ipv4/devinet.c
87275@@ -1763,7 +1763,7 @@ static int ipv4_doint_and_flush(ctl_table *ctl, int write,
87276 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
87277 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
87278
87279-static struct devinet_sysctl_table {
87280+static const struct devinet_sysctl_table {
87281 struct ctl_table_header *sysctl_header;
87282 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
87283 } devinet_sysctl = {
87284@@ -1881,7 +1881,7 @@ static __net_init int devinet_init_net(struct net *net)
87285 int err;
87286 struct ipv4_devconf *all, *dflt;
87287 #ifdef CONFIG_SYSCTL
87288- struct ctl_table *tbl = ctl_forward_entry;
87289+ ctl_table_no_const *tbl = NULL;
87290 struct ctl_table_header *forw_hdr;
87291 #endif
87292
87293@@ -1899,7 +1899,7 @@ static __net_init int devinet_init_net(struct net *net)
87294 goto err_alloc_dflt;
87295
87296 #ifdef CONFIG_SYSCTL
87297- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
87298+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
87299 if (tbl == NULL)
87300 goto err_alloc_ctl;
87301
87302@@ -1919,7 +1919,10 @@ static __net_init int devinet_init_net(struct net *net)
87303 goto err_reg_dflt;
87304
87305 err = -ENOMEM;
87306- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
87307+ if (!net_eq(net, &init_net))
87308+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
87309+ else
87310+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
87311 if (forw_hdr == NULL)
87312 goto err_reg_ctl;
87313 net->ipv4.forw_hdr = forw_hdr;
87314@@ -1935,8 +1938,7 @@ err_reg_ctl:
87315 err_reg_dflt:
87316 __devinet_sysctl_unregister(all);
87317 err_reg_all:
87318- if (tbl != ctl_forward_entry)
87319- kfree(tbl);
87320+ kfree(tbl);
87321 err_alloc_ctl:
87322 #endif
87323 if (dflt != &ipv4_devconf_dflt)
87324diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
87325index 3b4f0cd..a6ba66e 100644
87326--- a/net/ipv4/esp4.c
87327+++ b/net/ipv4/esp4.c
87328@@ -139,8 +139,6 @@ static int esp_output(struct xfrm_state *x, struct sk_buff *skb)
87329
87330 /* skb is pure payload to encrypt */
87331
87332- err = -ENOMEM;
87333-
87334 esp = x->data;
87335 aead = esp->aead;
87336 alen = crypto_aead_authsize(aead);
87337@@ -176,8 +174,10 @@ static int esp_output(struct xfrm_state *x, struct sk_buff *skb)
87338 }
87339
87340 tmp = esp_alloc_tmp(aead, nfrags + sglists, seqhilen);
87341- if (!tmp)
87342+ if (!tmp) {
87343+ err = -ENOMEM;
87344 goto error;
87345+ }
87346
87347 seqhi = esp_tmp_seqhi(tmp);
87348 iv = esp_tmp_iv(aead, tmp, seqhilen);
87349@@ -503,7 +503,7 @@ static void esp4_err(struct sk_buff *skb, u32 info)
87350 return;
87351
87352 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
87353- atomic_inc(&flow_cache_genid);
87354+ atomic_inc_unchecked(&flow_cache_genid);
87355 rt_genid_bump(net);
87356
87357 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_ESP, 0);
87358diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
87359index 5cd75e2..f57ef39 100644
87360--- a/net/ipv4/fib_frontend.c
87361+++ b/net/ipv4/fib_frontend.c
87362@@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
87363 #ifdef CONFIG_IP_ROUTE_MULTIPATH
87364 fib_sync_up(dev);
87365 #endif
87366- atomic_inc(&net->ipv4.dev_addr_genid);
87367+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
87368 rt_cache_flush(dev_net(dev));
87369 break;
87370 case NETDEV_DOWN:
87371 fib_del_ifaddr(ifa, NULL);
87372- atomic_inc(&net->ipv4.dev_addr_genid);
87373+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
87374 if (ifa->ifa_dev->ifa_list == NULL) {
87375 /* Last address was deleted from this interface.
87376 * Disable IP.
87377@@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
87378 #ifdef CONFIG_IP_ROUTE_MULTIPATH
87379 fib_sync_up(dev);
87380 #endif
87381- atomic_inc(&net->ipv4.dev_addr_genid);
87382+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
87383 rt_cache_flush(net);
87384 break;
87385 case NETDEV_DOWN:
87386diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
87387index 4797a80..2bd54e9 100644
87388--- a/net/ipv4/fib_semantics.c
87389+++ b/net/ipv4/fib_semantics.c
87390@@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
87391 nh->nh_saddr = inet_select_addr(nh->nh_dev,
87392 nh->nh_gw,
87393 nh->nh_parent->fib_scope);
87394- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
87395+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
87396
87397 return nh->nh_saddr;
87398 }
87399diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
87400index d0670f0..744ac80 100644
87401--- a/net/ipv4/inet_connection_sock.c
87402+++ b/net/ipv4/inet_connection_sock.c
87403@@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
87404 .range = { 32768, 61000 },
87405 };
87406
87407-unsigned long *sysctl_local_reserved_ports;
87408+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
87409 EXPORT_SYMBOL(sysctl_local_reserved_ports);
87410
87411 void inet_get_local_port_range(int *low, int *high)
87412diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
87413index fa3ae81..0dbe6b8 100644
87414--- a/net/ipv4/inet_hashtables.c
87415+++ b/net/ipv4/inet_hashtables.c
87416@@ -18,12 +18,15 @@
87417 #include <linux/sched.h>
87418 #include <linux/slab.h>
87419 #include <linux/wait.h>
87420+#include <linux/security.h>
87421
87422 #include <net/inet_connection_sock.h>
87423 #include <net/inet_hashtables.h>
87424 #include <net/secure_seq.h>
87425 #include <net/ip.h>
87426
87427+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
87428+
87429 /*
87430 * Allocate and initialize a new local port bind bucket.
87431 * The bindhash mutex for snum's hash chain must be held here.
87432@@ -540,6 +543,8 @@ ok:
87433 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
87434 spin_unlock(&head->lock);
87435
87436+ gr_update_task_in_ip_table(current, inet_sk(sk));
87437+
87438 if (tw) {
87439 inet_twsk_deschedule(tw, death_row);
87440 while (twrefcnt) {
87441diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
87442index 000e3d2..5472da3 100644
87443--- a/net/ipv4/inetpeer.c
87444+++ b/net/ipv4/inetpeer.c
87445@@ -503,8 +503,8 @@ relookup:
87446 if (p) {
87447 p->daddr = *daddr;
87448 atomic_set(&p->refcnt, 1);
87449- atomic_set(&p->rid, 0);
87450- atomic_set(&p->ip_id_count,
87451+ atomic_set_unchecked(&p->rid, 0);
87452+ atomic_set_unchecked(&p->ip_id_count,
87453 (daddr->family == AF_INET) ?
87454 secure_ip_id(daddr->addr.a4) :
87455 secure_ipv6_id(daddr->addr.a6));
87456diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
87457index a8fc332..4ca4ca65 100644
87458--- a/net/ipv4/ip_fragment.c
87459+++ b/net/ipv4/ip_fragment.c
87460@@ -319,7 +319,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
87461 return 0;
87462
87463 start = qp->rid;
87464- end = atomic_inc_return(&peer->rid);
87465+ end = atomic_inc_return_unchecked(&peer->rid);
87466 qp->rid = end;
87467
87468 rc = qp->q.fragments && (end - start) > max;
87469@@ -786,12 +786,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
87470
87471 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
87472 {
87473- struct ctl_table *table;
87474+ ctl_table_no_const *table = NULL;
87475 struct ctl_table_header *hdr;
87476
87477- table = ip4_frags_ns_ctl_table;
87478 if (!net_eq(net, &init_net)) {
87479- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
87480+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
87481 if (table == NULL)
87482 goto err_alloc;
87483
87484@@ -802,9 +801,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
87485 /* Don't export sysctls to unprivileged users */
87486 if (net->user_ns != &init_user_ns)
87487 table[0].procname = NULL;
87488- }
87489+ hdr = register_net_sysctl(net, "net/ipv4", table);
87490+ } else
87491+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
87492
87493- hdr = register_net_sysctl(net, "net/ipv4", table);
87494 if (hdr == NULL)
87495 goto err_reg;
87496
87497@@ -812,8 +812,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
87498 return 0;
87499
87500 err_reg:
87501- if (!net_eq(net, &init_net))
87502- kfree(table);
87503+ kfree(table);
87504 err_alloc:
87505 return -ENOMEM;
87506 }
87507diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
87508index a85062b..2958a9b 100644
87509--- a/net/ipv4/ip_gre.c
87510+++ b/net/ipv4/ip_gre.c
87511@@ -124,7 +124,7 @@ static bool log_ecn_error = true;
87512 module_param(log_ecn_error, bool, 0644);
87513 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
87514
87515-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
87516+static struct rtnl_link_ops ipgre_link_ops;
87517 static int ipgre_tunnel_init(struct net_device *dev);
87518 static void ipgre_tunnel_setup(struct net_device *dev);
87519 static int ipgre_tunnel_bind_dev(struct net_device *dev);
87520@@ -1753,7 +1753,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
87521 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
87522 };
87523
87524-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
87525+static struct rtnl_link_ops ipgre_link_ops = {
87526 .kind = "gre",
87527 .maxtype = IFLA_GRE_MAX,
87528 .policy = ipgre_policy,
87529@@ -1766,7 +1766,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
87530 .fill_info = ipgre_fill_info,
87531 };
87532
87533-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
87534+static struct rtnl_link_ops ipgre_tap_ops = {
87535 .kind = "gretap",
87536 .maxtype = IFLA_GRE_MAX,
87537 .policy = ipgre_policy,
87538diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
87539index d9c4f11..02b82dbc 100644
87540--- a/net/ipv4/ip_sockglue.c
87541+++ b/net/ipv4/ip_sockglue.c
87542@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
87543 len = min_t(unsigned int, len, opt->optlen);
87544 if (put_user(len, optlen))
87545 return -EFAULT;
87546- if (copy_to_user(optval, opt->__data, len))
87547+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
87548+ copy_to_user(optval, opt->__data, len))
87549 return -EFAULT;
87550 return 0;
87551 }
87552@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
87553 if (sk->sk_type != SOCK_STREAM)
87554 return -ENOPROTOOPT;
87555
87556- msg.msg_control = optval;
87557+ msg.msg_control = (void __force_kernel *)optval;
87558 msg.msg_controllen = len;
87559 msg.msg_flags = flags;
87560
87561diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
87562index c3a4233..1412161 100644
87563--- a/net/ipv4/ip_vti.c
87564+++ b/net/ipv4/ip_vti.c
87565@@ -47,7 +47,7 @@
87566 #define HASH_SIZE 16
87567 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&(HASH_SIZE-1))
87568
87569-static struct rtnl_link_ops vti_link_ops __read_mostly;
87570+static struct rtnl_link_ops vti_link_ops;
87571
87572 static int vti_net_id __read_mostly;
87573 struct vti_net {
87574@@ -886,7 +886,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
87575 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
87576 };
87577
87578-static struct rtnl_link_ops vti_link_ops __read_mostly = {
87579+static struct rtnl_link_ops vti_link_ops = {
87580 .kind = "vti",
87581 .maxtype = IFLA_VTI_MAX,
87582 .policy = vti_policy,
87583diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c
87584index 9a46dae..5f793a0 100644
87585--- a/net/ipv4/ipcomp.c
87586+++ b/net/ipv4/ipcomp.c
87587@@ -48,7 +48,7 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
87588 return;
87589
87590 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
87591- atomic_inc(&flow_cache_genid);
87592+ atomic_inc_unchecked(&flow_cache_genid);
87593 rt_genid_bump(net);
87594
87595 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_COMP, 0);
87596diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
87597index a2e50ae..e152b7c 100644
87598--- a/net/ipv4/ipconfig.c
87599+++ b/net/ipv4/ipconfig.c
87600@@ -323,7 +323,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
87601
87602 mm_segment_t oldfs = get_fs();
87603 set_fs(get_ds());
87604- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
87605+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
87606 set_fs(oldfs);
87607 return res;
87608 }
87609@@ -334,7 +334,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
87610
87611 mm_segment_t oldfs = get_fs();
87612 set_fs(get_ds());
87613- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
87614+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
87615 set_fs(oldfs);
87616 return res;
87617 }
87618@@ -345,7 +345,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
87619
87620 mm_segment_t oldfs = get_fs();
87621 set_fs(get_ds());
87622- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
87623+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
87624 set_fs(oldfs);
87625 return res;
87626 }
87627diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
87628index 191fc24..1b3b804 100644
87629--- a/net/ipv4/ipip.c
87630+++ b/net/ipv4/ipip.c
87631@@ -138,7 +138,7 @@ struct ipip_net {
87632 static int ipip_tunnel_init(struct net_device *dev);
87633 static void ipip_tunnel_setup(struct net_device *dev);
87634 static void ipip_dev_free(struct net_device *dev);
87635-static struct rtnl_link_ops ipip_link_ops __read_mostly;
87636+static struct rtnl_link_ops ipip_link_ops;
87637
87638 static struct rtnl_link_stats64 *ipip_get_stats64(struct net_device *dev,
87639 struct rtnl_link_stats64 *tot)
87640@@ -972,7 +972,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
87641 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
87642 };
87643
87644-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
87645+static struct rtnl_link_ops ipip_link_ops = {
87646 .kind = "ipip",
87647 .maxtype = IFLA_IPTUN_MAX,
87648 .policy = ipip_policy,
87649diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
87650index 3ea4127..849297b 100644
87651--- a/net/ipv4/netfilter/arp_tables.c
87652+++ b/net/ipv4/netfilter/arp_tables.c
87653@@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
87654 #endif
87655
87656 static int get_info(struct net *net, void __user *user,
87657- const int *len, int compat)
87658+ int len, int compat)
87659 {
87660 char name[XT_TABLE_MAXNAMELEN];
87661 struct xt_table *t;
87662 int ret;
87663
87664- if (*len != sizeof(struct arpt_getinfo)) {
87665- duprintf("length %u != %Zu\n", *len,
87666+ if (len != sizeof(struct arpt_getinfo)) {
87667+ duprintf("length %u != %Zu\n", len,
87668 sizeof(struct arpt_getinfo));
87669 return -EINVAL;
87670 }
87671@@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
87672 info.size = private->size;
87673 strcpy(info.name, name);
87674
87675- if (copy_to_user(user, &info, *len) != 0)
87676+ if (copy_to_user(user, &info, len) != 0)
87677 ret = -EFAULT;
87678 else
87679 ret = 0;
87680@@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
87681
87682 switch (cmd) {
87683 case ARPT_SO_GET_INFO:
87684- ret = get_info(sock_net(sk), user, len, 1);
87685+ ret = get_info(sock_net(sk), user, *len, 1);
87686 break;
87687 case ARPT_SO_GET_ENTRIES:
87688 ret = compat_get_entries(sock_net(sk), user, len);
87689@@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
87690
87691 switch (cmd) {
87692 case ARPT_SO_GET_INFO:
87693- ret = get_info(sock_net(sk), user, len, 0);
87694+ ret = get_info(sock_net(sk), user, *len, 0);
87695 break;
87696
87697 case ARPT_SO_GET_ENTRIES:
87698diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
87699index 17c5e06..1b91206 100644
87700--- a/net/ipv4/netfilter/ip_tables.c
87701+++ b/net/ipv4/netfilter/ip_tables.c
87702@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
87703 #endif
87704
87705 static int get_info(struct net *net, void __user *user,
87706- const int *len, int compat)
87707+ int len, int compat)
87708 {
87709 char name[XT_TABLE_MAXNAMELEN];
87710 struct xt_table *t;
87711 int ret;
87712
87713- if (*len != sizeof(struct ipt_getinfo)) {
87714- duprintf("length %u != %zu\n", *len,
87715+ if (len != sizeof(struct ipt_getinfo)) {
87716+ duprintf("length %u != %zu\n", len,
87717 sizeof(struct ipt_getinfo));
87718 return -EINVAL;
87719 }
87720@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
87721 info.size = private->size;
87722 strcpy(info.name, name);
87723
87724- if (copy_to_user(user, &info, *len) != 0)
87725+ if (copy_to_user(user, &info, len) != 0)
87726 ret = -EFAULT;
87727 else
87728 ret = 0;
87729@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
87730
87731 switch (cmd) {
87732 case IPT_SO_GET_INFO:
87733- ret = get_info(sock_net(sk), user, len, 1);
87734+ ret = get_info(sock_net(sk), user, *len, 1);
87735 break;
87736 case IPT_SO_GET_ENTRIES:
87737 ret = compat_get_entries(sock_net(sk), user, len);
87738@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
87739
87740 switch (cmd) {
87741 case IPT_SO_GET_INFO:
87742- ret = get_info(sock_net(sk), user, len, 0);
87743+ ret = get_info(sock_net(sk), user, *len, 0);
87744 break;
87745
87746 case IPT_SO_GET_ENTRIES:
87747diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
87748index dc454cc..5bb917f 100644
87749--- a/net/ipv4/ping.c
87750+++ b/net/ipv4/ping.c
87751@@ -844,7 +844,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
87752 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
87753 0, sock_i_ino(sp),
87754 atomic_read(&sp->sk_refcnt), sp,
87755- atomic_read(&sp->sk_drops), len);
87756+ atomic_read_unchecked(&sp->sk_drops), len);
87757 }
87758
87759 static int ping_seq_show(struct seq_file *seq, void *v)
87760diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
87761index 6f08991..55867ad 100644
87762--- a/net/ipv4/raw.c
87763+++ b/net/ipv4/raw.c
87764@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
87765 int raw_rcv(struct sock *sk, struct sk_buff *skb)
87766 {
87767 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
87768- atomic_inc(&sk->sk_drops);
87769+ atomic_inc_unchecked(&sk->sk_drops);
87770 kfree_skb(skb);
87771 return NET_RX_DROP;
87772 }
87773@@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
87774
87775 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
87776 {
87777+ struct icmp_filter filter;
87778+
87779 if (optlen > sizeof(struct icmp_filter))
87780 optlen = sizeof(struct icmp_filter);
87781- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
87782+ if (copy_from_user(&filter, optval, optlen))
87783 return -EFAULT;
87784+ raw_sk(sk)->filter = filter;
87785 return 0;
87786 }
87787
87788 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
87789 {
87790 int len, ret = -EFAULT;
87791+ struct icmp_filter filter;
87792
87793 if (get_user(len, optlen))
87794 goto out;
87795@@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
87796 if (len > sizeof(struct icmp_filter))
87797 len = sizeof(struct icmp_filter);
87798 ret = -EFAULT;
87799- if (put_user(len, optlen) ||
87800- copy_to_user(optval, &raw_sk(sk)->filter, len))
87801+ filter = raw_sk(sk)->filter;
87802+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
87803 goto out;
87804 ret = 0;
87805 out: return ret;
87806@@ -998,7 +1002,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
87807 0, 0L, 0,
87808 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
87809 0, sock_i_ino(sp),
87810- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
87811+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
87812 }
87813
87814 static int raw_seq_show(struct seq_file *seq, void *v)
87815diff --git a/net/ipv4/route.c b/net/ipv4/route.c
87816index a0fcc47..32e2c89 100644
87817--- a/net/ipv4/route.c
87818+++ b/net/ipv4/route.c
87819@@ -2552,34 +2552,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
87820 .maxlen = sizeof(int),
87821 .mode = 0200,
87822 .proc_handler = ipv4_sysctl_rtcache_flush,
87823+ .extra1 = &init_net,
87824 },
87825 { },
87826 };
87827
87828 static __net_init int sysctl_route_net_init(struct net *net)
87829 {
87830- struct ctl_table *tbl;
87831+ ctl_table_no_const *tbl = NULL;
87832
87833- tbl = ipv4_route_flush_table;
87834 if (!net_eq(net, &init_net)) {
87835- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
87836+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
87837 if (tbl == NULL)
87838 goto err_dup;
87839
87840 /* Don't export sysctls to unprivileged users */
87841 if (net->user_ns != &init_user_ns)
87842 tbl[0].procname = NULL;
87843- }
87844- tbl[0].extra1 = net;
87845+ tbl[0].extra1 = net;
87846+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
87847+ } else
87848+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
87849
87850- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
87851 if (net->ipv4.route_hdr == NULL)
87852 goto err_reg;
87853 return 0;
87854
87855 err_reg:
87856- if (tbl != ipv4_route_flush_table)
87857- kfree(tbl);
87858+ kfree(tbl);
87859 err_dup:
87860 return -ENOMEM;
87861 }
87862@@ -2602,7 +2602,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
87863
87864 static __net_init int rt_genid_init(struct net *net)
87865 {
87866- atomic_set(&net->rt_genid, 0);
87867+ atomic_set_unchecked(&net->rt_genid, 0);
87868 get_random_bytes(&net->ipv4.dev_addr_genid,
87869 sizeof(net->ipv4.dev_addr_genid));
87870 return 0;
87871diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c
87872index b236ef04..f962f19 100644
87873--- a/net/ipv4/syncookies.c
87874+++ b/net/ipv4/syncookies.c
87875@@ -348,8 +348,8 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
87876 * hasn't changed since we received the original syn, but I see
87877 * no easy way to do this.
87878 */
87879- flowi4_init_output(&fl4, 0, sk->sk_mark, RT_CONN_FLAGS(sk),
87880- RT_SCOPE_UNIVERSE, IPPROTO_TCP,
87881+ flowi4_init_output(&fl4, sk->sk_bound_dev_if, sk->sk_mark,
87882+ RT_CONN_FLAGS(sk), RT_SCOPE_UNIVERSE, IPPROTO_TCP,
87883 inet_sk_flowi_flags(sk),
87884 (opt && opt->srr) ? opt->faddr : ireq->rmt_addr,
87885 ireq->loc_addr, th->source, th->dest);
87886diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
87887index d84400b..62e066e 100644
87888--- a/net/ipv4/sysctl_net_ipv4.c
87889+++ b/net/ipv4/sysctl_net_ipv4.c
87890@@ -54,7 +54,7 @@ static int ipv4_local_port_range(ctl_table *table, int write,
87891 {
87892 int ret;
87893 int range[2];
87894- ctl_table tmp = {
87895+ ctl_table_no_const tmp = {
87896 .data = &range,
87897 .maxlen = sizeof(range),
87898 .mode = table->mode,
87899@@ -107,7 +107,7 @@ static int ipv4_ping_group_range(ctl_table *table, int write,
87900 int ret;
87901 gid_t urange[2];
87902 kgid_t low, high;
87903- ctl_table tmp = {
87904+ ctl_table_no_const tmp = {
87905 .data = &urange,
87906 .maxlen = sizeof(urange),
87907 .mode = table->mode,
87908@@ -138,7 +138,7 @@ static int proc_tcp_congestion_control(ctl_table *ctl, int write,
87909 void __user *buffer, size_t *lenp, loff_t *ppos)
87910 {
87911 char val[TCP_CA_NAME_MAX];
87912- ctl_table tbl = {
87913+ ctl_table_no_const tbl = {
87914 .data = val,
87915 .maxlen = TCP_CA_NAME_MAX,
87916 };
87917@@ -157,7 +157,7 @@ static int proc_tcp_available_congestion_control(ctl_table *ctl,
87918 void __user *buffer, size_t *lenp,
87919 loff_t *ppos)
87920 {
87921- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
87922+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
87923 int ret;
87924
87925 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
87926@@ -174,7 +174,7 @@ static int proc_allowed_congestion_control(ctl_table *ctl,
87927 void __user *buffer, size_t *lenp,
87928 loff_t *ppos)
87929 {
87930- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
87931+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
87932 int ret;
87933
87934 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
87935@@ -200,15 +200,17 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
87936 struct mem_cgroup *memcg;
87937 #endif
87938
87939- ctl_table tmp = {
87940+ ctl_table_no_const tmp = {
87941 .data = &vec,
87942 .maxlen = sizeof(vec),
87943 .mode = ctl->mode,
87944 };
87945
87946 if (!write) {
87947- ctl->data = &net->ipv4.sysctl_tcp_mem;
87948- return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
87949+ ctl_table_no_const tcp_mem = *ctl;
87950+
87951+ tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
87952+ return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
87953 }
87954
87955 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
87956@@ -235,7 +237,7 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
87957 int proc_tcp_fastopen_key(ctl_table *ctl, int write, void __user *buffer,
87958 size_t *lenp, loff_t *ppos)
87959 {
87960- ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
87961+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
87962 struct tcp_fastopen_context *ctxt;
87963 int ret;
87964 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
87965@@ -476,7 +478,7 @@ static struct ctl_table ipv4_table[] = {
87966 },
87967 {
87968 .procname = "ip_local_reserved_ports",
87969- .data = NULL, /* initialized in sysctl_ipv4_init */
87970+ .data = sysctl_local_reserved_ports,
87971 .maxlen = 65536,
87972 .mode = 0644,
87973 .proc_handler = proc_do_large_bitmap,
87974@@ -860,11 +862,10 @@ static struct ctl_table ipv4_net_table[] = {
87975
87976 static __net_init int ipv4_sysctl_init_net(struct net *net)
87977 {
87978- struct ctl_table *table;
87979+ ctl_table_no_const *table = NULL;
87980
87981- table = ipv4_net_table;
87982 if (!net_eq(net, &init_net)) {
87983- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
87984+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
87985 if (table == NULL)
87986 goto err_alloc;
87987
87988@@ -897,15 +898,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
87989
87990 tcp_init_mem(net);
87991
87992- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
87993+ if (!net_eq(net, &init_net))
87994+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
87995+ else
87996+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
87997 if (net->ipv4.ipv4_hdr == NULL)
87998 goto err_reg;
87999
88000 return 0;
88001
88002 err_reg:
88003- if (!net_eq(net, &init_net))
88004- kfree(table);
88005+ kfree(table);
88006 err_alloc:
88007 return -ENOMEM;
88008 }
88009@@ -927,16 +930,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
88010 static __init int sysctl_ipv4_init(void)
88011 {
88012 struct ctl_table_header *hdr;
88013- struct ctl_table *i;
88014-
88015- for (i = ipv4_table; i->procname; i++) {
88016- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
88017- i->data = sysctl_local_reserved_ports;
88018- break;
88019- }
88020- }
88021- if (!i->procname)
88022- return -EINVAL;
88023
88024 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
88025 if (hdr == NULL)
88026diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
88027index 9841a71..ef60409 100644
88028--- a/net/ipv4/tcp_input.c
88029+++ b/net/ipv4/tcp_input.c
88030@@ -4730,7 +4730,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
88031 * simplifies code)
88032 */
88033 static void
88034-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
88035+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
88036 struct sk_buff *head, struct sk_buff *tail,
88037 u32 start, u32 end)
88038 {
88039@@ -5847,6 +5847,7 @@ discard:
88040 tcp_paws_reject(&tp->rx_opt, 0))
88041 goto discard_and_undo;
88042
88043+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
88044 if (th->syn) {
88045 /* We see SYN without ACK. It is attempt of
88046 * simultaneous connect with crossed SYNs.
88047@@ -5897,6 +5898,7 @@ discard:
88048 goto discard;
88049 #endif
88050 }
88051+#endif
88052 /* "fifth, if neither of the SYN or RST bits is set then
88053 * drop the segment and return."
88054 */
88055@@ -5941,7 +5943,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
88056 goto discard;
88057
88058 if (th->syn) {
88059- if (th->fin)
88060+ if (th->fin || th->urg || th->psh)
88061 goto discard;
88062 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
88063 return 1;
88064diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
88065index d9130a9..00328ff 100644
88066--- a/net/ipv4/tcp_ipv4.c
88067+++ b/net/ipv4/tcp_ipv4.c
88068@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
88069 EXPORT_SYMBOL(sysctl_tcp_low_latency);
88070
88071
88072+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88073+extern int grsec_enable_blackhole;
88074+#endif
88075+
88076 #ifdef CONFIG_TCP_MD5SIG
88077 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
88078 __be32 daddr, __be32 saddr, const struct tcphdr *th);
88079@@ -1895,6 +1899,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
88080 return 0;
88081
88082 reset:
88083+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88084+ if (!grsec_enable_blackhole)
88085+#endif
88086 tcp_v4_send_reset(rsk, skb);
88087 discard:
88088 kfree_skb(skb);
88089@@ -1994,12 +2001,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
88090 TCP_SKB_CB(skb)->sacked = 0;
88091
88092 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
88093- if (!sk)
88094+ if (!sk) {
88095+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88096+ ret = 1;
88097+#endif
88098 goto no_tcp_socket;
88099-
88100+ }
88101 process:
88102- if (sk->sk_state == TCP_TIME_WAIT)
88103+ if (sk->sk_state == TCP_TIME_WAIT) {
88104+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88105+ ret = 2;
88106+#endif
88107 goto do_time_wait;
88108+ }
88109
88110 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
88111 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
88112@@ -2050,6 +2064,10 @@ no_tcp_socket:
88113 bad_packet:
88114 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
88115 } else {
88116+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88117+ if (!grsec_enable_blackhole || (ret == 1 &&
88118+ (skb->dev->flags & IFF_LOOPBACK)))
88119+#endif
88120 tcp_v4_send_reset(NULL, skb);
88121 }
88122
88123diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
88124index f35f2df..ccb5ca6 100644
88125--- a/net/ipv4/tcp_minisocks.c
88126+++ b/net/ipv4/tcp_minisocks.c
88127@@ -27,6 +27,10 @@
88128 #include <net/inet_common.h>
88129 #include <net/xfrm.h>
88130
88131+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88132+extern int grsec_enable_blackhole;
88133+#endif
88134+
88135 int sysctl_tcp_syncookies __read_mostly = 1;
88136 EXPORT_SYMBOL(sysctl_tcp_syncookies);
88137
88138@@ -742,7 +746,10 @@ embryonic_reset:
88139 * avoid becoming vulnerable to outside attack aiming at
88140 * resetting legit local connections.
88141 */
88142- req->rsk_ops->send_reset(sk, skb);
88143+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88144+ if (!grsec_enable_blackhole)
88145+#endif
88146+ req->rsk_ops->send_reset(sk, skb);
88147 } else if (fastopen) { /* received a valid RST pkt */
88148 reqsk_fastopen_remove(sk, req, true);
88149 tcp_reset(sk);
88150diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
88151index 17d659e..a9f50ee 100644
88152--- a/net/ipv4/tcp_output.c
88153+++ b/net/ipv4/tcp_output.c
88154@@ -2388,8 +2388,12 @@ int __tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb)
88155 */
88156 TCP_SKB_CB(skb)->when = tcp_time_stamp;
88157
88158- /* make sure skb->data is aligned on arches that require it */
88159- if (unlikely(NET_IP_ALIGN && ((unsigned long)skb->data & 3))) {
88160+ /* make sure skb->data is aligned on arches that require it
88161+ * and check if ack-trimming & collapsing extended the headroom
88162+ * beyond what csum_start can cover.
88163+ */
88164+ if (unlikely((NET_IP_ALIGN && ((unsigned long)skb->data & 3)) ||
88165+ skb_headroom(skb) >= 0xFFFF)) {
88166 struct sk_buff *nskb = __pskb_copy(skb, MAX_TCP_HEADER,
88167 GFP_ATOMIC);
88168 return nskb ? tcp_transmit_skb(sk, nskb, 0, GFP_ATOMIC) :
88169diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
88170index 4526fe6..1a34e43 100644
88171--- a/net/ipv4/tcp_probe.c
88172+++ b/net/ipv4/tcp_probe.c
88173@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
88174 if (cnt + width >= len)
88175 break;
88176
88177- if (copy_to_user(buf + cnt, tbuf, width))
88178+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
88179 return -EFAULT;
88180 cnt += width;
88181 }
88182diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
88183index b78aac3..e18230b 100644
88184--- a/net/ipv4/tcp_timer.c
88185+++ b/net/ipv4/tcp_timer.c
88186@@ -22,6 +22,10 @@
88187 #include <linux/gfp.h>
88188 #include <net/tcp.h>
88189
88190+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88191+extern int grsec_lastack_retries;
88192+#endif
88193+
88194 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
88195 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
88196 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
88197@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
88198 }
88199 }
88200
88201+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88202+ if ((sk->sk_state == TCP_LAST_ACK) &&
88203+ (grsec_lastack_retries > 0) &&
88204+ (grsec_lastack_retries < retry_until))
88205+ retry_until = grsec_lastack_retries;
88206+#endif
88207+
88208 if (retransmits_timed_out(sk, retry_until,
88209 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
88210 /* Has it gone just too far? */
88211diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
88212index 1f4d405..3524677 100644
88213--- a/net/ipv4/udp.c
88214+++ b/net/ipv4/udp.c
88215@@ -87,6 +87,7 @@
88216 #include <linux/types.h>
88217 #include <linux/fcntl.h>
88218 #include <linux/module.h>
88219+#include <linux/security.h>
88220 #include <linux/socket.h>
88221 #include <linux/sockios.h>
88222 #include <linux/igmp.h>
88223@@ -111,6 +112,10 @@
88224 #include <trace/events/skb.h>
88225 #include "udp_impl.h"
88226
88227+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88228+extern int grsec_enable_blackhole;
88229+#endif
88230+
88231 struct udp_table udp_table __read_mostly;
88232 EXPORT_SYMBOL(udp_table);
88233
88234@@ -569,6 +574,9 @@ found:
88235 return s;
88236 }
88237
88238+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
88239+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
88240+
88241 /*
88242 * This routine is called by the ICMP module when it gets some
88243 * sort of error condition. If err < 0 then the socket should
88244@@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
88245 dport = usin->sin_port;
88246 if (dport == 0)
88247 return -EINVAL;
88248+
88249+ err = gr_search_udp_sendmsg(sk, usin);
88250+ if (err)
88251+ return err;
88252 } else {
88253 if (sk->sk_state != TCP_ESTABLISHED)
88254 return -EDESTADDRREQ;
88255+
88256+ err = gr_search_udp_sendmsg(sk, NULL);
88257+ if (err)
88258+ return err;
88259+
88260 daddr = inet->inet_daddr;
88261 dport = inet->inet_dport;
88262 /* Open fast path for connected socket.
88263@@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
88264 udp_lib_checksum_complete(skb)) {
88265 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
88266 IS_UDPLITE(sk));
88267- atomic_inc(&sk->sk_drops);
88268+ atomic_inc_unchecked(&sk->sk_drops);
88269 __skb_unlink(skb, rcvq);
88270 __skb_queue_tail(&list_kill, skb);
88271 }
88272@@ -1194,6 +1211,10 @@ try_again:
88273 if (!skb)
88274 goto out;
88275
88276+ err = gr_search_udp_recvmsg(sk, skb);
88277+ if (err)
88278+ goto out_free;
88279+
88280 ulen = skb->len - sizeof(struct udphdr);
88281 copied = len;
88282 if (copied > ulen)
88283@@ -1227,7 +1248,7 @@ try_again:
88284 if (unlikely(err)) {
88285 trace_kfree_skb(skb, udp_recvmsg);
88286 if (!peeked) {
88287- atomic_inc(&sk->sk_drops);
88288+ atomic_inc_unchecked(&sk->sk_drops);
88289 UDP_INC_STATS_USER(sock_net(sk),
88290 UDP_MIB_INERRORS, is_udplite);
88291 }
88292@@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
88293
88294 drop:
88295 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
88296- atomic_inc(&sk->sk_drops);
88297+ atomic_inc_unchecked(&sk->sk_drops);
88298 kfree_skb(skb);
88299 return -1;
88300 }
88301@@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
88302 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
88303
88304 if (!skb1) {
88305- atomic_inc(&sk->sk_drops);
88306+ atomic_inc_unchecked(&sk->sk_drops);
88307 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
88308 IS_UDPLITE(sk));
88309 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
88310@@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
88311 goto csum_error;
88312
88313 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
88314+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88315+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
88316+#endif
88317 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
88318
88319 /*
88320@@ -2120,7 +2144,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
88321 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
88322 0, sock_i_ino(sp),
88323 atomic_read(&sp->sk_refcnt), sp,
88324- atomic_read(&sp->sk_drops), len);
88325+ atomic_read_unchecked(&sp->sk_drops), len);
88326 }
88327
88328 int udp4_seq_show(struct seq_file *seq, void *v)
88329diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
88330index a36d17e..96d099f 100644
88331--- a/net/ipv6/addrconf.c
88332+++ b/net/ipv6/addrconf.c
88333@@ -2272,7 +2272,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
88334 p.iph.ihl = 5;
88335 p.iph.protocol = IPPROTO_IPV6;
88336 p.iph.ttl = 64;
88337- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
88338+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
88339
88340 if (ops->ndo_do_ioctl) {
88341 mm_segment_t oldfs = get_fs();
88342@@ -4388,7 +4388,7 @@ int addrconf_sysctl_forward(ctl_table *ctl, int write,
88343 int *valp = ctl->data;
88344 int val = *valp;
88345 loff_t pos = *ppos;
88346- ctl_table lctl;
88347+ ctl_table_no_const lctl;
88348 int ret;
88349
88350 /*
88351@@ -4470,7 +4470,7 @@ int addrconf_sysctl_disable(ctl_table *ctl, int write,
88352 int *valp = ctl->data;
88353 int val = *valp;
88354 loff_t pos = *ppos;
88355- ctl_table lctl;
88356+ ctl_table_no_const lctl;
88357 int ret;
88358
88359 /*
88360diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
88361index fff5bdd..15194fb 100644
88362--- a/net/ipv6/icmp.c
88363+++ b/net/ipv6/icmp.c
88364@@ -973,7 +973,7 @@ ctl_table ipv6_icmp_table_template[] = {
88365
88366 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
88367 {
88368- struct ctl_table *table;
88369+ ctl_table_no_const *table;
88370
88371 table = kmemdup(ipv6_icmp_table_template,
88372 sizeof(ipv6_icmp_table_template),
88373diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
88374index 131dd09..f7ed64f 100644
88375--- a/net/ipv6/ip6_gre.c
88376+++ b/net/ipv6/ip6_gre.c
88377@@ -73,7 +73,7 @@ struct ip6gre_net {
88378 struct net_device *fb_tunnel_dev;
88379 };
88380
88381-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
88382+static struct rtnl_link_ops ip6gre_link_ops;
88383 static int ip6gre_tunnel_init(struct net_device *dev);
88384 static void ip6gre_tunnel_setup(struct net_device *dev);
88385 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
88386@@ -1337,7 +1337,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
88387 }
88388
88389
88390-static struct inet6_protocol ip6gre_protocol __read_mostly = {
88391+static struct inet6_protocol ip6gre_protocol = {
88392 .handler = ip6gre_rcv,
88393 .err_handler = ip6gre_err,
88394 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
88395@@ -1671,7 +1671,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
88396 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
88397 };
88398
88399-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
88400+static struct rtnl_link_ops ip6gre_link_ops = {
88401 .kind = "ip6gre",
88402 .maxtype = IFLA_GRE_MAX,
88403 .policy = ip6gre_policy,
88404@@ -1684,7 +1684,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
88405 .fill_info = ip6gre_fill_info,
88406 };
88407
88408-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
88409+static struct rtnl_link_ops ip6gre_tap_ops = {
88410 .kind = "ip6gretap",
88411 .maxtype = IFLA_GRE_MAX,
88412 .policy = ip6gre_policy,
88413diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
88414index a14f28b..b4b8956 100644
88415--- a/net/ipv6/ip6_tunnel.c
88416+++ b/net/ipv6/ip6_tunnel.c
88417@@ -87,7 +87,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
88418
88419 static int ip6_tnl_dev_init(struct net_device *dev);
88420 static void ip6_tnl_dev_setup(struct net_device *dev);
88421-static struct rtnl_link_ops ip6_link_ops __read_mostly;
88422+static struct rtnl_link_ops ip6_link_ops;
88423
88424 static int ip6_tnl_net_id __read_mostly;
88425 struct ip6_tnl_net {
88426@@ -1686,7 +1686,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
88427 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
88428 };
88429
88430-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
88431+static struct rtnl_link_ops ip6_link_ops = {
88432 .kind = "ip6tnl",
88433 .maxtype = IFLA_IPTUN_MAX,
88434 .policy = ip6_tnl_policy,
88435diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
88436index d1e2e8e..51c19ae 100644
88437--- a/net/ipv6/ipv6_sockglue.c
88438+++ b/net/ipv6/ipv6_sockglue.c
88439@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
88440 if (sk->sk_type != SOCK_STREAM)
88441 return -ENOPROTOOPT;
88442
88443- msg.msg_control = optval;
88444+ msg.msg_control = (void __force_kernel *)optval;
88445 msg.msg_controllen = len;
88446 msg.msg_flags = flags;
88447
88448diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
88449index 125a90d..2a11f36 100644
88450--- a/net/ipv6/netfilter/ip6_tables.c
88451+++ b/net/ipv6/netfilter/ip6_tables.c
88452@@ -1076,14 +1076,14 @@ static int compat_table_info(const struct xt_table_info *info,
88453 #endif
88454
88455 static int get_info(struct net *net, void __user *user,
88456- const int *len, int compat)
88457+ int len, int compat)
88458 {
88459 char name[XT_TABLE_MAXNAMELEN];
88460 struct xt_table *t;
88461 int ret;
88462
88463- if (*len != sizeof(struct ip6t_getinfo)) {
88464- duprintf("length %u != %zu\n", *len,
88465+ if (len != sizeof(struct ip6t_getinfo)) {
88466+ duprintf("length %u != %zu\n", len,
88467 sizeof(struct ip6t_getinfo));
88468 return -EINVAL;
88469 }
88470@@ -1120,7 +1120,7 @@ static int get_info(struct net *net, void __user *user,
88471 info.size = private->size;
88472 strcpy(info.name, name);
88473
88474- if (copy_to_user(user, &info, *len) != 0)
88475+ if (copy_to_user(user, &info, len) != 0)
88476 ret = -EFAULT;
88477 else
88478 ret = 0;
88479@@ -1974,7 +1974,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
88480
88481 switch (cmd) {
88482 case IP6T_SO_GET_INFO:
88483- ret = get_info(sock_net(sk), user, len, 1);
88484+ ret = get_info(sock_net(sk), user, *len, 1);
88485 break;
88486 case IP6T_SO_GET_ENTRIES:
88487 ret = compat_get_entries(sock_net(sk), user, len);
88488@@ -2021,7 +2021,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
88489
88490 switch (cmd) {
88491 case IP6T_SO_GET_INFO:
88492- ret = get_info(sock_net(sk), user, len, 0);
88493+ ret = get_info(sock_net(sk), user, *len, 0);
88494 break;
88495
88496 case IP6T_SO_GET_ENTRIES:
88497diff --git a/net/ipv6/netfilter/ip6t_NPT.c b/net/ipv6/netfilter/ip6t_NPT.c
88498index 83acc14..0ea43c7 100644
88499--- a/net/ipv6/netfilter/ip6t_NPT.c
88500+++ b/net/ipv6/netfilter/ip6t_NPT.c
88501@@ -57,7 +57,7 @@ static bool ip6t_npt_map_pfx(const struct ip6t_npt_tginfo *npt,
88502 if (pfx_len - i >= 32)
88503 mask = 0;
88504 else
88505- mask = htonl(~((1 << (pfx_len - i)) - 1));
88506+ mask = htonl((1 << (i - pfx_len + 32)) - 1);
88507
88508 idx = i / 32;
88509 addr->s6_addr32[idx] &= mask;
88510diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
88511index 2f3a018..8bca195 100644
88512--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
88513+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
88514@@ -89,12 +89,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
88515
88516 static int nf_ct_frag6_sysctl_register(struct net *net)
88517 {
88518- struct ctl_table *table;
88519+ ctl_table_no_const *table = NULL;
88520 struct ctl_table_header *hdr;
88521
88522- table = nf_ct_frag6_sysctl_table;
88523 if (!net_eq(net, &init_net)) {
88524- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
88525+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
88526 GFP_KERNEL);
88527 if (table == NULL)
88528 goto err_alloc;
88529@@ -102,9 +101,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
88530 table[0].data = &net->ipv6.frags.high_thresh;
88531 table[1].data = &net->ipv6.frags.low_thresh;
88532 table[2].data = &net->ipv6.frags.timeout;
88533- }
88534-
88535- hdr = register_net_sysctl(net, "net/netfilter", table);
88536+ hdr = register_net_sysctl(net, "net/netfilter", table);
88537+ } else
88538+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
88539 if (hdr == NULL)
88540 goto err_reg;
88541
88542@@ -112,8 +111,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
88543 return 0;
88544
88545 err_reg:
88546- if (!net_eq(net, &init_net))
88547- kfree(table);
88548+ kfree(table);
88549 err_alloc:
88550 return -ENOMEM;
88551 }
88552diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
88553index 70fa814..d70c28c 100644
88554--- a/net/ipv6/raw.c
88555+++ b/net/ipv6/raw.c
88556@@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
88557 {
88558 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
88559 skb_checksum_complete(skb)) {
88560- atomic_inc(&sk->sk_drops);
88561+ atomic_inc_unchecked(&sk->sk_drops);
88562 kfree_skb(skb);
88563 return NET_RX_DROP;
88564 }
88565@@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
88566 struct raw6_sock *rp = raw6_sk(sk);
88567
88568 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
88569- atomic_inc(&sk->sk_drops);
88570+ atomic_inc_unchecked(&sk->sk_drops);
88571 kfree_skb(skb);
88572 return NET_RX_DROP;
88573 }
88574@@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
88575
88576 if (inet->hdrincl) {
88577 if (skb_checksum_complete(skb)) {
88578- atomic_inc(&sk->sk_drops);
88579+ atomic_inc_unchecked(&sk->sk_drops);
88580 kfree_skb(skb);
88581 return NET_RX_DROP;
88582 }
88583@@ -604,7 +604,7 @@ out:
88584 return err;
88585 }
88586
88587-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
88588+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
88589 struct flowi6 *fl6, struct dst_entry **dstp,
88590 unsigned int flags)
88591 {
88592@@ -916,12 +916,15 @@ do_confirm:
88593 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
88594 char __user *optval, int optlen)
88595 {
88596+ struct icmp6_filter filter;
88597+
88598 switch (optname) {
88599 case ICMPV6_FILTER:
88600 if (optlen > sizeof(struct icmp6_filter))
88601 optlen = sizeof(struct icmp6_filter);
88602- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
88603+ if (copy_from_user(&filter, optval, optlen))
88604 return -EFAULT;
88605+ raw6_sk(sk)->filter = filter;
88606 return 0;
88607 default:
88608 return -ENOPROTOOPT;
88609@@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
88610 char __user *optval, int __user *optlen)
88611 {
88612 int len;
88613+ struct icmp6_filter filter;
88614
88615 switch (optname) {
88616 case ICMPV6_FILTER:
88617@@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
88618 len = sizeof(struct icmp6_filter);
88619 if (put_user(len, optlen))
88620 return -EFAULT;
88621- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
88622+ filter = raw6_sk(sk)->filter;
88623+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
88624 return -EFAULT;
88625 return 0;
88626 default:
88627@@ -1253,7 +1258,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
88628 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
88629 0,
88630 sock_i_ino(sp),
88631- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
88632+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
88633 }
88634
88635 static int raw6_seq_show(struct seq_file *seq, void *v)
88636diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
88637index d9ba8a2..f3f9e14 100644
88638--- a/net/ipv6/reassembly.c
88639+++ b/net/ipv6/reassembly.c
88640@@ -608,12 +608,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
88641
88642 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
88643 {
88644- struct ctl_table *table;
88645+ ctl_table_no_const *table = NULL;
88646 struct ctl_table_header *hdr;
88647
88648- table = ip6_frags_ns_ctl_table;
88649 if (!net_eq(net, &init_net)) {
88650- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
88651+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
88652 if (table == NULL)
88653 goto err_alloc;
88654
88655@@ -624,9 +623,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
88656 /* Don't export sysctls to unprivileged users */
88657 if (net->user_ns != &init_user_ns)
88658 table[0].procname = NULL;
88659- }
88660+ hdr = register_net_sysctl(net, "net/ipv6", table);
88661+ } else
88662+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
88663
88664- hdr = register_net_sysctl(net, "net/ipv6", table);
88665 if (hdr == NULL)
88666 goto err_reg;
88667
88668@@ -634,8 +634,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
88669 return 0;
88670
88671 err_reg:
88672- if (!net_eq(net, &init_net))
88673- kfree(table);
88674+ kfree(table);
88675 err_alloc:
88676 return -ENOMEM;
88677 }
88678diff --git a/net/ipv6/route.c b/net/ipv6/route.c
88679index 5845613..3af8fc7 100644
88680--- a/net/ipv6/route.c
88681+++ b/net/ipv6/route.c
88682@@ -2966,7 +2966,7 @@ ctl_table ipv6_route_table_template[] = {
88683
88684 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
88685 {
88686- struct ctl_table *table;
88687+ ctl_table_no_const *table;
88688
88689 table = kmemdup(ipv6_route_table_template,
88690 sizeof(ipv6_route_table_template),
88691diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
88692index cfba99b..20ca511 100644
88693--- a/net/ipv6/sit.c
88694+++ b/net/ipv6/sit.c
88695@@ -72,7 +72,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
88696 static int ipip6_tunnel_init(struct net_device *dev);
88697 static void ipip6_tunnel_setup(struct net_device *dev);
88698 static void ipip6_dev_free(struct net_device *dev);
88699-static struct rtnl_link_ops sit_link_ops __read_mostly;
88700+static struct rtnl_link_ops sit_link_ops;
88701
88702 static int sit_net_id __read_mostly;
88703 struct sit_net {
88704@@ -1463,7 +1463,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
88705 #endif
88706 };
88707
88708-static struct rtnl_link_ops sit_link_ops __read_mostly = {
88709+static struct rtnl_link_ops sit_link_ops = {
88710 .kind = "sit",
88711 .maxtype = IFLA_IPTUN_MAX,
88712 .policy = ipip6_policy,
88713diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
88714index e85c48b..b8268d3 100644
88715--- a/net/ipv6/sysctl_net_ipv6.c
88716+++ b/net/ipv6/sysctl_net_ipv6.c
88717@@ -40,7 +40,7 @@ static ctl_table ipv6_rotable[] = {
88718
88719 static int __net_init ipv6_sysctl_net_init(struct net *net)
88720 {
88721- struct ctl_table *ipv6_table;
88722+ ctl_table_no_const *ipv6_table;
88723 struct ctl_table *ipv6_route_table;
88724 struct ctl_table *ipv6_icmp_table;
88725 int err;
88726diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
88727index 8d19346..f122ba5 100644
88728--- a/net/ipv6/tcp_ipv6.c
88729+++ b/net/ipv6/tcp_ipv6.c
88730@@ -103,6 +103,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
88731 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
88732 }
88733
88734+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88735+extern int grsec_enable_blackhole;
88736+#endif
88737+
88738 static void tcp_v6_hash(struct sock *sk)
88739 {
88740 if (sk->sk_state != TCP_CLOSE) {
88741@@ -386,6 +390,7 @@ static void tcp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
88742
88743 if (dst)
88744 dst->ops->redirect(dst, sk, skb);
88745+ goto out;
88746 }
88747
88748 if (type == ICMPV6_PKT_TOOBIG) {
88749@@ -1440,6 +1445,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
88750 return 0;
88751
88752 reset:
88753+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88754+ if (!grsec_enable_blackhole)
88755+#endif
88756 tcp_v6_send_reset(sk, skb);
88757 discard:
88758 if (opt_skb)
88759@@ -1521,12 +1529,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
88760 TCP_SKB_CB(skb)->sacked = 0;
88761
88762 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
88763- if (!sk)
88764+ if (!sk) {
88765+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88766+ ret = 1;
88767+#endif
88768 goto no_tcp_socket;
88769+ }
88770
88771 process:
88772- if (sk->sk_state == TCP_TIME_WAIT)
88773+ if (sk->sk_state == TCP_TIME_WAIT) {
88774+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88775+ ret = 2;
88776+#endif
88777 goto do_time_wait;
88778+ }
88779
88780 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
88781 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
88782@@ -1575,6 +1591,10 @@ no_tcp_socket:
88783 bad_packet:
88784 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
88785 } else {
88786+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88787+ if (!grsec_enable_blackhole || (ret == 1 &&
88788+ (skb->dev->flags & IFF_LOOPBACK)))
88789+#endif
88790 tcp_v6_send_reset(NULL, skb);
88791 }
88792
88793diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
88794index fb08329..2d6919e 100644
88795--- a/net/ipv6/udp.c
88796+++ b/net/ipv6/udp.c
88797@@ -51,6 +51,10 @@
88798 #include <trace/events/skb.h>
88799 #include "udp_impl.h"
88800
88801+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88802+extern int grsec_enable_blackhole;
88803+#endif
88804+
88805 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
88806 {
88807 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
88808@@ -395,7 +399,7 @@ try_again:
88809 if (unlikely(err)) {
88810 trace_kfree_skb(skb, udpv6_recvmsg);
88811 if (!peeked) {
88812- atomic_inc(&sk->sk_drops);
88813+ atomic_inc_unchecked(&sk->sk_drops);
88814 if (is_udp4)
88815 UDP_INC_STATS_USER(sock_net(sk),
88816 UDP_MIB_INERRORS,
88817@@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
88818 return rc;
88819 drop:
88820 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
88821- atomic_inc(&sk->sk_drops);
88822+ atomic_inc_unchecked(&sk->sk_drops);
88823 kfree_skb(skb);
88824 return -1;
88825 }
88826@@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
88827 if (likely(skb1 == NULL))
88828 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
88829 if (!skb1) {
88830- atomic_inc(&sk->sk_drops);
88831+ atomic_inc_unchecked(&sk->sk_drops);
88832 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
88833 IS_UDPLITE(sk));
88834 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
88835@@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
88836 goto discard;
88837
88838 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
88839+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88840+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
88841+#endif
88842 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
88843
88844 kfree_skb(skb);
88845@@ -1379,7 +1386,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
88846 0,
88847 sock_i_ino(sp),
88848 atomic_read(&sp->sk_refcnt), sp,
88849- atomic_read(&sp->sk_drops));
88850+ atomic_read_unchecked(&sp->sk_drops));
88851 }
88852
88853 int udp6_seq_show(struct seq_file *seq, void *v)
88854diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
88855index a68c88c..d55b0c5 100644
88856--- a/net/irda/ircomm/ircomm_tty.c
88857+++ b/net/irda/ircomm/ircomm_tty.c
88858@@ -312,12 +312,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
88859 add_wait_queue(&port->open_wait, &wait);
88860
88861 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
88862- __FILE__, __LINE__, tty->driver->name, port->count);
88863+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
88864
88865 spin_lock_irqsave(&port->lock, flags);
88866 if (!tty_hung_up_p(filp)) {
88867 extra_count = 1;
88868- port->count--;
88869+ atomic_dec(&port->count);
88870 }
88871 spin_unlock_irqrestore(&port->lock, flags);
88872 port->blocked_open++;
88873@@ -353,7 +353,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
88874 }
88875
88876 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
88877- __FILE__, __LINE__, tty->driver->name, port->count);
88878+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
88879
88880 schedule();
88881 }
88882@@ -364,13 +364,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
88883 if (extra_count) {
88884 /* ++ is not atomic, so this should be protected - Jean II */
88885 spin_lock_irqsave(&port->lock, flags);
88886- port->count++;
88887+ atomic_inc(&port->count);
88888 spin_unlock_irqrestore(&port->lock, flags);
88889 }
88890 port->blocked_open--;
88891
88892 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
88893- __FILE__, __LINE__, tty->driver->name, port->count);
88894+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
88895
88896 if (!retval)
88897 port->flags |= ASYNC_NORMAL_ACTIVE;
88898@@ -444,12 +444,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
88899
88900 /* ++ is not atomic, so this should be protected - Jean II */
88901 spin_lock_irqsave(&self->port.lock, flags);
88902- self->port.count++;
88903+ atomic_inc(&self->port.count);
88904 spin_unlock_irqrestore(&self->port.lock, flags);
88905 tty_port_tty_set(&self->port, tty);
88906
88907 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
88908- self->line, self->port.count);
88909+ self->line, atomic_read(&self->port.count));
88910
88911 /* Not really used by us, but lets do it anyway */
88912 tty->low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
88913@@ -986,7 +986,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
88914 tty_kref_put(port->tty);
88915 }
88916 port->tty = NULL;
88917- port->count = 0;
88918+ atomic_set(&port->count, 0);
88919 spin_unlock_irqrestore(&port->lock, flags);
88920
88921 wake_up_interruptible(&port->open_wait);
88922@@ -1343,7 +1343,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
88923 seq_putc(m, '\n');
88924
88925 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
88926- seq_printf(m, "Open count: %d\n", self->port.count);
88927+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
88928 seq_printf(m, "Max data size: %d\n", self->max_data_size);
88929 seq_printf(m, "Max header size: %d\n", self->max_header_size);
88930
88931diff --git a/net/irda/iriap.c b/net/irda/iriap.c
88932index e71e85b..29340a9 100644
88933--- a/net/irda/iriap.c
88934+++ b/net/irda/iriap.c
88935@@ -495,8 +495,11 @@ static void iriap_getvaluebyclass_confirm(struct iriap_cb *self,
88936 /* case CS_ISO_8859_9: */
88937 /* case CS_UNICODE: */
88938 default:
88939- IRDA_DEBUG(0, "%s(), charset %s, not supported\n",
88940- __func__, ias_charset_types[charset]);
88941+ IRDA_DEBUG(0, "%s(), charset [%d] %s, not supported\n",
88942+ __func__, charset,
88943+ charset < ARRAY_SIZE(ias_charset_types) ?
88944+ ias_charset_types[charset] :
88945+ "(unknown)");
88946
88947 /* Aborting, close connection! */
88948 iriap_disconnect_request(self);
88949diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
88950index cd6f7a9..e63fe89 100644
88951--- a/net/iucv/af_iucv.c
88952+++ b/net/iucv/af_iucv.c
88953@@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
88954
88955 write_lock_bh(&iucv_sk_list.lock);
88956
88957- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
88958+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
88959 while (__iucv_get_sock_by_name(name)) {
88960 sprintf(name, "%08x",
88961- atomic_inc_return(&iucv_sk_list.autobind_name));
88962+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
88963 }
88964
88965 write_unlock_bh(&iucv_sk_list.lock);
88966diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
88967index df08250..02021fe 100644
88968--- a/net/iucv/iucv.c
88969+++ b/net/iucv/iucv.c
88970@@ -690,7 +690,7 @@ static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
88971 return NOTIFY_OK;
88972 }
88973
88974-static struct notifier_block __refdata iucv_cpu_notifier = {
88975+static struct notifier_block iucv_cpu_notifier = {
88976 .notifier_call = iucv_cpu_notify,
88977 };
88978
88979diff --git a/net/key/af_key.c b/net/key/af_key.c
88980index 5b426a6..970032b 100644
88981--- a/net/key/af_key.c
88982+++ b/net/key/af_key.c
88983@@ -3019,10 +3019,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
88984 static u32 get_acqseq(void)
88985 {
88986 u32 res;
88987- static atomic_t acqseq;
88988+ static atomic_unchecked_t acqseq;
88989
88990 do {
88991- res = atomic_inc_return(&acqseq);
88992+ res = atomic_inc_return_unchecked(&acqseq);
88993 } while (!res);
88994 return res;
88995 }
88996diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
88997index 49c48c6..9e72ff4 100644
88998--- a/net/mac80211/cfg.c
88999+++ b/net/mac80211/cfg.c
89000@@ -790,7 +790,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
89001 ret = ieee80211_vif_use_channel(sdata, chandef,
89002 IEEE80211_CHANCTX_EXCLUSIVE);
89003 }
89004- } else if (local->open_count == local->monitors) {
89005+ } else if (local_read(&local->open_count) == local->monitors) {
89006 local->_oper_channel = chandef->chan;
89007 local->_oper_channel_type = cfg80211_get_chandef_type(chandef);
89008 ieee80211_hw_config(local, 0);
89009@@ -2718,7 +2718,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
89010 else
89011 local->probe_req_reg--;
89012
89013- if (!local->open_count)
89014+ if (!local_read(&local->open_count))
89015 break;
89016
89017 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
89018diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
89019index 55d8f89..bec0c2b 100644
89020--- a/net/mac80211/ieee80211_i.h
89021+++ b/net/mac80211/ieee80211_i.h
89022@@ -28,6 +28,7 @@
89023 #include <net/ieee80211_radiotap.h>
89024 #include <net/cfg80211.h>
89025 #include <net/mac80211.h>
89026+#include <asm/local.h>
89027 #include "key.h"
89028 #include "sta_info.h"
89029 #include "debug.h"
89030@@ -910,7 +911,7 @@ struct ieee80211_local {
89031 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
89032 spinlock_t queue_stop_reason_lock;
89033
89034- int open_count;
89035+ local_t open_count;
89036 int monitors, cooked_mntrs;
89037 /* number of interfaces with corresponding FIF_ flags */
89038 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
89039diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
89040index 8be854e..ad72a69 100644
89041--- a/net/mac80211/iface.c
89042+++ b/net/mac80211/iface.c
89043@@ -546,7 +546,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
89044 break;
89045 }
89046
89047- if (local->open_count == 0) {
89048+ if (local_read(&local->open_count) == 0) {
89049 res = drv_start(local);
89050 if (res)
89051 goto err_del_bss;
89052@@ -591,7 +591,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
89053 break;
89054 }
89055
89056- if (local->monitors == 0 && local->open_count == 0) {
89057+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
89058 res = ieee80211_add_virtual_monitor(local);
89059 if (res)
89060 goto err_stop;
89061@@ -699,7 +699,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
89062 mutex_unlock(&local->mtx);
89063
89064 if (coming_up)
89065- local->open_count++;
89066+ local_inc(&local->open_count);
89067
89068 if (hw_reconf_flags)
89069 ieee80211_hw_config(local, hw_reconf_flags);
89070@@ -713,7 +713,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
89071 err_del_interface:
89072 drv_remove_interface(local, sdata);
89073 err_stop:
89074- if (!local->open_count)
89075+ if (!local_read(&local->open_count))
89076 drv_stop(local);
89077 err_del_bss:
89078 sdata->bss = NULL;
89079@@ -827,7 +827,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
89080 }
89081
89082 if (going_down)
89083- local->open_count--;
89084+ local_dec(&local->open_count);
89085
89086 switch (sdata->vif.type) {
89087 case NL80211_IFTYPE_AP_VLAN:
89088@@ -884,7 +884,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
89089
89090 ieee80211_recalc_ps(local, -1);
89091
89092- if (local->open_count == 0) {
89093+ if (local_read(&local->open_count) == 0) {
89094 if (local->ops->napi_poll)
89095 napi_disable(&local->napi);
89096 ieee80211_clear_tx_pending(local);
89097@@ -910,7 +910,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
89098 }
89099 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
89100
89101- if (local->monitors == local->open_count && local->monitors > 0)
89102+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
89103 ieee80211_add_virtual_monitor(local);
89104 }
89105
89106diff --git a/net/mac80211/main.c b/net/mac80211/main.c
89107index 1b087ff..bf600e9 100644
89108--- a/net/mac80211/main.c
89109+++ b/net/mac80211/main.c
89110@@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
89111 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
89112 IEEE80211_CONF_CHANGE_POWER);
89113
89114- if (changed && local->open_count) {
89115+ if (changed && local_read(&local->open_count)) {
89116 ret = drv_config(local, changed);
89117 /*
89118 * Goal:
89119diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
89120index 79a48f3..5e185c9 100644
89121--- a/net/mac80211/pm.c
89122+++ b/net/mac80211/pm.c
89123@@ -35,7 +35,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
89124 struct sta_info *sta;
89125 struct ieee80211_chanctx *ctx;
89126
89127- if (!local->open_count)
89128+ if (!local_read(&local->open_count))
89129 goto suspend;
89130
89131 ieee80211_scan_cancel(local);
89132@@ -73,7 +73,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
89133 cancel_work_sync(&local->dynamic_ps_enable_work);
89134 del_timer_sync(&local->dynamic_ps_timer);
89135
89136- local->wowlan = wowlan && local->open_count;
89137+ local->wowlan = wowlan && local_read(&local->open_count);
89138 if (local->wowlan) {
89139 int err = drv_suspend(local, wowlan);
89140 if (err < 0) {
89141@@ -187,7 +187,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
89142 mutex_unlock(&local->chanctx_mtx);
89143
89144 /* stop hardware - this must stop RX */
89145- if (local->open_count)
89146+ if (local_read(&local->open_count))
89147 ieee80211_stop_device(local);
89148
89149 suspend:
89150diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
89151index dd88381..eef4dd6 100644
89152--- a/net/mac80211/rate.c
89153+++ b/net/mac80211/rate.c
89154@@ -493,7 +493,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
89155
89156 ASSERT_RTNL();
89157
89158- if (local->open_count)
89159+ if (local_read(&local->open_count))
89160 return -EBUSY;
89161
89162 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
89163diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
89164index c97a065..ff61928 100644
89165--- a/net/mac80211/rc80211_pid_debugfs.c
89166+++ b/net/mac80211/rc80211_pid_debugfs.c
89167@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
89168
89169 spin_unlock_irqrestore(&events->lock, status);
89170
89171- if (copy_to_user(buf, pb, p))
89172+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
89173 return -EFAULT;
89174
89175 return p;
89176diff --git a/net/mac80211/util.c b/net/mac80211/util.c
89177index f11e8c5..08d0013 100644
89178--- a/net/mac80211/util.c
89179+++ b/net/mac80211/util.c
89180@@ -1380,7 +1380,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
89181 }
89182 #endif
89183 /* everything else happens only if HW was up & running */
89184- if (!local->open_count)
89185+ if (!local_read(&local->open_count))
89186 goto wake_up;
89187
89188 /*
89189diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
89190index 49e96df..63a51c3 100644
89191--- a/net/netfilter/Kconfig
89192+++ b/net/netfilter/Kconfig
89193@@ -936,6 +936,16 @@ config NETFILTER_XT_MATCH_ESP
89194
89195 To compile it as a module, choose M here. If unsure, say N.
89196
89197+config NETFILTER_XT_MATCH_GRADM
89198+ tristate '"gradm" match support'
89199+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
89200+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
89201+ ---help---
89202+ The gradm match allows to match on grsecurity RBAC being enabled.
89203+ It is useful when iptables rules are applied early on bootup to
89204+ prevent connections to the machine (except from a trusted host)
89205+ while the RBAC system is disabled.
89206+
89207 config NETFILTER_XT_MATCH_HASHLIMIT
89208 tristate '"hashlimit" match support'
89209 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
89210diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
89211index 3259697..54d5393 100644
89212--- a/net/netfilter/Makefile
89213+++ b/net/netfilter/Makefile
89214@@ -109,6 +109,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
89215 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
89216 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
89217 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
89218+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
89219 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
89220 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
89221 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
89222diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
89223index 6d6d8f2..a676749 100644
89224--- a/net/netfilter/ipset/ip_set_core.c
89225+++ b/net/netfilter/ipset/ip_set_core.c
89226@@ -1800,7 +1800,7 @@ done:
89227 return ret;
89228 }
89229
89230-static struct nf_sockopt_ops so_set __read_mostly = {
89231+static struct nf_sockopt_ops so_set = {
89232 .pf = PF_INET,
89233 .get_optmin = SO_IP_SET,
89234 .get_optmax = SO_IP_SET + 1,
89235diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
89236index 30e764a..c3b6a9d 100644
89237--- a/net/netfilter/ipvs/ip_vs_conn.c
89238+++ b/net/netfilter/ipvs/ip_vs_conn.c
89239@@ -554,7 +554,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
89240 /* Increase the refcnt counter of the dest */
89241 atomic_inc(&dest->refcnt);
89242
89243- conn_flags = atomic_read(&dest->conn_flags);
89244+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
89245 if (cp->protocol != IPPROTO_UDP)
89246 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
89247 flags = cp->flags;
89248@@ -899,7 +899,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
89249 atomic_set(&cp->refcnt, 1);
89250
89251 atomic_set(&cp->n_control, 0);
89252- atomic_set(&cp->in_pkts, 0);
89253+ atomic_set_unchecked(&cp->in_pkts, 0);
89254
89255 atomic_inc(&ipvs->conn_count);
89256 if (flags & IP_VS_CONN_F_NO_CPORT)
89257@@ -1180,7 +1180,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
89258
89259 /* Don't drop the entry if its number of incoming packets is not
89260 located in [0, 8] */
89261- i = atomic_read(&cp->in_pkts);
89262+ i = atomic_read_unchecked(&cp->in_pkts);
89263 if (i > 8 || i < 0) return 0;
89264
89265 if (!todrop_rate[i]) return 0;
89266diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
89267index 47edf5a..235b07d 100644
89268--- a/net/netfilter/ipvs/ip_vs_core.c
89269+++ b/net/netfilter/ipvs/ip_vs_core.c
89270@@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
89271 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
89272 /* do not touch skb anymore */
89273
89274- atomic_inc(&cp->in_pkts);
89275+ atomic_inc_unchecked(&cp->in_pkts);
89276 ip_vs_conn_put(cp);
89277 return ret;
89278 }
89279@@ -1691,7 +1691,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
89280 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
89281 pkts = sysctl_sync_threshold(ipvs);
89282 else
89283- pkts = atomic_add_return(1, &cp->in_pkts);
89284+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
89285
89286 if (ipvs->sync_state & IP_VS_STATE_MASTER)
89287 ip_vs_sync_conn(net, cp, pkts);
89288diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
89289index ec664cb..7f34a77 100644
89290--- a/net/netfilter/ipvs/ip_vs_ctl.c
89291+++ b/net/netfilter/ipvs/ip_vs_ctl.c
89292@@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
89293 ip_vs_rs_hash(ipvs, dest);
89294 write_unlock_bh(&ipvs->rs_lock);
89295 }
89296- atomic_set(&dest->conn_flags, conn_flags);
89297+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
89298
89299 /* bind the service */
89300 if (!dest->svc) {
89301@@ -1688,7 +1688,7 @@ proc_do_sync_ports(ctl_table *table, int write,
89302 * align with netns init in ip_vs_control_net_init()
89303 */
89304
89305-static struct ctl_table vs_vars[] = {
89306+static ctl_table_no_const vs_vars[] __read_only = {
89307 {
89308 .procname = "amemthresh",
89309 .maxlen = sizeof(int),
89310@@ -2081,7 +2081,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
89311 " %-7s %-6d %-10d %-10d\n",
89312 &dest->addr.in6,
89313 ntohs(dest->port),
89314- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
89315+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
89316 atomic_read(&dest->weight),
89317 atomic_read(&dest->activeconns),
89318 atomic_read(&dest->inactconns));
89319@@ -2092,7 +2092,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
89320 "%-7s %-6d %-10d %-10d\n",
89321 ntohl(dest->addr.ip),
89322 ntohs(dest->port),
89323- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
89324+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
89325 atomic_read(&dest->weight),
89326 atomic_read(&dest->activeconns),
89327 atomic_read(&dest->inactconns));
89328@@ -2562,7 +2562,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
89329
89330 entry.addr = dest->addr.ip;
89331 entry.port = dest->port;
89332- entry.conn_flags = atomic_read(&dest->conn_flags);
89333+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
89334 entry.weight = atomic_read(&dest->weight);
89335 entry.u_threshold = dest->u_threshold;
89336 entry.l_threshold = dest->l_threshold;
89337@@ -3098,7 +3098,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
89338 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
89339 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
89340 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
89341- (atomic_read(&dest->conn_flags) &
89342+ (atomic_read_unchecked(&dest->conn_flags) &
89343 IP_VS_CONN_F_FWD_MASK)) ||
89344 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
89345 atomic_read(&dest->weight)) ||
89346@@ -3688,7 +3688,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
89347 {
89348 int idx;
89349 struct netns_ipvs *ipvs = net_ipvs(net);
89350- struct ctl_table *tbl;
89351+ ctl_table_no_const *tbl;
89352
89353 atomic_set(&ipvs->dropentry, 0);
89354 spin_lock_init(&ipvs->dropentry_lock);
89355diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
89356index fdd89b9..bd96aa9 100644
89357--- a/net/netfilter/ipvs/ip_vs_lblc.c
89358+++ b/net/netfilter/ipvs/ip_vs_lblc.c
89359@@ -115,7 +115,7 @@ struct ip_vs_lblc_table {
89360 * IPVS LBLC sysctl table
89361 */
89362 #ifdef CONFIG_SYSCTL
89363-static ctl_table vs_vars_table[] = {
89364+static ctl_table_no_const vs_vars_table[] __read_only = {
89365 {
89366 .procname = "lblc_expiration",
89367 .data = NULL,
89368diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
89369index c03b6a3..8ce3681 100644
89370--- a/net/netfilter/ipvs/ip_vs_lblcr.c
89371+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
89372@@ -288,7 +288,7 @@ struct ip_vs_lblcr_table {
89373 * IPVS LBLCR sysctl table
89374 */
89375
89376-static ctl_table vs_vars_table[] = {
89377+static ctl_table_no_const vs_vars_table[] __read_only = {
89378 {
89379 .procname = "lblcr_expiration",
89380 .data = NULL,
89381diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
89382index 44fd10c..2a163b3 100644
89383--- a/net/netfilter/ipvs/ip_vs_sync.c
89384+++ b/net/netfilter/ipvs/ip_vs_sync.c
89385@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
89386 cp = cp->control;
89387 if (cp) {
89388 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
89389- pkts = atomic_add_return(1, &cp->in_pkts);
89390+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
89391 else
89392 pkts = sysctl_sync_threshold(ipvs);
89393 ip_vs_sync_conn(net, cp->control, pkts);
89394@@ -758,7 +758,7 @@ control:
89395 if (!cp)
89396 return;
89397 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
89398- pkts = atomic_add_return(1, &cp->in_pkts);
89399+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
89400 else
89401 pkts = sysctl_sync_threshold(ipvs);
89402 goto sloop;
89403@@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
89404
89405 if (opt)
89406 memcpy(&cp->in_seq, opt, sizeof(*opt));
89407- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
89408+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
89409 cp->state = state;
89410 cp->old_state = cp->state;
89411 /*
89412diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
89413index ee6b7a9..f9a89f6 100644
89414--- a/net/netfilter/ipvs/ip_vs_xmit.c
89415+++ b/net/netfilter/ipvs/ip_vs_xmit.c
89416@@ -1210,7 +1210,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
89417 else
89418 rc = NF_ACCEPT;
89419 /* do not touch skb anymore */
89420- atomic_inc(&cp->in_pkts);
89421+ atomic_inc_unchecked(&cp->in_pkts);
89422 goto out;
89423 }
89424
89425@@ -1332,7 +1332,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
89426 else
89427 rc = NF_ACCEPT;
89428 /* do not touch skb anymore */
89429- atomic_inc(&cp->in_pkts);
89430+ atomic_inc_unchecked(&cp->in_pkts);
89431 goto out;
89432 }
89433
89434diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
89435index 7df424e..a527b02 100644
89436--- a/net/netfilter/nf_conntrack_acct.c
89437+++ b/net/netfilter/nf_conntrack_acct.c
89438@@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
89439 #ifdef CONFIG_SYSCTL
89440 static int nf_conntrack_acct_init_sysctl(struct net *net)
89441 {
89442- struct ctl_table *table;
89443+ ctl_table_no_const *table;
89444
89445 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
89446 GFP_KERNEL);
89447diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
89448index e4a0c4f..c263f28 100644
89449--- a/net/netfilter/nf_conntrack_core.c
89450+++ b/net/netfilter/nf_conntrack_core.c
89451@@ -1529,6 +1529,10 @@ err_extend:
89452 #define DYING_NULLS_VAL ((1<<30)+1)
89453 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
89454
89455+#ifdef CONFIG_GRKERNSEC_HIDESYM
89456+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
89457+#endif
89458+
89459 static int nf_conntrack_init_net(struct net *net)
89460 {
89461 int ret;
89462@@ -1543,7 +1547,11 @@ static int nf_conntrack_init_net(struct net *net)
89463 goto err_stat;
89464 }
89465
89466+#ifdef CONFIG_GRKERNSEC_HIDESYM
89467+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
89468+#else
89469 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
89470+#endif
89471 if (!net->ct.slabname) {
89472 ret = -ENOMEM;
89473 goto err_slabname;
89474diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
89475index faa978f..1afb18f 100644
89476--- a/net/netfilter/nf_conntrack_ecache.c
89477+++ b/net/netfilter/nf_conntrack_ecache.c
89478@@ -186,7 +186,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
89479 #ifdef CONFIG_SYSCTL
89480 static int nf_conntrack_event_init_sysctl(struct net *net)
89481 {
89482- struct ctl_table *table;
89483+ ctl_table_no_const *table;
89484
89485 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
89486 GFP_KERNEL);
89487diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
89488index 884f2b3..d53b33a 100644
89489--- a/net/netfilter/nf_conntrack_helper.c
89490+++ b/net/netfilter/nf_conntrack_helper.c
89491@@ -55,7 +55,7 @@ static struct ctl_table helper_sysctl_table[] = {
89492
89493 static int nf_conntrack_helper_init_sysctl(struct net *net)
89494 {
89495- struct ctl_table *table;
89496+ ctl_table_no_const *table;
89497
89498 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
89499 GFP_KERNEL);
89500diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
89501index 51e928d..72a413a 100644
89502--- a/net/netfilter/nf_conntrack_proto.c
89503+++ b/net/netfilter/nf_conntrack_proto.c
89504@@ -51,7 +51,7 @@ nf_ct_register_sysctl(struct net *net,
89505
89506 static void
89507 nf_ct_unregister_sysctl(struct ctl_table_header **header,
89508- struct ctl_table **table,
89509+ ctl_table_no_const **table,
89510 unsigned int users)
89511 {
89512 if (users > 0)
89513diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
89514index e7185c6..4ad6c9c 100644
89515--- a/net/netfilter/nf_conntrack_standalone.c
89516+++ b/net/netfilter/nf_conntrack_standalone.c
89517@@ -470,7 +470,7 @@ static ctl_table nf_ct_netfilter_table[] = {
89518
89519 static int nf_conntrack_standalone_init_sysctl(struct net *net)
89520 {
89521- struct ctl_table *table;
89522+ ctl_table_no_const *table;
89523
89524 if (net_eq(net, &init_net)) {
89525 nf_ct_netfilter_header =
89526diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
89527index 7ea8026..bc9512d 100644
89528--- a/net/netfilter/nf_conntrack_timestamp.c
89529+++ b/net/netfilter/nf_conntrack_timestamp.c
89530@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
89531 #ifdef CONFIG_SYSCTL
89532 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
89533 {
89534- struct ctl_table *table;
89535+ ctl_table_no_const *table;
89536
89537 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
89538 GFP_KERNEL);
89539diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
89540index 9e31269..bc4c1b7 100644
89541--- a/net/netfilter/nf_log.c
89542+++ b/net/netfilter/nf_log.c
89543@@ -215,7 +215,7 @@ static const struct file_operations nflog_file_ops = {
89544
89545 #ifdef CONFIG_SYSCTL
89546 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
89547-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
89548+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
89549 static struct ctl_table_header *nf_log_dir_header;
89550
89551 static int nf_log_proc_dostring(ctl_table *table, int write,
89552@@ -246,14 +246,16 @@ static int nf_log_proc_dostring(ctl_table *table, int write,
89553 rcu_assign_pointer(nf_loggers[tindex], logger);
89554 mutex_unlock(&nf_log_mutex);
89555 } else {
89556+ ctl_table_no_const nf_log_table = *table;
89557+
89558 mutex_lock(&nf_log_mutex);
89559 logger = rcu_dereference_protected(nf_loggers[tindex],
89560 lockdep_is_held(&nf_log_mutex));
89561 if (!logger)
89562- table->data = "NONE";
89563+ nf_log_table.data = "NONE";
89564 else
89565- table->data = logger->name;
89566- r = proc_dostring(table, write, buffer, lenp, ppos);
89567+ nf_log_table.data = logger->name;
89568+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
89569 mutex_unlock(&nf_log_mutex);
89570 }
89571
89572diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
89573index f042ae5..30ea486 100644
89574--- a/net/netfilter/nf_sockopt.c
89575+++ b/net/netfilter/nf_sockopt.c
89576@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
89577 }
89578 }
89579
89580- list_add(&reg->list, &nf_sockopts);
89581+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
89582 out:
89583 mutex_unlock(&nf_sockopt_mutex);
89584 return ret;
89585@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
89586 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
89587 {
89588 mutex_lock(&nf_sockopt_mutex);
89589- list_del(&reg->list);
89590+ pax_list_del((struct list_head *)&reg->list);
89591 mutex_unlock(&nf_sockopt_mutex);
89592 }
89593 EXPORT_SYMBOL(nf_unregister_sockopt);
89594diff --git a/net/netfilter/nfnetlink_acct.c b/net/netfilter/nfnetlink_acct.c
89595index 589d686..dc3fd5d 100644
89596--- a/net/netfilter/nfnetlink_acct.c
89597+++ b/net/netfilter/nfnetlink_acct.c
89598@@ -49,6 +49,8 @@ nfnl_acct_new(struct sock *nfnl, struct sk_buff *skb,
89599 return -EINVAL;
89600
89601 acct_name = nla_data(tb[NFACCT_NAME]);
89602+ if (strlen(acct_name) == 0)
89603+ return -EINVAL;
89604
89605 list_for_each_entry(nfacct, &nfnl_acct_list, head) {
89606 if (strncmp(nfacct->name, acct_name, NFACCT_NAME_MAX) != 0)
89607diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
89608index 92fd8ec..3f6ea4b 100644
89609--- a/net/netfilter/nfnetlink_log.c
89610+++ b/net/netfilter/nfnetlink_log.c
89611@@ -72,7 +72,7 @@ struct nfulnl_instance {
89612 };
89613
89614 static DEFINE_SPINLOCK(instances_lock);
89615-static atomic_t global_seq;
89616+static atomic_unchecked_t global_seq;
89617
89618 #define INSTANCE_BUCKETS 16
89619 static struct hlist_head instance_table[INSTANCE_BUCKETS];
89620@@ -537,7 +537,7 @@ __build_packet_message(struct nfulnl_instance *inst,
89621 /* global sequence number */
89622 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
89623 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
89624- htonl(atomic_inc_return(&global_seq))))
89625+ htonl(atomic_inc_return_unchecked(&global_seq))))
89626 goto nla_put_failure;
89627
89628 if (data_len) {
89629diff --git a/net/netfilter/nfnetlink_queue_core.c b/net/netfilter/nfnetlink_queue_core.c
89630index 3158d87..39006c9 100644
89631--- a/net/netfilter/nfnetlink_queue_core.c
89632+++ b/net/netfilter/nfnetlink_queue_core.c
89633@@ -1064,8 +1064,10 @@ static int __init nfnetlink_queue_init(void)
89634
89635 #ifdef CONFIG_PROC_FS
89636 if (!proc_create("nfnetlink_queue", 0440,
89637- proc_net_netfilter, &nfqnl_file_ops))
89638+ proc_net_netfilter, &nfqnl_file_ops)) {
89639+ status = -ENOMEM;
89640 goto cleanup_subsys;
89641+ }
89642 #endif
89643
89644 register_netdevice_notifier(&nfqnl_dev_notifier);
89645diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
89646new file mode 100644
89647index 0000000..c566332
89648--- /dev/null
89649+++ b/net/netfilter/xt_gradm.c
89650@@ -0,0 +1,51 @@
89651+/*
89652+ * gradm match for netfilter
89653