]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.8.8-201304181923.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.8.8-201304181923.patch
CommitLineData
ebed0866
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/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
8250index 79da178..c2eede8 100644
8251--- a/arch/sparc/include/asm/pgtsrmmu.h
8252+++ b/arch/sparc/include/asm/pgtsrmmu.h
8253@@ -115,6 +115,11 @@
8254 SRMMU_EXEC | SRMMU_REF)
8255 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
8256 SRMMU_EXEC | SRMMU_REF)
8257+
8258+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
8259+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
8260+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
8261+
8262 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
8263 SRMMU_DIRTY | SRMMU_REF)
8264
8265diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
8266index 9689176..63c18ea 100644
8267--- a/arch/sparc/include/asm/spinlock_64.h
8268+++ b/arch/sparc/include/asm/spinlock_64.h
8269@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
8270
8271 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
8272
8273-static void inline arch_read_lock(arch_rwlock_t *lock)
8274+static inline void arch_read_lock(arch_rwlock_t *lock)
8275 {
8276 unsigned long tmp1, tmp2;
8277
8278 __asm__ __volatile__ (
8279 "1: ldsw [%2], %0\n"
8280 " brlz,pn %0, 2f\n"
8281-"4: add %0, 1, %1\n"
8282+"4: addcc %0, 1, %1\n"
8283+
8284+#ifdef CONFIG_PAX_REFCOUNT
8285+" tvs %%icc, 6\n"
8286+#endif
8287+
8288 " cas [%2], %0, %1\n"
8289 " cmp %0, %1\n"
8290 " bne,pn %%icc, 1b\n"
8291@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
8292 " .previous"
8293 : "=&r" (tmp1), "=&r" (tmp2)
8294 : "r" (lock)
8295- : "memory");
8296+ : "memory", "cc");
8297 }
8298
8299-static int inline arch_read_trylock(arch_rwlock_t *lock)
8300+static inline int arch_read_trylock(arch_rwlock_t *lock)
8301 {
8302 int tmp1, tmp2;
8303
8304@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
8305 "1: ldsw [%2], %0\n"
8306 " brlz,a,pn %0, 2f\n"
8307 " mov 0, %0\n"
8308-" add %0, 1, %1\n"
8309+" addcc %0, 1, %1\n"
8310+
8311+#ifdef CONFIG_PAX_REFCOUNT
8312+" tvs %%icc, 6\n"
8313+#endif
8314+
8315 " cas [%2], %0, %1\n"
8316 " cmp %0, %1\n"
8317 " bne,pn %%icc, 1b\n"
8318@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
8319 return tmp1;
8320 }
8321
8322-static void inline arch_read_unlock(arch_rwlock_t *lock)
8323+static inline void arch_read_unlock(arch_rwlock_t *lock)
8324 {
8325 unsigned long tmp1, tmp2;
8326
8327 __asm__ __volatile__(
8328 "1: lduw [%2], %0\n"
8329-" sub %0, 1, %1\n"
8330+" subcc %0, 1, %1\n"
8331+
8332+#ifdef CONFIG_PAX_REFCOUNT
8333+" tvs %%icc, 6\n"
8334+#endif
8335+
8336 " cas [%2], %0, %1\n"
8337 " cmp %0, %1\n"
8338 " bne,pn %%xcc, 1b\n"
8339@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
8340 : "memory");
8341 }
8342
8343-static void inline arch_write_lock(arch_rwlock_t *lock)
8344+static inline void arch_write_lock(arch_rwlock_t *lock)
8345 {
8346 unsigned long mask, tmp1, tmp2;
8347
8348@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
8349 : "memory");
8350 }
8351
8352-static void inline arch_write_unlock(arch_rwlock_t *lock)
8353+static inline void arch_write_unlock(arch_rwlock_t *lock)
8354 {
8355 __asm__ __volatile__(
8356 " stw %%g0, [%0]"
8357@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
8358 : "memory");
8359 }
8360
8361-static int inline arch_write_trylock(arch_rwlock_t *lock)
8362+static inline int arch_write_trylock(arch_rwlock_t *lock)
8363 {
8364 unsigned long mask, tmp1, tmp2, result;
8365
8366diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
8367index 25849ae..924c54b 100644
8368--- a/arch/sparc/include/asm/thread_info_32.h
8369+++ b/arch/sparc/include/asm/thread_info_32.h
8370@@ -49,6 +49,8 @@ struct thread_info {
8371 unsigned long w_saved;
8372
8373 struct restart_block restart_block;
8374+
8375+ unsigned long lowest_stack;
8376 };
8377
8378 /*
8379diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
8380index 269bd92..e46a9b8 100644
8381--- a/arch/sparc/include/asm/thread_info_64.h
8382+++ b/arch/sparc/include/asm/thread_info_64.h
8383@@ -63,6 +63,8 @@ struct thread_info {
8384 struct pt_regs *kern_una_regs;
8385 unsigned int kern_una_insn;
8386
8387+ unsigned long lowest_stack;
8388+
8389 unsigned long fpregs[0] __attribute__ ((aligned(64)));
8390 };
8391
8392@@ -192,10 +194,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
8393 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
8394 /* flag bit 6 is available */
8395 #define TIF_32BIT 7 /* 32-bit binary */
8396-/* flag bit 8 is available */
8397+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
8398 #define TIF_SECCOMP 9 /* secure computing */
8399 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
8400 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
8401+
8402 /* NOTE: Thread flags >= 12 should be ones we have no interest
8403 * in using in assembly, else we can't use the mask as
8404 * an immediate value in instructions such as andcc.
8405@@ -214,12 +217,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
8406 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
8407 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8408 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
8409+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8410
8411 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
8412 _TIF_DO_NOTIFY_RESUME_MASK | \
8413 _TIF_NEED_RESCHED)
8414 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
8415
8416+#define _TIF_WORK_SYSCALL \
8417+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
8418+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
8419+
8420+
8421 /*
8422 * Thread-synchronous status.
8423 *
8424diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
8425index 0167d26..767bb0c 100644
8426--- a/arch/sparc/include/asm/uaccess.h
8427+++ b/arch/sparc/include/asm/uaccess.h
8428@@ -1,5 +1,6 @@
8429 #ifndef ___ASM_SPARC_UACCESS_H
8430 #define ___ASM_SPARC_UACCESS_H
8431+
8432 #if defined(__sparc__) && defined(__arch64__)
8433 #include <asm/uaccess_64.h>
8434 #else
8435diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
8436index 53a28dd..50c38c3 100644
8437--- a/arch/sparc/include/asm/uaccess_32.h
8438+++ b/arch/sparc/include/asm/uaccess_32.h
8439@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
8440
8441 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8442 {
8443- if (n && __access_ok((unsigned long) to, n))
8444+ if ((long)n < 0)
8445+ return n;
8446+
8447+ if (n && __access_ok((unsigned long) to, n)) {
8448+ if (!__builtin_constant_p(n))
8449+ check_object_size(from, n, true);
8450 return __copy_user(to, (__force void __user *) from, n);
8451- else
8452+ } else
8453 return n;
8454 }
8455
8456 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
8457 {
8458+ if ((long)n < 0)
8459+ return n;
8460+
8461+ if (!__builtin_constant_p(n))
8462+ check_object_size(from, n, true);
8463+
8464 return __copy_user(to, (__force void __user *) from, n);
8465 }
8466
8467 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8468 {
8469- if (n && __access_ok((unsigned long) from, n))
8470+ if ((long)n < 0)
8471+ return n;
8472+
8473+ if (n && __access_ok((unsigned long) from, n)) {
8474+ if (!__builtin_constant_p(n))
8475+ check_object_size(to, n, false);
8476 return __copy_user((__force void __user *) to, from, n);
8477- else
8478+ } else
8479 return n;
8480 }
8481
8482 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
8483 {
8484+ if ((long)n < 0)
8485+ return n;
8486+
8487 return __copy_user((__force void __user *) to, from, n);
8488 }
8489
8490diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
8491index e562d3c..191f176 100644
8492--- a/arch/sparc/include/asm/uaccess_64.h
8493+++ b/arch/sparc/include/asm/uaccess_64.h
8494@@ -10,6 +10,7 @@
8495 #include <linux/compiler.h>
8496 #include <linux/string.h>
8497 #include <linux/thread_info.h>
8498+#include <linux/kernel.h>
8499 #include <asm/asi.h>
8500 #include <asm/spitfire.h>
8501 #include <asm-generic/uaccess-unaligned.h>
8502@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
8503 static inline unsigned long __must_check
8504 copy_from_user(void *to, const void __user *from, unsigned long size)
8505 {
8506- unsigned long ret = ___copy_from_user(to, from, size);
8507+ unsigned long ret;
8508
8509+ if ((long)size < 0 || size > INT_MAX)
8510+ return size;
8511+
8512+ if (!__builtin_constant_p(size))
8513+ check_object_size(to, size, false);
8514+
8515+ ret = ___copy_from_user(to, from, size);
8516 if (unlikely(ret))
8517 ret = copy_from_user_fixup(to, from, size);
8518
8519@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
8520 static inline unsigned long __must_check
8521 copy_to_user(void __user *to, const void *from, unsigned long size)
8522 {
8523- unsigned long ret = ___copy_to_user(to, from, size);
8524+ unsigned long ret;
8525
8526+ if ((long)size < 0 || size > INT_MAX)
8527+ return size;
8528+
8529+ if (!__builtin_constant_p(size))
8530+ check_object_size(from, size, true);
8531+
8532+ ret = ___copy_to_user(to, from, size);
8533 if (unlikely(ret))
8534 ret = copy_to_user_fixup(to, from, size);
8535 return ret;
8536diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
8537index 6cf591b..b49e65a 100644
8538--- a/arch/sparc/kernel/Makefile
8539+++ b/arch/sparc/kernel/Makefile
8540@@ -3,7 +3,7 @@
8541 #
8542
8543 asflags-y := -ansi
8544-ccflags-y := -Werror
8545+#ccflags-y := -Werror
8546
8547 extra-y := head_$(BITS).o
8548
8549diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
8550index be8e862..5b50b12 100644
8551--- a/arch/sparc/kernel/process_32.c
8552+++ b/arch/sparc/kernel/process_32.c
8553@@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
8554
8555 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
8556 r->psr, r->pc, r->npc, r->y, print_tainted());
8557- printk("PC: <%pS>\n", (void *) r->pc);
8558+ printk("PC: <%pA>\n", (void *) r->pc);
8559 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8560 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
8561 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
8562 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8563 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
8564 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
8565- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
8566+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
8567
8568 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8569 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
8570@@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8571 rw = (struct reg_window32 *) fp;
8572 pc = rw->ins[7];
8573 printk("[%08lx : ", pc);
8574- printk("%pS ] ", (void *) pc);
8575+ printk("%pA ] ", (void *) pc);
8576 fp = rw->ins[6];
8577 } while (++count < 16);
8578 printk("\n");
8579diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
8580index cdb80b2..5ca141d 100644
8581--- a/arch/sparc/kernel/process_64.c
8582+++ b/arch/sparc/kernel/process_64.c
8583@@ -181,14 +181,14 @@ static void show_regwindow(struct pt_regs *regs)
8584 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
8585 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
8586 if (regs->tstate & TSTATE_PRIV)
8587- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
8588+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
8589 }
8590
8591 void show_regs(struct pt_regs *regs)
8592 {
8593 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
8594 regs->tpc, regs->tnpc, regs->y, print_tainted());
8595- printk("TPC: <%pS>\n", (void *) regs->tpc);
8596+ printk("TPC: <%pA>\n", (void *) regs->tpc);
8597 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
8598 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
8599 regs->u_regs[3]);
8600@@ -201,7 +201,7 @@ void show_regs(struct pt_regs *regs)
8601 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
8602 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
8603 regs->u_regs[15]);
8604- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
8605+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
8606 show_regwindow(regs);
8607 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
8608 }
8609@@ -290,7 +290,7 @@ void arch_trigger_all_cpu_backtrace(void)
8610 ((tp && tp->task) ? tp->task->pid : -1));
8611
8612 if (gp->tstate & TSTATE_PRIV) {
8613- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
8614+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
8615 (void *) gp->tpc,
8616 (void *) gp->o7,
8617 (void *) gp->i7,
8618diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
8619index 1303021..c2a6321 100644
8620--- a/arch/sparc/kernel/prom_common.c
8621+++ b/arch/sparc/kernel/prom_common.c
8622@@ -143,7 +143,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
8623
8624 unsigned int prom_early_allocated __initdata;
8625
8626-static struct of_pdt_ops prom_sparc_ops __initdata = {
8627+static struct of_pdt_ops prom_sparc_ops __initconst = {
8628 .nextprop = prom_common_nextprop,
8629 .getproplen = prom_getproplen,
8630 .getproperty = prom_getproperty,
8631diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
8632index 7ff45e4..a58f271 100644
8633--- a/arch/sparc/kernel/ptrace_64.c
8634+++ b/arch/sparc/kernel/ptrace_64.c
8635@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
8636 return ret;
8637 }
8638
8639+#ifdef CONFIG_GRKERNSEC_SETXID
8640+extern void gr_delayed_cred_worker(void);
8641+#endif
8642+
8643 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8644 {
8645 int ret = 0;
8646@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8647 /* do the secure computing check first */
8648 secure_computing_strict(regs->u_regs[UREG_G1]);
8649
8650+#ifdef CONFIG_GRKERNSEC_SETXID
8651+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8652+ gr_delayed_cred_worker();
8653+#endif
8654+
8655 if (test_thread_flag(TIF_SYSCALL_TRACE))
8656 ret = tracehook_report_syscall_entry(regs);
8657
8658@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8659
8660 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
8661 {
8662+#ifdef CONFIG_GRKERNSEC_SETXID
8663+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8664+ gr_delayed_cred_worker();
8665+#endif
8666+
8667 audit_syscall_exit(regs);
8668
8669 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8670diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
8671index 2da0bdc..79128d2 100644
8672--- a/arch/sparc/kernel/sys_sparc_32.c
8673+++ b/arch/sparc/kernel/sys_sparc_32.c
8674@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8675 if (len > TASK_SIZE - PAGE_SIZE)
8676 return -ENOMEM;
8677 if (!addr)
8678- addr = TASK_UNMAPPED_BASE;
8679+ addr = current->mm->mmap_base;
8680
8681 info.flags = 0;
8682 info.length = len;
8683diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
8684index 708bc29..f0129cb 100644
8685--- a/arch/sparc/kernel/sys_sparc_64.c
8686+++ b/arch/sparc/kernel/sys_sparc_64.c
8687@@ -90,13 +90,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8688 struct vm_area_struct * vma;
8689 unsigned long task_size = TASK_SIZE;
8690 int do_color_align;
8691+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8692 struct vm_unmapped_area_info info;
8693
8694 if (flags & MAP_FIXED) {
8695 /* We do not accept a shared mapping if it would violate
8696 * cache aliasing constraints.
8697 */
8698- if ((flags & MAP_SHARED) &&
8699+ if ((filp || (flags & MAP_SHARED)) &&
8700 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8701 return -EINVAL;
8702 return addr;
8703@@ -111,6 +112,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8704 if (filp || (flags & MAP_SHARED))
8705 do_color_align = 1;
8706
8707+#ifdef CONFIG_PAX_RANDMMAP
8708+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8709+#endif
8710+
8711 if (addr) {
8712 if (do_color_align)
8713 addr = COLOR_ALIGN(addr, pgoff);
8714@@ -118,14 +123,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8715 addr = PAGE_ALIGN(addr);
8716
8717 vma = find_vma(mm, addr);
8718- if (task_size - len >= addr &&
8719- (!vma || addr + len <= vma->vm_start))
8720+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8721 return addr;
8722 }
8723
8724 info.flags = 0;
8725 info.length = len;
8726- info.low_limit = TASK_UNMAPPED_BASE;
8727+ info.low_limit = mm->mmap_base;
8728 info.high_limit = min(task_size, VA_EXCLUDE_START);
8729 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
8730 info.align_offset = pgoff << PAGE_SHIFT;
8731@@ -134,6 +138,12 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8732 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
8733 VM_BUG_ON(addr != -ENOMEM);
8734 info.low_limit = VA_EXCLUDE_END;
8735+
8736+#ifdef CONFIG_PAX_RANDMMAP
8737+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8738+ info.low_limit += mm->delta_mmap;
8739+#endif
8740+
8741 info.high_limit = task_size;
8742 addr = vm_unmapped_area(&info);
8743 }
8744@@ -151,6 +161,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8745 unsigned long task_size = STACK_TOP32;
8746 unsigned long addr = addr0;
8747 int do_color_align;
8748+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8749 struct vm_unmapped_area_info info;
8750
8751 /* This should only ever run for 32-bit processes. */
8752@@ -160,7 +171,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8753 /* We do not accept a shared mapping if it would violate
8754 * cache aliasing constraints.
8755 */
8756- if ((flags & MAP_SHARED) &&
8757+ if ((filp || (flags & MAP_SHARED)) &&
8758 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8759 return -EINVAL;
8760 return addr;
8761@@ -173,6 +184,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8762 if (filp || (flags & MAP_SHARED))
8763 do_color_align = 1;
8764
8765+#ifdef CONFIG_PAX_RANDMMAP
8766+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8767+#endif
8768+
8769 /* requesting a specific address */
8770 if (addr) {
8771 if (do_color_align)
8772@@ -181,8 +196,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8773 addr = PAGE_ALIGN(addr);
8774
8775 vma = find_vma(mm, addr);
8776- if (task_size - len >= addr &&
8777- (!vma || addr + len <= vma->vm_start))
8778+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8779 return addr;
8780 }
8781
8782@@ -204,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8783 VM_BUG_ON(addr != -ENOMEM);
8784 info.flags = 0;
8785 info.low_limit = TASK_UNMAPPED_BASE;
8786+
8787+#ifdef CONFIG_PAX_RANDMMAP
8788+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8789+ info.low_limit += mm->delta_mmap;
8790+#endif
8791+
8792 info.high_limit = STACK_TOP32;
8793 addr = vm_unmapped_area(&info);
8794 }
8795@@ -264,6 +284,10 @@ static unsigned long mmap_rnd(void)
8796 {
8797 unsigned long rnd = 0UL;
8798
8799+#ifdef CONFIG_PAX_RANDMMAP
8800+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8801+#endif
8802+
8803 if (current->flags & PF_RANDOMIZE) {
8804 unsigned long val = get_random_int();
8805 if (test_thread_flag(TIF_32BIT))
8806@@ -289,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8807 gap == RLIM_INFINITY ||
8808 sysctl_legacy_va_layout) {
8809 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
8810+
8811+#ifdef CONFIG_PAX_RANDMMAP
8812+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8813+ mm->mmap_base += mm->delta_mmap;
8814+#endif
8815+
8816 mm->get_unmapped_area = arch_get_unmapped_area;
8817 mm->unmap_area = arch_unmap_area;
8818 } else {
8819@@ -301,6 +331,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8820 gap = (task_size / 6 * 5);
8821
8822 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
8823+
8824+#ifdef CONFIG_PAX_RANDMMAP
8825+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8826+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8827+#endif
8828+
8829 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8830 mm->unmap_area = arch_unmap_area_topdown;
8831 }
8832diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
8833index e0fed77..604a7e5 100644
8834--- a/arch/sparc/kernel/syscalls.S
8835+++ b/arch/sparc/kernel/syscalls.S
8836@@ -58,7 +58,7 @@ sys32_rt_sigreturn:
8837 #endif
8838 .align 32
8839 1: ldx [%g6 + TI_FLAGS], %l5
8840- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8841+ andcc %l5, _TIF_WORK_SYSCALL, %g0
8842 be,pt %icc, rtrap
8843 nop
8844 call syscall_trace_leave
8845@@ -190,7 +190,7 @@ linux_sparc_syscall32:
8846
8847 srl %i5, 0, %o5 ! IEU1
8848 srl %i2, 0, %o2 ! IEU0 Group
8849- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8850+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8851 bne,pn %icc, linux_syscall_trace32 ! CTI
8852 mov %i0, %l5 ! IEU1
8853 call %l7 ! CTI Group brk forced
8854@@ -213,7 +213,7 @@ linux_sparc_syscall:
8855
8856 mov %i3, %o3 ! IEU1
8857 mov %i4, %o4 ! IEU0 Group
8858- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8859+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8860 bne,pn %icc, linux_syscall_trace ! CTI Group
8861 mov %i0, %l5 ! IEU0
8862 2: call %l7 ! CTI Group brk forced
8863@@ -229,7 +229,7 @@ ret_sys_call:
8864
8865 cmp %o0, -ERESTART_RESTARTBLOCK
8866 bgeu,pn %xcc, 1f
8867- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8868+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8869 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
8870
8871 2:
8872diff --git a/arch/sparc/kernel/sysfs.c b/arch/sparc/kernel/sysfs.c
8873index 654e8aa..45f431b 100644
8874--- a/arch/sparc/kernel/sysfs.c
8875+++ b/arch/sparc/kernel/sysfs.c
8876@@ -266,7 +266,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
8877 return NOTIFY_OK;
8878 }
8879
8880-static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
8881+static struct notifier_block sysfs_cpu_nb = {
8882 .notifier_call = sysfs_cpu_notify,
8883 };
8884
8885diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
8886index a5785ea..405c5f7 100644
8887--- a/arch/sparc/kernel/traps_32.c
8888+++ b/arch/sparc/kernel/traps_32.c
8889@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
8890 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
8891 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
8892
8893+extern void gr_handle_kernel_exploit(void);
8894+
8895 void die_if_kernel(char *str, struct pt_regs *regs)
8896 {
8897 static int die_counter;
8898@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8899 count++ < 30 &&
8900 (((unsigned long) rw) >= PAGE_OFFSET) &&
8901 !(((unsigned long) rw) & 0x7)) {
8902- printk("Caller[%08lx]: %pS\n", rw->ins[7],
8903+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
8904 (void *) rw->ins[7]);
8905 rw = (struct reg_window32 *)rw->ins[6];
8906 }
8907 }
8908 printk("Instruction DUMP:");
8909 instruction_dump ((unsigned long *) regs->pc);
8910- if(regs->psr & PSR_PS)
8911+ if(regs->psr & PSR_PS) {
8912+ gr_handle_kernel_exploit();
8913 do_exit(SIGKILL);
8914+ }
8915 do_exit(SIGSEGV);
8916 }
8917
8918diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
8919index e7ecf15..6520e65 100644
8920--- a/arch/sparc/kernel/traps_64.c
8921+++ b/arch/sparc/kernel/traps_64.c
8922@@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
8923 i + 1,
8924 p->trapstack[i].tstate, p->trapstack[i].tpc,
8925 p->trapstack[i].tnpc, p->trapstack[i].tt);
8926- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
8927+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
8928 }
8929 }
8930
8931@@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
8932
8933 lvl -= 0x100;
8934 if (regs->tstate & TSTATE_PRIV) {
8935+
8936+#ifdef CONFIG_PAX_REFCOUNT
8937+ if (lvl == 6)
8938+ pax_report_refcount_overflow(regs);
8939+#endif
8940+
8941 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
8942 die_if_kernel(buffer, regs);
8943 }
8944@@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
8945 void bad_trap_tl1(struct pt_regs *regs, long lvl)
8946 {
8947 char buffer[32];
8948-
8949+
8950 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
8951 0, lvl, SIGTRAP) == NOTIFY_STOP)
8952 return;
8953
8954+#ifdef CONFIG_PAX_REFCOUNT
8955+ if (lvl == 6)
8956+ pax_report_refcount_overflow(regs);
8957+#endif
8958+
8959 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
8960
8961 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
8962@@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
8963 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
8964 printk("%s" "ERROR(%d): ",
8965 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
8966- printk("TPC<%pS>\n", (void *) regs->tpc);
8967+ printk("TPC<%pA>\n", (void *) regs->tpc);
8968 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
8969 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
8970 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
8971@@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8972 smp_processor_id(),
8973 (type & 0x1) ? 'I' : 'D',
8974 regs->tpc);
8975- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
8976+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
8977 panic("Irrecoverable Cheetah+ parity error.");
8978 }
8979
8980@@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8981 smp_processor_id(),
8982 (type & 0x1) ? 'I' : 'D',
8983 regs->tpc);
8984- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
8985+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
8986 }
8987
8988 struct sun4v_error_entry {
8989@@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
8990
8991 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
8992 regs->tpc, tl);
8993- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
8994+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
8995 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8996- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
8997+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
8998 (void *) regs->u_regs[UREG_I7]);
8999 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
9000 "pte[%lx] error[%lx]\n",
9001@@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
9002
9003 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
9004 regs->tpc, tl);
9005- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
9006+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
9007 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
9008- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
9009+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
9010 (void *) regs->u_regs[UREG_I7]);
9011 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
9012 "pte[%lx] error[%lx]\n",
9013@@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
9014 fp = (unsigned long)sf->fp + STACK_BIAS;
9015 }
9016
9017- printk(" [%016lx] %pS\n", pc, (void *) pc);
9018+ printk(" [%016lx] %pA\n", pc, (void *) pc);
9019 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
9020 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
9021 int index = tsk->curr_ret_stack;
9022 if (tsk->ret_stack && index >= graph) {
9023 pc = tsk->ret_stack[index - graph].ret;
9024- printk(" [%016lx] %pS\n", pc, (void *) pc);
9025+ printk(" [%016lx] %pA\n", pc, (void *) pc);
9026 graph++;
9027 }
9028 }
9029@@ -2367,6 +2378,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
9030 return (struct reg_window *) (fp + STACK_BIAS);
9031 }
9032
9033+extern void gr_handle_kernel_exploit(void);
9034+
9035 void die_if_kernel(char *str, struct pt_regs *regs)
9036 {
9037 static int die_counter;
9038@@ -2395,7 +2408,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
9039 while (rw &&
9040 count++ < 30 &&
9041 kstack_valid(tp, (unsigned long) rw)) {
9042- printk("Caller[%016lx]: %pS\n", rw->ins[7],
9043+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
9044 (void *) rw->ins[7]);
9045
9046 rw = kernel_stack_up(rw);
9047@@ -2408,8 +2421,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
9048 }
9049 user_instruction_dump ((unsigned int __user *) regs->tpc);
9050 }
9051- if (regs->tstate & TSTATE_PRIV)
9052+ if (regs->tstate & TSTATE_PRIV) {
9053+ gr_handle_kernel_exploit();
9054 do_exit(SIGKILL);
9055+ }
9056 do_exit(SIGSEGV);
9057 }
9058 EXPORT_SYMBOL(die_if_kernel);
9059diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
9060index 8201c25e..072a2a7 100644
9061--- a/arch/sparc/kernel/unaligned_64.c
9062+++ b/arch/sparc/kernel/unaligned_64.c
9063@@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
9064 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
9065
9066 if (__ratelimit(&ratelimit)) {
9067- printk("Kernel unaligned access at TPC[%lx] %pS\n",
9068+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
9069 regs->tpc, (void *) regs->tpc);
9070 }
9071 }
9072diff --git a/arch/sparc/kernel/us3_cpufreq.c b/arch/sparc/kernel/us3_cpufreq.c
9073index eb1624b..f9f4ddb 100644
9074--- a/arch/sparc/kernel/us3_cpufreq.c
9075+++ b/arch/sparc/kernel/us3_cpufreq.c
9076@@ -18,14 +18,12 @@
9077 #include <asm/head.h>
9078 #include <asm/timer.h>
9079
9080-static struct cpufreq_driver *cpufreq_us3_driver;
9081-
9082 struct us3_freq_percpu_info {
9083 struct cpufreq_frequency_table table[4];
9084 };
9085
9086 /* Indexed by cpu number. */
9087-static struct us3_freq_percpu_info *us3_freq_table;
9088+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
9089
9090 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
9091 * in the Safari config register.
9092@@ -191,12 +189,25 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
9093
9094 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
9095 {
9096- if (cpufreq_us3_driver)
9097- us3_set_cpu_divider_index(policy->cpu, 0);
9098+ us3_set_cpu_divider_index(policy->cpu, 0);
9099
9100 return 0;
9101 }
9102
9103+static int __init us3_freq_init(void);
9104+static void __exit us3_freq_exit(void);
9105+
9106+static struct cpufreq_driver cpufreq_us3_driver = {
9107+ .init = us3_freq_cpu_init,
9108+ .verify = us3_freq_verify,
9109+ .target = us3_freq_target,
9110+ .get = us3_freq_get,
9111+ .exit = us3_freq_cpu_exit,
9112+ .owner = THIS_MODULE,
9113+ .name = "UltraSPARC-III",
9114+
9115+};
9116+
9117 static int __init us3_freq_init(void)
9118 {
9119 unsigned long manuf, impl, ver;
9120@@ -213,57 +224,15 @@ static int __init us3_freq_init(void)
9121 (impl == CHEETAH_IMPL ||
9122 impl == CHEETAH_PLUS_IMPL ||
9123 impl == JAGUAR_IMPL ||
9124- impl == PANTHER_IMPL)) {
9125- struct cpufreq_driver *driver;
9126-
9127- ret = -ENOMEM;
9128- driver = kzalloc(sizeof(struct cpufreq_driver), GFP_KERNEL);
9129- if (!driver)
9130- goto err_out;
9131-
9132- us3_freq_table = kzalloc(
9133- (NR_CPUS * sizeof(struct us3_freq_percpu_info)),
9134- GFP_KERNEL);
9135- if (!us3_freq_table)
9136- goto err_out;
9137-
9138- driver->init = us3_freq_cpu_init;
9139- driver->verify = us3_freq_verify;
9140- driver->target = us3_freq_target;
9141- driver->get = us3_freq_get;
9142- driver->exit = us3_freq_cpu_exit;
9143- driver->owner = THIS_MODULE,
9144- strcpy(driver->name, "UltraSPARC-III");
9145-
9146- cpufreq_us3_driver = driver;
9147- ret = cpufreq_register_driver(driver);
9148- if (ret)
9149- goto err_out;
9150-
9151- return 0;
9152-
9153-err_out:
9154- if (driver) {
9155- kfree(driver);
9156- cpufreq_us3_driver = NULL;
9157- }
9158- kfree(us3_freq_table);
9159- us3_freq_table = NULL;
9160- return ret;
9161- }
9162+ impl == PANTHER_IMPL))
9163+ return cpufreq_register_driver(cpufreq_us3_driver);
9164
9165 return -ENODEV;
9166 }
9167
9168 static void __exit us3_freq_exit(void)
9169 {
9170- if (cpufreq_us3_driver) {
9171- cpufreq_unregister_driver(cpufreq_us3_driver);
9172- kfree(cpufreq_us3_driver);
9173- cpufreq_us3_driver = NULL;
9174- kfree(us3_freq_table);
9175- us3_freq_table = NULL;
9176- }
9177+ cpufreq_unregister_driver(cpufreq_us3_driver);
9178 }
9179
9180 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
9181diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
9182index 8410065f2..4fd4ca22 100644
9183--- a/arch/sparc/lib/Makefile
9184+++ b/arch/sparc/lib/Makefile
9185@@ -2,7 +2,7 @@
9186 #
9187
9188 asflags-y := -ansi -DST_DIV0=0x02
9189-ccflags-y := -Werror
9190+#ccflags-y := -Werror
9191
9192 lib-$(CONFIG_SPARC32) += ashrdi3.o
9193 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
9194diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
9195index 85c233d..68500e0 100644
9196--- a/arch/sparc/lib/atomic_64.S
9197+++ b/arch/sparc/lib/atomic_64.S
9198@@ -17,7 +17,12 @@
9199 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
9200 BACKOFF_SETUP(%o2)
9201 1: lduw [%o1], %g1
9202- add %g1, %o0, %g7
9203+ addcc %g1, %o0, %g7
9204+
9205+#ifdef CONFIG_PAX_REFCOUNT
9206+ tvs %icc, 6
9207+#endif
9208+
9209 cas [%o1], %g1, %g7
9210 cmp %g1, %g7
9211 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
9212@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
9213 2: BACKOFF_SPIN(%o2, %o3, 1b)
9214 ENDPROC(atomic_add)
9215
9216+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
9217+ BACKOFF_SETUP(%o2)
9218+1: lduw [%o1], %g1
9219+ add %g1, %o0, %g7
9220+ cas [%o1], %g1, %g7
9221+ cmp %g1, %g7
9222+ bne,pn %icc, 2f
9223+ nop
9224+ retl
9225+ nop
9226+2: BACKOFF_SPIN(%o2, %o3, 1b)
9227+ENDPROC(atomic_add_unchecked)
9228+
9229 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
9230 BACKOFF_SETUP(%o2)
9231 1: lduw [%o1], %g1
9232- sub %g1, %o0, %g7
9233+ subcc %g1, %o0, %g7
9234+
9235+#ifdef CONFIG_PAX_REFCOUNT
9236+ tvs %icc, 6
9237+#endif
9238+
9239 cas [%o1], %g1, %g7
9240 cmp %g1, %g7
9241 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
9242@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
9243 2: BACKOFF_SPIN(%o2, %o3, 1b)
9244 ENDPROC(atomic_sub)
9245
9246+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
9247+ BACKOFF_SETUP(%o2)
9248+1: lduw [%o1], %g1
9249+ sub %g1, %o0, %g7
9250+ cas [%o1], %g1, %g7
9251+ cmp %g1, %g7
9252+ bne,pn %icc, 2f
9253+ nop
9254+ retl
9255+ nop
9256+2: BACKOFF_SPIN(%o2, %o3, 1b)
9257+ENDPROC(atomic_sub_unchecked)
9258+
9259 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
9260 BACKOFF_SETUP(%o2)
9261 1: lduw [%o1], %g1
9262- add %g1, %o0, %g7
9263+ addcc %g1, %o0, %g7
9264+
9265+#ifdef CONFIG_PAX_REFCOUNT
9266+ tvs %icc, 6
9267+#endif
9268+
9269 cas [%o1], %g1, %g7
9270 cmp %g1, %g7
9271 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
9272@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
9273 2: BACKOFF_SPIN(%o2, %o3, 1b)
9274 ENDPROC(atomic_add_ret)
9275
9276+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
9277+ BACKOFF_SETUP(%o2)
9278+1: lduw [%o1], %g1
9279+ addcc %g1, %o0, %g7
9280+ cas [%o1], %g1, %g7
9281+ cmp %g1, %g7
9282+ bne,pn %icc, 2f
9283+ add %g7, %o0, %g7
9284+ sra %g7, 0, %o0
9285+ retl
9286+ nop
9287+2: BACKOFF_SPIN(%o2, %o3, 1b)
9288+ENDPROC(atomic_add_ret_unchecked)
9289+
9290 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
9291 BACKOFF_SETUP(%o2)
9292 1: lduw [%o1], %g1
9293- sub %g1, %o0, %g7
9294+ subcc %g1, %o0, %g7
9295+
9296+#ifdef CONFIG_PAX_REFCOUNT
9297+ tvs %icc, 6
9298+#endif
9299+
9300 cas [%o1], %g1, %g7
9301 cmp %g1, %g7
9302 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
9303@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
9304 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
9305 BACKOFF_SETUP(%o2)
9306 1: ldx [%o1], %g1
9307- add %g1, %o0, %g7
9308+ addcc %g1, %o0, %g7
9309+
9310+#ifdef CONFIG_PAX_REFCOUNT
9311+ tvs %xcc, 6
9312+#endif
9313+
9314 casx [%o1], %g1, %g7
9315 cmp %g1, %g7
9316 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9317@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
9318 2: BACKOFF_SPIN(%o2, %o3, 1b)
9319 ENDPROC(atomic64_add)
9320
9321+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
9322+ BACKOFF_SETUP(%o2)
9323+1: ldx [%o1], %g1
9324+ addcc %g1, %o0, %g7
9325+ casx [%o1], %g1, %g7
9326+ cmp %g1, %g7
9327+ bne,pn %xcc, 2f
9328+ nop
9329+ retl
9330+ nop
9331+2: BACKOFF_SPIN(%o2, %o3, 1b)
9332+ENDPROC(atomic64_add_unchecked)
9333+
9334 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
9335 BACKOFF_SETUP(%o2)
9336 1: ldx [%o1], %g1
9337- sub %g1, %o0, %g7
9338+ subcc %g1, %o0, %g7
9339+
9340+#ifdef CONFIG_PAX_REFCOUNT
9341+ tvs %xcc, 6
9342+#endif
9343+
9344 casx [%o1], %g1, %g7
9345 cmp %g1, %g7
9346 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9347@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
9348 2: BACKOFF_SPIN(%o2, %o3, 1b)
9349 ENDPROC(atomic64_sub)
9350
9351+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
9352+ BACKOFF_SETUP(%o2)
9353+1: ldx [%o1], %g1
9354+ subcc %g1, %o0, %g7
9355+ casx [%o1], %g1, %g7
9356+ cmp %g1, %g7
9357+ bne,pn %xcc, 2f
9358+ nop
9359+ retl
9360+ nop
9361+2: BACKOFF_SPIN(%o2, %o3, 1b)
9362+ENDPROC(atomic64_sub_unchecked)
9363+
9364 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
9365 BACKOFF_SETUP(%o2)
9366 1: ldx [%o1], %g1
9367- add %g1, %o0, %g7
9368+ addcc %g1, %o0, %g7
9369+
9370+#ifdef CONFIG_PAX_REFCOUNT
9371+ tvs %xcc, 6
9372+#endif
9373+
9374 casx [%o1], %g1, %g7
9375 cmp %g1, %g7
9376 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9377@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
9378 2: BACKOFF_SPIN(%o2, %o3, 1b)
9379 ENDPROC(atomic64_add_ret)
9380
9381+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
9382+ BACKOFF_SETUP(%o2)
9383+1: ldx [%o1], %g1
9384+ addcc %g1, %o0, %g7
9385+ casx [%o1], %g1, %g7
9386+ cmp %g1, %g7
9387+ bne,pn %xcc, 2f
9388+ add %g7, %o0, %g7
9389+ mov %g7, %o0
9390+ retl
9391+ nop
9392+2: BACKOFF_SPIN(%o2, %o3, 1b)
9393+ENDPROC(atomic64_add_ret_unchecked)
9394+
9395 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
9396 BACKOFF_SETUP(%o2)
9397 1: ldx [%o1], %g1
9398- sub %g1, %o0, %g7
9399+ subcc %g1, %o0, %g7
9400+
9401+#ifdef CONFIG_PAX_REFCOUNT
9402+ tvs %xcc, 6
9403+#endif
9404+
9405 casx [%o1], %g1, %g7
9406 cmp %g1, %g7
9407 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9408diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
9409index 0c4e35e..745d3e4 100644
9410--- a/arch/sparc/lib/ksyms.c
9411+++ b/arch/sparc/lib/ksyms.c
9412@@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
9413
9414 /* Atomic counter implementation. */
9415 EXPORT_SYMBOL(atomic_add);
9416+EXPORT_SYMBOL(atomic_add_unchecked);
9417 EXPORT_SYMBOL(atomic_add_ret);
9418+EXPORT_SYMBOL(atomic_add_ret_unchecked);
9419 EXPORT_SYMBOL(atomic_sub);
9420+EXPORT_SYMBOL(atomic_sub_unchecked);
9421 EXPORT_SYMBOL(atomic_sub_ret);
9422 EXPORT_SYMBOL(atomic64_add);
9423+EXPORT_SYMBOL(atomic64_add_unchecked);
9424 EXPORT_SYMBOL(atomic64_add_ret);
9425+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
9426 EXPORT_SYMBOL(atomic64_sub);
9427+EXPORT_SYMBOL(atomic64_sub_unchecked);
9428 EXPORT_SYMBOL(atomic64_sub_ret);
9429 EXPORT_SYMBOL(atomic64_dec_if_positive);
9430
9431diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
9432index 30c3ecc..736f015 100644
9433--- a/arch/sparc/mm/Makefile
9434+++ b/arch/sparc/mm/Makefile
9435@@ -2,7 +2,7 @@
9436 #
9437
9438 asflags-y := -ansi
9439-ccflags-y := -Werror
9440+#ccflags-y := -Werror
9441
9442 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
9443 obj-y += fault_$(BITS).o
9444diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
9445index e98bfda..ea8d221 100644
9446--- a/arch/sparc/mm/fault_32.c
9447+++ b/arch/sparc/mm/fault_32.c
9448@@ -21,6 +21,9 @@
9449 #include <linux/perf_event.h>
9450 #include <linux/interrupt.h>
9451 #include <linux/kdebug.h>
9452+#include <linux/slab.h>
9453+#include <linux/pagemap.h>
9454+#include <linux/compiler.h>
9455
9456 #include <asm/page.h>
9457 #include <asm/pgtable.h>
9458@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
9459 return safe_compute_effective_address(regs, insn);
9460 }
9461
9462+#ifdef CONFIG_PAX_PAGEEXEC
9463+#ifdef CONFIG_PAX_DLRESOLVE
9464+static void pax_emuplt_close(struct vm_area_struct *vma)
9465+{
9466+ vma->vm_mm->call_dl_resolve = 0UL;
9467+}
9468+
9469+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9470+{
9471+ unsigned int *kaddr;
9472+
9473+ vmf->page = alloc_page(GFP_HIGHUSER);
9474+ if (!vmf->page)
9475+ return VM_FAULT_OOM;
9476+
9477+ kaddr = kmap(vmf->page);
9478+ memset(kaddr, 0, PAGE_SIZE);
9479+ kaddr[0] = 0x9DE3BFA8U; /* save */
9480+ flush_dcache_page(vmf->page);
9481+ kunmap(vmf->page);
9482+ return VM_FAULT_MAJOR;
9483+}
9484+
9485+static const struct vm_operations_struct pax_vm_ops = {
9486+ .close = pax_emuplt_close,
9487+ .fault = pax_emuplt_fault
9488+};
9489+
9490+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
9491+{
9492+ int ret;
9493+
9494+ INIT_LIST_HEAD(&vma->anon_vma_chain);
9495+ vma->vm_mm = current->mm;
9496+ vma->vm_start = addr;
9497+ vma->vm_end = addr + PAGE_SIZE;
9498+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
9499+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
9500+ vma->vm_ops = &pax_vm_ops;
9501+
9502+ ret = insert_vm_struct(current->mm, vma);
9503+ if (ret)
9504+ return ret;
9505+
9506+ ++current->mm->total_vm;
9507+ return 0;
9508+}
9509+#endif
9510+
9511+/*
9512+ * PaX: decide what to do with offenders (regs->pc = fault address)
9513+ *
9514+ * returns 1 when task should be killed
9515+ * 2 when patched PLT trampoline was detected
9516+ * 3 when unpatched PLT trampoline was detected
9517+ */
9518+static int pax_handle_fetch_fault(struct pt_regs *regs)
9519+{
9520+
9521+#ifdef CONFIG_PAX_EMUPLT
9522+ int err;
9523+
9524+ do { /* PaX: patched PLT emulation #1 */
9525+ unsigned int sethi1, sethi2, jmpl;
9526+
9527+ err = get_user(sethi1, (unsigned int *)regs->pc);
9528+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
9529+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
9530+
9531+ if (err)
9532+ break;
9533+
9534+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
9535+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
9536+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
9537+ {
9538+ unsigned int addr;
9539+
9540+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
9541+ addr = regs->u_regs[UREG_G1];
9542+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9543+ regs->pc = addr;
9544+ regs->npc = addr+4;
9545+ return 2;
9546+ }
9547+ } while (0);
9548+
9549+ do { /* PaX: patched PLT emulation #2 */
9550+ unsigned int ba;
9551+
9552+ err = get_user(ba, (unsigned int *)regs->pc);
9553+
9554+ if (err)
9555+ break;
9556+
9557+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
9558+ unsigned int addr;
9559+
9560+ if ((ba & 0xFFC00000U) == 0x30800000U)
9561+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
9562+ else
9563+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9564+ regs->pc = addr;
9565+ regs->npc = addr+4;
9566+ return 2;
9567+ }
9568+ } while (0);
9569+
9570+ do { /* PaX: patched PLT emulation #3 */
9571+ unsigned int sethi, bajmpl, nop;
9572+
9573+ err = get_user(sethi, (unsigned int *)regs->pc);
9574+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
9575+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
9576+
9577+ if (err)
9578+ break;
9579+
9580+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9581+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
9582+ nop == 0x01000000U)
9583+ {
9584+ unsigned int addr;
9585+
9586+ addr = (sethi & 0x003FFFFFU) << 10;
9587+ regs->u_regs[UREG_G1] = addr;
9588+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
9589+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9590+ else
9591+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9592+ regs->pc = addr;
9593+ regs->npc = addr+4;
9594+ return 2;
9595+ }
9596+ } while (0);
9597+
9598+ do { /* PaX: unpatched PLT emulation step 1 */
9599+ unsigned int sethi, ba, nop;
9600+
9601+ err = get_user(sethi, (unsigned int *)regs->pc);
9602+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
9603+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
9604+
9605+ if (err)
9606+ break;
9607+
9608+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9609+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
9610+ nop == 0x01000000U)
9611+ {
9612+ unsigned int addr, save, call;
9613+
9614+ if ((ba & 0xFFC00000U) == 0x30800000U)
9615+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
9616+ else
9617+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9618+
9619+ err = get_user(save, (unsigned int *)addr);
9620+ err |= get_user(call, (unsigned int *)(addr+4));
9621+ err |= get_user(nop, (unsigned int *)(addr+8));
9622+ if (err)
9623+ break;
9624+
9625+#ifdef CONFIG_PAX_DLRESOLVE
9626+ if (save == 0x9DE3BFA8U &&
9627+ (call & 0xC0000000U) == 0x40000000U &&
9628+ nop == 0x01000000U)
9629+ {
9630+ struct vm_area_struct *vma;
9631+ unsigned long call_dl_resolve;
9632+
9633+ down_read(&current->mm->mmap_sem);
9634+ call_dl_resolve = current->mm->call_dl_resolve;
9635+ up_read(&current->mm->mmap_sem);
9636+ if (likely(call_dl_resolve))
9637+ goto emulate;
9638+
9639+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
9640+
9641+ down_write(&current->mm->mmap_sem);
9642+ if (current->mm->call_dl_resolve) {
9643+ call_dl_resolve = current->mm->call_dl_resolve;
9644+ up_write(&current->mm->mmap_sem);
9645+ if (vma)
9646+ kmem_cache_free(vm_area_cachep, vma);
9647+ goto emulate;
9648+ }
9649+
9650+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
9651+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
9652+ up_write(&current->mm->mmap_sem);
9653+ if (vma)
9654+ kmem_cache_free(vm_area_cachep, vma);
9655+ return 1;
9656+ }
9657+
9658+ if (pax_insert_vma(vma, call_dl_resolve)) {
9659+ up_write(&current->mm->mmap_sem);
9660+ kmem_cache_free(vm_area_cachep, vma);
9661+ return 1;
9662+ }
9663+
9664+ current->mm->call_dl_resolve = call_dl_resolve;
9665+ up_write(&current->mm->mmap_sem);
9666+
9667+emulate:
9668+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9669+ regs->pc = call_dl_resolve;
9670+ regs->npc = addr+4;
9671+ return 3;
9672+ }
9673+#endif
9674+
9675+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
9676+ if ((save & 0xFFC00000U) == 0x05000000U &&
9677+ (call & 0xFFFFE000U) == 0x85C0A000U &&
9678+ nop == 0x01000000U)
9679+ {
9680+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9681+ regs->u_regs[UREG_G2] = addr + 4;
9682+ addr = (save & 0x003FFFFFU) << 10;
9683+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9684+ regs->pc = addr;
9685+ regs->npc = addr+4;
9686+ return 3;
9687+ }
9688+ }
9689+ } while (0);
9690+
9691+ do { /* PaX: unpatched PLT emulation step 2 */
9692+ unsigned int save, call, nop;
9693+
9694+ err = get_user(save, (unsigned int *)(regs->pc-4));
9695+ err |= get_user(call, (unsigned int *)regs->pc);
9696+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
9697+ if (err)
9698+ break;
9699+
9700+ if (save == 0x9DE3BFA8U &&
9701+ (call & 0xC0000000U) == 0x40000000U &&
9702+ nop == 0x01000000U)
9703+ {
9704+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
9705+
9706+ regs->u_regs[UREG_RETPC] = regs->pc;
9707+ regs->pc = dl_resolve;
9708+ regs->npc = dl_resolve+4;
9709+ return 3;
9710+ }
9711+ } while (0);
9712+#endif
9713+
9714+ return 1;
9715+}
9716+
9717+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9718+{
9719+ unsigned long i;
9720+
9721+ printk(KERN_ERR "PAX: bytes at PC: ");
9722+ for (i = 0; i < 8; i++) {
9723+ unsigned int c;
9724+ if (get_user(c, (unsigned int *)pc+i))
9725+ printk(KERN_CONT "???????? ");
9726+ else
9727+ printk(KERN_CONT "%08x ", c);
9728+ }
9729+ printk("\n");
9730+}
9731+#endif
9732+
9733 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
9734 int text_fault)
9735 {
9736@@ -230,6 +504,24 @@ good_area:
9737 if (!(vma->vm_flags & VM_WRITE))
9738 goto bad_area;
9739 } else {
9740+
9741+#ifdef CONFIG_PAX_PAGEEXEC
9742+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
9743+ up_read(&mm->mmap_sem);
9744+ switch (pax_handle_fetch_fault(regs)) {
9745+
9746+#ifdef CONFIG_PAX_EMUPLT
9747+ case 2:
9748+ case 3:
9749+ return;
9750+#endif
9751+
9752+ }
9753+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
9754+ do_group_exit(SIGKILL);
9755+ }
9756+#endif
9757+
9758 /* Allow reads even for write-only mappings */
9759 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
9760 goto bad_area;
9761diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
9762index 5062ff3..e0b75f3 100644
9763--- a/arch/sparc/mm/fault_64.c
9764+++ b/arch/sparc/mm/fault_64.c
9765@@ -21,6 +21,9 @@
9766 #include <linux/kprobes.h>
9767 #include <linux/kdebug.h>
9768 #include <linux/percpu.h>
9769+#include <linux/slab.h>
9770+#include <linux/pagemap.h>
9771+#include <linux/compiler.h>
9772
9773 #include <asm/page.h>
9774 #include <asm/pgtable.h>
9775@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
9776 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
9777 regs->tpc);
9778 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
9779- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
9780+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
9781 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
9782 dump_stack();
9783 unhandled_fault(regs->tpc, current, regs);
9784@@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
9785 show_regs(regs);
9786 }
9787
9788+#ifdef CONFIG_PAX_PAGEEXEC
9789+#ifdef CONFIG_PAX_DLRESOLVE
9790+static void pax_emuplt_close(struct vm_area_struct *vma)
9791+{
9792+ vma->vm_mm->call_dl_resolve = 0UL;
9793+}
9794+
9795+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9796+{
9797+ unsigned int *kaddr;
9798+
9799+ vmf->page = alloc_page(GFP_HIGHUSER);
9800+ if (!vmf->page)
9801+ return VM_FAULT_OOM;
9802+
9803+ kaddr = kmap(vmf->page);
9804+ memset(kaddr, 0, PAGE_SIZE);
9805+ kaddr[0] = 0x9DE3BFA8U; /* save */
9806+ flush_dcache_page(vmf->page);
9807+ kunmap(vmf->page);
9808+ return VM_FAULT_MAJOR;
9809+}
9810+
9811+static const struct vm_operations_struct pax_vm_ops = {
9812+ .close = pax_emuplt_close,
9813+ .fault = pax_emuplt_fault
9814+};
9815+
9816+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
9817+{
9818+ int ret;
9819+
9820+ INIT_LIST_HEAD(&vma->anon_vma_chain);
9821+ vma->vm_mm = current->mm;
9822+ vma->vm_start = addr;
9823+ vma->vm_end = addr + PAGE_SIZE;
9824+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
9825+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
9826+ vma->vm_ops = &pax_vm_ops;
9827+
9828+ ret = insert_vm_struct(current->mm, vma);
9829+ if (ret)
9830+ return ret;
9831+
9832+ ++current->mm->total_vm;
9833+ return 0;
9834+}
9835+#endif
9836+
9837+/*
9838+ * PaX: decide what to do with offenders (regs->tpc = fault address)
9839+ *
9840+ * returns 1 when task should be killed
9841+ * 2 when patched PLT trampoline was detected
9842+ * 3 when unpatched PLT trampoline was detected
9843+ */
9844+static int pax_handle_fetch_fault(struct pt_regs *regs)
9845+{
9846+
9847+#ifdef CONFIG_PAX_EMUPLT
9848+ int err;
9849+
9850+ do { /* PaX: patched PLT emulation #1 */
9851+ unsigned int sethi1, sethi2, jmpl;
9852+
9853+ err = get_user(sethi1, (unsigned int *)regs->tpc);
9854+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
9855+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
9856+
9857+ if (err)
9858+ break;
9859+
9860+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
9861+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
9862+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
9863+ {
9864+ unsigned long addr;
9865+
9866+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
9867+ addr = regs->u_regs[UREG_G1];
9868+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9869+
9870+ if (test_thread_flag(TIF_32BIT))
9871+ addr &= 0xFFFFFFFFUL;
9872+
9873+ regs->tpc = addr;
9874+ regs->tnpc = addr+4;
9875+ return 2;
9876+ }
9877+ } while (0);
9878+
9879+ do { /* PaX: patched PLT emulation #2 */
9880+ unsigned int ba;
9881+
9882+ err = get_user(ba, (unsigned int *)regs->tpc);
9883+
9884+ if (err)
9885+ break;
9886+
9887+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
9888+ unsigned long addr;
9889+
9890+ if ((ba & 0xFFC00000U) == 0x30800000U)
9891+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9892+ else
9893+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9894+
9895+ if (test_thread_flag(TIF_32BIT))
9896+ addr &= 0xFFFFFFFFUL;
9897+
9898+ regs->tpc = addr;
9899+ regs->tnpc = addr+4;
9900+ return 2;
9901+ }
9902+ } while (0);
9903+
9904+ do { /* PaX: patched PLT emulation #3 */
9905+ unsigned int sethi, bajmpl, nop;
9906+
9907+ err = get_user(sethi, (unsigned int *)regs->tpc);
9908+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
9909+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9910+
9911+ if (err)
9912+ break;
9913+
9914+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9915+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
9916+ nop == 0x01000000U)
9917+ {
9918+ unsigned long addr;
9919+
9920+ addr = (sethi & 0x003FFFFFU) << 10;
9921+ regs->u_regs[UREG_G1] = addr;
9922+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
9923+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9924+ else
9925+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9926+
9927+ if (test_thread_flag(TIF_32BIT))
9928+ addr &= 0xFFFFFFFFUL;
9929+
9930+ regs->tpc = addr;
9931+ regs->tnpc = addr+4;
9932+ return 2;
9933+ }
9934+ } while (0);
9935+
9936+ do { /* PaX: patched PLT emulation #4 */
9937+ unsigned int sethi, mov1, call, mov2;
9938+
9939+ err = get_user(sethi, (unsigned int *)regs->tpc);
9940+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
9941+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
9942+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
9943+
9944+ if (err)
9945+ break;
9946+
9947+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9948+ mov1 == 0x8210000FU &&
9949+ (call & 0xC0000000U) == 0x40000000U &&
9950+ mov2 == 0x9E100001U)
9951+ {
9952+ unsigned long addr;
9953+
9954+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
9955+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9956+
9957+ if (test_thread_flag(TIF_32BIT))
9958+ addr &= 0xFFFFFFFFUL;
9959+
9960+ regs->tpc = addr;
9961+ regs->tnpc = addr+4;
9962+ return 2;
9963+ }
9964+ } while (0);
9965+
9966+ do { /* PaX: patched PLT emulation #5 */
9967+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
9968+
9969+ err = get_user(sethi, (unsigned int *)regs->tpc);
9970+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9971+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9972+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
9973+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
9974+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
9975+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
9976+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
9977+
9978+ if (err)
9979+ break;
9980+
9981+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9982+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
9983+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9984+ (or1 & 0xFFFFE000U) == 0x82106000U &&
9985+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
9986+ sllx == 0x83287020U &&
9987+ jmpl == 0x81C04005U &&
9988+ nop == 0x01000000U)
9989+ {
9990+ unsigned long addr;
9991+
9992+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9993+ regs->u_regs[UREG_G1] <<= 32;
9994+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9995+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9996+ regs->tpc = addr;
9997+ regs->tnpc = addr+4;
9998+ return 2;
9999+ }
10000+ } while (0);
10001+
10002+ do { /* PaX: patched PLT emulation #6 */
10003+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
10004+
10005+ err = get_user(sethi, (unsigned int *)regs->tpc);
10006+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
10007+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
10008+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
10009+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
10010+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
10011+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
10012+
10013+ if (err)
10014+ break;
10015+
10016+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10017+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
10018+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
10019+ sllx == 0x83287020U &&
10020+ (or & 0xFFFFE000U) == 0x8A116000U &&
10021+ jmpl == 0x81C04005U &&
10022+ nop == 0x01000000U)
10023+ {
10024+ unsigned long addr;
10025+
10026+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
10027+ regs->u_regs[UREG_G1] <<= 32;
10028+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
10029+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
10030+ regs->tpc = addr;
10031+ regs->tnpc = addr+4;
10032+ return 2;
10033+ }
10034+ } while (0);
10035+
10036+ do { /* PaX: unpatched PLT emulation step 1 */
10037+ unsigned int sethi, ba, nop;
10038+
10039+ err = get_user(sethi, (unsigned int *)regs->tpc);
10040+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
10041+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
10042+
10043+ if (err)
10044+ break;
10045+
10046+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10047+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
10048+ nop == 0x01000000U)
10049+ {
10050+ unsigned long addr;
10051+ unsigned int save, call;
10052+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
10053+
10054+ if ((ba & 0xFFC00000U) == 0x30800000U)
10055+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
10056+ else
10057+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10058+
10059+ if (test_thread_flag(TIF_32BIT))
10060+ addr &= 0xFFFFFFFFUL;
10061+
10062+ err = get_user(save, (unsigned int *)addr);
10063+ err |= get_user(call, (unsigned int *)(addr+4));
10064+ err |= get_user(nop, (unsigned int *)(addr+8));
10065+ if (err)
10066+ break;
10067+
10068+#ifdef CONFIG_PAX_DLRESOLVE
10069+ if (save == 0x9DE3BFA8U &&
10070+ (call & 0xC0000000U) == 0x40000000U &&
10071+ nop == 0x01000000U)
10072+ {
10073+ struct vm_area_struct *vma;
10074+ unsigned long call_dl_resolve;
10075+
10076+ down_read(&current->mm->mmap_sem);
10077+ call_dl_resolve = current->mm->call_dl_resolve;
10078+ up_read(&current->mm->mmap_sem);
10079+ if (likely(call_dl_resolve))
10080+ goto emulate;
10081+
10082+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
10083+
10084+ down_write(&current->mm->mmap_sem);
10085+ if (current->mm->call_dl_resolve) {
10086+ call_dl_resolve = current->mm->call_dl_resolve;
10087+ up_write(&current->mm->mmap_sem);
10088+ if (vma)
10089+ kmem_cache_free(vm_area_cachep, vma);
10090+ goto emulate;
10091+ }
10092+
10093+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
10094+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
10095+ up_write(&current->mm->mmap_sem);
10096+ if (vma)
10097+ kmem_cache_free(vm_area_cachep, vma);
10098+ return 1;
10099+ }
10100+
10101+ if (pax_insert_vma(vma, call_dl_resolve)) {
10102+ up_write(&current->mm->mmap_sem);
10103+ kmem_cache_free(vm_area_cachep, vma);
10104+ return 1;
10105+ }
10106+
10107+ current->mm->call_dl_resolve = call_dl_resolve;
10108+ up_write(&current->mm->mmap_sem);
10109+
10110+emulate:
10111+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10112+ regs->tpc = call_dl_resolve;
10113+ regs->tnpc = addr+4;
10114+ return 3;
10115+ }
10116+#endif
10117+
10118+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
10119+ if ((save & 0xFFC00000U) == 0x05000000U &&
10120+ (call & 0xFFFFE000U) == 0x85C0A000U &&
10121+ nop == 0x01000000U)
10122+ {
10123+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10124+ regs->u_regs[UREG_G2] = addr + 4;
10125+ addr = (save & 0x003FFFFFU) << 10;
10126+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10127+
10128+ if (test_thread_flag(TIF_32BIT))
10129+ addr &= 0xFFFFFFFFUL;
10130+
10131+ regs->tpc = addr;
10132+ regs->tnpc = addr+4;
10133+ return 3;
10134+ }
10135+
10136+ /* PaX: 64-bit PLT stub */
10137+ err = get_user(sethi1, (unsigned int *)addr);
10138+ err |= get_user(sethi2, (unsigned int *)(addr+4));
10139+ err |= get_user(or1, (unsigned int *)(addr+8));
10140+ err |= get_user(or2, (unsigned int *)(addr+12));
10141+ err |= get_user(sllx, (unsigned int *)(addr+16));
10142+ err |= get_user(add, (unsigned int *)(addr+20));
10143+ err |= get_user(jmpl, (unsigned int *)(addr+24));
10144+ err |= get_user(nop, (unsigned int *)(addr+28));
10145+ if (err)
10146+ break;
10147+
10148+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
10149+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
10150+ (or1 & 0xFFFFE000U) == 0x88112000U &&
10151+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
10152+ sllx == 0x89293020U &&
10153+ add == 0x8A010005U &&
10154+ jmpl == 0x89C14000U &&
10155+ nop == 0x01000000U)
10156+ {
10157+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10158+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
10159+ regs->u_regs[UREG_G4] <<= 32;
10160+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
10161+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
10162+ regs->u_regs[UREG_G4] = addr + 24;
10163+ addr = regs->u_regs[UREG_G5];
10164+ regs->tpc = addr;
10165+ regs->tnpc = addr+4;
10166+ return 3;
10167+ }
10168+ }
10169+ } while (0);
10170+
10171+#ifdef CONFIG_PAX_DLRESOLVE
10172+ do { /* PaX: unpatched PLT emulation step 2 */
10173+ unsigned int save, call, nop;
10174+
10175+ err = get_user(save, (unsigned int *)(regs->tpc-4));
10176+ err |= get_user(call, (unsigned int *)regs->tpc);
10177+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
10178+ if (err)
10179+ break;
10180+
10181+ if (save == 0x9DE3BFA8U &&
10182+ (call & 0xC0000000U) == 0x40000000U &&
10183+ nop == 0x01000000U)
10184+ {
10185+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
10186+
10187+ if (test_thread_flag(TIF_32BIT))
10188+ dl_resolve &= 0xFFFFFFFFUL;
10189+
10190+ regs->u_regs[UREG_RETPC] = regs->tpc;
10191+ regs->tpc = dl_resolve;
10192+ regs->tnpc = dl_resolve+4;
10193+ return 3;
10194+ }
10195+ } while (0);
10196+#endif
10197+
10198+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
10199+ unsigned int sethi, ba, nop;
10200+
10201+ err = get_user(sethi, (unsigned int *)regs->tpc);
10202+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
10203+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
10204+
10205+ if (err)
10206+ break;
10207+
10208+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10209+ (ba & 0xFFF00000U) == 0x30600000U &&
10210+ nop == 0x01000000U)
10211+ {
10212+ unsigned long addr;
10213+
10214+ addr = (sethi & 0x003FFFFFU) << 10;
10215+ regs->u_regs[UREG_G1] = addr;
10216+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10217+
10218+ if (test_thread_flag(TIF_32BIT))
10219+ addr &= 0xFFFFFFFFUL;
10220+
10221+ regs->tpc = addr;
10222+ regs->tnpc = addr+4;
10223+ return 2;
10224+ }
10225+ } while (0);
10226+
10227+#endif
10228+
10229+ return 1;
10230+}
10231+
10232+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
10233+{
10234+ unsigned long i;
10235+
10236+ printk(KERN_ERR "PAX: bytes at PC: ");
10237+ for (i = 0; i < 8; i++) {
10238+ unsigned int c;
10239+ if (get_user(c, (unsigned int *)pc+i))
10240+ printk(KERN_CONT "???????? ");
10241+ else
10242+ printk(KERN_CONT "%08x ", c);
10243+ }
10244+ printk("\n");
10245+}
10246+#endif
10247+
10248 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
10249 {
10250 struct mm_struct *mm = current->mm;
10251@@ -341,6 +804,29 @@ retry:
10252 if (!vma)
10253 goto bad_area;
10254
10255+#ifdef CONFIG_PAX_PAGEEXEC
10256+ /* PaX: detect ITLB misses on non-exec pages */
10257+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
10258+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
10259+ {
10260+ if (address != regs->tpc)
10261+ goto good_area;
10262+
10263+ up_read(&mm->mmap_sem);
10264+ switch (pax_handle_fetch_fault(regs)) {
10265+
10266+#ifdef CONFIG_PAX_EMUPLT
10267+ case 2:
10268+ case 3:
10269+ return;
10270+#endif
10271+
10272+ }
10273+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
10274+ do_group_exit(SIGKILL);
10275+ }
10276+#endif
10277+
10278 /* Pure DTLB misses do not tell us whether the fault causing
10279 * load/store/atomic was a write or not, it only says that there
10280 * was no match. So in such a case we (carefully) read the
10281diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
10282index d2b5944..bd813f2 100644
10283--- a/arch/sparc/mm/hugetlbpage.c
10284+++ b/arch/sparc/mm/hugetlbpage.c
10285@@ -38,7 +38,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
10286
10287 info.flags = 0;
10288 info.length = len;
10289- info.low_limit = TASK_UNMAPPED_BASE;
10290+ info.low_limit = mm->mmap_base;
10291 info.high_limit = min(task_size, VA_EXCLUDE_START);
10292 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
10293 info.align_offset = 0;
10294@@ -47,6 +47,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
10295 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10296 VM_BUG_ON(addr != -ENOMEM);
10297 info.low_limit = VA_EXCLUDE_END;
10298+
10299+#ifdef CONFIG_PAX_RANDMMAP
10300+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10301+ info.low_limit += mm->delta_mmap;
10302+#endif
10303+
10304 info.high_limit = task_size;
10305 addr = vm_unmapped_area(&info);
10306 }
10307@@ -85,6 +91,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10308 VM_BUG_ON(addr != -ENOMEM);
10309 info.flags = 0;
10310 info.low_limit = TASK_UNMAPPED_BASE;
10311+
10312+#ifdef CONFIG_PAX_RANDMMAP
10313+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10314+ info.low_limit += mm->delta_mmap;
10315+#endif
10316+
10317 info.high_limit = STACK_TOP32;
10318 addr = vm_unmapped_area(&info);
10319 }
10320@@ -99,6 +111,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
10321 struct mm_struct *mm = current->mm;
10322 struct vm_area_struct *vma;
10323 unsigned long task_size = TASK_SIZE;
10324+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
10325
10326 if (test_thread_flag(TIF_32BIT))
10327 task_size = STACK_TOP32;
10328@@ -114,11 +127,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
10329 return addr;
10330 }
10331
10332+#ifdef CONFIG_PAX_RANDMMAP
10333+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10334+#endif
10335+
10336 if (addr) {
10337 addr = ALIGN(addr, HPAGE_SIZE);
10338 vma = find_vma(mm, addr);
10339- if (task_size - len >= addr &&
10340- (!vma || addr + len <= vma->vm_start))
10341+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10342 return addr;
10343 }
10344 if (mm->get_unmapped_area == arch_get_unmapped_area)
10345diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
10346index f4500c6..889656c 100644
10347--- a/arch/tile/include/asm/atomic_64.h
10348+++ b/arch/tile/include/asm/atomic_64.h
10349@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
10350
10351 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10352
10353+#define atomic64_read_unchecked(v) atomic64_read(v)
10354+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
10355+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
10356+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
10357+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
10358+#define atomic64_inc_unchecked(v) atomic64_inc(v)
10359+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
10360+#define atomic64_dec_unchecked(v) atomic64_dec(v)
10361+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
10362+
10363 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
10364 #define smp_mb__before_atomic_dec() smp_mb()
10365 #define smp_mb__after_atomic_dec() smp_mb()
10366diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
10367index a9a5299..0fce79e 100644
10368--- a/arch/tile/include/asm/cache.h
10369+++ b/arch/tile/include/asm/cache.h
10370@@ -15,11 +15,12 @@
10371 #ifndef _ASM_TILE_CACHE_H
10372 #define _ASM_TILE_CACHE_H
10373
10374+#include <linux/const.h>
10375 #include <arch/chip.h>
10376
10377 /* bytes per L1 data cache line */
10378 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
10379-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10380+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10381
10382 /* bytes per L2 cache line */
10383 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
10384diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
10385index 9ab078a..d6635c2 100644
10386--- a/arch/tile/include/asm/uaccess.h
10387+++ b/arch/tile/include/asm/uaccess.h
10388@@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
10389 const void __user *from,
10390 unsigned long n)
10391 {
10392- int sz = __compiletime_object_size(to);
10393+ size_t sz = __compiletime_object_size(to);
10394
10395- if (likely(sz == -1 || sz >= n))
10396+ if (likely(sz == (size_t)-1 || sz >= n))
10397 n = _copy_from_user(to, from, n);
10398 else
10399 copy_from_user_overflow();
10400diff --git a/arch/um/Makefile b/arch/um/Makefile
10401index 133f7de..1d6f2f1 100644
10402--- a/arch/um/Makefile
10403+++ b/arch/um/Makefile
10404@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
10405 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
10406 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
10407
10408+ifdef CONSTIFY_PLUGIN
10409+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10410+endif
10411+
10412 #This will adjust *FLAGS accordingly to the platform.
10413 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
10414
10415diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
10416index 19e1bdd..3665b77 100644
10417--- a/arch/um/include/asm/cache.h
10418+++ b/arch/um/include/asm/cache.h
10419@@ -1,6 +1,7 @@
10420 #ifndef __UM_CACHE_H
10421 #define __UM_CACHE_H
10422
10423+#include <linux/const.h>
10424
10425 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
10426 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10427@@ -12,6 +13,6 @@
10428 # define L1_CACHE_SHIFT 5
10429 #endif
10430
10431-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10432+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10433
10434 #endif
10435diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
10436index 2e0a6b1..a64d0f5 100644
10437--- a/arch/um/include/asm/kmap_types.h
10438+++ b/arch/um/include/asm/kmap_types.h
10439@@ -8,6 +8,6 @@
10440
10441 /* No more #include "asm/arch/kmap_types.h" ! */
10442
10443-#define KM_TYPE_NR 14
10444+#define KM_TYPE_NR 15
10445
10446 #endif
10447diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
10448index 5ff53d9..5850cdf 100644
10449--- a/arch/um/include/asm/page.h
10450+++ b/arch/um/include/asm/page.h
10451@@ -14,6 +14,9 @@
10452 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
10453 #define PAGE_MASK (~(PAGE_SIZE-1))
10454
10455+#define ktla_ktva(addr) (addr)
10456+#define ktva_ktla(addr) (addr)
10457+
10458 #ifndef __ASSEMBLY__
10459
10460 struct page;
10461diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
10462index 0032f92..cd151e0 100644
10463--- a/arch/um/include/asm/pgtable-3level.h
10464+++ b/arch/um/include/asm/pgtable-3level.h
10465@@ -58,6 +58,7 @@
10466 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
10467 #define pud_populate(mm, pud, pmd) \
10468 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
10469+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
10470
10471 #ifdef CONFIG_64BIT
10472 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
10473diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
10474index b462b13..e7a19aa 100644
10475--- a/arch/um/kernel/process.c
10476+++ b/arch/um/kernel/process.c
10477@@ -386,22 +386,6 @@ int singlestepping(void * t)
10478 return 2;
10479 }
10480
10481-/*
10482- * Only x86 and x86_64 have an arch_align_stack().
10483- * All other arches have "#define arch_align_stack(x) (x)"
10484- * in their asm/system.h
10485- * As this is included in UML from asm-um/system-generic.h,
10486- * we can use it to behave as the subarch does.
10487- */
10488-#ifndef arch_align_stack
10489-unsigned long arch_align_stack(unsigned long sp)
10490-{
10491- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
10492- sp -= get_random_int() % 8192;
10493- return sp & ~0xf;
10494-}
10495-#endif
10496-
10497 unsigned long get_wchan(struct task_struct *p)
10498 {
10499 unsigned long stack_page, sp, ip;
10500diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
10501index ad8f795..2c7eec6 100644
10502--- a/arch/unicore32/include/asm/cache.h
10503+++ b/arch/unicore32/include/asm/cache.h
10504@@ -12,8 +12,10 @@
10505 #ifndef __UNICORE_CACHE_H__
10506 #define __UNICORE_CACHE_H__
10507
10508-#define L1_CACHE_SHIFT (5)
10509-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10510+#include <linux/const.h>
10511+
10512+#define L1_CACHE_SHIFT 5
10513+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10514
10515 /*
10516 * Memory returned by kmalloc() may be used for DMA, so we must make
10517diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
10518index 0694d09..58ea1a1 100644
10519--- a/arch/x86/Kconfig
10520+++ b/arch/x86/Kconfig
10521@@ -238,7 +238,7 @@ config X86_HT
10522
10523 config X86_32_LAZY_GS
10524 def_bool y
10525- depends on X86_32 && !CC_STACKPROTECTOR
10526+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
10527
10528 config ARCH_HWEIGHT_CFLAGS
10529 string
10530@@ -1031,6 +1031,7 @@ config MICROCODE_OLD_INTERFACE
10531
10532 config X86_MSR
10533 tristate "/dev/cpu/*/msr - Model-specific register support"
10534+ depends on !GRKERNSEC_KMEM
10535 ---help---
10536 This device gives privileged processes access to the x86
10537 Model-Specific Registers (MSRs). It is a character device with
10538@@ -1054,7 +1055,7 @@ choice
10539
10540 config NOHIGHMEM
10541 bool "off"
10542- depends on !X86_NUMAQ
10543+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
10544 ---help---
10545 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
10546 However, the address space of 32-bit x86 processors is only 4
10547@@ -1091,7 +1092,7 @@ config NOHIGHMEM
10548
10549 config HIGHMEM4G
10550 bool "4GB"
10551- depends on !X86_NUMAQ
10552+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
10553 ---help---
10554 Select this if you have a 32-bit processor and between 1 and 4
10555 gigabytes of physical RAM.
10556@@ -1145,7 +1146,7 @@ config PAGE_OFFSET
10557 hex
10558 default 0xB0000000 if VMSPLIT_3G_OPT
10559 default 0x80000000 if VMSPLIT_2G
10560- default 0x78000000 if VMSPLIT_2G_OPT
10561+ default 0x70000000 if VMSPLIT_2G_OPT
10562 default 0x40000000 if VMSPLIT_1G
10563 default 0xC0000000
10564 depends on X86_32
10565@@ -1542,6 +1543,7 @@ config SECCOMP
10566
10567 config CC_STACKPROTECTOR
10568 bool "Enable -fstack-protector buffer overflow detection"
10569+ depends on X86_64 || !PAX_MEMORY_UDEREF
10570 ---help---
10571 This option turns on the -fstack-protector GCC feature. This
10572 feature puts, at the beginning of functions, a canary value on
10573@@ -1662,6 +1664,8 @@ config X86_NEED_RELOCS
10574 config PHYSICAL_ALIGN
10575 hex "Alignment value to which kernel should be aligned" if X86_32
10576 default "0x1000000"
10577+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
10578+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
10579 range 0x2000 0x1000000
10580 ---help---
10581 This value puts the alignment restrictions on physical address
10582@@ -1737,9 +1741,10 @@ config DEBUG_HOTPLUG_CPU0
10583 If unsure, say N.
10584
10585 config COMPAT_VDSO
10586- def_bool y
10587+ def_bool n
10588 prompt "Compat VDSO support"
10589 depends on X86_32 || IA32_EMULATION
10590+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
10591 ---help---
10592 Map the 32-bit VDSO to the predictable old-style address too.
10593
10594diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
10595index c026cca..14657ae 100644
10596--- a/arch/x86/Kconfig.cpu
10597+++ b/arch/x86/Kconfig.cpu
10598@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
10599
10600 config X86_F00F_BUG
10601 def_bool y
10602- depends on M586MMX || M586TSC || M586 || M486
10603+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
10604
10605 config X86_INVD_BUG
10606 def_bool y
10607@@ -327,7 +327,7 @@ config X86_INVD_BUG
10608
10609 config X86_ALIGNMENT_16
10610 def_bool y
10611- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
10612+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
10613
10614 config X86_INTEL_USERCOPY
10615 def_bool y
10616@@ -373,7 +373,7 @@ config X86_CMPXCHG64
10617 # generates cmov.
10618 config X86_CMOV
10619 def_bool y
10620- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
10621+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
10622
10623 config X86_MINIMUM_CPU_FAMILY
10624 int
10625diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
10626index b322f12..652d0d9 100644
10627--- a/arch/x86/Kconfig.debug
10628+++ b/arch/x86/Kconfig.debug
10629@@ -84,7 +84,7 @@ config X86_PTDUMP
10630 config DEBUG_RODATA
10631 bool "Write protect kernel read-only data structures"
10632 default y
10633- depends on DEBUG_KERNEL
10634+ depends on DEBUG_KERNEL && BROKEN
10635 ---help---
10636 Mark the kernel read-only data as write-protected in the pagetables,
10637 in order to catch accidental (and incorrect) writes to such const
10638@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
10639
10640 config DEBUG_SET_MODULE_RONX
10641 bool "Set loadable kernel module data as NX and text as RO"
10642- depends on MODULES
10643+ depends on MODULES && BROKEN
10644 ---help---
10645 This option helps catch unintended modifications to loadable
10646 kernel module's text and read-only data. It also prevents execution
10647@@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
10648
10649 config DEBUG_STRICT_USER_COPY_CHECKS
10650 bool "Strict copy size checks"
10651- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
10652+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
10653 ---help---
10654 Enabling this option turns a certain set of sanity checks for user
10655 copy operations into compile time failures.
10656diff --git a/arch/x86/Makefile b/arch/x86/Makefile
10657index e71fc42..7829607 100644
10658--- a/arch/x86/Makefile
10659+++ b/arch/x86/Makefile
10660@@ -50,6 +50,7 @@ else
10661 UTS_MACHINE := x86_64
10662 CHECKFLAGS += -D__x86_64__ -m64
10663
10664+ biarch := $(call cc-option,-m64)
10665 KBUILD_AFLAGS += -m64
10666 KBUILD_CFLAGS += -m64
10667
10668@@ -230,3 +231,12 @@ define archhelp
10669 echo ' FDARGS="..." arguments for the booted kernel'
10670 echo ' FDINITRD=file initrd for the booted kernel'
10671 endef
10672+
10673+define OLD_LD
10674+
10675+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
10676+*** Please upgrade your binutils to 2.18 or newer
10677+endef
10678+
10679+archprepare:
10680+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
10681diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
10682index 379814b..add62ce 100644
10683--- a/arch/x86/boot/Makefile
10684+++ b/arch/x86/boot/Makefile
10685@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
10686 $(call cc-option, -fno-stack-protector) \
10687 $(call cc-option, -mpreferred-stack-boundary=2)
10688 KBUILD_CFLAGS += $(call cc-option, -m32)
10689+ifdef CONSTIFY_PLUGIN
10690+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10691+endif
10692 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10693 GCOV_PROFILE := n
10694
10695diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
10696index 878e4b9..20537ab 100644
10697--- a/arch/x86/boot/bitops.h
10698+++ b/arch/x86/boot/bitops.h
10699@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10700 u8 v;
10701 const u32 *p = (const u32 *)addr;
10702
10703- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10704+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10705 return v;
10706 }
10707
10708@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10709
10710 static inline void set_bit(int nr, void *addr)
10711 {
10712- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10713+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10714 }
10715
10716 #endif /* BOOT_BITOPS_H */
10717diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
10718index 18997e5..83d9c67 100644
10719--- a/arch/x86/boot/boot.h
10720+++ b/arch/x86/boot/boot.h
10721@@ -85,7 +85,7 @@ static inline void io_delay(void)
10722 static inline u16 ds(void)
10723 {
10724 u16 seg;
10725- asm("movw %%ds,%0" : "=rm" (seg));
10726+ asm volatile("movw %%ds,%0" : "=rm" (seg));
10727 return seg;
10728 }
10729
10730@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
10731 static inline int memcmp(const void *s1, const void *s2, size_t len)
10732 {
10733 u8 diff;
10734- asm("repe; cmpsb; setnz %0"
10735+ asm volatile("repe; cmpsb; setnz %0"
10736 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
10737 return diff;
10738 }
10739diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
10740index 5ef205c..342191d 100644
10741--- a/arch/x86/boot/compressed/Makefile
10742+++ b/arch/x86/boot/compressed/Makefile
10743@@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
10744 KBUILD_CFLAGS += $(cflags-y)
10745 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
10746 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
10747+ifdef CONSTIFY_PLUGIN
10748+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10749+endif
10750
10751 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10752 GCOV_PROFILE := n
10753diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
10754index c205035..5853587 100644
10755--- a/arch/x86/boot/compressed/eboot.c
10756+++ b/arch/x86/boot/compressed/eboot.c
10757@@ -150,7 +150,6 @@ again:
10758 *addr = max_addr;
10759 }
10760
10761-free_pool:
10762 efi_call_phys1(sys_table->boottime->free_pool, map);
10763
10764 fail:
10765@@ -214,7 +213,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
10766 if (i == map_size / desc_size)
10767 status = EFI_NOT_FOUND;
10768
10769-free_pool:
10770 efi_call_phys1(sys_table->boottime->free_pool, map);
10771 fail:
10772 return status;
10773diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
10774index 1e3184f..0d11e2e 100644
10775--- a/arch/x86/boot/compressed/head_32.S
10776+++ b/arch/x86/boot/compressed/head_32.S
10777@@ -118,7 +118,7 @@ preferred_addr:
10778 notl %eax
10779 andl %eax, %ebx
10780 #else
10781- movl $LOAD_PHYSICAL_ADDR, %ebx
10782+ movl $____LOAD_PHYSICAL_ADDR, %ebx
10783 #endif
10784
10785 /* Target address to relocate to for decompression */
10786@@ -204,7 +204,7 @@ relocated:
10787 * and where it was actually loaded.
10788 */
10789 movl %ebp, %ebx
10790- subl $LOAD_PHYSICAL_ADDR, %ebx
10791+ subl $____LOAD_PHYSICAL_ADDR, %ebx
10792 jz 2f /* Nothing to be done if loaded at compiled addr. */
10793 /*
10794 * Process relocations.
10795@@ -212,8 +212,7 @@ relocated:
10796
10797 1: subl $4, %edi
10798 movl (%edi), %ecx
10799- testl %ecx, %ecx
10800- jz 2f
10801+ jecxz 2f
10802 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
10803 jmp 1b
10804 2:
10805diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
10806index f5d1aaa..cce11dc 100644
10807--- a/arch/x86/boot/compressed/head_64.S
10808+++ b/arch/x86/boot/compressed/head_64.S
10809@@ -91,7 +91,7 @@ ENTRY(startup_32)
10810 notl %eax
10811 andl %eax, %ebx
10812 #else
10813- movl $LOAD_PHYSICAL_ADDR, %ebx
10814+ movl $____LOAD_PHYSICAL_ADDR, %ebx
10815 #endif
10816
10817 /* Target address to relocate to for decompression */
10818@@ -273,7 +273,7 @@ preferred_addr:
10819 notq %rax
10820 andq %rax, %rbp
10821 #else
10822- movq $LOAD_PHYSICAL_ADDR, %rbp
10823+ movq $____LOAD_PHYSICAL_ADDR, %rbp
10824 #endif
10825
10826 /* Target address to relocate to for decompression */
10827diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
10828index 88f7ff6..ed695dd 100644
10829--- a/arch/x86/boot/compressed/misc.c
10830+++ b/arch/x86/boot/compressed/misc.c
10831@@ -303,7 +303,7 @@ static void parse_elf(void *output)
10832 case PT_LOAD:
10833 #ifdef CONFIG_RELOCATABLE
10834 dest = output;
10835- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
10836+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
10837 #else
10838 dest = (void *)(phdr->p_paddr);
10839 #endif
10840@@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
10841 error("Destination address too large");
10842 #endif
10843 #ifndef CONFIG_RELOCATABLE
10844- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
10845+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
10846 error("Wrong destination address");
10847 #endif
10848
10849diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
10850index 4d3ff03..e4972ff 100644
10851--- a/arch/x86/boot/cpucheck.c
10852+++ b/arch/x86/boot/cpucheck.c
10853@@ -74,7 +74,7 @@ static int has_fpu(void)
10854 u16 fcw = -1, fsw = -1;
10855 u32 cr0;
10856
10857- asm("movl %%cr0,%0" : "=r" (cr0));
10858+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
10859 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
10860 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
10861 asm volatile("movl %0,%%cr0" : : "r" (cr0));
10862@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
10863 {
10864 u32 f0, f1;
10865
10866- asm("pushfl ; "
10867+ asm volatile("pushfl ; "
10868 "pushfl ; "
10869 "popl %0 ; "
10870 "movl %0,%1 ; "
10871@@ -115,7 +115,7 @@ static void get_flags(void)
10872 set_bit(X86_FEATURE_FPU, cpu.flags);
10873
10874 if (has_eflag(X86_EFLAGS_ID)) {
10875- asm("cpuid"
10876+ asm volatile("cpuid"
10877 : "=a" (max_intel_level),
10878 "=b" (cpu_vendor[0]),
10879 "=d" (cpu_vendor[1]),
10880@@ -124,7 +124,7 @@ static void get_flags(void)
10881
10882 if (max_intel_level >= 0x00000001 &&
10883 max_intel_level <= 0x0000ffff) {
10884- asm("cpuid"
10885+ asm volatile("cpuid"
10886 : "=a" (tfms),
10887 "=c" (cpu.flags[4]),
10888 "=d" (cpu.flags[0])
10889@@ -136,7 +136,7 @@ static void get_flags(void)
10890 cpu.model += ((tfms >> 16) & 0xf) << 4;
10891 }
10892
10893- asm("cpuid"
10894+ asm volatile("cpuid"
10895 : "=a" (max_amd_level)
10896 : "a" (0x80000000)
10897 : "ebx", "ecx", "edx");
10898@@ -144,7 +144,7 @@ static void get_flags(void)
10899 if (max_amd_level >= 0x80000001 &&
10900 max_amd_level <= 0x8000ffff) {
10901 u32 eax = 0x80000001;
10902- asm("cpuid"
10903+ asm volatile("cpuid"
10904 : "+a" (eax),
10905 "=c" (cpu.flags[6]),
10906 "=d" (cpu.flags[1])
10907@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10908 u32 ecx = MSR_K7_HWCR;
10909 u32 eax, edx;
10910
10911- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10912+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10913 eax &= ~(1 << 15);
10914- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10915+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10916
10917 get_flags(); /* Make sure it really did something */
10918 err = check_flags();
10919@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10920 u32 ecx = MSR_VIA_FCR;
10921 u32 eax, edx;
10922
10923- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10924+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10925 eax |= (1<<1)|(1<<7);
10926- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10927+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10928
10929 set_bit(X86_FEATURE_CX8, cpu.flags);
10930 err = check_flags();
10931@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10932 u32 eax, edx;
10933 u32 level = 1;
10934
10935- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10936- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10937- asm("cpuid"
10938+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10939+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10940+ asm volatile("cpuid"
10941 : "+a" (level), "=d" (cpu.flags[0])
10942 : : "ecx", "ebx");
10943- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10944+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10945
10946 err = check_flags();
10947 }
10948diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
10949index 944ce59..87ee37a 100644
10950--- a/arch/x86/boot/header.S
10951+++ b/arch/x86/boot/header.S
10952@@ -401,10 +401,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
10953 # single linked list of
10954 # struct setup_data
10955
10956-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
10957+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
10958
10959 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
10960+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
10961+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
10962+#else
10963 #define VO_INIT_SIZE (VO__end - VO__text)
10964+#endif
10965 #if ZO_INIT_SIZE > VO_INIT_SIZE
10966 #define INIT_SIZE ZO_INIT_SIZE
10967 #else
10968diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
10969index db75d07..8e6d0af 100644
10970--- a/arch/x86/boot/memory.c
10971+++ b/arch/x86/boot/memory.c
10972@@ -19,7 +19,7 @@
10973
10974 static int detect_memory_e820(void)
10975 {
10976- int count = 0;
10977+ unsigned int count = 0;
10978 struct biosregs ireg, oreg;
10979 struct e820entry *desc = boot_params.e820_map;
10980 static struct e820entry buf; /* static so it is zeroed */
10981diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
10982index 11e8c6e..fdbb1ed 100644
10983--- a/arch/x86/boot/video-vesa.c
10984+++ b/arch/x86/boot/video-vesa.c
10985@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
10986
10987 boot_params.screen_info.vesapm_seg = oreg.es;
10988 boot_params.screen_info.vesapm_off = oreg.di;
10989+ boot_params.screen_info.vesapm_size = oreg.cx;
10990 }
10991
10992 /*
10993diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
10994index 43eda28..5ab5fdb 100644
10995--- a/arch/x86/boot/video.c
10996+++ b/arch/x86/boot/video.c
10997@@ -96,7 +96,7 @@ static void store_mode_params(void)
10998 static unsigned int get_entry(void)
10999 {
11000 char entry_buf[4];
11001- int i, len = 0;
11002+ unsigned int i, len = 0;
11003 int key;
11004 unsigned int v;
11005
11006diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
11007index 5b577d5..3c1fed4 100644
11008--- a/arch/x86/crypto/aes-x86_64-asm_64.S
11009+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
11010@@ -8,6 +8,8 @@
11011 * including this sentence is retained in full.
11012 */
11013
11014+#include <asm/alternative-asm.h>
11015+
11016 .extern crypto_ft_tab
11017 .extern crypto_it_tab
11018 .extern crypto_fl_tab
11019@@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
11020 je B192; \
11021 leaq 32(r9),r9;
11022
11023+#define ret pax_force_retaddr 0, 1; ret
11024+
11025 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
11026 movq r1,r2; \
11027 movq r3,r4; \
11028diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
11029index 3470624..201259d 100644
11030--- a/arch/x86/crypto/aesni-intel_asm.S
11031+++ b/arch/x86/crypto/aesni-intel_asm.S
11032@@ -31,6 +31,7 @@
11033
11034 #include <linux/linkage.h>
11035 #include <asm/inst.h>
11036+#include <asm/alternative-asm.h>
11037
11038 #ifdef __x86_64__
11039 .data
11040@@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
11041 pop %r14
11042 pop %r13
11043 pop %r12
11044+ pax_force_retaddr 0, 1
11045 ret
11046+ENDPROC(aesni_gcm_dec)
11047
11048
11049 /*****************************************************************************
11050@@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
11051 pop %r14
11052 pop %r13
11053 pop %r12
11054+ pax_force_retaddr 0, 1
11055 ret
11056+ENDPROC(aesni_gcm_enc)
11057
11058 #endif
11059
11060@@ -1714,6 +1719,7 @@ _key_expansion_256a:
11061 pxor %xmm1, %xmm0
11062 movaps %xmm0, (TKEYP)
11063 add $0x10, TKEYP
11064+ pax_force_retaddr_bts
11065 ret
11066
11067 .align 4
11068@@ -1738,6 +1744,7 @@ _key_expansion_192a:
11069 shufps $0b01001110, %xmm2, %xmm1
11070 movaps %xmm1, 0x10(TKEYP)
11071 add $0x20, TKEYP
11072+ pax_force_retaddr_bts
11073 ret
11074
11075 .align 4
11076@@ -1757,6 +1764,7 @@ _key_expansion_192b:
11077
11078 movaps %xmm0, (TKEYP)
11079 add $0x10, TKEYP
11080+ pax_force_retaddr_bts
11081 ret
11082
11083 .align 4
11084@@ -1769,6 +1777,7 @@ _key_expansion_256b:
11085 pxor %xmm1, %xmm2
11086 movaps %xmm2, (TKEYP)
11087 add $0x10, TKEYP
11088+ pax_force_retaddr_bts
11089 ret
11090
11091 /*
11092@@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
11093 #ifndef __x86_64__
11094 popl KEYP
11095 #endif
11096+ pax_force_retaddr 0, 1
11097 ret
11098+ENDPROC(aesni_set_key)
11099
11100 /*
11101 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
11102@@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
11103 popl KLEN
11104 popl KEYP
11105 #endif
11106+ pax_force_retaddr 0, 1
11107 ret
11108+ENDPROC(aesni_enc)
11109
11110 /*
11111 * _aesni_enc1: internal ABI
11112@@ -1959,6 +1972,7 @@ _aesni_enc1:
11113 AESENC KEY STATE
11114 movaps 0x70(TKEYP), KEY
11115 AESENCLAST KEY STATE
11116+ pax_force_retaddr_bts
11117 ret
11118
11119 /*
11120@@ -2067,6 +2081,7 @@ _aesni_enc4:
11121 AESENCLAST KEY STATE2
11122 AESENCLAST KEY STATE3
11123 AESENCLAST KEY STATE4
11124+ pax_force_retaddr_bts
11125 ret
11126
11127 /*
11128@@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
11129 popl KLEN
11130 popl KEYP
11131 #endif
11132+ pax_force_retaddr 0, 1
11133 ret
11134+ENDPROC(aesni_dec)
11135
11136 /*
11137 * _aesni_dec1: internal ABI
11138@@ -2146,6 +2163,7 @@ _aesni_dec1:
11139 AESDEC KEY STATE
11140 movaps 0x70(TKEYP), KEY
11141 AESDECLAST KEY STATE
11142+ pax_force_retaddr_bts
11143 ret
11144
11145 /*
11146@@ -2254,6 +2272,7 @@ _aesni_dec4:
11147 AESDECLAST KEY STATE2
11148 AESDECLAST KEY STATE3
11149 AESDECLAST KEY STATE4
11150+ pax_force_retaddr_bts
11151 ret
11152
11153 /*
11154@@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
11155 popl KEYP
11156 popl LEN
11157 #endif
11158+ pax_force_retaddr 0, 1
11159 ret
11160+ENDPROC(aesni_ecb_enc)
11161
11162 /*
11163 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
11164@@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
11165 popl KEYP
11166 popl LEN
11167 #endif
11168+ pax_force_retaddr 0, 1
11169 ret
11170+ENDPROC(aesni_ecb_dec)
11171
11172 /*
11173 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
11174@@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
11175 popl LEN
11176 popl IVP
11177 #endif
11178+ pax_force_retaddr 0, 1
11179 ret
11180+ENDPROC(aesni_cbc_enc)
11181
11182 /*
11183 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
11184@@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
11185 popl LEN
11186 popl IVP
11187 #endif
11188+ pax_force_retaddr 0, 1
11189 ret
11190+ENDPROC(aesni_cbc_dec)
11191
11192 #ifdef __x86_64__
11193 .align 16
11194@@ -2526,6 +2553,7 @@ _aesni_inc_init:
11195 mov $1, TCTR_LOW
11196 MOVQ_R64_XMM TCTR_LOW INC
11197 MOVQ_R64_XMM CTR TCTR_LOW
11198+ pax_force_retaddr_bts
11199 ret
11200
11201 /*
11202@@ -2554,6 +2582,7 @@ _aesni_inc:
11203 .Linc_low:
11204 movaps CTR, IV
11205 PSHUFB_XMM BSWAP_MASK IV
11206+ pax_force_retaddr_bts
11207 ret
11208
11209 /*
11210@@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
11211 .Lctr_enc_ret:
11212 movups IV, (IVP)
11213 .Lctr_enc_just_ret:
11214+ pax_force_retaddr 0, 1
11215 ret
11216+ENDPROC(aesni_ctr_enc)
11217 #endif
11218diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
11219index 391d245..67f35c2 100644
11220--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
11221+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
11222@@ -20,6 +20,8 @@
11223 *
11224 */
11225
11226+#include <asm/alternative-asm.h>
11227+
11228 .file "blowfish-x86_64-asm.S"
11229 .text
11230
11231@@ -151,9 +153,11 @@ __blowfish_enc_blk:
11232 jnz __enc_xor;
11233
11234 write_block();
11235+ pax_force_retaddr 0, 1
11236 ret;
11237 __enc_xor:
11238 xor_block();
11239+ pax_force_retaddr 0, 1
11240 ret;
11241
11242 .align 8
11243@@ -188,6 +192,7 @@ blowfish_dec_blk:
11244
11245 movq %r11, %rbp;
11246
11247+ pax_force_retaddr 0, 1
11248 ret;
11249
11250 /**********************************************************************
11251@@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
11252
11253 popq %rbx;
11254 popq %rbp;
11255+ pax_force_retaddr 0, 1
11256 ret;
11257
11258 __enc_xor4:
11259@@ -349,6 +355,7 @@ __enc_xor4:
11260
11261 popq %rbx;
11262 popq %rbp;
11263+ pax_force_retaddr 0, 1
11264 ret;
11265
11266 .align 8
11267@@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
11268 popq %rbx;
11269 popq %rbp;
11270
11271+ pax_force_retaddr 0, 1
11272 ret;
11273
11274diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
11275index 0b33743..7a56206 100644
11276--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
11277+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
11278@@ -20,6 +20,8 @@
11279 *
11280 */
11281
11282+#include <asm/alternative-asm.h>
11283+
11284 .file "camellia-x86_64-asm_64.S"
11285 .text
11286
11287@@ -229,12 +231,14 @@ __enc_done:
11288 enc_outunpack(mov, RT1);
11289
11290 movq RRBP, %rbp;
11291+ pax_force_retaddr 0, 1
11292 ret;
11293
11294 __enc_xor:
11295 enc_outunpack(xor, RT1);
11296
11297 movq RRBP, %rbp;
11298+ pax_force_retaddr 0, 1
11299 ret;
11300
11301 .global camellia_dec_blk;
11302@@ -275,6 +279,7 @@ __dec_rounds16:
11303 dec_outunpack();
11304
11305 movq RRBP, %rbp;
11306+ pax_force_retaddr 0, 1
11307 ret;
11308
11309 /**********************************************************************
11310@@ -468,6 +473,7 @@ __enc2_done:
11311
11312 movq RRBP, %rbp;
11313 popq %rbx;
11314+ pax_force_retaddr 0, 1
11315 ret;
11316
11317 __enc2_xor:
11318@@ -475,6 +481,7 @@ __enc2_xor:
11319
11320 movq RRBP, %rbp;
11321 popq %rbx;
11322+ pax_force_retaddr 0, 1
11323 ret;
11324
11325 .global camellia_dec_blk_2way;
11326@@ -517,4 +524,5 @@ __dec2_rounds16:
11327
11328 movq RRBP, %rbp;
11329 movq RXOR, %rbx;
11330+ pax_force_retaddr 0, 1
11331 ret;
11332diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
11333index 15b00ac..2071784 100644
11334--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
11335+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
11336@@ -23,6 +23,8 @@
11337 *
11338 */
11339
11340+#include <asm/alternative-asm.h>
11341+
11342 .file "cast5-avx-x86_64-asm_64.S"
11343
11344 .extern cast_s1
11345@@ -281,6 +283,7 @@ __skip_enc:
11346 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
11347 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
11348
11349+ pax_force_retaddr 0, 1
11350 ret;
11351
11352 .align 16
11353@@ -353,6 +356,7 @@ __dec_tail:
11354 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
11355 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
11356
11357+ pax_force_retaddr 0, 1
11358 ret;
11359
11360 __skip_dec:
11361@@ -392,6 +396,7 @@ cast5_ecb_enc_16way:
11362 vmovdqu RR4, (6*4*4)(%r11);
11363 vmovdqu RL4, (7*4*4)(%r11);
11364
11365+ pax_force_retaddr
11366 ret;
11367
11368 .align 16
11369@@ -427,6 +432,7 @@ cast5_ecb_dec_16way:
11370 vmovdqu RR4, (6*4*4)(%r11);
11371 vmovdqu RL4, (7*4*4)(%r11);
11372
11373+ pax_force_retaddr
11374 ret;
11375
11376 .align 16
11377@@ -479,6 +485,7 @@ cast5_cbc_dec_16way:
11378
11379 popq %r12;
11380
11381+ pax_force_retaddr
11382 ret;
11383
11384 .align 16
11385@@ -555,4 +562,5 @@ cast5_ctr_16way:
11386
11387 popq %r12;
11388
11389+ pax_force_retaddr
11390 ret;
11391diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11392index 2569d0d..637c289 100644
11393--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11394+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11395@@ -23,6 +23,8 @@
11396 *
11397 */
11398
11399+#include <asm/alternative-asm.h>
11400+
11401 #include "glue_helper-asm-avx.S"
11402
11403 .file "cast6-avx-x86_64-asm_64.S"
11404@@ -294,6 +296,7 @@ __cast6_enc_blk8:
11405 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
11406 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
11407
11408+ pax_force_retaddr 0, 1
11409 ret;
11410
11411 .align 8
11412@@ -340,6 +343,7 @@ __cast6_dec_blk8:
11413 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
11414 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
11415
11416+ pax_force_retaddr 0, 1
11417 ret;
11418
11419 .align 8
11420@@ -361,6 +365,7 @@ cast6_ecb_enc_8way:
11421
11422 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11423
11424+ pax_force_retaddr
11425 ret;
11426
11427 .align 8
11428@@ -382,6 +387,7 @@ cast6_ecb_dec_8way:
11429
11430 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11431
11432+ pax_force_retaddr
11433 ret;
11434
11435 .align 8
11436@@ -408,6 +414,7 @@ cast6_cbc_dec_8way:
11437
11438 popq %r12;
11439
11440+ pax_force_retaddr
11441 ret;
11442
11443 .align 8
11444@@ -436,4 +443,5 @@ cast6_ctr_8way:
11445
11446 popq %r12;
11447
11448+ pax_force_retaddr
11449 ret;
11450diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
11451index 6214a9b..1f4fc9a 100644
11452--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
11453+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
11454@@ -1,3 +1,5 @@
11455+#include <asm/alternative-asm.h>
11456+
11457 # enter ECRYPT_encrypt_bytes
11458 .text
11459 .p2align 5
11460@@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
11461 add %r11,%rsp
11462 mov %rdi,%rax
11463 mov %rsi,%rdx
11464+ pax_force_retaddr 0, 1
11465 ret
11466 # bytesatleast65:
11467 ._bytesatleast65:
11468@@ -891,6 +894,7 @@ ECRYPT_keysetup:
11469 add %r11,%rsp
11470 mov %rdi,%rax
11471 mov %rsi,%rdx
11472+ pax_force_retaddr
11473 ret
11474 # enter ECRYPT_ivsetup
11475 .text
11476@@ -917,4 +921,5 @@ ECRYPT_ivsetup:
11477 add %r11,%rsp
11478 mov %rdi,%rax
11479 mov %rsi,%rdx
11480+ pax_force_retaddr
11481 ret
11482diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11483index 02b0e9f..cf4cf5c 100644
11484--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11485+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11486@@ -24,6 +24,8 @@
11487 *
11488 */
11489
11490+#include <asm/alternative-asm.h>
11491+
11492 #include "glue_helper-asm-avx.S"
11493
11494 .file "serpent-avx-x86_64-asm_64.S"
11495@@ -618,6 +620,7 @@ __serpent_enc_blk8_avx:
11496 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11497 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11498
11499+ pax_force_retaddr
11500 ret;
11501
11502 .align 8
11503@@ -673,6 +676,7 @@ __serpent_dec_blk8_avx:
11504 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
11505 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
11506
11507+ pax_force_retaddr
11508 ret;
11509
11510 .align 8
11511@@ -692,6 +696,7 @@ serpent_ecb_enc_8way_avx:
11512
11513 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11514
11515+ pax_force_retaddr
11516 ret;
11517
11518 .align 8
11519@@ -711,6 +716,7 @@ serpent_ecb_dec_8way_avx:
11520
11521 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
11522
11523+ pax_force_retaddr
11524 ret;
11525
11526 .align 8
11527@@ -730,6 +736,7 @@ serpent_cbc_dec_8way_avx:
11528
11529 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
11530
11531+ pax_force_retaddr
11532 ret;
11533
11534 .align 8
11535@@ -751,4 +758,5 @@ serpent_ctr_8way_avx:
11536
11537 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11538
11539+ pax_force_retaddr
11540 ret;
11541diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11542index 3ee1ff0..cbc568b 100644
11543--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11544+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11545@@ -24,6 +24,8 @@
11546 *
11547 */
11548
11549+#include <asm/alternative-asm.h>
11550+
11551 .file "serpent-sse2-x86_64-asm_64.S"
11552 .text
11553
11554@@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
11555 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11556 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11557
11558+ pax_force_retaddr
11559 ret;
11560
11561 __enc_xor8:
11562 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11563 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11564
11565+ pax_force_retaddr
11566 ret;
11567
11568 .align 8
11569@@ -755,4 +759,5 @@ serpent_dec_blk_8way:
11570 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
11571 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
11572
11573+ pax_force_retaddr
11574 ret;
11575diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
11576index 49d6987..df66bd4 100644
11577--- a/arch/x86/crypto/sha1_ssse3_asm.S
11578+++ b/arch/x86/crypto/sha1_ssse3_asm.S
11579@@ -28,6 +28,8 @@
11580 * (at your option) any later version.
11581 */
11582
11583+#include <asm/alternative-asm.h>
11584+
11585 #define CTX %rdi // arg1
11586 #define BUF %rsi // arg2
11587 #define CNT %rdx // arg3
11588@@ -104,6 +106,7 @@
11589 pop %r12
11590 pop %rbp
11591 pop %rbx
11592+ pax_force_retaddr 0, 1
11593 ret
11594
11595 .size \name, .-\name
11596diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11597index ebac16b..8092eb9 100644
11598--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11599+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11600@@ -23,6 +23,8 @@
11601 *
11602 */
11603
11604+#include <asm/alternative-asm.h>
11605+
11606 #include "glue_helper-asm-avx.S"
11607
11608 .file "twofish-avx-x86_64-asm_64.S"
11609@@ -283,6 +285,7 @@ __twofish_enc_blk8:
11610 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
11611 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
11612
11613+ pax_force_retaddr 0, 1
11614 ret;
11615
11616 .align 8
11617@@ -324,6 +327,7 @@ __twofish_dec_blk8:
11618 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
11619 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
11620
11621+ pax_force_retaddr 0, 1
11622 ret;
11623
11624 .align 8
11625@@ -345,6 +349,7 @@ twofish_ecb_enc_8way:
11626
11627 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
11628
11629+ pax_force_retaddr 0, 1
11630 ret;
11631
11632 .align 8
11633@@ -366,6 +371,7 @@ twofish_ecb_dec_8way:
11634
11635 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11636
11637+ pax_force_retaddr 0, 1
11638 ret;
11639
11640 .align 8
11641@@ -392,6 +398,7 @@ twofish_cbc_dec_8way:
11642
11643 popq %r12;
11644
11645+ pax_force_retaddr 0, 1
11646 ret;
11647
11648 .align 8
11649@@ -420,4 +427,5 @@ twofish_ctr_8way:
11650
11651 popq %r12;
11652
11653+ pax_force_retaddr 0, 1
11654 ret;
11655diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11656index 5b012a2..36d5364 100644
11657--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11658+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11659@@ -20,6 +20,8 @@
11660 *
11661 */
11662
11663+#include <asm/alternative-asm.h>
11664+
11665 .file "twofish-x86_64-asm-3way.S"
11666 .text
11667
11668@@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
11669 popq %r13;
11670 popq %r14;
11671 popq %r15;
11672+ pax_force_retaddr 0, 1
11673 ret;
11674
11675 __enc_xor3:
11676@@ -271,6 +274,7 @@ __enc_xor3:
11677 popq %r13;
11678 popq %r14;
11679 popq %r15;
11680+ pax_force_retaddr 0, 1
11681 ret;
11682
11683 .global twofish_dec_blk_3way
11684@@ -312,5 +316,6 @@ twofish_dec_blk_3way:
11685 popq %r13;
11686 popq %r14;
11687 popq %r15;
11688+ pax_force_retaddr 0, 1
11689 ret;
11690
11691diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
11692index 7bcf3fc..f53832f 100644
11693--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
11694+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
11695@@ -21,6 +21,7 @@
11696 .text
11697
11698 #include <asm/asm-offsets.h>
11699+#include <asm/alternative-asm.h>
11700
11701 #define a_offset 0
11702 #define b_offset 4
11703@@ -268,6 +269,7 @@ twofish_enc_blk:
11704
11705 popq R1
11706 movq $1,%rax
11707+ pax_force_retaddr 0, 1
11708 ret
11709
11710 twofish_dec_blk:
11711@@ -319,4 +321,5 @@ twofish_dec_blk:
11712
11713 popq R1
11714 movq $1,%rax
11715+ pax_force_retaddr 0, 1
11716 ret
11717diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
11718index a703af1..f5b9c36 100644
11719--- a/arch/x86/ia32/ia32_aout.c
11720+++ b/arch/x86/ia32/ia32_aout.c
11721@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
11722 unsigned long dump_start, dump_size;
11723 struct user32 dump;
11724
11725+ memset(&dump, 0, sizeof(dump));
11726+
11727 fs = get_fs();
11728 set_fs(KERNEL_DS);
11729 has_dumped = 1;
11730diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
11731index a1daf4a..f8c4537 100644
11732--- a/arch/x86/ia32/ia32_signal.c
11733+++ b/arch/x86/ia32/ia32_signal.c
11734@@ -348,7 +348,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
11735 sp -= frame_size;
11736 /* Align the stack pointer according to the i386 ABI,
11737 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
11738- sp = ((sp + 4) & -16ul) - 4;
11739+ sp = ((sp - 12) & -16ul) - 4;
11740 return (void __user *) sp;
11741 }
11742
11743@@ -406,7 +406,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
11744 * These are actually not used anymore, but left because some
11745 * gdb versions depend on them as a marker.
11746 */
11747- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11748+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11749 } put_user_catch(err);
11750
11751 if (err)
11752@@ -448,7 +448,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
11753 0xb8,
11754 __NR_ia32_rt_sigreturn,
11755 0x80cd,
11756- 0,
11757+ 0
11758 };
11759
11760 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
11761@@ -471,16 +471,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
11762
11763 if (ka->sa.sa_flags & SA_RESTORER)
11764 restorer = ka->sa.sa_restorer;
11765+ else if (current->mm->context.vdso)
11766+ /* Return stub is in 32bit vsyscall page */
11767+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
11768 else
11769- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
11770- rt_sigreturn);
11771+ restorer = &frame->retcode;
11772 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
11773
11774 /*
11775 * Not actually used anymore, but left because some gdb
11776 * versions need it.
11777 */
11778- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11779+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11780 } put_user_catch(err);
11781
11782 err |= copy_siginfo_to_user32(&frame->info, info);
11783diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
11784index 142c4ce..19b683f 100644
11785--- a/arch/x86/ia32/ia32entry.S
11786+++ b/arch/x86/ia32/ia32entry.S
11787@@ -15,8 +15,10 @@
11788 #include <asm/irqflags.h>
11789 #include <asm/asm.h>
11790 #include <asm/smap.h>
11791+#include <asm/pgtable.h>
11792 #include <linux/linkage.h>
11793 #include <linux/err.h>
11794+#include <asm/alternative-asm.h>
11795
11796 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
11797 #include <linux/elf-em.h>
11798@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
11799 ENDPROC(native_irq_enable_sysexit)
11800 #endif
11801
11802+ .macro pax_enter_kernel_user
11803+ pax_set_fptr_mask
11804+#ifdef CONFIG_PAX_MEMORY_UDEREF
11805+ call pax_enter_kernel_user
11806+#endif
11807+ .endm
11808+
11809+ .macro pax_exit_kernel_user
11810+#ifdef CONFIG_PAX_MEMORY_UDEREF
11811+ call pax_exit_kernel_user
11812+#endif
11813+#ifdef CONFIG_PAX_RANDKSTACK
11814+ pushq %rax
11815+ pushq %r11
11816+ call pax_randomize_kstack
11817+ popq %r11
11818+ popq %rax
11819+#endif
11820+ .endm
11821+
11822+.macro pax_erase_kstack
11823+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
11824+ call pax_erase_kstack
11825+#endif
11826+.endm
11827+
11828 /*
11829 * 32bit SYSENTER instruction entry.
11830 *
11831@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
11832 CFI_REGISTER rsp,rbp
11833 SWAPGS_UNSAFE_STACK
11834 movq PER_CPU_VAR(kernel_stack), %rsp
11835- addq $(KERNEL_STACK_OFFSET),%rsp
11836- /*
11837- * No need to follow this irqs on/off section: the syscall
11838- * disabled irqs, here we enable it straight after entry:
11839- */
11840- ENABLE_INTERRUPTS(CLBR_NONE)
11841 movl %ebp,%ebp /* zero extension */
11842 pushq_cfi $__USER32_DS
11843 /*CFI_REL_OFFSET ss,0*/
11844@@ -135,24 +157,44 @@ ENTRY(ia32_sysenter_target)
11845 CFI_REL_OFFSET rsp,0
11846 pushfq_cfi
11847 /*CFI_REL_OFFSET rflags,0*/
11848- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
11849- CFI_REGISTER rip,r10
11850+ orl $X86_EFLAGS_IF,(%rsp)
11851+ GET_THREAD_INFO(%r11)
11852+ movl TI_sysenter_return(%r11), %r11d
11853+ CFI_REGISTER rip,r11
11854 pushq_cfi $__USER32_CS
11855 /*CFI_REL_OFFSET cs,0*/
11856 movl %eax, %eax
11857- pushq_cfi %r10
11858+ pushq_cfi %r11
11859 CFI_REL_OFFSET rip,0
11860 pushq_cfi %rax
11861 cld
11862 SAVE_ARGS 0,1,0
11863+ pax_enter_kernel_user
11864+
11865+#ifdef CONFIG_PAX_RANDKSTACK
11866+ pax_erase_kstack
11867+#endif
11868+
11869+ /*
11870+ * No need to follow this irqs on/off section: the syscall
11871+ * disabled irqs, here we enable it straight after entry:
11872+ */
11873+ ENABLE_INTERRUPTS(CLBR_NONE)
11874 /* no need to do an access_ok check here because rbp has been
11875 32bit zero extended */
11876+
11877+#ifdef CONFIG_PAX_MEMORY_UDEREF
11878+ mov $PAX_USER_SHADOW_BASE,%r11
11879+ add %r11,%rbp
11880+#endif
11881+
11882 ASM_STAC
11883 1: movl (%rbp),%ebp
11884 _ASM_EXTABLE(1b,ia32_badarg)
11885 ASM_CLAC
11886- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11887- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11888+ GET_THREAD_INFO(%r11)
11889+ orl $TS_COMPAT,TI_status(%r11)
11890+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11891 CFI_REMEMBER_STATE
11892 jnz sysenter_tracesys
11893 cmpq $(IA32_NR_syscalls-1),%rax
11894@@ -162,12 +204,15 @@ sysenter_do_call:
11895 sysenter_dispatch:
11896 call *ia32_sys_call_table(,%rax,8)
11897 movq %rax,RAX-ARGOFFSET(%rsp)
11898+ GET_THREAD_INFO(%r11)
11899 DISABLE_INTERRUPTS(CLBR_NONE)
11900 TRACE_IRQS_OFF
11901- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11902+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11903 jnz sysexit_audit
11904 sysexit_from_sys_call:
11905- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11906+ pax_exit_kernel_user
11907+ pax_erase_kstack
11908+ andl $~TS_COMPAT,TI_status(%r11)
11909 /* clear IF, that popfq doesn't enable interrupts early */
11910 andl $~0x200,EFLAGS-R11(%rsp)
11911 movl RIP-R11(%rsp),%edx /* User %eip */
11912@@ -193,6 +238,9 @@ sysexit_from_sys_call:
11913 movl %eax,%esi /* 2nd arg: syscall number */
11914 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
11915 call __audit_syscall_entry
11916+
11917+ pax_erase_kstack
11918+
11919 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
11920 cmpq $(IA32_NR_syscalls-1),%rax
11921 ja ia32_badsys
11922@@ -204,7 +252,7 @@ sysexit_from_sys_call:
11923 .endm
11924
11925 .macro auditsys_exit exit
11926- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11927+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11928 jnz ia32_ret_from_sys_call
11929 TRACE_IRQS_ON
11930 ENABLE_INTERRUPTS(CLBR_NONE)
11931@@ -215,11 +263,12 @@ sysexit_from_sys_call:
11932 1: setbe %al /* 1 if error, 0 if not */
11933 movzbl %al,%edi /* zero-extend that into %edi */
11934 call __audit_syscall_exit
11935+ GET_THREAD_INFO(%r11)
11936 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
11937 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
11938 DISABLE_INTERRUPTS(CLBR_NONE)
11939 TRACE_IRQS_OFF
11940- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11941+ testl %edi,TI_flags(%r11)
11942 jz \exit
11943 CLEAR_RREGS -ARGOFFSET
11944 jmp int_with_check
11945@@ -237,7 +286,7 @@ sysexit_audit:
11946
11947 sysenter_tracesys:
11948 #ifdef CONFIG_AUDITSYSCALL
11949- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11950+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11951 jz sysenter_auditsys
11952 #endif
11953 SAVE_REST
11954@@ -249,6 +298,9 @@ sysenter_tracesys:
11955 RESTORE_REST
11956 cmpq $(IA32_NR_syscalls-1),%rax
11957 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
11958+
11959+ pax_erase_kstack
11960+
11961 jmp sysenter_do_call
11962 CFI_ENDPROC
11963 ENDPROC(ia32_sysenter_target)
11964@@ -276,19 +328,25 @@ ENDPROC(ia32_sysenter_target)
11965 ENTRY(ia32_cstar_target)
11966 CFI_STARTPROC32 simple
11967 CFI_SIGNAL_FRAME
11968- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
11969+ CFI_DEF_CFA rsp,0
11970 CFI_REGISTER rip,rcx
11971 /*CFI_REGISTER rflags,r11*/
11972 SWAPGS_UNSAFE_STACK
11973 movl %esp,%r8d
11974 CFI_REGISTER rsp,r8
11975 movq PER_CPU_VAR(kernel_stack),%rsp
11976+ SAVE_ARGS 8*6,0,0
11977+ pax_enter_kernel_user
11978+
11979+#ifdef CONFIG_PAX_RANDKSTACK
11980+ pax_erase_kstack
11981+#endif
11982+
11983 /*
11984 * No need to follow this irqs on/off section: the syscall
11985 * disabled irqs and here we enable it straight after entry:
11986 */
11987 ENABLE_INTERRUPTS(CLBR_NONE)
11988- SAVE_ARGS 8,0,0
11989 movl %eax,%eax /* zero extension */
11990 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
11991 movq %rcx,RIP-ARGOFFSET(%rsp)
11992@@ -304,12 +362,19 @@ ENTRY(ia32_cstar_target)
11993 /* no need to do an access_ok check here because r8 has been
11994 32bit zero extended */
11995 /* hardware stack frame is complete now */
11996+
11997+#ifdef CONFIG_PAX_MEMORY_UDEREF
11998+ mov $PAX_USER_SHADOW_BASE,%r11
11999+ add %r11,%r8
12000+#endif
12001+
12002 ASM_STAC
12003 1: movl (%r8),%r9d
12004 _ASM_EXTABLE(1b,ia32_badarg)
12005 ASM_CLAC
12006- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12007- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12008+ GET_THREAD_INFO(%r11)
12009+ orl $TS_COMPAT,TI_status(%r11)
12010+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
12011 CFI_REMEMBER_STATE
12012 jnz cstar_tracesys
12013 cmpq $IA32_NR_syscalls-1,%rax
12014@@ -319,12 +384,15 @@ cstar_do_call:
12015 cstar_dispatch:
12016 call *ia32_sys_call_table(,%rax,8)
12017 movq %rax,RAX-ARGOFFSET(%rsp)
12018+ GET_THREAD_INFO(%r11)
12019 DISABLE_INTERRUPTS(CLBR_NONE)
12020 TRACE_IRQS_OFF
12021- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12022+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
12023 jnz sysretl_audit
12024 sysretl_from_sys_call:
12025- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12026+ pax_exit_kernel_user
12027+ pax_erase_kstack
12028+ andl $~TS_COMPAT,TI_status(%r11)
12029 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
12030 movl RIP-ARGOFFSET(%rsp),%ecx
12031 CFI_REGISTER rip,rcx
12032@@ -352,7 +420,7 @@ sysretl_audit:
12033
12034 cstar_tracesys:
12035 #ifdef CONFIG_AUDITSYSCALL
12036- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12037+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
12038 jz cstar_auditsys
12039 #endif
12040 xchgl %r9d,%ebp
12041@@ -366,6 +434,9 @@ cstar_tracesys:
12042 xchgl %ebp,%r9d
12043 cmpq $(IA32_NR_syscalls-1),%rax
12044 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
12045+
12046+ pax_erase_kstack
12047+
12048 jmp cstar_do_call
12049 END(ia32_cstar_target)
12050
12051@@ -407,19 +478,26 @@ ENTRY(ia32_syscall)
12052 CFI_REL_OFFSET rip,RIP-RIP
12053 PARAVIRT_ADJUST_EXCEPTION_FRAME
12054 SWAPGS
12055- /*
12056- * No need to follow this irqs on/off section: the syscall
12057- * disabled irqs and here we enable it straight after entry:
12058- */
12059- ENABLE_INTERRUPTS(CLBR_NONE)
12060 movl %eax,%eax
12061 pushq_cfi %rax
12062 cld
12063 /* note the registers are not zero extended to the sf.
12064 this could be a problem. */
12065 SAVE_ARGS 0,1,0
12066- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12067- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12068+ pax_enter_kernel_user
12069+
12070+#ifdef CONFIG_PAX_RANDKSTACK
12071+ pax_erase_kstack
12072+#endif
12073+
12074+ /*
12075+ * No need to follow this irqs on/off section: the syscall
12076+ * disabled irqs and here we enable it straight after entry:
12077+ */
12078+ ENABLE_INTERRUPTS(CLBR_NONE)
12079+ GET_THREAD_INFO(%r11)
12080+ orl $TS_COMPAT,TI_status(%r11)
12081+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
12082 jnz ia32_tracesys
12083 cmpq $(IA32_NR_syscalls-1),%rax
12084 ja ia32_badsys
12085@@ -442,6 +520,9 @@ ia32_tracesys:
12086 RESTORE_REST
12087 cmpq $(IA32_NR_syscalls-1),%rax
12088 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
12089+
12090+ pax_erase_kstack
12091+
12092 jmp ia32_do_call
12093 END(ia32_syscall)
12094
12095diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
12096index d0b689b..6811ddc 100644
12097--- a/arch/x86/ia32/sys_ia32.c
12098+++ b/arch/x86/ia32/sys_ia32.c
12099@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
12100 */
12101 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
12102 {
12103- typeof(ubuf->st_uid) uid = 0;
12104- typeof(ubuf->st_gid) gid = 0;
12105+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
12106+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
12107 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
12108 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
12109 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
12110@@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
12111 mm_segment_t old_fs = get_fs();
12112
12113 set_fs(KERNEL_DS);
12114- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
12115+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
12116 set_fs(old_fs);
12117 if (put_compat_timespec(&t, interval))
12118 return -EFAULT;
12119@@ -313,13 +313,13 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
12120 asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
12121 compat_size_t sigsetsize)
12122 {
12123- sigset_t s;
12124+ sigset_t s = { };
12125 compat_sigset_t s32;
12126 int ret;
12127 mm_segment_t old_fs = get_fs();
12128
12129 set_fs(KERNEL_DS);
12130- ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
12131+ ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
12132 set_fs(old_fs);
12133 if (!ret) {
12134 switch (_NSIG_WORDS) {
12135@@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
12136 if (copy_siginfo_from_user32(&info, uinfo))
12137 return -EFAULT;
12138 set_fs(KERNEL_DS);
12139- ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
12140+ ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
12141 set_fs(old_fs);
12142 return ret;
12143 }
12144@@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
12145 return -EFAULT;
12146
12147 set_fs(KERNEL_DS);
12148- ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
12149+ ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
12150 count);
12151 set_fs(old_fs);
12152
12153diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
12154index 372231c..a5aa1a1 100644
12155--- a/arch/x86/include/asm/alternative-asm.h
12156+++ b/arch/x86/include/asm/alternative-asm.h
12157@@ -18,6 +18,45 @@
12158 .endm
12159 #endif
12160
12161+#ifdef KERNEXEC_PLUGIN
12162+ .macro pax_force_retaddr_bts rip=0
12163+ btsq $63,\rip(%rsp)
12164+ .endm
12165+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
12166+ .macro pax_force_retaddr rip=0, reload=0
12167+ btsq $63,\rip(%rsp)
12168+ .endm
12169+ .macro pax_force_fptr ptr
12170+ btsq $63,\ptr
12171+ .endm
12172+ .macro pax_set_fptr_mask
12173+ .endm
12174+#endif
12175+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
12176+ .macro pax_force_retaddr rip=0, reload=0
12177+ .if \reload
12178+ pax_set_fptr_mask
12179+ .endif
12180+ orq %r10,\rip(%rsp)
12181+ .endm
12182+ .macro pax_force_fptr ptr
12183+ orq %r10,\ptr
12184+ .endm
12185+ .macro pax_set_fptr_mask
12186+ movabs $0x8000000000000000,%r10
12187+ .endm
12188+#endif
12189+#else
12190+ .macro pax_force_retaddr rip=0, reload=0
12191+ .endm
12192+ .macro pax_force_fptr ptr
12193+ .endm
12194+ .macro pax_force_retaddr_bts rip=0
12195+ .endm
12196+ .macro pax_set_fptr_mask
12197+ .endm
12198+#endif
12199+
12200 .macro altinstruction_entry orig alt feature orig_len alt_len
12201 .long \orig - .
12202 .long \alt - .
12203diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
12204index 58ed6d9..f1cbe58 100644
12205--- a/arch/x86/include/asm/alternative.h
12206+++ b/arch/x86/include/asm/alternative.h
12207@@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
12208 ".pushsection .discard,\"aw\",@progbits\n" \
12209 DISCARD_ENTRY(1) \
12210 ".popsection\n" \
12211- ".pushsection .altinstr_replacement, \"ax\"\n" \
12212+ ".pushsection .altinstr_replacement, \"a\"\n" \
12213 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
12214 ".popsection"
12215
12216@@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
12217 DISCARD_ENTRY(1) \
12218 DISCARD_ENTRY(2) \
12219 ".popsection\n" \
12220- ".pushsection .altinstr_replacement, \"ax\"\n" \
12221+ ".pushsection .altinstr_replacement, \"a\"\n" \
12222 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
12223 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
12224 ".popsection"
12225diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
12226index 3388034..050f0b9 100644
12227--- a/arch/x86/include/asm/apic.h
12228+++ b/arch/x86/include/asm/apic.h
12229@@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
12230
12231 #ifdef CONFIG_X86_LOCAL_APIC
12232
12233-extern unsigned int apic_verbosity;
12234+extern int apic_verbosity;
12235 extern int local_apic_timer_c2_ok;
12236
12237 extern int disable_apic;
12238diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
12239index 20370c6..a2eb9b0 100644
12240--- a/arch/x86/include/asm/apm.h
12241+++ b/arch/x86/include/asm/apm.h
12242@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
12243 __asm__ __volatile__(APM_DO_ZERO_SEGS
12244 "pushl %%edi\n\t"
12245 "pushl %%ebp\n\t"
12246- "lcall *%%cs:apm_bios_entry\n\t"
12247+ "lcall *%%ss:apm_bios_entry\n\t"
12248 "setc %%al\n\t"
12249 "popl %%ebp\n\t"
12250 "popl %%edi\n\t"
12251@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
12252 __asm__ __volatile__(APM_DO_ZERO_SEGS
12253 "pushl %%edi\n\t"
12254 "pushl %%ebp\n\t"
12255- "lcall *%%cs:apm_bios_entry\n\t"
12256+ "lcall *%%ss:apm_bios_entry\n\t"
12257 "setc %%bl\n\t"
12258 "popl %%ebp\n\t"
12259 "popl %%edi\n\t"
12260diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
12261index 722aa3b..3a0bb27 100644
12262--- a/arch/x86/include/asm/atomic.h
12263+++ b/arch/x86/include/asm/atomic.h
12264@@ -22,7 +22,18 @@
12265 */
12266 static inline int atomic_read(const atomic_t *v)
12267 {
12268- return (*(volatile int *)&(v)->counter);
12269+ return (*(volatile const int *)&(v)->counter);
12270+}
12271+
12272+/**
12273+ * atomic_read_unchecked - read atomic variable
12274+ * @v: pointer of type atomic_unchecked_t
12275+ *
12276+ * Atomically reads the value of @v.
12277+ */
12278+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
12279+{
12280+ return (*(volatile const int *)&(v)->counter);
12281 }
12282
12283 /**
12284@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
12285 }
12286
12287 /**
12288+ * atomic_set_unchecked - set atomic variable
12289+ * @v: pointer of type atomic_unchecked_t
12290+ * @i: required value
12291+ *
12292+ * Atomically sets the value of @v to @i.
12293+ */
12294+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
12295+{
12296+ v->counter = i;
12297+}
12298+
12299+/**
12300 * atomic_add - add integer to atomic variable
12301 * @i: integer value to add
12302 * @v: pointer of type atomic_t
12303@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
12304 */
12305 static inline void atomic_add(int i, atomic_t *v)
12306 {
12307- asm volatile(LOCK_PREFIX "addl %1,%0"
12308+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
12309+
12310+#ifdef CONFIG_PAX_REFCOUNT
12311+ "jno 0f\n"
12312+ LOCK_PREFIX "subl %1,%0\n"
12313+ "int $4\n0:\n"
12314+ _ASM_EXTABLE(0b, 0b)
12315+#endif
12316+
12317+ : "+m" (v->counter)
12318+ : "ir" (i));
12319+}
12320+
12321+/**
12322+ * atomic_add_unchecked - add integer to atomic variable
12323+ * @i: integer value to add
12324+ * @v: pointer of type atomic_unchecked_t
12325+ *
12326+ * Atomically adds @i to @v.
12327+ */
12328+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
12329+{
12330+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
12331 : "+m" (v->counter)
12332 : "ir" (i));
12333 }
12334@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
12335 */
12336 static inline void atomic_sub(int i, atomic_t *v)
12337 {
12338- asm volatile(LOCK_PREFIX "subl %1,%0"
12339+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
12340+
12341+#ifdef CONFIG_PAX_REFCOUNT
12342+ "jno 0f\n"
12343+ LOCK_PREFIX "addl %1,%0\n"
12344+ "int $4\n0:\n"
12345+ _ASM_EXTABLE(0b, 0b)
12346+#endif
12347+
12348+ : "+m" (v->counter)
12349+ : "ir" (i));
12350+}
12351+
12352+/**
12353+ * atomic_sub_unchecked - subtract integer from atomic variable
12354+ * @i: integer value to subtract
12355+ * @v: pointer of type atomic_unchecked_t
12356+ *
12357+ * Atomically subtracts @i from @v.
12358+ */
12359+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
12360+{
12361+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
12362 : "+m" (v->counter)
12363 : "ir" (i));
12364 }
12365@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
12366 {
12367 unsigned char c;
12368
12369- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
12370+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
12371+
12372+#ifdef CONFIG_PAX_REFCOUNT
12373+ "jno 0f\n"
12374+ LOCK_PREFIX "addl %2,%0\n"
12375+ "int $4\n0:\n"
12376+ _ASM_EXTABLE(0b, 0b)
12377+#endif
12378+
12379+ "sete %1\n"
12380 : "+m" (v->counter), "=qm" (c)
12381 : "ir" (i) : "memory");
12382 return c;
12383@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
12384 */
12385 static inline void atomic_inc(atomic_t *v)
12386 {
12387- asm volatile(LOCK_PREFIX "incl %0"
12388+ asm volatile(LOCK_PREFIX "incl %0\n"
12389+
12390+#ifdef CONFIG_PAX_REFCOUNT
12391+ "jno 0f\n"
12392+ LOCK_PREFIX "decl %0\n"
12393+ "int $4\n0:\n"
12394+ _ASM_EXTABLE(0b, 0b)
12395+#endif
12396+
12397+ : "+m" (v->counter));
12398+}
12399+
12400+/**
12401+ * atomic_inc_unchecked - increment atomic variable
12402+ * @v: pointer of type atomic_unchecked_t
12403+ *
12404+ * Atomically increments @v by 1.
12405+ */
12406+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
12407+{
12408+ asm volatile(LOCK_PREFIX "incl %0\n"
12409 : "+m" (v->counter));
12410 }
12411
12412@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
12413 */
12414 static inline void atomic_dec(atomic_t *v)
12415 {
12416- asm volatile(LOCK_PREFIX "decl %0"
12417+ asm volatile(LOCK_PREFIX "decl %0\n"
12418+
12419+#ifdef CONFIG_PAX_REFCOUNT
12420+ "jno 0f\n"
12421+ LOCK_PREFIX "incl %0\n"
12422+ "int $4\n0:\n"
12423+ _ASM_EXTABLE(0b, 0b)
12424+#endif
12425+
12426+ : "+m" (v->counter));
12427+}
12428+
12429+/**
12430+ * atomic_dec_unchecked - decrement atomic variable
12431+ * @v: pointer of type atomic_unchecked_t
12432+ *
12433+ * Atomically decrements @v by 1.
12434+ */
12435+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
12436+{
12437+ asm volatile(LOCK_PREFIX "decl %0\n"
12438 : "+m" (v->counter));
12439 }
12440
12441@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
12442 {
12443 unsigned char c;
12444
12445- asm volatile(LOCK_PREFIX "decl %0; sete %1"
12446+ asm volatile(LOCK_PREFIX "decl %0\n"
12447+
12448+#ifdef CONFIG_PAX_REFCOUNT
12449+ "jno 0f\n"
12450+ LOCK_PREFIX "incl %0\n"
12451+ "int $4\n0:\n"
12452+ _ASM_EXTABLE(0b, 0b)
12453+#endif
12454+
12455+ "sete %1\n"
12456 : "+m" (v->counter), "=qm" (c)
12457 : : "memory");
12458 return c != 0;
12459@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
12460 {
12461 unsigned char c;
12462
12463- asm volatile(LOCK_PREFIX "incl %0; sete %1"
12464+ asm volatile(LOCK_PREFIX "incl %0\n"
12465+
12466+#ifdef CONFIG_PAX_REFCOUNT
12467+ "jno 0f\n"
12468+ LOCK_PREFIX "decl %0\n"
12469+ "int $4\n0:\n"
12470+ _ASM_EXTABLE(0b, 0b)
12471+#endif
12472+
12473+ "sete %1\n"
12474+ : "+m" (v->counter), "=qm" (c)
12475+ : : "memory");
12476+ return c != 0;
12477+}
12478+
12479+/**
12480+ * atomic_inc_and_test_unchecked - increment and test
12481+ * @v: pointer of type atomic_unchecked_t
12482+ *
12483+ * Atomically increments @v by 1
12484+ * and returns true if the result is zero, or false for all
12485+ * other cases.
12486+ */
12487+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
12488+{
12489+ unsigned char c;
12490+
12491+ asm volatile(LOCK_PREFIX "incl %0\n"
12492+ "sete %1\n"
12493 : "+m" (v->counter), "=qm" (c)
12494 : : "memory");
12495 return c != 0;
12496@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
12497 {
12498 unsigned char c;
12499
12500- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
12501+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
12502+
12503+#ifdef CONFIG_PAX_REFCOUNT
12504+ "jno 0f\n"
12505+ LOCK_PREFIX "subl %2,%0\n"
12506+ "int $4\n0:\n"
12507+ _ASM_EXTABLE(0b, 0b)
12508+#endif
12509+
12510+ "sets %1\n"
12511 : "+m" (v->counter), "=qm" (c)
12512 : "ir" (i) : "memory");
12513 return c;
12514@@ -172,6 +334,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
12515 */
12516 static inline int atomic_add_return(int i, atomic_t *v)
12517 {
12518+ return i + xadd_check_overflow(&v->counter, i);
12519+}
12520+
12521+/**
12522+ * atomic_add_return_unchecked - add integer and return
12523+ * @i: integer value to add
12524+ * @v: pointer of type atomic_unchecked_t
12525+ *
12526+ * Atomically adds @i to @v and returns @i + @v
12527+ */
12528+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
12529+{
12530 return i + xadd(&v->counter, i);
12531 }
12532
12533@@ -188,6 +362,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
12534 }
12535
12536 #define atomic_inc_return(v) (atomic_add_return(1, v))
12537+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
12538+{
12539+ return atomic_add_return_unchecked(1, v);
12540+}
12541 #define atomic_dec_return(v) (atomic_sub_return(1, v))
12542
12543 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
12544@@ -195,11 +373,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
12545 return cmpxchg(&v->counter, old, new);
12546 }
12547
12548+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
12549+{
12550+ return cmpxchg(&v->counter, old, new);
12551+}
12552+
12553 static inline int atomic_xchg(atomic_t *v, int new)
12554 {
12555 return xchg(&v->counter, new);
12556 }
12557
12558+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
12559+{
12560+ return xchg(&v->counter, new);
12561+}
12562+
12563 /**
12564 * __atomic_add_unless - add unless the number is already a given value
12565 * @v: pointer of type atomic_t
12566@@ -211,12 +399,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
12567 */
12568 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
12569 {
12570- int c, old;
12571+ int c, old, new;
12572 c = atomic_read(v);
12573 for (;;) {
12574- if (unlikely(c == (u)))
12575+ if (unlikely(c == u))
12576 break;
12577- old = atomic_cmpxchg((v), c, c + (a));
12578+
12579+ asm volatile("addl %2,%0\n"
12580+
12581+#ifdef CONFIG_PAX_REFCOUNT
12582+ "jno 0f\n"
12583+ "subl %2,%0\n"
12584+ "int $4\n0:\n"
12585+ _ASM_EXTABLE(0b, 0b)
12586+#endif
12587+
12588+ : "=r" (new)
12589+ : "0" (c), "ir" (a));
12590+
12591+ old = atomic_cmpxchg(v, c, new);
12592 if (likely(old == c))
12593 break;
12594 c = old;
12595@@ -225,6 +426,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
12596 }
12597
12598 /**
12599+ * atomic_inc_not_zero_hint - increment if not null
12600+ * @v: pointer of type atomic_t
12601+ * @hint: probable value of the atomic before the increment
12602+ *
12603+ * This version of atomic_inc_not_zero() gives a hint of probable
12604+ * value of the atomic. This helps processor to not read the memory
12605+ * before doing the atomic read/modify/write cycle, lowering
12606+ * number of bus transactions on some arches.
12607+ *
12608+ * Returns: 0 if increment was not done, 1 otherwise.
12609+ */
12610+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
12611+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
12612+{
12613+ int val, c = hint, new;
12614+
12615+ /* sanity test, should be removed by compiler if hint is a constant */
12616+ if (!hint)
12617+ return __atomic_add_unless(v, 1, 0);
12618+
12619+ do {
12620+ asm volatile("incl %0\n"
12621+
12622+#ifdef CONFIG_PAX_REFCOUNT
12623+ "jno 0f\n"
12624+ "decl %0\n"
12625+ "int $4\n0:\n"
12626+ _ASM_EXTABLE(0b, 0b)
12627+#endif
12628+
12629+ : "=r" (new)
12630+ : "0" (c));
12631+
12632+ val = atomic_cmpxchg(v, c, new);
12633+ if (val == c)
12634+ return 1;
12635+ c = val;
12636+ } while (c);
12637+
12638+ return 0;
12639+}
12640+
12641+/**
12642 * atomic_inc_short - increment of a short integer
12643 * @v: pointer to type int
12644 *
12645@@ -253,14 +497,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
12646 #endif
12647
12648 /* These are x86-specific, used by some header files */
12649-#define atomic_clear_mask(mask, addr) \
12650- asm volatile(LOCK_PREFIX "andl %0,%1" \
12651- : : "r" (~(mask)), "m" (*(addr)) : "memory")
12652+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
12653+{
12654+ asm volatile(LOCK_PREFIX "andl %1,%0"
12655+ : "+m" (v->counter)
12656+ : "r" (~(mask))
12657+ : "memory");
12658+}
12659
12660-#define atomic_set_mask(mask, addr) \
12661- asm volatile(LOCK_PREFIX "orl %0,%1" \
12662- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
12663- : "memory")
12664+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
12665+{
12666+ asm volatile(LOCK_PREFIX "andl %1,%0"
12667+ : "+m" (v->counter)
12668+ : "r" (~(mask))
12669+ : "memory");
12670+}
12671+
12672+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
12673+{
12674+ asm volatile(LOCK_PREFIX "orl %1,%0"
12675+ : "+m" (v->counter)
12676+ : "r" (mask)
12677+ : "memory");
12678+}
12679+
12680+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
12681+{
12682+ asm volatile(LOCK_PREFIX "orl %1,%0"
12683+ : "+m" (v->counter)
12684+ : "r" (mask)
12685+ : "memory");
12686+}
12687
12688 /* Atomic operations are already serializing on x86 */
12689 #define smp_mb__before_atomic_dec() barrier()
12690diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
12691index b154de7..aadebd8 100644
12692--- a/arch/x86/include/asm/atomic64_32.h
12693+++ b/arch/x86/include/asm/atomic64_32.h
12694@@ -12,6 +12,14 @@ typedef struct {
12695 u64 __aligned(8) counter;
12696 } atomic64_t;
12697
12698+#ifdef CONFIG_PAX_REFCOUNT
12699+typedef struct {
12700+ u64 __aligned(8) counter;
12701+} atomic64_unchecked_t;
12702+#else
12703+typedef atomic64_t atomic64_unchecked_t;
12704+#endif
12705+
12706 #define ATOMIC64_INIT(val) { (val) }
12707
12708 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
12709@@ -37,21 +45,31 @@ typedef struct {
12710 ATOMIC64_DECL_ONE(sym##_386)
12711
12712 ATOMIC64_DECL_ONE(add_386);
12713+ATOMIC64_DECL_ONE(add_unchecked_386);
12714 ATOMIC64_DECL_ONE(sub_386);
12715+ATOMIC64_DECL_ONE(sub_unchecked_386);
12716 ATOMIC64_DECL_ONE(inc_386);
12717+ATOMIC64_DECL_ONE(inc_unchecked_386);
12718 ATOMIC64_DECL_ONE(dec_386);
12719+ATOMIC64_DECL_ONE(dec_unchecked_386);
12720 #endif
12721
12722 #define alternative_atomic64(f, out, in...) \
12723 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
12724
12725 ATOMIC64_DECL(read);
12726+ATOMIC64_DECL(read_unchecked);
12727 ATOMIC64_DECL(set);
12728+ATOMIC64_DECL(set_unchecked);
12729 ATOMIC64_DECL(xchg);
12730 ATOMIC64_DECL(add_return);
12731+ATOMIC64_DECL(add_return_unchecked);
12732 ATOMIC64_DECL(sub_return);
12733+ATOMIC64_DECL(sub_return_unchecked);
12734 ATOMIC64_DECL(inc_return);
12735+ATOMIC64_DECL(inc_return_unchecked);
12736 ATOMIC64_DECL(dec_return);
12737+ATOMIC64_DECL(dec_return_unchecked);
12738 ATOMIC64_DECL(dec_if_positive);
12739 ATOMIC64_DECL(inc_not_zero);
12740 ATOMIC64_DECL(add_unless);
12741@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
12742 }
12743
12744 /**
12745+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
12746+ * @p: pointer to type atomic64_unchecked_t
12747+ * @o: expected value
12748+ * @n: new value
12749+ *
12750+ * Atomically sets @v to @n if it was equal to @o and returns
12751+ * the old value.
12752+ */
12753+
12754+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
12755+{
12756+ return cmpxchg64(&v->counter, o, n);
12757+}
12758+
12759+/**
12760 * atomic64_xchg - xchg atomic64 variable
12761 * @v: pointer to type atomic64_t
12762 * @n: value to assign
12763@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
12764 }
12765
12766 /**
12767+ * atomic64_set_unchecked - set atomic64 variable
12768+ * @v: pointer to type atomic64_unchecked_t
12769+ * @n: value to assign
12770+ *
12771+ * Atomically sets the value of @v to @n.
12772+ */
12773+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
12774+{
12775+ unsigned high = (unsigned)(i >> 32);
12776+ unsigned low = (unsigned)i;
12777+ alternative_atomic64(set, /* no output */,
12778+ "S" (v), "b" (low), "c" (high)
12779+ : "eax", "edx", "memory");
12780+}
12781+
12782+/**
12783 * atomic64_read - read atomic64 variable
12784 * @v: pointer to type atomic64_t
12785 *
12786@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
12787 }
12788
12789 /**
12790+ * atomic64_read_unchecked - read atomic64 variable
12791+ * @v: pointer to type atomic64_unchecked_t
12792+ *
12793+ * Atomically reads the value of @v and returns it.
12794+ */
12795+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
12796+{
12797+ long long r;
12798+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
12799+ return r;
12800+ }
12801+
12802+/**
12803 * atomic64_add_return - add and return
12804 * @i: integer value to add
12805 * @v: pointer to type atomic64_t
12806@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
12807 return i;
12808 }
12809
12810+/**
12811+ * atomic64_add_return_unchecked - add and return
12812+ * @i: integer value to add
12813+ * @v: pointer to type atomic64_unchecked_t
12814+ *
12815+ * Atomically adds @i to @v and returns @i + *@v
12816+ */
12817+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
12818+{
12819+ alternative_atomic64(add_return_unchecked,
12820+ ASM_OUTPUT2("+A" (i), "+c" (v)),
12821+ ASM_NO_INPUT_CLOBBER("memory"));
12822+ return i;
12823+}
12824+
12825 /*
12826 * Other variants with different arithmetic operators:
12827 */
12828@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
12829 return a;
12830 }
12831
12832+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12833+{
12834+ long long a;
12835+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
12836+ "S" (v) : "memory", "ecx");
12837+ return a;
12838+}
12839+
12840 static inline long long atomic64_dec_return(atomic64_t *v)
12841 {
12842 long long a;
12843@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
12844 }
12845
12846 /**
12847+ * atomic64_add_unchecked - add integer to atomic64 variable
12848+ * @i: integer value to add
12849+ * @v: pointer to type atomic64_unchecked_t
12850+ *
12851+ * Atomically adds @i to @v.
12852+ */
12853+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
12854+{
12855+ __alternative_atomic64(add_unchecked, add_return_unchecked,
12856+ ASM_OUTPUT2("+A" (i), "+c" (v)),
12857+ ASM_NO_INPUT_CLOBBER("memory"));
12858+ return i;
12859+}
12860+
12861+/**
12862 * atomic64_sub - subtract the atomic64 variable
12863 * @i: integer value to subtract
12864 * @v: pointer to type atomic64_t
12865diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
12866index 0e1cbfc..5623683 100644
12867--- a/arch/x86/include/asm/atomic64_64.h
12868+++ b/arch/x86/include/asm/atomic64_64.h
12869@@ -18,7 +18,19 @@
12870 */
12871 static inline long atomic64_read(const atomic64_t *v)
12872 {
12873- return (*(volatile long *)&(v)->counter);
12874+ return (*(volatile const long *)&(v)->counter);
12875+}
12876+
12877+/**
12878+ * atomic64_read_unchecked - read atomic64 variable
12879+ * @v: pointer of type atomic64_unchecked_t
12880+ *
12881+ * Atomically reads the value of @v.
12882+ * Doesn't imply a read memory barrier.
12883+ */
12884+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
12885+{
12886+ return (*(volatile const long *)&(v)->counter);
12887 }
12888
12889 /**
12890@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
12891 }
12892
12893 /**
12894+ * atomic64_set_unchecked - set atomic64 variable
12895+ * @v: pointer to type atomic64_unchecked_t
12896+ * @i: required value
12897+ *
12898+ * Atomically sets the value of @v to @i.
12899+ */
12900+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
12901+{
12902+ v->counter = i;
12903+}
12904+
12905+/**
12906 * atomic64_add - add integer to atomic64 variable
12907 * @i: integer value to add
12908 * @v: pointer to type atomic64_t
12909@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
12910 */
12911 static inline void atomic64_add(long i, atomic64_t *v)
12912 {
12913+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
12914+
12915+#ifdef CONFIG_PAX_REFCOUNT
12916+ "jno 0f\n"
12917+ LOCK_PREFIX "subq %1,%0\n"
12918+ "int $4\n0:\n"
12919+ _ASM_EXTABLE(0b, 0b)
12920+#endif
12921+
12922+ : "=m" (v->counter)
12923+ : "er" (i), "m" (v->counter));
12924+}
12925+
12926+/**
12927+ * atomic64_add_unchecked - add integer to atomic64 variable
12928+ * @i: integer value to add
12929+ * @v: pointer to type atomic64_unchecked_t
12930+ *
12931+ * Atomically adds @i to @v.
12932+ */
12933+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
12934+{
12935 asm volatile(LOCK_PREFIX "addq %1,%0"
12936 : "=m" (v->counter)
12937 : "er" (i), "m" (v->counter));
12938@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
12939 */
12940 static inline void atomic64_sub(long i, atomic64_t *v)
12941 {
12942- asm volatile(LOCK_PREFIX "subq %1,%0"
12943+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
12944+
12945+#ifdef CONFIG_PAX_REFCOUNT
12946+ "jno 0f\n"
12947+ LOCK_PREFIX "addq %1,%0\n"
12948+ "int $4\n0:\n"
12949+ _ASM_EXTABLE(0b, 0b)
12950+#endif
12951+
12952+ : "=m" (v->counter)
12953+ : "er" (i), "m" (v->counter));
12954+}
12955+
12956+/**
12957+ * atomic64_sub_unchecked - subtract the atomic64 variable
12958+ * @i: integer value to subtract
12959+ * @v: pointer to type atomic64_unchecked_t
12960+ *
12961+ * Atomically subtracts @i from @v.
12962+ */
12963+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
12964+{
12965+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
12966 : "=m" (v->counter)
12967 : "er" (i), "m" (v->counter));
12968 }
12969@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12970 {
12971 unsigned char c;
12972
12973- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
12974+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
12975+
12976+#ifdef CONFIG_PAX_REFCOUNT
12977+ "jno 0f\n"
12978+ LOCK_PREFIX "addq %2,%0\n"
12979+ "int $4\n0:\n"
12980+ _ASM_EXTABLE(0b, 0b)
12981+#endif
12982+
12983+ "sete %1\n"
12984 : "=m" (v->counter), "=qm" (c)
12985 : "er" (i), "m" (v->counter) : "memory");
12986 return c;
12987@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12988 */
12989 static inline void atomic64_inc(atomic64_t *v)
12990 {
12991+ asm volatile(LOCK_PREFIX "incq %0\n"
12992+
12993+#ifdef CONFIG_PAX_REFCOUNT
12994+ "jno 0f\n"
12995+ LOCK_PREFIX "decq %0\n"
12996+ "int $4\n0:\n"
12997+ _ASM_EXTABLE(0b, 0b)
12998+#endif
12999+
13000+ : "=m" (v->counter)
13001+ : "m" (v->counter));
13002+}
13003+
13004+/**
13005+ * atomic64_inc_unchecked - increment atomic64 variable
13006+ * @v: pointer to type atomic64_unchecked_t
13007+ *
13008+ * Atomically increments @v by 1.
13009+ */
13010+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
13011+{
13012 asm volatile(LOCK_PREFIX "incq %0"
13013 : "=m" (v->counter)
13014 : "m" (v->counter));
13015@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
13016 */
13017 static inline void atomic64_dec(atomic64_t *v)
13018 {
13019- asm volatile(LOCK_PREFIX "decq %0"
13020+ asm volatile(LOCK_PREFIX "decq %0\n"
13021+
13022+#ifdef CONFIG_PAX_REFCOUNT
13023+ "jno 0f\n"
13024+ LOCK_PREFIX "incq %0\n"
13025+ "int $4\n0:\n"
13026+ _ASM_EXTABLE(0b, 0b)
13027+#endif
13028+
13029+ : "=m" (v->counter)
13030+ : "m" (v->counter));
13031+}
13032+
13033+/**
13034+ * atomic64_dec_unchecked - decrement atomic64 variable
13035+ * @v: pointer to type atomic64_t
13036+ *
13037+ * Atomically decrements @v by 1.
13038+ */
13039+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
13040+{
13041+ asm volatile(LOCK_PREFIX "decq %0\n"
13042 : "=m" (v->counter)
13043 : "m" (v->counter));
13044 }
13045@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
13046 {
13047 unsigned char c;
13048
13049- asm volatile(LOCK_PREFIX "decq %0; sete %1"
13050+ asm volatile(LOCK_PREFIX "decq %0\n"
13051+
13052+#ifdef CONFIG_PAX_REFCOUNT
13053+ "jno 0f\n"
13054+ LOCK_PREFIX "incq %0\n"
13055+ "int $4\n0:\n"
13056+ _ASM_EXTABLE(0b, 0b)
13057+#endif
13058+
13059+ "sete %1\n"
13060 : "=m" (v->counter), "=qm" (c)
13061 : "m" (v->counter) : "memory");
13062 return c != 0;
13063@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
13064 {
13065 unsigned char c;
13066
13067- asm volatile(LOCK_PREFIX "incq %0; sete %1"
13068+ asm volatile(LOCK_PREFIX "incq %0\n"
13069+
13070+#ifdef CONFIG_PAX_REFCOUNT
13071+ "jno 0f\n"
13072+ LOCK_PREFIX "decq %0\n"
13073+ "int $4\n0:\n"
13074+ _ASM_EXTABLE(0b, 0b)
13075+#endif
13076+
13077+ "sete %1\n"
13078 : "=m" (v->counter), "=qm" (c)
13079 : "m" (v->counter) : "memory");
13080 return c != 0;
13081@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
13082 {
13083 unsigned char c;
13084
13085- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
13086+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
13087+
13088+#ifdef CONFIG_PAX_REFCOUNT
13089+ "jno 0f\n"
13090+ LOCK_PREFIX "subq %2,%0\n"
13091+ "int $4\n0:\n"
13092+ _ASM_EXTABLE(0b, 0b)
13093+#endif
13094+
13095+ "sets %1\n"
13096 : "=m" (v->counter), "=qm" (c)
13097 : "er" (i), "m" (v->counter) : "memory");
13098 return c;
13099@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
13100 */
13101 static inline long atomic64_add_return(long i, atomic64_t *v)
13102 {
13103+ return i + xadd_check_overflow(&v->counter, i);
13104+}
13105+
13106+/**
13107+ * atomic64_add_return_unchecked - add and return
13108+ * @i: integer value to add
13109+ * @v: pointer to type atomic64_unchecked_t
13110+ *
13111+ * Atomically adds @i to @v and returns @i + @v
13112+ */
13113+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
13114+{
13115 return i + xadd(&v->counter, i);
13116 }
13117
13118@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
13119 }
13120
13121 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
13122+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
13123+{
13124+ return atomic64_add_return_unchecked(1, v);
13125+}
13126 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
13127
13128 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
13129@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
13130 return cmpxchg(&v->counter, old, new);
13131 }
13132
13133+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
13134+{
13135+ return cmpxchg(&v->counter, old, new);
13136+}
13137+
13138 static inline long atomic64_xchg(atomic64_t *v, long new)
13139 {
13140 return xchg(&v->counter, new);
13141@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
13142 */
13143 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
13144 {
13145- long c, old;
13146+ long c, old, new;
13147 c = atomic64_read(v);
13148 for (;;) {
13149- if (unlikely(c == (u)))
13150+ if (unlikely(c == u))
13151 break;
13152- old = atomic64_cmpxchg((v), c, c + (a));
13153+
13154+ asm volatile("add %2,%0\n"
13155+
13156+#ifdef CONFIG_PAX_REFCOUNT
13157+ "jno 0f\n"
13158+ "sub %2,%0\n"
13159+ "int $4\n0:\n"
13160+ _ASM_EXTABLE(0b, 0b)
13161+#endif
13162+
13163+ : "=r" (new)
13164+ : "0" (c), "ir" (a));
13165+
13166+ old = atomic64_cmpxchg(v, c, new);
13167 if (likely(old == c))
13168 break;
13169 c = old;
13170 }
13171- return c != (u);
13172+ return c != u;
13173 }
13174
13175 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
13176diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
13177index 6dfd019..28e188d 100644
13178--- a/arch/x86/include/asm/bitops.h
13179+++ b/arch/x86/include/asm/bitops.h
13180@@ -40,7 +40,7 @@
13181 * a mask operation on a byte.
13182 */
13183 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
13184-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
13185+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
13186 #define CONST_MASK(nr) (1 << ((nr) & 7))
13187
13188 /**
13189@@ -486,7 +486,7 @@ static inline int fls(int x)
13190 * at position 64.
13191 */
13192 #ifdef CONFIG_X86_64
13193-static __always_inline int fls64(__u64 x)
13194+static __always_inline long fls64(__u64 x)
13195 {
13196 int bitpos = -1;
13197 /*
13198diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
13199index 4fa687a..60f2d39 100644
13200--- a/arch/x86/include/asm/boot.h
13201+++ b/arch/x86/include/asm/boot.h
13202@@ -6,10 +6,15 @@
13203 #include <uapi/asm/boot.h>
13204
13205 /* Physical address where kernel should be loaded. */
13206-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
13207+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
13208 + (CONFIG_PHYSICAL_ALIGN - 1)) \
13209 & ~(CONFIG_PHYSICAL_ALIGN - 1))
13210
13211+#ifndef __ASSEMBLY__
13212+extern unsigned char __LOAD_PHYSICAL_ADDR[];
13213+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
13214+#endif
13215+
13216 /* Minimum kernel alignment, as a power of two */
13217 #ifdef CONFIG_X86_64
13218 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
13219diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
13220index 48f99f1..d78ebf9 100644
13221--- a/arch/x86/include/asm/cache.h
13222+++ b/arch/x86/include/asm/cache.h
13223@@ -5,12 +5,13 @@
13224
13225 /* L1 cache line size */
13226 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
13227-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
13228+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
13229
13230 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
13231+#define __read_only __attribute__((__section__(".data..read_only")))
13232
13233 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
13234-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
13235+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
13236
13237 #ifdef CONFIG_X86_VSMP
13238 #ifdef CONFIG_SMP
13239diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
13240index 9863ee3..4a1f8e1 100644
13241--- a/arch/x86/include/asm/cacheflush.h
13242+++ b/arch/x86/include/asm/cacheflush.h
13243@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
13244 unsigned long pg_flags = pg->flags & _PGMT_MASK;
13245
13246 if (pg_flags == _PGMT_DEFAULT)
13247- return -1;
13248+ return ~0UL;
13249 else if (pg_flags == _PGMT_WC)
13250 return _PAGE_CACHE_WC;
13251 else if (pg_flags == _PGMT_UC_MINUS)
13252diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
13253index 46fc474..b02b0f9 100644
13254--- a/arch/x86/include/asm/checksum_32.h
13255+++ b/arch/x86/include/asm/checksum_32.h
13256@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
13257 int len, __wsum sum,
13258 int *src_err_ptr, int *dst_err_ptr);
13259
13260+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
13261+ int len, __wsum sum,
13262+ int *src_err_ptr, int *dst_err_ptr);
13263+
13264+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
13265+ int len, __wsum sum,
13266+ int *src_err_ptr, int *dst_err_ptr);
13267+
13268 /*
13269 * Note: when you get a NULL pointer exception here this means someone
13270 * passed in an incorrect kernel address to one of these functions.
13271@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
13272 int *err_ptr)
13273 {
13274 might_sleep();
13275- return csum_partial_copy_generic((__force void *)src, dst,
13276+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
13277 len, sum, err_ptr, NULL);
13278 }
13279
13280@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
13281 {
13282 might_sleep();
13283 if (access_ok(VERIFY_WRITE, dst, len))
13284- return csum_partial_copy_generic(src, (__force void *)dst,
13285+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
13286 len, sum, NULL, err_ptr);
13287
13288 if (len)
13289diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
13290index 8d871ea..c1a0dc9 100644
13291--- a/arch/x86/include/asm/cmpxchg.h
13292+++ b/arch/x86/include/asm/cmpxchg.h
13293@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
13294 __compiletime_error("Bad argument size for cmpxchg");
13295 extern void __xadd_wrong_size(void)
13296 __compiletime_error("Bad argument size for xadd");
13297+extern void __xadd_check_overflow_wrong_size(void)
13298+ __compiletime_error("Bad argument size for xadd_check_overflow");
13299 extern void __add_wrong_size(void)
13300 __compiletime_error("Bad argument size for add");
13301+extern void __add_check_overflow_wrong_size(void)
13302+ __compiletime_error("Bad argument size for add_check_overflow");
13303
13304 /*
13305 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
13306@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
13307 __ret; \
13308 })
13309
13310+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
13311+ ({ \
13312+ __typeof__ (*(ptr)) __ret = (arg); \
13313+ switch (sizeof(*(ptr))) { \
13314+ case __X86_CASE_L: \
13315+ asm volatile (lock #op "l %0, %1\n" \
13316+ "jno 0f\n" \
13317+ "mov %0,%1\n" \
13318+ "int $4\n0:\n" \
13319+ _ASM_EXTABLE(0b, 0b) \
13320+ : "+r" (__ret), "+m" (*(ptr)) \
13321+ : : "memory", "cc"); \
13322+ break; \
13323+ case __X86_CASE_Q: \
13324+ asm volatile (lock #op "q %q0, %1\n" \
13325+ "jno 0f\n" \
13326+ "mov %0,%1\n" \
13327+ "int $4\n0:\n" \
13328+ _ASM_EXTABLE(0b, 0b) \
13329+ : "+r" (__ret), "+m" (*(ptr)) \
13330+ : : "memory", "cc"); \
13331+ break; \
13332+ default: \
13333+ __ ## op ## _check_overflow_wrong_size(); \
13334+ } \
13335+ __ret; \
13336+ })
13337+
13338 /*
13339 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
13340 * Since this is generally used to protect other memory information, we
13341@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
13342 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
13343 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
13344
13345+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
13346+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
13347+
13348 #define __add(ptr, inc, lock) \
13349 ({ \
13350 __typeof__ (*(ptr)) __ret = (inc); \
13351diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
13352index 59c6c40..5e0b22c 100644
13353--- a/arch/x86/include/asm/compat.h
13354+++ b/arch/x86/include/asm/compat.h
13355@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
13356 typedef u32 compat_uint_t;
13357 typedef u32 compat_ulong_t;
13358 typedef u64 __attribute__((aligned(4))) compat_u64;
13359-typedef u32 compat_uptr_t;
13360+typedef u32 __user compat_uptr_t;
13361
13362 struct compat_timespec {
13363 compat_time_t tv_sec;
13364diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
13365index 2d9075e..b75a844 100644
13366--- a/arch/x86/include/asm/cpufeature.h
13367+++ b/arch/x86/include/asm/cpufeature.h
13368@@ -206,7 +206,7 @@
13369 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
13370 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
13371 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
13372-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
13373+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
13374 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
13375 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
13376 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
13377@@ -375,7 +375,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
13378 ".section .discard,\"aw\",@progbits\n"
13379 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
13380 ".previous\n"
13381- ".section .altinstr_replacement,\"ax\"\n"
13382+ ".section .altinstr_replacement,\"a\"\n"
13383 "3: movb $1,%0\n"
13384 "4:\n"
13385 ".previous\n"
13386diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
13387index 8bf1c06..b6ae785 100644
13388--- a/arch/x86/include/asm/desc.h
13389+++ b/arch/x86/include/asm/desc.h
13390@@ -4,6 +4,7 @@
13391 #include <asm/desc_defs.h>
13392 #include <asm/ldt.h>
13393 #include <asm/mmu.h>
13394+#include <asm/pgtable.h>
13395
13396 #include <linux/smp.h>
13397 #include <linux/percpu.h>
13398@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
13399
13400 desc->type = (info->read_exec_only ^ 1) << 1;
13401 desc->type |= info->contents << 2;
13402+ desc->type |= info->seg_not_present ^ 1;
13403
13404 desc->s = 1;
13405 desc->dpl = 0x3;
13406@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
13407 }
13408
13409 extern struct desc_ptr idt_descr;
13410-extern gate_desc idt_table[];
13411 extern struct desc_ptr nmi_idt_descr;
13412-extern gate_desc nmi_idt_table[];
13413-
13414-struct gdt_page {
13415- struct desc_struct gdt[GDT_ENTRIES];
13416-} __attribute__((aligned(PAGE_SIZE)));
13417-
13418-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
13419+extern gate_desc idt_table[256];
13420+extern gate_desc nmi_idt_table[256];
13421
13422+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
13423 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
13424 {
13425- return per_cpu(gdt_page, cpu).gdt;
13426+ return cpu_gdt_table[cpu];
13427 }
13428
13429 #ifdef CONFIG_X86_64
13430@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
13431 unsigned long base, unsigned dpl, unsigned flags,
13432 unsigned short seg)
13433 {
13434- gate->a = (seg << 16) | (base & 0xffff);
13435- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
13436+ gate->gate.offset_low = base;
13437+ gate->gate.seg = seg;
13438+ gate->gate.reserved = 0;
13439+ gate->gate.type = type;
13440+ gate->gate.s = 0;
13441+ gate->gate.dpl = dpl;
13442+ gate->gate.p = 1;
13443+ gate->gate.offset_high = base >> 16;
13444 }
13445
13446 #endif
13447@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
13448
13449 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
13450 {
13451+ pax_open_kernel();
13452 memcpy(&idt[entry], gate, sizeof(*gate));
13453+ pax_close_kernel();
13454 }
13455
13456 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
13457 {
13458+ pax_open_kernel();
13459 memcpy(&ldt[entry], desc, 8);
13460+ pax_close_kernel();
13461 }
13462
13463 static inline void
13464@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
13465 default: size = sizeof(*gdt); break;
13466 }
13467
13468+ pax_open_kernel();
13469 memcpy(&gdt[entry], desc, size);
13470+ pax_close_kernel();
13471 }
13472
13473 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
13474@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
13475
13476 static inline void native_load_tr_desc(void)
13477 {
13478+ pax_open_kernel();
13479 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
13480+ pax_close_kernel();
13481 }
13482
13483 static inline void native_load_gdt(const struct desc_ptr *dtr)
13484@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
13485 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
13486 unsigned int i;
13487
13488+ pax_open_kernel();
13489 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
13490 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
13491+ pax_close_kernel();
13492 }
13493
13494 #define _LDT_empty(info) \
13495@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
13496 preempt_enable();
13497 }
13498
13499-static inline unsigned long get_desc_base(const struct desc_struct *desc)
13500+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
13501 {
13502 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
13503 }
13504@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
13505 }
13506
13507 #ifdef CONFIG_X86_64
13508-static inline void set_nmi_gate(int gate, void *addr)
13509+static inline void set_nmi_gate(int gate, const void *addr)
13510 {
13511 gate_desc s;
13512
13513@@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
13514 }
13515 #endif
13516
13517-static inline void _set_gate(int gate, unsigned type, void *addr,
13518+static inline void _set_gate(int gate, unsigned type, const void *addr,
13519 unsigned dpl, unsigned ist, unsigned seg)
13520 {
13521 gate_desc s;
13522@@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
13523 * Pentium F0 0F bugfix can have resulted in the mapped
13524 * IDT being write-protected.
13525 */
13526-static inline void set_intr_gate(unsigned int n, void *addr)
13527+static inline void set_intr_gate(unsigned int n, const void *addr)
13528 {
13529 BUG_ON((unsigned)n > 0xFF);
13530 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
13531@@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
13532 /*
13533 * This routine sets up an interrupt gate at directory privilege level 3.
13534 */
13535-static inline void set_system_intr_gate(unsigned int n, void *addr)
13536+static inline void set_system_intr_gate(unsigned int n, const void *addr)
13537 {
13538 BUG_ON((unsigned)n > 0xFF);
13539 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
13540 }
13541
13542-static inline void set_system_trap_gate(unsigned int n, void *addr)
13543+static inline void set_system_trap_gate(unsigned int n, const void *addr)
13544 {
13545 BUG_ON((unsigned)n > 0xFF);
13546 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
13547 }
13548
13549-static inline void set_trap_gate(unsigned int n, void *addr)
13550+static inline void set_trap_gate(unsigned int n, const void *addr)
13551 {
13552 BUG_ON((unsigned)n > 0xFF);
13553 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
13554@@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
13555 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
13556 {
13557 BUG_ON((unsigned)n > 0xFF);
13558- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
13559+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
13560 }
13561
13562-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
13563+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
13564 {
13565 BUG_ON((unsigned)n > 0xFF);
13566 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
13567 }
13568
13569-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
13570+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
13571 {
13572 BUG_ON((unsigned)n > 0xFF);
13573 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
13574 }
13575
13576+#ifdef CONFIG_X86_32
13577+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
13578+{
13579+ struct desc_struct d;
13580+
13581+ if (likely(limit))
13582+ limit = (limit - 1UL) >> PAGE_SHIFT;
13583+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
13584+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
13585+}
13586+#endif
13587+
13588 #endif /* _ASM_X86_DESC_H */
13589diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
13590index 278441f..b95a174 100644
13591--- a/arch/x86/include/asm/desc_defs.h
13592+++ b/arch/x86/include/asm/desc_defs.h
13593@@ -31,6 +31,12 @@ struct desc_struct {
13594 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
13595 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
13596 };
13597+ struct {
13598+ u16 offset_low;
13599+ u16 seg;
13600+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
13601+ unsigned offset_high: 16;
13602+ } gate;
13603 };
13604 } __attribute__((packed));
13605
13606diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
13607index ced283a..ffe04cc 100644
13608--- a/arch/x86/include/asm/div64.h
13609+++ b/arch/x86/include/asm/div64.h
13610@@ -39,7 +39,7 @@
13611 __mod; \
13612 })
13613
13614-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
13615+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
13616 {
13617 union {
13618 u64 v64;
13619diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
13620index 9c999c1..3860cb8 100644
13621--- a/arch/x86/include/asm/elf.h
13622+++ b/arch/x86/include/asm/elf.h
13623@@ -243,7 +243,25 @@ extern int force_personality32;
13624 the loader. We need to make sure that it is out of the way of the program
13625 that it will "exec", and that there is sufficient room for the brk. */
13626
13627+#ifdef CONFIG_PAX_SEGMEXEC
13628+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
13629+#else
13630 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
13631+#endif
13632+
13633+#ifdef CONFIG_PAX_ASLR
13634+#ifdef CONFIG_X86_32
13635+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
13636+
13637+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
13638+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
13639+#else
13640+#define PAX_ELF_ET_DYN_BASE 0x400000UL
13641+
13642+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
13643+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
13644+#endif
13645+#endif
13646
13647 /* This yields a mask that user programs can use to figure out what
13648 instruction set this CPU supports. This could be done in user space,
13649@@ -296,16 +314,12 @@ do { \
13650
13651 #define ARCH_DLINFO \
13652 do { \
13653- if (vdso_enabled) \
13654- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
13655- (unsigned long)current->mm->context.vdso); \
13656+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
13657 } while (0)
13658
13659 #define ARCH_DLINFO_X32 \
13660 do { \
13661- if (vdso_enabled) \
13662- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
13663- (unsigned long)current->mm->context.vdso); \
13664+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
13665 } while (0)
13666
13667 #define AT_SYSINFO 32
13668@@ -320,7 +334,7 @@ else \
13669
13670 #endif /* !CONFIG_X86_32 */
13671
13672-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
13673+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
13674
13675 #define VDSO_ENTRY \
13676 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
13677@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
13678 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
13679 #define compat_arch_setup_additional_pages syscall32_setup_pages
13680
13681-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
13682-#define arch_randomize_brk arch_randomize_brk
13683-
13684 /*
13685 * True on X86_32 or when emulating IA32 on X86_64
13686 */
13687diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
13688index 75ce3f4..882e801 100644
13689--- a/arch/x86/include/asm/emergency-restart.h
13690+++ b/arch/x86/include/asm/emergency-restart.h
13691@@ -13,6 +13,6 @@ enum reboot_type {
13692
13693 extern enum reboot_type reboot_type;
13694
13695-extern void machine_emergency_restart(void);
13696+extern void machine_emergency_restart(void) __noreturn;
13697
13698 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
13699diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
13700index 41ab26e..a88c9e6 100644
13701--- a/arch/x86/include/asm/fpu-internal.h
13702+++ b/arch/x86/include/asm/fpu-internal.h
13703@@ -126,7 +126,9 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
13704 ({ \
13705 int err; \
13706 asm volatile(ASM_STAC "\n" \
13707- "1:" #insn "\n\t" \
13708+ "1:" \
13709+ __copyuser_seg \
13710+ #insn "\n\t" \
13711 "2: " ASM_CLAC "\n" \
13712 ".section .fixup,\"ax\"\n" \
13713 "3: movl $-1,%[err]\n" \
13714@@ -299,7 +301,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
13715 "emms\n\t" /* clear stack tags */
13716 "fildl %P[addr]", /* set F?P to defined value */
13717 X86_FEATURE_FXSAVE_LEAK,
13718- [addr] "m" (tsk->thread.fpu.has_fpu));
13719+ [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
13720
13721 return fpu_restore_checking(&tsk->thread.fpu);
13722 }
13723diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
13724index be27ba1..8f13ff9 100644
13725--- a/arch/x86/include/asm/futex.h
13726+++ b/arch/x86/include/asm/futex.h
13727@@ -12,6 +12,7 @@
13728 #include <asm/smap.h>
13729
13730 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
13731+ typecheck(u32 __user *, uaddr); \
13732 asm volatile("\t" ASM_STAC "\n" \
13733 "1:\t" insn "\n" \
13734 "2:\t" ASM_CLAC "\n" \
13735@@ -20,15 +21,16 @@
13736 "\tjmp\t2b\n" \
13737 "\t.previous\n" \
13738 _ASM_EXTABLE(1b, 3b) \
13739- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
13740+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
13741 : "i" (-EFAULT), "0" (oparg), "1" (0))
13742
13743 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
13744+ typecheck(u32 __user *, uaddr); \
13745 asm volatile("\t" ASM_STAC "\n" \
13746 "1:\tmovl %2, %0\n" \
13747 "\tmovl\t%0, %3\n" \
13748 "\t" insn "\n" \
13749- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
13750+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
13751 "\tjnz\t1b\n" \
13752 "3:\t" ASM_CLAC "\n" \
13753 "\t.section .fixup,\"ax\"\n" \
13754@@ -38,7 +40,7 @@
13755 _ASM_EXTABLE(1b, 4b) \
13756 _ASM_EXTABLE(2b, 4b) \
13757 : "=&a" (oldval), "=&r" (ret), \
13758- "+m" (*uaddr), "=&r" (tem) \
13759+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
13760 : "r" (oparg), "i" (-EFAULT), "1" (0))
13761
13762 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13763@@ -59,10 +61,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13764
13765 switch (op) {
13766 case FUTEX_OP_SET:
13767- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
13768+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
13769 break;
13770 case FUTEX_OP_ADD:
13771- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
13772+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
13773 uaddr, oparg);
13774 break;
13775 case FUTEX_OP_OR:
13776@@ -116,14 +118,14 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
13777 return -EFAULT;
13778
13779 asm volatile("\t" ASM_STAC "\n"
13780- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
13781+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
13782 "2:\t" ASM_CLAC "\n"
13783 "\t.section .fixup, \"ax\"\n"
13784 "3:\tmov %3, %0\n"
13785 "\tjmp 2b\n"
13786 "\t.previous\n"
13787 _ASM_EXTABLE(1b, 3b)
13788- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
13789+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
13790 : "i" (-EFAULT), "r" (newval), "1" (oldval)
13791 : "memory"
13792 );
13793diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
13794index eb92a6e..b98b2f4 100644
13795--- a/arch/x86/include/asm/hw_irq.h
13796+++ b/arch/x86/include/asm/hw_irq.h
13797@@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
13798 extern void enable_IO_APIC(void);
13799
13800 /* Statistics */
13801-extern atomic_t irq_err_count;
13802-extern atomic_t irq_mis_count;
13803+extern atomic_unchecked_t irq_err_count;
13804+extern atomic_unchecked_t irq_mis_count;
13805
13806 /* EISA */
13807 extern void eisa_set_level_irq(unsigned int irq);
13808diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
13809index a203659..9889f1c 100644
13810--- a/arch/x86/include/asm/i8259.h
13811+++ b/arch/x86/include/asm/i8259.h
13812@@ -62,7 +62,7 @@ struct legacy_pic {
13813 void (*init)(int auto_eoi);
13814 int (*irq_pending)(unsigned int irq);
13815 void (*make_irq)(unsigned int irq);
13816-};
13817+} __do_const;
13818
13819 extern struct legacy_pic *legacy_pic;
13820 extern struct legacy_pic null_legacy_pic;
13821diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
13822index d8e8eef..1765f78 100644
13823--- a/arch/x86/include/asm/io.h
13824+++ b/arch/x86/include/asm/io.h
13825@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
13826 "m" (*(volatile type __force *)addr) barrier); }
13827
13828 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
13829-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
13830-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
13831+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
13832+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
13833
13834 build_mmio_read(__readb, "b", unsigned char, "=q", )
13835-build_mmio_read(__readw, "w", unsigned short, "=r", )
13836-build_mmio_read(__readl, "l", unsigned int, "=r", )
13837+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
13838+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
13839
13840 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
13841 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
13842@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
13843 return ioremap_nocache(offset, size);
13844 }
13845
13846-extern void iounmap(volatile void __iomem *addr);
13847+extern void iounmap(const volatile void __iomem *addr);
13848
13849 extern void set_iounmap_nonlazy(void);
13850
13851@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
13852
13853 #include <linux/vmalloc.h>
13854
13855+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
13856+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
13857+{
13858+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13859+}
13860+
13861+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
13862+{
13863+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13864+}
13865+
13866 /*
13867 * Convert a virtual cached pointer to an uncached pointer
13868 */
13869diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
13870index bba3cf8..06bc8da 100644
13871--- a/arch/x86/include/asm/irqflags.h
13872+++ b/arch/x86/include/asm/irqflags.h
13873@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
13874 sti; \
13875 sysexit
13876
13877+#define GET_CR0_INTO_RDI mov %cr0, %rdi
13878+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
13879+#define GET_CR3_INTO_RDI mov %cr3, %rdi
13880+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
13881+
13882 #else
13883 #define INTERRUPT_RETURN iret
13884 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
13885diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
13886index d3ddd17..c9fb0cc 100644
13887--- a/arch/x86/include/asm/kprobes.h
13888+++ b/arch/x86/include/asm/kprobes.h
13889@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
13890 #define RELATIVEJUMP_SIZE 5
13891 #define RELATIVECALL_OPCODE 0xe8
13892 #define RELATIVE_ADDR_SIZE 4
13893-#define MAX_STACK_SIZE 64
13894-#define MIN_STACK_SIZE(ADDR) \
13895- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
13896- THREAD_SIZE - (unsigned long)(ADDR))) \
13897- ? (MAX_STACK_SIZE) \
13898- : (((unsigned long)current_thread_info()) + \
13899- THREAD_SIZE - (unsigned long)(ADDR)))
13900+#define MAX_STACK_SIZE 64UL
13901+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
13902
13903 #define flush_insn_slot(p) do { } while (0)
13904
13905diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
13906index dc87b65..85039f9 100644
13907--- a/arch/x86/include/asm/kvm_host.h
13908+++ b/arch/x86/include/asm/kvm_host.h
13909@@ -419,8 +419,8 @@ struct kvm_vcpu_arch {
13910 gpa_t time;
13911 struct pvclock_vcpu_time_info hv_clock;
13912 unsigned int hw_tsc_khz;
13913- unsigned int time_offset;
13914- struct page *time_page;
13915+ struct gfn_to_hva_cache pv_time;
13916+ bool pv_time_enabled;
13917 /* set guest stopped flag in pvclock flags field */
13918 bool pvclock_set_guest_stopped_request;
13919
13920diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
13921index 2d89e39..baee879 100644
13922--- a/arch/x86/include/asm/local.h
13923+++ b/arch/x86/include/asm/local.h
13924@@ -10,33 +10,97 @@ typedef struct {
13925 atomic_long_t a;
13926 } local_t;
13927
13928+typedef struct {
13929+ atomic_long_unchecked_t a;
13930+} local_unchecked_t;
13931+
13932 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
13933
13934 #define local_read(l) atomic_long_read(&(l)->a)
13935+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
13936 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
13937+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
13938
13939 static inline void local_inc(local_t *l)
13940 {
13941- asm volatile(_ASM_INC "%0"
13942+ asm volatile(_ASM_INC "%0\n"
13943+
13944+#ifdef CONFIG_PAX_REFCOUNT
13945+ "jno 0f\n"
13946+ _ASM_DEC "%0\n"
13947+ "int $4\n0:\n"
13948+ _ASM_EXTABLE(0b, 0b)
13949+#endif
13950+
13951+ : "+m" (l->a.counter));
13952+}
13953+
13954+static inline void local_inc_unchecked(local_unchecked_t *l)
13955+{
13956+ asm volatile(_ASM_INC "%0\n"
13957 : "+m" (l->a.counter));
13958 }
13959
13960 static inline void local_dec(local_t *l)
13961 {
13962- asm volatile(_ASM_DEC "%0"
13963+ asm volatile(_ASM_DEC "%0\n"
13964+
13965+#ifdef CONFIG_PAX_REFCOUNT
13966+ "jno 0f\n"
13967+ _ASM_INC "%0\n"
13968+ "int $4\n0:\n"
13969+ _ASM_EXTABLE(0b, 0b)
13970+#endif
13971+
13972+ : "+m" (l->a.counter));
13973+}
13974+
13975+static inline void local_dec_unchecked(local_unchecked_t *l)
13976+{
13977+ asm volatile(_ASM_DEC "%0\n"
13978 : "+m" (l->a.counter));
13979 }
13980
13981 static inline void local_add(long i, local_t *l)
13982 {
13983- asm volatile(_ASM_ADD "%1,%0"
13984+ asm volatile(_ASM_ADD "%1,%0\n"
13985+
13986+#ifdef CONFIG_PAX_REFCOUNT
13987+ "jno 0f\n"
13988+ _ASM_SUB "%1,%0\n"
13989+ "int $4\n0:\n"
13990+ _ASM_EXTABLE(0b, 0b)
13991+#endif
13992+
13993+ : "+m" (l->a.counter)
13994+ : "ir" (i));
13995+}
13996+
13997+static inline void local_add_unchecked(long i, local_unchecked_t *l)
13998+{
13999+ asm volatile(_ASM_ADD "%1,%0\n"
14000 : "+m" (l->a.counter)
14001 : "ir" (i));
14002 }
14003
14004 static inline void local_sub(long i, local_t *l)
14005 {
14006- asm volatile(_ASM_SUB "%1,%0"
14007+ asm volatile(_ASM_SUB "%1,%0\n"
14008+
14009+#ifdef CONFIG_PAX_REFCOUNT
14010+ "jno 0f\n"
14011+ _ASM_ADD "%1,%0\n"
14012+ "int $4\n0:\n"
14013+ _ASM_EXTABLE(0b, 0b)
14014+#endif
14015+
14016+ : "+m" (l->a.counter)
14017+ : "ir" (i));
14018+}
14019+
14020+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
14021+{
14022+ asm volatile(_ASM_SUB "%1,%0\n"
14023 : "+m" (l->a.counter)
14024 : "ir" (i));
14025 }
14026@@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
14027 {
14028 unsigned char c;
14029
14030- asm volatile(_ASM_SUB "%2,%0; sete %1"
14031+ asm volatile(_ASM_SUB "%2,%0\n"
14032+
14033+#ifdef CONFIG_PAX_REFCOUNT
14034+ "jno 0f\n"
14035+ _ASM_ADD "%2,%0\n"
14036+ "int $4\n0:\n"
14037+ _ASM_EXTABLE(0b, 0b)
14038+#endif
14039+
14040+ "sete %1\n"
14041 : "+m" (l->a.counter), "=qm" (c)
14042 : "ir" (i) : "memory");
14043 return c;
14044@@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
14045 {
14046 unsigned char c;
14047
14048- asm volatile(_ASM_DEC "%0; sete %1"
14049+ asm volatile(_ASM_DEC "%0\n"
14050+
14051+#ifdef CONFIG_PAX_REFCOUNT
14052+ "jno 0f\n"
14053+ _ASM_INC "%0\n"
14054+ "int $4\n0:\n"
14055+ _ASM_EXTABLE(0b, 0b)
14056+#endif
14057+
14058+ "sete %1\n"
14059 : "+m" (l->a.counter), "=qm" (c)
14060 : : "memory");
14061 return c != 0;
14062@@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
14063 {
14064 unsigned char c;
14065
14066- asm volatile(_ASM_INC "%0; sete %1"
14067+ asm volatile(_ASM_INC "%0\n"
14068+
14069+#ifdef CONFIG_PAX_REFCOUNT
14070+ "jno 0f\n"
14071+ _ASM_DEC "%0\n"
14072+ "int $4\n0:\n"
14073+ _ASM_EXTABLE(0b, 0b)
14074+#endif
14075+
14076+ "sete %1\n"
14077 : "+m" (l->a.counter), "=qm" (c)
14078 : : "memory");
14079 return c != 0;
14080@@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
14081 {
14082 unsigned char c;
14083
14084- asm volatile(_ASM_ADD "%2,%0; sets %1"
14085+ asm volatile(_ASM_ADD "%2,%0\n"
14086+
14087+#ifdef CONFIG_PAX_REFCOUNT
14088+ "jno 0f\n"
14089+ _ASM_SUB "%2,%0\n"
14090+ "int $4\n0:\n"
14091+ _ASM_EXTABLE(0b, 0b)
14092+#endif
14093+
14094+ "sets %1\n"
14095 : "+m" (l->a.counter), "=qm" (c)
14096 : "ir" (i) : "memory");
14097 return c;
14098@@ -125,6 +225,30 @@ static inline int local_add_negative(long i, local_t *l)
14099 static inline long local_add_return(long i, local_t *l)
14100 {
14101 long __i = i;
14102+ asm volatile(_ASM_XADD "%0, %1\n"
14103+
14104+#ifdef CONFIG_PAX_REFCOUNT
14105+ "jno 0f\n"
14106+ _ASM_MOV "%0,%1\n"
14107+ "int $4\n0:\n"
14108+ _ASM_EXTABLE(0b, 0b)
14109+#endif
14110+
14111+ : "+r" (i), "+m" (l->a.counter)
14112+ : : "memory");
14113+ return i + __i;
14114+}
14115+
14116+/**
14117+ * local_add_return_unchecked - add and return
14118+ * @i: integer value to add
14119+ * @l: pointer to type local_unchecked_t
14120+ *
14121+ * Atomically adds @i to @l and returns @i + @l
14122+ */
14123+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
14124+{
14125+ long __i = i;
14126 asm volatile(_ASM_XADD "%0, %1;"
14127 : "+r" (i), "+m" (l->a.counter)
14128 : : "memory");
14129@@ -141,6 +265,8 @@ static inline long local_sub_return(long i, local_t *l)
14130
14131 #define local_cmpxchg(l, o, n) \
14132 (cmpxchg_local(&((l)->a.counter), (o), (n)))
14133+#define local_cmpxchg_unchecked(l, o, n) \
14134+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
14135 /* Always has a lock prefix */
14136 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
14137
14138diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
14139new file mode 100644
14140index 0000000..2bfd3ba
14141--- /dev/null
14142+++ b/arch/x86/include/asm/mman.h
14143@@ -0,0 +1,15 @@
14144+#ifndef _X86_MMAN_H
14145+#define _X86_MMAN_H
14146+
14147+#include <uapi/asm/mman.h>
14148+
14149+#ifdef __KERNEL__
14150+#ifndef __ASSEMBLY__
14151+#ifdef CONFIG_X86_32
14152+#define arch_mmap_check i386_mmap_check
14153+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
14154+#endif
14155+#endif
14156+#endif
14157+
14158+#endif /* X86_MMAN_H */
14159diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
14160index 5f55e69..e20bfb1 100644
14161--- a/arch/x86/include/asm/mmu.h
14162+++ b/arch/x86/include/asm/mmu.h
14163@@ -9,7 +9,7 @@
14164 * we put the segment information here.
14165 */
14166 typedef struct {
14167- void *ldt;
14168+ struct desc_struct *ldt;
14169 int size;
14170
14171 #ifdef CONFIG_X86_64
14172@@ -18,7 +18,19 @@ typedef struct {
14173 #endif
14174
14175 struct mutex lock;
14176- void *vdso;
14177+ unsigned long vdso;
14178+
14179+#ifdef CONFIG_X86_32
14180+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
14181+ unsigned long user_cs_base;
14182+ unsigned long user_cs_limit;
14183+
14184+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
14185+ cpumask_t cpu_user_cs_mask;
14186+#endif
14187+
14188+#endif
14189+#endif
14190 } mm_context_t;
14191
14192 #ifdef CONFIG_SMP
14193diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
14194index cdbf367..adb37ac 100644
14195--- a/arch/x86/include/asm/mmu_context.h
14196+++ b/arch/x86/include/asm/mmu_context.h
14197@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
14198
14199 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
14200 {
14201+
14202+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14203+ unsigned int i;
14204+ pgd_t *pgd;
14205+
14206+ pax_open_kernel();
14207+ pgd = get_cpu_pgd(smp_processor_id());
14208+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
14209+ set_pgd_batched(pgd+i, native_make_pgd(0));
14210+ pax_close_kernel();
14211+#endif
14212+
14213 #ifdef CONFIG_SMP
14214 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
14215 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
14216@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
14217 struct task_struct *tsk)
14218 {
14219 unsigned cpu = smp_processor_id();
14220+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
14221+ int tlbstate = TLBSTATE_OK;
14222+#endif
14223
14224 if (likely(prev != next)) {
14225 #ifdef CONFIG_SMP
14226+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
14227+ tlbstate = this_cpu_read(cpu_tlbstate.state);
14228+#endif
14229 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
14230 this_cpu_write(cpu_tlbstate.active_mm, next);
14231 #endif
14232 cpumask_set_cpu(cpu, mm_cpumask(next));
14233
14234 /* Re-load page tables */
14235+#ifdef CONFIG_PAX_PER_CPU_PGD
14236+ pax_open_kernel();
14237+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
14238+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
14239+ pax_close_kernel();
14240+ load_cr3(get_cpu_pgd(cpu));
14241+#else
14242 load_cr3(next->pgd);
14243+#endif
14244
14245 /* stop flush ipis for the previous mm */
14246 cpumask_clear_cpu(cpu, mm_cpumask(prev));
14247@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
14248 */
14249 if (unlikely(prev->context.ldt != next->context.ldt))
14250 load_LDT_nolock(&next->context);
14251- }
14252+
14253+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
14254+ if (!(__supported_pte_mask & _PAGE_NX)) {
14255+ smp_mb__before_clear_bit();
14256+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
14257+ smp_mb__after_clear_bit();
14258+ cpu_set(cpu, next->context.cpu_user_cs_mask);
14259+ }
14260+#endif
14261+
14262+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
14263+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
14264+ prev->context.user_cs_limit != next->context.user_cs_limit))
14265+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
14266 #ifdef CONFIG_SMP
14267+ else if (unlikely(tlbstate != TLBSTATE_OK))
14268+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
14269+#endif
14270+#endif
14271+
14272+ }
14273 else {
14274+
14275+#ifdef CONFIG_PAX_PER_CPU_PGD
14276+ pax_open_kernel();
14277+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
14278+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
14279+ pax_close_kernel();
14280+ load_cr3(get_cpu_pgd(cpu));
14281+#endif
14282+
14283+#ifdef CONFIG_SMP
14284 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
14285 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
14286
14287@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
14288 * tlb flush IPI delivery. We must reload CR3
14289 * to make sure to use no freed page tables.
14290 */
14291+
14292+#ifndef CONFIG_PAX_PER_CPU_PGD
14293 load_cr3(next->pgd);
14294+#endif
14295+
14296 load_LDT_nolock(&next->context);
14297+
14298+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
14299+ if (!(__supported_pte_mask & _PAGE_NX))
14300+ cpu_set(cpu, next->context.cpu_user_cs_mask);
14301+#endif
14302+
14303+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
14304+#ifdef CONFIG_PAX_PAGEEXEC
14305+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
14306+#endif
14307+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
14308+#endif
14309+
14310 }
14311+#endif
14312 }
14313-#endif
14314 }
14315
14316 #define activate_mm(prev, next) \
14317diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
14318index e3b7819..b257c64 100644
14319--- a/arch/x86/include/asm/module.h
14320+++ b/arch/x86/include/asm/module.h
14321@@ -5,6 +5,7 @@
14322
14323 #ifdef CONFIG_X86_64
14324 /* X86_64 does not define MODULE_PROC_FAMILY */
14325+#define MODULE_PROC_FAMILY ""
14326 #elif defined CONFIG_M486
14327 #define MODULE_PROC_FAMILY "486 "
14328 #elif defined CONFIG_M586
14329@@ -57,8 +58,20 @@
14330 #error unknown processor family
14331 #endif
14332
14333-#ifdef CONFIG_X86_32
14334-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
14335+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
14336+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
14337+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
14338+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
14339+#else
14340+#define MODULE_PAX_KERNEXEC ""
14341 #endif
14342
14343+#ifdef CONFIG_PAX_MEMORY_UDEREF
14344+#define MODULE_PAX_UDEREF "UDEREF "
14345+#else
14346+#define MODULE_PAX_UDEREF ""
14347+#endif
14348+
14349+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
14350+
14351 #endif /* _ASM_X86_MODULE_H */
14352diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
14353index c0fa356..07a498a 100644
14354--- a/arch/x86/include/asm/nmi.h
14355+++ b/arch/x86/include/asm/nmi.h
14356@@ -42,11 +42,11 @@ struct nmiaction {
14357 nmi_handler_t handler;
14358 unsigned long flags;
14359 const char *name;
14360-};
14361+} __do_const;
14362
14363 #define register_nmi_handler(t, fn, fg, n, init...) \
14364 ({ \
14365- static struct nmiaction init fn##_na = { \
14366+ static const struct nmiaction init fn##_na = { \
14367 .handler = (fn), \
14368 .name = (n), \
14369 .flags = (fg), \
14370@@ -54,7 +54,7 @@ struct nmiaction {
14371 __register_nmi_handler((t), &fn##_na); \
14372 })
14373
14374-int __register_nmi_handler(unsigned int, struct nmiaction *);
14375+int __register_nmi_handler(unsigned int, const struct nmiaction *);
14376
14377 void unregister_nmi_handler(unsigned int, const char *);
14378
14379diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
14380index 320f7bb..e89f8f8 100644
14381--- a/arch/x86/include/asm/page_64_types.h
14382+++ b/arch/x86/include/asm/page_64_types.h
14383@@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
14384
14385 /* duplicated to the one in bootmem.h */
14386 extern unsigned long max_pfn;
14387-extern unsigned long phys_base;
14388+extern const unsigned long phys_base;
14389
14390 extern unsigned long __phys_addr(unsigned long);
14391 #define __phys_reloc_hide(x) (x)
14392diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
14393index 7361e47..16dc226 100644
14394--- a/arch/x86/include/asm/paravirt.h
14395+++ b/arch/x86/include/asm/paravirt.h
14396@@ -564,7 +564,7 @@ static inline pmd_t __pmd(pmdval_t val)
14397 return (pmd_t) { ret };
14398 }
14399
14400-static inline pmdval_t pmd_val(pmd_t pmd)
14401+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
14402 {
14403 pmdval_t ret;
14404
14405@@ -630,6 +630,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
14406 val);
14407 }
14408
14409+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
14410+{
14411+ pgdval_t val = native_pgd_val(pgd);
14412+
14413+ if (sizeof(pgdval_t) > sizeof(long))
14414+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
14415+ val, (u64)val >> 32);
14416+ else
14417+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
14418+ val);
14419+}
14420+
14421 static inline void pgd_clear(pgd_t *pgdp)
14422 {
14423 set_pgd(pgdp, __pgd(0));
14424@@ -714,6 +726,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
14425 pv_mmu_ops.set_fixmap(idx, phys, flags);
14426 }
14427
14428+#ifdef CONFIG_PAX_KERNEXEC
14429+static inline unsigned long pax_open_kernel(void)
14430+{
14431+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
14432+}
14433+
14434+static inline unsigned long pax_close_kernel(void)
14435+{
14436+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
14437+}
14438+#else
14439+static inline unsigned long pax_open_kernel(void) { return 0; }
14440+static inline unsigned long pax_close_kernel(void) { return 0; }
14441+#endif
14442+
14443 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
14444
14445 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
14446@@ -930,7 +957,7 @@ extern void default_banner(void);
14447
14448 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
14449 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
14450-#define PARA_INDIRECT(addr) *%cs:addr
14451+#define PARA_INDIRECT(addr) *%ss:addr
14452 #endif
14453
14454 #define INTERRUPT_RETURN \
14455@@ -1005,6 +1032,21 @@ extern void default_banner(void);
14456 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
14457 CLBR_NONE, \
14458 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
14459+
14460+#define GET_CR0_INTO_RDI \
14461+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
14462+ mov %rax,%rdi
14463+
14464+#define SET_RDI_INTO_CR0 \
14465+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14466+
14467+#define GET_CR3_INTO_RDI \
14468+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
14469+ mov %rax,%rdi
14470+
14471+#define SET_RDI_INTO_CR3 \
14472+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
14473+
14474 #endif /* CONFIG_X86_32 */
14475
14476 #endif /* __ASSEMBLY__ */
14477diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
14478index b3b0ec1..b1cd3eb 100644
14479--- a/arch/x86/include/asm/paravirt_types.h
14480+++ b/arch/x86/include/asm/paravirt_types.h
14481@@ -84,7 +84,7 @@ struct pv_init_ops {
14482 */
14483 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
14484 unsigned long addr, unsigned len);
14485-};
14486+} __no_const;
14487
14488
14489 struct pv_lazy_ops {
14490@@ -98,7 +98,7 @@ struct pv_time_ops {
14491 unsigned long long (*sched_clock)(void);
14492 unsigned long long (*steal_clock)(int cpu);
14493 unsigned long (*get_tsc_khz)(void);
14494-};
14495+} __no_const;
14496
14497 struct pv_cpu_ops {
14498 /* hooks for various privileged instructions */
14499@@ -192,7 +192,7 @@ struct pv_cpu_ops {
14500
14501 void (*start_context_switch)(struct task_struct *prev);
14502 void (*end_context_switch)(struct task_struct *next);
14503-};
14504+} __no_const;
14505
14506 struct pv_irq_ops {
14507 /*
14508@@ -223,7 +223,7 @@ struct pv_apic_ops {
14509 unsigned long start_eip,
14510 unsigned long start_esp);
14511 #endif
14512-};
14513+} __no_const;
14514
14515 struct pv_mmu_ops {
14516 unsigned long (*read_cr2)(void);
14517@@ -313,6 +313,7 @@ struct pv_mmu_ops {
14518 struct paravirt_callee_save make_pud;
14519
14520 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
14521+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
14522 #endif /* PAGETABLE_LEVELS == 4 */
14523 #endif /* PAGETABLE_LEVELS >= 3 */
14524
14525@@ -324,6 +325,12 @@ struct pv_mmu_ops {
14526 an mfn. We can tell which is which from the index. */
14527 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
14528 phys_addr_t phys, pgprot_t flags);
14529+
14530+#ifdef CONFIG_PAX_KERNEXEC
14531+ unsigned long (*pax_open_kernel)(void);
14532+ unsigned long (*pax_close_kernel)(void);
14533+#endif
14534+
14535 };
14536
14537 struct arch_spinlock;
14538@@ -334,7 +341,7 @@ struct pv_lock_ops {
14539 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
14540 int (*spin_trylock)(struct arch_spinlock *lock);
14541 void (*spin_unlock)(struct arch_spinlock *lock);
14542-};
14543+} __no_const;
14544
14545 /* This contains all the paravirt structures: we get a convenient
14546 * number for each function using the offset which we use to indicate
14547diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
14548index b4389a4..7024269 100644
14549--- a/arch/x86/include/asm/pgalloc.h
14550+++ b/arch/x86/include/asm/pgalloc.h
14551@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
14552 pmd_t *pmd, pte_t *pte)
14553 {
14554 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
14555+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
14556+}
14557+
14558+static inline void pmd_populate_user(struct mm_struct *mm,
14559+ pmd_t *pmd, pte_t *pte)
14560+{
14561+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
14562 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
14563 }
14564
14565@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
14566
14567 #ifdef CONFIG_X86_PAE
14568 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
14569+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
14570+{
14571+ pud_populate(mm, pudp, pmd);
14572+}
14573 #else /* !CONFIG_X86_PAE */
14574 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
14575 {
14576 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
14577 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
14578 }
14579+
14580+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
14581+{
14582+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
14583+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
14584+}
14585 #endif /* CONFIG_X86_PAE */
14586
14587 #if PAGETABLE_LEVELS > 3
14588@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
14589 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
14590 }
14591
14592+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
14593+{
14594+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
14595+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
14596+}
14597+
14598 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
14599 {
14600 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
14601diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
14602index f2b489c..4f7e2e5 100644
14603--- a/arch/x86/include/asm/pgtable-2level.h
14604+++ b/arch/x86/include/asm/pgtable-2level.h
14605@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
14606
14607 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14608 {
14609+ pax_open_kernel();
14610 *pmdp = pmd;
14611+ pax_close_kernel();
14612 }
14613
14614 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14615diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
14616index 4cc9f2b..5fd9226 100644
14617--- a/arch/x86/include/asm/pgtable-3level.h
14618+++ b/arch/x86/include/asm/pgtable-3level.h
14619@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14620
14621 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14622 {
14623+ pax_open_kernel();
14624 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
14625+ pax_close_kernel();
14626 }
14627
14628 static inline void native_set_pud(pud_t *pudp, pud_t pud)
14629 {
14630+ pax_open_kernel();
14631 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
14632+ pax_close_kernel();
14633 }
14634
14635 /*
14636diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
14637index 1c1a955..50f828c 100644
14638--- a/arch/x86/include/asm/pgtable.h
14639+++ b/arch/x86/include/asm/pgtable.h
14640@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
14641
14642 #ifndef __PAGETABLE_PUD_FOLDED
14643 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
14644+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
14645 #define pgd_clear(pgd) native_pgd_clear(pgd)
14646 #endif
14647
14648@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
14649
14650 #define arch_end_context_switch(prev) do {} while(0)
14651
14652+#define pax_open_kernel() native_pax_open_kernel()
14653+#define pax_close_kernel() native_pax_close_kernel()
14654 #endif /* CONFIG_PARAVIRT */
14655
14656+#define __HAVE_ARCH_PAX_OPEN_KERNEL
14657+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
14658+
14659+#ifdef CONFIG_PAX_KERNEXEC
14660+static inline unsigned long native_pax_open_kernel(void)
14661+{
14662+ unsigned long cr0;
14663+
14664+ preempt_disable();
14665+ barrier();
14666+ cr0 = read_cr0() ^ X86_CR0_WP;
14667+ BUG_ON(cr0 & X86_CR0_WP);
14668+ write_cr0(cr0);
14669+ return cr0 ^ X86_CR0_WP;
14670+}
14671+
14672+static inline unsigned long native_pax_close_kernel(void)
14673+{
14674+ unsigned long cr0;
14675+
14676+ cr0 = read_cr0() ^ X86_CR0_WP;
14677+ BUG_ON(!(cr0 & X86_CR0_WP));
14678+ write_cr0(cr0);
14679+ barrier();
14680+ preempt_enable_no_resched();
14681+ return cr0 ^ X86_CR0_WP;
14682+}
14683+#else
14684+static inline unsigned long native_pax_open_kernel(void) { return 0; }
14685+static inline unsigned long native_pax_close_kernel(void) { return 0; }
14686+#endif
14687+
14688 /*
14689 * The following only work if pte_present() is true.
14690 * Undefined behaviour if not..
14691 */
14692+static inline int pte_user(pte_t pte)
14693+{
14694+ return pte_val(pte) & _PAGE_USER;
14695+}
14696+
14697 static inline int pte_dirty(pte_t pte)
14698 {
14699 return pte_flags(pte) & _PAGE_DIRTY;
14700@@ -200,9 +240,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
14701 return pte_clear_flags(pte, _PAGE_RW);
14702 }
14703
14704+static inline pte_t pte_mkread(pte_t pte)
14705+{
14706+ return __pte(pte_val(pte) | _PAGE_USER);
14707+}
14708+
14709 static inline pte_t pte_mkexec(pte_t pte)
14710 {
14711- return pte_clear_flags(pte, _PAGE_NX);
14712+#ifdef CONFIG_X86_PAE
14713+ if (__supported_pte_mask & _PAGE_NX)
14714+ return pte_clear_flags(pte, _PAGE_NX);
14715+ else
14716+#endif
14717+ return pte_set_flags(pte, _PAGE_USER);
14718+}
14719+
14720+static inline pte_t pte_exprotect(pte_t pte)
14721+{
14722+#ifdef CONFIG_X86_PAE
14723+ if (__supported_pte_mask & _PAGE_NX)
14724+ return pte_set_flags(pte, _PAGE_NX);
14725+ else
14726+#endif
14727+ return pte_clear_flags(pte, _PAGE_USER);
14728 }
14729
14730 static inline pte_t pte_mkdirty(pte_t pte)
14731@@ -394,6 +454,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
14732 #endif
14733
14734 #ifndef __ASSEMBLY__
14735+
14736+#ifdef CONFIG_PAX_PER_CPU_PGD
14737+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
14738+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
14739+{
14740+ return cpu_pgd[cpu];
14741+}
14742+#endif
14743+
14744 #include <linux/mm_types.h>
14745
14746 static inline int pte_none(pte_t pte)
14747@@ -583,7 +652,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
14748
14749 static inline int pgd_bad(pgd_t pgd)
14750 {
14751- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
14752+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
14753 }
14754
14755 static inline int pgd_none(pgd_t pgd)
14756@@ -606,7 +675,12 @@ static inline int pgd_none(pgd_t pgd)
14757 * pgd_offset() returns a (pgd_t *)
14758 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
14759 */
14760-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
14761+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
14762+
14763+#ifdef CONFIG_PAX_PER_CPU_PGD
14764+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
14765+#endif
14766+
14767 /*
14768 * a shortcut which implies the use of the kernel's pgd, instead
14769 * of a process's
14770@@ -617,6 +691,20 @@ static inline int pgd_none(pgd_t pgd)
14771 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
14772 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
14773
14774+#ifdef CONFIG_X86_32
14775+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
14776+#else
14777+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
14778+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
14779+
14780+#ifdef CONFIG_PAX_MEMORY_UDEREF
14781+#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
14782+#else
14783+#define PAX_USER_SHADOW_BASE (_AC(0,UL))
14784+#endif
14785+
14786+#endif
14787+
14788 #ifndef __ASSEMBLY__
14789
14790 extern int direct_gbpages;
14791@@ -781,11 +869,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
14792 * dst and src can be on the same page, but the range must not overlap,
14793 * and must not cross a page boundary.
14794 */
14795-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
14796+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
14797 {
14798- memcpy(dst, src, count * sizeof(pgd_t));
14799+ pax_open_kernel();
14800+ while (count--)
14801+ *dst++ = *src++;
14802+ pax_close_kernel();
14803 }
14804
14805+#ifdef CONFIG_PAX_PER_CPU_PGD
14806+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
14807+#endif
14808+
14809+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14810+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
14811+#else
14812+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
14813+#endif
14814
14815 #include <asm-generic/pgtable.h>
14816 #endif /* __ASSEMBLY__ */
14817diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
14818index 8faa215..a8a17ea 100644
14819--- a/arch/x86/include/asm/pgtable_32.h
14820+++ b/arch/x86/include/asm/pgtable_32.h
14821@@ -25,9 +25,6 @@
14822 struct mm_struct;
14823 struct vm_area_struct;
14824
14825-extern pgd_t swapper_pg_dir[1024];
14826-extern pgd_t initial_page_table[1024];
14827-
14828 static inline void pgtable_cache_init(void) { }
14829 static inline void check_pgt_cache(void) { }
14830 void paging_init(void);
14831@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14832 # include <asm/pgtable-2level.h>
14833 #endif
14834
14835+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
14836+extern pgd_t initial_page_table[PTRS_PER_PGD];
14837+#ifdef CONFIG_X86_PAE
14838+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
14839+#endif
14840+
14841 #if defined(CONFIG_HIGHPTE)
14842 #define pte_offset_map(dir, address) \
14843 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
14844@@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14845 /* Clear a kernel PTE and flush it from the TLB */
14846 #define kpte_clear_flush(ptep, vaddr) \
14847 do { \
14848+ pax_open_kernel(); \
14849 pte_clear(&init_mm, (vaddr), (ptep)); \
14850+ pax_close_kernel(); \
14851 __flush_tlb_one((vaddr)); \
14852 } while (0)
14853
14854@@ -75,6 +80,9 @@ do { \
14855
14856 #endif /* !__ASSEMBLY__ */
14857
14858+#define HAVE_ARCH_UNMAPPED_AREA
14859+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
14860+
14861 /*
14862 * kern_addr_valid() is (1) for FLATMEM and (0) for
14863 * SPARSEMEM and DISCONTIGMEM
14864diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
14865index ed5903b..c7fe163 100644
14866--- a/arch/x86/include/asm/pgtable_32_types.h
14867+++ b/arch/x86/include/asm/pgtable_32_types.h
14868@@ -8,7 +8,7 @@
14869 */
14870 #ifdef CONFIG_X86_PAE
14871 # include <asm/pgtable-3level_types.h>
14872-# define PMD_SIZE (1UL << PMD_SHIFT)
14873+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
14874 # define PMD_MASK (~(PMD_SIZE - 1))
14875 #else
14876 # include <asm/pgtable-2level_types.h>
14877@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
14878 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
14879 #endif
14880
14881+#ifdef CONFIG_PAX_KERNEXEC
14882+#ifndef __ASSEMBLY__
14883+extern unsigned char MODULES_EXEC_VADDR[];
14884+extern unsigned char MODULES_EXEC_END[];
14885+#endif
14886+#include <asm/boot.h>
14887+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
14888+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
14889+#else
14890+#define ktla_ktva(addr) (addr)
14891+#define ktva_ktla(addr) (addr)
14892+#endif
14893+
14894 #define MODULES_VADDR VMALLOC_START
14895 #define MODULES_END VMALLOC_END
14896 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
14897diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
14898index 47356f9..deb94a2 100644
14899--- a/arch/x86/include/asm/pgtable_64.h
14900+++ b/arch/x86/include/asm/pgtable_64.h
14901@@ -16,10 +16,14 @@
14902
14903 extern pud_t level3_kernel_pgt[512];
14904 extern pud_t level3_ident_pgt[512];
14905+extern pud_t level3_vmalloc_start_pgt[512];
14906+extern pud_t level3_vmalloc_end_pgt[512];
14907+extern pud_t level3_vmemmap_pgt[512];
14908+extern pud_t level2_vmemmap_pgt[512];
14909 extern pmd_t level2_kernel_pgt[512];
14910 extern pmd_t level2_fixmap_pgt[512];
14911-extern pmd_t level2_ident_pgt[512];
14912-extern pgd_t init_level4_pgt[];
14913+extern pmd_t level2_ident_pgt[512*2];
14914+extern pgd_t init_level4_pgt[512];
14915
14916 #define swapper_pg_dir init_level4_pgt
14917
14918@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14919
14920 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14921 {
14922+ pax_open_kernel();
14923 *pmdp = pmd;
14924+ pax_close_kernel();
14925 }
14926
14927 static inline void native_pmd_clear(pmd_t *pmd)
14928@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
14929
14930 static inline void native_set_pud(pud_t *pudp, pud_t pud)
14931 {
14932+ pax_open_kernel();
14933 *pudp = pud;
14934+ pax_close_kernel();
14935 }
14936
14937 static inline void native_pud_clear(pud_t *pud)
14938@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
14939
14940 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
14941 {
14942+ pax_open_kernel();
14943+ *pgdp = pgd;
14944+ pax_close_kernel();
14945+}
14946+
14947+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
14948+{
14949 *pgdp = pgd;
14950 }
14951
14952diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
14953index 766ea16..5b96cb3 100644
14954--- a/arch/x86/include/asm/pgtable_64_types.h
14955+++ b/arch/x86/include/asm/pgtable_64_types.h
14956@@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
14957 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
14958 #define MODULES_END _AC(0xffffffffff000000, UL)
14959 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
14960+#define MODULES_EXEC_VADDR MODULES_VADDR
14961+#define MODULES_EXEC_END MODULES_END
14962+
14963+#define ktla_ktva(addr) (addr)
14964+#define ktva_ktla(addr) (addr)
14965
14966 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
14967diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
14968index 3c32db8..1ddccf5 100644
14969--- a/arch/x86/include/asm/pgtable_types.h
14970+++ b/arch/x86/include/asm/pgtable_types.h
14971@@ -16,13 +16,12 @@
14972 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
14973 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
14974 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
14975-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
14976+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
14977 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
14978 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
14979 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
14980-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
14981-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
14982-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
14983+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
14984+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
14985 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
14986
14987 /* If _PAGE_BIT_PRESENT is clear, we use these: */
14988@@ -40,7 +39,6 @@
14989 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
14990 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
14991 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
14992-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
14993 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
14994 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
14995 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
14996@@ -57,8 +55,10 @@
14997
14998 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
14999 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
15000-#else
15001+#elif defined(CONFIG_KMEMCHECK)
15002 #define _PAGE_NX (_AT(pteval_t, 0))
15003+#else
15004+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
15005 #endif
15006
15007 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
15008@@ -116,6 +116,9 @@
15009 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
15010 _PAGE_ACCESSED)
15011
15012+#define PAGE_READONLY_NOEXEC PAGE_READONLY
15013+#define PAGE_SHARED_NOEXEC PAGE_SHARED
15014+
15015 #define __PAGE_KERNEL_EXEC \
15016 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
15017 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
15018@@ -126,7 +129,7 @@
15019 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
15020 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
15021 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
15022-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
15023+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
15024 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
15025 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
15026 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
15027@@ -188,8 +191,8 @@
15028 * bits are combined, this will alow user to access the high address mapped
15029 * VDSO in the presence of CONFIG_COMPAT_VDSO
15030 */
15031-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
15032-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
15033+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
15034+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
15035 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
15036 #endif
15037
15038@@ -227,7 +230,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
15039 {
15040 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
15041 }
15042+#endif
15043
15044+#if PAGETABLE_LEVELS == 3
15045+#include <asm-generic/pgtable-nopud.h>
15046+#endif
15047+
15048+#if PAGETABLE_LEVELS == 2
15049+#include <asm-generic/pgtable-nopmd.h>
15050+#endif
15051+
15052+#ifndef __ASSEMBLY__
15053 #if PAGETABLE_LEVELS > 3
15054 typedef struct { pudval_t pud; } pud_t;
15055
15056@@ -241,8 +254,6 @@ static inline pudval_t native_pud_val(pud_t pud)
15057 return pud.pud;
15058 }
15059 #else
15060-#include <asm-generic/pgtable-nopud.h>
15061-
15062 static inline pudval_t native_pud_val(pud_t pud)
15063 {
15064 return native_pgd_val(pud.pgd);
15065@@ -262,8 +273,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
15066 return pmd.pmd;
15067 }
15068 #else
15069-#include <asm-generic/pgtable-nopmd.h>
15070-
15071 static inline pmdval_t native_pmd_val(pmd_t pmd)
15072 {
15073 return native_pgd_val(pmd.pud.pgd);
15074@@ -303,7 +312,6 @@ typedef struct page *pgtable_t;
15075
15076 extern pteval_t __supported_pte_mask;
15077 extern void set_nx(void);
15078-extern int nx_enabled;
15079
15080 #define pgprot_writecombine pgprot_writecombine
15081 extern pgprot_t pgprot_writecombine(pgprot_t prot);
15082diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
15083index 888184b..a07ac89 100644
15084--- a/arch/x86/include/asm/processor.h
15085+++ b/arch/x86/include/asm/processor.h
15086@@ -287,7 +287,7 @@ struct tss_struct {
15087
15088 } ____cacheline_aligned;
15089
15090-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
15091+extern struct tss_struct init_tss[NR_CPUS];
15092
15093 /*
15094 * Save the original ist values for checking stack pointers during debugging
15095@@ -827,11 +827,18 @@ static inline void spin_lock_prefetch(const void *x)
15096 */
15097 #define TASK_SIZE PAGE_OFFSET
15098 #define TASK_SIZE_MAX TASK_SIZE
15099+
15100+#ifdef CONFIG_PAX_SEGMEXEC
15101+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
15102+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
15103+#else
15104 #define STACK_TOP TASK_SIZE
15105-#define STACK_TOP_MAX STACK_TOP
15106+#endif
15107+
15108+#define STACK_TOP_MAX TASK_SIZE
15109
15110 #define INIT_THREAD { \
15111- .sp0 = sizeof(init_stack) + (long)&init_stack, \
15112+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
15113 .vm86_info = NULL, \
15114 .sysenter_cs = __KERNEL_CS, \
15115 .io_bitmap_ptr = NULL, \
15116@@ -845,7 +852,7 @@ static inline void spin_lock_prefetch(const void *x)
15117 */
15118 #define INIT_TSS { \
15119 .x86_tss = { \
15120- .sp0 = sizeof(init_stack) + (long)&init_stack, \
15121+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
15122 .ss0 = __KERNEL_DS, \
15123 .ss1 = __KERNEL_CS, \
15124 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
15125@@ -856,11 +863,7 @@ static inline void spin_lock_prefetch(const void *x)
15126 extern unsigned long thread_saved_pc(struct task_struct *tsk);
15127
15128 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
15129-#define KSTK_TOP(info) \
15130-({ \
15131- unsigned long *__ptr = (unsigned long *)(info); \
15132- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
15133-})
15134+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
15135
15136 /*
15137 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
15138@@ -875,7 +878,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
15139 #define task_pt_regs(task) \
15140 ({ \
15141 struct pt_regs *__regs__; \
15142- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
15143+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
15144 __regs__ - 1; \
15145 })
15146
15147@@ -885,13 +888,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
15148 /*
15149 * User space process size. 47bits minus one guard page.
15150 */
15151-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
15152+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
15153
15154 /* This decides where the kernel will search for a free chunk of vm
15155 * space during mmap's.
15156 */
15157 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
15158- 0xc0000000 : 0xFFFFe000)
15159+ 0xc0000000 : 0xFFFFf000)
15160
15161 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
15162 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
15163@@ -902,11 +905,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
15164 #define STACK_TOP_MAX TASK_SIZE_MAX
15165
15166 #define INIT_THREAD { \
15167- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
15168+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
15169 }
15170
15171 #define INIT_TSS { \
15172- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
15173+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
15174 }
15175
15176 /*
15177@@ -934,6 +937,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
15178 */
15179 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
15180
15181+#ifdef CONFIG_PAX_SEGMEXEC
15182+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
15183+#endif
15184+
15185 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
15186
15187 /* Get/set a process' ability to use the timestamp counter instruction */
15188@@ -994,12 +1001,12 @@ extern bool cpu_has_amd_erratum(const int *);
15189 #define cpu_has_amd_erratum(x) (false)
15190 #endif /* CONFIG_CPU_SUP_AMD */
15191
15192-extern unsigned long arch_align_stack(unsigned long sp);
15193+#define arch_align_stack(x) ((x) & ~0xfUL)
15194 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
15195
15196 void default_idle(void);
15197 bool set_pm_idle_to_default(void);
15198
15199-void stop_this_cpu(void *dummy);
15200+void stop_this_cpu(void *dummy) __noreturn;
15201
15202 #endif /* _ASM_X86_PROCESSOR_H */
15203diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
15204index 942a086..6c26446 100644
15205--- a/arch/x86/include/asm/ptrace.h
15206+++ b/arch/x86/include/asm/ptrace.h
15207@@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
15208 }
15209
15210 /*
15211- * user_mode_vm(regs) determines whether a register set came from user mode.
15212+ * user_mode(regs) determines whether a register set came from user mode.
15213 * This is true if V8086 mode was enabled OR if the register set was from
15214 * protected mode with RPL-3 CS value. This tricky test checks that with
15215 * one comparison. Many places in the kernel can bypass this full check
15216- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
15217+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
15218+ * be used.
15219 */
15220-static inline int user_mode(struct pt_regs *regs)
15221+static inline int user_mode_novm(struct pt_regs *regs)
15222 {
15223 #ifdef CONFIG_X86_32
15224 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
15225 #else
15226- return !!(regs->cs & 3);
15227+ return !!(regs->cs & SEGMENT_RPL_MASK);
15228 #endif
15229 }
15230
15231-static inline int user_mode_vm(struct pt_regs *regs)
15232+static inline int user_mode(struct pt_regs *regs)
15233 {
15234 #ifdef CONFIG_X86_32
15235 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
15236 USER_RPL;
15237 #else
15238- return user_mode(regs);
15239+ return user_mode_novm(regs);
15240 #endif
15241 }
15242
15243@@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
15244 #ifdef CONFIG_X86_64
15245 static inline bool user_64bit_mode(struct pt_regs *regs)
15246 {
15247+ unsigned long cs = regs->cs & 0xffff;
15248 #ifndef CONFIG_PARAVIRT
15249 /*
15250 * On non-paravirt systems, this is the only long mode CPL 3
15251 * selector. We do not allow long mode selectors in the LDT.
15252 */
15253- return regs->cs == __USER_CS;
15254+ return cs == __USER_CS;
15255 #else
15256 /* Headers are too twisted for this to go in paravirt.h. */
15257- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
15258+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
15259 #endif
15260 }
15261
15262@@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
15263 * Traps from the kernel do not save sp and ss.
15264 * Use the helper function to retrieve sp.
15265 */
15266- if (offset == offsetof(struct pt_regs, sp) &&
15267- regs->cs == __KERNEL_CS)
15268- return kernel_stack_pointer(regs);
15269+ if (offset == offsetof(struct pt_regs, sp)) {
15270+ unsigned long cs = regs->cs & 0xffff;
15271+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
15272+ return kernel_stack_pointer(regs);
15273+ }
15274 #endif
15275 return *(unsigned long *)((unsigned long)regs + offset);
15276 }
15277diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
15278index fe1ec5b..dc5c3fe 100644
15279--- a/arch/x86/include/asm/realmode.h
15280+++ b/arch/x86/include/asm/realmode.h
15281@@ -22,16 +22,14 @@ struct real_mode_header {
15282 #endif
15283 /* APM/BIOS reboot */
15284 u32 machine_real_restart_asm;
15285-#ifdef CONFIG_X86_64
15286 u32 machine_real_restart_seg;
15287-#endif
15288 };
15289
15290 /* This must match data at trampoline_32/64.S */
15291 struct trampoline_header {
15292 #ifdef CONFIG_X86_32
15293 u32 start;
15294- u16 gdt_pad;
15295+ u16 boot_cs;
15296 u16 gdt_limit;
15297 u32 gdt_base;
15298 #else
15299diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
15300index a82c4f1..ac45053 100644
15301--- a/arch/x86/include/asm/reboot.h
15302+++ b/arch/x86/include/asm/reboot.h
15303@@ -6,13 +6,13 @@
15304 struct pt_regs;
15305
15306 struct machine_ops {
15307- void (*restart)(char *cmd);
15308- void (*halt)(void);
15309- void (*power_off)(void);
15310+ void (* __noreturn restart)(char *cmd);
15311+ void (* __noreturn halt)(void);
15312+ void (* __noreturn power_off)(void);
15313 void (*shutdown)(void);
15314 void (*crash_shutdown)(struct pt_regs *);
15315- void (*emergency_restart)(void);
15316-};
15317+ void (* __noreturn emergency_restart)(void);
15318+} __no_const;
15319
15320 extern struct machine_ops machine_ops;
15321
15322diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
15323index 2dbe4a7..ce1db00 100644
15324--- a/arch/x86/include/asm/rwsem.h
15325+++ b/arch/x86/include/asm/rwsem.h
15326@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
15327 {
15328 asm volatile("# beginning down_read\n\t"
15329 LOCK_PREFIX _ASM_INC "(%1)\n\t"
15330+
15331+#ifdef CONFIG_PAX_REFCOUNT
15332+ "jno 0f\n"
15333+ LOCK_PREFIX _ASM_DEC "(%1)\n"
15334+ "int $4\n0:\n"
15335+ _ASM_EXTABLE(0b, 0b)
15336+#endif
15337+
15338 /* adds 0x00000001 */
15339 " jns 1f\n"
15340 " call call_rwsem_down_read_failed\n"
15341@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
15342 "1:\n\t"
15343 " mov %1,%2\n\t"
15344 " add %3,%2\n\t"
15345+
15346+#ifdef CONFIG_PAX_REFCOUNT
15347+ "jno 0f\n"
15348+ "sub %3,%2\n"
15349+ "int $4\n0:\n"
15350+ _ASM_EXTABLE(0b, 0b)
15351+#endif
15352+
15353 " jle 2f\n\t"
15354 LOCK_PREFIX " cmpxchg %2,%0\n\t"
15355 " jnz 1b\n\t"
15356@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
15357 long tmp;
15358 asm volatile("# beginning down_write\n\t"
15359 LOCK_PREFIX " xadd %1,(%2)\n\t"
15360+
15361+#ifdef CONFIG_PAX_REFCOUNT
15362+ "jno 0f\n"
15363+ "mov %1,(%2)\n"
15364+ "int $4\n0:\n"
15365+ _ASM_EXTABLE(0b, 0b)
15366+#endif
15367+
15368 /* adds 0xffff0001, returns the old value */
15369 " test %1,%1\n\t"
15370 /* was the count 0 before? */
15371@@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
15372 long tmp;
15373 asm volatile("# beginning __up_read\n\t"
15374 LOCK_PREFIX " xadd %1,(%2)\n\t"
15375+
15376+#ifdef CONFIG_PAX_REFCOUNT
15377+ "jno 0f\n"
15378+ "mov %1,(%2)\n"
15379+ "int $4\n0:\n"
15380+ _ASM_EXTABLE(0b, 0b)
15381+#endif
15382+
15383 /* subtracts 1, returns the old value */
15384 " jns 1f\n\t"
15385 " call call_rwsem_wake\n" /* expects old value in %edx */
15386@@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
15387 long tmp;
15388 asm volatile("# beginning __up_write\n\t"
15389 LOCK_PREFIX " xadd %1,(%2)\n\t"
15390+
15391+#ifdef CONFIG_PAX_REFCOUNT
15392+ "jno 0f\n"
15393+ "mov %1,(%2)\n"
15394+ "int $4\n0:\n"
15395+ _ASM_EXTABLE(0b, 0b)
15396+#endif
15397+
15398 /* subtracts 0xffff0001, returns the old value */
15399 " jns 1f\n\t"
15400 " call call_rwsem_wake\n" /* expects old value in %edx */
15401@@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
15402 {
15403 asm volatile("# beginning __downgrade_write\n\t"
15404 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
15405+
15406+#ifdef CONFIG_PAX_REFCOUNT
15407+ "jno 0f\n"
15408+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
15409+ "int $4\n0:\n"
15410+ _ASM_EXTABLE(0b, 0b)
15411+#endif
15412+
15413 /*
15414 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
15415 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
15416@@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
15417 */
15418 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
15419 {
15420- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
15421+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
15422+
15423+#ifdef CONFIG_PAX_REFCOUNT
15424+ "jno 0f\n"
15425+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
15426+ "int $4\n0:\n"
15427+ _ASM_EXTABLE(0b, 0b)
15428+#endif
15429+
15430 : "+m" (sem->count)
15431 : "er" (delta));
15432 }
15433@@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
15434 */
15435 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
15436 {
15437- return delta + xadd(&sem->count, delta);
15438+ return delta + xadd_check_overflow(&sem->count, delta);
15439 }
15440
15441 #endif /* __KERNEL__ */
15442diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
15443index c48a950..c6d7468 100644
15444--- a/arch/x86/include/asm/segment.h
15445+++ b/arch/x86/include/asm/segment.h
15446@@ -64,10 +64,15 @@
15447 * 26 - ESPFIX small SS
15448 * 27 - per-cpu [ offset to per-cpu data area ]
15449 * 28 - stack_canary-20 [ for stack protector ]
15450- * 29 - unused
15451- * 30 - unused
15452+ * 29 - PCI BIOS CS
15453+ * 30 - PCI BIOS DS
15454 * 31 - TSS for double fault handler
15455 */
15456+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
15457+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
15458+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
15459+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
15460+
15461 #define GDT_ENTRY_TLS_MIN 6
15462 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
15463
15464@@ -79,6 +84,8 @@
15465
15466 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
15467
15468+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
15469+
15470 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
15471
15472 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
15473@@ -104,6 +111,12 @@
15474 #define __KERNEL_STACK_CANARY 0
15475 #endif
15476
15477+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
15478+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
15479+
15480+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
15481+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
15482+
15483 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
15484
15485 /*
15486@@ -141,7 +154,7 @@
15487 */
15488
15489 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
15490-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
15491+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
15492
15493
15494 #else
15495@@ -165,6 +178,8 @@
15496 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
15497 #define __USER32_DS __USER_DS
15498
15499+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
15500+
15501 #define GDT_ENTRY_TSS 8 /* needs two entries */
15502 #define GDT_ENTRY_LDT 10 /* needs two entries */
15503 #define GDT_ENTRY_TLS_MIN 12
15504@@ -185,6 +200,7 @@
15505 #endif
15506
15507 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
15508+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
15509 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
15510 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
15511 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
15512@@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
15513 {
15514 unsigned long __limit;
15515 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
15516- return __limit + 1;
15517+ return __limit;
15518 }
15519
15520 #endif /* !__ASSEMBLY__ */
15521diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
15522index b073aae..39f9bdd 100644
15523--- a/arch/x86/include/asm/smp.h
15524+++ b/arch/x86/include/asm/smp.h
15525@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
15526 /* cpus sharing the last level cache: */
15527 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
15528 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
15529-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
15530+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
15531
15532 static inline struct cpumask *cpu_sibling_mask(int cpu)
15533 {
15534@@ -79,7 +79,7 @@ struct smp_ops {
15535
15536 void (*send_call_func_ipi)(const struct cpumask *mask);
15537 void (*send_call_func_single_ipi)(int cpu);
15538-};
15539+} __no_const;
15540
15541 /* Globals due to paravirt */
15542 extern void set_cpu_sibling_map(int cpu);
15543@@ -191,14 +191,8 @@ extern unsigned disabled_cpus __cpuinitdata;
15544 extern int safe_smp_processor_id(void);
15545
15546 #elif defined(CONFIG_X86_64_SMP)
15547-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
15548-
15549-#define stack_smp_processor_id() \
15550-({ \
15551- struct thread_info *ti; \
15552- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
15553- ti->cpu; \
15554-})
15555+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
15556+#define stack_smp_processor_id() raw_smp_processor_id()
15557 #define safe_smp_processor_id() smp_processor_id()
15558
15559 #endif
15560diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
15561index 33692ea..350a534 100644
15562--- a/arch/x86/include/asm/spinlock.h
15563+++ b/arch/x86/include/asm/spinlock.h
15564@@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
15565 static inline void arch_read_lock(arch_rwlock_t *rw)
15566 {
15567 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
15568+
15569+#ifdef CONFIG_PAX_REFCOUNT
15570+ "jno 0f\n"
15571+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
15572+ "int $4\n0:\n"
15573+ _ASM_EXTABLE(0b, 0b)
15574+#endif
15575+
15576 "jns 1f\n"
15577 "call __read_lock_failed\n\t"
15578 "1:\n"
15579@@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
15580 static inline void arch_write_lock(arch_rwlock_t *rw)
15581 {
15582 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
15583+
15584+#ifdef CONFIG_PAX_REFCOUNT
15585+ "jno 0f\n"
15586+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
15587+ "int $4\n0:\n"
15588+ _ASM_EXTABLE(0b, 0b)
15589+#endif
15590+
15591 "jz 1f\n"
15592 "call __write_lock_failed\n\t"
15593 "1:\n"
15594@@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
15595
15596 static inline void arch_read_unlock(arch_rwlock_t *rw)
15597 {
15598- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
15599+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
15600+
15601+#ifdef CONFIG_PAX_REFCOUNT
15602+ "jno 0f\n"
15603+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
15604+ "int $4\n0:\n"
15605+ _ASM_EXTABLE(0b, 0b)
15606+#endif
15607+
15608 :"+m" (rw->lock) : : "memory");
15609 }
15610
15611 static inline void arch_write_unlock(arch_rwlock_t *rw)
15612 {
15613- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
15614+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
15615+
15616+#ifdef CONFIG_PAX_REFCOUNT
15617+ "jno 0f\n"
15618+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
15619+ "int $4\n0:\n"
15620+ _ASM_EXTABLE(0b, 0b)
15621+#endif
15622+
15623 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
15624 }
15625
15626diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
15627index 6a99859..03cb807 100644
15628--- a/arch/x86/include/asm/stackprotector.h
15629+++ b/arch/x86/include/asm/stackprotector.h
15630@@ -47,7 +47,7 @@
15631 * head_32 for boot CPU and setup_per_cpu_areas() for others.
15632 */
15633 #define GDT_STACK_CANARY_INIT \
15634- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
15635+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
15636
15637 /*
15638 * Initialize the stackprotector canary value.
15639@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
15640
15641 static inline void load_stack_canary_segment(void)
15642 {
15643-#ifdef CONFIG_X86_32
15644+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
15645 asm volatile ("mov %0, %%gs" : : "r" (0));
15646 #endif
15647 }
15648diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
15649index 70bbe39..4ae2bd4 100644
15650--- a/arch/x86/include/asm/stacktrace.h
15651+++ b/arch/x86/include/asm/stacktrace.h
15652@@ -11,28 +11,20 @@
15653
15654 extern int kstack_depth_to_print;
15655
15656-struct thread_info;
15657+struct task_struct;
15658 struct stacktrace_ops;
15659
15660-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
15661- unsigned long *stack,
15662- unsigned long bp,
15663- const struct stacktrace_ops *ops,
15664- void *data,
15665- unsigned long *end,
15666- int *graph);
15667+typedef unsigned long walk_stack_t(struct task_struct *task,
15668+ void *stack_start,
15669+ unsigned long *stack,
15670+ unsigned long bp,
15671+ const struct stacktrace_ops *ops,
15672+ void *data,
15673+ unsigned long *end,
15674+ int *graph);
15675
15676-extern unsigned long
15677-print_context_stack(struct thread_info *tinfo,
15678- unsigned long *stack, unsigned long bp,
15679- const struct stacktrace_ops *ops, void *data,
15680- unsigned long *end, int *graph);
15681-
15682-extern unsigned long
15683-print_context_stack_bp(struct thread_info *tinfo,
15684- unsigned long *stack, unsigned long bp,
15685- const struct stacktrace_ops *ops, void *data,
15686- unsigned long *end, int *graph);
15687+extern walk_stack_t print_context_stack;
15688+extern walk_stack_t print_context_stack_bp;
15689
15690 /* Generic stack tracer with callbacks */
15691
15692@@ -40,7 +32,7 @@ struct stacktrace_ops {
15693 void (*address)(void *data, unsigned long address, int reliable);
15694 /* On negative return stop dumping */
15695 int (*stack)(void *data, char *name);
15696- walk_stack_t walk_stack;
15697+ walk_stack_t *walk_stack;
15698 };
15699
15700 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
15701diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
15702index 4ec45b3..a4f0a8a 100644
15703--- a/arch/x86/include/asm/switch_to.h
15704+++ b/arch/x86/include/asm/switch_to.h
15705@@ -108,7 +108,7 @@ do { \
15706 "call __switch_to\n\t" \
15707 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
15708 __switch_canary \
15709- "movq %P[thread_info](%%rsi),%%r8\n\t" \
15710+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
15711 "movq %%rax,%%rdi\n\t" \
15712 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
15713 "jnz ret_from_fork\n\t" \
15714@@ -119,7 +119,7 @@ do { \
15715 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
15716 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
15717 [_tif_fork] "i" (_TIF_FORK), \
15718- [thread_info] "i" (offsetof(struct task_struct, stack)), \
15719+ [thread_info] "m" (current_tinfo), \
15720 [current_task] "m" (current_task) \
15721 __switch_canary_iparam \
15722 : "memory", "cc" __EXTRA_CLOBBER)
15723diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
15724index 2d946e6..e453ec4 100644
15725--- a/arch/x86/include/asm/thread_info.h
15726+++ b/arch/x86/include/asm/thread_info.h
15727@@ -10,6 +10,7 @@
15728 #include <linux/compiler.h>
15729 #include <asm/page.h>
15730 #include <asm/types.h>
15731+#include <asm/percpu.h>
15732
15733 /*
15734 * low level task data that entry.S needs immediate access to
15735@@ -24,7 +25,6 @@ struct exec_domain;
15736 #include <linux/atomic.h>
15737
15738 struct thread_info {
15739- struct task_struct *task; /* main task structure */
15740 struct exec_domain *exec_domain; /* execution domain */
15741 __u32 flags; /* low level flags */
15742 __u32 status; /* thread synchronous flags */
15743@@ -34,19 +34,13 @@ struct thread_info {
15744 mm_segment_t addr_limit;
15745 struct restart_block restart_block;
15746 void __user *sysenter_return;
15747-#ifdef CONFIG_X86_32
15748- unsigned long previous_esp; /* ESP of the previous stack in
15749- case of nested (IRQ) stacks
15750- */
15751- __u8 supervisor_stack[0];
15752-#endif
15753+ unsigned long lowest_stack;
15754 unsigned int sig_on_uaccess_error:1;
15755 unsigned int uaccess_err:1; /* uaccess failed */
15756 };
15757
15758-#define INIT_THREAD_INFO(tsk) \
15759+#define INIT_THREAD_INFO \
15760 { \
15761- .task = &tsk, \
15762 .exec_domain = &default_exec_domain, \
15763 .flags = 0, \
15764 .cpu = 0, \
15765@@ -57,7 +51,7 @@ struct thread_info {
15766 }, \
15767 }
15768
15769-#define init_thread_info (init_thread_union.thread_info)
15770+#define init_thread_info (init_thread_union.stack)
15771 #define init_stack (init_thread_union.stack)
15772
15773 #else /* !__ASSEMBLY__ */
15774@@ -98,6 +92,7 @@ struct thread_info {
15775 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
15776 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
15777 #define TIF_X32 30 /* 32-bit native x86-64 binary */
15778+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
15779
15780 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
15781 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
15782@@ -122,17 +117,18 @@ struct thread_info {
15783 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
15784 #define _TIF_ADDR32 (1 << TIF_ADDR32)
15785 #define _TIF_X32 (1 << TIF_X32)
15786+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
15787
15788 /* work to do in syscall_trace_enter() */
15789 #define _TIF_WORK_SYSCALL_ENTRY \
15790 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
15791 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
15792- _TIF_NOHZ)
15793+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
15794
15795 /* work to do in syscall_trace_leave() */
15796 #define _TIF_WORK_SYSCALL_EXIT \
15797 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
15798- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
15799+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
15800
15801 /* work to do on interrupt/exception return */
15802 #define _TIF_WORK_MASK \
15803@@ -143,7 +139,7 @@ struct thread_info {
15804 /* work to do on any return to user space */
15805 #define _TIF_ALLWORK_MASK \
15806 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
15807- _TIF_NOHZ)
15808+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
15809
15810 /* Only used for 64 bit */
15811 #define _TIF_DO_NOTIFY_MASK \
15812@@ -159,45 +155,40 @@ struct thread_info {
15813
15814 #define PREEMPT_ACTIVE 0x10000000
15815
15816-#ifdef CONFIG_X86_32
15817-
15818-#define STACK_WARN (THREAD_SIZE/8)
15819-/*
15820- * macros/functions for gaining access to the thread information structure
15821- *
15822- * preempt_count needs to be 1 initially, until the scheduler is functional.
15823- */
15824-#ifndef __ASSEMBLY__
15825-
15826-
15827-/* how to get the current stack pointer from C */
15828-register unsigned long current_stack_pointer asm("esp") __used;
15829-
15830-/* how to get the thread information struct from C */
15831-static inline struct thread_info *current_thread_info(void)
15832-{
15833- return (struct thread_info *)
15834- (current_stack_pointer & ~(THREAD_SIZE - 1));
15835-}
15836-
15837-#else /* !__ASSEMBLY__ */
15838-
15839+#ifdef __ASSEMBLY__
15840 /* how to get the thread information struct from ASM */
15841 #define GET_THREAD_INFO(reg) \
15842- movl $-THREAD_SIZE, reg; \
15843- andl %esp, reg
15844+ mov PER_CPU_VAR(current_tinfo), reg
15845
15846 /* use this one if reg already contains %esp */
15847-#define GET_THREAD_INFO_WITH_ESP(reg) \
15848- andl $-THREAD_SIZE, reg
15849+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
15850+#else
15851+/* how to get the thread information struct from C */
15852+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
15853+
15854+static __always_inline struct thread_info *current_thread_info(void)
15855+{
15856+ return this_cpu_read_stable(current_tinfo);
15857+}
15858+#endif
15859+
15860+#ifdef CONFIG_X86_32
15861+
15862+#define STACK_WARN (THREAD_SIZE/8)
15863+/*
15864+ * macros/functions for gaining access to the thread information structure
15865+ *
15866+ * preempt_count needs to be 1 initially, until the scheduler is functional.
15867+ */
15868+#ifndef __ASSEMBLY__
15869+
15870+/* how to get the current stack pointer from C */
15871+register unsigned long current_stack_pointer asm("esp") __used;
15872
15873 #endif
15874
15875 #else /* X86_32 */
15876
15877-#include <asm/percpu.h>
15878-#define KERNEL_STACK_OFFSET (5*8)
15879-
15880 /*
15881 * macros/functions for gaining access to the thread information structure
15882 * preempt_count needs to be 1 initially, until the scheduler is functional.
15883@@ -205,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
15884 #ifndef __ASSEMBLY__
15885 DECLARE_PER_CPU(unsigned long, kernel_stack);
15886
15887-static inline struct thread_info *current_thread_info(void)
15888-{
15889- struct thread_info *ti;
15890- ti = (void *)(this_cpu_read_stable(kernel_stack) +
15891- KERNEL_STACK_OFFSET - THREAD_SIZE);
15892- return ti;
15893-}
15894-
15895-#else /* !__ASSEMBLY__ */
15896-
15897-/* how to get the thread information struct from ASM */
15898-#define GET_THREAD_INFO(reg) \
15899- movq PER_CPU_VAR(kernel_stack),reg ; \
15900- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
15901-
15902-/*
15903- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
15904- * a certain register (to be used in assembler memory operands).
15905- */
15906-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
15907-
15908+/* how to get the current stack pointer from C */
15909+register unsigned long current_stack_pointer asm("rsp") __used;
15910 #endif
15911
15912 #endif /* !X86_32 */
15913@@ -286,5 +258,12 @@ static inline bool is_ia32_task(void)
15914 extern void arch_task_cache_init(void);
15915 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
15916 extern void arch_release_task_struct(struct task_struct *tsk);
15917+
15918+#define __HAVE_THREAD_FUNCTIONS
15919+#define task_thread_info(task) (&(task)->tinfo)
15920+#define task_stack_page(task) ((task)->stack)
15921+#define setup_thread_stack(p, org) do {} while (0)
15922+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
15923+
15924 #endif
15925 #endif /* _ASM_X86_THREAD_INFO_H */
15926diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
15927index 1709801..0a60f2f 100644
15928--- a/arch/x86/include/asm/uaccess.h
15929+++ b/arch/x86/include/asm/uaccess.h
15930@@ -7,6 +7,7 @@
15931 #include <linux/compiler.h>
15932 #include <linux/thread_info.h>
15933 #include <linux/string.h>
15934+#include <linux/sched.h>
15935 #include <asm/asm.h>
15936 #include <asm/page.h>
15937 #include <asm/smap.h>
15938@@ -29,7 +30,12 @@
15939
15940 #define get_ds() (KERNEL_DS)
15941 #define get_fs() (current_thread_info()->addr_limit)
15942+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15943+void __set_fs(mm_segment_t x);
15944+void set_fs(mm_segment_t x);
15945+#else
15946 #define set_fs(x) (current_thread_info()->addr_limit = (x))
15947+#endif
15948
15949 #define segment_eq(a, b) ((a).seg == (b).seg)
15950
15951@@ -77,8 +83,33 @@
15952 * checks that the pointer is in the user space range - after calling
15953 * this function, memory access functions may still return -EFAULT.
15954 */
15955-#define access_ok(type, addr, size) \
15956- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15957+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15958+#define access_ok(type, addr, size) \
15959+({ \
15960+ long __size = size; \
15961+ unsigned long __addr = (unsigned long)addr; \
15962+ unsigned long __addr_ao = __addr & PAGE_MASK; \
15963+ unsigned long __end_ao = __addr + __size - 1; \
15964+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
15965+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
15966+ while(__addr_ao <= __end_ao) { \
15967+ char __c_ao; \
15968+ __addr_ao += PAGE_SIZE; \
15969+ if (__size > PAGE_SIZE) \
15970+ cond_resched(); \
15971+ if (__get_user(__c_ao, (char __user *)__addr)) \
15972+ break; \
15973+ if (type != VERIFY_WRITE) { \
15974+ __addr = __addr_ao; \
15975+ continue; \
15976+ } \
15977+ if (__put_user(__c_ao, (char __user *)__addr)) \
15978+ break; \
15979+ __addr = __addr_ao; \
15980+ } \
15981+ } \
15982+ __ret_ao; \
15983+})
15984
15985 /*
15986 * The exception table consists of pairs of addresses relative to the
15987@@ -189,13 +220,21 @@ extern int __get_user_bad(void);
15988 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
15989 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
15990
15991-
15992+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15993+#define __copyuser_seg "gs;"
15994+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
15995+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
15996+#else
15997+#define __copyuser_seg
15998+#define __COPYUSER_SET_ES
15999+#define __COPYUSER_RESTORE_ES
16000+#endif
16001
16002 #ifdef CONFIG_X86_32
16003 #define __put_user_asm_u64(x, addr, err, errret) \
16004 asm volatile(ASM_STAC "\n" \
16005- "1: movl %%eax,0(%2)\n" \
16006- "2: movl %%edx,4(%2)\n" \
16007+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
16008+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
16009 "3: " ASM_CLAC "\n" \
16010 ".section .fixup,\"ax\"\n" \
16011 "4: movl %3,%0\n" \
16012@@ -208,8 +247,8 @@ extern int __get_user_bad(void);
16013
16014 #define __put_user_asm_ex_u64(x, addr) \
16015 asm volatile(ASM_STAC "\n" \
16016- "1: movl %%eax,0(%1)\n" \
16017- "2: movl %%edx,4(%1)\n" \
16018+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
16019+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
16020 "3: " ASM_CLAC "\n" \
16021 _ASM_EXTABLE_EX(1b, 2b) \
16022 _ASM_EXTABLE_EX(2b, 3b) \
16023@@ -259,7 +298,7 @@ extern void __put_user_8(void);
16024 __typeof__(*(ptr)) __pu_val; \
16025 __chk_user_ptr(ptr); \
16026 might_fault(); \
16027- __pu_val = x; \
16028+ __pu_val = (x); \
16029 switch (sizeof(*(ptr))) { \
16030 case 1: \
16031 __put_user_x(1, __pu_val, ptr, __ret_pu); \
16032@@ -358,7 +397,7 @@ do { \
16033
16034 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
16035 asm volatile(ASM_STAC "\n" \
16036- "1: mov"itype" %2,%"rtype"1\n" \
16037+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
16038 "2: " ASM_CLAC "\n" \
16039 ".section .fixup,\"ax\"\n" \
16040 "3: mov %3,%0\n" \
16041@@ -366,7 +405,7 @@ do { \
16042 " jmp 2b\n" \
16043 ".previous\n" \
16044 _ASM_EXTABLE(1b, 3b) \
16045- : "=r" (err), ltype(x) \
16046+ : "=r" (err), ltype (x) \
16047 : "m" (__m(addr)), "i" (errret), "0" (err))
16048
16049 #define __get_user_size_ex(x, ptr, size) \
16050@@ -391,7 +430,7 @@ do { \
16051 } while (0)
16052
16053 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
16054- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
16055+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
16056 "2:\n" \
16057 _ASM_EXTABLE_EX(1b, 2b) \
16058 : ltype(x) : "m" (__m(addr)))
16059@@ -408,13 +447,24 @@ do { \
16060 int __gu_err; \
16061 unsigned long __gu_val; \
16062 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
16063- (x) = (__force __typeof__(*(ptr)))__gu_val; \
16064+ (x) = (__typeof__(*(ptr)))__gu_val; \
16065 __gu_err; \
16066 })
16067
16068 /* FIXME: this hack is definitely wrong -AK */
16069 struct __large_struct { unsigned long buf[100]; };
16070-#define __m(x) (*(struct __large_struct __user *)(x))
16071+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16072+#define ____m(x) \
16073+({ \
16074+ unsigned long ____x = (unsigned long)(x); \
16075+ if (____x < PAX_USER_SHADOW_BASE) \
16076+ ____x += PAX_USER_SHADOW_BASE; \
16077+ (void __user *)____x; \
16078+})
16079+#else
16080+#define ____m(x) (x)
16081+#endif
16082+#define __m(x) (*(struct __large_struct __user *)____m(x))
16083
16084 /*
16085 * Tell gcc we read from memory instead of writing: this is because
16086@@ -423,7 +473,7 @@ struct __large_struct { unsigned long buf[100]; };
16087 */
16088 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
16089 asm volatile(ASM_STAC "\n" \
16090- "1: mov"itype" %"rtype"1,%2\n" \
16091+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
16092 "2: " ASM_CLAC "\n" \
16093 ".section .fixup,\"ax\"\n" \
16094 "3: mov %3,%0\n" \
16095@@ -431,10 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
16096 ".previous\n" \
16097 _ASM_EXTABLE(1b, 3b) \
16098 : "=r"(err) \
16099- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
16100+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
16101
16102 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
16103- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
16104+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
16105 "2:\n" \
16106 _ASM_EXTABLE_EX(1b, 2b) \
16107 : : ltype(x), "m" (__m(addr)))
16108@@ -473,8 +523,12 @@ struct __large_struct { unsigned long buf[100]; };
16109 * On error, the variable @x is set to zero.
16110 */
16111
16112+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16113+#define __get_user(x, ptr) get_user((x), (ptr))
16114+#else
16115 #define __get_user(x, ptr) \
16116 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
16117+#endif
16118
16119 /**
16120 * __put_user: - Write a simple value into user space, with less checking.
16121@@ -496,8 +550,12 @@ struct __large_struct { unsigned long buf[100]; };
16122 * Returns zero on success, or -EFAULT on error.
16123 */
16124
16125+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16126+#define __put_user(x, ptr) put_user((x), (ptr))
16127+#else
16128 #define __put_user(x, ptr) \
16129 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
16130+#endif
16131
16132 #define __get_user_unaligned __get_user
16133 #define __put_user_unaligned __put_user
16134@@ -515,7 +573,7 @@ struct __large_struct { unsigned long buf[100]; };
16135 #define get_user_ex(x, ptr) do { \
16136 unsigned long __gue_val; \
16137 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
16138- (x) = (__force __typeof__(*(ptr)))__gue_val; \
16139+ (x) = (__typeof__(*(ptr)))__gue_val; \
16140 } while (0)
16141
16142 #define put_user_try uaccess_try
16143@@ -532,8 +590,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
16144 extern __must_check long strlen_user(const char __user *str);
16145 extern __must_check long strnlen_user(const char __user *str, long n);
16146
16147-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
16148-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
16149+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
16150+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
16151
16152 /*
16153 * movsl can be slow when source and dest are not both 8-byte aligned
16154diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
16155index 7f760a9..04b1c65 100644
16156--- a/arch/x86/include/asm/uaccess_32.h
16157+++ b/arch/x86/include/asm/uaccess_32.h
16158@@ -11,15 +11,15 @@
16159 #include <asm/page.h>
16160
16161 unsigned long __must_check __copy_to_user_ll
16162- (void __user *to, const void *from, unsigned long n);
16163+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
16164 unsigned long __must_check __copy_from_user_ll
16165- (void *to, const void __user *from, unsigned long n);
16166+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
16167 unsigned long __must_check __copy_from_user_ll_nozero
16168- (void *to, const void __user *from, unsigned long n);
16169+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
16170 unsigned long __must_check __copy_from_user_ll_nocache
16171- (void *to, const void __user *from, unsigned long n);
16172+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
16173 unsigned long __must_check __copy_from_user_ll_nocache_nozero
16174- (void *to, const void __user *from, unsigned long n);
16175+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
16176
16177 /**
16178 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
16179@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
16180 static __always_inline unsigned long __must_check
16181 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
16182 {
16183+ if ((long)n < 0)
16184+ return n;
16185+
16186+ check_object_size(from, n, true);
16187+
16188 if (__builtin_constant_p(n)) {
16189 unsigned long ret;
16190
16191@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
16192 __copy_to_user(void __user *to, const void *from, unsigned long n)
16193 {
16194 might_fault();
16195+
16196 return __copy_to_user_inatomic(to, from, n);
16197 }
16198
16199 static __always_inline unsigned long
16200 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
16201 {
16202+ if ((long)n < 0)
16203+ return n;
16204+
16205 /* Avoid zeroing the tail if the copy fails..
16206 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
16207 * but as the zeroing behaviour is only significant when n is not
16208@@ -137,6 +146,12 @@ static __always_inline unsigned long
16209 __copy_from_user(void *to, const void __user *from, unsigned long n)
16210 {
16211 might_fault();
16212+
16213+ if ((long)n < 0)
16214+ return n;
16215+
16216+ check_object_size(to, n, false);
16217+
16218 if (__builtin_constant_p(n)) {
16219 unsigned long ret;
16220
16221@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
16222 const void __user *from, unsigned long n)
16223 {
16224 might_fault();
16225+
16226+ if ((long)n < 0)
16227+ return n;
16228+
16229 if (__builtin_constant_p(n)) {
16230 unsigned long ret;
16231
16232@@ -181,15 +200,19 @@ static __always_inline unsigned long
16233 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
16234 unsigned long n)
16235 {
16236- return __copy_from_user_ll_nocache_nozero(to, from, n);
16237+ if ((long)n < 0)
16238+ return n;
16239+
16240+ return __copy_from_user_ll_nocache_nozero(to, from, n);
16241 }
16242
16243-unsigned long __must_check copy_to_user(void __user *to,
16244- const void *from, unsigned long n);
16245-unsigned long __must_check _copy_from_user(void *to,
16246- const void __user *from,
16247- unsigned long n);
16248-
16249+extern void copy_to_user_overflow(void)
16250+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16251+ __compiletime_error("copy_to_user() buffer size is not provably correct")
16252+#else
16253+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
16254+#endif
16255+;
16256
16257 extern void copy_from_user_overflow(void)
16258 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16259@@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
16260 #endif
16261 ;
16262
16263-static inline unsigned long __must_check copy_from_user(void *to,
16264- const void __user *from,
16265- unsigned long n)
16266+/**
16267+ * copy_to_user: - Copy a block of data into user space.
16268+ * @to: Destination address, in user space.
16269+ * @from: Source address, in kernel space.
16270+ * @n: Number of bytes to copy.
16271+ *
16272+ * Context: User context only. This function may sleep.
16273+ *
16274+ * Copy data from kernel space to user space.
16275+ *
16276+ * Returns number of bytes that could not be copied.
16277+ * On success, this will be zero.
16278+ */
16279+static inline unsigned long __must_check
16280+copy_to_user(void __user *to, const void *from, unsigned long n)
16281 {
16282- int sz = __compiletime_object_size(to);
16283+ size_t sz = __compiletime_object_size(from);
16284
16285- if (likely(sz == -1 || sz >= n))
16286- n = _copy_from_user(to, from, n);
16287- else
16288+ if (unlikely(sz != (size_t)-1 && sz < n))
16289+ copy_to_user_overflow();
16290+ else if (access_ok(VERIFY_WRITE, to, n))
16291+ n = __copy_to_user(to, from, n);
16292+ return n;
16293+}
16294+
16295+/**
16296+ * copy_from_user: - Copy a block of data from user space.
16297+ * @to: Destination address, in kernel space.
16298+ * @from: Source address, in user space.
16299+ * @n: Number of bytes to copy.
16300+ *
16301+ * Context: User context only. This function may sleep.
16302+ *
16303+ * Copy data from user space to kernel space.
16304+ *
16305+ * Returns number of bytes that could not be copied.
16306+ * On success, this will be zero.
16307+ *
16308+ * If some data could not be copied, this function will pad the copied
16309+ * data to the requested size using zero bytes.
16310+ */
16311+static inline unsigned long __must_check
16312+copy_from_user(void *to, const void __user *from, unsigned long n)
16313+{
16314+ size_t sz = __compiletime_object_size(to);
16315+
16316+ check_object_size(to, n, false);
16317+
16318+ if (unlikely(sz != (size_t)-1 && sz < n))
16319 copy_from_user_overflow();
16320-
16321+ else if (access_ok(VERIFY_READ, from, n))
16322+ n = __copy_from_user(to, from, n);
16323+ else if ((long)n > 0)
16324+ memset(to, 0, n);
16325 return n;
16326 }
16327
16328diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
16329index 142810c..1f2a0a7 100644
16330--- a/arch/x86/include/asm/uaccess_64.h
16331+++ b/arch/x86/include/asm/uaccess_64.h
16332@@ -10,6 +10,9 @@
16333 #include <asm/alternative.h>
16334 #include <asm/cpufeature.h>
16335 #include <asm/page.h>
16336+#include <asm/pgtable.h>
16337+
16338+#define set_fs(x) (current_thread_info()->addr_limit = (x))
16339
16340 /*
16341 * Copy To/From Userspace
16342@@ -17,13 +20,13 @@
16343
16344 /* Handles exceptions in both to and from, but doesn't do access_ok */
16345 __must_check unsigned long
16346-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
16347+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
16348 __must_check unsigned long
16349-copy_user_generic_string(void *to, const void *from, unsigned len);
16350+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
16351 __must_check unsigned long
16352-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
16353+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
16354
16355-static __always_inline __must_check unsigned long
16356+static __always_inline __must_check __size_overflow(3) unsigned long
16357 copy_user_generic(void *to, const void *from, unsigned len)
16358 {
16359 unsigned ret;
16360@@ -41,142 +44,204 @@ copy_user_generic(void *to, const void *from, unsigned len)
16361 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
16362 "=d" (len)),
16363 "1" (to), "2" (from), "3" (len)
16364- : "memory", "rcx", "r8", "r9", "r10", "r11");
16365+ : "memory", "rcx", "r8", "r9", "r11");
16366 return ret;
16367 }
16368
16369+static __always_inline __must_check unsigned long
16370+__copy_to_user(void __user *to, const void *from, unsigned long len);
16371+static __always_inline __must_check unsigned long
16372+__copy_from_user(void *to, const void __user *from, unsigned long len);
16373 __must_check unsigned long
16374-_copy_to_user(void __user *to, const void *from, unsigned len);
16375-__must_check unsigned long
16376-_copy_from_user(void *to, const void __user *from, unsigned len);
16377-__must_check unsigned long
16378-copy_in_user(void __user *to, const void __user *from, unsigned len);
16379+copy_in_user(void __user *to, const void __user *from, unsigned long len);
16380+
16381+extern void copy_to_user_overflow(void)
16382+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16383+ __compiletime_error("copy_to_user() buffer size is not provably correct")
16384+#else
16385+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
16386+#endif
16387+;
16388+
16389+extern void copy_from_user_overflow(void)
16390+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16391+ __compiletime_error("copy_from_user() buffer size is not provably correct")
16392+#else
16393+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
16394+#endif
16395+;
16396
16397 static inline unsigned long __must_check copy_from_user(void *to,
16398 const void __user *from,
16399 unsigned long n)
16400 {
16401- int sz = __compiletime_object_size(to);
16402-
16403 might_fault();
16404- if (likely(sz == -1 || sz >= n))
16405- n = _copy_from_user(to, from, n);
16406-#ifdef CONFIG_DEBUG_VM
16407- else
16408- WARN(1, "Buffer overflow detected!\n");
16409-#endif
16410+
16411+ check_object_size(to, n, false);
16412+
16413+ if (access_ok(VERIFY_READ, from, n))
16414+ n = __copy_from_user(to, from, n);
16415+ else if (n < INT_MAX)
16416+ memset(to, 0, n);
16417 return n;
16418 }
16419
16420 static __always_inline __must_check
16421-int copy_to_user(void __user *dst, const void *src, unsigned size)
16422+int copy_to_user(void __user *dst, const void *src, unsigned long size)
16423 {
16424 might_fault();
16425
16426- return _copy_to_user(dst, src, size);
16427+ if (access_ok(VERIFY_WRITE, dst, size))
16428+ size = __copy_to_user(dst, src, size);
16429+ return size;
16430 }
16431
16432 static __always_inline __must_check
16433-int __copy_from_user(void *dst, const void __user *src, unsigned size)
16434+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
16435 {
16436- int ret = 0;
16437+ size_t sz = __compiletime_object_size(dst);
16438+ unsigned ret = 0;
16439
16440 might_fault();
16441+
16442+ if (size > INT_MAX)
16443+ return size;
16444+
16445+ check_object_size(dst, size, false);
16446+
16447+#ifdef CONFIG_PAX_MEMORY_UDEREF
16448+ if (!__access_ok(VERIFY_READ, src, size))
16449+ return size;
16450+#endif
16451+
16452+ if (unlikely(sz != (size_t)-1 && sz < size)) {
16453+ copy_from_user_overflow();
16454+ return size;
16455+ }
16456+
16457 if (!__builtin_constant_p(size))
16458- return copy_user_generic(dst, (__force void *)src, size);
16459+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16460 switch (size) {
16461- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
16462+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
16463 ret, "b", "b", "=q", 1);
16464 return ret;
16465- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
16466+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
16467 ret, "w", "w", "=r", 2);
16468 return ret;
16469- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
16470+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
16471 ret, "l", "k", "=r", 4);
16472 return ret;
16473- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
16474+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16475 ret, "q", "", "=r", 8);
16476 return ret;
16477 case 10:
16478- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
16479+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16480 ret, "q", "", "=r", 10);
16481 if (unlikely(ret))
16482 return ret;
16483 __get_user_asm(*(u16 *)(8 + (char *)dst),
16484- (u16 __user *)(8 + (char __user *)src),
16485+ (const u16 __user *)(8 + (const char __user *)src),
16486 ret, "w", "w", "=r", 2);
16487 return ret;
16488 case 16:
16489- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
16490+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16491 ret, "q", "", "=r", 16);
16492 if (unlikely(ret))
16493 return ret;
16494 __get_user_asm(*(u64 *)(8 + (char *)dst),
16495- (u64 __user *)(8 + (char __user *)src),
16496+ (const u64 __user *)(8 + (const char __user *)src),
16497 ret, "q", "", "=r", 8);
16498 return ret;
16499 default:
16500- return copy_user_generic(dst, (__force void *)src, size);
16501+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16502 }
16503 }
16504
16505 static __always_inline __must_check
16506-int __copy_to_user(void __user *dst, const void *src, unsigned size)
16507+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
16508 {
16509- int ret = 0;
16510+ size_t sz = __compiletime_object_size(src);
16511+ unsigned ret = 0;
16512
16513 might_fault();
16514+
16515+ if (size > INT_MAX)
16516+ return size;
16517+
16518+ check_object_size(src, size, true);
16519+
16520+#ifdef CONFIG_PAX_MEMORY_UDEREF
16521+ if (!__access_ok(VERIFY_WRITE, dst, size))
16522+ return size;
16523+#endif
16524+
16525+ if (unlikely(sz != (size_t)-1 && sz < size)) {
16526+ copy_to_user_overflow();
16527+ return size;
16528+ }
16529+
16530 if (!__builtin_constant_p(size))
16531- return copy_user_generic((__force void *)dst, src, size);
16532+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16533 switch (size) {
16534- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
16535+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
16536 ret, "b", "b", "iq", 1);
16537 return ret;
16538- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
16539+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
16540 ret, "w", "w", "ir", 2);
16541 return ret;
16542- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
16543+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
16544 ret, "l", "k", "ir", 4);
16545 return ret;
16546- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
16547+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16548 ret, "q", "", "er", 8);
16549 return ret;
16550 case 10:
16551- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
16552+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16553 ret, "q", "", "er", 10);
16554 if (unlikely(ret))
16555 return ret;
16556 asm("":::"memory");
16557- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
16558+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
16559 ret, "w", "w", "ir", 2);
16560 return ret;
16561 case 16:
16562- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
16563+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16564 ret, "q", "", "er", 16);
16565 if (unlikely(ret))
16566 return ret;
16567 asm("":::"memory");
16568- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
16569+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
16570 ret, "q", "", "er", 8);
16571 return ret;
16572 default:
16573- return copy_user_generic((__force void *)dst, src, size);
16574+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16575 }
16576 }
16577
16578 static __always_inline __must_check
16579-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16580+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
16581 {
16582- int ret = 0;
16583+ unsigned ret = 0;
16584
16585 might_fault();
16586+
16587+ if (size > INT_MAX)
16588+ return size;
16589+
16590+#ifdef CONFIG_PAX_MEMORY_UDEREF
16591+ if (!__access_ok(VERIFY_READ, src, size))
16592+ return size;
16593+ if (!__access_ok(VERIFY_WRITE, dst, size))
16594+ return size;
16595+#endif
16596+
16597 if (!__builtin_constant_p(size))
16598- return copy_user_generic((__force void *)dst,
16599- (__force void *)src, size);
16600+ return copy_user_generic((__force_kernel void *)____m(dst),
16601+ (__force_kernel const void *)____m(src), size);
16602 switch (size) {
16603 case 1: {
16604 u8 tmp;
16605- __get_user_asm(tmp, (u8 __user *)src,
16606+ __get_user_asm(tmp, (const u8 __user *)src,
16607 ret, "b", "b", "=q", 1);
16608 if (likely(!ret))
16609 __put_user_asm(tmp, (u8 __user *)dst,
16610@@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16611 }
16612 case 2: {
16613 u16 tmp;
16614- __get_user_asm(tmp, (u16 __user *)src,
16615+ __get_user_asm(tmp, (const u16 __user *)src,
16616 ret, "w", "w", "=r", 2);
16617 if (likely(!ret))
16618 __put_user_asm(tmp, (u16 __user *)dst,
16619@@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16620
16621 case 4: {
16622 u32 tmp;
16623- __get_user_asm(tmp, (u32 __user *)src,
16624+ __get_user_asm(tmp, (const u32 __user *)src,
16625 ret, "l", "k", "=r", 4);
16626 if (likely(!ret))
16627 __put_user_asm(tmp, (u32 __user *)dst,
16628@@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16629 }
16630 case 8: {
16631 u64 tmp;
16632- __get_user_asm(tmp, (u64 __user *)src,
16633+ __get_user_asm(tmp, (const u64 __user *)src,
16634 ret, "q", "", "=r", 8);
16635 if (likely(!ret))
16636 __put_user_asm(tmp, (u64 __user *)dst,
16637@@ -212,41 +277,72 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16638 return ret;
16639 }
16640 default:
16641- return copy_user_generic((__force void *)dst,
16642- (__force void *)src, size);
16643+ return copy_user_generic((__force_kernel void *)____m(dst),
16644+ (__force_kernel const void *)____m(src), size);
16645 }
16646 }
16647
16648 static __must_check __always_inline int
16649-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
16650+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
16651 {
16652- return copy_user_generic(dst, (__force const void *)src, size);
16653+ if (size > INT_MAX)
16654+ return size;
16655+
16656+#ifdef CONFIG_PAX_MEMORY_UDEREF
16657+ if (!__access_ok(VERIFY_READ, src, size))
16658+ return size;
16659+#endif
16660+
16661+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16662 }
16663
16664-static __must_check __always_inline int
16665-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
16666+static __must_check __always_inline unsigned long
16667+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
16668 {
16669- return copy_user_generic((__force void *)dst, src, size);
16670+ if (size > INT_MAX)
16671+ return size;
16672+
16673+#ifdef CONFIG_PAX_MEMORY_UDEREF
16674+ if (!__access_ok(VERIFY_WRITE, dst, size))
16675+ return size;
16676+#endif
16677+
16678+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16679 }
16680
16681-extern long __copy_user_nocache(void *dst, const void __user *src,
16682- unsigned size, int zerorest);
16683+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
16684+ unsigned long size, int zerorest) __size_overflow(3);
16685
16686-static inline int
16687-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
16688+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
16689 {
16690 might_sleep();
16691+
16692+ if (size > INT_MAX)
16693+ return size;
16694+
16695+#ifdef CONFIG_PAX_MEMORY_UDEREF
16696+ if (!__access_ok(VERIFY_READ, src, size))
16697+ return size;
16698+#endif
16699+
16700 return __copy_user_nocache(dst, src, size, 1);
16701 }
16702
16703-static inline int
16704-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
16705- unsigned size)
16706+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
16707+ unsigned long size)
16708 {
16709+ if (size > INT_MAX)
16710+ return size;
16711+
16712+#ifdef CONFIG_PAX_MEMORY_UDEREF
16713+ if (!__access_ok(VERIFY_READ, src, size))
16714+ return size;
16715+#endif
16716+
16717 return __copy_user_nocache(dst, src, size, 0);
16718 }
16719
16720-unsigned long
16721-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
16722+extern unsigned long
16723+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
16724
16725 #endif /* _ASM_X86_UACCESS_64_H */
16726diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
16727index 5b238981..77fdd78 100644
16728--- a/arch/x86/include/asm/word-at-a-time.h
16729+++ b/arch/x86/include/asm/word-at-a-time.h
16730@@ -11,7 +11,7 @@
16731 * and shift, for example.
16732 */
16733 struct word_at_a_time {
16734- const unsigned long one_bits, high_bits;
16735+ unsigned long one_bits, high_bits;
16736 };
16737
16738 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
16739diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
16740index 5769349..a3d3e2a 100644
16741--- a/arch/x86/include/asm/x86_init.h
16742+++ b/arch/x86/include/asm/x86_init.h
16743@@ -141,7 +141,7 @@ struct x86_init_ops {
16744 struct x86_init_timers timers;
16745 struct x86_init_iommu iommu;
16746 struct x86_init_pci pci;
16747-};
16748+} __no_const;
16749
16750 /**
16751 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
16752@@ -152,7 +152,7 @@ struct x86_cpuinit_ops {
16753 void (*setup_percpu_clockev)(void);
16754 void (*early_percpu_clock_init)(void);
16755 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
16756-};
16757+} __no_const;
16758
16759 /**
16760 * struct x86_platform_ops - platform specific runtime functions
16761@@ -178,7 +178,7 @@ struct x86_platform_ops {
16762 void (*save_sched_clock_state)(void);
16763 void (*restore_sched_clock_state)(void);
16764 void (*apic_post_init)(void);
16765-};
16766+} __no_const;
16767
16768 struct pci_dev;
16769
16770@@ -187,14 +187,14 @@ struct x86_msi_ops {
16771 void (*teardown_msi_irq)(unsigned int irq);
16772 void (*teardown_msi_irqs)(struct pci_dev *dev);
16773 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
16774-};
16775+} __no_const;
16776
16777 struct x86_io_apic_ops {
16778 void (*init) (void);
16779 unsigned int (*read) (unsigned int apic, unsigned int reg);
16780 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
16781 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
16782-};
16783+} __no_const;
16784
16785 extern struct x86_init_ops x86_init;
16786 extern struct x86_cpuinit_ops x86_cpuinit;
16787diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
16788index 0415cda..b43d877 100644
16789--- a/arch/x86/include/asm/xsave.h
16790+++ b/arch/x86/include/asm/xsave.h
16791@@ -71,7 +71,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
16792 return -EFAULT;
16793
16794 __asm__ __volatile__(ASM_STAC "\n"
16795- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
16796+ "1:"
16797+ __copyuser_seg
16798+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
16799 "2: " ASM_CLAC "\n"
16800 ".section .fixup,\"ax\"\n"
16801 "3: movl $-1,%[err]\n"
16802@@ -87,12 +89,14 @@ static inline int xsave_user(struct xsave_struct __user *buf)
16803 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
16804 {
16805 int err;
16806- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
16807+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
16808 u32 lmask = mask;
16809 u32 hmask = mask >> 32;
16810
16811 __asm__ __volatile__(ASM_STAC "\n"
16812- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16813+ "1:"
16814+ __copyuser_seg
16815+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16816 "2: " ASM_CLAC "\n"
16817 ".section .fixup,\"ax\"\n"
16818 "3: movl $-1,%[err]\n"
16819diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
16820index bbae024..e1528f9 100644
16821--- a/arch/x86/include/uapi/asm/e820.h
16822+++ b/arch/x86/include/uapi/asm/e820.h
16823@@ -63,7 +63,7 @@ struct e820map {
16824 #define ISA_START_ADDRESS 0xa0000
16825 #define ISA_END_ADDRESS 0x100000
16826
16827-#define BIOS_BEGIN 0x000a0000
16828+#define BIOS_BEGIN 0x000c0000
16829 #define BIOS_END 0x00100000
16830
16831 #define BIOS_ROM_BASE 0xffe00000
16832diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
16833index 34e923a..0c6bb6e 100644
16834--- a/arch/x86/kernel/Makefile
16835+++ b/arch/x86/kernel/Makefile
16836@@ -22,7 +22,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
16837 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
16838 obj-$(CONFIG_IRQ_WORK) += irq_work.o
16839 obj-y += probe_roms.o
16840-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
16841+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
16842 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
16843 obj-y += syscall_$(BITS).o
16844 obj-$(CONFIG_X86_64) += vsyscall_64.o
16845diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
16846index bacf4b0..4ede72e 100644
16847--- a/arch/x86/kernel/acpi/boot.c
16848+++ b/arch/x86/kernel/acpi/boot.c
16849@@ -1358,7 +1358,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
16850 * If your system is blacklisted here, but you find that acpi=force
16851 * works for you, please contact linux-acpi@vger.kernel.org
16852 */
16853-static struct dmi_system_id __initdata acpi_dmi_table[] = {
16854+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
16855 /*
16856 * Boxes that need ACPI disabled
16857 */
16858@@ -1433,7 +1433,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
16859 };
16860
16861 /* second table for DMI checks that should run after early-quirks */
16862-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
16863+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
16864 /*
16865 * HP laptops which use a DSDT reporting as HP/SB400/10000,
16866 * which includes some code which overrides all temperature
16867diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
16868index d5e0d71..6533e08 100644
16869--- a/arch/x86/kernel/acpi/sleep.c
16870+++ b/arch/x86/kernel/acpi/sleep.c
16871@@ -74,8 +74,12 @@ int acpi_suspend_lowlevel(void)
16872 #else /* CONFIG_64BIT */
16873 #ifdef CONFIG_SMP
16874 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
16875+
16876+ pax_open_kernel();
16877 early_gdt_descr.address =
16878 (unsigned long)get_cpu_gdt_table(smp_processor_id());
16879+ pax_close_kernel();
16880+
16881 initial_gs = per_cpu_offset(smp_processor_id());
16882 #endif
16883 initial_code = (unsigned long)wakeup_long64;
16884diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
16885index 13ab720..95d5442 100644
16886--- a/arch/x86/kernel/acpi/wakeup_32.S
16887+++ b/arch/x86/kernel/acpi/wakeup_32.S
16888@@ -30,13 +30,11 @@ wakeup_pmode_return:
16889 # and restore the stack ... but you need gdt for this to work
16890 movl saved_context_esp, %esp
16891
16892- movl %cs:saved_magic, %eax
16893- cmpl $0x12345678, %eax
16894+ cmpl $0x12345678, saved_magic
16895 jne bogus_magic
16896
16897 # jump to place where we left off
16898- movl saved_eip, %eax
16899- jmp *%eax
16900+ jmp *(saved_eip)
16901
16902 bogus_magic:
16903 jmp bogus_magic
16904diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
16905index ef5ccca..bd83949 100644
16906--- a/arch/x86/kernel/alternative.c
16907+++ b/arch/x86/kernel/alternative.c
16908@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
16909 */
16910 for (a = start; a < end; a++) {
16911 instr = (u8 *)&a->instr_offset + a->instr_offset;
16912+
16913+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16914+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16915+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
16916+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16917+#endif
16918+
16919 replacement = (u8 *)&a->repl_offset + a->repl_offset;
16920 BUG_ON(a->replacementlen > a->instrlen);
16921 BUG_ON(a->instrlen > sizeof(insnbuf));
16922@@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
16923 for (poff = start; poff < end; poff++) {
16924 u8 *ptr = (u8 *)poff + *poff;
16925
16926+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16927+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16928+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16929+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16930+#endif
16931+
16932 if (!*poff || ptr < text || ptr >= text_end)
16933 continue;
16934 /* turn DS segment override prefix into lock prefix */
16935- if (*ptr == 0x3e)
16936+ if (*ktla_ktva(ptr) == 0x3e)
16937 text_poke(ptr, ((unsigned char []){0xf0}), 1);
16938 }
16939 mutex_unlock(&text_mutex);
16940@@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
16941 for (poff = start; poff < end; poff++) {
16942 u8 *ptr = (u8 *)poff + *poff;
16943
16944+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16945+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16946+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16947+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16948+#endif
16949+
16950 if (!*poff || ptr < text || ptr >= text_end)
16951 continue;
16952 /* turn lock prefix into DS segment override prefix */
16953- if (*ptr == 0xf0)
16954+ if (*ktla_ktva(ptr) == 0xf0)
16955 text_poke(ptr, ((unsigned char []){0x3E}), 1);
16956 }
16957 mutex_unlock(&text_mutex);
16958@@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
16959
16960 BUG_ON(p->len > MAX_PATCH_LEN);
16961 /* prep the buffer with the original instructions */
16962- memcpy(insnbuf, p->instr, p->len);
16963+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
16964 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
16965 (unsigned long)p->instr, p->len);
16966
16967@@ -515,7 +534,7 @@ void __init alternative_instructions(void)
16968 if (!uniproc_patched || num_possible_cpus() == 1)
16969 free_init_pages("SMP alternatives",
16970 (unsigned long)__smp_locks,
16971- (unsigned long)__smp_locks_end);
16972+ PAGE_ALIGN((unsigned long)__smp_locks_end));
16973 #endif
16974
16975 apply_paravirt(__parainstructions, __parainstructions_end);
16976@@ -535,13 +554,17 @@ void __init alternative_instructions(void)
16977 * instructions. And on the local CPU you need to be protected again NMI or MCE
16978 * handlers seeing an inconsistent instruction while you patch.
16979 */
16980-void *__init_or_module text_poke_early(void *addr, const void *opcode,
16981+void *__kprobes text_poke_early(void *addr, const void *opcode,
16982 size_t len)
16983 {
16984 unsigned long flags;
16985 local_irq_save(flags);
16986- memcpy(addr, opcode, len);
16987+
16988+ pax_open_kernel();
16989+ memcpy(ktla_ktva(addr), opcode, len);
16990 sync_core();
16991+ pax_close_kernel();
16992+
16993 local_irq_restore(flags);
16994 /* Could also do a CLFLUSH here to speed up CPU recovery; but
16995 that causes hangs on some VIA CPUs. */
16996@@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
16997 */
16998 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
16999 {
17000- unsigned long flags;
17001- char *vaddr;
17002+ unsigned char *vaddr = ktla_ktva(addr);
17003 struct page *pages[2];
17004- int i;
17005+ size_t i;
17006
17007 if (!core_kernel_text((unsigned long)addr)) {
17008- pages[0] = vmalloc_to_page(addr);
17009- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
17010+ pages[0] = vmalloc_to_page(vaddr);
17011+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
17012 } else {
17013- pages[0] = virt_to_page(addr);
17014+ pages[0] = virt_to_page(vaddr);
17015 WARN_ON(!PageReserved(pages[0]));
17016- pages[1] = virt_to_page(addr + PAGE_SIZE);
17017+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
17018 }
17019 BUG_ON(!pages[0]);
17020- local_irq_save(flags);
17021- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
17022- if (pages[1])
17023- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
17024- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
17025- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
17026- clear_fixmap(FIX_TEXT_POKE0);
17027- if (pages[1])
17028- clear_fixmap(FIX_TEXT_POKE1);
17029- local_flush_tlb();
17030- sync_core();
17031- /* Could also do a CLFLUSH here to speed up CPU recovery; but
17032- that causes hangs on some VIA CPUs. */
17033+ text_poke_early(addr, opcode, len);
17034 for (i = 0; i < len; i++)
17035- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
17036- local_irq_restore(flags);
17037+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
17038 return addr;
17039 }
17040
17041diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
17042index cbf5121..812b537 100644
17043--- a/arch/x86/kernel/apic/apic.c
17044+++ b/arch/x86/kernel/apic/apic.c
17045@@ -189,7 +189,7 @@ int first_system_vector = 0xfe;
17046 /*
17047 * Debug level, exported for io_apic.c
17048 */
17049-unsigned int apic_verbosity;
17050+int apic_verbosity;
17051
17052 int pic_mode;
17053
17054@@ -1956,7 +1956,7 @@ void smp_error_interrupt(struct pt_regs *regs)
17055 apic_write(APIC_ESR, 0);
17056 v1 = apic_read(APIC_ESR);
17057 ack_APIC_irq();
17058- atomic_inc(&irq_err_count);
17059+ atomic_inc_unchecked(&irq_err_count);
17060
17061 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
17062 smp_processor_id(), v0 , v1);
17063diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
17064index 00c77cf..2dc6a2d 100644
17065--- a/arch/x86/kernel/apic/apic_flat_64.c
17066+++ b/arch/x86/kernel/apic/apic_flat_64.c
17067@@ -157,7 +157,7 @@ static int flat_probe(void)
17068 return 1;
17069 }
17070
17071-static struct apic apic_flat = {
17072+static struct apic apic_flat __read_only = {
17073 .name = "flat",
17074 .probe = flat_probe,
17075 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
17076@@ -271,7 +271,7 @@ static int physflat_probe(void)
17077 return 0;
17078 }
17079
17080-static struct apic apic_physflat = {
17081+static struct apic apic_physflat __read_only = {
17082
17083 .name = "physical flat",
17084 .probe = physflat_probe,
17085diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
17086index e145f28..2752888 100644
17087--- a/arch/x86/kernel/apic/apic_noop.c
17088+++ b/arch/x86/kernel/apic/apic_noop.c
17089@@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
17090 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
17091 }
17092
17093-struct apic apic_noop = {
17094+struct apic apic_noop __read_only = {
17095 .name = "noop",
17096 .probe = noop_probe,
17097 .acpi_madt_oem_check = NULL,
17098diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
17099index d50e364..543bee3 100644
17100--- a/arch/x86/kernel/apic/bigsmp_32.c
17101+++ b/arch/x86/kernel/apic/bigsmp_32.c
17102@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
17103 return dmi_bigsmp;
17104 }
17105
17106-static struct apic apic_bigsmp = {
17107+static struct apic apic_bigsmp __read_only = {
17108
17109 .name = "bigsmp",
17110 .probe = probe_bigsmp,
17111diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
17112index 0874799..a7a7892 100644
17113--- a/arch/x86/kernel/apic/es7000_32.c
17114+++ b/arch/x86/kernel/apic/es7000_32.c
17115@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
17116 return ret && es7000_apic_is_cluster();
17117 }
17118
17119-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
17120-static struct apic __refdata apic_es7000_cluster = {
17121+static struct apic apic_es7000_cluster __read_only = {
17122
17123 .name = "es7000",
17124 .probe = probe_es7000,
17125@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
17126 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
17127 };
17128
17129-static struct apic __refdata apic_es7000 = {
17130+static struct apic apic_es7000 __read_only = {
17131
17132 .name = "es7000",
17133 .probe = probe_es7000,
17134diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
17135index b739d39..aebc14c 100644
17136--- a/arch/x86/kernel/apic/io_apic.c
17137+++ b/arch/x86/kernel/apic/io_apic.c
17138@@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
17139 }
17140 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
17141
17142-void lock_vector_lock(void)
17143+void lock_vector_lock(void) __acquires(vector_lock)
17144 {
17145 /* Used to the online set of cpus does not change
17146 * during assign_irq_vector.
17147@@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
17148 raw_spin_lock(&vector_lock);
17149 }
17150
17151-void unlock_vector_lock(void)
17152+void unlock_vector_lock(void) __releases(vector_lock)
17153 {
17154 raw_spin_unlock(&vector_lock);
17155 }
17156@@ -2399,7 +2399,7 @@ static void ack_apic_edge(struct irq_data *data)
17157 ack_APIC_irq();
17158 }
17159
17160-atomic_t irq_mis_count;
17161+atomic_unchecked_t irq_mis_count;
17162
17163 #ifdef CONFIG_GENERIC_PENDING_IRQ
17164 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
17165@@ -2540,7 +2540,7 @@ static void ack_apic_level(struct irq_data *data)
17166 * at the cpu.
17167 */
17168 if (!(v & (1 << (i & 0x1f)))) {
17169- atomic_inc(&irq_mis_count);
17170+ atomic_inc_unchecked(&irq_mis_count);
17171
17172 eoi_ioapic_irq(irq, cfg);
17173 }
17174@@ -2567,11 +2567,13 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
17175
17176 static void irq_remap_modify_chip_defaults(struct irq_chip *chip)
17177 {
17178- chip->irq_print_chip = ir_print_prefix;
17179- chip->irq_ack = ir_ack_apic_edge;
17180- chip->irq_eoi = ir_ack_apic_level;
17181+ pax_open_kernel();
17182+ *(void **)&chip->irq_print_chip = ir_print_prefix;
17183+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
17184+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
17185
17186- chip->irq_set_affinity = set_remapped_irq_affinity;
17187+ *(void **)&chip->irq_set_affinity = set_remapped_irq_affinity;
17188+ pax_close_kernel();
17189 }
17190 #endif /* CONFIG_IRQ_REMAP */
17191
17192diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
17193index d661ee9..791fd33 100644
17194--- a/arch/x86/kernel/apic/numaq_32.c
17195+++ b/arch/x86/kernel/apic/numaq_32.c
17196@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
17197 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
17198 }
17199
17200-/* Use __refdata to keep false positive warning calm. */
17201-static struct apic __refdata apic_numaq = {
17202+static struct apic apic_numaq __read_only = {
17203
17204 .name = "NUMAQ",
17205 .probe = probe_numaq,
17206diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
17207index eb35ef9..f184a21 100644
17208--- a/arch/x86/kernel/apic/probe_32.c
17209+++ b/arch/x86/kernel/apic/probe_32.c
17210@@ -72,7 +72,7 @@ static int probe_default(void)
17211 return 1;
17212 }
17213
17214-static struct apic apic_default = {
17215+static struct apic apic_default __read_only = {
17216
17217 .name = "default",
17218 .probe = probe_default,
17219diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
17220index 77c95c0..434f8a4 100644
17221--- a/arch/x86/kernel/apic/summit_32.c
17222+++ b/arch/x86/kernel/apic/summit_32.c
17223@@ -486,7 +486,7 @@ void setup_summit(void)
17224 }
17225 #endif
17226
17227-static struct apic apic_summit = {
17228+static struct apic apic_summit __read_only = {
17229
17230 .name = "summit",
17231 .probe = probe_summit,
17232diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
17233index c88baa4..757aee1 100644
17234--- a/arch/x86/kernel/apic/x2apic_cluster.c
17235+++ b/arch/x86/kernel/apic/x2apic_cluster.c
17236@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
17237 return notifier_from_errno(err);
17238 }
17239
17240-static struct notifier_block __refdata x2apic_cpu_notifier = {
17241+static struct notifier_block x2apic_cpu_notifier = {
17242 .notifier_call = update_clusterinfo,
17243 };
17244
17245@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
17246 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
17247 }
17248
17249-static struct apic apic_x2apic_cluster = {
17250+static struct apic apic_x2apic_cluster __read_only = {
17251
17252 .name = "cluster x2apic",
17253 .probe = x2apic_cluster_probe,
17254diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
17255index 562a76d..a003c0f 100644
17256--- a/arch/x86/kernel/apic/x2apic_phys.c
17257+++ b/arch/x86/kernel/apic/x2apic_phys.c
17258@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
17259 return apic == &apic_x2apic_phys;
17260 }
17261
17262-static struct apic apic_x2apic_phys = {
17263+static struct apic apic_x2apic_phys __read_only = {
17264
17265 .name = "physical x2apic",
17266 .probe = x2apic_phys_probe,
17267diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
17268index 8cfade9..b9d04fc 100644
17269--- a/arch/x86/kernel/apic/x2apic_uv_x.c
17270+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
17271@@ -333,7 +333,7 @@ static int uv_probe(void)
17272 return apic == &apic_x2apic_uv_x;
17273 }
17274
17275-static struct apic __refdata apic_x2apic_uv_x = {
17276+static struct apic apic_x2apic_uv_x __read_only = {
17277
17278 .name = "UV large system",
17279 .probe = uv_probe,
17280diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
17281index d65464e..1035d31 100644
17282--- a/arch/x86/kernel/apm_32.c
17283+++ b/arch/x86/kernel/apm_32.c
17284@@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
17285 * This is for buggy BIOS's that refer to (real mode) segment 0x40
17286 * even though they are called in protected mode.
17287 */
17288-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
17289+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
17290 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
17291
17292 static const char driver_version[] = "1.16ac"; /* no spaces */
17293@@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
17294 BUG_ON(cpu != 0);
17295 gdt = get_cpu_gdt_table(cpu);
17296 save_desc_40 = gdt[0x40 / 8];
17297+
17298+ pax_open_kernel();
17299 gdt[0x40 / 8] = bad_bios_desc;
17300+ pax_close_kernel();
17301
17302 apm_irq_save(flags);
17303 APM_DO_SAVE_SEGS;
17304@@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
17305 &call->esi);
17306 APM_DO_RESTORE_SEGS;
17307 apm_irq_restore(flags);
17308+
17309+ pax_open_kernel();
17310 gdt[0x40 / 8] = save_desc_40;
17311+ pax_close_kernel();
17312+
17313 put_cpu();
17314
17315 return call->eax & 0xff;
17316@@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
17317 BUG_ON(cpu != 0);
17318 gdt = get_cpu_gdt_table(cpu);
17319 save_desc_40 = gdt[0x40 / 8];
17320+
17321+ pax_open_kernel();
17322 gdt[0x40 / 8] = bad_bios_desc;
17323+ pax_close_kernel();
17324
17325 apm_irq_save(flags);
17326 APM_DO_SAVE_SEGS;
17327@@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
17328 &call->eax);
17329 APM_DO_RESTORE_SEGS;
17330 apm_irq_restore(flags);
17331+
17332+ pax_open_kernel();
17333 gdt[0x40 / 8] = save_desc_40;
17334+ pax_close_kernel();
17335+
17336 put_cpu();
17337 return error;
17338 }
17339@@ -2345,12 +2359,15 @@ static int __init apm_init(void)
17340 * code to that CPU.
17341 */
17342 gdt = get_cpu_gdt_table(0);
17343+
17344+ pax_open_kernel();
17345 set_desc_base(&gdt[APM_CS >> 3],
17346 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
17347 set_desc_base(&gdt[APM_CS_16 >> 3],
17348 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
17349 set_desc_base(&gdt[APM_DS >> 3],
17350 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
17351+ pax_close_kernel();
17352
17353 proc_create("apm", 0, NULL, &apm_file_ops);
17354
17355diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
17356index 2861082..6d4718e 100644
17357--- a/arch/x86/kernel/asm-offsets.c
17358+++ b/arch/x86/kernel/asm-offsets.c
17359@@ -33,6 +33,8 @@ void common(void) {
17360 OFFSET(TI_status, thread_info, status);
17361 OFFSET(TI_addr_limit, thread_info, addr_limit);
17362 OFFSET(TI_preempt_count, thread_info, preempt_count);
17363+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
17364+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
17365
17366 BLANK();
17367 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
17368@@ -53,8 +55,26 @@ void common(void) {
17369 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
17370 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
17371 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
17372+
17373+#ifdef CONFIG_PAX_KERNEXEC
17374+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
17375 #endif
17376
17377+#ifdef CONFIG_PAX_MEMORY_UDEREF
17378+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
17379+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
17380+#ifdef CONFIG_X86_64
17381+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
17382+#endif
17383+#endif
17384+
17385+#endif
17386+
17387+ BLANK();
17388+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
17389+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
17390+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
17391+
17392 #ifdef CONFIG_XEN
17393 BLANK();
17394 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
17395diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
17396index 1b4754f..fbb4227 100644
17397--- a/arch/x86/kernel/asm-offsets_64.c
17398+++ b/arch/x86/kernel/asm-offsets_64.c
17399@@ -76,6 +76,7 @@ int main(void)
17400 BLANK();
17401 #undef ENTRY
17402
17403+ DEFINE(TSS_size, sizeof(struct tss_struct));
17404 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
17405 BLANK();
17406
17407diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
17408index a0e067d..9c7db16 100644
17409--- a/arch/x86/kernel/cpu/Makefile
17410+++ b/arch/x86/kernel/cpu/Makefile
17411@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
17412 CFLAGS_REMOVE_perf_event.o = -pg
17413 endif
17414
17415-# Make sure load_percpu_segment has no stackprotector
17416-nostackp := $(call cc-option, -fno-stack-protector)
17417-CFLAGS_common.o := $(nostackp)
17418-
17419 obj-y := intel_cacheinfo.o scattered.o topology.o
17420 obj-y += proc.o capflags.o powerflags.o common.o
17421 obj-y += vmware.o hypervisor.o mshyperv.o
17422diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
17423index 15239ff..e23e04e 100644
17424--- a/arch/x86/kernel/cpu/amd.c
17425+++ b/arch/x86/kernel/cpu/amd.c
17426@@ -733,7 +733,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
17427 unsigned int size)
17428 {
17429 /* AMD errata T13 (order #21922) */
17430- if ((c->x86 == 6)) {
17431+ if (c->x86 == 6) {
17432 /* Duron Rev A0 */
17433 if (c->x86_model == 3 && c->x86_mask == 0)
17434 size = 64;
17435diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
17436index 9c3ab43..51e6366 100644
17437--- a/arch/x86/kernel/cpu/common.c
17438+++ b/arch/x86/kernel/cpu/common.c
17439@@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
17440
17441 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
17442
17443-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
17444-#ifdef CONFIG_X86_64
17445- /*
17446- * We need valid kernel segments for data and code in long mode too
17447- * IRET will check the segment types kkeil 2000/10/28
17448- * Also sysret mandates a special GDT layout
17449- *
17450- * TLS descriptors are currently at a different place compared to i386.
17451- * Hopefully nobody expects them at a fixed place (Wine?)
17452- */
17453- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
17454- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
17455- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
17456- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
17457- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
17458- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
17459-#else
17460- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
17461- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17462- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
17463- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
17464- /*
17465- * Segments used for calling PnP BIOS have byte granularity.
17466- * They code segments and data segments have fixed 64k limits,
17467- * the transfer segment sizes are set at run time.
17468- */
17469- /* 32-bit code */
17470- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
17471- /* 16-bit code */
17472- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
17473- /* 16-bit data */
17474- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
17475- /* 16-bit data */
17476- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
17477- /* 16-bit data */
17478- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
17479- /*
17480- * The APM segments have byte granularity and their bases
17481- * are set at run time. All have 64k limits.
17482- */
17483- /* 32-bit code */
17484- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
17485- /* 16-bit code */
17486- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
17487- /* data */
17488- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
17489-
17490- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17491- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17492- GDT_STACK_CANARY_INIT
17493-#endif
17494-} };
17495-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
17496-
17497 static int __init x86_xsave_setup(char *s)
17498 {
17499 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
17500@@ -389,7 +335,7 @@ void switch_to_new_gdt(int cpu)
17501 {
17502 struct desc_ptr gdt_descr;
17503
17504- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
17505+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
17506 gdt_descr.size = GDT_SIZE - 1;
17507 load_gdt(&gdt_descr);
17508 /* Reload the per-cpu base */
17509@@ -885,6 +831,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
17510 /* Filter out anything that depends on CPUID levels we don't have */
17511 filter_cpuid_features(c, true);
17512
17513+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
17514+ setup_clear_cpu_cap(X86_FEATURE_SEP);
17515+#endif
17516+
17517 /* If the model name is still unset, do table lookup. */
17518 if (!c->x86_model_id[0]) {
17519 const char *p;
17520@@ -1068,10 +1018,12 @@ static __init int setup_disablecpuid(char *arg)
17521 }
17522 __setup("clearcpuid=", setup_disablecpuid);
17523
17524+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
17525+EXPORT_PER_CPU_SYMBOL(current_tinfo);
17526+
17527 #ifdef CONFIG_X86_64
17528 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
17529-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
17530- (unsigned long) nmi_idt_table };
17531+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
17532
17533 DEFINE_PER_CPU_FIRST(union irq_stack_union,
17534 irq_stack_union) __aligned(PAGE_SIZE);
17535@@ -1085,7 +1037,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
17536 EXPORT_PER_CPU_SYMBOL(current_task);
17537
17538 DEFINE_PER_CPU(unsigned long, kernel_stack) =
17539- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
17540+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
17541 EXPORT_PER_CPU_SYMBOL(kernel_stack);
17542
17543 DEFINE_PER_CPU(char *, irq_stack_ptr) =
17544@@ -1224,7 +1176,7 @@ void __cpuinit cpu_init(void)
17545 int i;
17546
17547 cpu = stack_smp_processor_id();
17548- t = &per_cpu(init_tss, cpu);
17549+ t = init_tss + cpu;
17550 oist = &per_cpu(orig_ist, cpu);
17551
17552 #ifdef CONFIG_NUMA
17553@@ -1250,7 +1202,7 @@ void __cpuinit cpu_init(void)
17554 switch_to_new_gdt(cpu);
17555 loadsegment(fs, 0);
17556
17557- load_idt((const struct desc_ptr *)&idt_descr);
17558+ load_idt(&idt_descr);
17559
17560 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
17561 syscall_init();
17562@@ -1259,7 +1211,6 @@ void __cpuinit cpu_init(void)
17563 wrmsrl(MSR_KERNEL_GS_BASE, 0);
17564 barrier();
17565
17566- x86_configure_nx();
17567 enable_x2apic();
17568
17569 /*
17570@@ -1311,7 +1262,7 @@ void __cpuinit cpu_init(void)
17571 {
17572 int cpu = smp_processor_id();
17573 struct task_struct *curr = current;
17574- struct tss_struct *t = &per_cpu(init_tss, cpu);
17575+ struct tss_struct *t = init_tss + cpu;
17576 struct thread_struct *thread = &curr->thread;
17577
17578 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
17579diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
17580index fcaabd0..7b55a26 100644
17581--- a/arch/x86/kernel/cpu/intel.c
17582+++ b/arch/x86/kernel/cpu/intel.c
17583@@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
17584 * Update the IDT descriptor and reload the IDT so that
17585 * it uses the read-only mapped virtual address.
17586 */
17587- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
17588+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
17589 load_idt(&idt_descr);
17590 }
17591 #endif
17592diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
17593index 84c1309..39b7224 100644
17594--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
17595+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
17596@@ -1017,6 +1017,22 @@ static struct attribute *default_attrs[] = {
17597 };
17598
17599 #ifdef CONFIG_AMD_NB
17600+static struct attribute *default_attrs_amd_nb[] = {
17601+ &type.attr,
17602+ &level.attr,
17603+ &coherency_line_size.attr,
17604+ &physical_line_partition.attr,
17605+ &ways_of_associativity.attr,
17606+ &number_of_sets.attr,
17607+ &size.attr,
17608+ &shared_cpu_map.attr,
17609+ &shared_cpu_list.attr,
17610+ NULL,
17611+ NULL,
17612+ NULL,
17613+ NULL
17614+};
17615+
17616 static struct attribute ** __cpuinit amd_l3_attrs(void)
17617 {
17618 static struct attribute **attrs;
17619@@ -1027,18 +1043,7 @@ static struct attribute ** __cpuinit amd_l3_attrs(void)
17620
17621 n = ARRAY_SIZE(default_attrs);
17622
17623- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
17624- n += 2;
17625-
17626- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
17627- n += 1;
17628-
17629- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
17630- if (attrs == NULL)
17631- return attrs = default_attrs;
17632-
17633- for (n = 0; default_attrs[n]; n++)
17634- attrs[n] = default_attrs[n];
17635+ attrs = default_attrs_amd_nb;
17636
17637 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
17638 attrs[n++] = &cache_disable_0.attr;
17639@@ -1089,6 +1094,13 @@ static struct kobj_type ktype_cache = {
17640 .default_attrs = default_attrs,
17641 };
17642
17643+#ifdef CONFIG_AMD_NB
17644+static struct kobj_type ktype_cache_amd_nb = {
17645+ .sysfs_ops = &sysfs_ops,
17646+ .default_attrs = default_attrs_amd_nb,
17647+};
17648+#endif
17649+
17650 static struct kobj_type ktype_percpu_entry = {
17651 .sysfs_ops = &sysfs_ops,
17652 };
17653@@ -1154,20 +1166,26 @@ static int __cpuinit cache_add_dev(struct device *dev)
17654 return retval;
17655 }
17656
17657+#ifdef CONFIG_AMD_NB
17658+ amd_l3_attrs();
17659+#endif
17660+
17661 for (i = 0; i < num_cache_leaves; i++) {
17662+ struct kobj_type *ktype;
17663+
17664 this_object = INDEX_KOBJECT_PTR(cpu, i);
17665 this_object->cpu = cpu;
17666 this_object->index = i;
17667
17668 this_leaf = CPUID4_INFO_IDX(cpu, i);
17669
17670- ktype_cache.default_attrs = default_attrs;
17671+ ktype = &ktype_cache;
17672 #ifdef CONFIG_AMD_NB
17673 if (this_leaf->base.nb)
17674- ktype_cache.default_attrs = amd_l3_attrs();
17675+ ktype = &ktype_cache_amd_nb;
17676 #endif
17677 retval = kobject_init_and_add(&(this_object->kobj),
17678- &ktype_cache,
17679+ ktype,
17680 per_cpu(ici_cache_kobject, cpu),
17681 "index%1lu", i);
17682 if (unlikely(retval)) {
17683@@ -1222,7 +1240,7 @@ static int __cpuinit cacheinfo_cpu_callback(struct notifier_block *nfb,
17684 return NOTIFY_OK;
17685 }
17686
17687-static struct notifier_block __cpuinitdata cacheinfo_cpu_notifier = {
17688+static struct notifier_block cacheinfo_cpu_notifier = {
17689 .notifier_call = cacheinfo_cpu_callback,
17690 };
17691
17692diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
17693index 80dbda8..be16652 100644
17694--- a/arch/x86/kernel/cpu/mcheck/mce.c
17695+++ b/arch/x86/kernel/cpu/mcheck/mce.c
17696@@ -45,6 +45,7 @@
17697 #include <asm/processor.h>
17698 #include <asm/mce.h>
17699 #include <asm/msr.h>
17700+#include <asm/local.h>
17701
17702 #include "mce-internal.h"
17703
17704@@ -246,7 +247,7 @@ static void print_mce(struct mce *m)
17705 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
17706 m->cs, m->ip);
17707
17708- if (m->cs == __KERNEL_CS)
17709+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
17710 print_symbol("{%s}", m->ip);
17711 pr_cont("\n");
17712 }
17713@@ -279,10 +280,10 @@ static void print_mce(struct mce *m)
17714
17715 #define PANIC_TIMEOUT 5 /* 5 seconds */
17716
17717-static atomic_t mce_paniced;
17718+static atomic_unchecked_t mce_paniced;
17719
17720 static int fake_panic;
17721-static atomic_t mce_fake_paniced;
17722+static atomic_unchecked_t mce_fake_paniced;
17723
17724 /* Panic in progress. Enable interrupts and wait for final IPI */
17725 static void wait_for_panic(void)
17726@@ -306,7 +307,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17727 /*
17728 * Make sure only one CPU runs in machine check panic
17729 */
17730- if (atomic_inc_return(&mce_paniced) > 1)
17731+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
17732 wait_for_panic();
17733 barrier();
17734
17735@@ -314,7 +315,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17736 console_verbose();
17737 } else {
17738 /* Don't log too much for fake panic */
17739- if (atomic_inc_return(&mce_fake_paniced) > 1)
17740+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
17741 return;
17742 }
17743 /* First print corrected ones that are still unlogged */
17744@@ -686,7 +687,7 @@ static int mce_timed_out(u64 *t)
17745 * might have been modified by someone else.
17746 */
17747 rmb();
17748- if (atomic_read(&mce_paniced))
17749+ if (atomic_read_unchecked(&mce_paniced))
17750 wait_for_panic();
17751 if (!mca_cfg.monarch_timeout)
17752 goto out;
17753@@ -1662,7 +1663,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
17754 }
17755
17756 /* Call the installed machine check handler for this CPU setup. */
17757-void (*machine_check_vector)(struct pt_regs *, long error_code) =
17758+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
17759 unexpected_machine_check;
17760
17761 /*
17762@@ -1685,7 +1686,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
17763 return;
17764 }
17765
17766+ pax_open_kernel();
17767 machine_check_vector = do_machine_check;
17768+ pax_close_kernel();
17769
17770 __mcheck_cpu_init_generic();
17771 __mcheck_cpu_init_vendor(c);
17772@@ -1699,7 +1702,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
17773 */
17774
17775 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
17776-static int mce_chrdev_open_count; /* #times opened */
17777+static local_t mce_chrdev_open_count; /* #times opened */
17778 static int mce_chrdev_open_exclu; /* already open exclusive? */
17779
17780 static int mce_chrdev_open(struct inode *inode, struct file *file)
17781@@ -1707,7 +1710,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
17782 spin_lock(&mce_chrdev_state_lock);
17783
17784 if (mce_chrdev_open_exclu ||
17785- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
17786+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
17787 spin_unlock(&mce_chrdev_state_lock);
17788
17789 return -EBUSY;
17790@@ -1715,7 +1718,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
17791
17792 if (file->f_flags & O_EXCL)
17793 mce_chrdev_open_exclu = 1;
17794- mce_chrdev_open_count++;
17795+ local_inc(&mce_chrdev_open_count);
17796
17797 spin_unlock(&mce_chrdev_state_lock);
17798
17799@@ -1726,7 +1729,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
17800 {
17801 spin_lock(&mce_chrdev_state_lock);
17802
17803- mce_chrdev_open_count--;
17804+ local_dec(&mce_chrdev_open_count);
17805 mce_chrdev_open_exclu = 0;
17806
17807 spin_unlock(&mce_chrdev_state_lock);
17808@@ -2372,7 +2375,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
17809 return NOTIFY_OK;
17810 }
17811
17812-static struct notifier_block mce_cpu_notifier __cpuinitdata = {
17813+static struct notifier_block mce_cpu_notifier = {
17814 .notifier_call = mce_cpu_callback,
17815 };
17816
17817@@ -2382,7 +2385,7 @@ static __init void mce_init_banks(void)
17818
17819 for (i = 0; i < mca_cfg.banks; i++) {
17820 struct mce_bank *b = &mce_banks[i];
17821- struct device_attribute *a = &b->attr;
17822+ device_attribute_no_const *a = &b->attr;
17823
17824 sysfs_attr_init(&a->attr);
17825 a->attr.name = b->attrname;
17826@@ -2450,7 +2453,7 @@ struct dentry *mce_get_debugfs_dir(void)
17827 static void mce_reset(void)
17828 {
17829 cpu_missing = 0;
17830- atomic_set(&mce_fake_paniced, 0);
17831+ atomic_set_unchecked(&mce_fake_paniced, 0);
17832 atomic_set(&mce_executing, 0);
17833 atomic_set(&mce_callin, 0);
17834 atomic_set(&global_nwo, 0);
17835diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
17836index 2d5454c..51987eb 100644
17837--- a/arch/x86/kernel/cpu/mcheck/p5.c
17838+++ b/arch/x86/kernel/cpu/mcheck/p5.c
17839@@ -11,6 +11,7 @@
17840 #include <asm/processor.h>
17841 #include <asm/mce.h>
17842 #include <asm/msr.h>
17843+#include <asm/pgtable.h>
17844
17845 /* By default disabled */
17846 int mce_p5_enabled __read_mostly;
17847@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
17848 if (!cpu_has(c, X86_FEATURE_MCE))
17849 return;
17850
17851+ pax_open_kernel();
17852 machine_check_vector = pentium_machine_check;
17853+ pax_close_kernel();
17854 /* Make sure the vector pointer is visible before we enable MCEs: */
17855 wmb();
17856
17857diff --git a/arch/x86/kernel/cpu/mcheck/therm_throt.c b/arch/x86/kernel/cpu/mcheck/therm_throt.c
17858index 47a1870..8c019a7 100644
17859--- a/arch/x86/kernel/cpu/mcheck/therm_throt.c
17860+++ b/arch/x86/kernel/cpu/mcheck/therm_throt.c
17861@@ -288,7 +288,7 @@ thermal_throttle_cpu_callback(struct notifier_block *nfb,
17862 return notifier_from_errno(err);
17863 }
17864
17865-static struct notifier_block thermal_throttle_cpu_notifier __cpuinitdata =
17866+static struct notifier_block thermal_throttle_cpu_notifier =
17867 {
17868 .notifier_call = thermal_throttle_cpu_callback,
17869 };
17870diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
17871index 2d7998f..17c9de1 100644
17872--- a/arch/x86/kernel/cpu/mcheck/winchip.c
17873+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
17874@@ -10,6 +10,7 @@
17875 #include <asm/processor.h>
17876 #include <asm/mce.h>
17877 #include <asm/msr.h>
17878+#include <asm/pgtable.h>
17879
17880 /* Machine check handler for WinChip C6: */
17881 static void winchip_machine_check(struct pt_regs *regs, long error_code)
17882@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
17883 {
17884 u32 lo, hi;
17885
17886+ pax_open_kernel();
17887 machine_check_vector = winchip_machine_check;
17888+ pax_close_kernel();
17889 /* Make sure the vector pointer is visible before we enable MCEs: */
17890 wmb();
17891
17892diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
17893index 726bf96..81f0526 100644
17894--- a/arch/x86/kernel/cpu/mtrr/main.c
17895+++ b/arch/x86/kernel/cpu/mtrr/main.c
17896@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
17897 u64 size_or_mask, size_and_mask;
17898 static bool mtrr_aps_delayed_init;
17899
17900-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
17901+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
17902
17903 const struct mtrr_ops *mtrr_if;
17904
17905diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
17906index df5e41f..816c719 100644
17907--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
17908+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
17909@@ -25,7 +25,7 @@ struct mtrr_ops {
17910 int (*validate_add_page)(unsigned long base, unsigned long size,
17911 unsigned int type);
17912 int (*have_wrcomb)(void);
17913-};
17914+} __do_const;
17915
17916 extern int generic_get_free_region(unsigned long base, unsigned long size,
17917 int replace_reg);
17918diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
17919index 6774c17..72c1b22 100644
17920--- a/arch/x86/kernel/cpu/perf_event.c
17921+++ b/arch/x86/kernel/cpu/perf_event.c
17922@@ -1305,7 +1305,7 @@ static void __init pmu_check_apic(void)
17923 pr_info("no hardware sampling interrupt available.\n");
17924 }
17925
17926-static struct attribute_group x86_pmu_format_group = {
17927+static attribute_group_no_const x86_pmu_format_group = {
17928 .name = "format",
17929 .attrs = NULL,
17930 };
17931@@ -1313,7 +1313,7 @@ static struct attribute_group x86_pmu_format_group = {
17932 struct perf_pmu_events_attr {
17933 struct device_attribute attr;
17934 u64 id;
17935-};
17936+} __do_const;
17937
17938 /*
17939 * Remove all undefined events (x86_pmu.event_map(id) == 0)
17940@@ -1381,7 +1381,7 @@ static struct attribute *events_attr[] = {
17941 NULL,
17942 };
17943
17944-static struct attribute_group x86_pmu_events_group = {
17945+static attribute_group_no_const x86_pmu_events_group = {
17946 .name = "events",
17947 .attrs = events_attr,
17948 };
17949@@ -1880,7 +1880,7 @@ static unsigned long get_segment_base(unsigned int segment)
17950 if (idx > GDT_ENTRIES)
17951 return 0;
17952
17953- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
17954+ desc = get_cpu_gdt_table(smp_processor_id());
17955 }
17956
17957 return get_desc_base(desc + idx);
17958@@ -1970,7 +1970,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
17959 break;
17960
17961 perf_callchain_store(entry, frame.return_address);
17962- fp = frame.next_frame;
17963+ fp = (const void __force_user *)frame.next_frame;
17964 }
17965 }
17966
17967diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
17968index 4914e94..60b06e3 100644
17969--- a/arch/x86/kernel/cpu/perf_event_intel.c
17970+++ b/arch/x86/kernel/cpu/perf_event_intel.c
17971@@ -1958,10 +1958,10 @@ __init int intel_pmu_init(void)
17972 * v2 and above have a perf capabilities MSR
17973 */
17974 if (version > 1) {
17975- u64 capabilities;
17976+ u64 capabilities = x86_pmu.intel_cap.capabilities;
17977
17978- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
17979- x86_pmu.intel_cap.capabilities = capabilities;
17980+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
17981+ x86_pmu.intel_cap.capabilities = capabilities;
17982 }
17983
17984 intel_ds_init();
17985diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17986index b43200d..d235b3e 100644
17987--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17988+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17989@@ -2428,7 +2428,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
17990 static int __init uncore_type_init(struct intel_uncore_type *type)
17991 {
17992 struct intel_uncore_pmu *pmus;
17993- struct attribute_group *events_group;
17994+ attribute_group_no_const *attr_group;
17995 struct attribute **attrs;
17996 int i, j;
17997
17998@@ -2455,19 +2455,19 @@ static int __init uncore_type_init(struct intel_uncore_type *type)
17999 while (type->event_descs[i].attr.attr.name)
18000 i++;
18001
18002- events_group = kzalloc(sizeof(struct attribute *) * (i + 1) +
18003- sizeof(*events_group), GFP_KERNEL);
18004- if (!events_group)
18005+ attr_group = kzalloc(sizeof(struct attribute *) * (i + 1) +
18006+ sizeof(*attr_group), GFP_KERNEL);
18007+ if (!attr_group)
18008 goto fail;
18009
18010- attrs = (struct attribute **)(events_group + 1);
18011- events_group->name = "events";
18012- events_group->attrs = attrs;
18013+ attrs = (struct attribute **)(attr_group + 1);
18014+ attr_group->name = "events";
18015+ attr_group->attrs = attrs;
18016
18017 for (j = 0; j < i; j++)
18018 attrs[j] = &type->event_descs[j].attr.attr;
18019
18020- type->events_group = events_group;
18021+ type->events_group = attr_group;
18022 }
18023
18024 type->pmu_group = &uncore_pmu_attr_group;
18025@@ -2826,7 +2826,7 @@ static int
18026 return NOTIFY_OK;
18027 }
18028
18029-static struct notifier_block uncore_cpu_nb __cpuinitdata = {
18030+static struct notifier_block uncore_cpu_nb = {
18031 .notifier_call = uncore_cpu_notifier,
18032 /*
18033 * to migrate uncore events, our notifier should be executed
18034diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
18035index e68a455..975a932 100644
18036--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
18037+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
18038@@ -428,7 +428,7 @@ struct intel_uncore_box {
18039 struct uncore_event_desc {
18040 struct kobj_attribute attr;
18041 const char *config;
18042-};
18043+} __do_const;
18044
18045 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
18046 { \
18047diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
18048index 60c7891..9e911d3 100644
18049--- a/arch/x86/kernel/cpuid.c
18050+++ b/arch/x86/kernel/cpuid.c
18051@@ -171,7 +171,7 @@ static int __cpuinit cpuid_class_cpu_callback(struct notifier_block *nfb,
18052 return notifier_from_errno(err);
18053 }
18054
18055-static struct notifier_block __refdata cpuid_class_cpu_notifier =
18056+static struct notifier_block cpuid_class_cpu_notifier =
18057 {
18058 .notifier_call = cpuid_class_cpu_callback,
18059 };
18060diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
18061index 74467fe..18793d5 100644
18062--- a/arch/x86/kernel/crash.c
18063+++ b/arch/x86/kernel/crash.c
18064@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
18065 {
18066 #ifdef CONFIG_X86_32
18067 struct pt_regs fixed_regs;
18068-#endif
18069
18070-#ifdef CONFIG_X86_32
18071- if (!user_mode_vm(regs)) {
18072+ if (!user_mode(regs)) {
18073 crash_fixup_ss_esp(&fixed_regs, regs);
18074 regs = &fixed_regs;
18075 }
18076diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
18077index 37250fe..bf2ec74 100644
18078--- a/arch/x86/kernel/doublefault_32.c
18079+++ b/arch/x86/kernel/doublefault_32.c
18080@@ -11,7 +11,7 @@
18081
18082 #define DOUBLEFAULT_STACKSIZE (1024)
18083 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
18084-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
18085+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
18086
18087 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
18088
18089@@ -21,7 +21,7 @@ static void doublefault_fn(void)
18090 unsigned long gdt, tss;
18091
18092 store_gdt(&gdt_desc);
18093- gdt = gdt_desc.address;
18094+ gdt = (unsigned long)gdt_desc.address;
18095
18096 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
18097
18098@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
18099 /* 0x2 bit is always set */
18100 .flags = X86_EFLAGS_SF | 0x2,
18101 .sp = STACK_START,
18102- .es = __USER_DS,
18103+ .es = __KERNEL_DS,
18104 .cs = __KERNEL_CS,
18105 .ss = __KERNEL_DS,
18106- .ds = __USER_DS,
18107+ .ds = __KERNEL_DS,
18108 .fs = __KERNEL_PERCPU,
18109
18110 .__cr3 = __pa_nodebug(swapper_pg_dir),
18111diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
18112index ae42418b..787c16b 100644
18113--- a/arch/x86/kernel/dumpstack.c
18114+++ b/arch/x86/kernel/dumpstack.c
18115@@ -2,6 +2,9 @@
18116 * Copyright (C) 1991, 1992 Linus Torvalds
18117 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
18118 */
18119+#ifdef CONFIG_GRKERNSEC_HIDESYM
18120+#define __INCLUDED_BY_HIDESYM 1
18121+#endif
18122 #include <linux/kallsyms.h>
18123 #include <linux/kprobes.h>
18124 #include <linux/uaccess.h>
18125@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
18126 static void
18127 print_ftrace_graph_addr(unsigned long addr, void *data,
18128 const struct stacktrace_ops *ops,
18129- struct thread_info *tinfo, int *graph)
18130+ struct task_struct *task, int *graph)
18131 {
18132- struct task_struct *task;
18133 unsigned long ret_addr;
18134 int index;
18135
18136 if (addr != (unsigned long)return_to_handler)
18137 return;
18138
18139- task = tinfo->task;
18140 index = task->curr_ret_stack;
18141
18142 if (!task->ret_stack || index < *graph)
18143@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
18144 static inline void
18145 print_ftrace_graph_addr(unsigned long addr, void *data,
18146 const struct stacktrace_ops *ops,
18147- struct thread_info *tinfo, int *graph)
18148+ struct task_struct *task, int *graph)
18149 { }
18150 #endif
18151
18152@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
18153 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
18154 */
18155
18156-static inline int valid_stack_ptr(struct thread_info *tinfo,
18157- void *p, unsigned int size, void *end)
18158+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
18159 {
18160- void *t = tinfo;
18161 if (end) {
18162 if (p < end && p >= (end-THREAD_SIZE))
18163 return 1;
18164@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
18165 }
18166
18167 unsigned long
18168-print_context_stack(struct thread_info *tinfo,
18169+print_context_stack(struct task_struct *task, void *stack_start,
18170 unsigned long *stack, unsigned long bp,
18171 const struct stacktrace_ops *ops, void *data,
18172 unsigned long *end, int *graph)
18173 {
18174 struct stack_frame *frame = (struct stack_frame *)bp;
18175
18176- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
18177+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
18178 unsigned long addr;
18179
18180 addr = *stack;
18181@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
18182 } else {
18183 ops->address(data, addr, 0);
18184 }
18185- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
18186+ print_ftrace_graph_addr(addr, data, ops, task, graph);
18187 }
18188 stack++;
18189 }
18190@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
18191 EXPORT_SYMBOL_GPL(print_context_stack);
18192
18193 unsigned long
18194-print_context_stack_bp(struct thread_info *tinfo,
18195+print_context_stack_bp(struct task_struct *task, void *stack_start,
18196 unsigned long *stack, unsigned long bp,
18197 const struct stacktrace_ops *ops, void *data,
18198 unsigned long *end, int *graph)
18199@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
18200 struct stack_frame *frame = (struct stack_frame *)bp;
18201 unsigned long *ret_addr = &frame->return_address;
18202
18203- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
18204+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
18205 unsigned long addr = *ret_addr;
18206
18207 if (!__kernel_text_address(addr))
18208@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
18209 ops->address(data, addr, 1);
18210 frame = frame->next_frame;
18211 ret_addr = &frame->return_address;
18212- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
18213+ print_ftrace_graph_addr(addr, data, ops, task, graph);
18214 }
18215
18216 return (unsigned long)frame;
18217@@ -189,7 +188,7 @@ void dump_stack(void)
18218
18219 bp = stack_frame(current, NULL);
18220 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
18221- current->pid, current->comm, print_tainted(),
18222+ task_pid_nr(current), current->comm, print_tainted(),
18223 init_utsname()->release,
18224 (int)strcspn(init_utsname()->version, " "),
18225 init_utsname()->version);
18226@@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
18227 }
18228 EXPORT_SYMBOL_GPL(oops_begin);
18229
18230+extern void gr_handle_kernel_exploit(void);
18231+
18232 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
18233 {
18234 if (regs && kexec_should_crash(current))
18235@@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
18236 panic("Fatal exception in interrupt");
18237 if (panic_on_oops)
18238 panic("Fatal exception");
18239- do_exit(signr);
18240+
18241+ gr_handle_kernel_exploit();
18242+
18243+ do_group_exit(signr);
18244 }
18245
18246 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
18247@@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
18248 print_modules();
18249 show_regs(regs);
18250 #ifdef CONFIG_X86_32
18251- if (user_mode_vm(regs)) {
18252+ if (user_mode(regs)) {
18253 sp = regs->sp;
18254 ss = regs->ss & 0xffff;
18255 } else {
18256@@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
18257 unsigned long flags = oops_begin();
18258 int sig = SIGSEGV;
18259
18260- if (!user_mode_vm(regs))
18261+ if (!user_mode(regs))
18262 report_bug(regs->ip, regs);
18263
18264 if (__die(str, regs, err))
18265diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
18266index 1038a41..db2c12b 100644
18267--- a/arch/x86/kernel/dumpstack_32.c
18268+++ b/arch/x86/kernel/dumpstack_32.c
18269@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18270 bp = stack_frame(task, regs);
18271
18272 for (;;) {
18273- struct thread_info *context;
18274+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
18275
18276- context = (struct thread_info *)
18277- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
18278- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
18279+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
18280
18281- stack = (unsigned long *)context->previous_esp;
18282- if (!stack)
18283+ if (stack_start == task_stack_page(task))
18284 break;
18285+ stack = *(unsigned long **)stack_start;
18286 if (ops->stack(data, "IRQ") < 0)
18287 break;
18288 touch_nmi_watchdog();
18289@@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
18290 {
18291 int i;
18292
18293- __show_regs(regs, !user_mode_vm(regs));
18294+ __show_regs(regs, !user_mode(regs));
18295
18296 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
18297 TASK_COMM_LEN, current->comm, task_pid_nr(current),
18298@@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
18299 * When in-kernel, we also print out the stack and code at the
18300 * time of the fault..
18301 */
18302- if (!user_mode_vm(regs)) {
18303+ if (!user_mode(regs)) {
18304 unsigned int code_prologue = code_bytes * 43 / 64;
18305 unsigned int code_len = code_bytes;
18306 unsigned char c;
18307 u8 *ip;
18308+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
18309
18310 pr_emerg("Stack:\n");
18311 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
18312
18313 pr_emerg("Code:");
18314
18315- ip = (u8 *)regs->ip - code_prologue;
18316+ ip = (u8 *)regs->ip - code_prologue + cs_base;
18317 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
18318 /* try starting at IP */
18319- ip = (u8 *)regs->ip;
18320+ ip = (u8 *)regs->ip + cs_base;
18321 code_len = code_len - code_prologue + 1;
18322 }
18323 for (i = 0; i < code_len; i++, ip++) {
18324@@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
18325 pr_cont(" Bad EIP value.");
18326 break;
18327 }
18328- if (ip == (u8 *)regs->ip)
18329+ if (ip == (u8 *)regs->ip + cs_base)
18330 pr_cont(" <%02x>", c);
18331 else
18332 pr_cont(" %02x", c);
18333@@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
18334 {
18335 unsigned short ud2;
18336
18337+ ip = ktla_ktva(ip);
18338 if (ip < PAGE_OFFSET)
18339 return 0;
18340 if (probe_kernel_address((unsigned short *)ip, ud2))
18341@@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
18342
18343 return ud2 == 0x0b0f;
18344 }
18345+
18346+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18347+void pax_check_alloca(unsigned long size)
18348+{
18349+ unsigned long sp = (unsigned long)&sp, stack_left;
18350+
18351+ /* all kernel stacks are of the same size */
18352+ stack_left = sp & (THREAD_SIZE - 1);
18353+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18354+}
18355+EXPORT_SYMBOL(pax_check_alloca);
18356+#endif
18357diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
18358index b653675..51cc8c0 100644
18359--- a/arch/x86/kernel/dumpstack_64.c
18360+++ b/arch/x86/kernel/dumpstack_64.c
18361@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18362 unsigned long *irq_stack_end =
18363 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
18364 unsigned used = 0;
18365- struct thread_info *tinfo;
18366 int graph = 0;
18367 unsigned long dummy;
18368+ void *stack_start;
18369
18370 if (!task)
18371 task = current;
18372@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18373 * current stack address. If the stacks consist of nested
18374 * exceptions
18375 */
18376- tinfo = task_thread_info(task);
18377 for (;;) {
18378 char *id;
18379 unsigned long *estack_end;
18380+
18381 estack_end = in_exception_stack(cpu, (unsigned long)stack,
18382 &used, &id);
18383
18384@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18385 if (ops->stack(data, id) < 0)
18386 break;
18387
18388- bp = ops->walk_stack(tinfo, stack, bp, ops,
18389+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
18390 data, estack_end, &graph);
18391 ops->stack(data, "<EOE>");
18392 /*
18393@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18394 * second-to-last pointer (index -2 to end) in the
18395 * exception stack:
18396 */
18397+ if ((u16)estack_end[-1] != __KERNEL_DS)
18398+ goto out;
18399 stack = (unsigned long *) estack_end[-2];
18400 continue;
18401 }
18402@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18403 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
18404 if (ops->stack(data, "IRQ") < 0)
18405 break;
18406- bp = ops->walk_stack(tinfo, stack, bp,
18407+ bp = ops->walk_stack(task, irq_stack, stack, bp,
18408 ops, data, irq_stack_end, &graph);
18409 /*
18410 * We link to the next stack (which would be
18411@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18412 /*
18413 * This handles the process stack:
18414 */
18415- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
18416+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
18417+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
18418+out:
18419 put_cpu();
18420 }
18421 EXPORT_SYMBOL(dump_trace);
18422@@ -249,7 +253,7 @@ void show_regs(struct pt_regs *regs)
18423 {
18424 int i;
18425 unsigned long sp;
18426- const int cpu = smp_processor_id();
18427+ const int cpu = raw_smp_processor_id();
18428 struct task_struct *cur = current;
18429
18430 sp = regs->sp;
18431@@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
18432
18433 return ud2 == 0x0b0f;
18434 }
18435+
18436+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18437+void pax_check_alloca(unsigned long size)
18438+{
18439+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
18440+ unsigned cpu, used;
18441+ char *id;
18442+
18443+ /* check the process stack first */
18444+ stack_start = (unsigned long)task_stack_page(current);
18445+ stack_end = stack_start + THREAD_SIZE;
18446+ if (likely(stack_start <= sp && sp < stack_end)) {
18447+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
18448+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18449+ return;
18450+ }
18451+
18452+ cpu = get_cpu();
18453+
18454+ /* check the irq stacks */
18455+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
18456+ stack_start = stack_end - IRQ_STACK_SIZE;
18457+ if (stack_start <= sp && sp < stack_end) {
18458+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
18459+ put_cpu();
18460+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18461+ return;
18462+ }
18463+
18464+ /* check the exception stacks */
18465+ used = 0;
18466+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
18467+ stack_start = stack_end - EXCEPTION_STKSZ;
18468+ if (stack_end && stack_start <= sp && sp < stack_end) {
18469+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
18470+ put_cpu();
18471+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18472+ return;
18473+ }
18474+
18475+ put_cpu();
18476+
18477+ /* unknown stack */
18478+ BUG();
18479+}
18480+EXPORT_SYMBOL(pax_check_alloca);
18481+#endif
18482diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
18483index 9b9f18b..9fcaa04 100644
18484--- a/arch/x86/kernel/early_printk.c
18485+++ b/arch/x86/kernel/early_printk.c
18486@@ -7,6 +7,7 @@
18487 #include <linux/pci_regs.h>
18488 #include <linux/pci_ids.h>
18489 #include <linux/errno.h>
18490+#include <linux/sched.h>
18491 #include <asm/io.h>
18492 #include <asm/processor.h>
18493 #include <asm/fcntl.h>
18494diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
18495index 6ed91d9..6cc365b 100644
18496--- a/arch/x86/kernel/entry_32.S
18497+++ b/arch/x86/kernel/entry_32.S
18498@@ -177,13 +177,153 @@
18499 /*CFI_REL_OFFSET gs, PT_GS*/
18500 .endm
18501 .macro SET_KERNEL_GS reg
18502+
18503+#ifdef CONFIG_CC_STACKPROTECTOR
18504 movl $(__KERNEL_STACK_CANARY), \reg
18505+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
18506+ movl $(__USER_DS), \reg
18507+#else
18508+ xorl \reg, \reg
18509+#endif
18510+
18511 movl \reg, %gs
18512 .endm
18513
18514 #endif /* CONFIG_X86_32_LAZY_GS */
18515
18516-.macro SAVE_ALL
18517+.macro pax_enter_kernel
18518+#ifdef CONFIG_PAX_KERNEXEC
18519+ call pax_enter_kernel
18520+#endif
18521+.endm
18522+
18523+.macro pax_exit_kernel
18524+#ifdef CONFIG_PAX_KERNEXEC
18525+ call pax_exit_kernel
18526+#endif
18527+.endm
18528+
18529+#ifdef CONFIG_PAX_KERNEXEC
18530+ENTRY(pax_enter_kernel)
18531+#ifdef CONFIG_PARAVIRT
18532+ pushl %eax
18533+ pushl %ecx
18534+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
18535+ mov %eax, %esi
18536+#else
18537+ mov %cr0, %esi
18538+#endif
18539+ bts $16, %esi
18540+ jnc 1f
18541+ mov %cs, %esi
18542+ cmp $__KERNEL_CS, %esi
18543+ jz 3f
18544+ ljmp $__KERNEL_CS, $3f
18545+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
18546+2:
18547+#ifdef CONFIG_PARAVIRT
18548+ mov %esi, %eax
18549+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
18550+#else
18551+ mov %esi, %cr0
18552+#endif
18553+3:
18554+#ifdef CONFIG_PARAVIRT
18555+ popl %ecx
18556+ popl %eax
18557+#endif
18558+ ret
18559+ENDPROC(pax_enter_kernel)
18560+
18561+ENTRY(pax_exit_kernel)
18562+#ifdef CONFIG_PARAVIRT
18563+ pushl %eax
18564+ pushl %ecx
18565+#endif
18566+ mov %cs, %esi
18567+ cmp $__KERNEXEC_KERNEL_CS, %esi
18568+ jnz 2f
18569+#ifdef CONFIG_PARAVIRT
18570+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
18571+ mov %eax, %esi
18572+#else
18573+ mov %cr0, %esi
18574+#endif
18575+ btr $16, %esi
18576+ ljmp $__KERNEL_CS, $1f
18577+1:
18578+#ifdef CONFIG_PARAVIRT
18579+ mov %esi, %eax
18580+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
18581+#else
18582+ mov %esi, %cr0
18583+#endif
18584+2:
18585+#ifdef CONFIG_PARAVIRT
18586+ popl %ecx
18587+ popl %eax
18588+#endif
18589+ ret
18590+ENDPROC(pax_exit_kernel)
18591+#endif
18592+
18593+.macro pax_erase_kstack
18594+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18595+ call pax_erase_kstack
18596+#endif
18597+.endm
18598+
18599+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18600+/*
18601+ * ebp: thread_info
18602+ */
18603+ENTRY(pax_erase_kstack)
18604+ pushl %edi
18605+ pushl %ecx
18606+ pushl %eax
18607+
18608+ mov TI_lowest_stack(%ebp), %edi
18609+ mov $-0xBEEF, %eax
18610+ std
18611+
18612+1: mov %edi, %ecx
18613+ and $THREAD_SIZE_asm - 1, %ecx
18614+ shr $2, %ecx
18615+ repne scasl
18616+ jecxz 2f
18617+
18618+ cmp $2*16, %ecx
18619+ jc 2f
18620+
18621+ mov $2*16, %ecx
18622+ repe scasl
18623+ jecxz 2f
18624+ jne 1b
18625+
18626+2: cld
18627+ mov %esp, %ecx
18628+ sub %edi, %ecx
18629+
18630+ cmp $THREAD_SIZE_asm, %ecx
18631+ jb 3f
18632+ ud2
18633+3:
18634+
18635+ shr $2, %ecx
18636+ rep stosl
18637+
18638+ mov TI_task_thread_sp0(%ebp), %edi
18639+ sub $128, %edi
18640+ mov %edi, TI_lowest_stack(%ebp)
18641+
18642+ popl %eax
18643+ popl %ecx
18644+ popl %edi
18645+ ret
18646+ENDPROC(pax_erase_kstack)
18647+#endif
18648+
18649+.macro __SAVE_ALL _DS
18650 cld
18651 PUSH_GS
18652 pushl_cfi %fs
18653@@ -206,7 +346,7 @@
18654 CFI_REL_OFFSET ecx, 0
18655 pushl_cfi %ebx
18656 CFI_REL_OFFSET ebx, 0
18657- movl $(__USER_DS), %edx
18658+ movl $\_DS, %edx
18659 movl %edx, %ds
18660 movl %edx, %es
18661 movl $(__KERNEL_PERCPU), %edx
18662@@ -214,6 +354,15 @@
18663 SET_KERNEL_GS %edx
18664 .endm
18665
18666+.macro SAVE_ALL
18667+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
18668+ __SAVE_ALL __KERNEL_DS
18669+ pax_enter_kernel
18670+#else
18671+ __SAVE_ALL __USER_DS
18672+#endif
18673+.endm
18674+
18675 .macro RESTORE_INT_REGS
18676 popl_cfi %ebx
18677 CFI_RESTORE ebx
18678@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
18679 popfl_cfi
18680 jmp syscall_exit
18681 CFI_ENDPROC
18682-END(ret_from_fork)
18683+ENDPROC(ret_from_fork)
18684
18685 ENTRY(ret_from_kernel_thread)
18686 CFI_STARTPROC
18687@@ -344,7 +493,15 @@ ret_from_intr:
18688 andl $SEGMENT_RPL_MASK, %eax
18689 #endif
18690 cmpl $USER_RPL, %eax
18691+
18692+#ifdef CONFIG_PAX_KERNEXEC
18693+ jae resume_userspace
18694+
18695+ pax_exit_kernel
18696+ jmp resume_kernel
18697+#else
18698 jb resume_kernel # not returning to v8086 or userspace
18699+#endif
18700
18701 ENTRY(resume_userspace)
18702 LOCKDEP_SYS_EXIT
18703@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
18704 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
18705 # int/exception return?
18706 jne work_pending
18707- jmp restore_all
18708-END(ret_from_exception)
18709+ jmp restore_all_pax
18710+ENDPROC(ret_from_exception)
18711
18712 #ifdef CONFIG_PREEMPT
18713 ENTRY(resume_kernel)
18714@@ -372,7 +529,7 @@ need_resched:
18715 jz restore_all
18716 call preempt_schedule_irq
18717 jmp need_resched
18718-END(resume_kernel)
18719+ENDPROC(resume_kernel)
18720 #endif
18721 CFI_ENDPROC
18722 /*
18723@@ -406,30 +563,45 @@ sysenter_past_esp:
18724 /*CFI_REL_OFFSET cs, 0*/
18725 /*
18726 * Push current_thread_info()->sysenter_return to the stack.
18727- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
18728- * pushed above; +8 corresponds to copy_thread's esp0 setting.
18729 */
18730- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
18731+ pushl_cfi $0
18732 CFI_REL_OFFSET eip, 0
18733
18734 pushl_cfi %eax
18735 SAVE_ALL
18736+ GET_THREAD_INFO(%ebp)
18737+ movl TI_sysenter_return(%ebp),%ebp
18738+ movl %ebp,PT_EIP(%esp)
18739 ENABLE_INTERRUPTS(CLBR_NONE)
18740
18741 /*
18742 * Load the potential sixth argument from user stack.
18743 * Careful about security.
18744 */
18745+ movl PT_OLDESP(%esp),%ebp
18746+
18747+#ifdef CONFIG_PAX_MEMORY_UDEREF
18748+ mov PT_OLDSS(%esp),%ds
18749+1: movl %ds:(%ebp),%ebp
18750+ push %ss
18751+ pop %ds
18752+#else
18753 cmpl $__PAGE_OFFSET-3,%ebp
18754 jae syscall_fault
18755 ASM_STAC
18756 1: movl (%ebp),%ebp
18757 ASM_CLAC
18758+#endif
18759+
18760 movl %ebp,PT_EBP(%esp)
18761 _ASM_EXTABLE(1b,syscall_fault)
18762
18763 GET_THREAD_INFO(%ebp)
18764
18765+#ifdef CONFIG_PAX_RANDKSTACK
18766+ pax_erase_kstack
18767+#endif
18768+
18769 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
18770 jnz sysenter_audit
18771 sysenter_do_call:
18772@@ -444,12 +616,24 @@ sysenter_do_call:
18773 testl $_TIF_ALLWORK_MASK, %ecx
18774 jne sysexit_audit
18775 sysenter_exit:
18776+
18777+#ifdef CONFIG_PAX_RANDKSTACK
18778+ pushl_cfi %eax
18779+ movl %esp, %eax
18780+ call pax_randomize_kstack
18781+ popl_cfi %eax
18782+#endif
18783+
18784+ pax_erase_kstack
18785+
18786 /* if something modifies registers it must also disable sysexit */
18787 movl PT_EIP(%esp), %edx
18788 movl PT_OLDESP(%esp), %ecx
18789 xorl %ebp,%ebp
18790 TRACE_IRQS_ON
18791 1: mov PT_FS(%esp), %fs
18792+2: mov PT_DS(%esp), %ds
18793+3: mov PT_ES(%esp), %es
18794 PTGS_TO_GS
18795 ENABLE_INTERRUPTS_SYSEXIT
18796
18797@@ -466,6 +650,9 @@ sysenter_audit:
18798 movl %eax,%edx /* 2nd arg: syscall number */
18799 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
18800 call __audit_syscall_entry
18801+
18802+ pax_erase_kstack
18803+
18804 pushl_cfi %ebx
18805 movl PT_EAX(%esp),%eax /* reload syscall number */
18806 jmp sysenter_do_call
18807@@ -491,10 +678,16 @@ sysexit_audit:
18808
18809 CFI_ENDPROC
18810 .pushsection .fixup,"ax"
18811-2: movl $0,PT_FS(%esp)
18812+4: movl $0,PT_FS(%esp)
18813+ jmp 1b
18814+5: movl $0,PT_DS(%esp)
18815+ jmp 1b
18816+6: movl $0,PT_ES(%esp)
18817 jmp 1b
18818 .popsection
18819- _ASM_EXTABLE(1b,2b)
18820+ _ASM_EXTABLE(1b,4b)
18821+ _ASM_EXTABLE(2b,5b)
18822+ _ASM_EXTABLE(3b,6b)
18823 PTGS_TO_GS_EX
18824 ENDPROC(ia32_sysenter_target)
18825
18826@@ -509,6 +702,11 @@ ENTRY(system_call)
18827 pushl_cfi %eax # save orig_eax
18828 SAVE_ALL
18829 GET_THREAD_INFO(%ebp)
18830+
18831+#ifdef CONFIG_PAX_RANDKSTACK
18832+ pax_erase_kstack
18833+#endif
18834+
18835 # system call tracing in operation / emulation
18836 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
18837 jnz syscall_trace_entry
18838@@ -527,6 +725,15 @@ syscall_exit:
18839 testl $_TIF_ALLWORK_MASK, %ecx # current->work
18840 jne syscall_exit_work
18841
18842+restore_all_pax:
18843+
18844+#ifdef CONFIG_PAX_RANDKSTACK
18845+ movl %esp, %eax
18846+ call pax_randomize_kstack
18847+#endif
18848+
18849+ pax_erase_kstack
18850+
18851 restore_all:
18852 TRACE_IRQS_IRET
18853 restore_all_notrace:
18854@@ -583,14 +790,34 @@ ldt_ss:
18855 * compensating for the offset by changing to the ESPFIX segment with
18856 * a base address that matches for the difference.
18857 */
18858-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
18859+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
18860 mov %esp, %edx /* load kernel esp */
18861 mov PT_OLDESP(%esp), %eax /* load userspace esp */
18862 mov %dx, %ax /* eax: new kernel esp */
18863 sub %eax, %edx /* offset (low word is 0) */
18864+#ifdef CONFIG_SMP
18865+ movl PER_CPU_VAR(cpu_number), %ebx
18866+ shll $PAGE_SHIFT_asm, %ebx
18867+ addl $cpu_gdt_table, %ebx
18868+#else
18869+ movl $cpu_gdt_table, %ebx
18870+#endif
18871 shr $16, %edx
18872- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
18873- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
18874+
18875+#ifdef CONFIG_PAX_KERNEXEC
18876+ mov %cr0, %esi
18877+ btr $16, %esi
18878+ mov %esi, %cr0
18879+#endif
18880+
18881+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
18882+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
18883+
18884+#ifdef CONFIG_PAX_KERNEXEC
18885+ bts $16, %esi
18886+ mov %esi, %cr0
18887+#endif
18888+
18889 pushl_cfi $__ESPFIX_SS
18890 pushl_cfi %eax /* new kernel esp */
18891 /* Disable interrupts, but do not irqtrace this section: we
18892@@ -619,20 +846,18 @@ work_resched:
18893 movl TI_flags(%ebp), %ecx
18894 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
18895 # than syscall tracing?
18896- jz restore_all
18897+ jz restore_all_pax
18898 testb $_TIF_NEED_RESCHED, %cl
18899 jnz work_resched
18900
18901 work_notifysig: # deal with pending signals and
18902 # notify-resume requests
18903+ movl %esp, %eax
18904 #ifdef CONFIG_VM86
18905 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
18906- movl %esp, %eax
18907 jne work_notifysig_v86 # returning to kernel-space or
18908 # vm86-space
18909 1:
18910-#else
18911- movl %esp, %eax
18912 #endif
18913 TRACE_IRQS_ON
18914 ENABLE_INTERRUPTS(CLBR_NONE)
18915@@ -653,7 +878,7 @@ work_notifysig_v86:
18916 movl %eax, %esp
18917 jmp 1b
18918 #endif
18919-END(work_pending)
18920+ENDPROC(work_pending)
18921
18922 # perform syscall exit tracing
18923 ALIGN
18924@@ -661,11 +886,14 @@ syscall_trace_entry:
18925 movl $-ENOSYS,PT_EAX(%esp)
18926 movl %esp, %eax
18927 call syscall_trace_enter
18928+
18929+ pax_erase_kstack
18930+
18931 /* What it returned is what we'll actually use. */
18932 cmpl $(NR_syscalls), %eax
18933 jnae syscall_call
18934 jmp syscall_exit
18935-END(syscall_trace_entry)
18936+ENDPROC(syscall_trace_entry)
18937
18938 # perform syscall exit tracing
18939 ALIGN
18940@@ -678,21 +906,25 @@ syscall_exit_work:
18941 movl %esp, %eax
18942 call syscall_trace_leave
18943 jmp resume_userspace
18944-END(syscall_exit_work)
18945+ENDPROC(syscall_exit_work)
18946 CFI_ENDPROC
18947
18948 RING0_INT_FRAME # can't unwind into user space anyway
18949 syscall_fault:
18950+#ifdef CONFIG_PAX_MEMORY_UDEREF
18951+ push %ss
18952+ pop %ds
18953+#endif
18954 ASM_CLAC
18955 GET_THREAD_INFO(%ebp)
18956 movl $-EFAULT,PT_EAX(%esp)
18957 jmp resume_userspace
18958-END(syscall_fault)
18959+ENDPROC(syscall_fault)
18960
18961 syscall_badsys:
18962 movl $-ENOSYS,PT_EAX(%esp)
18963 jmp resume_userspace
18964-END(syscall_badsys)
18965+ENDPROC(syscall_badsys)
18966 CFI_ENDPROC
18967 /*
18968 * End of kprobes section
18969@@ -753,8 +985,15 @@ PTREGSCALL1(vm86old)
18970 * normal stack and adjusts ESP with the matching offset.
18971 */
18972 /* fixup the stack */
18973- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
18974- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
18975+#ifdef CONFIG_SMP
18976+ movl PER_CPU_VAR(cpu_number), %ebx
18977+ shll $PAGE_SHIFT_asm, %ebx
18978+ addl $cpu_gdt_table, %ebx
18979+#else
18980+ movl $cpu_gdt_table, %ebx
18981+#endif
18982+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
18983+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
18984 shl $16, %eax
18985 addl %esp, %eax /* the adjusted stack pointer */
18986 pushl_cfi $__KERNEL_DS
18987@@ -807,7 +1046,7 @@ vector=vector+1
18988 .endr
18989 2: jmp common_interrupt
18990 .endr
18991-END(irq_entries_start)
18992+ENDPROC(irq_entries_start)
18993
18994 .previous
18995 END(interrupt)
18996@@ -858,7 +1097,7 @@ ENTRY(coprocessor_error)
18997 pushl_cfi $do_coprocessor_error
18998 jmp error_code
18999 CFI_ENDPROC
19000-END(coprocessor_error)
19001+ENDPROC(coprocessor_error)
19002
19003 ENTRY(simd_coprocessor_error)
19004 RING0_INT_FRAME
19005@@ -880,7 +1119,7 @@ ENTRY(simd_coprocessor_error)
19006 #endif
19007 jmp error_code
19008 CFI_ENDPROC
19009-END(simd_coprocessor_error)
19010+ENDPROC(simd_coprocessor_error)
19011
19012 ENTRY(device_not_available)
19013 RING0_INT_FRAME
19014@@ -889,18 +1128,18 @@ ENTRY(device_not_available)
19015 pushl_cfi $do_device_not_available
19016 jmp error_code
19017 CFI_ENDPROC
19018-END(device_not_available)
19019+ENDPROC(device_not_available)
19020
19021 #ifdef CONFIG_PARAVIRT
19022 ENTRY(native_iret)
19023 iret
19024 _ASM_EXTABLE(native_iret, iret_exc)
19025-END(native_iret)
19026+ENDPROC(native_iret)
19027
19028 ENTRY(native_irq_enable_sysexit)
19029 sti
19030 sysexit
19031-END(native_irq_enable_sysexit)
19032+ENDPROC(native_irq_enable_sysexit)
19033 #endif
19034
19035 ENTRY(overflow)
19036@@ -910,7 +1149,7 @@ ENTRY(overflow)
19037 pushl_cfi $do_overflow
19038 jmp error_code
19039 CFI_ENDPROC
19040-END(overflow)
19041+ENDPROC(overflow)
19042
19043 ENTRY(bounds)
19044 RING0_INT_FRAME
19045@@ -919,7 +1158,7 @@ ENTRY(bounds)
19046 pushl_cfi $do_bounds
19047 jmp error_code
19048 CFI_ENDPROC
19049-END(bounds)
19050+ENDPROC(bounds)
19051
19052 ENTRY(invalid_op)
19053 RING0_INT_FRAME
19054@@ -928,7 +1167,7 @@ ENTRY(invalid_op)
19055 pushl_cfi $do_invalid_op
19056 jmp error_code
19057 CFI_ENDPROC
19058-END(invalid_op)
19059+ENDPROC(invalid_op)
19060
19061 ENTRY(coprocessor_segment_overrun)
19062 RING0_INT_FRAME
19063@@ -937,7 +1176,7 @@ ENTRY(coprocessor_segment_overrun)
19064 pushl_cfi $do_coprocessor_segment_overrun
19065 jmp error_code
19066 CFI_ENDPROC
19067-END(coprocessor_segment_overrun)
19068+ENDPROC(coprocessor_segment_overrun)
19069
19070 ENTRY(invalid_TSS)
19071 RING0_EC_FRAME
19072@@ -945,7 +1184,7 @@ ENTRY(invalid_TSS)
19073 pushl_cfi $do_invalid_TSS
19074 jmp error_code
19075 CFI_ENDPROC
19076-END(invalid_TSS)
19077+ENDPROC(invalid_TSS)
19078
19079 ENTRY(segment_not_present)
19080 RING0_EC_FRAME
19081@@ -953,7 +1192,7 @@ ENTRY(segment_not_present)
19082 pushl_cfi $do_segment_not_present
19083 jmp error_code
19084 CFI_ENDPROC
19085-END(segment_not_present)
19086+ENDPROC(segment_not_present)
19087
19088 ENTRY(stack_segment)
19089 RING0_EC_FRAME
19090@@ -961,7 +1200,7 @@ ENTRY(stack_segment)
19091 pushl_cfi $do_stack_segment
19092 jmp error_code
19093 CFI_ENDPROC
19094-END(stack_segment)
19095+ENDPROC(stack_segment)
19096
19097 ENTRY(alignment_check)
19098 RING0_EC_FRAME
19099@@ -969,7 +1208,7 @@ ENTRY(alignment_check)
19100 pushl_cfi $do_alignment_check
19101 jmp error_code
19102 CFI_ENDPROC
19103-END(alignment_check)
19104+ENDPROC(alignment_check)
19105
19106 ENTRY(divide_error)
19107 RING0_INT_FRAME
19108@@ -978,7 +1217,7 @@ ENTRY(divide_error)
19109 pushl_cfi $do_divide_error
19110 jmp error_code
19111 CFI_ENDPROC
19112-END(divide_error)
19113+ENDPROC(divide_error)
19114
19115 #ifdef CONFIG_X86_MCE
19116 ENTRY(machine_check)
19117@@ -988,7 +1227,7 @@ ENTRY(machine_check)
19118 pushl_cfi machine_check_vector
19119 jmp error_code
19120 CFI_ENDPROC
19121-END(machine_check)
19122+ENDPROC(machine_check)
19123 #endif
19124
19125 ENTRY(spurious_interrupt_bug)
19126@@ -998,7 +1237,7 @@ ENTRY(spurious_interrupt_bug)
19127 pushl_cfi $do_spurious_interrupt_bug
19128 jmp error_code
19129 CFI_ENDPROC
19130-END(spurious_interrupt_bug)
19131+ENDPROC(spurious_interrupt_bug)
19132 /*
19133 * End of kprobes section
19134 */
19135@@ -1101,7 +1340,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
19136
19137 ENTRY(mcount)
19138 ret
19139-END(mcount)
19140+ENDPROC(mcount)
19141
19142 ENTRY(ftrace_caller)
19143 cmpl $0, function_trace_stop
19144@@ -1134,7 +1373,7 @@ ftrace_graph_call:
19145 .globl ftrace_stub
19146 ftrace_stub:
19147 ret
19148-END(ftrace_caller)
19149+ENDPROC(ftrace_caller)
19150
19151 ENTRY(ftrace_regs_caller)
19152 pushf /* push flags before compare (in cs location) */
19153@@ -1235,7 +1474,7 @@ trace:
19154 popl %ecx
19155 popl %eax
19156 jmp ftrace_stub
19157-END(mcount)
19158+ENDPROC(mcount)
19159 #endif /* CONFIG_DYNAMIC_FTRACE */
19160 #endif /* CONFIG_FUNCTION_TRACER */
19161
19162@@ -1253,7 +1492,7 @@ ENTRY(ftrace_graph_caller)
19163 popl %ecx
19164 popl %eax
19165 ret
19166-END(ftrace_graph_caller)
19167+ENDPROC(ftrace_graph_caller)
19168
19169 .globl return_to_handler
19170 return_to_handler:
19171@@ -1309,15 +1548,18 @@ error_code:
19172 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
19173 REG_TO_PTGS %ecx
19174 SET_KERNEL_GS %ecx
19175- movl $(__USER_DS), %ecx
19176+ movl $(__KERNEL_DS), %ecx
19177 movl %ecx, %ds
19178 movl %ecx, %es
19179+
19180+ pax_enter_kernel
19181+
19182 TRACE_IRQS_OFF
19183 movl %esp,%eax # pt_regs pointer
19184 call *%edi
19185 jmp ret_from_exception
19186 CFI_ENDPROC
19187-END(page_fault)
19188+ENDPROC(page_fault)
19189
19190 /*
19191 * Debug traps and NMI can happen at the one SYSENTER instruction
19192@@ -1360,7 +1602,7 @@ debug_stack_correct:
19193 call do_debug
19194 jmp ret_from_exception
19195 CFI_ENDPROC
19196-END(debug)
19197+ENDPROC(debug)
19198
19199 /*
19200 * NMI is doubly nasty. It can happen _while_ we're handling
19201@@ -1398,6 +1640,9 @@ nmi_stack_correct:
19202 xorl %edx,%edx # zero error code
19203 movl %esp,%eax # pt_regs pointer
19204 call do_nmi
19205+
19206+ pax_exit_kernel
19207+
19208 jmp restore_all_notrace
19209 CFI_ENDPROC
19210
19211@@ -1434,12 +1679,15 @@ nmi_espfix_stack:
19212 FIXUP_ESPFIX_STACK # %eax == %esp
19213 xorl %edx,%edx # zero error code
19214 call do_nmi
19215+
19216+ pax_exit_kernel
19217+
19218 RESTORE_REGS
19219 lss 12+4(%esp), %esp # back to espfix stack
19220 CFI_ADJUST_CFA_OFFSET -24
19221 jmp irq_return
19222 CFI_ENDPROC
19223-END(nmi)
19224+ENDPROC(nmi)
19225
19226 ENTRY(int3)
19227 RING0_INT_FRAME
19228@@ -1452,14 +1700,14 @@ ENTRY(int3)
19229 call do_int3
19230 jmp ret_from_exception
19231 CFI_ENDPROC
19232-END(int3)
19233+ENDPROC(int3)
19234
19235 ENTRY(general_protection)
19236 RING0_EC_FRAME
19237 pushl_cfi $do_general_protection
19238 jmp error_code
19239 CFI_ENDPROC
19240-END(general_protection)
19241+ENDPROC(general_protection)
19242
19243 #ifdef CONFIG_KVM_GUEST
19244 ENTRY(async_page_fault)
19245@@ -1468,7 +1716,7 @@ ENTRY(async_page_fault)
19246 pushl_cfi $do_async_page_fault
19247 jmp error_code
19248 CFI_ENDPROC
19249-END(async_page_fault)
19250+ENDPROC(async_page_fault)
19251 #endif
19252
19253 /*
19254diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
19255index cb3c591..7ba137c 100644
19256--- a/arch/x86/kernel/entry_64.S
19257+++ b/arch/x86/kernel/entry_64.S
19258@@ -59,6 +59,8 @@
19259 #include <asm/context_tracking.h>
19260 #include <asm/smap.h>
19261 #include <linux/err.h>
19262+#include <asm/pgtable.h>
19263+#include <asm/alternative-asm.h>
19264
19265 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
19266 #include <linux/elf-em.h>
19267@@ -80,8 +82,9 @@
19268 #ifdef CONFIG_DYNAMIC_FTRACE
19269
19270 ENTRY(function_hook)
19271+ pax_force_retaddr
19272 retq
19273-END(function_hook)
19274+ENDPROC(function_hook)
19275
19276 /* skip is set if stack has been adjusted */
19277 .macro ftrace_caller_setup skip=0
19278@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
19279 #endif
19280
19281 GLOBAL(ftrace_stub)
19282+ pax_force_retaddr
19283 retq
19284-END(ftrace_caller)
19285+ENDPROC(ftrace_caller)
19286
19287 ENTRY(ftrace_regs_caller)
19288 /* Save the current flags before compare (in SS location)*/
19289@@ -191,7 +195,7 @@ ftrace_restore_flags:
19290 popfq
19291 jmp ftrace_stub
19292
19293-END(ftrace_regs_caller)
19294+ENDPROC(ftrace_regs_caller)
19295
19296
19297 #else /* ! CONFIG_DYNAMIC_FTRACE */
19298@@ -212,6 +216,7 @@ ENTRY(function_hook)
19299 #endif
19300
19301 GLOBAL(ftrace_stub)
19302+ pax_force_retaddr
19303 retq
19304
19305 trace:
19306@@ -225,12 +230,13 @@ trace:
19307 #endif
19308 subq $MCOUNT_INSN_SIZE, %rdi
19309
19310+ pax_force_fptr ftrace_trace_function
19311 call *ftrace_trace_function
19312
19313 MCOUNT_RESTORE_FRAME
19314
19315 jmp ftrace_stub
19316-END(function_hook)
19317+ENDPROC(function_hook)
19318 #endif /* CONFIG_DYNAMIC_FTRACE */
19319 #endif /* CONFIG_FUNCTION_TRACER */
19320
19321@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
19322
19323 MCOUNT_RESTORE_FRAME
19324
19325+ pax_force_retaddr
19326 retq
19327-END(ftrace_graph_caller)
19328+ENDPROC(ftrace_graph_caller)
19329
19330 GLOBAL(return_to_handler)
19331 subq $24, %rsp
19332@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
19333 movq 8(%rsp), %rdx
19334 movq (%rsp), %rax
19335 addq $24, %rsp
19336+ pax_force_fptr %rdi
19337 jmp *%rdi
19338+ENDPROC(return_to_handler)
19339 #endif
19340
19341
19342@@ -284,6 +293,273 @@ ENTRY(native_usergs_sysret64)
19343 ENDPROC(native_usergs_sysret64)
19344 #endif /* CONFIG_PARAVIRT */
19345
19346+ .macro ljmpq sel, off
19347+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
19348+ .byte 0x48; ljmp *1234f(%rip)
19349+ .pushsection .rodata
19350+ .align 16
19351+ 1234: .quad \off; .word \sel
19352+ .popsection
19353+#else
19354+ pushq $\sel
19355+ pushq $\off
19356+ lretq
19357+#endif
19358+ .endm
19359+
19360+ .macro pax_enter_kernel
19361+ pax_set_fptr_mask
19362+#ifdef CONFIG_PAX_KERNEXEC
19363+ call pax_enter_kernel
19364+#endif
19365+ .endm
19366+
19367+ .macro pax_exit_kernel
19368+#ifdef CONFIG_PAX_KERNEXEC
19369+ call pax_exit_kernel
19370+#endif
19371+ .endm
19372+
19373+#ifdef CONFIG_PAX_KERNEXEC
19374+ENTRY(pax_enter_kernel)
19375+ pushq %rdi
19376+
19377+#ifdef CONFIG_PARAVIRT
19378+ PV_SAVE_REGS(CLBR_RDI)
19379+#endif
19380+
19381+ GET_CR0_INTO_RDI
19382+ bts $16,%rdi
19383+ jnc 3f
19384+ mov %cs,%edi
19385+ cmp $__KERNEL_CS,%edi
19386+ jnz 2f
19387+1:
19388+
19389+#ifdef CONFIG_PARAVIRT
19390+ PV_RESTORE_REGS(CLBR_RDI)
19391+#endif
19392+
19393+ popq %rdi
19394+ pax_force_retaddr
19395+ retq
19396+
19397+2: ljmpq __KERNEL_CS,1b
19398+3: ljmpq __KERNEXEC_KERNEL_CS,4f
19399+4: SET_RDI_INTO_CR0
19400+ jmp 1b
19401+ENDPROC(pax_enter_kernel)
19402+
19403+ENTRY(pax_exit_kernel)
19404+ pushq %rdi
19405+
19406+#ifdef CONFIG_PARAVIRT
19407+ PV_SAVE_REGS(CLBR_RDI)
19408+#endif
19409+
19410+ mov %cs,%rdi
19411+ cmp $__KERNEXEC_KERNEL_CS,%edi
19412+ jz 2f
19413+1:
19414+
19415+#ifdef CONFIG_PARAVIRT
19416+ PV_RESTORE_REGS(CLBR_RDI);
19417+#endif
19418+
19419+ popq %rdi
19420+ pax_force_retaddr
19421+ retq
19422+
19423+2: GET_CR0_INTO_RDI
19424+ btr $16,%rdi
19425+ ljmpq __KERNEL_CS,3f
19426+3: SET_RDI_INTO_CR0
19427+ jmp 1b
19428+ENDPROC(pax_exit_kernel)
19429+#endif
19430+
19431+ .macro pax_enter_kernel_user
19432+ pax_set_fptr_mask
19433+#ifdef CONFIG_PAX_MEMORY_UDEREF
19434+ call pax_enter_kernel_user
19435+#endif
19436+ .endm
19437+
19438+ .macro pax_exit_kernel_user
19439+#ifdef CONFIG_PAX_MEMORY_UDEREF
19440+ call pax_exit_kernel_user
19441+#endif
19442+#ifdef CONFIG_PAX_RANDKSTACK
19443+ pushq %rax
19444+ call pax_randomize_kstack
19445+ popq %rax
19446+#endif
19447+ .endm
19448+
19449+#ifdef CONFIG_PAX_MEMORY_UDEREF
19450+ENTRY(pax_enter_kernel_user)
19451+ pushq %rdi
19452+ pushq %rbx
19453+
19454+#ifdef CONFIG_PARAVIRT
19455+ PV_SAVE_REGS(CLBR_RDI)
19456+#endif
19457+
19458+ GET_CR3_INTO_RDI
19459+ mov %rdi,%rbx
19460+ add $__START_KERNEL_map,%rbx
19461+ sub phys_base(%rip),%rbx
19462+
19463+#ifdef CONFIG_PARAVIRT
19464+ pushq %rdi
19465+ cmpl $0, pv_info+PARAVIRT_enabled
19466+ jz 1f
19467+ i = 0
19468+ .rept USER_PGD_PTRS
19469+ mov i*8(%rbx),%rsi
19470+ mov $0,%sil
19471+ lea i*8(%rbx),%rdi
19472+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
19473+ i = i + 1
19474+ .endr
19475+ jmp 2f
19476+1:
19477+#endif
19478+
19479+ i = 0
19480+ .rept USER_PGD_PTRS
19481+ movb $0,i*8(%rbx)
19482+ i = i + 1
19483+ .endr
19484+
19485+#ifdef CONFIG_PARAVIRT
19486+2: popq %rdi
19487+#endif
19488+ SET_RDI_INTO_CR3
19489+
19490+#ifdef CONFIG_PAX_KERNEXEC
19491+ GET_CR0_INTO_RDI
19492+ bts $16,%rdi
19493+ SET_RDI_INTO_CR0
19494+#endif
19495+
19496+#ifdef CONFIG_PARAVIRT
19497+ PV_RESTORE_REGS(CLBR_RDI)
19498+#endif
19499+
19500+ popq %rbx
19501+ popq %rdi
19502+ pax_force_retaddr
19503+ retq
19504+ENDPROC(pax_enter_kernel_user)
19505+
19506+ENTRY(pax_exit_kernel_user)
19507+ push %rdi
19508+
19509+#ifdef CONFIG_PARAVIRT
19510+ pushq %rbx
19511+ PV_SAVE_REGS(CLBR_RDI)
19512+#endif
19513+
19514+#ifdef CONFIG_PAX_KERNEXEC
19515+ GET_CR0_INTO_RDI
19516+ btr $16,%rdi
19517+ SET_RDI_INTO_CR0
19518+#endif
19519+
19520+ GET_CR3_INTO_RDI
19521+ add $__START_KERNEL_map,%rdi
19522+ sub phys_base(%rip),%rdi
19523+
19524+#ifdef CONFIG_PARAVIRT
19525+ cmpl $0, pv_info+PARAVIRT_enabled
19526+ jz 1f
19527+ mov %rdi,%rbx
19528+ i = 0
19529+ .rept USER_PGD_PTRS
19530+ mov i*8(%rbx),%rsi
19531+ mov $0x67,%sil
19532+ lea i*8(%rbx),%rdi
19533+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
19534+ i = i + 1
19535+ .endr
19536+ jmp 2f
19537+1:
19538+#endif
19539+
19540+ i = 0
19541+ .rept USER_PGD_PTRS
19542+ movb $0x67,i*8(%rdi)
19543+ i = i + 1
19544+ .endr
19545+
19546+#ifdef CONFIG_PARAVIRT
19547+2: PV_RESTORE_REGS(CLBR_RDI)
19548+ popq %rbx
19549+#endif
19550+
19551+ popq %rdi
19552+ pax_force_retaddr
19553+ retq
19554+ENDPROC(pax_exit_kernel_user)
19555+#endif
19556+
19557+.macro pax_erase_kstack
19558+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
19559+ call pax_erase_kstack
19560+#endif
19561+.endm
19562+
19563+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
19564+ENTRY(pax_erase_kstack)
19565+ pushq %rdi
19566+ pushq %rcx
19567+ pushq %rax
19568+ pushq %r11
19569+
19570+ GET_THREAD_INFO(%r11)
19571+ mov TI_lowest_stack(%r11), %rdi
19572+ mov $-0xBEEF, %rax
19573+ std
19574+
19575+1: mov %edi, %ecx
19576+ and $THREAD_SIZE_asm - 1, %ecx
19577+ shr $3, %ecx
19578+ repne scasq
19579+ jecxz 2f
19580+
19581+ cmp $2*8, %ecx
19582+ jc 2f
19583+
19584+ mov $2*8, %ecx
19585+ repe scasq
19586+ jecxz 2f
19587+ jne 1b
19588+
19589+2: cld
19590+ mov %esp, %ecx
19591+ sub %edi, %ecx
19592+
19593+ cmp $THREAD_SIZE_asm, %rcx
19594+ jb 3f
19595+ ud2
19596+3:
19597+
19598+ shr $3, %ecx
19599+ rep stosq
19600+
19601+ mov TI_task_thread_sp0(%r11), %rdi
19602+ sub $256, %rdi
19603+ mov %rdi, TI_lowest_stack(%r11)
19604+
19605+ popq %r11
19606+ popq %rax
19607+ popq %rcx
19608+ popq %rdi
19609+ pax_force_retaddr
19610+ ret
19611+ENDPROC(pax_erase_kstack)
19612+#endif
19613
19614 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
19615 #ifdef CONFIG_TRACE_IRQFLAGS
19616@@ -375,8 +651,8 @@ ENDPROC(native_usergs_sysret64)
19617 .endm
19618
19619 .macro UNFAKE_STACK_FRAME
19620- addq $8*6, %rsp
19621- CFI_ADJUST_CFA_OFFSET -(6*8)
19622+ addq $8*6 + ARG_SKIP, %rsp
19623+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
19624 .endm
19625
19626 /*
19627@@ -463,7 +739,7 @@ ENDPROC(native_usergs_sysret64)
19628 movq %rsp, %rsi
19629
19630 leaq -RBP(%rsp),%rdi /* arg1 for handler */
19631- testl $3, CS-RBP(%rsi)
19632+ testb $3, CS-RBP(%rsi)
19633 je 1f
19634 SWAPGS
19635 /*
19636@@ -498,9 +774,10 @@ ENTRY(save_rest)
19637 movq_cfi r15, R15+16
19638 movq %r11, 8(%rsp) /* return address */
19639 FIXUP_TOP_OF_STACK %r11, 16
19640+ pax_force_retaddr
19641 ret
19642 CFI_ENDPROC
19643-END(save_rest)
19644+ENDPROC(save_rest)
19645
19646 /* save complete stack frame */
19647 .pushsection .kprobes.text, "ax"
19648@@ -529,9 +806,10 @@ ENTRY(save_paranoid)
19649 js 1f /* negative -> in kernel */
19650 SWAPGS
19651 xorl %ebx,%ebx
19652-1: ret
19653+1: pax_force_retaddr_bts
19654+ ret
19655 CFI_ENDPROC
19656-END(save_paranoid)
19657+ENDPROC(save_paranoid)
19658 .popsection
19659
19660 /*
19661@@ -553,7 +831,7 @@ ENTRY(ret_from_fork)
19662
19663 RESTORE_REST
19664
19665- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
19666+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
19667 jz 1f
19668
19669 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
19670@@ -571,7 +849,7 @@ ENTRY(ret_from_fork)
19671 RESTORE_REST
19672 jmp int_ret_from_sys_call
19673 CFI_ENDPROC
19674-END(ret_from_fork)
19675+ENDPROC(ret_from_fork)
19676
19677 /*
19678 * System call entry. Up to 6 arguments in registers are supported.
19679@@ -608,7 +886,7 @@ END(ret_from_fork)
19680 ENTRY(system_call)
19681 CFI_STARTPROC simple
19682 CFI_SIGNAL_FRAME
19683- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
19684+ CFI_DEF_CFA rsp,0
19685 CFI_REGISTER rip,rcx
19686 /*CFI_REGISTER rflags,r11*/
19687 SWAPGS_UNSAFE_STACK
19688@@ -621,16 +899,23 @@ GLOBAL(system_call_after_swapgs)
19689
19690 movq %rsp,PER_CPU_VAR(old_rsp)
19691 movq PER_CPU_VAR(kernel_stack),%rsp
19692+ SAVE_ARGS 8*6,0
19693+ pax_enter_kernel_user
19694+
19695+#ifdef CONFIG_PAX_RANDKSTACK
19696+ pax_erase_kstack
19697+#endif
19698+
19699 /*
19700 * No need to follow this irqs off/on section - it's straight
19701 * and short:
19702 */
19703 ENABLE_INTERRUPTS(CLBR_NONE)
19704- SAVE_ARGS 8,0
19705 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
19706 movq %rcx,RIP-ARGOFFSET(%rsp)
19707 CFI_REL_OFFSET rip,RIP-ARGOFFSET
19708- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
19709+ GET_THREAD_INFO(%rcx)
19710+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
19711 jnz tracesys
19712 system_call_fastpath:
19713 #if __SYSCALL_MASK == ~0
19714@@ -640,7 +925,7 @@ system_call_fastpath:
19715 cmpl $__NR_syscall_max,%eax
19716 #endif
19717 ja badsys
19718- movq %r10,%rcx
19719+ movq R10-ARGOFFSET(%rsp),%rcx
19720 call *sys_call_table(,%rax,8) # XXX: rip relative
19721 movq %rax,RAX-ARGOFFSET(%rsp)
19722 /*
19723@@ -654,10 +939,13 @@ sysret_check:
19724 LOCKDEP_SYS_EXIT
19725 DISABLE_INTERRUPTS(CLBR_NONE)
19726 TRACE_IRQS_OFF
19727- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
19728+ GET_THREAD_INFO(%rcx)
19729+ movl TI_flags(%rcx),%edx
19730 andl %edi,%edx
19731 jnz sysret_careful
19732 CFI_REMEMBER_STATE
19733+ pax_exit_kernel_user
19734+ pax_erase_kstack
19735 /*
19736 * sysretq will re-enable interrupts:
19737 */
19738@@ -709,14 +997,18 @@ badsys:
19739 * jump back to the normal fast path.
19740 */
19741 auditsys:
19742- movq %r10,%r9 /* 6th arg: 4th syscall arg */
19743+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
19744 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
19745 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
19746 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
19747 movq %rax,%rsi /* 2nd arg: syscall number */
19748 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
19749 call __audit_syscall_entry
19750+
19751+ pax_erase_kstack
19752+
19753 LOAD_ARGS 0 /* reload call-clobbered registers */
19754+ pax_set_fptr_mask
19755 jmp system_call_fastpath
19756
19757 /*
19758@@ -737,7 +1029,7 @@ sysret_audit:
19759 /* Do syscall tracing */
19760 tracesys:
19761 #ifdef CONFIG_AUDITSYSCALL
19762- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
19763+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
19764 jz auditsys
19765 #endif
19766 SAVE_REST
19767@@ -745,12 +1037,16 @@ tracesys:
19768 FIXUP_TOP_OF_STACK %rdi
19769 movq %rsp,%rdi
19770 call syscall_trace_enter
19771+
19772+ pax_erase_kstack
19773+
19774 /*
19775 * Reload arg registers from stack in case ptrace changed them.
19776 * We don't reload %rax because syscall_trace_enter() returned
19777 * the value it wants us to use in the table lookup.
19778 */
19779 LOAD_ARGS ARGOFFSET, 1
19780+ pax_set_fptr_mask
19781 RESTORE_REST
19782 #if __SYSCALL_MASK == ~0
19783 cmpq $__NR_syscall_max,%rax
19784@@ -759,7 +1055,7 @@ tracesys:
19785 cmpl $__NR_syscall_max,%eax
19786 #endif
19787 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
19788- movq %r10,%rcx /* fixup for C */
19789+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
19790 call *sys_call_table(,%rax,8)
19791 movq %rax,RAX-ARGOFFSET(%rsp)
19792 /* Use IRET because user could have changed frame */
19793@@ -780,7 +1076,9 @@ GLOBAL(int_with_check)
19794 andl %edi,%edx
19795 jnz int_careful
19796 andl $~TS_COMPAT,TI_status(%rcx)
19797- jmp retint_swapgs
19798+ pax_exit_kernel_user
19799+ pax_erase_kstack
19800+ jmp retint_swapgs_pax
19801
19802 /* Either reschedule or signal or syscall exit tracking needed. */
19803 /* First do a reschedule test. */
19804@@ -826,7 +1124,7 @@ int_restore_rest:
19805 TRACE_IRQS_OFF
19806 jmp int_with_check
19807 CFI_ENDPROC
19808-END(system_call)
19809+ENDPROC(system_call)
19810
19811 /*
19812 * Certain special system calls that need to save a complete full stack frame.
19813@@ -842,7 +1140,7 @@ ENTRY(\label)
19814 call \func
19815 jmp ptregscall_common
19816 CFI_ENDPROC
19817-END(\label)
19818+ENDPROC(\label)
19819 .endm
19820
19821 .macro FORK_LIKE func
19822@@ -856,9 +1154,10 @@ ENTRY(stub_\func)
19823 DEFAULT_FRAME 0 8 /* offset 8: return address */
19824 call sys_\func
19825 RESTORE_TOP_OF_STACK %r11, 8
19826+ pax_force_retaddr
19827 ret $REST_SKIP /* pop extended registers */
19828 CFI_ENDPROC
19829-END(stub_\func)
19830+ENDPROC(stub_\func)
19831 .endm
19832
19833 FORK_LIKE clone
19834@@ -875,9 +1174,10 @@ ENTRY(ptregscall_common)
19835 movq_cfi_restore R12+8, r12
19836 movq_cfi_restore RBP+8, rbp
19837 movq_cfi_restore RBX+8, rbx
19838+ pax_force_retaddr
19839 ret $REST_SKIP /* pop extended registers */
19840 CFI_ENDPROC
19841-END(ptregscall_common)
19842+ENDPROC(ptregscall_common)
19843
19844 ENTRY(stub_execve)
19845 CFI_STARTPROC
19846@@ -891,7 +1191,7 @@ ENTRY(stub_execve)
19847 RESTORE_REST
19848 jmp int_ret_from_sys_call
19849 CFI_ENDPROC
19850-END(stub_execve)
19851+ENDPROC(stub_execve)
19852
19853 /*
19854 * sigreturn is special because it needs to restore all registers on return.
19855@@ -909,7 +1209,7 @@ ENTRY(stub_rt_sigreturn)
19856 RESTORE_REST
19857 jmp int_ret_from_sys_call
19858 CFI_ENDPROC
19859-END(stub_rt_sigreturn)
19860+ENDPROC(stub_rt_sigreturn)
19861
19862 #ifdef CONFIG_X86_X32_ABI
19863 ENTRY(stub_x32_rt_sigreturn)
19864@@ -975,7 +1275,7 @@ vector=vector+1
19865 2: jmp common_interrupt
19866 .endr
19867 CFI_ENDPROC
19868-END(irq_entries_start)
19869+ENDPROC(irq_entries_start)
19870
19871 .previous
19872 END(interrupt)
19873@@ -995,6 +1295,16 @@ END(interrupt)
19874 subq $ORIG_RAX-RBP, %rsp
19875 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
19876 SAVE_ARGS_IRQ
19877+#ifdef CONFIG_PAX_MEMORY_UDEREF
19878+ testb $3, CS(%rdi)
19879+ jnz 1f
19880+ pax_enter_kernel
19881+ jmp 2f
19882+1: pax_enter_kernel_user
19883+2:
19884+#else
19885+ pax_enter_kernel
19886+#endif
19887 call \func
19888 .endm
19889
19890@@ -1027,7 +1337,7 @@ ret_from_intr:
19891
19892 exit_intr:
19893 GET_THREAD_INFO(%rcx)
19894- testl $3,CS-ARGOFFSET(%rsp)
19895+ testb $3,CS-ARGOFFSET(%rsp)
19896 je retint_kernel
19897
19898 /* Interrupt came from user space */
19899@@ -1049,12 +1359,16 @@ retint_swapgs: /* return to user-space */
19900 * The iretq could re-enable interrupts:
19901 */
19902 DISABLE_INTERRUPTS(CLBR_ANY)
19903+ pax_exit_kernel_user
19904+retint_swapgs_pax:
19905 TRACE_IRQS_IRETQ
19906 SWAPGS
19907 jmp restore_args
19908
19909 retint_restore_args: /* return to kernel space */
19910 DISABLE_INTERRUPTS(CLBR_ANY)
19911+ pax_exit_kernel
19912+ pax_force_retaddr (RIP-ARGOFFSET)
19913 /*
19914 * The iretq could re-enable interrupts:
19915 */
19916@@ -1137,7 +1451,7 @@ ENTRY(retint_kernel)
19917 #endif
19918
19919 CFI_ENDPROC
19920-END(common_interrupt)
19921+ENDPROC(common_interrupt)
19922 /*
19923 * End of kprobes section
19924 */
19925@@ -1155,7 +1469,7 @@ ENTRY(\sym)
19926 interrupt \do_sym
19927 jmp ret_from_intr
19928 CFI_ENDPROC
19929-END(\sym)
19930+ENDPROC(\sym)
19931 .endm
19932
19933 #ifdef CONFIG_SMP
19934@@ -1211,12 +1525,22 @@ ENTRY(\sym)
19935 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19936 call error_entry
19937 DEFAULT_FRAME 0
19938+#ifdef CONFIG_PAX_MEMORY_UDEREF
19939+ testb $3, CS(%rsp)
19940+ jnz 1f
19941+ pax_enter_kernel
19942+ jmp 2f
19943+1: pax_enter_kernel_user
19944+2:
19945+#else
19946+ pax_enter_kernel
19947+#endif
19948 movq %rsp,%rdi /* pt_regs pointer */
19949 xorl %esi,%esi /* no error code */
19950 call \do_sym
19951 jmp error_exit /* %ebx: no swapgs flag */
19952 CFI_ENDPROC
19953-END(\sym)
19954+ENDPROC(\sym)
19955 .endm
19956
19957 .macro paranoidzeroentry sym do_sym
19958@@ -1229,15 +1553,25 @@ ENTRY(\sym)
19959 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19960 call save_paranoid
19961 TRACE_IRQS_OFF
19962+#ifdef CONFIG_PAX_MEMORY_UDEREF
19963+ testb $3, CS(%rsp)
19964+ jnz 1f
19965+ pax_enter_kernel
19966+ jmp 2f
19967+1: pax_enter_kernel_user
19968+2:
19969+#else
19970+ pax_enter_kernel
19971+#endif
19972 movq %rsp,%rdi /* pt_regs pointer */
19973 xorl %esi,%esi /* no error code */
19974 call \do_sym
19975 jmp paranoid_exit /* %ebx: no swapgs flag */
19976 CFI_ENDPROC
19977-END(\sym)
19978+ENDPROC(\sym)
19979 .endm
19980
19981-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
19982+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
19983 .macro paranoidzeroentry_ist sym do_sym ist
19984 ENTRY(\sym)
19985 INTR_FRAME
19986@@ -1248,14 +1582,30 @@ ENTRY(\sym)
19987 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19988 call save_paranoid
19989 TRACE_IRQS_OFF_DEBUG
19990+#ifdef CONFIG_PAX_MEMORY_UDEREF
19991+ testb $3, CS(%rsp)
19992+ jnz 1f
19993+ pax_enter_kernel
19994+ jmp 2f
19995+1: pax_enter_kernel_user
19996+2:
19997+#else
19998+ pax_enter_kernel
19999+#endif
20000 movq %rsp,%rdi /* pt_regs pointer */
20001 xorl %esi,%esi /* no error code */
20002+#ifdef CONFIG_SMP
20003+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
20004+ lea init_tss(%r12), %r12
20005+#else
20006+ lea init_tss(%rip), %r12
20007+#endif
20008 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
20009 call \do_sym
20010 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
20011 jmp paranoid_exit /* %ebx: no swapgs flag */
20012 CFI_ENDPROC
20013-END(\sym)
20014+ENDPROC(\sym)
20015 .endm
20016
20017 .macro errorentry sym do_sym
20018@@ -1267,13 +1617,23 @@ ENTRY(\sym)
20019 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
20020 call error_entry
20021 DEFAULT_FRAME 0
20022+#ifdef CONFIG_PAX_MEMORY_UDEREF
20023+ testb $3, CS(%rsp)
20024+ jnz 1f
20025+ pax_enter_kernel
20026+ jmp 2f
20027+1: pax_enter_kernel_user
20028+2:
20029+#else
20030+ pax_enter_kernel
20031+#endif
20032 movq %rsp,%rdi /* pt_regs pointer */
20033 movq ORIG_RAX(%rsp),%rsi /* get error code */
20034 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
20035 call \do_sym
20036 jmp error_exit /* %ebx: no swapgs flag */
20037 CFI_ENDPROC
20038-END(\sym)
20039+ENDPROC(\sym)
20040 .endm
20041
20042 /* error code is on the stack already */
20043@@ -1287,13 +1647,23 @@ ENTRY(\sym)
20044 call save_paranoid
20045 DEFAULT_FRAME 0
20046 TRACE_IRQS_OFF
20047+#ifdef CONFIG_PAX_MEMORY_UDEREF
20048+ testb $3, CS(%rsp)
20049+ jnz 1f
20050+ pax_enter_kernel
20051+ jmp 2f
20052+1: pax_enter_kernel_user
20053+2:
20054+#else
20055+ pax_enter_kernel
20056+#endif
20057 movq %rsp,%rdi /* pt_regs pointer */
20058 movq ORIG_RAX(%rsp),%rsi /* get error code */
20059 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
20060 call \do_sym
20061 jmp paranoid_exit /* %ebx: no swapgs flag */
20062 CFI_ENDPROC
20063-END(\sym)
20064+ENDPROC(\sym)
20065 .endm
20066
20067 zeroentry divide_error do_divide_error
20068@@ -1323,9 +1693,10 @@ gs_change:
20069 2: mfence /* workaround */
20070 SWAPGS
20071 popfq_cfi
20072+ pax_force_retaddr
20073 ret
20074 CFI_ENDPROC
20075-END(native_load_gs_index)
20076+ENDPROC(native_load_gs_index)
20077
20078 _ASM_EXTABLE(gs_change,bad_gs)
20079 .section .fixup,"ax"
20080@@ -1353,9 +1724,10 @@ ENTRY(call_softirq)
20081 CFI_DEF_CFA_REGISTER rsp
20082 CFI_ADJUST_CFA_OFFSET -8
20083 decl PER_CPU_VAR(irq_count)
20084+ pax_force_retaddr
20085 ret
20086 CFI_ENDPROC
20087-END(call_softirq)
20088+ENDPROC(call_softirq)
20089
20090 #ifdef CONFIG_XEN
20091 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
20092@@ -1393,7 +1765,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
20093 decl PER_CPU_VAR(irq_count)
20094 jmp error_exit
20095 CFI_ENDPROC
20096-END(xen_do_hypervisor_callback)
20097+ENDPROC(xen_do_hypervisor_callback)
20098
20099 /*
20100 * Hypervisor uses this for application faults while it executes.
20101@@ -1452,7 +1824,7 @@ ENTRY(xen_failsafe_callback)
20102 SAVE_ALL
20103 jmp error_exit
20104 CFI_ENDPROC
20105-END(xen_failsafe_callback)
20106+ENDPROC(xen_failsafe_callback)
20107
20108 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
20109 xen_hvm_callback_vector xen_evtchn_do_upcall
20110@@ -1501,16 +1873,31 @@ ENTRY(paranoid_exit)
20111 TRACE_IRQS_OFF_DEBUG
20112 testl %ebx,%ebx /* swapgs needed? */
20113 jnz paranoid_restore
20114- testl $3,CS(%rsp)
20115+ testb $3,CS(%rsp)
20116 jnz paranoid_userspace
20117+#ifdef CONFIG_PAX_MEMORY_UDEREF
20118+ pax_exit_kernel
20119+ TRACE_IRQS_IRETQ 0
20120+ SWAPGS_UNSAFE_STACK
20121+ RESTORE_ALL 8
20122+ pax_force_retaddr_bts
20123+ jmp irq_return
20124+#endif
20125 paranoid_swapgs:
20126+#ifdef CONFIG_PAX_MEMORY_UDEREF
20127+ pax_exit_kernel_user
20128+#else
20129+ pax_exit_kernel
20130+#endif
20131 TRACE_IRQS_IRETQ 0
20132 SWAPGS_UNSAFE_STACK
20133 RESTORE_ALL 8
20134 jmp irq_return
20135 paranoid_restore:
20136+ pax_exit_kernel
20137 TRACE_IRQS_IRETQ_DEBUG 0
20138 RESTORE_ALL 8
20139+ pax_force_retaddr_bts
20140 jmp irq_return
20141 paranoid_userspace:
20142 GET_THREAD_INFO(%rcx)
20143@@ -1539,7 +1926,7 @@ paranoid_schedule:
20144 TRACE_IRQS_OFF
20145 jmp paranoid_userspace
20146 CFI_ENDPROC
20147-END(paranoid_exit)
20148+ENDPROC(paranoid_exit)
20149
20150 /*
20151 * Exception entry point. This expects an error code/orig_rax on the stack.
20152@@ -1566,12 +1953,13 @@ ENTRY(error_entry)
20153 movq_cfi r14, R14+8
20154 movq_cfi r15, R15+8
20155 xorl %ebx,%ebx
20156- testl $3,CS+8(%rsp)
20157+ testb $3,CS+8(%rsp)
20158 je error_kernelspace
20159 error_swapgs:
20160 SWAPGS
20161 error_sti:
20162 TRACE_IRQS_OFF
20163+ pax_force_retaddr_bts
20164 ret
20165
20166 /*
20167@@ -1598,7 +1986,7 @@ bstep_iret:
20168 movq %rcx,RIP+8(%rsp)
20169 jmp error_swapgs
20170 CFI_ENDPROC
20171-END(error_entry)
20172+ENDPROC(error_entry)
20173
20174
20175 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
20176@@ -1618,7 +2006,7 @@ ENTRY(error_exit)
20177 jnz retint_careful
20178 jmp retint_swapgs
20179 CFI_ENDPROC
20180-END(error_exit)
20181+ENDPROC(error_exit)
20182
20183 /*
20184 * Test if a given stack is an NMI stack or not.
20185@@ -1676,9 +2064,11 @@ ENTRY(nmi)
20186 * If %cs was not the kernel segment, then the NMI triggered in user
20187 * space, which means it is definitely not nested.
20188 */
20189+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
20190+ je 1f
20191 cmpl $__KERNEL_CS, 16(%rsp)
20192 jne first_nmi
20193-
20194+1:
20195 /*
20196 * Check the special variable on the stack to see if NMIs are
20197 * executing.
20198@@ -1712,14 +2102,13 @@ nested_nmi:
20199
20200 1:
20201 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
20202- leaq -1*8(%rsp), %rdx
20203- movq %rdx, %rsp
20204+ subq $8, %rsp
20205 CFI_ADJUST_CFA_OFFSET 1*8
20206 leaq -10*8(%rsp), %rdx
20207 pushq_cfi $__KERNEL_DS
20208 pushq_cfi %rdx
20209 pushfq_cfi
20210- pushq_cfi $__KERNEL_CS
20211+ pushq_cfi 6*8(%rsp)
20212 pushq_cfi $repeat_nmi
20213
20214 /* Put stack back */
20215@@ -1731,6 +2120,7 @@ nested_nmi_out:
20216 CFI_RESTORE rdx
20217
20218 /* No need to check faults here */
20219+ pax_force_retaddr_bts
20220 INTERRUPT_RETURN
20221
20222 CFI_RESTORE_STATE
20223@@ -1847,6 +2237,17 @@ end_repeat_nmi:
20224 */
20225 movq %cr2, %r12
20226
20227+#ifdef CONFIG_PAX_MEMORY_UDEREF
20228+ testb $3, CS(%rsp)
20229+ jnz 1f
20230+ pax_enter_kernel
20231+ jmp 2f
20232+1: pax_enter_kernel_user
20233+2:
20234+#else
20235+ pax_enter_kernel
20236+#endif
20237+
20238 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
20239 movq %rsp,%rdi
20240 movq $-1,%rsi
20241@@ -1862,23 +2263,34 @@ end_repeat_nmi:
20242 testl %ebx,%ebx /* swapgs needed? */
20243 jnz nmi_restore
20244 nmi_swapgs:
20245+#ifdef CONFIG_PAX_MEMORY_UDEREF
20246+ pax_exit_kernel_user
20247+#else
20248+ pax_exit_kernel
20249+#endif
20250 SWAPGS_UNSAFE_STACK
20251+ RESTORE_ALL 6*8
20252+ /* Clear the NMI executing stack variable */
20253+ movq $0, 5*8(%rsp)
20254+ jmp irq_return
20255 nmi_restore:
20256+ pax_exit_kernel
20257 /* Pop the extra iret frame at once */
20258 RESTORE_ALL 6*8
20259+ pax_force_retaddr_bts
20260
20261 /* Clear the NMI executing stack variable */
20262 movq $0, 5*8(%rsp)
20263 jmp irq_return
20264 CFI_ENDPROC
20265-END(nmi)
20266+ENDPROC(nmi)
20267
20268 ENTRY(ignore_sysret)
20269 CFI_STARTPROC
20270 mov $-ENOSYS,%eax
20271 sysret
20272 CFI_ENDPROC
20273-END(ignore_sysret)
20274+ENDPROC(ignore_sysret)
20275
20276 /*
20277 * End of kprobes section
20278diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
20279index 1d41402..af9a46a 100644
20280--- a/arch/x86/kernel/ftrace.c
20281+++ b/arch/x86/kernel/ftrace.c
20282@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
20283 {
20284 unsigned char replaced[MCOUNT_INSN_SIZE];
20285
20286+ ip = ktla_ktva(ip);
20287+
20288 /*
20289 * Note: Due to modules and __init, code can
20290 * disappear and change, we need to protect against faulting
20291@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
20292 unsigned char old[MCOUNT_INSN_SIZE], *new;
20293 int ret;
20294
20295- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
20296+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
20297 new = ftrace_call_replace(ip, (unsigned long)func);
20298
20299 /* See comment above by declaration of modifying_ftrace_code */
20300@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
20301 /* Also update the regs callback function */
20302 if (!ret) {
20303 ip = (unsigned long)(&ftrace_regs_call);
20304- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
20305+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
20306 new = ftrace_call_replace(ip, (unsigned long)func);
20307 ret = ftrace_modify_code(ip, old, new);
20308 }
20309@@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
20310 * kernel identity mapping to modify code.
20311 */
20312 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
20313- ip = (unsigned long)__va(__pa(ip));
20314+ ip = (unsigned long)__va(__pa(ktla_ktva(ip)));
20315
20316 return probe_kernel_write((void *)ip, val, size);
20317 }
20318@@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
20319 unsigned char replaced[MCOUNT_INSN_SIZE];
20320 unsigned char brk = BREAKPOINT_INSTRUCTION;
20321
20322- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
20323+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
20324 return -EFAULT;
20325
20326 /* Make sure it is what we expect it to be */
20327@@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
20328 return ret;
20329
20330 fail_update:
20331- probe_kernel_write((void *)ip, &old_code[0], 1);
20332+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
20333 goto out;
20334 }
20335
20336@@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
20337 {
20338 unsigned char code[MCOUNT_INSN_SIZE];
20339
20340+ ip = ktla_ktva(ip);
20341+
20342 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
20343 return -EFAULT;
20344
20345diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
20346index c18f59d..9c0c9f6 100644
20347--- a/arch/x86/kernel/head32.c
20348+++ b/arch/x86/kernel/head32.c
20349@@ -18,6 +18,7 @@
20350 #include <asm/io_apic.h>
20351 #include <asm/bios_ebda.h>
20352 #include <asm/tlbflush.h>
20353+#include <asm/boot.h>
20354
20355 static void __init i386_default_early_setup(void)
20356 {
20357@@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
20358
20359 void __init i386_start_kernel(void)
20360 {
20361- memblock_reserve(__pa_symbol(&_text),
20362- __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
20363+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
20364
20365 #ifdef CONFIG_BLK_DEV_INITRD
20366 /* Reserve INITRD */
20367diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
20368index c8932c7..d56b622 100644
20369--- a/arch/x86/kernel/head_32.S
20370+++ b/arch/x86/kernel/head_32.S
20371@@ -26,6 +26,12 @@
20372 /* Physical address */
20373 #define pa(X) ((X) - __PAGE_OFFSET)
20374
20375+#ifdef CONFIG_PAX_KERNEXEC
20376+#define ta(X) (X)
20377+#else
20378+#define ta(X) ((X) - __PAGE_OFFSET)
20379+#endif
20380+
20381 /*
20382 * References to members of the new_cpu_data structure.
20383 */
20384@@ -55,11 +61,7 @@
20385 * and small than max_low_pfn, otherwise will waste some page table entries
20386 */
20387
20388-#if PTRS_PER_PMD > 1
20389-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
20390-#else
20391-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
20392-#endif
20393+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
20394
20395 /* Number of possible pages in the lowmem region */
20396 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
20397@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
20398 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
20399
20400 /*
20401+ * Real beginning of normal "text" segment
20402+ */
20403+ENTRY(stext)
20404+ENTRY(_stext)
20405+
20406+/*
20407 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
20408 * %esi points to the real-mode code as a 32-bit pointer.
20409 * CS and DS must be 4 GB flat segments, but we don't depend on
20410@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
20411 * can.
20412 */
20413 __HEAD
20414+
20415+#ifdef CONFIG_PAX_KERNEXEC
20416+ jmp startup_32
20417+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
20418+.fill PAGE_SIZE-5,1,0xcc
20419+#endif
20420+
20421 ENTRY(startup_32)
20422 movl pa(stack_start),%ecx
20423
20424@@ -106,6 +121,59 @@ ENTRY(startup_32)
20425 2:
20426 leal -__PAGE_OFFSET(%ecx),%esp
20427
20428+#ifdef CONFIG_SMP
20429+ movl $pa(cpu_gdt_table),%edi
20430+ movl $__per_cpu_load,%eax
20431+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
20432+ rorl $16,%eax
20433+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
20434+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
20435+ movl $__per_cpu_end - 1,%eax
20436+ subl $__per_cpu_start,%eax
20437+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
20438+#endif
20439+
20440+#ifdef CONFIG_PAX_MEMORY_UDEREF
20441+ movl $NR_CPUS,%ecx
20442+ movl $pa(cpu_gdt_table),%edi
20443+1:
20444+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
20445+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
20446+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
20447+ addl $PAGE_SIZE_asm,%edi
20448+ loop 1b
20449+#endif
20450+
20451+#ifdef CONFIG_PAX_KERNEXEC
20452+ movl $pa(boot_gdt),%edi
20453+ movl $__LOAD_PHYSICAL_ADDR,%eax
20454+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
20455+ rorl $16,%eax
20456+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
20457+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
20458+ rorl $16,%eax
20459+
20460+ ljmp $(__BOOT_CS),$1f
20461+1:
20462+
20463+ movl $NR_CPUS,%ecx
20464+ movl $pa(cpu_gdt_table),%edi
20465+ addl $__PAGE_OFFSET,%eax
20466+1:
20467+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
20468+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
20469+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
20470+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
20471+ rorl $16,%eax
20472+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
20473+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
20474+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
20475+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
20476+ rorl $16,%eax
20477+ addl $PAGE_SIZE_asm,%edi
20478+ loop 1b
20479+#endif
20480+
20481 /*
20482 * Clear BSS first so that there are no surprises...
20483 */
20484@@ -196,8 +264,11 @@ ENTRY(startup_32)
20485 movl %eax, pa(max_pfn_mapped)
20486
20487 /* Do early initialization of the fixmap area */
20488- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
20489- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
20490+#ifdef CONFIG_COMPAT_VDSO
20491+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
20492+#else
20493+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
20494+#endif
20495 #else /* Not PAE */
20496
20497 page_pde_offset = (__PAGE_OFFSET >> 20);
20498@@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
20499 movl %eax, pa(max_pfn_mapped)
20500
20501 /* Do early initialization of the fixmap area */
20502- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
20503- movl %eax,pa(initial_page_table+0xffc)
20504+#ifdef CONFIG_COMPAT_VDSO
20505+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
20506+#else
20507+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
20508+#endif
20509 #endif
20510
20511 #ifdef CONFIG_PARAVIRT
20512@@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
20513 cmpl $num_subarch_entries, %eax
20514 jae bad_subarch
20515
20516- movl pa(subarch_entries)(,%eax,4), %eax
20517- subl $__PAGE_OFFSET, %eax
20518- jmp *%eax
20519+ jmp *pa(subarch_entries)(,%eax,4)
20520
20521 bad_subarch:
20522 WEAK(lguest_entry)
20523@@ -256,10 +328,10 @@ WEAK(xen_entry)
20524 __INITDATA
20525
20526 subarch_entries:
20527- .long default_entry /* normal x86/PC */
20528- .long lguest_entry /* lguest hypervisor */
20529- .long xen_entry /* Xen hypervisor */
20530- .long default_entry /* Moorestown MID */
20531+ .long ta(default_entry) /* normal x86/PC */
20532+ .long ta(lguest_entry) /* lguest hypervisor */
20533+ .long ta(xen_entry) /* Xen hypervisor */
20534+ .long ta(default_entry) /* Moorestown MID */
20535 num_subarch_entries = (. - subarch_entries) / 4
20536 .previous
20537 #else
20538@@ -335,6 +407,7 @@ default_entry:
20539 movl pa(mmu_cr4_features),%eax
20540 movl %eax,%cr4
20541
20542+#ifdef CONFIG_X86_PAE
20543 testb $X86_CR4_PAE, %al # check if PAE is enabled
20544 jz 6f
20545
20546@@ -363,6 +436,9 @@ default_entry:
20547 /* Make changes effective */
20548 wrmsr
20549
20550+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
20551+#endif
20552+
20553 6:
20554
20555 /*
20556@@ -460,14 +536,20 @@ is386: movl $2,%ecx # set MP
20557 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
20558 movl %eax,%ss # after changing gdt.
20559
20560- movl $(__USER_DS),%eax # DS/ES contains default USER segment
20561+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
20562 movl %eax,%ds
20563 movl %eax,%es
20564
20565 movl $(__KERNEL_PERCPU), %eax
20566 movl %eax,%fs # set this cpu's percpu
20567
20568+#ifdef CONFIG_CC_STACKPROTECTOR
20569 movl $(__KERNEL_STACK_CANARY),%eax
20570+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
20571+ movl $(__USER_DS),%eax
20572+#else
20573+ xorl %eax,%eax
20574+#endif
20575 movl %eax,%gs
20576
20577 xorl %eax,%eax # Clear LDT
20578@@ -544,8 +626,11 @@ setup_once:
20579 * relocation. Manually set base address in stack canary
20580 * segment descriptor.
20581 */
20582- movl $gdt_page,%eax
20583+ movl $cpu_gdt_table,%eax
20584 movl $stack_canary,%ecx
20585+#ifdef CONFIG_SMP
20586+ addl $__per_cpu_load,%ecx
20587+#endif
20588 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
20589 shrl $16, %ecx
20590 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
20591@@ -576,7 +661,7 @@ ENDPROC(early_idt_handlers)
20592 /* This is global to keep gas from relaxing the jumps */
20593 ENTRY(early_idt_handler)
20594 cld
20595- cmpl $2,%ss:early_recursion_flag
20596+ cmpl $1,%ss:early_recursion_flag
20597 je hlt_loop
20598 incl %ss:early_recursion_flag
20599
20600@@ -614,8 +699,8 @@ ENTRY(early_idt_handler)
20601 pushl (20+6*4)(%esp) /* trapno */
20602 pushl $fault_msg
20603 call printk
20604-#endif
20605 call dump_stack
20606+#endif
20607 hlt_loop:
20608 hlt
20609 jmp hlt_loop
20610@@ -634,8 +719,11 @@ ENDPROC(early_idt_handler)
20611 /* This is the default interrupt "handler" :-) */
20612 ALIGN
20613 ignore_int:
20614- cld
20615 #ifdef CONFIG_PRINTK
20616+ cmpl $2,%ss:early_recursion_flag
20617+ je hlt_loop
20618+ incl %ss:early_recursion_flag
20619+ cld
20620 pushl %eax
20621 pushl %ecx
20622 pushl %edx
20623@@ -644,9 +732,6 @@ ignore_int:
20624 movl $(__KERNEL_DS),%eax
20625 movl %eax,%ds
20626 movl %eax,%es
20627- cmpl $2,early_recursion_flag
20628- je hlt_loop
20629- incl early_recursion_flag
20630 pushl 16(%esp)
20631 pushl 24(%esp)
20632 pushl 32(%esp)
20633@@ -680,29 +765,43 @@ ENTRY(setup_once_ref)
20634 /*
20635 * BSS section
20636 */
20637-__PAGE_ALIGNED_BSS
20638- .align PAGE_SIZE
20639 #ifdef CONFIG_X86_PAE
20640+.section .initial_pg_pmd,"a",@progbits
20641 initial_pg_pmd:
20642 .fill 1024*KPMDS,4,0
20643 #else
20644+.section .initial_page_table,"a",@progbits
20645 ENTRY(initial_page_table)
20646 .fill 1024,4,0
20647 #endif
20648+.section .initial_pg_fixmap,"a",@progbits
20649 initial_pg_fixmap:
20650 .fill 1024,4,0
20651+.section .empty_zero_page,"a",@progbits
20652 ENTRY(empty_zero_page)
20653 .fill 4096,1,0
20654+.section .swapper_pg_dir,"a",@progbits
20655 ENTRY(swapper_pg_dir)
20656+#ifdef CONFIG_X86_PAE
20657+ .fill 4,8,0
20658+#else
20659 .fill 1024,4,0
20660+#endif
20661+
20662+/*
20663+ * The IDT has to be page-aligned to simplify the Pentium
20664+ * F0 0F bug workaround.. We have a special link segment
20665+ * for this.
20666+ */
20667+.section .idt,"a",@progbits
20668+ENTRY(idt_table)
20669+ .fill 256,8,0
20670
20671 /*
20672 * This starts the data section.
20673 */
20674 #ifdef CONFIG_X86_PAE
20675-__PAGE_ALIGNED_DATA
20676- /* Page-aligned for the benefit of paravirt? */
20677- .align PAGE_SIZE
20678+.section .initial_page_table,"a",@progbits
20679 ENTRY(initial_page_table)
20680 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
20681 # if KPMDS == 3
20682@@ -721,12 +820,20 @@ ENTRY(initial_page_table)
20683 # error "Kernel PMDs should be 1, 2 or 3"
20684 # endif
20685 .align PAGE_SIZE /* needs to be page-sized too */
20686+
20687+#ifdef CONFIG_PAX_PER_CPU_PGD
20688+ENTRY(cpu_pgd)
20689+ .rept NR_CPUS
20690+ .fill 4,8,0
20691+ .endr
20692+#endif
20693+
20694 #endif
20695
20696 .data
20697 .balign 4
20698 ENTRY(stack_start)
20699- .long init_thread_union+THREAD_SIZE
20700+ .long init_thread_union+THREAD_SIZE-8
20701
20702 __INITRODATA
20703 int_msg:
20704@@ -754,7 +861,7 @@ fault_msg:
20705 * segment size, and 32-bit linear address value:
20706 */
20707
20708- .data
20709+.section .rodata,"a",@progbits
20710 .globl boot_gdt_descr
20711 .globl idt_descr
20712
20713@@ -763,7 +870,7 @@ fault_msg:
20714 .word 0 # 32 bit align gdt_desc.address
20715 boot_gdt_descr:
20716 .word __BOOT_DS+7
20717- .long boot_gdt - __PAGE_OFFSET
20718+ .long pa(boot_gdt)
20719
20720 .word 0 # 32-bit align idt_desc.address
20721 idt_descr:
20722@@ -774,7 +881,7 @@ idt_descr:
20723 .word 0 # 32 bit align gdt_desc.address
20724 ENTRY(early_gdt_descr)
20725 .word GDT_ENTRIES*8-1
20726- .long gdt_page /* Overwritten for secondary CPUs */
20727+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
20728
20729 /*
20730 * The boot_gdt must mirror the equivalent in setup.S and is
20731@@ -783,5 +890,65 @@ ENTRY(early_gdt_descr)
20732 .align L1_CACHE_BYTES
20733 ENTRY(boot_gdt)
20734 .fill GDT_ENTRY_BOOT_CS,8,0
20735- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
20736- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
20737+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
20738+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
20739+
20740+ .align PAGE_SIZE_asm
20741+ENTRY(cpu_gdt_table)
20742+ .rept NR_CPUS
20743+ .quad 0x0000000000000000 /* NULL descriptor */
20744+ .quad 0x0000000000000000 /* 0x0b reserved */
20745+ .quad 0x0000000000000000 /* 0x13 reserved */
20746+ .quad 0x0000000000000000 /* 0x1b reserved */
20747+
20748+#ifdef CONFIG_PAX_KERNEXEC
20749+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
20750+#else
20751+ .quad 0x0000000000000000 /* 0x20 unused */
20752+#endif
20753+
20754+ .quad 0x0000000000000000 /* 0x28 unused */
20755+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
20756+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
20757+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
20758+ .quad 0x0000000000000000 /* 0x4b reserved */
20759+ .quad 0x0000000000000000 /* 0x53 reserved */
20760+ .quad 0x0000000000000000 /* 0x5b reserved */
20761+
20762+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
20763+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
20764+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
20765+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
20766+
20767+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
20768+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
20769+
20770+ /*
20771+ * Segments used for calling PnP BIOS have byte granularity.
20772+ * The code segments and data segments have fixed 64k limits,
20773+ * the transfer segment sizes are set at run time.
20774+ */
20775+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
20776+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
20777+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
20778+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
20779+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
20780+
20781+ /*
20782+ * The APM segments have byte granularity and their bases
20783+ * are set at run time. All have 64k limits.
20784+ */
20785+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
20786+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
20787+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
20788+
20789+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
20790+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
20791+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
20792+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
20793+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
20794+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
20795+
20796+ /* Be sure this is zeroed to avoid false validations in Xen */
20797+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
20798+ .endr
20799diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
20800index 980053c..74d3b44 100644
20801--- a/arch/x86/kernel/head_64.S
20802+++ b/arch/x86/kernel/head_64.S
20803@@ -20,6 +20,8 @@
20804 #include <asm/processor-flags.h>
20805 #include <asm/percpu.h>
20806 #include <asm/nops.h>
20807+#include <asm/cpufeature.h>
20808+#include <asm/alternative-asm.h>
20809
20810 #ifdef CONFIG_PARAVIRT
20811 #include <asm/asm-offsets.h>
20812@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
20813 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
20814 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
20815 L3_START_KERNEL = pud_index(__START_KERNEL_map)
20816+L4_VMALLOC_START = pgd_index(VMALLOC_START)
20817+L3_VMALLOC_START = pud_index(VMALLOC_START)
20818+L4_VMALLOC_END = pgd_index(VMALLOC_END)
20819+L3_VMALLOC_END = pud_index(VMALLOC_END)
20820+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
20821+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
20822
20823 .text
20824 __HEAD
20825@@ -88,35 +96,23 @@ startup_64:
20826 */
20827 addq %rbp, init_level4_pgt + 0(%rip)
20828 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
20829+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
20830+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
20831+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
20832 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
20833
20834 addq %rbp, level3_ident_pgt + 0(%rip)
20835+#ifndef CONFIG_XEN
20836+ addq %rbp, level3_ident_pgt + 8(%rip)
20837+#endif
20838
20839- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
20840- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
20841+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
20842+
20843+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
20844+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
20845
20846 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
20847-
20848- /* Add an Identity mapping if I am above 1G */
20849- leaq _text(%rip), %rdi
20850- andq $PMD_PAGE_MASK, %rdi
20851-
20852- movq %rdi, %rax
20853- shrq $PUD_SHIFT, %rax
20854- andq $(PTRS_PER_PUD - 1), %rax
20855- jz ident_complete
20856-
20857- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
20858- leaq level3_ident_pgt(%rip), %rbx
20859- movq %rdx, 0(%rbx, %rax, 8)
20860-
20861- movq %rdi, %rax
20862- shrq $PMD_SHIFT, %rax
20863- andq $(PTRS_PER_PMD - 1), %rax
20864- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
20865- leaq level2_spare_pgt(%rip), %rbx
20866- movq %rdx, 0(%rbx, %rax, 8)
20867-ident_complete:
20868+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
20869
20870 /*
20871 * Fixup the kernel text+data virtual addresses. Note that
20872@@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
20873 * after the boot processor executes this code.
20874 */
20875
20876- /* Enable PAE mode and PGE */
20877- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
20878+ /* Enable PAE mode and PSE/PGE */
20879+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
20880 movq %rax, %cr4
20881
20882 /* Setup early boot stage 4 level pagetables. */
20883@@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
20884 movl $MSR_EFER, %ecx
20885 rdmsr
20886 btsl $_EFER_SCE, %eax /* Enable System Call */
20887- btl $20,%edi /* No Execute supported? */
20888+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
20889 jnc 1f
20890 btsl $_EFER_NX, %eax
20891+ leaq init_level4_pgt(%rip), %rdi
20892+#ifndef CONFIG_EFI
20893+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
20894+#endif
20895+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
20896+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
20897+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
20898+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
20899 1: wrmsr /* Make changes effective */
20900
20901 /* Setup cr0 */
20902@@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
20903 * jump. In addition we need to ensure %cs is set so we make this
20904 * a far return.
20905 */
20906+ pax_set_fptr_mask
20907 movq initial_code(%rip),%rax
20908 pushq $0 # fake return address to stop unwinder
20909 pushq $__KERNEL_CS # set correct cs
20910@@ -284,7 +289,7 @@ ENDPROC(start_cpu0)
20911 bad_address:
20912 jmp bad_address
20913
20914- .section ".init.text","ax"
20915+ __INIT
20916 .globl early_idt_handlers
20917 early_idt_handlers:
20918 # 104(%rsp) %rflags
20919@@ -343,7 +348,7 @@ ENTRY(early_idt_handler)
20920 call dump_stack
20921 #ifdef CONFIG_KALLSYMS
20922 leaq early_idt_ripmsg(%rip),%rdi
20923- movq 40(%rsp),%rsi # %rip again
20924+ movq 88(%rsp),%rsi # %rip again
20925 call __print_symbol
20926 #endif
20927 #endif /* EARLY_PRINTK */
20928@@ -363,11 +368,15 @@ ENTRY(early_idt_handler)
20929 addq $16,%rsp # drop vector number and error code
20930 decl early_recursion_flag(%rip)
20931 INTERRUPT_RETURN
20932+ .previous
20933
20934+ __INITDATA
20935 .balign 4
20936 early_recursion_flag:
20937 .long 0
20938+ .previous
20939
20940+ .section .rodata,"a",@progbits
20941 #ifdef CONFIG_EARLY_PRINTK
20942 early_idt_msg:
20943 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
20944@@ -376,6 +385,7 @@ early_idt_ripmsg:
20945 #endif /* CONFIG_EARLY_PRINTK */
20946 .previous
20947
20948+ .section .rodata,"a",@progbits
20949 #define NEXT_PAGE(name) \
20950 .balign PAGE_SIZE; \
20951 ENTRY(name)
20952@@ -388,7 +398,6 @@ ENTRY(name)
20953 i = i + 1 ; \
20954 .endr
20955
20956- .data
20957 /*
20958 * This default setting generates an ident mapping at address 0x100000
20959 * and a mapping for the kernel that precisely maps virtual address
20960@@ -399,13 +408,41 @@ NEXT_PAGE(init_level4_pgt)
20961 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20962 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
20963 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20964+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
20965+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
20966+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
20967+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
20968+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
20969+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20970 .org init_level4_pgt + L4_START_KERNEL*8, 0
20971 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
20972 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
20973
20974+#ifdef CONFIG_PAX_PER_CPU_PGD
20975+NEXT_PAGE(cpu_pgd)
20976+ .rept NR_CPUS
20977+ .fill 512,8,0
20978+ .endr
20979+#endif
20980+
20981 NEXT_PAGE(level3_ident_pgt)
20982 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20983+#ifdef CONFIG_XEN
20984 .fill 511,8,0
20985+#else
20986+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
20987+ .fill 510,8,0
20988+#endif
20989+
20990+NEXT_PAGE(level3_vmalloc_start_pgt)
20991+ .fill 512,8,0
20992+
20993+NEXT_PAGE(level3_vmalloc_end_pgt)
20994+ .fill 512,8,0
20995+
20996+NEXT_PAGE(level3_vmemmap_pgt)
20997+ .fill L3_VMEMMAP_START,8,0
20998+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20999
21000 NEXT_PAGE(level3_kernel_pgt)
21001 .fill L3_START_KERNEL,8,0
21002@@ -413,20 +450,23 @@ NEXT_PAGE(level3_kernel_pgt)
21003 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
21004 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
21005
21006+NEXT_PAGE(level2_vmemmap_pgt)
21007+ .fill 512,8,0
21008+
21009 NEXT_PAGE(level2_fixmap_pgt)
21010- .fill 506,8,0
21011- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
21012- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
21013- .fill 5,8,0
21014+ .fill 507,8,0
21015+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
21016+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
21017+ .fill 4,8,0
21018
21019-NEXT_PAGE(level1_fixmap_pgt)
21020+NEXT_PAGE(level1_vsyscall_pgt)
21021 .fill 512,8,0
21022
21023-NEXT_PAGE(level2_ident_pgt)
21024- /* Since I easily can, map the first 1G.
21025+ /* Since I easily can, map the first 2G.
21026 * Don't set NX because code runs from these pages.
21027 */
21028- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
21029+NEXT_PAGE(level2_ident_pgt)
21030+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
21031
21032 NEXT_PAGE(level2_kernel_pgt)
21033 /*
21034@@ -439,37 +479,59 @@ NEXT_PAGE(level2_kernel_pgt)
21035 * If you want to increase this then increase MODULES_VADDR
21036 * too.)
21037 */
21038- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
21039- KERNEL_IMAGE_SIZE/PMD_SIZE)
21040-
21041-NEXT_PAGE(level2_spare_pgt)
21042- .fill 512, 8, 0
21043+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
21044
21045 #undef PMDS
21046 #undef NEXT_PAGE
21047
21048- .data
21049+ .align PAGE_SIZE
21050+ENTRY(cpu_gdt_table)
21051+ .rept NR_CPUS
21052+ .quad 0x0000000000000000 /* NULL descriptor */
21053+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
21054+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
21055+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
21056+ .quad 0x00cffb000000ffff /* __USER32_CS */
21057+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
21058+ .quad 0x00affb000000ffff /* __USER_CS */
21059+
21060+#ifdef CONFIG_PAX_KERNEXEC
21061+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
21062+#else
21063+ .quad 0x0 /* unused */
21064+#endif
21065+
21066+ .quad 0,0 /* TSS */
21067+ .quad 0,0 /* LDT */
21068+ .quad 0,0,0 /* three TLS descriptors */
21069+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
21070+ /* asm/segment.h:GDT_ENTRIES must match this */
21071+
21072+ /* zero the remaining page */
21073+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
21074+ .endr
21075+
21076 .align 16
21077 .globl early_gdt_descr
21078 early_gdt_descr:
21079 .word GDT_ENTRIES*8-1
21080 early_gdt_descr_base:
21081- .quad INIT_PER_CPU_VAR(gdt_page)
21082+ .quad cpu_gdt_table
21083
21084 ENTRY(phys_base)
21085 /* This must match the first entry in level2_kernel_pgt */
21086 .quad 0x0000000000000000
21087
21088 #include "../../x86/xen/xen-head.S"
21089-
21090- .section .bss, "aw", @nobits
21091+
21092+ .section .rodata,"a",@progbits
21093 .align L1_CACHE_BYTES
21094 ENTRY(idt_table)
21095- .skip IDT_ENTRIES * 16
21096+ .fill 512,8,0
21097
21098 .align L1_CACHE_BYTES
21099 ENTRY(nmi_idt_table)
21100- .skip IDT_ENTRIES * 16
21101+ .fill 512,8,0
21102
21103 __PAGE_ALIGNED_BSS
21104 .align PAGE_SIZE
21105diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
21106index 9c3bd4a..e1d9b35 100644
21107--- a/arch/x86/kernel/i386_ksyms_32.c
21108+++ b/arch/x86/kernel/i386_ksyms_32.c
21109@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
21110 EXPORT_SYMBOL(cmpxchg8b_emu);
21111 #endif
21112
21113+EXPORT_SYMBOL_GPL(cpu_gdt_table);
21114+
21115 /* Networking helper routines. */
21116 EXPORT_SYMBOL(csum_partial_copy_generic);
21117+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
21118+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
21119
21120 EXPORT_SYMBOL(__get_user_1);
21121 EXPORT_SYMBOL(__get_user_2);
21122@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
21123
21124 EXPORT_SYMBOL(csum_partial);
21125 EXPORT_SYMBOL(empty_zero_page);
21126+
21127+#ifdef CONFIG_PAX_KERNEXEC
21128+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
21129+#endif
21130diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
21131index 245a71d..89d9ce4 100644
21132--- a/arch/x86/kernel/i387.c
21133+++ b/arch/x86/kernel/i387.c
21134@@ -55,7 +55,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
21135 static inline bool interrupted_user_mode(void)
21136 {
21137 struct pt_regs *regs = get_irq_regs();
21138- return regs && user_mode_vm(regs);
21139+ return regs && user_mode(regs);
21140 }
21141
21142 /*
21143diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
21144index 9a5c460..b332a4b 100644
21145--- a/arch/x86/kernel/i8259.c
21146+++ b/arch/x86/kernel/i8259.c
21147@@ -209,7 +209,7 @@ spurious_8259A_irq:
21148 "spurious 8259A interrupt: IRQ%d.\n", irq);
21149 spurious_irq_mask |= irqmask;
21150 }
21151- atomic_inc(&irq_err_count);
21152+ atomic_inc_unchecked(&irq_err_count);
21153 /*
21154 * Theoretically we do not have to handle this IRQ,
21155 * but in Linux this does not cause problems and is
21156@@ -333,14 +333,16 @@ static void init_8259A(int auto_eoi)
21157 /* (slave's support for AEOI in flat mode is to be investigated) */
21158 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
21159
21160+ pax_open_kernel();
21161 if (auto_eoi)
21162 /*
21163 * In AEOI mode we just have to mask the interrupt
21164 * when acking.
21165 */
21166- i8259A_chip.irq_mask_ack = disable_8259A_irq;
21167+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
21168 else
21169- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
21170+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
21171+ pax_close_kernel();
21172
21173 udelay(100); /* wait for 8259A to initialize */
21174
21175diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
21176index a979b5b..1d6db75 100644
21177--- a/arch/x86/kernel/io_delay.c
21178+++ b/arch/x86/kernel/io_delay.c
21179@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
21180 * Quirk table for systems that misbehave (lock up, etc.) if port
21181 * 0x80 is used:
21182 */
21183-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
21184+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
21185 {
21186 .callback = dmi_io_delay_0xed_port,
21187 .ident = "Compaq Presario V6000",
21188diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
21189index 8c96897..be66bfa 100644
21190--- a/arch/x86/kernel/ioport.c
21191+++ b/arch/x86/kernel/ioport.c
21192@@ -6,6 +6,7 @@
21193 #include <linux/sched.h>
21194 #include <linux/kernel.h>
21195 #include <linux/capability.h>
21196+#include <linux/security.h>
21197 #include <linux/errno.h>
21198 #include <linux/types.h>
21199 #include <linux/ioport.h>
21200@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
21201
21202 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
21203 return -EINVAL;
21204+#ifdef CONFIG_GRKERNSEC_IO
21205+ if (turn_on && grsec_disable_privio) {
21206+ gr_handle_ioperm();
21207+ return -EPERM;
21208+ }
21209+#endif
21210 if (turn_on && !capable(CAP_SYS_RAWIO))
21211 return -EPERM;
21212
21213@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
21214 * because the ->io_bitmap_max value must match the bitmap
21215 * contents:
21216 */
21217- tss = &per_cpu(init_tss, get_cpu());
21218+ tss = init_tss + get_cpu();
21219
21220 if (turn_on)
21221 bitmap_clear(t->io_bitmap_ptr, from, num);
21222@@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
21223 return -EINVAL;
21224 /* Trying to gain more privileges? */
21225 if (level > old) {
21226+#ifdef CONFIG_GRKERNSEC_IO
21227+ if (grsec_disable_privio) {
21228+ gr_handle_iopl();
21229+ return -EPERM;
21230+ }
21231+#endif
21232 if (!capable(CAP_SYS_RAWIO))
21233 return -EPERM;
21234 }
21235diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
21236index e4595f1..ee3bfb8 100644
21237--- a/arch/x86/kernel/irq.c
21238+++ b/arch/x86/kernel/irq.c
21239@@ -18,7 +18,7 @@
21240 #include <asm/mce.h>
21241 #include <asm/hw_irq.h>
21242
21243-atomic_t irq_err_count;
21244+atomic_unchecked_t irq_err_count;
21245
21246 /* Function pointer for generic interrupt vector handling */
21247 void (*x86_platform_ipi_callback)(void) = NULL;
21248@@ -122,9 +122,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
21249 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
21250 seq_printf(p, " Machine check polls\n");
21251 #endif
21252- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
21253+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
21254 #if defined(CONFIG_X86_IO_APIC)
21255- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
21256+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
21257 #endif
21258 return 0;
21259 }
21260@@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
21261
21262 u64 arch_irq_stat(void)
21263 {
21264- u64 sum = atomic_read(&irq_err_count);
21265+ u64 sum = atomic_read_unchecked(&irq_err_count);
21266
21267 #ifdef CONFIG_X86_IO_APIC
21268- sum += atomic_read(&irq_mis_count);
21269+ sum += atomic_read_unchecked(&irq_mis_count);
21270 #endif
21271 return sum;
21272 }
21273diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
21274index 344faf8..355f60d 100644
21275--- a/arch/x86/kernel/irq_32.c
21276+++ b/arch/x86/kernel/irq_32.c
21277@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
21278 __asm__ __volatile__("andl %%esp,%0" :
21279 "=r" (sp) : "0" (THREAD_SIZE - 1));
21280
21281- return sp < (sizeof(struct thread_info) + STACK_WARN);
21282+ return sp < STACK_WARN;
21283 }
21284
21285 static void print_stack_overflow(void)
21286@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
21287 * per-CPU IRQ handling contexts (thread information and stack)
21288 */
21289 union irq_ctx {
21290- struct thread_info tinfo;
21291- u32 stack[THREAD_SIZE/sizeof(u32)];
21292+ unsigned long previous_esp;
21293+ u32 stack[THREAD_SIZE/sizeof(u32)];
21294 } __attribute__((aligned(THREAD_SIZE)));
21295
21296 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
21297@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
21298 static inline int
21299 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21300 {
21301- union irq_ctx *curctx, *irqctx;
21302+ union irq_ctx *irqctx;
21303 u32 *isp, arg1, arg2;
21304
21305- curctx = (union irq_ctx *) current_thread_info();
21306 irqctx = __this_cpu_read(hardirq_ctx);
21307
21308 /*
21309@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21310 * handler) we can't do that and just have to keep using the
21311 * current stack (which is the irq stack already after all)
21312 */
21313- if (unlikely(curctx == irqctx))
21314+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
21315 return 0;
21316
21317 /* build the stack frame on the IRQ stack */
21318- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
21319- irqctx->tinfo.task = curctx->tinfo.task;
21320- irqctx->tinfo.previous_esp = current_stack_pointer;
21321+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
21322+ irqctx->previous_esp = current_stack_pointer;
21323
21324- /* Copy the preempt_count so that the [soft]irq checks work. */
21325- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
21326+#ifdef CONFIG_PAX_MEMORY_UDEREF
21327+ __set_fs(MAKE_MM_SEG(0));
21328+#endif
21329
21330 if (unlikely(overflow))
21331 call_on_stack(print_stack_overflow, isp);
21332@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21333 : "0" (irq), "1" (desc), "2" (isp),
21334 "D" (desc->handle_irq)
21335 : "memory", "cc", "ecx");
21336+
21337+#ifdef CONFIG_PAX_MEMORY_UDEREF
21338+ __set_fs(current_thread_info()->addr_limit);
21339+#endif
21340+
21341 return 1;
21342 }
21343
21344@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21345 */
21346 void __cpuinit irq_ctx_init(int cpu)
21347 {
21348- union irq_ctx *irqctx;
21349-
21350 if (per_cpu(hardirq_ctx, cpu))
21351 return;
21352
21353- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
21354- THREADINFO_GFP,
21355- THREAD_SIZE_ORDER));
21356- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
21357- irqctx->tinfo.cpu = cpu;
21358- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
21359- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
21360-
21361- per_cpu(hardirq_ctx, cpu) = irqctx;
21362-
21363- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
21364- THREADINFO_GFP,
21365- THREAD_SIZE_ORDER));
21366- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
21367- irqctx->tinfo.cpu = cpu;
21368- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
21369-
21370- per_cpu(softirq_ctx, cpu) = irqctx;
21371+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
21372+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
21373+
21374+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
21375+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
21376
21377 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
21378 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
21379@@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
21380 asmlinkage void do_softirq(void)
21381 {
21382 unsigned long flags;
21383- struct thread_info *curctx;
21384 union irq_ctx *irqctx;
21385 u32 *isp;
21386
21387@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
21388 local_irq_save(flags);
21389
21390 if (local_softirq_pending()) {
21391- curctx = current_thread_info();
21392 irqctx = __this_cpu_read(softirq_ctx);
21393- irqctx->tinfo.task = curctx->task;
21394- irqctx->tinfo.previous_esp = current_stack_pointer;
21395+ irqctx->previous_esp = current_stack_pointer;
21396
21397 /* build the stack frame on the softirq stack */
21398- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
21399+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
21400+
21401+#ifdef CONFIG_PAX_MEMORY_UDEREF
21402+ __set_fs(MAKE_MM_SEG(0));
21403+#endif
21404
21405 call_on_stack(__do_softirq, isp);
21406+
21407+#ifdef CONFIG_PAX_MEMORY_UDEREF
21408+ __set_fs(current_thread_info()->addr_limit);
21409+#endif
21410+
21411 /*
21412 * Shouldn't happen, we returned above if in_interrupt():
21413 */
21414@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
21415 if (unlikely(!desc))
21416 return false;
21417
21418- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
21419+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
21420 if (unlikely(overflow))
21421 print_stack_overflow();
21422 desc->handle_irq(irq, desc);
21423diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
21424index d04d3ec..ea4b374 100644
21425--- a/arch/x86/kernel/irq_64.c
21426+++ b/arch/x86/kernel/irq_64.c
21427@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
21428 u64 estack_top, estack_bottom;
21429 u64 curbase = (u64)task_stack_page(current);
21430
21431- if (user_mode_vm(regs))
21432+ if (user_mode(regs))
21433 return;
21434
21435 if (regs->sp >= curbase + sizeof(struct thread_info) +
21436diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
21437index dc1404b..bbc43e7 100644
21438--- a/arch/x86/kernel/kdebugfs.c
21439+++ b/arch/x86/kernel/kdebugfs.c
21440@@ -27,7 +27,7 @@ struct setup_data_node {
21441 u32 len;
21442 };
21443
21444-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
21445+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
21446 size_t count, loff_t *ppos)
21447 {
21448 struct setup_data_node *node = file->private_data;
21449diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
21450index 836f832..a8bda67 100644
21451--- a/arch/x86/kernel/kgdb.c
21452+++ b/arch/x86/kernel/kgdb.c
21453@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
21454 #ifdef CONFIG_X86_32
21455 switch (regno) {
21456 case GDB_SS:
21457- if (!user_mode_vm(regs))
21458+ if (!user_mode(regs))
21459 *(unsigned long *)mem = __KERNEL_DS;
21460 break;
21461 case GDB_SP:
21462- if (!user_mode_vm(regs))
21463+ if (!user_mode(regs))
21464 *(unsigned long *)mem = kernel_stack_pointer(regs);
21465 break;
21466 case GDB_GS:
21467@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
21468 bp->attr.bp_addr = breakinfo[breakno].addr;
21469 bp->attr.bp_len = breakinfo[breakno].len;
21470 bp->attr.bp_type = breakinfo[breakno].type;
21471- info->address = breakinfo[breakno].addr;
21472+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
21473+ info->address = ktla_ktva(breakinfo[breakno].addr);
21474+ else
21475+ info->address = breakinfo[breakno].addr;
21476 info->len = breakinfo[breakno].len;
21477 info->type = breakinfo[breakno].type;
21478 val = arch_install_hw_breakpoint(bp);
21479@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
21480 case 'k':
21481 /* clear the trace bit */
21482 linux_regs->flags &= ~X86_EFLAGS_TF;
21483- atomic_set(&kgdb_cpu_doing_single_step, -1);
21484+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
21485
21486 /* set the trace bit if we're stepping */
21487 if (remcomInBuffer[0] == 's') {
21488 linux_regs->flags |= X86_EFLAGS_TF;
21489- atomic_set(&kgdb_cpu_doing_single_step,
21490+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
21491 raw_smp_processor_id());
21492 }
21493
21494@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
21495
21496 switch (cmd) {
21497 case DIE_DEBUG:
21498- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
21499+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
21500 if (user_mode(regs))
21501 return single_step_cont(regs, args);
21502 break;
21503@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
21504 #endif /* CONFIG_DEBUG_RODATA */
21505
21506 bpt->type = BP_BREAKPOINT;
21507- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
21508+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
21509 BREAK_INSTR_SIZE);
21510 if (err)
21511 return err;
21512- err = probe_kernel_write((char *)bpt->bpt_addr,
21513+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
21514 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
21515 #ifdef CONFIG_DEBUG_RODATA
21516 if (!err)
21517@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
21518 return -EBUSY;
21519 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
21520 BREAK_INSTR_SIZE);
21521- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
21522+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
21523 if (err)
21524 return err;
21525 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
21526@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
21527 if (mutex_is_locked(&text_mutex))
21528 goto knl_write;
21529 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
21530- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
21531+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
21532 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
21533 goto knl_write;
21534 return err;
21535 knl_write:
21536 #endif /* CONFIG_DEBUG_RODATA */
21537- return probe_kernel_write((char *)bpt->bpt_addr,
21538+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
21539 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
21540 }
21541
21542diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
21543index c5e410e..ed5a7f0 100644
21544--- a/arch/x86/kernel/kprobes-opt.c
21545+++ b/arch/x86/kernel/kprobes-opt.c
21546@@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
21547 * Verify if the address gap is in 2GB range, because this uses
21548 * a relative jump.
21549 */
21550- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
21551+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
21552 if (abs(rel) > 0x7fffffff)
21553 return -ERANGE;
21554
21555@@ -353,16 +353,16 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
21556 op->optinsn.size = ret;
21557
21558 /* Copy arch-dep-instance from template */
21559- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
21560+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
21561
21562 /* Set probe information */
21563 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
21564
21565 /* Set probe function call */
21566- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
21567+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
21568
21569 /* Set returning jmp instruction at the tail of out-of-line buffer */
21570- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
21571+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
21572 (u8 *)op->kp.addr + op->optinsn.size);
21573
21574 flush_icache_range((unsigned long) buf,
21575@@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
21576 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
21577
21578 /* Backup instructions which will be replaced by jump address */
21579- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
21580+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
21581 RELATIVE_ADDR_SIZE);
21582
21583 insn_buf[0] = RELATIVEJUMP_OPCODE;
21584@@ -483,7 +483,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
21585 /* This kprobe is really able to run optimized path. */
21586 op = container_of(p, struct optimized_kprobe, kp);
21587 /* Detour through copied instructions */
21588- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
21589+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
21590 if (!reenter)
21591 reset_current_kprobe();
21592 preempt_enable_no_resched();
21593diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
21594index 57916c0..9e0b9d0 100644
21595--- a/arch/x86/kernel/kprobes.c
21596+++ b/arch/x86/kernel/kprobes.c
21597@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
21598 s32 raddr;
21599 } __attribute__((packed)) *insn;
21600
21601- insn = (struct __arch_relative_insn *)from;
21602+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
21603+
21604+ pax_open_kernel();
21605 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
21606 insn->op = op;
21607+ pax_close_kernel();
21608 }
21609
21610 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
21611@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
21612 kprobe_opcode_t opcode;
21613 kprobe_opcode_t *orig_opcodes = opcodes;
21614
21615- if (search_exception_tables((unsigned long)opcodes))
21616+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
21617 return 0; /* Page fault may occur on this address. */
21618
21619 retry:
21620@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
21621 * for the first byte, we can recover the original instruction
21622 * from it and kp->opcode.
21623 */
21624- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
21625+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
21626 buf[0] = kp->opcode;
21627- return (unsigned long)buf;
21628+ return ktva_ktla((unsigned long)buf);
21629 }
21630
21631 /*
21632@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
21633 /* Another subsystem puts a breakpoint, failed to recover */
21634 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
21635 return 0;
21636+ pax_open_kernel();
21637 memcpy(dest, insn.kaddr, insn.length);
21638+ pax_close_kernel();
21639
21640 #ifdef CONFIG_X86_64
21641 if (insn_rip_relative(&insn)) {
21642@@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
21643 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
21644 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
21645 disp = (u8 *) dest + insn_offset_displacement(&insn);
21646+ pax_open_kernel();
21647 *(s32 *) disp = (s32) newdisp;
21648+ pax_close_kernel();
21649 }
21650 #endif
21651 return insn.length;
21652@@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
21653 * nor set current_kprobe, because it doesn't use single
21654 * stepping.
21655 */
21656- regs->ip = (unsigned long)p->ainsn.insn;
21657+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
21658 preempt_enable_no_resched();
21659 return;
21660 }
21661@@ -502,9 +509,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
21662 regs->flags &= ~X86_EFLAGS_IF;
21663 /* single step inline if the instruction is an int3 */
21664 if (p->opcode == BREAKPOINT_INSTRUCTION)
21665- regs->ip = (unsigned long)p->addr;
21666+ regs->ip = ktla_ktva((unsigned long)p->addr);
21667 else
21668- regs->ip = (unsigned long)p->ainsn.insn;
21669+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
21670 }
21671
21672 /*
21673@@ -600,7 +607,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
21674 setup_singlestep(p, regs, kcb, 0);
21675 return 1;
21676 }
21677- } else if (*addr != BREAKPOINT_INSTRUCTION) {
21678+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
21679 /*
21680 * The breakpoint instruction was removed right
21681 * after we hit it. Another cpu has removed
21682@@ -651,6 +658,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
21683 " movq %rax, 152(%rsp)\n"
21684 RESTORE_REGS_STRING
21685 " popfq\n"
21686+#ifdef KERNEXEC_PLUGIN
21687+ " btsq $63,(%rsp)\n"
21688+#endif
21689 #else
21690 " pushf\n"
21691 SAVE_REGS_STRING
21692@@ -788,7 +798,7 @@ static void __kprobes
21693 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
21694 {
21695 unsigned long *tos = stack_addr(regs);
21696- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
21697+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
21698 unsigned long orig_ip = (unsigned long)p->addr;
21699 kprobe_opcode_t *insn = p->ainsn.insn;
21700
21701@@ -970,7 +980,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
21702 struct die_args *args = data;
21703 int ret = NOTIFY_DONE;
21704
21705- if (args->regs && user_mode_vm(args->regs))
21706+ if (args->regs && user_mode(args->regs))
21707 return ret;
21708
21709 switch (val) {
21710diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
21711index 9c2bd8b..bb1131c 100644
21712--- a/arch/x86/kernel/kvm.c
21713+++ b/arch/x86/kernel/kvm.c
21714@@ -452,7 +452,7 @@ static int __cpuinit kvm_cpu_notify(struct notifier_block *self,
21715 return NOTIFY_OK;
21716 }
21717
21718-static struct notifier_block __cpuinitdata kvm_cpu_notifier = {
21719+static struct notifier_block kvm_cpu_notifier = {
21720 .notifier_call = kvm_cpu_notify,
21721 };
21722 #endif
21723diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
21724index ebc9873..1b9724b 100644
21725--- a/arch/x86/kernel/ldt.c
21726+++ b/arch/x86/kernel/ldt.c
21727@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
21728 if (reload) {
21729 #ifdef CONFIG_SMP
21730 preempt_disable();
21731- load_LDT(pc);
21732+ load_LDT_nolock(pc);
21733 if (!cpumask_equal(mm_cpumask(current->mm),
21734 cpumask_of(smp_processor_id())))
21735 smp_call_function(flush_ldt, current->mm, 1);
21736 preempt_enable();
21737 #else
21738- load_LDT(pc);
21739+ load_LDT_nolock(pc);
21740 #endif
21741 }
21742 if (oldsize) {
21743@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
21744 return err;
21745
21746 for (i = 0; i < old->size; i++)
21747- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
21748+ write_ldt_entry(new->ldt, i, old->ldt + i);
21749 return 0;
21750 }
21751
21752@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
21753 retval = copy_ldt(&mm->context, &old_mm->context);
21754 mutex_unlock(&old_mm->context.lock);
21755 }
21756+
21757+ if (tsk == current) {
21758+ mm->context.vdso = 0;
21759+
21760+#ifdef CONFIG_X86_32
21761+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21762+ mm->context.user_cs_base = 0UL;
21763+ mm->context.user_cs_limit = ~0UL;
21764+
21765+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
21766+ cpus_clear(mm->context.cpu_user_cs_mask);
21767+#endif
21768+
21769+#endif
21770+#endif
21771+
21772+ }
21773+
21774 return retval;
21775 }
21776
21777@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
21778 }
21779 }
21780
21781+#ifdef CONFIG_PAX_SEGMEXEC
21782+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
21783+ error = -EINVAL;
21784+ goto out_unlock;
21785+ }
21786+#endif
21787+
21788 fill_ldt(&ldt, &ldt_info);
21789 if (oldmode)
21790 ldt.avl = 0;
21791diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
21792index 5b19e4d..6476a76 100644
21793--- a/arch/x86/kernel/machine_kexec_32.c
21794+++ b/arch/x86/kernel/machine_kexec_32.c
21795@@ -26,7 +26,7 @@
21796 #include <asm/cacheflush.h>
21797 #include <asm/debugreg.h>
21798
21799-static void set_idt(void *newidt, __u16 limit)
21800+static void set_idt(struct desc_struct *newidt, __u16 limit)
21801 {
21802 struct desc_ptr curidt;
21803
21804@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
21805 }
21806
21807
21808-static void set_gdt(void *newgdt, __u16 limit)
21809+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
21810 {
21811 struct desc_ptr curgdt;
21812
21813@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
21814 }
21815
21816 control_page = page_address(image->control_code_page);
21817- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
21818+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
21819
21820 relocate_kernel_ptr = control_page;
21821 page_list[PA_CONTROL_PAGE] = __pa(control_page);
21822diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
21823index 3a04b22..1d2eb09 100644
21824--- a/arch/x86/kernel/microcode_core.c
21825+++ b/arch/x86/kernel/microcode_core.c
21826@@ -512,7 +512,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21827 return NOTIFY_OK;
21828 }
21829
21830-static struct notifier_block __refdata mc_cpu_notifier = {
21831+static struct notifier_block mc_cpu_notifier = {
21832 .notifier_call = mc_cpu_callback,
21833 };
21834
21835diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
21836index 3544aed..01ddc1c 100644
21837--- a/arch/x86/kernel/microcode_intel.c
21838+++ b/arch/x86/kernel/microcode_intel.c
21839@@ -431,13 +431,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21840
21841 static int get_ucode_user(void *to, const void *from, size_t n)
21842 {
21843- return copy_from_user(to, from, n);
21844+ return copy_from_user(to, (const void __force_user *)from, n);
21845 }
21846
21847 static enum ucode_state
21848 request_microcode_user(int cpu, const void __user *buf, size_t size)
21849 {
21850- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21851+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21852 }
21853
21854 static void microcode_fini_cpu(int cpu)
21855diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
21856index 216a4d7..228255a 100644
21857--- a/arch/x86/kernel/module.c
21858+++ b/arch/x86/kernel/module.c
21859@@ -43,15 +43,60 @@ do { \
21860 } while (0)
21861 #endif
21862
21863-void *module_alloc(unsigned long size)
21864+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
21865 {
21866- if (PAGE_ALIGN(size) > MODULES_LEN)
21867+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
21868 return NULL;
21869 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
21870- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
21871+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
21872 -1, __builtin_return_address(0));
21873 }
21874
21875+void *module_alloc(unsigned long size)
21876+{
21877+
21878+#ifdef CONFIG_PAX_KERNEXEC
21879+ return __module_alloc(size, PAGE_KERNEL);
21880+#else
21881+ return __module_alloc(size, PAGE_KERNEL_EXEC);
21882+#endif
21883+
21884+}
21885+
21886+#ifdef CONFIG_PAX_KERNEXEC
21887+#ifdef CONFIG_X86_32
21888+void *module_alloc_exec(unsigned long size)
21889+{
21890+ struct vm_struct *area;
21891+
21892+ if (size == 0)
21893+ return NULL;
21894+
21895+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
21896+ return area ? area->addr : NULL;
21897+}
21898+EXPORT_SYMBOL(module_alloc_exec);
21899+
21900+void module_free_exec(struct module *mod, void *module_region)
21901+{
21902+ vunmap(module_region);
21903+}
21904+EXPORT_SYMBOL(module_free_exec);
21905+#else
21906+void module_free_exec(struct module *mod, void *module_region)
21907+{
21908+ module_free(mod, module_region);
21909+}
21910+EXPORT_SYMBOL(module_free_exec);
21911+
21912+void *module_alloc_exec(unsigned long size)
21913+{
21914+ return __module_alloc(size, PAGE_KERNEL_RX);
21915+}
21916+EXPORT_SYMBOL(module_alloc_exec);
21917+#endif
21918+#endif
21919+
21920 #ifdef CONFIG_X86_32
21921 int apply_relocate(Elf32_Shdr *sechdrs,
21922 const char *strtab,
21923@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
21924 unsigned int i;
21925 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
21926 Elf32_Sym *sym;
21927- uint32_t *location;
21928+ uint32_t *plocation, location;
21929
21930 DEBUGP("Applying relocate section %u to %u\n",
21931 relsec, sechdrs[relsec].sh_info);
21932 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
21933 /* This is where to make the change */
21934- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
21935- + rel[i].r_offset;
21936+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
21937+ location = (uint32_t)plocation;
21938+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
21939+ plocation = ktla_ktva((void *)plocation);
21940 /* This is the symbol it is referring to. Note that all
21941 undefined symbols have been resolved. */
21942 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
21943@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
21944 switch (ELF32_R_TYPE(rel[i].r_info)) {
21945 case R_386_32:
21946 /* We add the value into the location given */
21947- *location += sym->st_value;
21948+ pax_open_kernel();
21949+ *plocation += sym->st_value;
21950+ pax_close_kernel();
21951 break;
21952 case R_386_PC32:
21953 /* Add the value, subtract its position */
21954- *location += sym->st_value - (uint32_t)location;
21955+ pax_open_kernel();
21956+ *plocation += sym->st_value - location;
21957+ pax_close_kernel();
21958 break;
21959 default:
21960 pr_err("%s: Unknown relocation: %u\n",
21961@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
21962 case R_X86_64_NONE:
21963 break;
21964 case R_X86_64_64:
21965+ pax_open_kernel();
21966 *(u64 *)loc = val;
21967+ pax_close_kernel();
21968 break;
21969 case R_X86_64_32:
21970+ pax_open_kernel();
21971 *(u32 *)loc = val;
21972+ pax_close_kernel();
21973 if (val != *(u32 *)loc)
21974 goto overflow;
21975 break;
21976 case R_X86_64_32S:
21977+ pax_open_kernel();
21978 *(s32 *)loc = val;
21979+ pax_close_kernel();
21980 if ((s64)val != *(s32 *)loc)
21981 goto overflow;
21982 break;
21983 case R_X86_64_PC32:
21984 val -= (u64)loc;
21985+ pax_open_kernel();
21986 *(u32 *)loc = val;
21987+ pax_close_kernel();
21988+
21989 #if 0
21990 if ((s64)val != *(s32 *)loc)
21991 goto overflow;
21992diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
21993index 4929502..686c291 100644
21994--- a/arch/x86/kernel/msr.c
21995+++ b/arch/x86/kernel/msr.c
21996@@ -234,7 +234,7 @@ static int __cpuinit msr_class_cpu_callback(struct notifier_block *nfb,
21997 return notifier_from_errno(err);
21998 }
21999
22000-static struct notifier_block __refdata msr_class_cpu_notifier = {
22001+static struct notifier_block msr_class_cpu_notifier = {
22002 .notifier_call = msr_class_cpu_callback,
22003 };
22004
22005diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
22006index f84f5c5..f404e81 100644
22007--- a/arch/x86/kernel/nmi.c
22008+++ b/arch/x86/kernel/nmi.c
22009@@ -105,7 +105,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
22010 return handled;
22011 }
22012
22013-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
22014+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
22015 {
22016 struct nmi_desc *desc = nmi_to_desc(type);
22017 unsigned long flags;
22018@@ -129,9 +129,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
22019 * event confuses some handlers (kdump uses this flag)
22020 */
22021 if (action->flags & NMI_FLAG_FIRST)
22022- list_add_rcu(&action->list, &desc->head);
22023+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
22024 else
22025- list_add_tail_rcu(&action->list, &desc->head);
22026+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
22027
22028 spin_unlock_irqrestore(&desc->lock, flags);
22029 return 0;
22030@@ -154,7 +154,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
22031 if (!strcmp(n->name, name)) {
22032 WARN(in_nmi(),
22033 "Trying to free NMI (%s) from NMI context!\n", n->name);
22034- list_del_rcu(&n->list);
22035+ pax_list_del_rcu((struct list_head *)&n->list);
22036 break;
22037 }
22038 }
22039@@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
22040 dotraplinkage notrace __kprobes void
22041 do_nmi(struct pt_regs *regs, long error_code)
22042 {
22043+
22044+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
22045+ if (!user_mode(regs)) {
22046+ unsigned long cs = regs->cs & 0xFFFF;
22047+ unsigned long ip = ktva_ktla(regs->ip);
22048+
22049+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
22050+ regs->ip = ip;
22051+ }
22052+#endif
22053+
22054 nmi_nesting_preprocess(regs);
22055
22056 nmi_enter();
22057diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
22058index 6d9582e..f746287 100644
22059--- a/arch/x86/kernel/nmi_selftest.c
22060+++ b/arch/x86/kernel/nmi_selftest.c
22061@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
22062 {
22063 /* trap all the unknown NMIs we may generate */
22064 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
22065- __initdata);
22066+ __initconst);
22067 }
22068
22069 static void __init cleanup_nmi_testsuite(void)
22070@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
22071 unsigned long timeout;
22072
22073 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
22074- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
22075+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
22076 nmi_fail = FAILURE;
22077 return;
22078 }
22079diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
22080index 676b8c7..870ba04 100644
22081--- a/arch/x86/kernel/paravirt-spinlocks.c
22082+++ b/arch/x86/kernel/paravirt-spinlocks.c
22083@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
22084 arch_spin_lock(lock);
22085 }
22086
22087-struct pv_lock_ops pv_lock_ops = {
22088+struct pv_lock_ops pv_lock_ops __read_only = {
22089 #ifdef CONFIG_SMP
22090 .spin_is_locked = __ticket_spin_is_locked,
22091 .spin_is_contended = __ticket_spin_is_contended,
22092diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
22093index 8bfb335..c1463c6 100644
22094--- a/arch/x86/kernel/paravirt.c
22095+++ b/arch/x86/kernel/paravirt.c
22096@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
22097 {
22098 return x;
22099 }
22100+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
22101+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
22102+#endif
22103
22104 void __init default_banner(void)
22105 {
22106@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
22107 if (opfunc == NULL)
22108 /* If there's no function, patch it with a ud2a (BUG) */
22109 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
22110- else if (opfunc == _paravirt_nop)
22111+ else if (opfunc == (void *)_paravirt_nop)
22112 /* If the operation is a nop, then nop the callsite */
22113 ret = paravirt_patch_nop();
22114
22115 /* identity functions just return their single argument */
22116- else if (opfunc == _paravirt_ident_32)
22117+ else if (opfunc == (void *)_paravirt_ident_32)
22118 ret = paravirt_patch_ident_32(insnbuf, len);
22119- else if (opfunc == _paravirt_ident_64)
22120+ else if (opfunc == (void *)_paravirt_ident_64)
22121 ret = paravirt_patch_ident_64(insnbuf, len);
22122+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
22123+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
22124+ ret = paravirt_patch_ident_64(insnbuf, len);
22125+#endif
22126
22127 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
22128 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
22129@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
22130 if (insn_len > len || start == NULL)
22131 insn_len = len;
22132 else
22133- memcpy(insnbuf, start, insn_len);
22134+ memcpy(insnbuf, ktla_ktva(start), insn_len);
22135
22136 return insn_len;
22137 }
22138@@ -304,7 +311,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
22139 return this_cpu_read(paravirt_lazy_mode);
22140 }
22141
22142-struct pv_info pv_info = {
22143+struct pv_info pv_info __read_only = {
22144 .name = "bare hardware",
22145 .paravirt_enabled = 0,
22146 .kernel_rpl = 0,
22147@@ -315,16 +322,16 @@ struct pv_info pv_info = {
22148 #endif
22149 };
22150
22151-struct pv_init_ops pv_init_ops = {
22152+struct pv_init_ops pv_init_ops __read_only = {
22153 .patch = native_patch,
22154 };
22155
22156-struct pv_time_ops pv_time_ops = {
22157+struct pv_time_ops pv_time_ops __read_only = {
22158 .sched_clock = native_sched_clock,
22159 .steal_clock = native_steal_clock,
22160 };
22161
22162-struct pv_irq_ops pv_irq_ops = {
22163+struct pv_irq_ops pv_irq_ops __read_only = {
22164 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
22165 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
22166 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
22167@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
22168 #endif
22169 };
22170
22171-struct pv_cpu_ops pv_cpu_ops = {
22172+struct pv_cpu_ops pv_cpu_ops __read_only = {
22173 .cpuid = native_cpuid,
22174 .get_debugreg = native_get_debugreg,
22175 .set_debugreg = native_set_debugreg,
22176@@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
22177 .end_context_switch = paravirt_nop,
22178 };
22179
22180-struct pv_apic_ops pv_apic_ops = {
22181+struct pv_apic_ops pv_apic_ops __read_only= {
22182 #ifdef CONFIG_X86_LOCAL_APIC
22183 .startup_ipi_hook = paravirt_nop,
22184 #endif
22185 };
22186
22187-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
22188+#ifdef CONFIG_X86_32
22189+#ifdef CONFIG_X86_PAE
22190+/* 64-bit pagetable entries */
22191+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
22192+#else
22193 /* 32-bit pagetable entries */
22194 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
22195+#endif
22196 #else
22197 /* 64-bit pagetable entries */
22198 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
22199 #endif
22200
22201-struct pv_mmu_ops pv_mmu_ops = {
22202+struct pv_mmu_ops pv_mmu_ops __read_only = {
22203
22204 .read_cr2 = native_read_cr2,
22205 .write_cr2 = native_write_cr2,
22206@@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
22207 .make_pud = PTE_IDENT,
22208
22209 .set_pgd = native_set_pgd,
22210+ .set_pgd_batched = native_set_pgd_batched,
22211 #endif
22212 #endif /* PAGETABLE_LEVELS >= 3 */
22213
22214@@ -479,6 +492,12 @@ struct pv_mmu_ops pv_mmu_ops = {
22215 },
22216
22217 .set_fixmap = native_set_fixmap,
22218+
22219+#ifdef CONFIG_PAX_KERNEXEC
22220+ .pax_open_kernel = native_pax_open_kernel,
22221+ .pax_close_kernel = native_pax_close_kernel,
22222+#endif
22223+
22224 };
22225
22226 EXPORT_SYMBOL_GPL(pv_time_ops);
22227diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
22228index 35ccf75..7a15747 100644
22229--- a/arch/x86/kernel/pci-iommu_table.c
22230+++ b/arch/x86/kernel/pci-iommu_table.c
22231@@ -2,7 +2,7 @@
22232 #include <asm/iommu_table.h>
22233 #include <linux/string.h>
22234 #include <linux/kallsyms.h>
22235-
22236+#include <linux/sched.h>
22237
22238 #define DEBUG 1
22239
22240diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
22241index 6c483ba..d10ce2f 100644
22242--- a/arch/x86/kernel/pci-swiotlb.c
22243+++ b/arch/x86/kernel/pci-swiotlb.c
22244@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
22245 void *vaddr, dma_addr_t dma_addr,
22246 struct dma_attrs *attrs)
22247 {
22248- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
22249+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
22250 }
22251
22252 static struct dma_map_ops swiotlb_dma_ops = {
22253diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
22254index 2ed787f..f70c9f6 100644
22255--- a/arch/x86/kernel/process.c
22256+++ b/arch/x86/kernel/process.c
22257@@ -36,7 +36,8 @@
22258 * section. Since TSS's are completely CPU-local, we want them
22259 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
22260 */
22261-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
22262+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
22263+EXPORT_SYMBOL(init_tss);
22264
22265 #ifdef CONFIG_X86_64
22266 static DEFINE_PER_CPU(unsigned char, is_idle);
22267@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
22268 task_xstate_cachep =
22269 kmem_cache_create("task_xstate", xstate_size,
22270 __alignof__(union thread_xstate),
22271- SLAB_PANIC | SLAB_NOTRACK, NULL);
22272+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
22273 }
22274
22275 /*
22276@@ -105,7 +106,7 @@ void exit_thread(void)
22277 unsigned long *bp = t->io_bitmap_ptr;
22278
22279 if (bp) {
22280- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
22281+ struct tss_struct *tss = init_tss + get_cpu();
22282
22283 t->io_bitmap_ptr = NULL;
22284 clear_thread_flag(TIF_IO_BITMAP);
22285@@ -136,7 +137,7 @@ void show_regs_common(void)
22286 board = dmi_get_system_info(DMI_BOARD_NAME);
22287
22288 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
22289- current->pid, current->comm, print_tainted(),
22290+ task_pid_nr(current), current->comm, print_tainted(),
22291 init_utsname()->release,
22292 (int)strcspn(init_utsname()->version, " "),
22293 init_utsname()->version,
22294@@ -149,6 +150,9 @@ void flush_thread(void)
22295 {
22296 struct task_struct *tsk = current;
22297
22298+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
22299+ loadsegment(gs, 0);
22300+#endif
22301 flush_ptrace_hw_breakpoint(tsk);
22302 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
22303 drop_init_fpu(tsk);
22304@@ -301,7 +305,7 @@ static void __exit_idle(void)
22305 void exit_idle(void)
22306 {
22307 /* idle loop has pid 0 */
22308- if (current->pid)
22309+ if (task_pid_nr(current))
22310 return;
22311 __exit_idle();
22312 }
22313@@ -404,7 +408,7 @@ bool set_pm_idle_to_default(void)
22314
22315 return ret;
22316 }
22317-void stop_this_cpu(void *dummy)
22318+__noreturn void stop_this_cpu(void *dummy)
22319 {
22320 local_irq_disable();
22321 /*
22322@@ -632,16 +636,37 @@ static int __init idle_setup(char *str)
22323 }
22324 early_param("idle", idle_setup);
22325
22326-unsigned long arch_align_stack(unsigned long sp)
22327+#ifdef CONFIG_PAX_RANDKSTACK
22328+void pax_randomize_kstack(struct pt_regs *regs)
22329 {
22330- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
22331- sp -= get_random_int() % 8192;
22332- return sp & ~0xf;
22333-}
22334+ struct thread_struct *thread = &current->thread;
22335+ unsigned long time;
22336
22337-unsigned long arch_randomize_brk(struct mm_struct *mm)
22338-{
22339- unsigned long range_end = mm->brk + 0x02000000;
22340- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
22341-}
22342+ if (!randomize_va_space)
22343+ return;
22344+
22345+ if (v8086_mode(regs))
22346+ return;
22347
22348+ rdtscl(time);
22349+
22350+ /* P4 seems to return a 0 LSB, ignore it */
22351+#ifdef CONFIG_MPENTIUM4
22352+ time &= 0x3EUL;
22353+ time <<= 2;
22354+#elif defined(CONFIG_X86_64)
22355+ time &= 0xFUL;
22356+ time <<= 4;
22357+#else
22358+ time &= 0x1FUL;
22359+ time <<= 3;
22360+#endif
22361+
22362+ thread->sp0 ^= time;
22363+ load_sp0(init_tss + smp_processor_id(), thread);
22364+
22365+#ifdef CONFIG_X86_64
22366+ this_cpu_write(kernel_stack, thread->sp0);
22367+#endif
22368+}
22369+#endif
22370diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
22371index b5a8905..d9cacac 100644
22372--- a/arch/x86/kernel/process_32.c
22373+++ b/arch/x86/kernel/process_32.c
22374@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
22375 unsigned long thread_saved_pc(struct task_struct *tsk)
22376 {
22377 return ((unsigned long *)tsk->thread.sp)[3];
22378+//XXX return tsk->thread.eip;
22379 }
22380
22381 void __show_regs(struct pt_regs *regs, int all)
22382@@ -74,21 +75,20 @@ void __show_regs(struct pt_regs *regs, int all)
22383 unsigned long sp;
22384 unsigned short ss, gs;
22385
22386- if (user_mode_vm(regs)) {
22387+ if (user_mode(regs)) {
22388 sp = regs->sp;
22389 ss = regs->ss & 0xffff;
22390- gs = get_user_gs(regs);
22391 } else {
22392 sp = kernel_stack_pointer(regs);
22393 savesegment(ss, ss);
22394- savesegment(gs, gs);
22395 }
22396+ gs = get_user_gs(regs);
22397
22398 show_regs_common();
22399
22400 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
22401 (u16)regs->cs, regs->ip, regs->flags,
22402- smp_processor_id());
22403+ raw_smp_processor_id());
22404 print_symbol("EIP is at %s\n", regs->ip);
22405
22406 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
22407@@ -130,20 +130,21 @@ void release_thread(struct task_struct *dead_task)
22408 int copy_thread(unsigned long clone_flags, unsigned long sp,
22409 unsigned long arg, struct task_struct *p)
22410 {
22411- struct pt_regs *childregs = task_pt_regs(p);
22412+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
22413 struct task_struct *tsk;
22414 int err;
22415
22416 p->thread.sp = (unsigned long) childregs;
22417 p->thread.sp0 = (unsigned long) (childregs+1);
22418+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
22419
22420 if (unlikely(p->flags & PF_KTHREAD)) {
22421 /* kernel thread */
22422 memset(childregs, 0, sizeof(struct pt_regs));
22423 p->thread.ip = (unsigned long) ret_from_kernel_thread;
22424- task_user_gs(p) = __KERNEL_STACK_CANARY;
22425- childregs->ds = __USER_DS;
22426- childregs->es = __USER_DS;
22427+ savesegment(gs, childregs->gs);
22428+ childregs->ds = __KERNEL_DS;
22429+ childregs->es = __KERNEL_DS;
22430 childregs->fs = __KERNEL_PERCPU;
22431 childregs->bx = sp; /* function */
22432 childregs->bp = arg;
22433@@ -250,7 +251,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22434 struct thread_struct *prev = &prev_p->thread,
22435 *next = &next_p->thread;
22436 int cpu = smp_processor_id();
22437- struct tss_struct *tss = &per_cpu(init_tss, cpu);
22438+ struct tss_struct *tss = init_tss + cpu;
22439 fpu_switch_t fpu;
22440
22441 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
22442@@ -274,6 +275,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22443 */
22444 lazy_save_gs(prev->gs);
22445
22446+#ifdef CONFIG_PAX_MEMORY_UDEREF
22447+ __set_fs(task_thread_info(next_p)->addr_limit);
22448+#endif
22449+
22450 /*
22451 * Load the per-thread Thread-Local Storage descriptor.
22452 */
22453@@ -304,6 +309,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22454 */
22455 arch_end_context_switch(next_p);
22456
22457+ this_cpu_write(current_task, next_p);
22458+ this_cpu_write(current_tinfo, &next_p->tinfo);
22459+
22460 /*
22461 * Restore %gs if needed (which is common)
22462 */
22463@@ -312,8 +320,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22464
22465 switch_fpu_finish(next_p, fpu);
22466
22467- this_cpu_write(current_task, next_p);
22468-
22469 return prev_p;
22470 }
22471
22472@@ -343,4 +349,3 @@ unsigned long get_wchan(struct task_struct *p)
22473 } while (count++ < 16);
22474 return 0;
22475 }
22476-
22477diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
22478index 6e68a61..955a9a5 100644
22479--- a/arch/x86/kernel/process_64.c
22480+++ b/arch/x86/kernel/process_64.c
22481@@ -152,10 +152,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
22482 struct pt_regs *childregs;
22483 struct task_struct *me = current;
22484
22485- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
22486+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
22487 childregs = task_pt_regs(p);
22488 p->thread.sp = (unsigned long) childregs;
22489 p->thread.usersp = me->thread.usersp;
22490+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
22491 set_tsk_thread_flag(p, TIF_FORK);
22492 p->fpu_counter = 0;
22493 p->thread.io_bitmap_ptr = NULL;
22494@@ -274,7 +275,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22495 struct thread_struct *prev = &prev_p->thread;
22496 struct thread_struct *next = &next_p->thread;
22497 int cpu = smp_processor_id();
22498- struct tss_struct *tss = &per_cpu(init_tss, cpu);
22499+ struct tss_struct *tss = init_tss + cpu;
22500 unsigned fsindex, gsindex;
22501 fpu_switch_t fpu;
22502
22503@@ -356,10 +357,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22504 prev->usersp = this_cpu_read(old_rsp);
22505 this_cpu_write(old_rsp, next->usersp);
22506 this_cpu_write(current_task, next_p);
22507+ this_cpu_write(current_tinfo, &next_p->tinfo);
22508
22509- this_cpu_write(kernel_stack,
22510- (unsigned long)task_stack_page(next_p) +
22511- THREAD_SIZE - KERNEL_STACK_OFFSET);
22512+ this_cpu_write(kernel_stack, next->sp0);
22513
22514 /*
22515 * Now maybe reload the debug registers and handle I/O bitmaps
22516@@ -428,12 +428,11 @@ unsigned long get_wchan(struct task_struct *p)
22517 if (!p || p == current || p->state == TASK_RUNNING)
22518 return 0;
22519 stack = (unsigned long)task_stack_page(p);
22520- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
22521+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
22522 return 0;
22523 fp = *(u64 *)(p->thread.sp);
22524 do {
22525- if (fp < (unsigned long)stack ||
22526- fp >= (unsigned long)stack+THREAD_SIZE)
22527+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
22528 return 0;
22529 ip = *(u64 *)(fp+8);
22530 if (!in_sched_functions(ip))
22531diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
22532index b629bbe..0fa615a 100644
22533--- a/arch/x86/kernel/ptrace.c
22534+++ b/arch/x86/kernel/ptrace.c
22535@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
22536 {
22537 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
22538 unsigned long sp = (unsigned long)&regs->sp;
22539- struct thread_info *tinfo;
22540
22541- if (context == (sp & ~(THREAD_SIZE - 1)))
22542+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
22543 return sp;
22544
22545- tinfo = (struct thread_info *)context;
22546- if (tinfo->previous_esp)
22547- return tinfo->previous_esp;
22548+ sp = *(unsigned long *)context;
22549+ if (sp)
22550+ return sp;
22551
22552 return (unsigned long)regs;
22553 }
22554@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
22555 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
22556 {
22557 int i;
22558- int dr7 = 0;
22559+ unsigned long dr7 = 0;
22560 struct arch_hw_breakpoint *info;
22561
22562 for (i = 0; i < HBP_NUM; i++) {
22563@@ -856,7 +855,7 @@ long arch_ptrace(struct task_struct *child, long request,
22564 unsigned long addr, unsigned long data)
22565 {
22566 int ret;
22567- unsigned long __user *datap = (unsigned long __user *)data;
22568+ unsigned long __user *datap = (__force unsigned long __user *)data;
22569
22570 switch (request) {
22571 /* read the word at location addr in the USER area. */
22572@@ -941,14 +940,14 @@ long arch_ptrace(struct task_struct *child, long request,
22573 if ((int) addr < 0)
22574 return -EIO;
22575 ret = do_get_thread_area(child, addr,
22576- (struct user_desc __user *)data);
22577+ (__force struct user_desc __user *) data);
22578 break;
22579
22580 case PTRACE_SET_THREAD_AREA:
22581 if ((int) addr < 0)
22582 return -EIO;
22583 ret = do_set_thread_area(child, addr,
22584- (struct user_desc __user *)data, 0);
22585+ (__force struct user_desc __user *) data, 0);
22586 break;
22587 #endif
22588
22589@@ -1326,7 +1325,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
22590
22591 #ifdef CONFIG_X86_64
22592
22593-static struct user_regset x86_64_regsets[] __read_mostly = {
22594+static user_regset_no_const x86_64_regsets[] __read_only = {
22595 [REGSET_GENERAL] = {
22596 .core_note_type = NT_PRSTATUS,
22597 .n = sizeof(struct user_regs_struct) / sizeof(long),
22598@@ -1367,7 +1366,7 @@ static const struct user_regset_view user_x86_64_view = {
22599 #endif /* CONFIG_X86_64 */
22600
22601 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
22602-static struct user_regset x86_32_regsets[] __read_mostly = {
22603+static user_regset_no_const x86_32_regsets[] __read_only = {
22604 [REGSET_GENERAL] = {
22605 .core_note_type = NT_PRSTATUS,
22606 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
22607@@ -1420,7 +1419,7 @@ static const struct user_regset_view user_x86_32_view = {
22608 */
22609 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
22610
22611-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
22612+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
22613 {
22614 #ifdef CONFIG_X86_64
22615 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
22616@@ -1455,7 +1454,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
22617 memset(info, 0, sizeof(*info));
22618 info->si_signo = SIGTRAP;
22619 info->si_code = si_code;
22620- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
22621+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
22622 }
22623
22624 void user_single_step_siginfo(struct task_struct *tsk,
22625@@ -1484,6 +1483,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
22626 # define IS_IA32 0
22627 #endif
22628
22629+#ifdef CONFIG_GRKERNSEC_SETXID
22630+extern void gr_delayed_cred_worker(void);
22631+#endif
22632+
22633 /*
22634 * We must return the syscall number to actually look up in the table.
22635 * This can be -1L to skip running any syscall at all.
22636@@ -1494,6 +1497,11 @@ long syscall_trace_enter(struct pt_regs *regs)
22637
22638 user_exit();
22639
22640+#ifdef CONFIG_GRKERNSEC_SETXID
22641+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
22642+ gr_delayed_cred_worker();
22643+#endif
22644+
22645 /*
22646 * If we stepped into a sysenter/syscall insn, it trapped in
22647 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
22648@@ -1549,6 +1557,11 @@ void syscall_trace_leave(struct pt_regs *regs)
22649 */
22650 user_exit();
22651
22652+#ifdef CONFIG_GRKERNSEC_SETXID
22653+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
22654+ gr_delayed_cred_worker();
22655+#endif
22656+
22657 audit_syscall_exit(regs);
22658
22659 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
22660diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
22661index 2cb9470..ff1fd80 100644
22662--- a/arch/x86/kernel/pvclock.c
22663+++ b/arch/x86/kernel/pvclock.c
22664@@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
22665 return pv_tsc_khz;
22666 }
22667
22668-static atomic64_t last_value = ATOMIC64_INIT(0);
22669+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
22670
22671 void pvclock_resume(void)
22672 {
22673- atomic64_set(&last_value, 0);
22674+ atomic64_set_unchecked(&last_value, 0);
22675 }
22676
22677 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
22678@@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
22679 * updating at the same time, and one of them could be slightly behind,
22680 * making the assumption that last_value always go forward fail to hold.
22681 */
22682- last = atomic64_read(&last_value);
22683+ last = atomic64_read_unchecked(&last_value);
22684 do {
22685 if (ret < last)
22686 return last;
22687- last = atomic64_cmpxchg(&last_value, last, ret);
22688+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
22689 } while (unlikely(last != ret));
22690
22691 return ret;
22692diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
22693index 76fa1e9..abf09ea 100644
22694--- a/arch/x86/kernel/reboot.c
22695+++ b/arch/x86/kernel/reboot.c
22696@@ -36,7 +36,7 @@ void (*pm_power_off)(void);
22697 EXPORT_SYMBOL(pm_power_off);
22698
22699 static const struct desc_ptr no_idt = {};
22700-static int reboot_mode;
22701+static unsigned short reboot_mode;
22702 enum reboot_type reboot_type = BOOT_ACPI;
22703 int reboot_force;
22704
22705@@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
22706
22707 void __noreturn machine_real_restart(unsigned int type)
22708 {
22709+
22710+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
22711+ struct desc_struct *gdt;
22712+#endif
22713+
22714 local_irq_disable();
22715
22716 /*
22717@@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
22718
22719 /* Jump to the identity-mapped low memory code */
22720 #ifdef CONFIG_X86_32
22721- asm volatile("jmpl *%0" : :
22722+
22723+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22724+ gdt = get_cpu_gdt_table(smp_processor_id());
22725+ pax_open_kernel();
22726+#ifdef CONFIG_PAX_MEMORY_UDEREF
22727+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
22728+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
22729+ loadsegment(ds, __KERNEL_DS);
22730+ loadsegment(es, __KERNEL_DS);
22731+ loadsegment(ss, __KERNEL_DS);
22732+#endif
22733+#ifdef CONFIG_PAX_KERNEXEC
22734+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
22735+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
22736+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
22737+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
22738+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
22739+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
22740+#endif
22741+ pax_close_kernel();
22742+#endif
22743+
22744+ asm volatile("ljmpl *%0" : :
22745 "rm" (real_mode_header->machine_real_restart_asm),
22746 "a" (type));
22747 #else
22748@@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
22749 * try to force a triple fault and then cycle between hitting the keyboard
22750 * controller and doing that
22751 */
22752-static void native_machine_emergency_restart(void)
22753+static void __noreturn native_machine_emergency_restart(void)
22754 {
22755 int i;
22756 int attempt = 0;
22757@@ -654,13 +681,13 @@ void native_machine_shutdown(void)
22758 #endif
22759 }
22760
22761-static void __machine_emergency_restart(int emergency)
22762+static void __noreturn __machine_emergency_restart(int emergency)
22763 {
22764 reboot_emergency = emergency;
22765 machine_ops.emergency_restart();
22766 }
22767
22768-static void native_machine_restart(char *__unused)
22769+static void __noreturn native_machine_restart(char *__unused)
22770 {
22771 pr_notice("machine restart\n");
22772
22773@@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
22774 __machine_emergency_restart(0);
22775 }
22776
22777-static void native_machine_halt(void)
22778+static void __noreturn native_machine_halt(void)
22779 {
22780 /* Stop other cpus and apics */
22781 machine_shutdown();
22782@@ -679,7 +706,7 @@ static void native_machine_halt(void)
22783 stop_this_cpu(NULL);
22784 }
22785
22786-static void native_machine_power_off(void)
22787+static void __noreturn native_machine_power_off(void)
22788 {
22789 if (pm_power_off) {
22790 if (!reboot_force)
22791@@ -688,9 +715,10 @@ static void native_machine_power_off(void)
22792 }
22793 /* A fallback in case there is no PM info available */
22794 tboot_shutdown(TB_SHUTDOWN_HALT);
22795+ unreachable();
22796 }
22797
22798-struct machine_ops machine_ops = {
22799+struct machine_ops machine_ops __read_only = {
22800 .power_off = native_machine_power_off,
22801 .shutdown = native_machine_shutdown,
22802 .emergency_restart = native_machine_emergency_restart,
22803diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
22804index 7a6f3b3..bed145d7 100644
22805--- a/arch/x86/kernel/relocate_kernel_64.S
22806+++ b/arch/x86/kernel/relocate_kernel_64.S
22807@@ -11,6 +11,7 @@
22808 #include <asm/kexec.h>
22809 #include <asm/processor-flags.h>
22810 #include <asm/pgtable_types.h>
22811+#include <asm/alternative-asm.h>
22812
22813 /*
22814 * Must be relocatable PIC code callable as a C function
22815@@ -160,13 +161,14 @@ identity_mapped:
22816 xorq %rbp, %rbp
22817 xorq %r8, %r8
22818 xorq %r9, %r9
22819- xorq %r10, %r9
22820+ xorq %r10, %r10
22821 xorq %r11, %r11
22822 xorq %r12, %r12
22823 xorq %r13, %r13
22824 xorq %r14, %r14
22825 xorq %r15, %r15
22826
22827+ pax_force_retaddr 0, 1
22828 ret
22829
22830 1:
22831diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
22832index 8b24289..d37b58b 100644
22833--- a/arch/x86/kernel/setup.c
22834+++ b/arch/x86/kernel/setup.c
22835@@ -437,7 +437,7 @@ static void __init parse_setup_data(void)
22836
22837 switch (data->type) {
22838 case SETUP_E820_EXT:
22839- parse_e820_ext(data);
22840+ parse_e820_ext((struct setup_data __force_kernel *)data);
22841 break;
22842 case SETUP_DTB:
22843 add_dtb(pa_data);
22844@@ -706,7 +706,7 @@ static void __init trim_bios_range(void)
22845 * area (640->1Mb) as ram even though it is not.
22846 * take them out.
22847 */
22848- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
22849+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
22850
22851 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
22852 }
22853@@ -830,14 +830,14 @@ void __init setup_arch(char **cmdline_p)
22854
22855 if (!boot_params.hdr.root_flags)
22856 root_mountflags &= ~MS_RDONLY;
22857- init_mm.start_code = (unsigned long) _text;
22858- init_mm.end_code = (unsigned long) _etext;
22859+ init_mm.start_code = ktla_ktva((unsigned long) _text);
22860+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
22861 init_mm.end_data = (unsigned long) _edata;
22862 init_mm.brk = _brk_end;
22863
22864- code_resource.start = virt_to_phys(_text);
22865- code_resource.end = virt_to_phys(_etext)-1;
22866- data_resource.start = virt_to_phys(_etext);
22867+ code_resource.start = virt_to_phys(ktla_ktva(_text));
22868+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
22869+ data_resource.start = virt_to_phys(_sdata);
22870 data_resource.end = virt_to_phys(_edata)-1;
22871 bss_resource.start = virt_to_phys(&__bss_start);
22872 bss_resource.end = virt_to_phys(&__bss_stop)-1;
22873diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
22874index 5cdff03..80fa283 100644
22875--- a/arch/x86/kernel/setup_percpu.c
22876+++ b/arch/x86/kernel/setup_percpu.c
22877@@ -21,19 +21,17 @@
22878 #include <asm/cpu.h>
22879 #include <asm/stackprotector.h>
22880
22881-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
22882+#ifdef CONFIG_SMP
22883+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
22884 EXPORT_PER_CPU_SYMBOL(cpu_number);
22885+#endif
22886
22887-#ifdef CONFIG_X86_64
22888 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
22889-#else
22890-#define BOOT_PERCPU_OFFSET 0
22891-#endif
22892
22893 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
22894 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
22895
22896-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
22897+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
22898 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
22899 };
22900 EXPORT_SYMBOL(__per_cpu_offset);
22901@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
22902 {
22903 #ifdef CONFIG_NEED_MULTIPLE_NODES
22904 pg_data_t *last = NULL;
22905- unsigned int cpu;
22906+ int cpu;
22907
22908 for_each_possible_cpu(cpu) {
22909 int node = early_cpu_to_node(cpu);
22910@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
22911 {
22912 #ifdef CONFIG_X86_32
22913 struct desc_struct gdt;
22914+ unsigned long base = per_cpu_offset(cpu);
22915
22916- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
22917- 0x2 | DESCTYPE_S, 0x8);
22918- gdt.s = 1;
22919+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
22920+ 0x83 | DESCTYPE_S, 0xC);
22921 write_gdt_entry(get_cpu_gdt_table(cpu),
22922 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
22923 #endif
22924@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
22925 /* alrighty, percpu areas up and running */
22926 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
22927 for_each_possible_cpu(cpu) {
22928+#ifdef CONFIG_CC_STACKPROTECTOR
22929+#ifdef CONFIG_X86_32
22930+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
22931+#endif
22932+#endif
22933 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
22934 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
22935 per_cpu(cpu_number, cpu) = cpu;
22936@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
22937 */
22938 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
22939 #endif
22940+#ifdef CONFIG_CC_STACKPROTECTOR
22941+#ifdef CONFIG_X86_32
22942+ if (!cpu)
22943+ per_cpu(stack_canary.canary, cpu) = canary;
22944+#endif
22945+#endif
22946 /*
22947 * Up to this point, the boot CPU has been using .init.data
22948 * area. Reload any changed state for the boot CPU.
22949diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
22950index d6bf1f3..3ffce5a 100644
22951--- a/arch/x86/kernel/signal.c
22952+++ b/arch/x86/kernel/signal.c
22953@@ -196,7 +196,7 @@ static unsigned long align_sigframe(unsigned long sp)
22954 * Align the stack pointer according to the i386 ABI,
22955 * i.e. so that on function entry ((sp + 4) & 15) == 0.
22956 */
22957- sp = ((sp + 4) & -16ul) - 4;
22958+ sp = ((sp - 12) & -16ul) - 4;
22959 #else /* !CONFIG_X86_32 */
22960 sp = round_down(sp, 16) - 8;
22961 #endif
22962@@ -304,9 +304,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
22963 }
22964
22965 if (current->mm->context.vdso)
22966- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
22967+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
22968 else
22969- restorer = &frame->retcode;
22970+ restorer = (void __user *)&frame->retcode;
22971 if (ka->sa.sa_flags & SA_RESTORER)
22972 restorer = ka->sa.sa_restorer;
22973
22974@@ -320,7 +320,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
22975 * reasons and because gdb uses it as a signature to notice
22976 * signal handler stack frames.
22977 */
22978- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
22979+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
22980
22981 if (err)
22982 return -EFAULT;
22983@@ -367,7 +367,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
22984 err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
22985
22986 /* Set up to return from userspace. */
22987- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
22988+ if (current->mm->context.vdso)
22989+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
22990+ else
22991+ restorer = (void __user *)&frame->retcode;
22992 if (ka->sa.sa_flags & SA_RESTORER)
22993 restorer = ka->sa.sa_restorer;
22994 put_user_ex(restorer, &frame->pretcode);
22995@@ -379,7 +382,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
22996 * reasons and because gdb uses it as a signature to notice
22997 * signal handler stack frames.
22998 */
22999- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
23000+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
23001 } put_user_catch(err);
23002
23003 err |= copy_siginfo_to_user(&frame->info, info);
23004diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
23005index 48d2b7d..90d328a 100644
23006--- a/arch/x86/kernel/smp.c
23007+++ b/arch/x86/kernel/smp.c
23008@@ -285,7 +285,7 @@ static int __init nonmi_ipi_setup(char *str)
23009
23010 __setup("nonmi_ipi", nonmi_ipi_setup);
23011
23012-struct smp_ops smp_ops = {
23013+struct smp_ops smp_ops __read_only = {
23014 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
23015 .smp_prepare_cpus = native_smp_prepare_cpus,
23016 .smp_cpus_done = native_smp_cpus_done,
23017diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
23018index ed0fe38..87fc692 100644
23019--- a/arch/x86/kernel/smpboot.c
23020+++ b/arch/x86/kernel/smpboot.c
23021@@ -748,6 +748,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
23022 idle->thread.sp = (unsigned long) (((struct pt_regs *)
23023 (THREAD_SIZE + task_stack_page(idle))) - 1);
23024 per_cpu(current_task, cpu) = idle;
23025+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
23026
23027 #ifdef CONFIG_X86_32
23028 /* Stack for startup_32 can be just as for start_secondary onwards */
23029@@ -755,11 +756,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
23030 #else
23031 clear_tsk_thread_flag(idle, TIF_FORK);
23032 initial_gs = per_cpu_offset(cpu);
23033- per_cpu(kernel_stack, cpu) =
23034- (unsigned long)task_stack_page(idle) -
23035- KERNEL_STACK_OFFSET + THREAD_SIZE;
23036+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
23037 #endif
23038+
23039+ pax_open_kernel();
23040 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
23041+ pax_close_kernel();
23042+
23043 initial_code = (unsigned long)start_secondary;
23044 stack_start = idle->thread.sp;
23045
23046@@ -908,6 +911,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
23047 /* the FPU context is blank, nobody can own it */
23048 __cpu_disable_lazy_restore(cpu);
23049
23050+#ifdef CONFIG_PAX_PER_CPU_PGD
23051+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
23052+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
23053+ KERNEL_PGD_PTRS);
23054+#endif
23055+
23056+ /* the FPU context is blank, nobody can own it */
23057+ __cpu_disable_lazy_restore(cpu);
23058+
23059 err = do_boot_cpu(apicid, cpu, tidle);
23060 if (err) {
23061 pr_debug("do_boot_cpu failed %d\n", err);
23062diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
23063index 9b4d51d..5d28b58 100644
23064--- a/arch/x86/kernel/step.c
23065+++ b/arch/x86/kernel/step.c
23066@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
23067 struct desc_struct *desc;
23068 unsigned long base;
23069
23070- seg &= ~7UL;
23071+ seg >>= 3;
23072
23073 mutex_lock(&child->mm->context.lock);
23074- if (unlikely((seg >> 3) >= child->mm->context.size))
23075+ if (unlikely(seg >= child->mm->context.size))
23076 addr = -1L; /* bogus selector, access would fault */
23077 else {
23078 desc = child->mm->context.ldt + seg;
23079@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
23080 addr += base;
23081 }
23082 mutex_unlock(&child->mm->context.lock);
23083- }
23084+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
23085+ addr = ktla_ktva(addr);
23086
23087 return addr;
23088 }
23089@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
23090 unsigned char opcode[15];
23091 unsigned long addr = convert_ip_to_linear(child, regs);
23092
23093+ if (addr == -EINVAL)
23094+ return 0;
23095+
23096 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
23097 for (i = 0; i < copied; i++) {
23098 switch (opcode[i]) {
23099diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
23100new file mode 100644
23101index 0000000..207bec6
23102--- /dev/null
23103+++ b/arch/x86/kernel/sys_i386_32.c
23104@@ -0,0 +1,250 @@
23105+/*
23106+ * This file contains various random system calls that
23107+ * have a non-standard calling sequence on the Linux/i386
23108+ * platform.
23109+ */
23110+
23111+#include <linux/errno.h>
23112+#include <linux/sched.h>
23113+#include <linux/mm.h>
23114+#include <linux/fs.h>
23115+#include <linux/smp.h>
23116+#include <linux/sem.h>
23117+#include <linux/msg.h>
23118+#include <linux/shm.h>
23119+#include <linux/stat.h>
23120+#include <linux/syscalls.h>
23121+#include <linux/mman.h>
23122+#include <linux/file.h>
23123+#include <linux/utsname.h>
23124+#include <linux/ipc.h>
23125+
23126+#include <linux/uaccess.h>
23127+#include <linux/unistd.h>
23128+
23129+#include <asm/syscalls.h>
23130+
23131+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
23132+{
23133+ unsigned long pax_task_size = TASK_SIZE;
23134+
23135+#ifdef CONFIG_PAX_SEGMEXEC
23136+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
23137+ pax_task_size = SEGMEXEC_TASK_SIZE;
23138+#endif
23139+
23140+ if (flags & MAP_FIXED)
23141+ if (len > pax_task_size || addr > pax_task_size - len)
23142+ return -EINVAL;
23143+
23144+ return 0;
23145+}
23146+
23147+unsigned long
23148+arch_get_unmapped_area(struct file *filp, unsigned long addr,
23149+ unsigned long len, unsigned long pgoff, unsigned long flags)
23150+{
23151+ struct mm_struct *mm = current->mm;
23152+ struct vm_area_struct *vma;
23153+ unsigned long start_addr, pax_task_size = TASK_SIZE;
23154+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
23155+
23156+#ifdef CONFIG_PAX_SEGMEXEC
23157+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
23158+ pax_task_size = SEGMEXEC_TASK_SIZE;
23159+#endif
23160+
23161+ pax_task_size -= PAGE_SIZE;
23162+
23163+ if (len > pax_task_size)
23164+ return -ENOMEM;
23165+
23166+ if (flags & MAP_FIXED)
23167+ return addr;
23168+
23169+#ifdef CONFIG_PAX_RANDMMAP
23170+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23171+#endif
23172+
23173+ if (addr) {
23174+ addr = PAGE_ALIGN(addr);
23175+ if (pax_task_size - len >= addr) {
23176+ vma = find_vma(mm, addr);
23177+ if (check_heap_stack_gap(vma, addr, len, offset))
23178+ return addr;
23179+ }
23180+ }
23181+ if (len > mm->cached_hole_size) {
23182+ start_addr = addr = mm->free_area_cache;
23183+ } else {
23184+ start_addr = addr = mm->mmap_base;
23185+ mm->cached_hole_size = 0;
23186+ }
23187+
23188+#ifdef CONFIG_PAX_PAGEEXEC
23189+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
23190+ start_addr = 0x00110000UL;
23191+
23192+#ifdef CONFIG_PAX_RANDMMAP
23193+ if (mm->pax_flags & MF_PAX_RANDMMAP)
23194+ start_addr += mm->delta_mmap & 0x03FFF000UL;
23195+#endif
23196+
23197+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
23198+ start_addr = addr = mm->mmap_base;
23199+ else
23200+ addr = start_addr;
23201+ }
23202+#endif
23203+
23204+full_search:
23205+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
23206+ /* At this point: (!vma || addr < vma->vm_end). */
23207+ if (pax_task_size - len < addr) {
23208+ /*
23209+ * Start a new search - just in case we missed
23210+ * some holes.
23211+ */
23212+ if (start_addr != mm->mmap_base) {
23213+ start_addr = addr = mm->mmap_base;
23214+ mm->cached_hole_size = 0;
23215+ goto full_search;
23216+ }
23217+ return -ENOMEM;
23218+ }
23219+ if (check_heap_stack_gap(vma, addr, len, offset))
23220+ break;
23221+ if (addr + mm->cached_hole_size < vma->vm_start)
23222+ mm->cached_hole_size = vma->vm_start - addr;
23223+ addr = vma->vm_end;
23224+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
23225+ start_addr = addr = mm->mmap_base;
23226+ mm->cached_hole_size = 0;
23227+ goto full_search;
23228+ }
23229+ }
23230+
23231+ /*
23232+ * Remember the place where we stopped the search:
23233+ */
23234+ mm->free_area_cache = addr + len;
23235+ return addr;
23236+}
23237+
23238+unsigned long
23239+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
23240+ const unsigned long len, const unsigned long pgoff,
23241+ const unsigned long flags)
23242+{
23243+ struct vm_area_struct *vma;
23244+ struct mm_struct *mm = current->mm;
23245+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
23246+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
23247+
23248+#ifdef CONFIG_PAX_SEGMEXEC
23249+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
23250+ pax_task_size = SEGMEXEC_TASK_SIZE;
23251+#endif
23252+
23253+ pax_task_size -= PAGE_SIZE;
23254+
23255+ /* requested length too big for entire address space */
23256+ if (len > pax_task_size)
23257+ return -ENOMEM;
23258+
23259+ if (flags & MAP_FIXED)
23260+ return addr;
23261+
23262+#ifdef CONFIG_PAX_PAGEEXEC
23263+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
23264+ goto bottomup;
23265+#endif
23266+
23267+#ifdef CONFIG_PAX_RANDMMAP
23268+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23269+#endif
23270+
23271+ /* requesting a specific address */
23272+ if (addr) {
23273+ addr = PAGE_ALIGN(addr);
23274+ if (pax_task_size - len >= addr) {
23275+ vma = find_vma(mm, addr);
23276+ if (check_heap_stack_gap(vma, addr, len, offset))
23277+ return addr;
23278+ }
23279+ }
23280+
23281+ /* check if free_area_cache is useful for us */
23282+ if (len <= mm->cached_hole_size) {
23283+ mm->cached_hole_size = 0;
23284+ mm->free_area_cache = mm->mmap_base;
23285+ }
23286+
23287+ /* either no address requested or can't fit in requested address hole */
23288+ addr = mm->free_area_cache;
23289+
23290+ /* make sure it can fit in the remaining address space */
23291+ if (addr > len) {
23292+ vma = find_vma(mm, addr-len);
23293+ if (check_heap_stack_gap(vma, addr - len, len, offset))
23294+ /* remember the address as a hint for next time */
23295+ return (mm->free_area_cache = addr-len);
23296+ }
23297+
23298+ if (mm->mmap_base < len)
23299+ goto bottomup;
23300+
23301+ addr = mm->mmap_base-len;
23302+
23303+ do {
23304+ /*
23305+ * Lookup failure means no vma is above this address,
23306+ * else if new region fits below vma->vm_start,
23307+ * return with success:
23308+ */
23309+ vma = find_vma(mm, addr);
23310+ if (check_heap_stack_gap(vma, addr, len, offset))
23311+ /* remember the address as a hint for next time */
23312+ return (mm->free_area_cache = addr);
23313+
23314+ /* remember the largest hole we saw so far */
23315+ if (addr + mm->cached_hole_size < vma->vm_start)
23316+ mm->cached_hole_size = vma->vm_start - addr;
23317+
23318+ /* try just below the current vma->vm_start */
23319+ addr = skip_heap_stack_gap(vma, len, offset);
23320+ } while (!IS_ERR_VALUE(addr));
23321+
23322+bottomup:
23323+ /*
23324+ * A failed mmap() very likely causes application failure,
23325+ * so fall back to the bottom-up function here. This scenario
23326+ * can happen with large stack limits and large mmap()
23327+ * allocations.
23328+ */
23329+
23330+#ifdef CONFIG_PAX_SEGMEXEC
23331+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
23332+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
23333+ else
23334+#endif
23335+
23336+ mm->mmap_base = TASK_UNMAPPED_BASE;
23337+
23338+#ifdef CONFIG_PAX_RANDMMAP
23339+ if (mm->pax_flags & MF_PAX_RANDMMAP)
23340+ mm->mmap_base += mm->delta_mmap;
23341+#endif
23342+
23343+ mm->free_area_cache = mm->mmap_base;
23344+ mm->cached_hole_size = ~0UL;
23345+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
23346+ /*
23347+ * Restore the topdown base:
23348+ */
23349+ mm->mmap_base = base;
23350+ mm->free_area_cache = base;
23351+ mm->cached_hole_size = ~0UL;
23352+
23353+ return addr;
23354+}
23355diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
23356index 97ef74b..57a1882 100644
23357--- a/arch/x86/kernel/sys_x86_64.c
23358+++ b/arch/x86/kernel/sys_x86_64.c
23359@@ -81,8 +81,8 @@ out:
23360 return error;
23361 }
23362
23363-static void find_start_end(unsigned long flags, unsigned long *begin,
23364- unsigned long *end)
23365+static void find_start_end(struct mm_struct *mm, unsigned long flags,
23366+ unsigned long *begin, unsigned long *end)
23367 {
23368 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
23369 unsigned long new_begin;
23370@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
23371 *begin = new_begin;
23372 }
23373 } else {
23374- *begin = TASK_UNMAPPED_BASE;
23375+ *begin = mm->mmap_base;
23376 *end = TASK_SIZE;
23377 }
23378 }
23379@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
23380 struct vm_area_struct *vma;
23381 struct vm_unmapped_area_info info;
23382 unsigned long begin, end;
23383+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
23384
23385 if (flags & MAP_FIXED)
23386 return addr;
23387
23388- find_start_end(flags, &begin, &end);
23389+ find_start_end(mm, flags, &begin, &end);
23390
23391 if (len > end)
23392 return -ENOMEM;
23393
23394+#ifdef CONFIG_PAX_RANDMMAP
23395+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23396+#endif
23397+
23398 if (addr) {
23399 addr = PAGE_ALIGN(addr);
23400 vma = find_vma(mm, addr);
23401- if (end - len >= addr &&
23402- (!vma || addr + len <= vma->vm_start))
23403+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
23404 return addr;
23405 }
23406
23407@@ -161,6 +165,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
23408 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
23409 goto bottomup;
23410
23411+#ifdef CONFIG_PAX_RANDMMAP
23412+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23413+#endif
23414+
23415 /* requesting a specific address */
23416 if (addr) {
23417 addr = PAGE_ALIGN(addr);
23418diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
23419index f84fe00..f41d9f1 100644
23420--- a/arch/x86/kernel/tboot.c
23421+++ b/arch/x86/kernel/tboot.c
23422@@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
23423
23424 void tboot_shutdown(u32 shutdown_type)
23425 {
23426- void (*shutdown)(void);
23427+ void (* __noreturn shutdown)(void);
23428
23429 if (!tboot_enabled())
23430 return;
23431@@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
23432
23433 switch_to_tboot_pt();
23434
23435- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
23436+ shutdown = (void *)tboot->shutdown_entry;
23437 shutdown();
23438
23439 /* should not reach here */
23440@@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
23441 return 0;
23442 }
23443
23444-static atomic_t ap_wfs_count;
23445+static atomic_unchecked_t ap_wfs_count;
23446
23447 static int tboot_wait_for_aps(int num_aps)
23448 {
23449@@ -324,16 +324,16 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
23450 {
23451 switch (action) {
23452 case CPU_DYING:
23453- atomic_inc(&ap_wfs_count);
23454+ atomic_inc_unchecked(&ap_wfs_count);
23455 if (num_online_cpus() == 1)
23456- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
23457+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
23458 return NOTIFY_BAD;
23459 break;
23460 }
23461 return NOTIFY_OK;
23462 }
23463
23464-static struct notifier_block tboot_cpu_notifier __cpuinitdata =
23465+static struct notifier_block tboot_cpu_notifier =
23466 {
23467 .notifier_call = tboot_cpu_callback,
23468 };
23469@@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
23470
23471 tboot_create_trampoline();
23472
23473- atomic_set(&ap_wfs_count, 0);
23474+ atomic_set_unchecked(&ap_wfs_count, 0);
23475 register_hotcpu_notifier(&tboot_cpu_notifier);
23476
23477 acpi_os_set_prepare_sleep(&tboot_sleep);
23478diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
23479index 24d3c91..d06b473 100644
23480--- a/arch/x86/kernel/time.c
23481+++ b/arch/x86/kernel/time.c
23482@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
23483 {
23484 unsigned long pc = instruction_pointer(regs);
23485
23486- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
23487+ if (!user_mode(regs) && in_lock_functions(pc)) {
23488 #ifdef CONFIG_FRAME_POINTER
23489- return *(unsigned long *)(regs->bp + sizeof(long));
23490+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
23491 #else
23492 unsigned long *sp =
23493 (unsigned long *)kernel_stack_pointer(regs);
23494@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
23495 * or above a saved flags. Eflags has bits 22-31 zero,
23496 * kernel addresses don't.
23497 */
23498+
23499+#ifdef CONFIG_PAX_KERNEXEC
23500+ return ktla_ktva(sp[0]);
23501+#else
23502 if (sp[0] >> 22)
23503 return sp[0];
23504 if (sp[1] >> 22)
23505 return sp[1];
23506 #endif
23507+
23508+#endif
23509 }
23510 return pc;
23511 }
23512diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
23513index 9d9d2f9..cad418a 100644
23514--- a/arch/x86/kernel/tls.c
23515+++ b/arch/x86/kernel/tls.c
23516@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
23517 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
23518 return -EINVAL;
23519
23520+#ifdef CONFIG_PAX_SEGMEXEC
23521+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
23522+ return -EINVAL;
23523+#endif
23524+
23525 set_tls_desc(p, idx, &info, 1);
23526
23527 return 0;
23528@@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
23529
23530 if (kbuf)
23531 info = kbuf;
23532- else if (__copy_from_user(infobuf, ubuf, count))
23533+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
23534 return -EFAULT;
23535 else
23536 info = infobuf;
23537diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
23538index ecffca1..95c4d13 100644
23539--- a/arch/x86/kernel/traps.c
23540+++ b/arch/x86/kernel/traps.c
23541@@ -68,12 +68,6 @@
23542 #include <asm/setup.h>
23543
23544 asmlinkage int system_call(void);
23545-
23546-/*
23547- * The IDT has to be page-aligned to simplify the Pentium
23548- * F0 0F bug workaround.
23549- */
23550-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
23551 #endif
23552
23553 DECLARE_BITMAP(used_vectors, NR_VECTORS);
23554@@ -106,11 +100,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
23555 }
23556
23557 static int __kprobes
23558-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23559+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
23560 struct pt_regs *regs, long error_code)
23561 {
23562 #ifdef CONFIG_X86_32
23563- if (regs->flags & X86_VM_MASK) {
23564+ if (v8086_mode(regs)) {
23565 /*
23566 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
23567 * On nmi (interrupt 2), do_trap should not be called.
23568@@ -123,12 +117,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23569 return -1;
23570 }
23571 #endif
23572- if (!user_mode(regs)) {
23573+ if (!user_mode_novm(regs)) {
23574 if (!fixup_exception(regs)) {
23575 tsk->thread.error_code = error_code;
23576 tsk->thread.trap_nr = trapnr;
23577+
23578+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23579+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
23580+ str = "PAX: suspicious stack segment fault";
23581+#endif
23582+
23583 die(str, regs, error_code);
23584 }
23585+
23586+#ifdef CONFIG_PAX_REFCOUNT
23587+ if (trapnr == 4)
23588+ pax_report_refcount_overflow(regs);
23589+#endif
23590+
23591 return 0;
23592 }
23593
23594@@ -136,7 +142,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23595 }
23596
23597 static void __kprobes
23598-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
23599+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
23600 long error_code, siginfo_t *info)
23601 {
23602 struct task_struct *tsk = current;
23603@@ -160,7 +166,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
23604 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
23605 printk_ratelimit()) {
23606 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
23607- tsk->comm, tsk->pid, str,
23608+ tsk->comm, task_pid_nr(tsk), str,
23609 regs->ip, regs->sp, error_code);
23610 print_vma_addr(" in ", regs->ip);
23611 pr_cont("\n");
23612@@ -266,7 +272,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
23613 conditional_sti(regs);
23614
23615 #ifdef CONFIG_X86_32
23616- if (regs->flags & X86_VM_MASK) {
23617+ if (v8086_mode(regs)) {
23618 local_irq_enable();
23619 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
23620 goto exit;
23621@@ -274,18 +280,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
23622 #endif
23623
23624 tsk = current;
23625- if (!user_mode(regs)) {
23626+ if (!user_mode_novm(regs)) {
23627 if (fixup_exception(regs))
23628 goto exit;
23629
23630 tsk->thread.error_code = error_code;
23631 tsk->thread.trap_nr = X86_TRAP_GP;
23632 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
23633- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
23634+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
23635+
23636+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23637+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
23638+ die("PAX: suspicious general protection fault", regs, error_code);
23639+ else
23640+#endif
23641+
23642 die("general protection fault", regs, error_code);
23643+ }
23644 goto exit;
23645 }
23646
23647+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23648+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
23649+ struct mm_struct *mm = tsk->mm;
23650+ unsigned long limit;
23651+
23652+ down_write(&mm->mmap_sem);
23653+ limit = mm->context.user_cs_limit;
23654+ if (limit < TASK_SIZE) {
23655+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
23656+ up_write(&mm->mmap_sem);
23657+ return;
23658+ }
23659+ up_write(&mm->mmap_sem);
23660+ }
23661+#endif
23662+
23663 tsk->thread.error_code = error_code;
23664 tsk->thread.trap_nr = X86_TRAP_GP;
23665
23666@@ -440,7 +470,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
23667 /* It's safe to allow irq's after DR6 has been saved */
23668 preempt_conditional_sti(regs);
23669
23670- if (regs->flags & X86_VM_MASK) {
23671+ if (v8086_mode(regs)) {
23672 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
23673 X86_TRAP_DB);
23674 preempt_conditional_cli(regs);
23675@@ -455,7 +485,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
23676 * We already checked v86 mode above, so we can check for kernel mode
23677 * by just checking the CPL of CS.
23678 */
23679- if ((dr6 & DR_STEP) && !user_mode(regs)) {
23680+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
23681 tsk->thread.debugreg6 &= ~DR_STEP;
23682 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
23683 regs->flags &= ~X86_EFLAGS_TF;
23684@@ -487,7 +517,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
23685 return;
23686 conditional_sti(regs);
23687
23688- if (!user_mode_vm(regs))
23689+ if (!user_mode(regs))
23690 {
23691 if (!fixup_exception(regs)) {
23692 task->thread.error_code = error_code;
23693diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
23694index c71025b..b117501 100644
23695--- a/arch/x86/kernel/uprobes.c
23696+++ b/arch/x86/kernel/uprobes.c
23697@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
23698 int ret = NOTIFY_DONE;
23699
23700 /* We are only interested in userspace traps */
23701- if (regs && !user_mode_vm(regs))
23702+ if (regs && !user_mode(regs))
23703 return NOTIFY_DONE;
23704
23705 switch (val) {
23706diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
23707index b9242ba..50c5edd 100644
23708--- a/arch/x86/kernel/verify_cpu.S
23709+++ b/arch/x86/kernel/verify_cpu.S
23710@@ -20,6 +20,7 @@
23711 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
23712 * arch/x86/kernel/trampoline_64.S: secondary processor verification
23713 * arch/x86/kernel/head_32.S: processor startup
23714+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
23715 *
23716 * verify_cpu, returns the status of longmode and SSE in register %eax.
23717 * 0: Success 1: Failure
23718diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
23719index 1dfe69c..a3df6f6 100644
23720--- a/arch/x86/kernel/vm86_32.c
23721+++ b/arch/x86/kernel/vm86_32.c
23722@@ -43,6 +43,7 @@
23723 #include <linux/ptrace.h>
23724 #include <linux/audit.h>
23725 #include <linux/stddef.h>
23726+#include <linux/grsecurity.h>
23727
23728 #include <asm/uaccess.h>
23729 #include <asm/io.h>
23730@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
23731 do_exit(SIGSEGV);
23732 }
23733
23734- tss = &per_cpu(init_tss, get_cpu());
23735+ tss = init_tss + get_cpu();
23736 current->thread.sp0 = current->thread.saved_sp0;
23737 current->thread.sysenter_cs = __KERNEL_CS;
23738 load_sp0(tss, &current->thread);
23739@@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
23740 struct task_struct *tsk;
23741 int tmp, ret = -EPERM;
23742
23743+#ifdef CONFIG_GRKERNSEC_VM86
23744+ if (!capable(CAP_SYS_RAWIO)) {
23745+ gr_handle_vm86();
23746+ goto out;
23747+ }
23748+#endif
23749+
23750 tsk = current;
23751 if (tsk->thread.saved_sp0)
23752 goto out;
23753@@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
23754 int tmp, ret;
23755 struct vm86plus_struct __user *v86;
23756
23757+#ifdef CONFIG_GRKERNSEC_VM86
23758+ if (!capable(CAP_SYS_RAWIO)) {
23759+ gr_handle_vm86();
23760+ ret = -EPERM;
23761+ goto out;
23762+ }
23763+#endif
23764+
23765 tsk = current;
23766 switch (cmd) {
23767 case VM86_REQUEST_IRQ:
23768@@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
23769 tsk->thread.saved_fs = info->regs32->fs;
23770 tsk->thread.saved_gs = get_user_gs(info->regs32);
23771
23772- tss = &per_cpu(init_tss, get_cpu());
23773+ tss = init_tss + get_cpu();
23774 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
23775 if (cpu_has_sep)
23776 tsk->thread.sysenter_cs = 0;
23777@@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
23778 goto cannot_handle;
23779 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
23780 goto cannot_handle;
23781- intr_ptr = (unsigned long __user *) (i << 2);
23782+ intr_ptr = (__force unsigned long __user *) (i << 2);
23783 if (get_user(segoffs, intr_ptr))
23784 goto cannot_handle;
23785 if ((segoffs >> 16) == BIOSSEG)
23786diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
23787index 22a1530..8fbaaad 100644
23788--- a/arch/x86/kernel/vmlinux.lds.S
23789+++ b/arch/x86/kernel/vmlinux.lds.S
23790@@ -26,6 +26,13 @@
23791 #include <asm/page_types.h>
23792 #include <asm/cache.h>
23793 #include <asm/boot.h>
23794+#include <asm/segment.h>
23795+
23796+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23797+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
23798+#else
23799+#define __KERNEL_TEXT_OFFSET 0
23800+#endif
23801
23802 #undef i386 /* in case the preprocessor is a 32bit one */
23803
23804@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
23805
23806 PHDRS {
23807 text PT_LOAD FLAGS(5); /* R_E */
23808+#ifdef CONFIG_X86_32
23809+ module PT_LOAD FLAGS(5); /* R_E */
23810+#endif
23811+#ifdef CONFIG_XEN
23812+ rodata PT_LOAD FLAGS(5); /* R_E */
23813+#else
23814+ rodata PT_LOAD FLAGS(4); /* R__ */
23815+#endif
23816 data PT_LOAD FLAGS(6); /* RW_ */
23817-#ifdef CONFIG_X86_64
23818+ init.begin PT_LOAD FLAGS(6); /* RW_ */
23819 #ifdef CONFIG_SMP
23820 percpu PT_LOAD FLAGS(6); /* RW_ */
23821 #endif
23822+ text.init PT_LOAD FLAGS(5); /* R_E */
23823+ text.exit PT_LOAD FLAGS(5); /* R_E */
23824 init PT_LOAD FLAGS(7); /* RWE */
23825-#endif
23826 note PT_NOTE FLAGS(0); /* ___ */
23827 }
23828
23829 SECTIONS
23830 {
23831 #ifdef CONFIG_X86_32
23832- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
23833- phys_startup_32 = startup_32 - LOAD_OFFSET;
23834+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
23835 #else
23836- . = __START_KERNEL;
23837- phys_startup_64 = startup_64 - LOAD_OFFSET;
23838+ . = __START_KERNEL;
23839 #endif
23840
23841 /* Text and read-only data */
23842- .text : AT(ADDR(.text) - LOAD_OFFSET) {
23843- _text = .;
23844+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
23845 /* bootstrapping code */
23846+#ifdef CONFIG_X86_32
23847+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23848+#else
23849+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23850+#endif
23851+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23852+ _text = .;
23853 HEAD_TEXT
23854 #ifdef CONFIG_X86_32
23855 . = ALIGN(PAGE_SIZE);
23856@@ -108,13 +128,48 @@ SECTIONS
23857 IRQENTRY_TEXT
23858 *(.fixup)
23859 *(.gnu.warning)
23860- /* End of text section */
23861- _etext = .;
23862 } :text = 0x9090
23863
23864- NOTES :text :note
23865+ . += __KERNEL_TEXT_OFFSET;
23866
23867- EXCEPTION_TABLE(16) :text = 0x9090
23868+#ifdef CONFIG_X86_32
23869+ . = ALIGN(PAGE_SIZE);
23870+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
23871+
23872+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
23873+ MODULES_EXEC_VADDR = .;
23874+ BYTE(0)
23875+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
23876+ . = ALIGN(HPAGE_SIZE) - 1;
23877+ MODULES_EXEC_END = .;
23878+#endif
23879+
23880+ } :module
23881+#endif
23882+
23883+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
23884+ /* End of text section */
23885+ BYTE(0)
23886+ _etext = . - __KERNEL_TEXT_OFFSET;
23887+ }
23888+
23889+#ifdef CONFIG_X86_32
23890+ . = ALIGN(PAGE_SIZE);
23891+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
23892+ *(.idt)
23893+ . = ALIGN(PAGE_SIZE);
23894+ *(.empty_zero_page)
23895+ *(.initial_pg_fixmap)
23896+ *(.initial_pg_pmd)
23897+ *(.initial_page_table)
23898+ *(.swapper_pg_dir)
23899+ } :rodata
23900+#endif
23901+
23902+ . = ALIGN(PAGE_SIZE);
23903+ NOTES :rodata :note
23904+
23905+ EXCEPTION_TABLE(16) :rodata
23906
23907 #if defined(CONFIG_DEBUG_RODATA)
23908 /* .text should occupy whole number of pages */
23909@@ -126,16 +181,20 @@ SECTIONS
23910
23911 /* Data */
23912 .data : AT(ADDR(.data) - LOAD_OFFSET) {
23913+
23914+#ifdef CONFIG_PAX_KERNEXEC
23915+ . = ALIGN(HPAGE_SIZE);
23916+#else
23917+ . = ALIGN(PAGE_SIZE);
23918+#endif
23919+
23920 /* Start of data section */
23921 _sdata = .;
23922
23923 /* init_task */
23924 INIT_TASK_DATA(THREAD_SIZE)
23925
23926-#ifdef CONFIG_X86_32
23927- /* 32 bit has nosave before _edata */
23928 NOSAVE_DATA
23929-#endif
23930
23931 PAGE_ALIGNED_DATA(PAGE_SIZE)
23932
23933@@ -176,12 +235,19 @@ SECTIONS
23934 #endif /* CONFIG_X86_64 */
23935
23936 /* Init code and data - will be freed after init */
23937- . = ALIGN(PAGE_SIZE);
23938 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
23939+ BYTE(0)
23940+
23941+#ifdef CONFIG_PAX_KERNEXEC
23942+ . = ALIGN(HPAGE_SIZE);
23943+#else
23944+ . = ALIGN(PAGE_SIZE);
23945+#endif
23946+
23947 __init_begin = .; /* paired with __init_end */
23948- }
23949+ } :init.begin
23950
23951-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
23952+#ifdef CONFIG_SMP
23953 /*
23954 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
23955 * output PHDR, so the next output section - .init.text - should
23956@@ -190,12 +256,27 @@ SECTIONS
23957 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
23958 #endif
23959
23960- INIT_TEXT_SECTION(PAGE_SIZE)
23961-#ifdef CONFIG_X86_64
23962- :init
23963-#endif
23964+ . = ALIGN(PAGE_SIZE);
23965+ init_begin = .;
23966+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
23967+ VMLINUX_SYMBOL(_sinittext) = .;
23968+ INIT_TEXT
23969+ VMLINUX_SYMBOL(_einittext) = .;
23970+ . = ALIGN(PAGE_SIZE);
23971+ } :text.init
23972
23973- INIT_DATA_SECTION(16)
23974+ /*
23975+ * .exit.text is discard at runtime, not link time, to deal with
23976+ * references from .altinstructions and .eh_frame
23977+ */
23978+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
23979+ EXIT_TEXT
23980+ . = ALIGN(16);
23981+ } :text.exit
23982+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
23983+
23984+ . = ALIGN(PAGE_SIZE);
23985+ INIT_DATA_SECTION(16) :init
23986
23987 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
23988 __x86_cpu_dev_start = .;
23989@@ -257,19 +338,12 @@ SECTIONS
23990 }
23991
23992 . = ALIGN(8);
23993- /*
23994- * .exit.text is discard at runtime, not link time, to deal with
23995- * references from .altinstructions and .eh_frame
23996- */
23997- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
23998- EXIT_TEXT
23999- }
24000
24001 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
24002 EXIT_DATA
24003 }
24004
24005-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
24006+#ifndef CONFIG_SMP
24007 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
24008 #endif
24009
24010@@ -288,16 +362,10 @@ SECTIONS
24011 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
24012 __smp_locks = .;
24013 *(.smp_locks)
24014- . = ALIGN(PAGE_SIZE);
24015 __smp_locks_end = .;
24016+ . = ALIGN(PAGE_SIZE);
24017 }
24018
24019-#ifdef CONFIG_X86_64
24020- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
24021- NOSAVE_DATA
24022- }
24023-#endif
24024-
24025 /* BSS */
24026 . = ALIGN(PAGE_SIZE);
24027 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
24028@@ -313,6 +381,7 @@ SECTIONS
24029 __brk_base = .;
24030 . += 64 * 1024; /* 64k alignment slop space */
24031 *(.brk_reservation) /* areas brk users have reserved */
24032+ . = ALIGN(HPAGE_SIZE);
24033 __brk_limit = .;
24034 }
24035
24036@@ -339,13 +408,12 @@ SECTIONS
24037 * for the boot processor.
24038 */
24039 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
24040-INIT_PER_CPU(gdt_page);
24041 INIT_PER_CPU(irq_stack_union);
24042
24043 /*
24044 * Build-time check on the image size:
24045 */
24046-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
24047+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
24048 "kernel image bigger than KERNEL_IMAGE_SIZE");
24049
24050 #ifdef CONFIG_SMP
24051diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
24052index 9a907a6..f83f921 100644
24053--- a/arch/x86/kernel/vsyscall_64.c
24054+++ b/arch/x86/kernel/vsyscall_64.c
24055@@ -56,15 +56,13 @@
24056 DEFINE_VVAR(int, vgetcpu_mode);
24057 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
24058
24059-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
24060+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
24061
24062 static int __init vsyscall_setup(char *str)
24063 {
24064 if (str) {
24065 if (!strcmp("emulate", str))
24066 vsyscall_mode = EMULATE;
24067- else if (!strcmp("native", str))
24068- vsyscall_mode = NATIVE;
24069 else if (!strcmp("none", str))
24070 vsyscall_mode = NONE;
24071 else
24072@@ -323,8 +321,7 @@ do_ret:
24073 return true;
24074
24075 sigsegv:
24076- force_sig(SIGSEGV, current);
24077- return true;
24078+ do_group_exit(SIGKILL);
24079 }
24080
24081 /*
24082@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
24083 extern char __vvar_page;
24084 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
24085
24086- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
24087- vsyscall_mode == NATIVE
24088- ? PAGE_KERNEL_VSYSCALL
24089- : PAGE_KERNEL_VVAR);
24090+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
24091 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
24092 (unsigned long)VSYSCALL_START);
24093
24094diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
24095index 1330dd1..d220b99 100644
24096--- a/arch/x86/kernel/x8664_ksyms_64.c
24097+++ b/arch/x86/kernel/x8664_ksyms_64.c
24098@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
24099 EXPORT_SYMBOL(copy_user_generic_unrolled);
24100 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
24101 EXPORT_SYMBOL(__copy_user_nocache);
24102-EXPORT_SYMBOL(_copy_from_user);
24103-EXPORT_SYMBOL(_copy_to_user);
24104
24105 EXPORT_SYMBOL(copy_page);
24106 EXPORT_SYMBOL(clear_page);
24107diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
24108index 7a3d075..6cb373d 100644
24109--- a/arch/x86/kernel/x86_init.c
24110+++ b/arch/x86/kernel/x86_init.c
24111@@ -88,7 +88,7 @@ struct x86_init_ops x86_init __initdata = {
24112 },
24113 };
24114
24115-struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
24116+struct x86_cpuinit_ops x86_cpuinit __cpuinitconst = {
24117 .early_percpu_clock_init = x86_init_noop,
24118 .setup_percpu_clockev = setup_secondary_APIC_clock,
24119 };
24120@@ -96,7 +96,7 @@ struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
24121 static void default_nmi_init(void) { };
24122 static int default_i8042_detect(void) { return 1; };
24123
24124-struct x86_platform_ops x86_platform = {
24125+struct x86_platform_ops x86_platform __read_only = {
24126 .calibrate_tsc = native_calibrate_tsc,
24127 .get_wallclock = mach_get_cmos_time,
24128 .set_wallclock = mach_set_rtc_mmss,
24129@@ -110,14 +110,14 @@ struct x86_platform_ops x86_platform = {
24130 };
24131
24132 EXPORT_SYMBOL_GPL(x86_platform);
24133-struct x86_msi_ops x86_msi = {
24134+struct x86_msi_ops x86_msi __read_only = {
24135 .setup_msi_irqs = native_setup_msi_irqs,
24136 .teardown_msi_irq = native_teardown_msi_irq,
24137 .teardown_msi_irqs = default_teardown_msi_irqs,
24138 .restore_msi_irqs = default_restore_msi_irqs,
24139 };
24140
24141-struct x86_io_apic_ops x86_io_apic_ops = {
24142+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
24143 .init = native_io_apic_init_mappings,
24144 .read = native_io_apic_read,
24145 .write = native_io_apic_write,
24146diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
24147index ada87a3..afea76d 100644
24148--- a/arch/x86/kernel/xsave.c
24149+++ b/arch/x86/kernel/xsave.c
24150@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
24151 {
24152 int err;
24153
24154+ buf = (struct xsave_struct __user *)____m(buf);
24155 if (use_xsave())
24156 err = xsave_user(buf);
24157 else if (use_fxsr())
24158@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
24159 */
24160 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
24161 {
24162+ buf = (void __user *)____m(buf);
24163 if (use_xsave()) {
24164 if ((unsigned long)buf % 64 || fx_only) {
24165 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
24166diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
24167index a20ecb5..d0e2194 100644
24168--- a/arch/x86/kvm/cpuid.c
24169+++ b/arch/x86/kvm/cpuid.c
24170@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
24171 struct kvm_cpuid2 *cpuid,
24172 struct kvm_cpuid_entry2 __user *entries)
24173 {
24174- int r;
24175+ int r, i;
24176
24177 r = -E2BIG;
24178 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
24179 goto out;
24180 r = -EFAULT;
24181- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
24182- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
24183+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
24184 goto out;
24185+ for (i = 0; i < cpuid->nent; ++i) {
24186+ struct kvm_cpuid_entry2 cpuid_entry;
24187+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
24188+ goto out;
24189+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
24190+ }
24191 vcpu->arch.cpuid_nent = cpuid->nent;
24192 kvm_apic_set_version(vcpu);
24193 kvm_x86_ops->cpuid_update(vcpu);
24194@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
24195 struct kvm_cpuid2 *cpuid,
24196 struct kvm_cpuid_entry2 __user *entries)
24197 {
24198- int r;
24199+ int r, i;
24200
24201 r = -E2BIG;
24202 if (cpuid->nent < vcpu->arch.cpuid_nent)
24203 goto out;
24204 r = -EFAULT;
24205- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
24206- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
24207+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
24208 goto out;
24209+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
24210+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
24211+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
24212+ goto out;
24213+ }
24214 return 0;
24215
24216 out:
24217diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
24218index a27e763..54bfe43 100644
24219--- a/arch/x86/kvm/emulate.c
24220+++ b/arch/x86/kvm/emulate.c
24221@@ -292,6 +292,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
24222
24223 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
24224 do { \
24225+ unsigned long _tmp; \
24226 __asm__ __volatile__ ( \
24227 _PRE_EFLAGS("0", "4", "2") \
24228 _op _suffix " %"_x"3,%1; " \
24229@@ -306,8 +307,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
24230 /* Raw emulation: instruction has two explicit operands. */
24231 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
24232 do { \
24233- unsigned long _tmp; \
24234- \
24235 switch ((ctxt)->dst.bytes) { \
24236 case 2: \
24237 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
24238@@ -323,7 +322,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
24239
24240 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
24241 do { \
24242- unsigned long _tmp; \
24243 switch ((ctxt)->dst.bytes) { \
24244 case 1: \
24245 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
24246diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
24247index 9392f52..0e56d77 100644
24248--- a/arch/x86/kvm/lapic.c
24249+++ b/arch/x86/kvm/lapic.c
24250@@ -55,7 +55,7 @@
24251 #define APIC_BUS_CYCLE_NS 1
24252
24253 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
24254-#define apic_debug(fmt, arg...)
24255+#define apic_debug(fmt, arg...) do {} while (0)
24256
24257 #define APIC_LVT_NUM 6
24258 /* 14 is the version for Xeon and Pentium 8.4.8*/
24259diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
24260index 891eb6d..e027900 100644
24261--- a/arch/x86/kvm/paging_tmpl.h
24262+++ b/arch/x86/kvm/paging_tmpl.h
24263@@ -208,7 +208,7 @@ retry_walk:
24264 if (unlikely(kvm_is_error_hva(host_addr)))
24265 goto error;
24266
24267- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
24268+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
24269 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
24270 goto error;
24271 walker->ptep_user[walker->level - 1] = ptep_user;
24272diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
24273index d29d3cd..ec9d522 100644
24274--- a/arch/x86/kvm/svm.c
24275+++ b/arch/x86/kvm/svm.c
24276@@ -3507,7 +3507,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
24277 int cpu = raw_smp_processor_id();
24278
24279 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
24280+
24281+ pax_open_kernel();
24282 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
24283+ pax_close_kernel();
24284+
24285 load_TR_desc();
24286 }
24287
24288@@ -3881,6 +3885,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
24289 #endif
24290 #endif
24291
24292+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
24293+ __set_fs(current_thread_info()->addr_limit);
24294+#endif
24295+
24296 reload_tss(vcpu);
24297
24298 local_irq_disable();
24299diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
24300index 9120ae1..238abc0 100644
24301--- a/arch/x86/kvm/vmx.c
24302+++ b/arch/x86/kvm/vmx.c
24303@@ -1370,7 +1370,11 @@ static void reload_tss(void)
24304 struct desc_struct *descs;
24305
24306 descs = (void *)gdt->address;
24307+
24308+ pax_open_kernel();
24309 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
24310+ pax_close_kernel();
24311+
24312 load_TR_desc();
24313 }
24314
24315@@ -1594,6 +1598,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
24316 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
24317 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
24318
24319+#ifdef CONFIG_PAX_PER_CPU_PGD
24320+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
24321+#endif
24322+
24323 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
24324 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
24325 vmx->loaded_vmcs->cpu = cpu;
24326@@ -2738,8 +2746,11 @@ static __init int hardware_setup(void)
24327 if (!cpu_has_vmx_flexpriority())
24328 flexpriority_enabled = 0;
24329
24330- if (!cpu_has_vmx_tpr_shadow())
24331- kvm_x86_ops->update_cr8_intercept = NULL;
24332+ if (!cpu_has_vmx_tpr_shadow()) {
24333+ pax_open_kernel();
24334+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
24335+ pax_close_kernel();
24336+ }
24337
24338 if (enable_ept && !cpu_has_vmx_ept_2m_page())
24339 kvm_disable_largepages();
24340@@ -3782,7 +3793,10 @@ static void vmx_set_constant_host_state(void)
24341
24342 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
24343 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
24344+
24345+#ifndef CONFIG_PAX_PER_CPU_PGD
24346 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
24347+#endif
24348
24349 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
24350 #ifdef CONFIG_X86_64
24351@@ -3803,7 +3817,7 @@ static void vmx_set_constant_host_state(void)
24352 native_store_idt(&dt);
24353 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
24354
24355- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
24356+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
24357
24358 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
24359 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
24360@@ -6355,6 +6369,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24361 "jmp 2f \n\t"
24362 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
24363 "2: "
24364+
24365+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24366+ "ljmp %[cs],$3f\n\t"
24367+ "3: "
24368+#endif
24369+
24370 /* Save guest registers, load host registers, keep flags */
24371 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
24372 "pop %0 \n\t"
24373@@ -6407,6 +6427,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24374 #endif
24375 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
24376 [wordsize]"i"(sizeof(ulong))
24377+
24378+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24379+ ,[cs]"i"(__KERNEL_CS)
24380+#endif
24381+
24382 : "cc", "memory"
24383 #ifdef CONFIG_X86_64
24384 , "rax", "rbx", "rdi", "rsi"
24385@@ -6420,7 +6445,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24386 if (debugctlmsr)
24387 update_debugctlmsr(debugctlmsr);
24388
24389-#ifndef CONFIG_X86_64
24390+#ifdef CONFIG_X86_32
24391 /*
24392 * The sysexit path does not restore ds/es, so we must set them to
24393 * a reasonable value ourselves.
24394@@ -6429,8 +6454,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24395 * may be executed in interrupt context, which saves and restore segments
24396 * around it, nullifying its effect.
24397 */
24398- loadsegment(ds, __USER_DS);
24399- loadsegment(es, __USER_DS);
24400+ loadsegment(ds, __KERNEL_DS);
24401+ loadsegment(es, __KERNEL_DS);
24402+ loadsegment(ss, __KERNEL_DS);
24403+
24404+#ifdef CONFIG_PAX_KERNEXEC
24405+ loadsegment(fs, __KERNEL_PERCPU);
24406+#endif
24407+
24408+#ifdef CONFIG_PAX_MEMORY_UDEREF
24409+ __set_fs(current_thread_info()->addr_limit);
24410+#endif
24411+
24412 #endif
24413
24414 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
24415diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
24416index c243b81..b692af3 100644
24417--- a/arch/x86/kvm/x86.c
24418+++ b/arch/x86/kvm/x86.c
24419@@ -1408,10 +1408,9 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
24420 unsigned long flags, this_tsc_khz;
24421 struct kvm_vcpu_arch *vcpu = &v->arch;
24422 struct kvm_arch *ka = &v->kvm->arch;
24423- void *shared_kaddr;
24424 s64 kernel_ns, max_kernel_ns;
24425 u64 tsc_timestamp, host_tsc;
24426- struct pvclock_vcpu_time_info *guest_hv_clock;
24427+ struct pvclock_vcpu_time_info guest_hv_clock;
24428 u8 pvclock_flags;
24429 bool use_master_clock;
24430
24431@@ -1465,7 +1464,7 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
24432
24433 local_irq_restore(flags);
24434
24435- if (!vcpu->time_page)
24436+ if (!vcpu->pv_time_enabled)
24437 return 0;
24438
24439 /*
24440@@ -1527,12 +1526,12 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
24441 */
24442 vcpu->hv_clock.version += 2;
24443
24444- shared_kaddr = kmap_atomic(vcpu->time_page);
24445-
24446- guest_hv_clock = shared_kaddr + vcpu->time_offset;
24447+ if (unlikely(kvm_read_guest_cached(v->kvm, &vcpu->pv_time,
24448+ &guest_hv_clock, sizeof(guest_hv_clock))))
24449+ return 0;
24450
24451 /* retain PVCLOCK_GUEST_STOPPED if set in guest copy */
24452- pvclock_flags = (guest_hv_clock->flags & PVCLOCK_GUEST_STOPPED);
24453+ pvclock_flags = (guest_hv_clock.flags & PVCLOCK_GUEST_STOPPED);
24454
24455 if (vcpu->pvclock_set_guest_stopped_request) {
24456 pvclock_flags |= PVCLOCK_GUEST_STOPPED;
24457@@ -1545,12 +1544,9 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
24458
24459 vcpu->hv_clock.flags = pvclock_flags;
24460
24461- memcpy(shared_kaddr + vcpu->time_offset, &vcpu->hv_clock,
24462- sizeof(vcpu->hv_clock));
24463-
24464- kunmap_atomic(shared_kaddr);
24465-
24466- mark_page_dirty(v->kvm, vcpu->time >> PAGE_SHIFT);
24467+ kvm_write_guest_cached(v->kvm, &vcpu->pv_time,
24468+ &vcpu->hv_clock,
24469+ sizeof(vcpu->hv_clock));
24470 return 0;
24471 }
24472
24473@@ -1692,8 +1688,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
24474 {
24475 struct kvm *kvm = vcpu->kvm;
24476 int lm = is_long_mode(vcpu);
24477- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
24478- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
24479+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
24480+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
24481 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
24482 : kvm->arch.xen_hvm_config.blob_size_32;
24483 u32 page_num = data & ~PAGE_MASK;
24484@@ -1839,10 +1835,7 @@ static int kvm_pv_enable_async_pf(struct kvm_vcpu *vcpu, u64 data)
24485
24486 static void kvmclock_reset(struct kvm_vcpu *vcpu)
24487 {
24488- if (vcpu->arch.time_page) {
24489- kvm_release_page_dirty(vcpu->arch.time_page);
24490- vcpu->arch.time_page = NULL;
24491- }
24492+ vcpu->arch.pv_time_enabled = false;
24493 }
24494
24495 static void accumulate_steal_time(struct kvm_vcpu *vcpu)
24496@@ -1948,6 +1941,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
24497 break;
24498 case MSR_KVM_SYSTEM_TIME_NEW:
24499 case MSR_KVM_SYSTEM_TIME: {
24500+ u64 gpa_offset;
24501 kvmclock_reset(vcpu);
24502
24503 vcpu->arch.time = data;
24504@@ -1957,14 +1951,17 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
24505 if (!(data & 1))
24506 break;
24507
24508- /* ...but clean it before doing the actual write */
24509- vcpu->arch.time_offset = data & ~(PAGE_MASK | 1);
24510+ gpa_offset = data & ~(PAGE_MASK | 1);
24511
24512- vcpu->arch.time_page =
24513- gfn_to_page(vcpu->kvm, data >> PAGE_SHIFT);
24514+ /* Check that the address is 32-byte aligned. */
24515+ if (gpa_offset & (sizeof(struct pvclock_vcpu_time_info) - 1))
24516+ break;
24517
24518- if (is_error_page(vcpu->arch.time_page))
24519- vcpu->arch.time_page = NULL;
24520+ if (kvm_gfn_to_hva_cache_init(vcpu->kvm,
24521+ &vcpu->arch.pv_time, data & ~1ULL))
24522+ vcpu->arch.pv_time_enabled = false;
24523+ else
24524+ vcpu->arch.pv_time_enabled = true;
24525
24526 break;
24527 }
24528@@ -2571,6 +2568,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
24529 if (n < msr_list.nmsrs)
24530 goto out;
24531 r = -EFAULT;
24532+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
24533+ goto out;
24534 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
24535 num_msrs_to_save * sizeof(u32)))
24536 goto out;
24537@@ -2700,7 +2699,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
24538 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
24539 struct kvm_interrupt *irq)
24540 {
24541- if (irq->irq < 0 || irq->irq >= KVM_NR_INTERRUPTS)
24542+ if (irq->irq >= KVM_NR_INTERRUPTS)
24543 return -EINVAL;
24544 if (irqchip_in_kernel(vcpu->kvm))
24545 return -ENXIO;
24546@@ -2967,7 +2966,7 @@ static int kvm_vcpu_ioctl_x86_set_xcrs(struct kvm_vcpu *vcpu,
24547 */
24548 static int kvm_set_guest_paused(struct kvm_vcpu *vcpu)
24549 {
24550- if (!vcpu->arch.time_page)
24551+ if (!vcpu->arch.pv_time_enabled)
24552 return -EINVAL;
24553 vcpu->arch.pvclock_set_guest_stopped_request = true;
24554 kvm_make_request(KVM_REQ_CLOCK_UPDATE, vcpu);
24555@@ -5213,7 +5212,7 @@ static struct notifier_block pvclock_gtod_notifier = {
24556 };
24557 #endif
24558
24559-int kvm_arch_init(void *opaque)
24560+int kvm_arch_init(const void *opaque)
24561 {
24562 int r;
24563 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
24564@@ -6661,6 +6660,7 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
24565 goto fail_free_wbinvd_dirty_mask;
24566
24567 vcpu->arch.ia32_tsc_adjust_msr = 0x0;
24568+ vcpu->arch.pv_time_enabled = false;
24569 kvm_async_pf_hash_reset(vcpu);
24570 kvm_pmu_init(vcpu);
24571
24572diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
24573index 20a4fd4..d806083 100644
24574--- a/arch/x86/lguest/boot.c
24575+++ b/arch/x86/lguest/boot.c
24576@@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
24577 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
24578 * Launcher to reboot us.
24579 */
24580-static void lguest_restart(char *reason)
24581+static __noreturn void lguest_restart(char *reason)
24582 {
24583 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
24584+ BUG();
24585 }
24586
24587 /*G:050
24588diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
24589index 00933d5..3a64af9 100644
24590--- a/arch/x86/lib/atomic64_386_32.S
24591+++ b/arch/x86/lib/atomic64_386_32.S
24592@@ -48,6 +48,10 @@ BEGIN(read)
24593 movl (v), %eax
24594 movl 4(v), %edx
24595 RET_ENDP
24596+BEGIN(read_unchecked)
24597+ movl (v), %eax
24598+ movl 4(v), %edx
24599+RET_ENDP
24600 #undef v
24601
24602 #define v %esi
24603@@ -55,6 +59,10 @@ BEGIN(set)
24604 movl %ebx, (v)
24605 movl %ecx, 4(v)
24606 RET_ENDP
24607+BEGIN(set_unchecked)
24608+ movl %ebx, (v)
24609+ movl %ecx, 4(v)
24610+RET_ENDP
24611 #undef v
24612
24613 #define v %esi
24614@@ -70,6 +78,20 @@ RET_ENDP
24615 BEGIN(add)
24616 addl %eax, (v)
24617 adcl %edx, 4(v)
24618+
24619+#ifdef CONFIG_PAX_REFCOUNT
24620+ jno 0f
24621+ subl %eax, (v)
24622+ sbbl %edx, 4(v)
24623+ int $4
24624+0:
24625+ _ASM_EXTABLE(0b, 0b)
24626+#endif
24627+
24628+RET_ENDP
24629+BEGIN(add_unchecked)
24630+ addl %eax, (v)
24631+ adcl %edx, 4(v)
24632 RET_ENDP
24633 #undef v
24634
24635@@ -77,6 +99,24 @@ RET_ENDP
24636 BEGIN(add_return)
24637 addl (v), %eax
24638 adcl 4(v), %edx
24639+
24640+#ifdef CONFIG_PAX_REFCOUNT
24641+ into
24642+1234:
24643+ _ASM_EXTABLE(1234b, 2f)
24644+#endif
24645+
24646+ movl %eax, (v)
24647+ movl %edx, 4(v)
24648+
24649+#ifdef CONFIG_PAX_REFCOUNT
24650+2:
24651+#endif
24652+
24653+RET_ENDP
24654+BEGIN(add_return_unchecked)
24655+ addl (v), %eax
24656+ adcl 4(v), %edx
24657 movl %eax, (v)
24658 movl %edx, 4(v)
24659 RET_ENDP
24660@@ -86,6 +126,20 @@ RET_ENDP
24661 BEGIN(sub)
24662 subl %eax, (v)
24663 sbbl %edx, 4(v)
24664+
24665+#ifdef CONFIG_PAX_REFCOUNT
24666+ jno 0f
24667+ addl %eax, (v)
24668+ adcl %edx, 4(v)
24669+ int $4
24670+0:
24671+ _ASM_EXTABLE(0b, 0b)
24672+#endif
24673+
24674+RET_ENDP
24675+BEGIN(sub_unchecked)
24676+ subl %eax, (v)
24677+ sbbl %edx, 4(v)
24678 RET_ENDP
24679 #undef v
24680
24681@@ -96,6 +150,27 @@ BEGIN(sub_return)
24682 sbbl $0, %edx
24683 addl (v), %eax
24684 adcl 4(v), %edx
24685+
24686+#ifdef CONFIG_PAX_REFCOUNT
24687+ into
24688+1234:
24689+ _ASM_EXTABLE(1234b, 2f)
24690+#endif
24691+
24692+ movl %eax, (v)
24693+ movl %edx, 4(v)
24694+
24695+#ifdef CONFIG_PAX_REFCOUNT
24696+2:
24697+#endif
24698+
24699+RET_ENDP
24700+BEGIN(sub_return_unchecked)
24701+ negl %edx
24702+ negl %eax
24703+ sbbl $0, %edx
24704+ addl (v), %eax
24705+ adcl 4(v), %edx
24706 movl %eax, (v)
24707 movl %edx, 4(v)
24708 RET_ENDP
24709@@ -105,6 +180,20 @@ RET_ENDP
24710 BEGIN(inc)
24711 addl $1, (v)
24712 adcl $0, 4(v)
24713+
24714+#ifdef CONFIG_PAX_REFCOUNT
24715+ jno 0f
24716+ subl $1, (v)
24717+ sbbl $0, 4(v)
24718+ int $4
24719+0:
24720+ _ASM_EXTABLE(0b, 0b)
24721+#endif
24722+
24723+RET_ENDP
24724+BEGIN(inc_unchecked)
24725+ addl $1, (v)
24726+ adcl $0, 4(v)
24727 RET_ENDP
24728 #undef v
24729
24730@@ -114,6 +203,26 @@ BEGIN(inc_return)
24731 movl 4(v), %edx
24732 addl $1, %eax
24733 adcl $0, %edx
24734+
24735+#ifdef CONFIG_PAX_REFCOUNT
24736+ into
24737+1234:
24738+ _ASM_EXTABLE(1234b, 2f)
24739+#endif
24740+
24741+ movl %eax, (v)
24742+ movl %edx, 4(v)
24743+
24744+#ifdef CONFIG_PAX_REFCOUNT
24745+2:
24746+#endif
24747+
24748+RET_ENDP
24749+BEGIN(inc_return_unchecked)
24750+ movl (v), %eax
24751+ movl 4(v), %edx
24752+ addl $1, %eax
24753+ adcl $0, %edx
24754 movl %eax, (v)
24755 movl %edx, 4(v)
24756 RET_ENDP
24757@@ -123,6 +232,20 @@ RET_ENDP
24758 BEGIN(dec)
24759 subl $1, (v)
24760 sbbl $0, 4(v)
24761+
24762+#ifdef CONFIG_PAX_REFCOUNT
24763+ jno 0f
24764+ addl $1, (v)
24765+ adcl $0, 4(v)
24766+ int $4
24767+0:
24768+ _ASM_EXTABLE(0b, 0b)
24769+#endif
24770+
24771+RET_ENDP
24772+BEGIN(dec_unchecked)
24773+ subl $1, (v)
24774+ sbbl $0, 4(v)
24775 RET_ENDP
24776 #undef v
24777
24778@@ -132,6 +255,26 @@ BEGIN(dec_return)
24779 movl 4(v), %edx
24780 subl $1, %eax
24781 sbbl $0, %edx
24782+
24783+#ifdef CONFIG_PAX_REFCOUNT
24784+ into
24785+1234:
24786+ _ASM_EXTABLE(1234b, 2f)
24787+#endif
24788+
24789+ movl %eax, (v)
24790+ movl %edx, 4(v)
24791+
24792+#ifdef CONFIG_PAX_REFCOUNT
24793+2:
24794+#endif
24795+
24796+RET_ENDP
24797+BEGIN(dec_return_unchecked)
24798+ movl (v), %eax
24799+ movl 4(v), %edx
24800+ subl $1, %eax
24801+ sbbl $0, %edx
24802 movl %eax, (v)
24803 movl %edx, 4(v)
24804 RET_ENDP
24805@@ -143,6 +286,13 @@ BEGIN(add_unless)
24806 adcl %edx, %edi
24807 addl (v), %eax
24808 adcl 4(v), %edx
24809+
24810+#ifdef CONFIG_PAX_REFCOUNT
24811+ into
24812+1234:
24813+ _ASM_EXTABLE(1234b, 2f)
24814+#endif
24815+
24816 cmpl %eax, %ecx
24817 je 3f
24818 1:
24819@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
24820 1:
24821 addl $1, %eax
24822 adcl $0, %edx
24823+
24824+#ifdef CONFIG_PAX_REFCOUNT
24825+ into
24826+1234:
24827+ _ASM_EXTABLE(1234b, 2f)
24828+#endif
24829+
24830 movl %eax, (v)
24831 movl %edx, 4(v)
24832 movl $1, %eax
24833@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
24834 movl 4(v), %edx
24835 subl $1, %eax
24836 sbbl $0, %edx
24837+
24838+#ifdef CONFIG_PAX_REFCOUNT
24839+ into
24840+1234:
24841+ _ASM_EXTABLE(1234b, 1f)
24842+#endif
24843+
24844 js 1f
24845 movl %eax, (v)
24846 movl %edx, 4(v)
24847diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
24848index f5cc9eb..51fa319 100644
24849--- a/arch/x86/lib/atomic64_cx8_32.S
24850+++ b/arch/x86/lib/atomic64_cx8_32.S
24851@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
24852 CFI_STARTPROC
24853
24854 read64 %ecx
24855+ pax_force_retaddr
24856 ret
24857 CFI_ENDPROC
24858 ENDPROC(atomic64_read_cx8)
24859
24860+ENTRY(atomic64_read_unchecked_cx8)
24861+ CFI_STARTPROC
24862+
24863+ read64 %ecx
24864+ pax_force_retaddr
24865+ ret
24866+ CFI_ENDPROC
24867+ENDPROC(atomic64_read_unchecked_cx8)
24868+
24869 ENTRY(atomic64_set_cx8)
24870 CFI_STARTPROC
24871
24872@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
24873 cmpxchg8b (%esi)
24874 jne 1b
24875
24876+ pax_force_retaddr
24877 ret
24878 CFI_ENDPROC
24879 ENDPROC(atomic64_set_cx8)
24880
24881+ENTRY(atomic64_set_unchecked_cx8)
24882+ CFI_STARTPROC
24883+
24884+1:
24885+/* we don't need LOCK_PREFIX since aligned 64-bit writes
24886+ * are atomic on 586 and newer */
24887+ cmpxchg8b (%esi)
24888+ jne 1b
24889+
24890+ pax_force_retaddr
24891+ ret
24892+ CFI_ENDPROC
24893+ENDPROC(atomic64_set_unchecked_cx8)
24894+
24895 ENTRY(atomic64_xchg_cx8)
24896 CFI_STARTPROC
24897
24898@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
24899 cmpxchg8b (%esi)
24900 jne 1b
24901
24902+ pax_force_retaddr
24903 ret
24904 CFI_ENDPROC
24905 ENDPROC(atomic64_xchg_cx8)
24906
24907-.macro addsub_return func ins insc
24908-ENTRY(atomic64_\func\()_return_cx8)
24909+.macro addsub_return func ins insc unchecked=""
24910+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
24911 CFI_STARTPROC
24912 SAVE ebp
24913 SAVE ebx
24914@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
24915 movl %edx, %ecx
24916 \ins\()l %esi, %ebx
24917 \insc\()l %edi, %ecx
24918+
24919+.ifb \unchecked
24920+#ifdef CONFIG_PAX_REFCOUNT
24921+ into
24922+2:
24923+ _ASM_EXTABLE(2b, 3f)
24924+#endif
24925+.endif
24926+
24927 LOCK_PREFIX
24928 cmpxchg8b (%ebp)
24929 jne 1b
24930-
24931-10:
24932 movl %ebx, %eax
24933 movl %ecx, %edx
24934+
24935+.ifb \unchecked
24936+#ifdef CONFIG_PAX_REFCOUNT
24937+3:
24938+#endif
24939+.endif
24940+
24941 RESTORE edi
24942 RESTORE esi
24943 RESTORE ebx
24944 RESTORE ebp
24945+ pax_force_retaddr
24946 ret
24947 CFI_ENDPROC
24948-ENDPROC(atomic64_\func\()_return_cx8)
24949+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
24950 .endm
24951
24952 addsub_return add add adc
24953 addsub_return sub sub sbb
24954+addsub_return add add adc _unchecked
24955+addsub_return sub sub sbb _unchecked
24956
24957-.macro incdec_return func ins insc
24958-ENTRY(atomic64_\func\()_return_cx8)
24959+.macro incdec_return func ins insc unchecked=""
24960+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
24961 CFI_STARTPROC
24962 SAVE ebx
24963
24964@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
24965 movl %edx, %ecx
24966 \ins\()l $1, %ebx
24967 \insc\()l $0, %ecx
24968+
24969+.ifb \unchecked
24970+#ifdef CONFIG_PAX_REFCOUNT
24971+ into
24972+2:
24973+ _ASM_EXTABLE(2b, 3f)
24974+#endif
24975+.endif
24976+
24977 LOCK_PREFIX
24978 cmpxchg8b (%esi)
24979 jne 1b
24980
24981-10:
24982 movl %ebx, %eax
24983 movl %ecx, %edx
24984+
24985+.ifb \unchecked
24986+#ifdef CONFIG_PAX_REFCOUNT
24987+3:
24988+#endif
24989+.endif
24990+
24991 RESTORE ebx
24992+ pax_force_retaddr
24993 ret
24994 CFI_ENDPROC
24995-ENDPROC(atomic64_\func\()_return_cx8)
24996+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
24997 .endm
24998
24999 incdec_return inc add adc
25000 incdec_return dec sub sbb
25001+incdec_return inc add adc _unchecked
25002+incdec_return dec sub sbb _unchecked
25003
25004 ENTRY(atomic64_dec_if_positive_cx8)
25005 CFI_STARTPROC
25006@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
25007 movl %edx, %ecx
25008 subl $1, %ebx
25009 sbb $0, %ecx
25010+
25011+#ifdef CONFIG_PAX_REFCOUNT
25012+ into
25013+1234:
25014+ _ASM_EXTABLE(1234b, 2f)
25015+#endif
25016+
25017 js 2f
25018 LOCK_PREFIX
25019 cmpxchg8b (%esi)
25020@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
25021 movl %ebx, %eax
25022 movl %ecx, %edx
25023 RESTORE ebx
25024+ pax_force_retaddr
25025 ret
25026 CFI_ENDPROC
25027 ENDPROC(atomic64_dec_if_positive_cx8)
25028@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
25029 movl %edx, %ecx
25030 addl %ebp, %ebx
25031 adcl %edi, %ecx
25032+
25033+#ifdef CONFIG_PAX_REFCOUNT
25034+ into
25035+1234:
25036+ _ASM_EXTABLE(1234b, 3f)
25037+#endif
25038+
25039 LOCK_PREFIX
25040 cmpxchg8b (%esi)
25041 jne 1b
25042@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
25043 CFI_ADJUST_CFA_OFFSET -8
25044 RESTORE ebx
25045 RESTORE ebp
25046+ pax_force_retaddr
25047 ret
25048 4:
25049 cmpl %edx, 4(%esp)
25050@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
25051 xorl %ecx, %ecx
25052 addl $1, %ebx
25053 adcl %edx, %ecx
25054+
25055+#ifdef CONFIG_PAX_REFCOUNT
25056+ into
25057+1234:
25058+ _ASM_EXTABLE(1234b, 3f)
25059+#endif
25060+
25061 LOCK_PREFIX
25062 cmpxchg8b (%esi)
25063 jne 1b
25064@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
25065 movl $1, %eax
25066 3:
25067 RESTORE ebx
25068+ pax_force_retaddr
25069 ret
25070 CFI_ENDPROC
25071 ENDPROC(atomic64_inc_not_zero_cx8)
25072diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
25073index 2af5df3..62b1a5a 100644
25074--- a/arch/x86/lib/checksum_32.S
25075+++ b/arch/x86/lib/checksum_32.S
25076@@ -29,7 +29,8 @@
25077 #include <asm/dwarf2.h>
25078 #include <asm/errno.h>
25079 #include <asm/asm.h>
25080-
25081+#include <asm/segment.h>
25082+
25083 /*
25084 * computes a partial checksum, e.g. for TCP/UDP fragments
25085 */
25086@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
25087
25088 #define ARGBASE 16
25089 #define FP 12
25090-
25091-ENTRY(csum_partial_copy_generic)
25092+
25093+ENTRY(csum_partial_copy_generic_to_user)
25094 CFI_STARTPROC
25095+
25096+#ifdef CONFIG_PAX_MEMORY_UDEREF
25097+ pushl_cfi %gs
25098+ popl_cfi %es
25099+ jmp csum_partial_copy_generic
25100+#endif
25101+
25102+ENTRY(csum_partial_copy_generic_from_user)
25103+
25104+#ifdef CONFIG_PAX_MEMORY_UDEREF
25105+ pushl_cfi %gs
25106+ popl_cfi %ds
25107+#endif
25108+
25109+ENTRY(csum_partial_copy_generic)
25110 subl $4,%esp
25111 CFI_ADJUST_CFA_OFFSET 4
25112 pushl_cfi %edi
25113@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
25114 jmp 4f
25115 SRC(1: movw (%esi), %bx )
25116 addl $2, %esi
25117-DST( movw %bx, (%edi) )
25118+DST( movw %bx, %es:(%edi) )
25119 addl $2, %edi
25120 addw %bx, %ax
25121 adcl $0, %eax
25122@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
25123 SRC(1: movl (%esi), %ebx )
25124 SRC( movl 4(%esi), %edx )
25125 adcl %ebx, %eax
25126-DST( movl %ebx, (%edi) )
25127+DST( movl %ebx, %es:(%edi) )
25128 adcl %edx, %eax
25129-DST( movl %edx, 4(%edi) )
25130+DST( movl %edx, %es:4(%edi) )
25131
25132 SRC( movl 8(%esi), %ebx )
25133 SRC( movl 12(%esi), %edx )
25134 adcl %ebx, %eax
25135-DST( movl %ebx, 8(%edi) )
25136+DST( movl %ebx, %es:8(%edi) )
25137 adcl %edx, %eax
25138-DST( movl %edx, 12(%edi) )
25139+DST( movl %edx, %es:12(%edi) )
25140
25141 SRC( movl 16(%esi), %ebx )
25142 SRC( movl 20(%esi), %edx )
25143 adcl %ebx, %eax
25144-DST( movl %ebx, 16(%edi) )
25145+DST( movl %ebx, %es:16(%edi) )
25146 adcl %edx, %eax
25147-DST( movl %edx, 20(%edi) )
25148+DST( movl %edx, %es:20(%edi) )
25149
25150 SRC( movl 24(%esi), %ebx )
25151 SRC( movl 28(%esi), %edx )
25152 adcl %ebx, %eax
25153-DST( movl %ebx, 24(%edi) )
25154+DST( movl %ebx, %es:24(%edi) )
25155 adcl %edx, %eax
25156-DST( movl %edx, 28(%edi) )
25157+DST( movl %edx, %es:28(%edi) )
25158
25159 lea 32(%esi), %esi
25160 lea 32(%edi), %edi
25161@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
25162 shrl $2, %edx # This clears CF
25163 SRC(3: movl (%esi), %ebx )
25164 adcl %ebx, %eax
25165-DST( movl %ebx, (%edi) )
25166+DST( movl %ebx, %es:(%edi) )
25167 lea 4(%esi), %esi
25168 lea 4(%edi), %edi
25169 dec %edx
25170@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
25171 jb 5f
25172 SRC( movw (%esi), %cx )
25173 leal 2(%esi), %esi
25174-DST( movw %cx, (%edi) )
25175+DST( movw %cx, %es:(%edi) )
25176 leal 2(%edi), %edi
25177 je 6f
25178 shll $16,%ecx
25179 SRC(5: movb (%esi), %cl )
25180-DST( movb %cl, (%edi) )
25181+DST( movb %cl, %es:(%edi) )
25182 6: addl %ecx, %eax
25183 adcl $0, %eax
25184 7:
25185@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
25186
25187 6001:
25188 movl ARGBASE+20(%esp), %ebx # src_err_ptr
25189- movl $-EFAULT, (%ebx)
25190+ movl $-EFAULT, %ss:(%ebx)
25191
25192 # zero the complete destination - computing the rest
25193 # is too much work
25194@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
25195
25196 6002:
25197 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
25198- movl $-EFAULT,(%ebx)
25199+ movl $-EFAULT,%ss:(%ebx)
25200 jmp 5000b
25201
25202 .previous
25203
25204+ pushl_cfi %ss
25205+ popl_cfi %ds
25206+ pushl_cfi %ss
25207+ popl_cfi %es
25208 popl_cfi %ebx
25209 CFI_RESTORE ebx
25210 popl_cfi %esi
25211@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
25212 popl_cfi %ecx # equivalent to addl $4,%esp
25213 ret
25214 CFI_ENDPROC
25215-ENDPROC(csum_partial_copy_generic)
25216+ENDPROC(csum_partial_copy_generic_to_user)
25217
25218 #else
25219
25220 /* Version for PentiumII/PPro */
25221
25222 #define ROUND1(x) \
25223+ nop; nop; nop; \
25224 SRC(movl x(%esi), %ebx ) ; \
25225 addl %ebx, %eax ; \
25226- DST(movl %ebx, x(%edi) ) ;
25227+ DST(movl %ebx, %es:x(%edi)) ;
25228
25229 #define ROUND(x) \
25230+ nop; nop; nop; \
25231 SRC(movl x(%esi), %ebx ) ; \
25232 adcl %ebx, %eax ; \
25233- DST(movl %ebx, x(%edi) ) ;
25234+ DST(movl %ebx, %es:x(%edi)) ;
25235
25236 #define ARGBASE 12
25237-
25238-ENTRY(csum_partial_copy_generic)
25239+
25240+ENTRY(csum_partial_copy_generic_to_user)
25241 CFI_STARTPROC
25242+
25243+#ifdef CONFIG_PAX_MEMORY_UDEREF
25244+ pushl_cfi %gs
25245+ popl_cfi %es
25246+ jmp csum_partial_copy_generic
25247+#endif
25248+
25249+ENTRY(csum_partial_copy_generic_from_user)
25250+
25251+#ifdef CONFIG_PAX_MEMORY_UDEREF
25252+ pushl_cfi %gs
25253+ popl_cfi %ds
25254+#endif
25255+
25256+ENTRY(csum_partial_copy_generic)
25257 pushl_cfi %ebx
25258 CFI_REL_OFFSET ebx, 0
25259 pushl_cfi %edi
25260@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
25261 subl %ebx, %edi
25262 lea -1(%esi),%edx
25263 andl $-32,%edx
25264- lea 3f(%ebx,%ebx), %ebx
25265+ lea 3f(%ebx,%ebx,2), %ebx
25266 testl %esi, %esi
25267 jmp *%ebx
25268 1: addl $64,%esi
25269@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
25270 jb 5f
25271 SRC( movw (%esi), %dx )
25272 leal 2(%esi), %esi
25273-DST( movw %dx, (%edi) )
25274+DST( movw %dx, %es:(%edi) )
25275 leal 2(%edi), %edi
25276 je 6f
25277 shll $16,%edx
25278 5:
25279 SRC( movb (%esi), %dl )
25280-DST( movb %dl, (%edi) )
25281+DST( movb %dl, %es:(%edi) )
25282 6: addl %edx, %eax
25283 adcl $0, %eax
25284 7:
25285 .section .fixup, "ax"
25286 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
25287- movl $-EFAULT, (%ebx)
25288+ movl $-EFAULT, %ss:(%ebx)
25289 # zero the complete destination (computing the rest is too much work)
25290 movl ARGBASE+8(%esp),%edi # dst
25291 movl ARGBASE+12(%esp),%ecx # len
25292@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
25293 rep; stosb
25294 jmp 7b
25295 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
25296- movl $-EFAULT, (%ebx)
25297+ movl $-EFAULT, %ss:(%ebx)
25298 jmp 7b
25299 .previous
25300
25301+#ifdef CONFIG_PAX_MEMORY_UDEREF
25302+ pushl_cfi %ss
25303+ popl_cfi %ds
25304+ pushl_cfi %ss
25305+ popl_cfi %es
25306+#endif
25307+
25308 popl_cfi %esi
25309 CFI_RESTORE esi
25310 popl_cfi %edi
25311@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
25312 CFI_RESTORE ebx
25313 ret
25314 CFI_ENDPROC
25315-ENDPROC(csum_partial_copy_generic)
25316+ENDPROC(csum_partial_copy_generic_to_user)
25317
25318 #undef ROUND
25319 #undef ROUND1
25320diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
25321index f2145cf..cea889d 100644
25322--- a/arch/x86/lib/clear_page_64.S
25323+++ b/arch/x86/lib/clear_page_64.S
25324@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
25325 movl $4096/8,%ecx
25326 xorl %eax,%eax
25327 rep stosq
25328+ pax_force_retaddr
25329 ret
25330 CFI_ENDPROC
25331 ENDPROC(clear_page_c)
25332@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
25333 movl $4096,%ecx
25334 xorl %eax,%eax
25335 rep stosb
25336+ pax_force_retaddr
25337 ret
25338 CFI_ENDPROC
25339 ENDPROC(clear_page_c_e)
25340@@ -43,6 +45,7 @@ ENTRY(clear_page)
25341 leaq 64(%rdi),%rdi
25342 jnz .Lloop
25343 nop
25344+ pax_force_retaddr
25345 ret
25346 CFI_ENDPROC
25347 .Lclear_page_end:
25348@@ -58,7 +61,7 @@ ENDPROC(clear_page)
25349
25350 #include <asm/cpufeature.h>
25351
25352- .section .altinstr_replacement,"ax"
25353+ .section .altinstr_replacement,"a"
25354 1: .byte 0xeb /* jmp <disp8> */
25355 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
25356 2: .byte 0xeb /* jmp <disp8> */
25357diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
25358index 1e572c5..2a162cd 100644
25359--- a/arch/x86/lib/cmpxchg16b_emu.S
25360+++ b/arch/x86/lib/cmpxchg16b_emu.S
25361@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
25362
25363 popf
25364 mov $1, %al
25365+ pax_force_retaddr
25366 ret
25367
25368 not_same:
25369 popf
25370 xor %al,%al
25371+ pax_force_retaddr
25372 ret
25373
25374 CFI_ENDPROC
25375diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
25376index 176cca6..1166c50 100644
25377--- a/arch/x86/lib/copy_page_64.S
25378+++ b/arch/x86/lib/copy_page_64.S
25379@@ -9,6 +9,7 @@ copy_page_rep:
25380 CFI_STARTPROC
25381 movl $4096/8, %ecx
25382 rep movsq
25383+ pax_force_retaddr
25384 ret
25385 CFI_ENDPROC
25386 ENDPROC(copy_page_rep)
25387@@ -20,12 +21,14 @@ ENDPROC(copy_page_rep)
25388
25389 ENTRY(copy_page)
25390 CFI_STARTPROC
25391- subq $2*8, %rsp
25392- CFI_ADJUST_CFA_OFFSET 2*8
25393+ subq $3*8, %rsp
25394+ CFI_ADJUST_CFA_OFFSET 3*8
25395 movq %rbx, (%rsp)
25396 CFI_REL_OFFSET rbx, 0
25397 movq %r12, 1*8(%rsp)
25398 CFI_REL_OFFSET r12, 1*8
25399+ movq %r13, 2*8(%rsp)
25400+ CFI_REL_OFFSET r13, 2*8
25401
25402 movl $(4096/64)-5, %ecx
25403 .p2align 4
25404@@ -36,7 +39,7 @@ ENTRY(copy_page)
25405 movq 0x8*2(%rsi), %rdx
25406 movq 0x8*3(%rsi), %r8
25407 movq 0x8*4(%rsi), %r9
25408- movq 0x8*5(%rsi), %r10
25409+ movq 0x8*5(%rsi), %r13
25410 movq 0x8*6(%rsi), %r11
25411 movq 0x8*7(%rsi), %r12
25412
25413@@ -47,7 +50,7 @@ ENTRY(copy_page)
25414 movq %rdx, 0x8*2(%rdi)
25415 movq %r8, 0x8*3(%rdi)
25416 movq %r9, 0x8*4(%rdi)
25417- movq %r10, 0x8*5(%rdi)
25418+ movq %r13, 0x8*5(%rdi)
25419 movq %r11, 0x8*6(%rdi)
25420 movq %r12, 0x8*7(%rdi)
25421
25422@@ -66,7 +69,7 @@ ENTRY(copy_page)
25423 movq 0x8*2(%rsi), %rdx
25424 movq 0x8*3(%rsi), %r8
25425 movq 0x8*4(%rsi), %r9
25426- movq 0x8*5(%rsi), %r10
25427+ movq 0x8*5(%rsi), %r13
25428 movq 0x8*6(%rsi), %r11
25429 movq 0x8*7(%rsi), %r12
25430
25431@@ -75,7 +78,7 @@ ENTRY(copy_page)
25432 movq %rdx, 0x8*2(%rdi)
25433 movq %r8, 0x8*3(%rdi)
25434 movq %r9, 0x8*4(%rdi)
25435- movq %r10, 0x8*5(%rdi)
25436+ movq %r13, 0x8*5(%rdi)
25437 movq %r11, 0x8*6(%rdi)
25438 movq %r12, 0x8*7(%rdi)
25439
25440@@ -87,8 +90,11 @@ ENTRY(copy_page)
25441 CFI_RESTORE rbx
25442 movq 1*8(%rsp), %r12
25443 CFI_RESTORE r12
25444- addq $2*8, %rsp
25445- CFI_ADJUST_CFA_OFFSET -2*8
25446+ movq 2*8(%rsp), %r13
25447+ CFI_RESTORE r13
25448+ addq $3*8, %rsp
25449+ CFI_ADJUST_CFA_OFFSET -3*8
25450+ pax_force_retaddr
25451 ret
25452 .Lcopy_page_end:
25453 CFI_ENDPROC
25454@@ -99,7 +105,7 @@ ENDPROC(copy_page)
25455
25456 #include <asm/cpufeature.h>
25457
25458- .section .altinstr_replacement,"ax"
25459+ .section .altinstr_replacement,"a"
25460 1: .byte 0xeb /* jmp <disp8> */
25461 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
25462 2:
25463diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
25464index a30ca15..d25fab6 100644
25465--- a/arch/x86/lib/copy_user_64.S
25466+++ b/arch/x86/lib/copy_user_64.S
25467@@ -18,6 +18,7 @@
25468 #include <asm/alternative-asm.h>
25469 #include <asm/asm.h>
25470 #include <asm/smap.h>
25471+#include <asm/pgtable.h>
25472
25473 /*
25474 * By placing feature2 after feature1 in altinstructions section, we logically
25475@@ -31,7 +32,7 @@
25476 .byte 0xe9 /* 32bit jump */
25477 .long \orig-1f /* by default jump to orig */
25478 1:
25479- .section .altinstr_replacement,"ax"
25480+ .section .altinstr_replacement,"a"
25481 2: .byte 0xe9 /* near jump with 32bit immediate */
25482 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
25483 3: .byte 0xe9 /* near jump with 32bit immediate */
25484@@ -70,47 +71,20 @@
25485 #endif
25486 .endm
25487
25488-/* Standard copy_to_user with segment limit checking */
25489-ENTRY(_copy_to_user)
25490- CFI_STARTPROC
25491- GET_THREAD_INFO(%rax)
25492- movq %rdi,%rcx
25493- addq %rdx,%rcx
25494- jc bad_to_user
25495- cmpq TI_addr_limit(%rax),%rcx
25496- ja bad_to_user
25497- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
25498- copy_user_generic_unrolled,copy_user_generic_string, \
25499- copy_user_enhanced_fast_string
25500- CFI_ENDPROC
25501-ENDPROC(_copy_to_user)
25502-
25503-/* Standard copy_from_user with segment limit checking */
25504-ENTRY(_copy_from_user)
25505- CFI_STARTPROC
25506- GET_THREAD_INFO(%rax)
25507- movq %rsi,%rcx
25508- addq %rdx,%rcx
25509- jc bad_from_user
25510- cmpq TI_addr_limit(%rax),%rcx
25511- ja bad_from_user
25512- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
25513- copy_user_generic_unrolled,copy_user_generic_string, \
25514- copy_user_enhanced_fast_string
25515- CFI_ENDPROC
25516-ENDPROC(_copy_from_user)
25517-
25518 .section .fixup,"ax"
25519 /* must zero dest */
25520 ENTRY(bad_from_user)
25521 bad_from_user:
25522 CFI_STARTPROC
25523+ testl %edx,%edx
25524+ js bad_to_user
25525 movl %edx,%ecx
25526 xorl %eax,%eax
25527 rep
25528 stosb
25529 bad_to_user:
25530 movl %edx,%eax
25531+ pax_force_retaddr
25532 ret
25533 CFI_ENDPROC
25534 ENDPROC(bad_from_user)
25535@@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
25536 jz 17f
25537 1: movq (%rsi),%r8
25538 2: movq 1*8(%rsi),%r9
25539-3: movq 2*8(%rsi),%r10
25540+3: movq 2*8(%rsi),%rax
25541 4: movq 3*8(%rsi),%r11
25542 5: movq %r8,(%rdi)
25543 6: movq %r9,1*8(%rdi)
25544-7: movq %r10,2*8(%rdi)
25545+7: movq %rax,2*8(%rdi)
25546 8: movq %r11,3*8(%rdi)
25547 9: movq 4*8(%rsi),%r8
25548 10: movq 5*8(%rsi),%r9
25549-11: movq 6*8(%rsi),%r10
25550+11: movq 6*8(%rsi),%rax
25551 12: movq 7*8(%rsi),%r11
25552 13: movq %r8,4*8(%rdi)
25553 14: movq %r9,5*8(%rdi)
25554-15: movq %r10,6*8(%rdi)
25555+15: movq %rax,6*8(%rdi)
25556 16: movq %r11,7*8(%rdi)
25557 leaq 64(%rsi),%rsi
25558 leaq 64(%rdi),%rdi
25559@@ -180,6 +154,7 @@ ENTRY(copy_user_generic_unrolled)
25560 jnz 21b
25561 23: xor %eax,%eax
25562 ASM_CLAC
25563+ pax_force_retaddr
25564 ret
25565
25566 .section .fixup,"ax"
25567@@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
25568 movsb
25569 4: xorl %eax,%eax
25570 ASM_CLAC
25571+ pax_force_retaddr
25572 ret
25573
25574 .section .fixup,"ax"
25575@@ -286,6 +262,7 @@ ENTRY(copy_user_enhanced_fast_string)
25576 movsb
25577 2: xorl %eax,%eax
25578 ASM_CLAC
25579+ pax_force_retaddr
25580 ret
25581
25582 .section .fixup,"ax"
25583diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
25584index 6a4f43c..f5f9e26 100644
25585--- a/arch/x86/lib/copy_user_nocache_64.S
25586+++ b/arch/x86/lib/copy_user_nocache_64.S
25587@@ -8,6 +8,7 @@
25588
25589 #include <linux/linkage.h>
25590 #include <asm/dwarf2.h>
25591+#include <asm/alternative-asm.h>
25592
25593 #define FIX_ALIGNMENT 1
25594
25595@@ -16,6 +17,7 @@
25596 #include <asm/thread_info.h>
25597 #include <asm/asm.h>
25598 #include <asm/smap.h>
25599+#include <asm/pgtable.h>
25600
25601 .macro ALIGN_DESTINATION
25602 #ifdef FIX_ALIGNMENT
25603@@ -49,6 +51,15 @@
25604 */
25605 ENTRY(__copy_user_nocache)
25606 CFI_STARTPROC
25607+
25608+#ifdef CONFIG_PAX_MEMORY_UDEREF
25609+ mov $PAX_USER_SHADOW_BASE,%rcx
25610+ cmp %rcx,%rsi
25611+ jae 1f
25612+ add %rcx,%rsi
25613+1:
25614+#endif
25615+
25616 ASM_STAC
25617 cmpl $8,%edx
25618 jb 20f /* less then 8 bytes, go to byte copy loop */
25619@@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
25620 jz 17f
25621 1: movq (%rsi),%r8
25622 2: movq 1*8(%rsi),%r9
25623-3: movq 2*8(%rsi),%r10
25624+3: movq 2*8(%rsi),%rax
25625 4: movq 3*8(%rsi),%r11
25626 5: movnti %r8,(%rdi)
25627 6: movnti %r9,1*8(%rdi)
25628-7: movnti %r10,2*8(%rdi)
25629+7: movnti %rax,2*8(%rdi)
25630 8: movnti %r11,3*8(%rdi)
25631 9: movq 4*8(%rsi),%r8
25632 10: movq 5*8(%rsi),%r9
25633-11: movq 6*8(%rsi),%r10
25634+11: movq 6*8(%rsi),%rax
25635 12: movq 7*8(%rsi),%r11
25636 13: movnti %r8,4*8(%rdi)
25637 14: movnti %r9,5*8(%rdi)
25638-15: movnti %r10,6*8(%rdi)
25639+15: movnti %rax,6*8(%rdi)
25640 16: movnti %r11,7*8(%rdi)
25641 leaq 64(%rsi),%rsi
25642 leaq 64(%rdi),%rdi
25643@@ -99,6 +110,7 @@ ENTRY(__copy_user_nocache)
25644 23: xorl %eax,%eax
25645 ASM_CLAC
25646 sfence
25647+ pax_force_retaddr
25648 ret
25649
25650 .section .fixup,"ax"
25651diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
25652index 2419d5f..953ee51 100644
25653--- a/arch/x86/lib/csum-copy_64.S
25654+++ b/arch/x86/lib/csum-copy_64.S
25655@@ -9,6 +9,7 @@
25656 #include <asm/dwarf2.h>
25657 #include <asm/errno.h>
25658 #include <asm/asm.h>
25659+#include <asm/alternative-asm.h>
25660
25661 /*
25662 * Checksum copy with exception handling.
25663@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
25664 CFI_RESTORE rbp
25665 addq $7*8, %rsp
25666 CFI_ADJUST_CFA_OFFSET -7*8
25667+ pax_force_retaddr 0, 1
25668 ret
25669 CFI_RESTORE_STATE
25670
25671diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
25672index 25b7ae8..169fafc 100644
25673--- a/arch/x86/lib/csum-wrappers_64.c
25674+++ b/arch/x86/lib/csum-wrappers_64.c
25675@@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
25676 len -= 2;
25677 }
25678 }
25679- isum = csum_partial_copy_generic((__force const void *)src,
25680+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
25681 dst, len, isum, errp, NULL);
25682 if (unlikely(*errp))
25683 goto out_err;
25684@@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
25685 }
25686
25687 *errp = 0;
25688- return csum_partial_copy_generic(src, (void __force *)dst,
25689+ return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
25690 len, isum, NULL, errp);
25691 }
25692 EXPORT_SYMBOL(csum_partial_copy_to_user);
25693diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
25694index 156b9c8..b144132 100644
25695--- a/arch/x86/lib/getuser.S
25696+++ b/arch/x86/lib/getuser.S
25697@@ -34,17 +34,40 @@
25698 #include <asm/thread_info.h>
25699 #include <asm/asm.h>
25700 #include <asm/smap.h>
25701+#include <asm/segment.h>
25702+#include <asm/pgtable.h>
25703+#include <asm/alternative-asm.h>
25704+
25705+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
25706+#define __copyuser_seg gs;
25707+#else
25708+#define __copyuser_seg
25709+#endif
25710
25711 .text
25712 ENTRY(__get_user_1)
25713 CFI_STARTPROC
25714+
25715+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25716 GET_THREAD_INFO(%_ASM_DX)
25717 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25718 jae bad_get_user
25719 ASM_STAC
25720-1: movzb (%_ASM_AX),%edx
25721+
25722+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25723+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
25724+ cmp %_ASM_DX,%_ASM_AX
25725+ jae 1234f
25726+ add %_ASM_DX,%_ASM_AX
25727+1234:
25728+#endif
25729+
25730+#endif
25731+
25732+1: __copyuser_seg movzb (%_ASM_AX),%edx
25733 xor %eax,%eax
25734 ASM_CLAC
25735+ pax_force_retaddr
25736 ret
25737 CFI_ENDPROC
25738 ENDPROC(__get_user_1)
25739@@ -52,14 +75,28 @@ ENDPROC(__get_user_1)
25740 ENTRY(__get_user_2)
25741 CFI_STARTPROC
25742 add $1,%_ASM_AX
25743+
25744+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25745 jc bad_get_user
25746 GET_THREAD_INFO(%_ASM_DX)
25747 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25748 jae bad_get_user
25749 ASM_STAC
25750-2: movzwl -1(%_ASM_AX),%edx
25751+
25752+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25753+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
25754+ cmp %_ASM_DX,%_ASM_AX
25755+ jae 1234f
25756+ add %_ASM_DX,%_ASM_AX
25757+1234:
25758+#endif
25759+
25760+#endif
25761+
25762+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
25763 xor %eax,%eax
25764 ASM_CLAC
25765+ pax_force_retaddr
25766 ret
25767 CFI_ENDPROC
25768 ENDPROC(__get_user_2)
25769@@ -67,14 +104,28 @@ ENDPROC(__get_user_2)
25770 ENTRY(__get_user_4)
25771 CFI_STARTPROC
25772 add $3,%_ASM_AX
25773+
25774+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25775 jc bad_get_user
25776 GET_THREAD_INFO(%_ASM_DX)
25777 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25778 jae bad_get_user
25779 ASM_STAC
25780-3: mov -3(%_ASM_AX),%edx
25781+
25782+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25783+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
25784+ cmp %_ASM_DX,%_ASM_AX
25785+ jae 1234f
25786+ add %_ASM_DX,%_ASM_AX
25787+1234:
25788+#endif
25789+
25790+#endif
25791+
25792+3: __copyuser_seg mov -3(%_ASM_AX),%edx
25793 xor %eax,%eax
25794 ASM_CLAC
25795+ pax_force_retaddr
25796 ret
25797 CFI_ENDPROC
25798 ENDPROC(__get_user_4)
25799@@ -87,10 +138,20 @@ ENTRY(__get_user_8)
25800 GET_THREAD_INFO(%_ASM_DX)
25801 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25802 jae bad_get_user
25803+
25804+#ifdef CONFIG_PAX_MEMORY_UDEREF
25805+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
25806+ cmp %_ASM_DX,%_ASM_AX
25807+ jae 1234f
25808+ add %_ASM_DX,%_ASM_AX
25809+1234:
25810+#endif
25811+
25812 ASM_STAC
25813 4: movq -7(%_ASM_AX),%_ASM_DX
25814 xor %eax,%eax
25815 ASM_CLAC
25816+ pax_force_retaddr
25817 ret
25818 CFI_ENDPROC
25819 ENDPROC(__get_user_8)
25820@@ -101,6 +162,7 @@ bad_get_user:
25821 xor %edx,%edx
25822 mov $(-EFAULT),%_ASM_AX
25823 ASM_CLAC
25824+ pax_force_retaddr
25825 ret
25826 CFI_ENDPROC
25827 END(bad_get_user)
25828diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
25829index 54fcffe..7be149e 100644
25830--- a/arch/x86/lib/insn.c
25831+++ b/arch/x86/lib/insn.c
25832@@ -20,8 +20,10 @@
25833
25834 #ifdef __KERNEL__
25835 #include <linux/string.h>
25836+#include <asm/pgtable_types.h>
25837 #else
25838 #include <string.h>
25839+#define ktla_ktva(addr) addr
25840 #endif
25841 #include <asm/inat.h>
25842 #include <asm/insn.h>
25843@@ -53,8 +55,8 @@
25844 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
25845 {
25846 memset(insn, 0, sizeof(*insn));
25847- insn->kaddr = kaddr;
25848- insn->next_byte = kaddr;
25849+ insn->kaddr = ktla_ktva(kaddr);
25850+ insn->next_byte = ktla_ktva(kaddr);
25851 insn->x86_64 = x86_64 ? 1 : 0;
25852 insn->opnd_bytes = 4;
25853 if (x86_64)
25854diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
25855index 05a95e7..326f2fa 100644
25856--- a/arch/x86/lib/iomap_copy_64.S
25857+++ b/arch/x86/lib/iomap_copy_64.S
25858@@ -17,6 +17,7 @@
25859
25860 #include <linux/linkage.h>
25861 #include <asm/dwarf2.h>
25862+#include <asm/alternative-asm.h>
25863
25864 /*
25865 * override generic version in lib/iomap_copy.c
25866@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
25867 CFI_STARTPROC
25868 movl %edx,%ecx
25869 rep movsd
25870+ pax_force_retaddr
25871 ret
25872 CFI_ENDPROC
25873 ENDPROC(__iowrite32_copy)
25874diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
25875index 1c273be..da9cc0e 100644
25876--- a/arch/x86/lib/memcpy_64.S
25877+++ b/arch/x86/lib/memcpy_64.S
25878@@ -33,6 +33,7 @@
25879 rep movsq
25880 movl %edx, %ecx
25881 rep movsb
25882+ pax_force_retaddr
25883 ret
25884 .Lmemcpy_e:
25885 .previous
25886@@ -49,6 +50,7 @@
25887 movq %rdi, %rax
25888 movq %rdx, %rcx
25889 rep movsb
25890+ pax_force_retaddr
25891 ret
25892 .Lmemcpy_e_e:
25893 .previous
25894@@ -76,13 +78,13 @@ ENTRY(memcpy)
25895 */
25896 movq 0*8(%rsi), %r8
25897 movq 1*8(%rsi), %r9
25898- movq 2*8(%rsi), %r10
25899+ movq 2*8(%rsi), %rcx
25900 movq 3*8(%rsi), %r11
25901 leaq 4*8(%rsi), %rsi
25902
25903 movq %r8, 0*8(%rdi)
25904 movq %r9, 1*8(%rdi)
25905- movq %r10, 2*8(%rdi)
25906+ movq %rcx, 2*8(%rdi)
25907 movq %r11, 3*8(%rdi)
25908 leaq 4*8(%rdi), %rdi
25909 jae .Lcopy_forward_loop
25910@@ -105,12 +107,12 @@ ENTRY(memcpy)
25911 subq $0x20, %rdx
25912 movq -1*8(%rsi), %r8
25913 movq -2*8(%rsi), %r9
25914- movq -3*8(%rsi), %r10
25915+ movq -3*8(%rsi), %rcx
25916 movq -4*8(%rsi), %r11
25917 leaq -4*8(%rsi), %rsi
25918 movq %r8, -1*8(%rdi)
25919 movq %r9, -2*8(%rdi)
25920- movq %r10, -3*8(%rdi)
25921+ movq %rcx, -3*8(%rdi)
25922 movq %r11, -4*8(%rdi)
25923 leaq -4*8(%rdi), %rdi
25924 jae .Lcopy_backward_loop
25925@@ -130,12 +132,13 @@ ENTRY(memcpy)
25926 */
25927 movq 0*8(%rsi), %r8
25928 movq 1*8(%rsi), %r9
25929- movq -2*8(%rsi, %rdx), %r10
25930+ movq -2*8(%rsi, %rdx), %rcx
25931 movq -1*8(%rsi, %rdx), %r11
25932 movq %r8, 0*8(%rdi)
25933 movq %r9, 1*8(%rdi)
25934- movq %r10, -2*8(%rdi, %rdx)
25935+ movq %rcx, -2*8(%rdi, %rdx)
25936 movq %r11, -1*8(%rdi, %rdx)
25937+ pax_force_retaddr
25938 retq
25939 .p2align 4
25940 .Lless_16bytes:
25941@@ -148,6 +151,7 @@ ENTRY(memcpy)
25942 movq -1*8(%rsi, %rdx), %r9
25943 movq %r8, 0*8(%rdi)
25944 movq %r9, -1*8(%rdi, %rdx)
25945+ pax_force_retaddr
25946 retq
25947 .p2align 4
25948 .Lless_8bytes:
25949@@ -161,6 +165,7 @@ ENTRY(memcpy)
25950 movl -4(%rsi, %rdx), %r8d
25951 movl %ecx, (%rdi)
25952 movl %r8d, -4(%rdi, %rdx)
25953+ pax_force_retaddr
25954 retq
25955 .p2align 4
25956 .Lless_3bytes:
25957@@ -179,6 +184,7 @@ ENTRY(memcpy)
25958 movb %cl, (%rdi)
25959
25960 .Lend:
25961+ pax_force_retaddr
25962 retq
25963 CFI_ENDPROC
25964 ENDPROC(memcpy)
25965diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
25966index ee16461..c39c199 100644
25967--- a/arch/x86/lib/memmove_64.S
25968+++ b/arch/x86/lib/memmove_64.S
25969@@ -61,13 +61,13 @@ ENTRY(memmove)
25970 5:
25971 sub $0x20, %rdx
25972 movq 0*8(%rsi), %r11
25973- movq 1*8(%rsi), %r10
25974+ movq 1*8(%rsi), %rcx
25975 movq 2*8(%rsi), %r9
25976 movq 3*8(%rsi), %r8
25977 leaq 4*8(%rsi), %rsi
25978
25979 movq %r11, 0*8(%rdi)
25980- movq %r10, 1*8(%rdi)
25981+ movq %rcx, 1*8(%rdi)
25982 movq %r9, 2*8(%rdi)
25983 movq %r8, 3*8(%rdi)
25984 leaq 4*8(%rdi), %rdi
25985@@ -81,10 +81,10 @@ ENTRY(memmove)
25986 4:
25987 movq %rdx, %rcx
25988 movq -8(%rsi, %rdx), %r11
25989- lea -8(%rdi, %rdx), %r10
25990+ lea -8(%rdi, %rdx), %r9
25991 shrq $3, %rcx
25992 rep movsq
25993- movq %r11, (%r10)
25994+ movq %r11, (%r9)
25995 jmp 13f
25996 .Lmemmove_end_forward:
25997
25998@@ -95,14 +95,14 @@ ENTRY(memmove)
25999 7:
26000 movq %rdx, %rcx
26001 movq (%rsi), %r11
26002- movq %rdi, %r10
26003+ movq %rdi, %r9
26004 leaq -8(%rsi, %rdx), %rsi
26005 leaq -8(%rdi, %rdx), %rdi
26006 shrq $3, %rcx
26007 std
26008 rep movsq
26009 cld
26010- movq %r11, (%r10)
26011+ movq %r11, (%r9)
26012 jmp 13f
26013
26014 /*
26015@@ -127,13 +127,13 @@ ENTRY(memmove)
26016 8:
26017 subq $0x20, %rdx
26018 movq -1*8(%rsi), %r11
26019- movq -2*8(%rsi), %r10
26020+ movq -2*8(%rsi), %rcx
26021 movq -3*8(%rsi), %r9
26022 movq -4*8(%rsi), %r8
26023 leaq -4*8(%rsi), %rsi
26024
26025 movq %r11, -1*8(%rdi)
26026- movq %r10, -2*8(%rdi)
26027+ movq %rcx, -2*8(%rdi)
26028 movq %r9, -3*8(%rdi)
26029 movq %r8, -4*8(%rdi)
26030 leaq -4*8(%rdi), %rdi
26031@@ -151,11 +151,11 @@ ENTRY(memmove)
26032 * Move data from 16 bytes to 31 bytes.
26033 */
26034 movq 0*8(%rsi), %r11
26035- movq 1*8(%rsi), %r10
26036+ movq 1*8(%rsi), %rcx
26037 movq -2*8(%rsi, %rdx), %r9
26038 movq -1*8(%rsi, %rdx), %r8
26039 movq %r11, 0*8(%rdi)
26040- movq %r10, 1*8(%rdi)
26041+ movq %rcx, 1*8(%rdi)
26042 movq %r9, -2*8(%rdi, %rdx)
26043 movq %r8, -1*8(%rdi, %rdx)
26044 jmp 13f
26045@@ -167,9 +167,9 @@ ENTRY(memmove)
26046 * Move data from 8 bytes to 15 bytes.
26047 */
26048 movq 0*8(%rsi), %r11
26049- movq -1*8(%rsi, %rdx), %r10
26050+ movq -1*8(%rsi, %rdx), %r9
26051 movq %r11, 0*8(%rdi)
26052- movq %r10, -1*8(%rdi, %rdx)
26053+ movq %r9, -1*8(%rdi, %rdx)
26054 jmp 13f
26055 10:
26056 cmpq $4, %rdx
26057@@ -178,9 +178,9 @@ ENTRY(memmove)
26058 * Move data from 4 bytes to 7 bytes.
26059 */
26060 movl (%rsi), %r11d
26061- movl -4(%rsi, %rdx), %r10d
26062+ movl -4(%rsi, %rdx), %r9d
26063 movl %r11d, (%rdi)
26064- movl %r10d, -4(%rdi, %rdx)
26065+ movl %r9d, -4(%rdi, %rdx)
26066 jmp 13f
26067 11:
26068 cmp $2, %rdx
26069@@ -189,9 +189,9 @@ ENTRY(memmove)
26070 * Move data from 2 bytes to 3 bytes.
26071 */
26072 movw (%rsi), %r11w
26073- movw -2(%rsi, %rdx), %r10w
26074+ movw -2(%rsi, %rdx), %r9w
26075 movw %r11w, (%rdi)
26076- movw %r10w, -2(%rdi, %rdx)
26077+ movw %r9w, -2(%rdi, %rdx)
26078 jmp 13f
26079 12:
26080 cmp $1, %rdx
26081@@ -202,6 +202,7 @@ ENTRY(memmove)
26082 movb (%rsi), %r11b
26083 movb %r11b, (%rdi)
26084 13:
26085+ pax_force_retaddr
26086 retq
26087 CFI_ENDPROC
26088
26089@@ -210,6 +211,7 @@ ENTRY(memmove)
26090 /* Forward moving data. */
26091 movq %rdx, %rcx
26092 rep movsb
26093+ pax_force_retaddr
26094 retq
26095 .Lmemmove_end_forward_efs:
26096 .previous
26097diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
26098index 2dcb380..963660a 100644
26099--- a/arch/x86/lib/memset_64.S
26100+++ b/arch/x86/lib/memset_64.S
26101@@ -30,6 +30,7 @@
26102 movl %edx,%ecx
26103 rep stosb
26104 movq %r9,%rax
26105+ pax_force_retaddr
26106 ret
26107 .Lmemset_e:
26108 .previous
26109@@ -52,6 +53,7 @@
26110 movq %rdx,%rcx
26111 rep stosb
26112 movq %r9,%rax
26113+ pax_force_retaddr
26114 ret
26115 .Lmemset_e_e:
26116 .previous
26117@@ -59,7 +61,7 @@
26118 ENTRY(memset)
26119 ENTRY(__memset)
26120 CFI_STARTPROC
26121- movq %rdi,%r10
26122+ movq %rdi,%r11
26123
26124 /* expand byte value */
26125 movzbl %sil,%ecx
26126@@ -117,7 +119,8 @@ ENTRY(__memset)
26127 jnz .Lloop_1
26128
26129 .Lende:
26130- movq %r10,%rax
26131+ movq %r11,%rax
26132+ pax_force_retaddr
26133 ret
26134
26135 CFI_RESTORE_STATE
26136diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
26137index c9f2d9b..e7fd2c0 100644
26138--- a/arch/x86/lib/mmx_32.c
26139+++ b/arch/x86/lib/mmx_32.c
26140@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
26141 {
26142 void *p;
26143 int i;
26144+ unsigned long cr0;
26145
26146 if (unlikely(in_interrupt()))
26147 return __memcpy(to, from, len);
26148@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
26149 kernel_fpu_begin();
26150
26151 __asm__ __volatile__ (
26152- "1: prefetch (%0)\n" /* This set is 28 bytes */
26153- " prefetch 64(%0)\n"
26154- " prefetch 128(%0)\n"
26155- " prefetch 192(%0)\n"
26156- " prefetch 256(%0)\n"
26157+ "1: prefetch (%1)\n" /* This set is 28 bytes */
26158+ " prefetch 64(%1)\n"
26159+ " prefetch 128(%1)\n"
26160+ " prefetch 192(%1)\n"
26161+ " prefetch 256(%1)\n"
26162 "2: \n"
26163 ".section .fixup, \"ax\"\n"
26164- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26165+ "3: \n"
26166+
26167+#ifdef CONFIG_PAX_KERNEXEC
26168+ " movl %%cr0, %0\n"
26169+ " movl %0, %%eax\n"
26170+ " andl $0xFFFEFFFF, %%eax\n"
26171+ " movl %%eax, %%cr0\n"
26172+#endif
26173+
26174+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26175+
26176+#ifdef CONFIG_PAX_KERNEXEC
26177+ " movl %0, %%cr0\n"
26178+#endif
26179+
26180 " jmp 2b\n"
26181 ".previous\n"
26182 _ASM_EXTABLE(1b, 3b)
26183- : : "r" (from));
26184+ : "=&r" (cr0) : "r" (from) : "ax");
26185
26186 for ( ; i > 5; i--) {
26187 __asm__ __volatile__ (
26188- "1: prefetch 320(%0)\n"
26189- "2: movq (%0), %%mm0\n"
26190- " movq 8(%0), %%mm1\n"
26191- " movq 16(%0), %%mm2\n"
26192- " movq 24(%0), %%mm3\n"
26193- " movq %%mm0, (%1)\n"
26194- " movq %%mm1, 8(%1)\n"
26195- " movq %%mm2, 16(%1)\n"
26196- " movq %%mm3, 24(%1)\n"
26197- " movq 32(%0), %%mm0\n"
26198- " movq 40(%0), %%mm1\n"
26199- " movq 48(%0), %%mm2\n"
26200- " movq 56(%0), %%mm3\n"
26201- " movq %%mm0, 32(%1)\n"
26202- " movq %%mm1, 40(%1)\n"
26203- " movq %%mm2, 48(%1)\n"
26204- " movq %%mm3, 56(%1)\n"
26205+ "1: prefetch 320(%1)\n"
26206+ "2: movq (%1), %%mm0\n"
26207+ " movq 8(%1), %%mm1\n"
26208+ " movq 16(%1), %%mm2\n"
26209+ " movq 24(%1), %%mm3\n"
26210+ " movq %%mm0, (%2)\n"
26211+ " movq %%mm1, 8(%2)\n"
26212+ " movq %%mm2, 16(%2)\n"
26213+ " movq %%mm3, 24(%2)\n"
26214+ " movq 32(%1), %%mm0\n"
26215+ " movq 40(%1), %%mm1\n"
26216+ " movq 48(%1), %%mm2\n"
26217+ " movq 56(%1), %%mm3\n"
26218+ " movq %%mm0, 32(%2)\n"
26219+ " movq %%mm1, 40(%2)\n"
26220+ " movq %%mm2, 48(%2)\n"
26221+ " movq %%mm3, 56(%2)\n"
26222 ".section .fixup, \"ax\"\n"
26223- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26224+ "3:\n"
26225+
26226+#ifdef CONFIG_PAX_KERNEXEC
26227+ " movl %%cr0, %0\n"
26228+ " movl %0, %%eax\n"
26229+ " andl $0xFFFEFFFF, %%eax\n"
26230+ " movl %%eax, %%cr0\n"
26231+#endif
26232+
26233+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26234+
26235+#ifdef CONFIG_PAX_KERNEXEC
26236+ " movl %0, %%cr0\n"
26237+#endif
26238+
26239 " jmp 2b\n"
26240 ".previous\n"
26241 _ASM_EXTABLE(1b, 3b)
26242- : : "r" (from), "r" (to) : "memory");
26243+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
26244
26245 from += 64;
26246 to += 64;
26247@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
26248 static void fast_copy_page(void *to, void *from)
26249 {
26250 int i;
26251+ unsigned long cr0;
26252
26253 kernel_fpu_begin();
26254
26255@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
26256 * but that is for later. -AV
26257 */
26258 __asm__ __volatile__(
26259- "1: prefetch (%0)\n"
26260- " prefetch 64(%0)\n"
26261- " prefetch 128(%0)\n"
26262- " prefetch 192(%0)\n"
26263- " prefetch 256(%0)\n"
26264+ "1: prefetch (%1)\n"
26265+ " prefetch 64(%1)\n"
26266+ " prefetch 128(%1)\n"
26267+ " prefetch 192(%1)\n"
26268+ " prefetch 256(%1)\n"
26269 "2: \n"
26270 ".section .fixup, \"ax\"\n"
26271- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26272+ "3: \n"
26273+
26274+#ifdef CONFIG_PAX_KERNEXEC
26275+ " movl %%cr0, %0\n"
26276+ " movl %0, %%eax\n"
26277+ " andl $0xFFFEFFFF, %%eax\n"
26278+ " movl %%eax, %%cr0\n"
26279+#endif
26280+
26281+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26282+
26283+#ifdef CONFIG_PAX_KERNEXEC
26284+ " movl %0, %%cr0\n"
26285+#endif
26286+
26287 " jmp 2b\n"
26288 ".previous\n"
26289- _ASM_EXTABLE(1b, 3b) : : "r" (from));
26290+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
26291
26292 for (i = 0; i < (4096-320)/64; i++) {
26293 __asm__ __volatile__ (
26294- "1: prefetch 320(%0)\n"
26295- "2: movq (%0), %%mm0\n"
26296- " movntq %%mm0, (%1)\n"
26297- " movq 8(%0), %%mm1\n"
26298- " movntq %%mm1, 8(%1)\n"
26299- " movq 16(%0), %%mm2\n"
26300- " movntq %%mm2, 16(%1)\n"
26301- " movq 24(%0), %%mm3\n"
26302- " movntq %%mm3, 24(%1)\n"
26303- " movq 32(%0), %%mm4\n"
26304- " movntq %%mm4, 32(%1)\n"
26305- " movq 40(%0), %%mm5\n"
26306- " movntq %%mm5, 40(%1)\n"
26307- " movq 48(%0), %%mm6\n"
26308- " movntq %%mm6, 48(%1)\n"
26309- " movq 56(%0), %%mm7\n"
26310- " movntq %%mm7, 56(%1)\n"
26311+ "1: prefetch 320(%1)\n"
26312+ "2: movq (%1), %%mm0\n"
26313+ " movntq %%mm0, (%2)\n"
26314+ " movq 8(%1), %%mm1\n"
26315+ " movntq %%mm1, 8(%2)\n"
26316+ " movq 16(%1), %%mm2\n"
26317+ " movntq %%mm2, 16(%2)\n"
26318+ " movq 24(%1), %%mm3\n"
26319+ " movntq %%mm3, 24(%2)\n"
26320+ " movq 32(%1), %%mm4\n"
26321+ " movntq %%mm4, 32(%2)\n"
26322+ " movq 40(%1), %%mm5\n"
26323+ " movntq %%mm5, 40(%2)\n"
26324+ " movq 48(%1), %%mm6\n"
26325+ " movntq %%mm6, 48(%2)\n"
26326+ " movq 56(%1), %%mm7\n"
26327+ " movntq %%mm7, 56(%2)\n"
26328 ".section .fixup, \"ax\"\n"
26329- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26330+ "3:\n"
26331+
26332+#ifdef CONFIG_PAX_KERNEXEC
26333+ " movl %%cr0, %0\n"
26334+ " movl %0, %%eax\n"
26335+ " andl $0xFFFEFFFF, %%eax\n"
26336+ " movl %%eax, %%cr0\n"
26337+#endif
26338+
26339+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26340+
26341+#ifdef CONFIG_PAX_KERNEXEC
26342+ " movl %0, %%cr0\n"
26343+#endif
26344+
26345 " jmp 2b\n"
26346 ".previous\n"
26347- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
26348+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
26349
26350 from += 64;
26351 to += 64;
26352@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
26353 static void fast_copy_page(void *to, void *from)
26354 {
26355 int i;
26356+ unsigned long cr0;
26357
26358 kernel_fpu_begin();
26359
26360 __asm__ __volatile__ (
26361- "1: prefetch (%0)\n"
26362- " prefetch 64(%0)\n"
26363- " prefetch 128(%0)\n"
26364- " prefetch 192(%0)\n"
26365- " prefetch 256(%0)\n"
26366+ "1: prefetch (%1)\n"
26367+ " prefetch 64(%1)\n"
26368+ " prefetch 128(%1)\n"
26369+ " prefetch 192(%1)\n"
26370+ " prefetch 256(%1)\n"
26371 "2: \n"
26372 ".section .fixup, \"ax\"\n"
26373- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26374+ "3: \n"
26375+
26376+#ifdef CONFIG_PAX_KERNEXEC
26377+ " movl %%cr0, %0\n"
26378+ " movl %0, %%eax\n"
26379+ " andl $0xFFFEFFFF, %%eax\n"
26380+ " movl %%eax, %%cr0\n"
26381+#endif
26382+
26383+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26384+
26385+#ifdef CONFIG_PAX_KERNEXEC
26386+ " movl %0, %%cr0\n"
26387+#endif
26388+
26389 " jmp 2b\n"
26390 ".previous\n"
26391- _ASM_EXTABLE(1b, 3b) : : "r" (from));
26392+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
26393
26394 for (i = 0; i < 4096/64; i++) {
26395 __asm__ __volatile__ (
26396- "1: prefetch 320(%0)\n"
26397- "2: movq (%0), %%mm0\n"
26398- " movq 8(%0), %%mm1\n"
26399- " movq 16(%0), %%mm2\n"
26400- " movq 24(%0), %%mm3\n"
26401- " movq %%mm0, (%1)\n"
26402- " movq %%mm1, 8(%1)\n"
26403- " movq %%mm2, 16(%1)\n"
26404- " movq %%mm3, 24(%1)\n"
26405- " movq 32(%0), %%mm0\n"
26406- " movq 40(%0), %%mm1\n"
26407- " movq 48(%0), %%mm2\n"
26408- " movq 56(%0), %%mm3\n"
26409- " movq %%mm0, 32(%1)\n"
26410- " movq %%mm1, 40(%1)\n"
26411- " movq %%mm2, 48(%1)\n"
26412- " movq %%mm3, 56(%1)\n"
26413+ "1: prefetch 320(%1)\n"
26414+ "2: movq (%1), %%mm0\n"
26415+ " movq 8(%1), %%mm1\n"
26416+ " movq 16(%1), %%mm2\n"
26417+ " movq 24(%1), %%mm3\n"
26418+ " movq %%mm0, (%2)\n"
26419+ " movq %%mm1, 8(%2)\n"
26420+ " movq %%mm2, 16(%2)\n"
26421+ " movq %%mm3, 24(%2)\n"
26422+ " movq 32(%1), %%mm0\n"
26423+ " movq 40(%1), %%mm1\n"
26424+ " movq 48(%1), %%mm2\n"
26425+ " movq 56(%1), %%mm3\n"
26426+ " movq %%mm0, 32(%2)\n"
26427+ " movq %%mm1, 40(%2)\n"
26428+ " movq %%mm2, 48(%2)\n"
26429+ " movq %%mm3, 56(%2)\n"
26430 ".section .fixup, \"ax\"\n"
26431- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26432+ "3:\n"
26433+
26434+#ifdef CONFIG_PAX_KERNEXEC
26435+ " movl %%cr0, %0\n"
26436+ " movl %0, %%eax\n"
26437+ " andl $0xFFFEFFFF, %%eax\n"
26438+ " movl %%eax, %%cr0\n"
26439+#endif
26440+
26441+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26442+
26443+#ifdef CONFIG_PAX_KERNEXEC
26444+ " movl %0, %%cr0\n"
26445+#endif
26446+
26447 " jmp 2b\n"
26448 ".previous\n"
26449 _ASM_EXTABLE(1b, 3b)
26450- : : "r" (from), "r" (to) : "memory");
26451+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
26452
26453 from += 64;
26454 to += 64;
26455diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
26456index f6d13ee..aca5f0b 100644
26457--- a/arch/x86/lib/msr-reg.S
26458+++ b/arch/x86/lib/msr-reg.S
26459@@ -3,6 +3,7 @@
26460 #include <asm/dwarf2.h>
26461 #include <asm/asm.h>
26462 #include <asm/msr.h>
26463+#include <asm/alternative-asm.h>
26464
26465 #ifdef CONFIG_X86_64
26466 /*
26467@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
26468 CFI_STARTPROC
26469 pushq_cfi %rbx
26470 pushq_cfi %rbp
26471- movq %rdi, %r10 /* Save pointer */
26472+ movq %rdi, %r9 /* Save pointer */
26473 xorl %r11d, %r11d /* Return value */
26474 movl (%rdi), %eax
26475 movl 4(%rdi), %ecx
26476@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
26477 movl 28(%rdi), %edi
26478 CFI_REMEMBER_STATE
26479 1: \op
26480-2: movl %eax, (%r10)
26481+2: movl %eax, (%r9)
26482 movl %r11d, %eax /* Return value */
26483- movl %ecx, 4(%r10)
26484- movl %edx, 8(%r10)
26485- movl %ebx, 12(%r10)
26486- movl %ebp, 20(%r10)
26487- movl %esi, 24(%r10)
26488- movl %edi, 28(%r10)
26489+ movl %ecx, 4(%r9)
26490+ movl %edx, 8(%r9)
26491+ movl %ebx, 12(%r9)
26492+ movl %ebp, 20(%r9)
26493+ movl %esi, 24(%r9)
26494+ movl %edi, 28(%r9)
26495 popq_cfi %rbp
26496 popq_cfi %rbx
26497+ pax_force_retaddr
26498 ret
26499 3:
26500 CFI_RESTORE_STATE
26501diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
26502index fc6ba17..04471c5 100644
26503--- a/arch/x86/lib/putuser.S
26504+++ b/arch/x86/lib/putuser.S
26505@@ -16,7 +16,9 @@
26506 #include <asm/errno.h>
26507 #include <asm/asm.h>
26508 #include <asm/smap.h>
26509-
26510+#include <asm/segment.h>
26511+#include <asm/pgtable.h>
26512+#include <asm/alternative-asm.h>
26513
26514 /*
26515 * __put_user_X
26516@@ -30,57 +32,125 @@
26517 * as they get called from within inline assembly.
26518 */
26519
26520-#define ENTER CFI_STARTPROC ; \
26521- GET_THREAD_INFO(%_ASM_BX)
26522-#define EXIT ASM_CLAC ; \
26523- ret ; \
26524+#define ENTER CFI_STARTPROC
26525+#define EXIT ASM_CLAC ; \
26526+ pax_force_retaddr ; \
26527+ ret ; \
26528 CFI_ENDPROC
26529
26530+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26531+#define _DEST %_ASM_CX,%_ASM_BX
26532+#else
26533+#define _DEST %_ASM_CX
26534+#endif
26535+
26536+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
26537+#define __copyuser_seg gs;
26538+#else
26539+#define __copyuser_seg
26540+#endif
26541+
26542 .text
26543 ENTRY(__put_user_1)
26544 ENTER
26545+
26546+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26547+ GET_THREAD_INFO(%_ASM_BX)
26548 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
26549 jae bad_put_user
26550 ASM_STAC
26551-1: movb %al,(%_ASM_CX)
26552+
26553+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26554+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
26555+ cmp %_ASM_BX,%_ASM_CX
26556+ jb 1234f
26557+ xor %ebx,%ebx
26558+1234:
26559+#endif
26560+
26561+#endif
26562+
26563+1: __copyuser_seg movb %al,(_DEST)
26564 xor %eax,%eax
26565 EXIT
26566 ENDPROC(__put_user_1)
26567
26568 ENTRY(__put_user_2)
26569 ENTER
26570+
26571+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26572+ GET_THREAD_INFO(%_ASM_BX)
26573 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26574 sub $1,%_ASM_BX
26575 cmp %_ASM_BX,%_ASM_CX
26576 jae bad_put_user
26577 ASM_STAC
26578-2: movw %ax,(%_ASM_CX)
26579+
26580+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26581+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
26582+ cmp %_ASM_BX,%_ASM_CX
26583+ jb 1234f
26584+ xor %ebx,%ebx
26585+1234:
26586+#endif
26587+
26588+#endif
26589+
26590+2: __copyuser_seg movw %ax,(_DEST)
26591 xor %eax,%eax
26592 EXIT
26593 ENDPROC(__put_user_2)
26594
26595 ENTRY(__put_user_4)
26596 ENTER
26597+
26598+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26599+ GET_THREAD_INFO(%_ASM_BX)
26600 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26601 sub $3,%_ASM_BX
26602 cmp %_ASM_BX,%_ASM_CX
26603 jae bad_put_user
26604 ASM_STAC
26605-3: movl %eax,(%_ASM_CX)
26606+
26607+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26608+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
26609+ cmp %_ASM_BX,%_ASM_CX
26610+ jb 1234f
26611+ xor %ebx,%ebx
26612+1234:
26613+#endif
26614+
26615+#endif
26616+
26617+3: __copyuser_seg movl %eax,(_DEST)
26618 xor %eax,%eax
26619 EXIT
26620 ENDPROC(__put_user_4)
26621
26622 ENTRY(__put_user_8)
26623 ENTER
26624+
26625+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26626+ GET_THREAD_INFO(%_ASM_BX)
26627 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26628 sub $7,%_ASM_BX
26629 cmp %_ASM_BX,%_ASM_CX
26630 jae bad_put_user
26631 ASM_STAC
26632-4: mov %_ASM_AX,(%_ASM_CX)
26633+
26634+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26635+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
26636+ cmp %_ASM_BX,%_ASM_CX
26637+ jb 1234f
26638+ xor %ebx,%ebx
26639+1234:
26640+#endif
26641+
26642+#endif
26643+
26644+4: __copyuser_seg mov %_ASM_AX,(_DEST)
26645 #ifdef CONFIG_X86_32
26646-5: movl %edx,4(%_ASM_CX)
26647+5: __copyuser_seg movl %edx,4(_DEST)
26648 #endif
26649 xor %eax,%eax
26650 EXIT
26651diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
26652index 1cad221..de671ee 100644
26653--- a/arch/x86/lib/rwlock.S
26654+++ b/arch/x86/lib/rwlock.S
26655@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
26656 FRAME
26657 0: LOCK_PREFIX
26658 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
26659+
26660+#ifdef CONFIG_PAX_REFCOUNT
26661+ jno 1234f
26662+ LOCK_PREFIX
26663+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
26664+ int $4
26665+1234:
26666+ _ASM_EXTABLE(1234b, 1234b)
26667+#endif
26668+
26669 1: rep; nop
26670 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
26671 jne 1b
26672 LOCK_PREFIX
26673 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
26674+
26675+#ifdef CONFIG_PAX_REFCOUNT
26676+ jno 1234f
26677+ LOCK_PREFIX
26678+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
26679+ int $4
26680+1234:
26681+ _ASM_EXTABLE(1234b, 1234b)
26682+#endif
26683+
26684 jnz 0b
26685 ENDFRAME
26686+ pax_force_retaddr
26687 ret
26688 CFI_ENDPROC
26689 END(__write_lock_failed)
26690@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
26691 FRAME
26692 0: LOCK_PREFIX
26693 READ_LOCK_SIZE(inc) (%__lock_ptr)
26694+
26695+#ifdef CONFIG_PAX_REFCOUNT
26696+ jno 1234f
26697+ LOCK_PREFIX
26698+ READ_LOCK_SIZE(dec) (%__lock_ptr)
26699+ int $4
26700+1234:
26701+ _ASM_EXTABLE(1234b, 1234b)
26702+#endif
26703+
26704 1: rep; nop
26705 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
26706 js 1b
26707 LOCK_PREFIX
26708 READ_LOCK_SIZE(dec) (%__lock_ptr)
26709+
26710+#ifdef CONFIG_PAX_REFCOUNT
26711+ jno 1234f
26712+ LOCK_PREFIX
26713+ READ_LOCK_SIZE(inc) (%__lock_ptr)
26714+ int $4
26715+1234:
26716+ _ASM_EXTABLE(1234b, 1234b)
26717+#endif
26718+
26719 js 0b
26720 ENDFRAME
26721+ pax_force_retaddr
26722 ret
26723 CFI_ENDPROC
26724 END(__read_lock_failed)
26725diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
26726index 5dff5f0..cadebf4 100644
26727--- a/arch/x86/lib/rwsem.S
26728+++ b/arch/x86/lib/rwsem.S
26729@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
26730 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
26731 CFI_RESTORE __ASM_REG(dx)
26732 restore_common_regs
26733+ pax_force_retaddr
26734 ret
26735 CFI_ENDPROC
26736 ENDPROC(call_rwsem_down_read_failed)
26737@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
26738 movq %rax,%rdi
26739 call rwsem_down_write_failed
26740 restore_common_regs
26741+ pax_force_retaddr
26742 ret
26743 CFI_ENDPROC
26744 ENDPROC(call_rwsem_down_write_failed)
26745@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
26746 movq %rax,%rdi
26747 call rwsem_wake
26748 restore_common_regs
26749-1: ret
26750+1: pax_force_retaddr
26751+ ret
26752 CFI_ENDPROC
26753 ENDPROC(call_rwsem_wake)
26754
26755@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
26756 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
26757 CFI_RESTORE __ASM_REG(dx)
26758 restore_common_regs
26759+ pax_force_retaddr
26760 ret
26761 CFI_ENDPROC
26762 ENDPROC(call_rwsem_downgrade_wake)
26763diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
26764index a63efd6..ccecad8 100644
26765--- a/arch/x86/lib/thunk_64.S
26766+++ b/arch/x86/lib/thunk_64.S
26767@@ -8,6 +8,7 @@
26768 #include <linux/linkage.h>
26769 #include <asm/dwarf2.h>
26770 #include <asm/calling.h>
26771+#include <asm/alternative-asm.h>
26772
26773 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
26774 .macro THUNK name, func, put_ret_addr_in_rdi=0
26775@@ -41,5 +42,6 @@
26776 SAVE_ARGS
26777 restore:
26778 RESTORE_ARGS
26779+ pax_force_retaddr
26780 ret
26781 CFI_ENDPROC
26782diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
26783index f0312d7..9c39d63 100644
26784--- a/arch/x86/lib/usercopy_32.c
26785+++ b/arch/x86/lib/usercopy_32.c
26786@@ -42,11 +42,13 @@ do { \
26787 int __d0; \
26788 might_fault(); \
26789 __asm__ __volatile__( \
26790+ __COPYUSER_SET_ES \
26791 ASM_STAC "\n" \
26792 "0: rep; stosl\n" \
26793 " movl %2,%0\n" \
26794 "1: rep; stosb\n" \
26795 "2: " ASM_CLAC "\n" \
26796+ __COPYUSER_RESTORE_ES \
26797 ".section .fixup,\"ax\"\n" \
26798 "3: lea 0(%2,%0,4),%0\n" \
26799 " jmp 2b\n" \
26800@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
26801
26802 #ifdef CONFIG_X86_INTEL_USERCOPY
26803 static unsigned long
26804-__copy_user_intel(void __user *to, const void *from, unsigned long size)
26805+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
26806 {
26807 int d0, d1;
26808 __asm__ __volatile__(
26809@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26810 " .align 2,0x90\n"
26811 "3: movl 0(%4), %%eax\n"
26812 "4: movl 4(%4), %%edx\n"
26813- "5: movl %%eax, 0(%3)\n"
26814- "6: movl %%edx, 4(%3)\n"
26815+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
26816+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
26817 "7: movl 8(%4), %%eax\n"
26818 "8: movl 12(%4),%%edx\n"
26819- "9: movl %%eax, 8(%3)\n"
26820- "10: movl %%edx, 12(%3)\n"
26821+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
26822+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
26823 "11: movl 16(%4), %%eax\n"
26824 "12: movl 20(%4), %%edx\n"
26825- "13: movl %%eax, 16(%3)\n"
26826- "14: movl %%edx, 20(%3)\n"
26827+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
26828+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
26829 "15: movl 24(%4), %%eax\n"
26830 "16: movl 28(%4), %%edx\n"
26831- "17: movl %%eax, 24(%3)\n"
26832- "18: movl %%edx, 28(%3)\n"
26833+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
26834+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
26835 "19: movl 32(%4), %%eax\n"
26836 "20: movl 36(%4), %%edx\n"
26837- "21: movl %%eax, 32(%3)\n"
26838- "22: movl %%edx, 36(%3)\n"
26839+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
26840+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
26841 "23: movl 40(%4), %%eax\n"
26842 "24: movl 44(%4), %%edx\n"
26843- "25: movl %%eax, 40(%3)\n"
26844- "26: movl %%edx, 44(%3)\n"
26845+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
26846+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
26847 "27: movl 48(%4), %%eax\n"
26848 "28: movl 52(%4), %%edx\n"
26849- "29: movl %%eax, 48(%3)\n"
26850- "30: movl %%edx, 52(%3)\n"
26851+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
26852+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
26853 "31: movl 56(%4), %%eax\n"
26854 "32: movl 60(%4), %%edx\n"
26855- "33: movl %%eax, 56(%3)\n"
26856- "34: movl %%edx, 60(%3)\n"
26857+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
26858+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
26859 " addl $-64, %0\n"
26860 " addl $64, %4\n"
26861 " addl $64, %3\n"
26862@@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26863 " shrl $2, %0\n"
26864 " andl $3, %%eax\n"
26865 " cld\n"
26866+ __COPYUSER_SET_ES
26867 "99: rep; movsl\n"
26868 "36: movl %%eax, %0\n"
26869 "37: rep; movsb\n"
26870 "100:\n"
26871+ __COPYUSER_RESTORE_ES
26872 ".section .fixup,\"ax\"\n"
26873 "101: lea 0(%%eax,%0,4),%0\n"
26874 " jmp 100b\n"
26875@@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26876 }
26877
26878 static unsigned long
26879+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
26880+{
26881+ int d0, d1;
26882+ __asm__ __volatile__(
26883+ " .align 2,0x90\n"
26884+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
26885+ " cmpl $67, %0\n"
26886+ " jbe 3f\n"
26887+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
26888+ " .align 2,0x90\n"
26889+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
26890+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
26891+ "5: movl %%eax, 0(%3)\n"
26892+ "6: movl %%edx, 4(%3)\n"
26893+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
26894+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
26895+ "9: movl %%eax, 8(%3)\n"
26896+ "10: movl %%edx, 12(%3)\n"
26897+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
26898+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
26899+ "13: movl %%eax, 16(%3)\n"
26900+ "14: movl %%edx, 20(%3)\n"
26901+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
26902+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
26903+ "17: movl %%eax, 24(%3)\n"
26904+ "18: movl %%edx, 28(%3)\n"
26905+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
26906+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
26907+ "21: movl %%eax, 32(%3)\n"
26908+ "22: movl %%edx, 36(%3)\n"
26909+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
26910+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
26911+ "25: movl %%eax, 40(%3)\n"
26912+ "26: movl %%edx, 44(%3)\n"
26913+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
26914+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
26915+ "29: movl %%eax, 48(%3)\n"
26916+ "30: movl %%edx, 52(%3)\n"
26917+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
26918+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
26919+ "33: movl %%eax, 56(%3)\n"
26920+ "34: movl %%edx, 60(%3)\n"
26921+ " addl $-64, %0\n"
26922+ " addl $64, %4\n"
26923+ " addl $64, %3\n"
26924+ " cmpl $63, %0\n"
26925+ " ja 1b\n"
26926+ "35: movl %0, %%eax\n"
26927+ " shrl $2, %0\n"
26928+ " andl $3, %%eax\n"
26929+ " cld\n"
26930+ "99: rep; "__copyuser_seg" movsl\n"
26931+ "36: movl %%eax, %0\n"
26932+ "37: rep; "__copyuser_seg" movsb\n"
26933+ "100:\n"
26934+ ".section .fixup,\"ax\"\n"
26935+ "101: lea 0(%%eax,%0,4),%0\n"
26936+ " jmp 100b\n"
26937+ ".previous\n"
26938+ _ASM_EXTABLE(1b,100b)
26939+ _ASM_EXTABLE(2b,100b)
26940+ _ASM_EXTABLE(3b,100b)
26941+ _ASM_EXTABLE(4b,100b)
26942+ _ASM_EXTABLE(5b,100b)
26943+ _ASM_EXTABLE(6b,100b)
26944+ _ASM_EXTABLE(7b,100b)
26945+ _ASM_EXTABLE(8b,100b)
26946+ _ASM_EXTABLE(9b,100b)
26947+ _ASM_EXTABLE(10b,100b)
26948+ _ASM_EXTABLE(11b,100b)
26949+ _ASM_EXTABLE(12b,100b)
26950+ _ASM_EXTABLE(13b,100b)
26951+ _ASM_EXTABLE(14b,100b)
26952+ _ASM_EXTABLE(15b,100b)
26953+ _ASM_EXTABLE(16b,100b)
26954+ _ASM_EXTABLE(17b,100b)
26955+ _ASM_EXTABLE(18b,100b)
26956+ _ASM_EXTABLE(19b,100b)
26957+ _ASM_EXTABLE(20b,100b)
26958+ _ASM_EXTABLE(21b,100b)
26959+ _ASM_EXTABLE(22b,100b)
26960+ _ASM_EXTABLE(23b,100b)
26961+ _ASM_EXTABLE(24b,100b)
26962+ _ASM_EXTABLE(25b,100b)
26963+ _ASM_EXTABLE(26b,100b)
26964+ _ASM_EXTABLE(27b,100b)
26965+ _ASM_EXTABLE(28b,100b)
26966+ _ASM_EXTABLE(29b,100b)
26967+ _ASM_EXTABLE(30b,100b)
26968+ _ASM_EXTABLE(31b,100b)
26969+ _ASM_EXTABLE(32b,100b)
26970+ _ASM_EXTABLE(33b,100b)
26971+ _ASM_EXTABLE(34b,100b)
26972+ _ASM_EXTABLE(35b,100b)
26973+ _ASM_EXTABLE(36b,100b)
26974+ _ASM_EXTABLE(37b,100b)
26975+ _ASM_EXTABLE(99b,101b)
26976+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
26977+ : "1"(to), "2"(from), "0"(size)
26978+ : "eax", "edx", "memory");
26979+ return size;
26980+}
26981+
26982+static unsigned long __size_overflow(3)
26983 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26984 {
26985 int d0, d1;
26986 __asm__ __volatile__(
26987 " .align 2,0x90\n"
26988- "0: movl 32(%4), %%eax\n"
26989+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26990 " cmpl $67, %0\n"
26991 " jbe 2f\n"
26992- "1: movl 64(%4), %%eax\n"
26993+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26994 " .align 2,0x90\n"
26995- "2: movl 0(%4), %%eax\n"
26996- "21: movl 4(%4), %%edx\n"
26997+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26998+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26999 " movl %%eax, 0(%3)\n"
27000 " movl %%edx, 4(%3)\n"
27001- "3: movl 8(%4), %%eax\n"
27002- "31: movl 12(%4),%%edx\n"
27003+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
27004+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
27005 " movl %%eax, 8(%3)\n"
27006 " movl %%edx, 12(%3)\n"
27007- "4: movl 16(%4), %%eax\n"
27008- "41: movl 20(%4), %%edx\n"
27009+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
27010+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
27011 " movl %%eax, 16(%3)\n"
27012 " movl %%edx, 20(%3)\n"
27013- "10: movl 24(%4), %%eax\n"
27014- "51: movl 28(%4), %%edx\n"
27015+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
27016+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
27017 " movl %%eax, 24(%3)\n"
27018 " movl %%edx, 28(%3)\n"
27019- "11: movl 32(%4), %%eax\n"
27020- "61: movl 36(%4), %%edx\n"
27021+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
27022+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
27023 " movl %%eax, 32(%3)\n"
27024 " movl %%edx, 36(%3)\n"
27025- "12: movl 40(%4), %%eax\n"
27026- "71: movl 44(%4), %%edx\n"
27027+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
27028+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
27029 " movl %%eax, 40(%3)\n"
27030 " movl %%edx, 44(%3)\n"
27031- "13: movl 48(%4), %%eax\n"
27032- "81: movl 52(%4), %%edx\n"
27033+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
27034+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
27035 " movl %%eax, 48(%3)\n"
27036 " movl %%edx, 52(%3)\n"
27037- "14: movl 56(%4), %%eax\n"
27038- "91: movl 60(%4), %%edx\n"
27039+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
27040+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
27041 " movl %%eax, 56(%3)\n"
27042 " movl %%edx, 60(%3)\n"
27043 " addl $-64, %0\n"
27044@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
27045 " shrl $2, %0\n"
27046 " andl $3, %%eax\n"
27047 " cld\n"
27048- "6: rep; movsl\n"
27049+ "6: rep; "__copyuser_seg" movsl\n"
27050 " movl %%eax,%0\n"
27051- "7: rep; movsb\n"
27052+ "7: rep; "__copyuser_seg" movsb\n"
27053 "8:\n"
27054 ".section .fixup,\"ax\"\n"
27055 "9: lea 0(%%eax,%0,4),%0\n"
27056@@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
27057 * hyoshiok@miraclelinux.com
27058 */
27059
27060-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
27061+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
27062 const void __user *from, unsigned long size)
27063 {
27064 int d0, d1;
27065
27066 __asm__ __volatile__(
27067 " .align 2,0x90\n"
27068- "0: movl 32(%4), %%eax\n"
27069+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
27070 " cmpl $67, %0\n"
27071 " jbe 2f\n"
27072- "1: movl 64(%4), %%eax\n"
27073+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
27074 " .align 2,0x90\n"
27075- "2: movl 0(%4), %%eax\n"
27076- "21: movl 4(%4), %%edx\n"
27077+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
27078+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
27079 " movnti %%eax, 0(%3)\n"
27080 " movnti %%edx, 4(%3)\n"
27081- "3: movl 8(%4), %%eax\n"
27082- "31: movl 12(%4),%%edx\n"
27083+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
27084+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
27085 " movnti %%eax, 8(%3)\n"
27086 " movnti %%edx, 12(%3)\n"
27087- "4: movl 16(%4), %%eax\n"
27088- "41: movl 20(%4), %%edx\n"
27089+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
27090+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
27091 " movnti %%eax, 16(%3)\n"
27092 " movnti %%edx, 20(%3)\n"
27093- "10: movl 24(%4), %%eax\n"
27094- "51: movl 28(%4), %%edx\n"
27095+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
27096+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
27097 " movnti %%eax, 24(%3)\n"
27098 " movnti %%edx, 28(%3)\n"
27099- "11: movl 32(%4), %%eax\n"
27100- "61: movl 36(%4), %%edx\n"
27101+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
27102+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
27103 " movnti %%eax, 32(%3)\n"
27104 " movnti %%edx, 36(%3)\n"
27105- "12: movl 40(%4), %%eax\n"
27106- "71: movl 44(%4), %%edx\n"
27107+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
27108+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
27109 " movnti %%eax, 40(%3)\n"
27110 " movnti %%edx, 44(%3)\n"
27111- "13: movl 48(%4), %%eax\n"
27112- "81: movl 52(%4), %%edx\n"
27113+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
27114+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
27115 " movnti %%eax, 48(%3)\n"
27116 " movnti %%edx, 52(%3)\n"
27117- "14: movl 56(%4), %%eax\n"
27118- "91: movl 60(%4), %%edx\n"
27119+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
27120+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
27121 " movnti %%eax, 56(%3)\n"
27122 " movnti %%edx, 60(%3)\n"
27123 " addl $-64, %0\n"
27124@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
27125 " shrl $2, %0\n"
27126 " andl $3, %%eax\n"
27127 " cld\n"
27128- "6: rep; movsl\n"
27129+ "6: rep; "__copyuser_seg" movsl\n"
27130 " movl %%eax,%0\n"
27131- "7: rep; movsb\n"
27132+ "7: rep; "__copyuser_seg" movsb\n"
27133 "8:\n"
27134 ".section .fixup,\"ax\"\n"
27135 "9: lea 0(%%eax,%0,4),%0\n"
27136@@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
27137 return size;
27138 }
27139
27140-static unsigned long __copy_user_intel_nocache(void *to,
27141+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
27142 const void __user *from, unsigned long size)
27143 {
27144 int d0, d1;
27145
27146 __asm__ __volatile__(
27147 " .align 2,0x90\n"
27148- "0: movl 32(%4), %%eax\n"
27149+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
27150 " cmpl $67, %0\n"
27151 " jbe 2f\n"
27152- "1: movl 64(%4), %%eax\n"
27153+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
27154 " .align 2,0x90\n"
27155- "2: movl 0(%4), %%eax\n"
27156- "21: movl 4(%4), %%edx\n"
27157+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
27158+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
27159 " movnti %%eax, 0(%3)\n"
27160 " movnti %%edx, 4(%3)\n"
27161- "3: movl 8(%4), %%eax\n"
27162- "31: movl 12(%4),%%edx\n"
27163+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
27164+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
27165 " movnti %%eax, 8(%3)\n"
27166 " movnti %%edx, 12(%3)\n"
27167- "4: movl 16(%4), %%eax\n"
27168- "41: movl 20(%4), %%edx\n"
27169+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
27170+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
27171 " movnti %%eax, 16(%3)\n"
27172 " movnti %%edx, 20(%3)\n"
27173- "10: movl 24(%4), %%eax\n"
27174- "51: movl 28(%4), %%edx\n"
27175+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
27176+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
27177 " movnti %%eax, 24(%3)\n"
27178 " movnti %%edx, 28(%3)\n"
27179- "11: movl 32(%4), %%eax\n"
27180- "61: movl 36(%4), %%edx\n"
27181+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
27182+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
27183 " movnti %%eax, 32(%3)\n"
27184 " movnti %%edx, 36(%3)\n"
27185- "12: movl 40(%4), %%eax\n"
27186- "71: movl 44(%4), %%edx\n"
27187+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
27188+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
27189 " movnti %%eax, 40(%3)\n"
27190 " movnti %%edx, 44(%3)\n"
27191- "13: movl 48(%4), %%eax\n"
27192- "81: movl 52(%4), %%edx\n"
27193+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
27194+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
27195 " movnti %%eax, 48(%3)\n"
27196 " movnti %%edx, 52(%3)\n"
27197- "14: movl 56(%4), %%eax\n"
27198- "91: movl 60(%4), %%edx\n"
27199+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
27200+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
27201 " movnti %%eax, 56(%3)\n"
27202 " movnti %%edx, 60(%3)\n"
27203 " addl $-64, %0\n"
27204@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
27205 " shrl $2, %0\n"
27206 " andl $3, %%eax\n"
27207 " cld\n"
27208- "6: rep; movsl\n"
27209+ "6: rep; "__copyuser_seg" movsl\n"
27210 " movl %%eax,%0\n"
27211- "7: rep; movsb\n"
27212+ "7: rep; "__copyuser_seg" movsb\n"
27213 "8:\n"
27214 ".section .fixup,\"ax\"\n"
27215 "9: lea 0(%%eax,%0,4),%0\n"
27216@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
27217 */
27218 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
27219 unsigned long size);
27220-unsigned long __copy_user_intel(void __user *to, const void *from,
27221+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
27222+ unsigned long size);
27223+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
27224 unsigned long size);
27225 unsigned long __copy_user_zeroing_intel_nocache(void *to,
27226 const void __user *from, unsigned long size);
27227 #endif /* CONFIG_X86_INTEL_USERCOPY */
27228
27229 /* Generic arbitrary sized copy. */
27230-#define __copy_user(to, from, size) \
27231+#define __copy_user(to, from, size, prefix, set, restore) \
27232 do { \
27233 int __d0, __d1, __d2; \
27234 __asm__ __volatile__( \
27235+ set \
27236 " cmp $7,%0\n" \
27237 " jbe 1f\n" \
27238 " movl %1,%0\n" \
27239 " negl %0\n" \
27240 " andl $7,%0\n" \
27241 " subl %0,%3\n" \
27242- "4: rep; movsb\n" \
27243+ "4: rep; "prefix"movsb\n" \
27244 " movl %3,%0\n" \
27245 " shrl $2,%0\n" \
27246 " andl $3,%3\n" \
27247 " .align 2,0x90\n" \
27248- "0: rep; movsl\n" \
27249+ "0: rep; "prefix"movsl\n" \
27250 " movl %3,%0\n" \
27251- "1: rep; movsb\n" \
27252+ "1: rep; "prefix"movsb\n" \
27253 "2:\n" \
27254+ restore \
27255 ".section .fixup,\"ax\"\n" \
27256 "5: addl %3,%0\n" \
27257 " jmp 2b\n" \
27258@@ -538,14 +650,14 @@ do { \
27259 " negl %0\n" \
27260 " andl $7,%0\n" \
27261 " subl %0,%3\n" \
27262- "4: rep; movsb\n" \
27263+ "4: rep; "__copyuser_seg"movsb\n" \
27264 " movl %3,%0\n" \
27265 " shrl $2,%0\n" \
27266 " andl $3,%3\n" \
27267 " .align 2,0x90\n" \
27268- "0: rep; movsl\n" \
27269+ "0: rep; "__copyuser_seg"movsl\n" \
27270 " movl %3,%0\n" \
27271- "1: rep; movsb\n" \
27272+ "1: rep; "__copyuser_seg"movsb\n" \
27273 "2:\n" \
27274 ".section .fixup,\"ax\"\n" \
27275 "5: addl %3,%0\n" \
27276@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
27277 {
27278 stac();
27279 if (movsl_is_ok(to, from, n))
27280- __copy_user(to, from, n);
27281+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
27282 else
27283- n = __copy_user_intel(to, from, n);
27284+ n = __generic_copy_to_user_intel(to, from, n);
27285 clac();
27286 return n;
27287 }
27288@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
27289 {
27290 stac();
27291 if (movsl_is_ok(to, from, n))
27292- __copy_user(to, from, n);
27293+ __copy_user(to, from, n, __copyuser_seg, "", "");
27294 else
27295- n = __copy_user_intel((void __user *)to,
27296- (const void *)from, n);
27297+ n = __generic_copy_from_user_intel(to, from, n);
27298 clac();
27299 return n;
27300 }
27301@@ -632,66 +743,51 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
27302 if (n > 64 && cpu_has_xmm2)
27303 n = __copy_user_intel_nocache(to, from, n);
27304 else
27305- __copy_user(to, from, n);
27306+ __copy_user(to, from, n, __copyuser_seg, "", "");
27307 #else
27308- __copy_user(to, from, n);
27309+ __copy_user(to, from, n, __copyuser_seg, "", "");
27310 #endif
27311 clac();
27312 return n;
27313 }
27314 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
27315
27316-/**
27317- * copy_to_user: - Copy a block of data into user space.
27318- * @to: Destination address, in user space.
27319- * @from: Source address, in kernel space.
27320- * @n: Number of bytes to copy.
27321- *
27322- * Context: User context only. This function may sleep.
27323- *
27324- * Copy data from kernel space to user space.
27325- *
27326- * Returns number of bytes that could not be copied.
27327- * On success, this will be zero.
27328- */
27329-unsigned long
27330-copy_to_user(void __user *to, const void *from, unsigned long n)
27331-{
27332- if (access_ok(VERIFY_WRITE, to, n))
27333- n = __copy_to_user(to, from, n);
27334- return n;
27335-}
27336-EXPORT_SYMBOL(copy_to_user);
27337-
27338-/**
27339- * copy_from_user: - Copy a block of data from user space.
27340- * @to: Destination address, in kernel space.
27341- * @from: Source address, in user space.
27342- * @n: Number of bytes to copy.
27343- *
27344- * Context: User context only. This function may sleep.
27345- *
27346- * Copy data from user space to kernel space.
27347- *
27348- * Returns number of bytes that could not be copied.
27349- * On success, this will be zero.
27350- *
27351- * If some data could not be copied, this function will pad the copied
27352- * data to the requested size using zero bytes.
27353- */
27354-unsigned long
27355-_copy_from_user(void *to, const void __user *from, unsigned long n)
27356-{
27357- if (access_ok(VERIFY_READ, from, n))
27358- n = __copy_from_user(to, from, n);
27359- else
27360- memset(to, 0, n);
27361- return n;
27362-}
27363-EXPORT_SYMBOL(_copy_from_user);
27364-
27365 void copy_from_user_overflow(void)
27366 {
27367 WARN(1, "Buffer overflow detected!\n");
27368 }
27369 EXPORT_SYMBOL(copy_from_user_overflow);
27370+
27371+void copy_to_user_overflow(void)
27372+{
27373+ WARN(1, "Buffer overflow detected!\n");
27374+}
27375+EXPORT_SYMBOL(copy_to_user_overflow);
27376+
27377+#ifdef CONFIG_PAX_MEMORY_UDEREF
27378+void __set_fs(mm_segment_t x)
27379+{
27380+ switch (x.seg) {
27381+ case 0:
27382+ loadsegment(gs, 0);
27383+ break;
27384+ case TASK_SIZE_MAX:
27385+ loadsegment(gs, __USER_DS);
27386+ break;
27387+ case -1UL:
27388+ loadsegment(gs, __KERNEL_DS);
27389+ break;
27390+ default:
27391+ BUG();
27392+ }
27393+ return;
27394+}
27395+EXPORT_SYMBOL(__set_fs);
27396+
27397+void set_fs(mm_segment_t x)
27398+{
27399+ current_thread_info()->addr_limit = x;
27400+ __set_fs(x);
27401+}
27402+EXPORT_SYMBOL(set_fs);
27403+#endif
27404diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
27405index 906fea3..ee8a097 100644
27406--- a/arch/x86/lib/usercopy_64.c
27407+++ b/arch/x86/lib/usercopy_64.c
27408@@ -39,7 +39,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
27409 _ASM_EXTABLE(0b,3b)
27410 _ASM_EXTABLE(1b,2b)
27411 : [size8] "=&c"(size), [dst] "=&D" (__d0)
27412- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
27413+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
27414 [zero] "r" (0UL), [eight] "r" (8UL));
27415 clac();
27416 return size;
27417@@ -54,12 +54,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
27418 }
27419 EXPORT_SYMBOL(clear_user);
27420
27421-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
27422+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
27423 {
27424- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
27425- return copy_user_generic((__force void *)to, (__force void *)from, len);
27426- }
27427- return len;
27428+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
27429+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
27430+ return len;
27431 }
27432 EXPORT_SYMBOL(copy_in_user);
27433
27434@@ -69,7 +68,7 @@ EXPORT_SYMBOL(copy_in_user);
27435 * it is not necessary to optimize tail handling.
27436 */
27437 unsigned long
27438-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
27439+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
27440 {
27441 char c;
27442 unsigned zero_len;
27443@@ -87,3 +86,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
27444 clac();
27445 return len;
27446 }
27447+
27448+void copy_from_user_overflow(void)
27449+{
27450+ WARN(1, "Buffer overflow detected!\n");
27451+}
27452+EXPORT_SYMBOL(copy_from_user_overflow);
27453+
27454+void copy_to_user_overflow(void)
27455+{
27456+ WARN(1, "Buffer overflow detected!\n");
27457+}
27458+EXPORT_SYMBOL(copy_to_user_overflow);
27459diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
27460index 903ec1e..c4166b2 100644
27461--- a/arch/x86/mm/extable.c
27462+++ b/arch/x86/mm/extable.c
27463@@ -6,12 +6,24 @@
27464 static inline unsigned long
27465 ex_insn_addr(const struct exception_table_entry *x)
27466 {
27467- return (unsigned long)&x->insn + x->insn;
27468+ unsigned long reloc = 0;
27469+
27470+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27471+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27472+#endif
27473+
27474+ return (unsigned long)&x->insn + x->insn + reloc;
27475 }
27476 static inline unsigned long
27477 ex_fixup_addr(const struct exception_table_entry *x)
27478 {
27479- return (unsigned long)&x->fixup + x->fixup;
27480+ unsigned long reloc = 0;
27481+
27482+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27483+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27484+#endif
27485+
27486+ return (unsigned long)&x->fixup + x->fixup + reloc;
27487 }
27488
27489 int fixup_exception(struct pt_regs *regs)
27490@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
27491 unsigned long new_ip;
27492
27493 #ifdef CONFIG_PNPBIOS
27494- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
27495+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
27496 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
27497 extern u32 pnp_bios_is_utter_crap;
27498 pnp_bios_is_utter_crap = 1;
27499@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
27500 i += 4;
27501 p->fixup -= i;
27502 i += 4;
27503+
27504+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27505+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
27506+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27507+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27508+#endif
27509+
27510 }
27511 }
27512
27513diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
27514index 4f7d793..165a8be 100644
27515--- a/arch/x86/mm/fault.c
27516+++ b/arch/x86/mm/fault.c
27517@@ -13,12 +13,19 @@
27518 #include <linux/perf_event.h> /* perf_sw_event */
27519 #include <linux/hugetlb.h> /* hstate_index_to_shift */
27520 #include <linux/prefetch.h> /* prefetchw */
27521+#include <linux/unistd.h>
27522+#include <linux/compiler.h>
27523
27524 #include <asm/traps.h> /* dotraplinkage, ... */
27525 #include <asm/pgalloc.h> /* pgd_*(), ... */
27526 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
27527 #include <asm/fixmap.h> /* VSYSCALL_START */
27528 #include <asm/context_tracking.h> /* exception_enter(), ... */
27529+#include <asm/tlbflush.h>
27530+
27531+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27532+#include <asm/stacktrace.h>
27533+#endif
27534
27535 /*
27536 * Page fault error code bits:
27537@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
27538 int ret = 0;
27539
27540 /* kprobe_running() needs smp_processor_id() */
27541- if (kprobes_built_in() && !user_mode_vm(regs)) {
27542+ if (kprobes_built_in() && !user_mode(regs)) {
27543 preempt_disable();
27544 if (kprobe_running() && kprobe_fault_handler(regs, 14))
27545 ret = 1;
27546@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
27547 return !instr_lo || (instr_lo>>1) == 1;
27548 case 0x00:
27549 /* Prefetch instruction is 0x0F0D or 0x0F18 */
27550- if (probe_kernel_address(instr, opcode))
27551+ if (user_mode(regs)) {
27552+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
27553+ return 0;
27554+ } else if (probe_kernel_address(instr, opcode))
27555 return 0;
27556
27557 *prefetch = (instr_lo == 0xF) &&
27558@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
27559 while (instr < max_instr) {
27560 unsigned char opcode;
27561
27562- if (probe_kernel_address(instr, opcode))
27563+ if (user_mode(regs)) {
27564+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
27565+ break;
27566+ } else if (probe_kernel_address(instr, opcode))
27567 break;
27568
27569 instr++;
27570@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
27571 force_sig_info(si_signo, &info, tsk);
27572 }
27573
27574+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27575+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
27576+#endif
27577+
27578+#ifdef CONFIG_PAX_EMUTRAMP
27579+static int pax_handle_fetch_fault(struct pt_regs *regs);
27580+#endif
27581+
27582+#ifdef CONFIG_PAX_PAGEEXEC
27583+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
27584+{
27585+ pgd_t *pgd;
27586+ pud_t *pud;
27587+ pmd_t *pmd;
27588+
27589+ pgd = pgd_offset(mm, address);
27590+ if (!pgd_present(*pgd))
27591+ return NULL;
27592+ pud = pud_offset(pgd, address);
27593+ if (!pud_present(*pud))
27594+ return NULL;
27595+ pmd = pmd_offset(pud, address);
27596+ if (!pmd_present(*pmd))
27597+ return NULL;
27598+ return pmd;
27599+}
27600+#endif
27601+
27602 DEFINE_SPINLOCK(pgd_lock);
27603 LIST_HEAD(pgd_list);
27604
27605@@ -232,10 +273,22 @@ void vmalloc_sync_all(void)
27606 for (address = VMALLOC_START & PMD_MASK;
27607 address >= TASK_SIZE && address < FIXADDR_TOP;
27608 address += PMD_SIZE) {
27609+
27610+#ifdef CONFIG_PAX_PER_CPU_PGD
27611+ unsigned long cpu;
27612+#else
27613 struct page *page;
27614+#endif
27615
27616 spin_lock(&pgd_lock);
27617+
27618+#ifdef CONFIG_PAX_PER_CPU_PGD
27619+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
27620+ pgd_t *pgd = get_cpu_pgd(cpu);
27621+ pmd_t *ret;
27622+#else
27623 list_for_each_entry(page, &pgd_list, lru) {
27624+ pgd_t *pgd;
27625 spinlock_t *pgt_lock;
27626 pmd_t *ret;
27627
27628@@ -243,8 +296,14 @@ void vmalloc_sync_all(void)
27629 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
27630
27631 spin_lock(pgt_lock);
27632- ret = vmalloc_sync_one(page_address(page), address);
27633+ pgd = page_address(page);
27634+#endif
27635+
27636+ ret = vmalloc_sync_one(pgd, address);
27637+
27638+#ifndef CONFIG_PAX_PER_CPU_PGD
27639 spin_unlock(pgt_lock);
27640+#endif
27641
27642 if (!ret)
27643 break;
27644@@ -278,6 +337,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
27645 * an interrupt in the middle of a task switch..
27646 */
27647 pgd_paddr = read_cr3();
27648+
27649+#ifdef CONFIG_PAX_PER_CPU_PGD
27650+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
27651+#endif
27652+
27653 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
27654 if (!pmd_k)
27655 return -1;
27656@@ -373,7 +437,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
27657 * happen within a race in page table update. In the later
27658 * case just flush:
27659 */
27660+
27661+#ifdef CONFIG_PAX_PER_CPU_PGD
27662+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
27663+ pgd = pgd_offset_cpu(smp_processor_id(), address);
27664+#else
27665 pgd = pgd_offset(current->active_mm, address);
27666+#endif
27667+
27668 pgd_ref = pgd_offset_k(address);
27669 if (pgd_none(*pgd_ref))
27670 return -1;
27671@@ -543,7 +614,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
27672 static int is_errata100(struct pt_regs *regs, unsigned long address)
27673 {
27674 #ifdef CONFIG_X86_64
27675- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
27676+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
27677 return 1;
27678 #endif
27679 return 0;
27680@@ -570,7 +641,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
27681 }
27682
27683 static const char nx_warning[] = KERN_CRIT
27684-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
27685+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
27686
27687 static void
27688 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
27689@@ -579,15 +650,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
27690 if (!oops_may_print())
27691 return;
27692
27693- if (error_code & PF_INSTR) {
27694+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
27695 unsigned int level;
27696
27697 pte_t *pte = lookup_address(address, &level);
27698
27699 if (pte && pte_present(*pte) && !pte_exec(*pte))
27700- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
27701+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
27702 }
27703
27704+#ifdef CONFIG_PAX_KERNEXEC
27705+ if (init_mm.start_code <= address && address < init_mm.end_code) {
27706+ if (current->signal->curr_ip)
27707+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
27708+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
27709+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
27710+ else
27711+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
27712+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
27713+ }
27714+#endif
27715+
27716 printk(KERN_ALERT "BUG: unable to handle kernel ");
27717 if (address < PAGE_SIZE)
27718 printk(KERN_CONT "NULL pointer dereference");
27719@@ -750,6 +833,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
27720 return;
27721 }
27722 #endif
27723+
27724+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27725+ if (pax_is_fetch_fault(regs, error_code, address)) {
27726+
27727+#ifdef CONFIG_PAX_EMUTRAMP
27728+ switch (pax_handle_fetch_fault(regs)) {
27729+ case 2:
27730+ return;
27731+ }
27732+#endif
27733+
27734+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
27735+ do_group_exit(SIGKILL);
27736+ }
27737+#endif
27738+
27739 /* Kernel addresses are always protection faults: */
27740 if (address >= TASK_SIZE)
27741 error_code |= PF_PROT;
27742@@ -835,7 +934,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
27743 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
27744 printk(KERN_ERR
27745 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
27746- tsk->comm, tsk->pid, address);
27747+ tsk->comm, task_pid_nr(tsk), address);
27748 code = BUS_MCEERR_AR;
27749 }
27750 #endif
27751@@ -898,6 +997,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
27752 return 1;
27753 }
27754
27755+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27756+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
27757+{
27758+ pte_t *pte;
27759+ pmd_t *pmd;
27760+ spinlock_t *ptl;
27761+ unsigned char pte_mask;
27762+
27763+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
27764+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
27765+ return 0;
27766+
27767+ /* PaX: it's our fault, let's handle it if we can */
27768+
27769+ /* PaX: take a look at read faults before acquiring any locks */
27770+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
27771+ /* instruction fetch attempt from a protected page in user mode */
27772+ up_read(&mm->mmap_sem);
27773+
27774+#ifdef CONFIG_PAX_EMUTRAMP
27775+ switch (pax_handle_fetch_fault(regs)) {
27776+ case 2:
27777+ return 1;
27778+ }
27779+#endif
27780+
27781+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
27782+ do_group_exit(SIGKILL);
27783+ }
27784+
27785+ pmd = pax_get_pmd(mm, address);
27786+ if (unlikely(!pmd))
27787+ return 0;
27788+
27789+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
27790+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
27791+ pte_unmap_unlock(pte, ptl);
27792+ return 0;
27793+ }
27794+
27795+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
27796+ /* write attempt to a protected page in user mode */
27797+ pte_unmap_unlock(pte, ptl);
27798+ return 0;
27799+ }
27800+
27801+#ifdef CONFIG_SMP
27802+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
27803+#else
27804+ if (likely(address > get_limit(regs->cs)))
27805+#endif
27806+ {
27807+ set_pte(pte, pte_mkread(*pte));
27808+ __flush_tlb_one(address);
27809+ pte_unmap_unlock(pte, ptl);
27810+ up_read(&mm->mmap_sem);
27811+ return 1;
27812+ }
27813+
27814+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
27815+
27816+ /*
27817+ * PaX: fill DTLB with user rights and retry
27818+ */
27819+ __asm__ __volatile__ (
27820+ "orb %2,(%1)\n"
27821+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
27822+/*
27823+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
27824+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
27825+ * page fault when examined during a TLB load attempt. this is true not only
27826+ * for PTEs holding a non-present entry but also present entries that will
27827+ * raise a page fault (such as those set up by PaX, or the copy-on-write
27828+ * mechanism). in effect it means that we do *not* need to flush the TLBs
27829+ * for our target pages since their PTEs are simply not in the TLBs at all.
27830+
27831+ * the best thing in omitting it is that we gain around 15-20% speed in the
27832+ * fast path of the page fault handler and can get rid of tracing since we
27833+ * can no longer flush unintended entries.
27834+ */
27835+ "invlpg (%0)\n"
27836+#endif
27837+ __copyuser_seg"testb $0,(%0)\n"
27838+ "xorb %3,(%1)\n"
27839+ :
27840+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
27841+ : "memory", "cc");
27842+ pte_unmap_unlock(pte, ptl);
27843+ up_read(&mm->mmap_sem);
27844+ return 1;
27845+}
27846+#endif
27847+
27848 /*
27849 * Handle a spurious fault caused by a stale TLB entry.
27850 *
27851@@ -970,6 +1162,9 @@ int show_unhandled_signals = 1;
27852 static inline int
27853 access_error(unsigned long error_code, struct vm_area_struct *vma)
27854 {
27855+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
27856+ return 1;
27857+
27858 if (error_code & PF_WRITE) {
27859 /* write, present and write, not present: */
27860 if (unlikely(!(vma->vm_flags & VM_WRITE)))
27861@@ -998,7 +1193,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
27862 if (error_code & PF_USER)
27863 return false;
27864
27865- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
27866+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
27867 return false;
27868
27869 return true;
27870@@ -1014,18 +1209,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
27871 {
27872 struct vm_area_struct *vma;
27873 struct task_struct *tsk;
27874- unsigned long address;
27875 struct mm_struct *mm;
27876 int fault;
27877 int write = error_code & PF_WRITE;
27878 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
27879 (write ? FAULT_FLAG_WRITE : 0);
27880
27881- tsk = current;
27882- mm = tsk->mm;
27883-
27884 /* Get the faulting address: */
27885- address = read_cr2();
27886+ unsigned long address = read_cr2();
27887+
27888+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27889+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
27890+ if (!search_exception_tables(regs->ip)) {
27891+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
27892+ bad_area_nosemaphore(regs, error_code, address);
27893+ return;
27894+ }
27895+ if (address < PAX_USER_SHADOW_BASE) {
27896+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
27897+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
27898+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
27899+ } else
27900+ address -= PAX_USER_SHADOW_BASE;
27901+ }
27902+#endif
27903+
27904+ tsk = current;
27905+ mm = tsk->mm;
27906
27907 /*
27908 * Detect and handle instructions that would cause a page fault for
27909@@ -1086,7 +1296,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
27910 * User-mode registers count as a user access even for any
27911 * potential system fault or CPU buglet:
27912 */
27913- if (user_mode_vm(regs)) {
27914+ if (user_mode(regs)) {
27915 local_irq_enable();
27916 error_code |= PF_USER;
27917 } else {
27918@@ -1148,6 +1358,11 @@ retry:
27919 might_sleep();
27920 }
27921
27922+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27923+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
27924+ return;
27925+#endif
27926+
27927 vma = find_vma(mm, address);
27928 if (unlikely(!vma)) {
27929 bad_area(regs, error_code, address);
27930@@ -1159,18 +1374,24 @@ retry:
27931 bad_area(regs, error_code, address);
27932 return;
27933 }
27934- if (error_code & PF_USER) {
27935- /*
27936- * Accessing the stack below %sp is always a bug.
27937- * The large cushion allows instructions like enter
27938- * and pusha to work. ("enter $65535, $31" pushes
27939- * 32 pointers and then decrements %sp by 65535.)
27940- */
27941- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
27942- bad_area(regs, error_code, address);
27943- return;
27944- }
27945+ /*
27946+ * Accessing the stack below %sp is always a bug.
27947+ * The large cushion allows instructions like enter
27948+ * and pusha to work. ("enter $65535, $31" pushes
27949+ * 32 pointers and then decrements %sp by 65535.)
27950+ */
27951+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
27952+ bad_area(regs, error_code, address);
27953+ return;
27954 }
27955+
27956+#ifdef CONFIG_PAX_SEGMEXEC
27957+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
27958+ bad_area(regs, error_code, address);
27959+ return;
27960+ }
27961+#endif
27962+
27963 if (unlikely(expand_stack(vma, address))) {
27964 bad_area(regs, error_code, address);
27965 return;
27966@@ -1234,3 +1455,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
27967 __do_page_fault(regs, error_code);
27968 exception_exit(regs);
27969 }
27970+
27971+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27972+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
27973+{
27974+ struct mm_struct *mm = current->mm;
27975+ unsigned long ip = regs->ip;
27976+
27977+ if (v8086_mode(regs))
27978+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
27979+
27980+#ifdef CONFIG_PAX_PAGEEXEC
27981+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
27982+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
27983+ return true;
27984+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
27985+ return true;
27986+ return false;
27987+ }
27988+#endif
27989+
27990+#ifdef CONFIG_PAX_SEGMEXEC
27991+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
27992+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
27993+ return true;
27994+ return false;
27995+ }
27996+#endif
27997+
27998+ return false;
27999+}
28000+#endif
28001+
28002+#ifdef CONFIG_PAX_EMUTRAMP
28003+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
28004+{
28005+ int err;
28006+
28007+ do { /* PaX: libffi trampoline emulation */
28008+ unsigned char mov, jmp;
28009+ unsigned int addr1, addr2;
28010+
28011+#ifdef CONFIG_X86_64
28012+ if ((regs->ip + 9) >> 32)
28013+ break;
28014+#endif
28015+
28016+ err = get_user(mov, (unsigned char __user *)regs->ip);
28017+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
28018+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
28019+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
28020+
28021+ if (err)
28022+ break;
28023+
28024+ if (mov == 0xB8 && jmp == 0xE9) {
28025+ regs->ax = addr1;
28026+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
28027+ return 2;
28028+ }
28029+ } while (0);
28030+
28031+ do { /* PaX: gcc trampoline emulation #1 */
28032+ unsigned char mov1, mov2;
28033+ unsigned short jmp;
28034+ unsigned int addr1, addr2;
28035+
28036+#ifdef CONFIG_X86_64
28037+ if ((regs->ip + 11) >> 32)
28038+ break;
28039+#endif
28040+
28041+ err = get_user(mov1, (unsigned char __user *)regs->ip);
28042+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
28043+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
28044+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
28045+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
28046+
28047+ if (err)
28048+ break;
28049+
28050+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
28051+ regs->cx = addr1;
28052+ regs->ax = addr2;
28053+ regs->ip = addr2;
28054+ return 2;
28055+ }
28056+ } while (0);
28057+
28058+ do { /* PaX: gcc trampoline emulation #2 */
28059+ unsigned char mov, jmp;
28060+ unsigned int addr1, addr2;
28061+
28062+#ifdef CONFIG_X86_64
28063+ if ((regs->ip + 9) >> 32)
28064+ break;
28065+#endif
28066+
28067+ err = get_user(mov, (unsigned char __user *)regs->ip);
28068+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
28069+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
28070+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
28071+
28072+ if (err)
28073+ break;
28074+
28075+ if (mov == 0xB9 && jmp == 0xE9) {
28076+ regs->cx = addr1;
28077+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
28078+ return 2;
28079+ }
28080+ } while (0);
28081+
28082+ return 1; /* PaX in action */
28083+}
28084+
28085+#ifdef CONFIG_X86_64
28086+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
28087+{
28088+ int err;
28089+
28090+ do { /* PaX: libffi trampoline emulation */
28091+ unsigned short mov1, mov2, jmp1;
28092+ unsigned char stcclc, jmp2;
28093+ unsigned long addr1, addr2;
28094+
28095+ err = get_user(mov1, (unsigned short __user *)regs->ip);
28096+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
28097+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
28098+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
28099+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
28100+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
28101+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
28102+
28103+ if (err)
28104+ break;
28105+
28106+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
28107+ regs->r11 = addr1;
28108+ regs->r10 = addr2;
28109+ if (stcclc == 0xF8)
28110+ regs->flags &= ~X86_EFLAGS_CF;
28111+ else
28112+ regs->flags |= X86_EFLAGS_CF;
28113+ regs->ip = addr1;
28114+ return 2;
28115+ }
28116+ } while (0);
28117+
28118+ do { /* PaX: gcc trampoline emulation #1 */
28119+ unsigned short mov1, mov2, jmp1;
28120+ unsigned char jmp2;
28121+ unsigned int addr1;
28122+ unsigned long addr2;
28123+
28124+ err = get_user(mov1, (unsigned short __user *)regs->ip);
28125+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
28126+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
28127+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
28128+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
28129+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
28130+
28131+ if (err)
28132+ break;
28133+
28134+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
28135+ regs->r11 = addr1;
28136+ regs->r10 = addr2;
28137+ regs->ip = addr1;
28138+ return 2;
28139+ }
28140+ } while (0);
28141+
28142+ do { /* PaX: gcc trampoline emulation #2 */
28143+ unsigned short mov1, mov2, jmp1;
28144+ unsigned char jmp2;
28145+ unsigned long addr1, addr2;
28146+
28147+ err = get_user(mov1, (unsigned short __user *)regs->ip);
28148+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
28149+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
28150+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
28151+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
28152+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
28153+
28154+ if (err)
28155+ break;
28156+
28157+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
28158+ regs->r11 = addr1;
28159+ regs->r10 = addr2;
28160+ regs->ip = addr1;
28161+ return 2;
28162+ }
28163+ } while (0);
28164+
28165+ return 1; /* PaX in action */
28166+}
28167+#endif
28168+
28169+/*
28170+ * PaX: decide what to do with offenders (regs->ip = fault address)
28171+ *
28172+ * returns 1 when task should be killed
28173+ * 2 when gcc trampoline was detected
28174+ */
28175+static int pax_handle_fetch_fault(struct pt_regs *regs)
28176+{
28177+ if (v8086_mode(regs))
28178+ return 1;
28179+
28180+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
28181+ return 1;
28182+
28183+#ifdef CONFIG_X86_32
28184+ return pax_handle_fetch_fault_32(regs);
28185+#else
28186+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
28187+ return pax_handle_fetch_fault_32(regs);
28188+ else
28189+ return pax_handle_fetch_fault_64(regs);
28190+#endif
28191+}
28192+#endif
28193+
28194+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
28195+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
28196+{
28197+ long i;
28198+
28199+ printk(KERN_ERR "PAX: bytes at PC: ");
28200+ for (i = 0; i < 20; i++) {
28201+ unsigned char c;
28202+ if (get_user(c, (unsigned char __force_user *)pc+i))
28203+ printk(KERN_CONT "?? ");
28204+ else
28205+ printk(KERN_CONT "%02x ", c);
28206+ }
28207+ printk("\n");
28208+
28209+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
28210+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
28211+ unsigned long c;
28212+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
28213+#ifdef CONFIG_X86_32
28214+ printk(KERN_CONT "???????? ");
28215+#else
28216+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
28217+ printk(KERN_CONT "???????? ???????? ");
28218+ else
28219+ printk(KERN_CONT "???????????????? ");
28220+#endif
28221+ } else {
28222+#ifdef CONFIG_X86_64
28223+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
28224+ printk(KERN_CONT "%08x ", (unsigned int)c);
28225+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
28226+ } else
28227+#endif
28228+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
28229+ }
28230+ }
28231+ printk("\n");
28232+}
28233+#endif
28234+
28235+/**
28236+ * probe_kernel_write(): safely attempt to write to a location
28237+ * @dst: address to write to
28238+ * @src: pointer to the data that shall be written
28239+ * @size: size of the data chunk
28240+ *
28241+ * Safely write to address @dst from the buffer at @src. If a kernel fault
28242+ * happens, handle that and return -EFAULT.
28243+ */
28244+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
28245+{
28246+ long ret;
28247+ mm_segment_t old_fs = get_fs();
28248+
28249+ set_fs(KERNEL_DS);
28250+ pagefault_disable();
28251+ pax_open_kernel();
28252+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
28253+ pax_close_kernel();
28254+ pagefault_enable();
28255+ set_fs(old_fs);
28256+
28257+ return ret ? -EFAULT : 0;
28258+}
28259diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
28260index dd74e46..7d26398 100644
28261--- a/arch/x86/mm/gup.c
28262+++ b/arch/x86/mm/gup.c
28263@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
28264 addr = start;
28265 len = (unsigned long) nr_pages << PAGE_SHIFT;
28266 end = start + len;
28267- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
28268+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
28269 (void __user *)start, len)))
28270 return 0;
28271
28272diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
28273index 6f31ee5..8ee4164 100644
28274--- a/arch/x86/mm/highmem_32.c
28275+++ b/arch/x86/mm/highmem_32.c
28276@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
28277 idx = type + KM_TYPE_NR*smp_processor_id();
28278 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
28279 BUG_ON(!pte_none(*(kmap_pte-idx)));
28280+
28281+ pax_open_kernel();
28282 set_pte(kmap_pte-idx, mk_pte(page, prot));
28283+ pax_close_kernel();
28284+
28285 arch_flush_lazy_mmu_mode();
28286
28287 return (void *)vaddr;
28288diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
28289index ae1aa71..56316db 100644
28290--- a/arch/x86/mm/hugetlbpage.c
28291+++ b/arch/x86/mm/hugetlbpage.c
28292@@ -279,6 +279,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
28293 info.flags = 0;
28294 info.length = len;
28295 info.low_limit = TASK_UNMAPPED_BASE;
28296+
28297+#ifdef CONFIG_PAX_RANDMMAP
28298+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
28299+ info.low_limit += current->mm->delta_mmap;
28300+#endif
28301+
28302 info.high_limit = TASK_SIZE;
28303 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
28304 info.align_offset = 0;
28305@@ -311,6 +317,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
28306 VM_BUG_ON(addr != -ENOMEM);
28307 info.flags = 0;
28308 info.low_limit = TASK_UNMAPPED_BASE;
28309+
28310+#ifdef CONFIG_PAX_RANDMMAP
28311+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
28312+ info.low_limit += current->mm->delta_mmap;
28313+#endif
28314+
28315 info.high_limit = TASK_SIZE;
28316 addr = vm_unmapped_area(&info);
28317 }
28318@@ -325,10 +337,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
28319 struct hstate *h = hstate_file(file);
28320 struct mm_struct *mm = current->mm;
28321 struct vm_area_struct *vma;
28322+ unsigned long pax_task_size = TASK_SIZE;
28323+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
28324
28325 if (len & ~huge_page_mask(h))
28326 return -EINVAL;
28327- if (len > TASK_SIZE)
28328+
28329+#ifdef CONFIG_PAX_SEGMEXEC
28330+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28331+ pax_task_size = SEGMEXEC_TASK_SIZE;
28332+#endif
28333+
28334+ pax_task_size -= PAGE_SIZE;
28335+
28336+ if (len > pax_task_size)
28337 return -ENOMEM;
28338
28339 if (flags & MAP_FIXED) {
28340@@ -337,11 +359,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
28341 return addr;
28342 }
28343
28344+#ifdef CONFIG_PAX_RANDMMAP
28345+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
28346+#endif
28347+
28348 if (addr) {
28349 addr = ALIGN(addr, huge_page_size(h));
28350 vma = find_vma(mm, addr);
28351- if (TASK_SIZE - len >= addr &&
28352- (!vma || addr + len <= vma->vm_start))
28353+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
28354 return addr;
28355 }
28356 if (mm->get_unmapped_area == arch_get_unmapped_area)
28357diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
28358index d7aea41..0fc945b 100644
28359--- a/arch/x86/mm/init.c
28360+++ b/arch/x86/mm/init.c
28361@@ -4,6 +4,7 @@
28362 #include <linux/swap.h>
28363 #include <linux/memblock.h>
28364 #include <linux/bootmem.h> /* for max_low_pfn */
28365+#include <linux/tboot.h>
28366
28367 #include <asm/cacheflush.h>
28368 #include <asm/e820.h>
28369@@ -16,6 +17,8 @@
28370 #include <asm/tlb.h>
28371 #include <asm/proto.h>
28372 #include <asm/dma.h> /* for MAX_DMA_PFN */
28373+#include <asm/desc.h>
28374+#include <asm/bios_ebda.h>
28375
28376 unsigned long __initdata pgt_buf_start;
28377 unsigned long __meminitdata pgt_buf_end;
28378@@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
28379 {
28380 int i;
28381 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
28382- unsigned long start = 0, good_end;
28383+ unsigned long start = 0x100000, good_end;
28384 phys_addr_t base;
28385
28386 for (i = 0; i < nr_range; i++) {
28387@@ -321,10 +324,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
28388 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
28389 * mmio resources as well as potential bios/acpi data regions.
28390 */
28391+
28392+#ifdef CONFIG_GRKERNSEC_KMEM
28393+static unsigned int ebda_start __read_only;
28394+static unsigned int ebda_end __read_only;
28395+#endif
28396+
28397 int devmem_is_allowed(unsigned long pagenr)
28398 {
28399- if (pagenr < 256)
28400+#ifdef CONFIG_GRKERNSEC_KMEM
28401+ /* allow BDA */
28402+ if (!pagenr)
28403 return 1;
28404+ /* allow EBDA */
28405+ if (pagenr >= ebda_start && pagenr < ebda_end)
28406+ return 1;
28407+ /* if tboot is in use, allow access to its hardcoded serial log range */
28408+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
28409+ return 1;
28410+#else
28411+ if (!pagenr)
28412+ return 1;
28413+#ifdef CONFIG_VM86
28414+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
28415+ return 1;
28416+#endif
28417+#endif
28418+
28419+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
28420+ return 1;
28421+#ifdef CONFIG_GRKERNSEC_KMEM
28422+ /* throw out everything else below 1MB */
28423+ if (pagenr <= 256)
28424+ return 0;
28425+#endif
28426 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
28427 return 0;
28428 if (!page_is_ram(pagenr))
28429@@ -381,8 +414,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
28430 #endif
28431 }
28432
28433+#ifdef CONFIG_GRKERNSEC_KMEM
28434+static inline void gr_init_ebda(void)
28435+{
28436+ unsigned int ebda_addr;
28437+ unsigned int ebda_size = 0;
28438+
28439+ ebda_addr = get_bios_ebda();
28440+ if (ebda_addr) {
28441+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
28442+ ebda_size <<= 10;
28443+ }
28444+ if (ebda_addr && ebda_size) {
28445+ ebda_start = ebda_addr >> PAGE_SHIFT;
28446+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
28447+ } else {
28448+ ebda_start = 0x9f000 >> PAGE_SHIFT;
28449+ ebda_end = 0xa0000 >> PAGE_SHIFT;
28450+ }
28451+}
28452+#else
28453+static inline void gr_init_ebda(void) { }
28454+#endif
28455+
28456 void free_initmem(void)
28457 {
28458+#ifdef CONFIG_PAX_KERNEXEC
28459+#ifdef CONFIG_X86_32
28460+ /* PaX: limit KERNEL_CS to actual size */
28461+ unsigned long addr, limit;
28462+ struct desc_struct d;
28463+ int cpu;
28464+#else
28465+ pgd_t *pgd;
28466+ pud_t *pud;
28467+ pmd_t *pmd;
28468+ unsigned long addr, end;
28469+#endif
28470+#endif
28471+
28472+ gr_init_ebda();
28473+
28474+#ifdef CONFIG_PAX_KERNEXEC
28475+#ifdef CONFIG_X86_32
28476+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
28477+ limit = (limit - 1UL) >> PAGE_SHIFT;
28478+
28479+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
28480+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
28481+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
28482+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
28483+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
28484+ }
28485+
28486+ /* PaX: make KERNEL_CS read-only */
28487+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
28488+ if (!paravirt_enabled())
28489+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
28490+/*
28491+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
28492+ pgd = pgd_offset_k(addr);
28493+ pud = pud_offset(pgd, addr);
28494+ pmd = pmd_offset(pud, addr);
28495+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28496+ }
28497+*/
28498+#ifdef CONFIG_X86_PAE
28499+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
28500+/*
28501+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
28502+ pgd = pgd_offset_k(addr);
28503+ pud = pud_offset(pgd, addr);
28504+ pmd = pmd_offset(pud, addr);
28505+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
28506+ }
28507+*/
28508+#endif
28509+
28510+#ifdef CONFIG_MODULES
28511+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
28512+#endif
28513+
28514+#else
28515+ /* PaX: make kernel code/rodata read-only, rest non-executable */
28516+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
28517+ pgd = pgd_offset_k(addr);
28518+ pud = pud_offset(pgd, addr);
28519+ pmd = pmd_offset(pud, addr);
28520+ if (!pmd_present(*pmd))
28521+ continue;
28522+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
28523+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28524+ else
28525+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
28526+ }
28527+
28528+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
28529+ end = addr + KERNEL_IMAGE_SIZE;
28530+ for (; addr < end; addr += PMD_SIZE) {
28531+ pgd = pgd_offset_k(addr);
28532+ pud = pud_offset(pgd, addr);
28533+ pmd = pmd_offset(pud, addr);
28534+ if (!pmd_present(*pmd))
28535+ continue;
28536+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
28537+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28538+ }
28539+#endif
28540+
28541+ flush_tlb_all();
28542+#endif
28543+
28544 free_init_pages("unused kernel memory",
28545 (unsigned long)(&__init_begin),
28546 (unsigned long)(&__init_end));
28547diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
28548index 745d66b..56bf568 100644
28549--- a/arch/x86/mm/init_32.c
28550+++ b/arch/x86/mm/init_32.c
28551@@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
28552 }
28553
28554 /*
28555- * Creates a middle page table and puts a pointer to it in the
28556- * given global directory entry. This only returns the gd entry
28557- * in non-PAE compilation mode, since the middle layer is folded.
28558- */
28559-static pmd_t * __init one_md_table_init(pgd_t *pgd)
28560-{
28561- pud_t *pud;
28562- pmd_t *pmd_table;
28563-
28564-#ifdef CONFIG_X86_PAE
28565- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
28566- if (after_bootmem)
28567- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
28568- else
28569- pmd_table = (pmd_t *)alloc_low_page();
28570- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
28571- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
28572- pud = pud_offset(pgd, 0);
28573- BUG_ON(pmd_table != pmd_offset(pud, 0));
28574-
28575- return pmd_table;
28576- }
28577-#endif
28578- pud = pud_offset(pgd, 0);
28579- pmd_table = pmd_offset(pud, 0);
28580-
28581- return pmd_table;
28582-}
28583-
28584-/*
28585 * Create a page table and place a pointer to it in a middle page
28586 * directory entry:
28587 */
28588@@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
28589 page_table = (pte_t *)alloc_low_page();
28590
28591 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
28592+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
28593+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
28594+#else
28595 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
28596+#endif
28597 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
28598 }
28599
28600 return pte_offset_kernel(pmd, 0);
28601 }
28602
28603+static pmd_t * __init one_md_table_init(pgd_t *pgd)
28604+{
28605+ pud_t *pud;
28606+ pmd_t *pmd_table;
28607+
28608+ pud = pud_offset(pgd, 0);
28609+ pmd_table = pmd_offset(pud, 0);
28610+
28611+ return pmd_table;
28612+}
28613+
28614 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
28615 {
28616 int pgd_idx = pgd_index(vaddr);
28617@@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28618 int pgd_idx, pmd_idx;
28619 unsigned long vaddr;
28620 pgd_t *pgd;
28621+ pud_t *pud;
28622 pmd_t *pmd;
28623 pte_t *pte = NULL;
28624
28625@@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28626 pgd = pgd_base + pgd_idx;
28627
28628 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
28629- pmd = one_md_table_init(pgd);
28630- pmd = pmd + pmd_index(vaddr);
28631+ pud = pud_offset(pgd, vaddr);
28632+ pmd = pmd_offset(pud, vaddr);
28633+
28634+#ifdef CONFIG_X86_PAE
28635+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
28636+#endif
28637+
28638 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
28639 pmd++, pmd_idx++) {
28640 pte = page_table_kmap_check(one_page_table_init(pmd),
28641@@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28642 }
28643 }
28644
28645-static inline int is_kernel_text(unsigned long addr)
28646+static inline int is_kernel_text(unsigned long start, unsigned long end)
28647 {
28648- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
28649- return 1;
28650- return 0;
28651+ if ((start > ktla_ktva((unsigned long)_etext) ||
28652+ end <= ktla_ktva((unsigned long)_stext)) &&
28653+ (start > ktla_ktva((unsigned long)_einittext) ||
28654+ end <= ktla_ktva((unsigned long)_sinittext)) &&
28655+
28656+#ifdef CONFIG_ACPI_SLEEP
28657+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
28658+#endif
28659+
28660+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
28661+ return 0;
28662+ return 1;
28663 }
28664
28665 /*
28666@@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
28667 unsigned long last_map_addr = end;
28668 unsigned long start_pfn, end_pfn;
28669 pgd_t *pgd_base = swapper_pg_dir;
28670- int pgd_idx, pmd_idx, pte_ofs;
28671+ unsigned int pgd_idx, pmd_idx, pte_ofs;
28672 unsigned long pfn;
28673 pgd_t *pgd;
28674+ pud_t *pud;
28675 pmd_t *pmd;
28676 pte_t *pte;
28677 unsigned pages_2m, pages_4k;
28678@@ -280,8 +281,13 @@ repeat:
28679 pfn = start_pfn;
28680 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
28681 pgd = pgd_base + pgd_idx;
28682- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
28683- pmd = one_md_table_init(pgd);
28684+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
28685+ pud = pud_offset(pgd, 0);
28686+ pmd = pmd_offset(pud, 0);
28687+
28688+#ifdef CONFIG_X86_PAE
28689+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
28690+#endif
28691
28692 if (pfn >= end_pfn)
28693 continue;
28694@@ -293,14 +299,13 @@ repeat:
28695 #endif
28696 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
28697 pmd++, pmd_idx++) {
28698- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
28699+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
28700
28701 /*
28702 * Map with big pages if possible, otherwise
28703 * create normal page tables:
28704 */
28705 if (use_pse) {
28706- unsigned int addr2;
28707 pgprot_t prot = PAGE_KERNEL_LARGE;
28708 /*
28709 * first pass will use the same initial
28710@@ -310,11 +315,7 @@ repeat:
28711 __pgprot(PTE_IDENT_ATTR |
28712 _PAGE_PSE);
28713
28714- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
28715- PAGE_OFFSET + PAGE_SIZE-1;
28716-
28717- if (is_kernel_text(addr) ||
28718- is_kernel_text(addr2))
28719+ if (is_kernel_text(address, address + PMD_SIZE))
28720 prot = PAGE_KERNEL_LARGE_EXEC;
28721
28722 pages_2m++;
28723@@ -331,7 +332,7 @@ repeat:
28724 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
28725 pte += pte_ofs;
28726 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
28727- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
28728+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
28729 pgprot_t prot = PAGE_KERNEL;
28730 /*
28731 * first pass will use the same initial
28732@@ -339,7 +340,7 @@ repeat:
28733 */
28734 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
28735
28736- if (is_kernel_text(addr))
28737+ if (is_kernel_text(address, address + PAGE_SIZE))
28738 prot = PAGE_KERNEL_EXEC;
28739
28740 pages_4k++;
28741@@ -465,7 +466,7 @@ void __init native_pagetable_init(void)
28742
28743 pud = pud_offset(pgd, va);
28744 pmd = pmd_offset(pud, va);
28745- if (!pmd_present(*pmd))
28746+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
28747 break;
28748
28749 pte = pte_offset_kernel(pmd, va);
28750@@ -514,12 +515,10 @@ void __init early_ioremap_page_table_range_init(void)
28751
28752 static void __init pagetable_init(void)
28753 {
28754- pgd_t *pgd_base = swapper_pg_dir;
28755-
28756- permanent_kmaps_init(pgd_base);
28757+ permanent_kmaps_init(swapper_pg_dir);
28758 }
28759
28760-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
28761+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
28762 EXPORT_SYMBOL_GPL(__supported_pte_mask);
28763
28764 /* user-defined highmem size */
28765@@ -728,6 +727,12 @@ void __init mem_init(void)
28766
28767 pci_iommu_alloc();
28768
28769+#ifdef CONFIG_PAX_PER_CPU_PGD
28770+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
28771+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28772+ KERNEL_PGD_PTRS);
28773+#endif
28774+
28775 #ifdef CONFIG_FLATMEM
28776 BUG_ON(!mem_map);
28777 #endif
28778@@ -754,7 +759,7 @@ void __init mem_init(void)
28779 reservedpages++;
28780
28781 codesize = (unsigned long) &_etext - (unsigned long) &_text;
28782- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
28783+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
28784 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
28785
28786 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
28787@@ -795,10 +800,10 @@ void __init mem_init(void)
28788 ((unsigned long)&__init_end -
28789 (unsigned long)&__init_begin) >> 10,
28790
28791- (unsigned long)&_etext, (unsigned long)&_edata,
28792- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
28793+ (unsigned long)&_sdata, (unsigned long)&_edata,
28794+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
28795
28796- (unsigned long)&_text, (unsigned long)&_etext,
28797+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
28798 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
28799
28800 /*
28801@@ -876,6 +881,7 @@ void set_kernel_text_rw(void)
28802 if (!kernel_set_to_readonly)
28803 return;
28804
28805+ start = ktla_ktva(start);
28806 pr_debug("Set kernel text: %lx - %lx for read write\n",
28807 start, start+size);
28808
28809@@ -890,6 +896,7 @@ void set_kernel_text_ro(void)
28810 if (!kernel_set_to_readonly)
28811 return;
28812
28813+ start = ktla_ktva(start);
28814 pr_debug("Set kernel text: %lx - %lx for read only\n",
28815 start, start+size);
28816
28817@@ -918,6 +925,7 @@ void mark_rodata_ro(void)
28818 unsigned long start = PFN_ALIGN(_text);
28819 unsigned long size = PFN_ALIGN(_etext) - start;
28820
28821+ start = ktla_ktva(start);
28822 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
28823 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
28824 size >> 10);
28825diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
28826index 75c9a6a..498d677 100644
28827--- a/arch/x86/mm/init_64.c
28828+++ b/arch/x86/mm/init_64.c
28829@@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
28830 * around without checking the pgd every time.
28831 */
28832
28833-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
28834+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
28835 EXPORT_SYMBOL_GPL(__supported_pte_mask);
28836
28837 int force_personality32;
28838@@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28839
28840 for (address = start; address <= end; address += PGDIR_SIZE) {
28841 const pgd_t *pgd_ref = pgd_offset_k(address);
28842+
28843+#ifdef CONFIG_PAX_PER_CPU_PGD
28844+ unsigned long cpu;
28845+#else
28846 struct page *page;
28847+#endif
28848
28849 if (pgd_none(*pgd_ref))
28850 continue;
28851
28852 spin_lock(&pgd_lock);
28853+
28854+#ifdef CONFIG_PAX_PER_CPU_PGD
28855+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
28856+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
28857+#else
28858 list_for_each_entry(page, &pgd_list, lru) {
28859 pgd_t *pgd;
28860 spinlock_t *pgt_lock;
28861@@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28862 /* the pgt_lock only for Xen */
28863 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
28864 spin_lock(pgt_lock);
28865+#endif
28866
28867 if (pgd_none(*pgd))
28868 set_pgd(pgd, *pgd_ref);
28869@@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28870 BUG_ON(pgd_page_vaddr(*pgd)
28871 != pgd_page_vaddr(*pgd_ref));
28872
28873+#ifndef CONFIG_PAX_PER_CPU_PGD
28874 spin_unlock(pgt_lock);
28875+#endif
28876+
28877 }
28878 spin_unlock(&pgd_lock);
28879 }
28880@@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
28881 {
28882 if (pgd_none(*pgd)) {
28883 pud_t *pud = (pud_t *)spp_getpage();
28884- pgd_populate(&init_mm, pgd, pud);
28885+ pgd_populate_kernel(&init_mm, pgd, pud);
28886 if (pud != pud_offset(pgd, 0))
28887 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
28888 pud, pud_offset(pgd, 0));
28889@@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
28890 {
28891 if (pud_none(*pud)) {
28892 pmd_t *pmd = (pmd_t *) spp_getpage();
28893- pud_populate(&init_mm, pud, pmd);
28894+ pud_populate_kernel(&init_mm, pud, pmd);
28895 if (pmd != pmd_offset(pud, 0))
28896 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
28897 pmd, pmd_offset(pud, 0));
28898@@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
28899 pmd = fill_pmd(pud, vaddr);
28900 pte = fill_pte(pmd, vaddr);
28901
28902+ pax_open_kernel();
28903 set_pte(pte, new_pte);
28904+ pax_close_kernel();
28905
28906 /*
28907 * It's enough to flush this one mapping.
28908@@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
28909 pgd = pgd_offset_k((unsigned long)__va(phys));
28910 if (pgd_none(*pgd)) {
28911 pud = (pud_t *) spp_getpage();
28912- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
28913- _PAGE_USER));
28914+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
28915 }
28916 pud = pud_offset(pgd, (unsigned long)__va(phys));
28917 if (pud_none(*pud)) {
28918 pmd = (pmd_t *) spp_getpage();
28919- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
28920- _PAGE_USER));
28921+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
28922 }
28923 pmd = pmd_offset(pud, phys);
28924 BUG_ON(!pmd_none(*pmd));
28925@@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
28926 if (pfn >= pgt_buf_top)
28927 panic("alloc_low_page: ran out of memory");
28928
28929- adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
28930+ adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
28931 clear_page(adr);
28932 *phys = pfn * PAGE_SIZE;
28933 return adr;
28934@@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
28935
28936 phys = __pa(virt);
28937 left = phys & (PAGE_SIZE - 1);
28938- adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
28939+ adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
28940 adr = (void *)(((unsigned long)adr) | left);
28941
28942 return adr;
28943@@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
28944 unmap_low_page(pmd);
28945
28946 spin_lock(&init_mm.page_table_lock);
28947- pud_populate(&init_mm, pud, __va(pmd_phys));
28948+ pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
28949 spin_unlock(&init_mm.page_table_lock);
28950 }
28951 __flush_tlb_all();
28952@@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
28953 unmap_low_page(pud);
28954
28955 spin_lock(&init_mm.page_table_lock);
28956- pgd_populate(&init_mm, pgd, __va(pud_phys));
28957+ pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
28958 spin_unlock(&init_mm.page_table_lock);
28959 pgd_changed = true;
28960 }
28961@@ -693,6 +707,12 @@ void __init mem_init(void)
28962
28963 pci_iommu_alloc();
28964
28965+#ifdef CONFIG_PAX_PER_CPU_PGD
28966+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
28967+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28968+ KERNEL_PGD_PTRS);
28969+#endif
28970+
28971 /* clear_bss() already clear the empty_zero_page */
28972
28973 reservedpages = 0;
28974@@ -856,8 +876,8 @@ int kern_addr_valid(unsigned long addr)
28975 static struct vm_area_struct gate_vma = {
28976 .vm_start = VSYSCALL_START,
28977 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
28978- .vm_page_prot = PAGE_READONLY_EXEC,
28979- .vm_flags = VM_READ | VM_EXEC
28980+ .vm_page_prot = PAGE_READONLY,
28981+ .vm_flags = VM_READ
28982 };
28983
28984 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
28985@@ -891,7 +911,7 @@ int in_gate_area_no_mm(unsigned long addr)
28986
28987 const char *arch_vma_name(struct vm_area_struct *vma)
28988 {
28989- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
28990+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
28991 return "[vdso]";
28992 if (vma == &gate_vma)
28993 return "[vsyscall]";
28994diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
28995index 7b179b4..6bd17777 100644
28996--- a/arch/x86/mm/iomap_32.c
28997+++ b/arch/x86/mm/iomap_32.c
28998@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
28999 type = kmap_atomic_idx_push();
29000 idx = type + KM_TYPE_NR * smp_processor_id();
29001 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
29002+
29003+ pax_open_kernel();
29004 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
29005+ pax_close_kernel();
29006+
29007 arch_flush_lazy_mmu_mode();
29008
29009 return (void *)vaddr;
29010diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
29011index 78fe3f1..73b95e2 100644
29012--- a/arch/x86/mm/ioremap.c
29013+++ b/arch/x86/mm/ioremap.c
29014@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
29015 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
29016 int is_ram = page_is_ram(pfn);
29017
29018- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
29019+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
29020 return NULL;
29021 WARN_ON_ONCE(is_ram);
29022 }
29023@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
29024 *
29025 * Caller must ensure there is only one unmapping for the same pointer.
29026 */
29027-void iounmap(volatile void __iomem *addr)
29028+void iounmap(const volatile void __iomem *addr)
29029 {
29030 struct vm_struct *p, *o;
29031
29032@@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
29033
29034 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
29035 if (page_is_ram(start >> PAGE_SHIFT))
29036+#ifdef CONFIG_HIGHMEM
29037+ if ((start >> PAGE_SHIFT) < max_low_pfn)
29038+#endif
29039 return __va(phys);
29040
29041 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
29042@@ -327,6 +330,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
29043 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
29044 {
29045 if (page_is_ram(phys >> PAGE_SHIFT))
29046+#ifdef CONFIG_HIGHMEM
29047+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
29048+#endif
29049 return;
29050
29051 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
29052@@ -344,7 +350,7 @@ static int __init early_ioremap_debug_setup(char *str)
29053 early_param("early_ioremap_debug", early_ioremap_debug_setup);
29054
29055 static __initdata int after_paging_init;
29056-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
29057+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
29058
29059 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
29060 {
29061@@ -381,8 +387,7 @@ void __init early_ioremap_init(void)
29062 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
29063
29064 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
29065- memset(bm_pte, 0, sizeof(bm_pte));
29066- pmd_populate_kernel(&init_mm, pmd, bm_pte);
29067+ pmd_populate_user(&init_mm, pmd, bm_pte);
29068
29069 /*
29070 * The boot-ioremap range spans multiple pmds, for which
29071diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
29072index d87dd6d..bf3fa66 100644
29073--- a/arch/x86/mm/kmemcheck/kmemcheck.c
29074+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
29075@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
29076 * memory (e.g. tracked pages)? For now, we need this to avoid
29077 * invoking kmemcheck for PnP BIOS calls.
29078 */
29079- if (regs->flags & X86_VM_MASK)
29080+ if (v8086_mode(regs))
29081 return false;
29082- if (regs->cs != __KERNEL_CS)
29083+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
29084 return false;
29085
29086 pte = kmemcheck_pte_lookup(address);
29087diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
29088index 845df68..1d8d29f 100644
29089--- a/arch/x86/mm/mmap.c
29090+++ b/arch/x86/mm/mmap.c
29091@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
29092 * Leave an at least ~128 MB hole with possible stack randomization.
29093 */
29094 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
29095-#define MAX_GAP (TASK_SIZE/6*5)
29096+#define MAX_GAP (pax_task_size/6*5)
29097
29098 static int mmap_is_legacy(void)
29099 {
29100@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
29101 return rnd << PAGE_SHIFT;
29102 }
29103
29104-static unsigned long mmap_base(void)
29105+static unsigned long mmap_base(struct mm_struct *mm)
29106 {
29107 unsigned long gap = rlimit(RLIMIT_STACK);
29108+ unsigned long pax_task_size = TASK_SIZE;
29109+
29110+#ifdef CONFIG_PAX_SEGMEXEC
29111+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
29112+ pax_task_size = SEGMEXEC_TASK_SIZE;
29113+#endif
29114
29115 if (gap < MIN_GAP)
29116 gap = MIN_GAP;
29117 else if (gap > MAX_GAP)
29118 gap = MAX_GAP;
29119
29120- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
29121+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
29122 }
29123
29124 /*
29125 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
29126 * does, but not when emulating X86_32
29127 */
29128-static unsigned long mmap_legacy_base(void)
29129+static unsigned long mmap_legacy_base(struct mm_struct *mm)
29130 {
29131- if (mmap_is_ia32())
29132+ if (mmap_is_ia32()) {
29133+
29134+#ifdef CONFIG_PAX_SEGMEXEC
29135+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
29136+ return SEGMEXEC_TASK_UNMAPPED_BASE;
29137+ else
29138+#endif
29139+
29140 return TASK_UNMAPPED_BASE;
29141- else
29142+ } else
29143 return TASK_UNMAPPED_BASE + mmap_rnd();
29144 }
29145
29146@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
29147 void arch_pick_mmap_layout(struct mm_struct *mm)
29148 {
29149 if (mmap_is_legacy()) {
29150- mm->mmap_base = mmap_legacy_base();
29151+ mm->mmap_base = mmap_legacy_base(mm);
29152+
29153+#ifdef CONFIG_PAX_RANDMMAP
29154+ if (mm->pax_flags & MF_PAX_RANDMMAP)
29155+ mm->mmap_base += mm->delta_mmap;
29156+#endif
29157+
29158 mm->get_unmapped_area = arch_get_unmapped_area;
29159 mm->unmap_area = arch_unmap_area;
29160 } else {
29161- mm->mmap_base = mmap_base();
29162+ mm->mmap_base = mmap_base(mm);
29163+
29164+#ifdef CONFIG_PAX_RANDMMAP
29165+ if (mm->pax_flags & MF_PAX_RANDMMAP)
29166+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
29167+#endif
29168+
29169 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
29170 mm->unmap_area = arch_unmap_area_topdown;
29171 }
29172diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
29173index dc0b727..f612039 100644
29174--- a/arch/x86/mm/mmio-mod.c
29175+++ b/arch/x86/mm/mmio-mod.c
29176@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
29177 break;
29178 default:
29179 {
29180- unsigned char *ip = (unsigned char *)instptr;
29181+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
29182 my_trace->opcode = MMIO_UNKNOWN_OP;
29183 my_trace->width = 0;
29184 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
29185@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
29186 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
29187 void __iomem *addr)
29188 {
29189- static atomic_t next_id;
29190+ static atomic_unchecked_t next_id;
29191 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
29192 /* These are page-unaligned. */
29193 struct mmiotrace_map map = {
29194@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
29195 .private = trace
29196 },
29197 .phys = offset,
29198- .id = atomic_inc_return(&next_id)
29199+ .id = atomic_inc_return_unchecked(&next_id)
29200 };
29201 map.map_id = trace->id;
29202
29203@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
29204 ioremap_trace_core(offset, size, addr);
29205 }
29206
29207-static void iounmap_trace_core(volatile void __iomem *addr)
29208+static void iounmap_trace_core(const volatile void __iomem *addr)
29209 {
29210 struct mmiotrace_map map = {
29211 .phys = 0,
29212@@ -328,7 +328,7 @@ not_enabled:
29213 }
29214 }
29215
29216-void mmiotrace_iounmap(volatile void __iomem *addr)
29217+void mmiotrace_iounmap(const volatile void __iomem *addr)
29218 {
29219 might_sleep();
29220 if (is_enabled()) /* recheck and proper locking in *_core() */
29221diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
29222index 8504f36..5fc68f2 100644
29223--- a/arch/x86/mm/numa.c
29224+++ b/arch/x86/mm/numa.c
29225@@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
29226 return true;
29227 }
29228
29229-static int __init numa_register_memblks(struct numa_meminfo *mi)
29230+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
29231 {
29232 unsigned long uninitialized_var(pfn_align);
29233 int i, nid;
29234diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
29235index b008656..773eac2 100644
29236--- a/arch/x86/mm/pageattr-test.c
29237+++ b/arch/x86/mm/pageattr-test.c
29238@@ -36,7 +36,7 @@ enum {
29239
29240 static int pte_testbit(pte_t pte)
29241 {
29242- return pte_flags(pte) & _PAGE_UNUSED1;
29243+ return pte_flags(pte) & _PAGE_CPA_TEST;
29244 }
29245
29246 struct split_state {
29247diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
29248index a718e0d..77419bc 100644
29249--- a/arch/x86/mm/pageattr.c
29250+++ b/arch/x86/mm/pageattr.c
29251@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
29252 */
29253 #ifdef CONFIG_PCI_BIOS
29254 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
29255- pgprot_val(forbidden) |= _PAGE_NX;
29256+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
29257 #endif
29258
29259 /*
29260@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
29261 * Does not cover __inittext since that is gone later on. On
29262 * 64bit we do not enforce !NX on the low mapping
29263 */
29264- if (within(address, (unsigned long)_text, (unsigned long)_etext))
29265- pgprot_val(forbidden) |= _PAGE_NX;
29266+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
29267+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
29268
29269+#ifdef CONFIG_DEBUG_RODATA
29270 /*
29271 * The .rodata section needs to be read-only. Using the pfn
29272 * catches all aliases.
29273@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
29274 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
29275 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
29276 pgprot_val(forbidden) |= _PAGE_RW;
29277+#endif
29278
29279 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
29280 /*
29281@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
29282 }
29283 #endif
29284
29285+#ifdef CONFIG_PAX_KERNEXEC
29286+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
29287+ pgprot_val(forbidden) |= _PAGE_RW;
29288+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
29289+ }
29290+#endif
29291+
29292 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
29293
29294 return prot;
29295@@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
29296 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
29297 {
29298 /* change init_mm */
29299+ pax_open_kernel();
29300 set_pte_atomic(kpte, pte);
29301+
29302 #ifdef CONFIG_X86_32
29303 if (!SHARED_KERNEL_PMD) {
29304+
29305+#ifdef CONFIG_PAX_PER_CPU_PGD
29306+ unsigned long cpu;
29307+#else
29308 struct page *page;
29309+#endif
29310
29311+#ifdef CONFIG_PAX_PER_CPU_PGD
29312+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
29313+ pgd_t *pgd = get_cpu_pgd(cpu);
29314+#else
29315 list_for_each_entry(page, &pgd_list, lru) {
29316- pgd_t *pgd;
29317+ pgd_t *pgd = (pgd_t *)page_address(page);
29318+#endif
29319+
29320 pud_t *pud;
29321 pmd_t *pmd;
29322
29323- pgd = (pgd_t *)page_address(page) + pgd_index(address);
29324+ pgd += pgd_index(address);
29325 pud = pud_offset(pgd, address);
29326 pmd = pmd_offset(pud, address);
29327 set_pte_atomic((pte_t *)pmd, pte);
29328 }
29329 }
29330 #endif
29331+ pax_close_kernel();
29332 }
29333
29334 static int
29335diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
29336index 0eb572e..92f5c1e 100644
29337--- a/arch/x86/mm/pat.c
29338+++ b/arch/x86/mm/pat.c
29339@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
29340
29341 if (!entry) {
29342 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
29343- current->comm, current->pid, start, end - 1);
29344+ current->comm, task_pid_nr(current), start, end - 1);
29345 return -EINVAL;
29346 }
29347
29348@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29349
29350 while (cursor < to) {
29351 if (!devmem_is_allowed(pfn)) {
29352- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
29353- current->comm, from, to - 1);
29354+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
29355+ current->comm, from, to - 1, cursor);
29356 return 0;
29357 }
29358 cursor += PAGE_SIZE;
29359@@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
29360 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
29361 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
29362 "for [mem %#010Lx-%#010Lx]\n",
29363- current->comm, current->pid,
29364+ current->comm, task_pid_nr(current),
29365 cattr_name(flags),
29366 base, (unsigned long long)(base + size-1));
29367 return -EINVAL;
29368@@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
29369 flags = lookup_memtype(paddr);
29370 if (want_flags != flags) {
29371 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
29372- current->comm, current->pid,
29373+ current->comm, task_pid_nr(current),
29374 cattr_name(want_flags),
29375 (unsigned long long)paddr,
29376 (unsigned long long)(paddr + size - 1),
29377@@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
29378 free_memtype(paddr, paddr + size);
29379 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
29380 " for [mem %#010Lx-%#010Lx], got %s\n",
29381- current->comm, current->pid,
29382+ current->comm, task_pid_nr(current),
29383 cattr_name(want_flags),
29384 (unsigned long long)paddr,
29385 (unsigned long long)(paddr + size - 1),
29386diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
29387index 9f0614d..92ae64a 100644
29388--- a/arch/x86/mm/pf_in.c
29389+++ b/arch/x86/mm/pf_in.c
29390@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
29391 int i;
29392 enum reason_type rv = OTHERS;
29393
29394- p = (unsigned char *)ins_addr;
29395+ p = (unsigned char *)ktla_ktva(ins_addr);
29396 p += skip_prefix(p, &prf);
29397 p += get_opcode(p, &opcode);
29398
29399@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
29400 struct prefix_bits prf;
29401 int i;
29402
29403- p = (unsigned char *)ins_addr;
29404+ p = (unsigned char *)ktla_ktva(ins_addr);
29405 p += skip_prefix(p, &prf);
29406 p += get_opcode(p, &opcode);
29407
29408@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
29409 struct prefix_bits prf;
29410 int i;
29411
29412- p = (unsigned char *)ins_addr;
29413+ p = (unsigned char *)ktla_ktva(ins_addr);
29414 p += skip_prefix(p, &prf);
29415 p += get_opcode(p, &opcode);
29416
29417@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
29418 struct prefix_bits prf;
29419 int i;
29420
29421- p = (unsigned char *)ins_addr;
29422+ p = (unsigned char *)ktla_ktva(ins_addr);
29423 p += skip_prefix(p, &prf);
29424 p += get_opcode(p, &opcode);
29425 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
29426@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
29427 struct prefix_bits prf;
29428 int i;
29429
29430- p = (unsigned char *)ins_addr;
29431+ p = (unsigned char *)ktla_ktva(ins_addr);
29432 p += skip_prefix(p, &prf);
29433 p += get_opcode(p, &opcode);
29434 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
29435diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
29436index 395b3b4a..213e72b 100644
29437--- a/arch/x86/mm/pgtable.c
29438+++ b/arch/x86/mm/pgtable.c
29439@@ -91,10 +91,64 @@ static inline void pgd_list_del(pgd_t *pgd)
29440 list_del(&page->lru);
29441 }
29442
29443-#define UNSHARED_PTRS_PER_PGD \
29444- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
29445+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29446+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
29447
29448+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
29449+{
29450+ unsigned int count = USER_PGD_PTRS;
29451
29452+ while (count--)
29453+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
29454+}
29455+#endif
29456+
29457+#ifdef CONFIG_PAX_PER_CPU_PGD
29458+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
29459+{
29460+ unsigned int count = USER_PGD_PTRS;
29461+
29462+ while (count--) {
29463+ pgd_t pgd;
29464+
29465+#ifdef CONFIG_X86_64
29466+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
29467+#else
29468+ pgd = *src++;
29469+#endif
29470+
29471+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29472+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
29473+#endif
29474+
29475+ *dst++ = pgd;
29476+ }
29477+
29478+}
29479+#endif
29480+
29481+#ifdef CONFIG_X86_64
29482+#define pxd_t pud_t
29483+#define pyd_t pgd_t
29484+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
29485+#define pxd_free(mm, pud) pud_free((mm), (pud))
29486+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
29487+#define pyd_offset(mm, address) pgd_offset((mm), (address))
29488+#define PYD_SIZE PGDIR_SIZE
29489+#else
29490+#define pxd_t pmd_t
29491+#define pyd_t pud_t
29492+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
29493+#define pxd_free(mm, pud) pmd_free((mm), (pud))
29494+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
29495+#define pyd_offset(mm, address) pud_offset((mm), (address))
29496+#define PYD_SIZE PUD_SIZE
29497+#endif
29498+
29499+#ifdef CONFIG_PAX_PER_CPU_PGD
29500+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
29501+static inline void pgd_dtor(pgd_t *pgd) {}
29502+#else
29503 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
29504 {
29505 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
29506@@ -135,6 +189,7 @@ static void pgd_dtor(pgd_t *pgd)
29507 pgd_list_del(pgd);
29508 spin_unlock(&pgd_lock);
29509 }
29510+#endif
29511
29512 /*
29513 * List of all pgd's needed for non-PAE so it can invalidate entries
29514@@ -147,7 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
29515 * -- nyc
29516 */
29517
29518-#ifdef CONFIG_X86_PAE
29519+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
29520 /*
29521 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
29522 * updating the top-level pagetable entries to guarantee the
29523@@ -159,7 +214,7 @@ static void pgd_dtor(pgd_t *pgd)
29524 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
29525 * and initialize the kernel pmds here.
29526 */
29527-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
29528+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
29529
29530 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
29531 {
29532@@ -177,36 +232,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
29533 */
29534 flush_tlb_mm(mm);
29535 }
29536+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
29537+#define PREALLOCATED_PXDS USER_PGD_PTRS
29538 #else /* !CONFIG_X86_PAE */
29539
29540 /* No need to prepopulate any pagetable entries in non-PAE modes. */
29541-#define PREALLOCATED_PMDS 0
29542+#define PREALLOCATED_PXDS 0
29543
29544 #endif /* CONFIG_X86_PAE */
29545
29546-static void free_pmds(pmd_t *pmds[])
29547+static void free_pxds(pxd_t *pxds[])
29548 {
29549 int i;
29550
29551- for(i = 0; i < PREALLOCATED_PMDS; i++)
29552- if (pmds[i])
29553- free_page((unsigned long)pmds[i]);
29554+ for(i = 0; i < PREALLOCATED_PXDS; i++)
29555+ if (pxds[i])
29556+ free_page((unsigned long)pxds[i]);
29557 }
29558
29559-static int preallocate_pmds(pmd_t *pmds[])
29560+static int preallocate_pxds(pxd_t *pxds[])
29561 {
29562 int i;
29563 bool failed = false;
29564
29565- for(i = 0; i < PREALLOCATED_PMDS; i++) {
29566- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
29567- if (pmd == NULL)
29568+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
29569+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
29570+ if (pxd == NULL)
29571 failed = true;
29572- pmds[i] = pmd;
29573+ pxds[i] = pxd;
29574 }
29575
29576 if (failed) {
29577- free_pmds(pmds);
29578+ free_pxds(pxds);
29579 return -ENOMEM;
29580 }
29581
29582@@ -219,51 +276,55 @@ static int preallocate_pmds(pmd_t *pmds[])
29583 * preallocate which never got a corresponding vma will need to be
29584 * freed manually.
29585 */
29586-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
29587+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
29588 {
29589 int i;
29590
29591- for(i = 0; i < PREALLOCATED_PMDS; i++) {
29592+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
29593 pgd_t pgd = pgdp[i];
29594
29595 if (pgd_val(pgd) != 0) {
29596- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
29597+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
29598
29599- pgdp[i] = native_make_pgd(0);
29600+ set_pgd(pgdp + i, native_make_pgd(0));
29601
29602- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
29603- pmd_free(mm, pmd);
29604+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
29605+ pxd_free(mm, pxd);
29606 }
29607 }
29608 }
29609
29610-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
29611+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
29612 {
29613- pud_t *pud;
29614+ pyd_t *pyd;
29615 unsigned long addr;
29616 int i;
29617
29618- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
29619+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
29620 return;
29621
29622- pud = pud_offset(pgd, 0);
29623+#ifdef CONFIG_X86_64
29624+ pyd = pyd_offset(mm, 0L);
29625+#else
29626+ pyd = pyd_offset(pgd, 0L);
29627+#endif
29628
29629- for (addr = i = 0; i < PREALLOCATED_PMDS;
29630- i++, pud++, addr += PUD_SIZE) {
29631- pmd_t *pmd = pmds[i];
29632+ for (addr = i = 0; i < PREALLOCATED_PXDS;
29633+ i++, pyd++, addr += PYD_SIZE) {
29634+ pxd_t *pxd = pxds[i];
29635
29636 if (i >= KERNEL_PGD_BOUNDARY)
29637- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
29638- sizeof(pmd_t) * PTRS_PER_PMD);
29639+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
29640+ sizeof(pxd_t) * PTRS_PER_PMD);
29641
29642- pud_populate(mm, pud, pmd);
29643+ pyd_populate(mm, pyd, pxd);
29644 }
29645 }
29646
29647 pgd_t *pgd_alloc(struct mm_struct *mm)
29648 {
29649 pgd_t *pgd;
29650- pmd_t *pmds[PREALLOCATED_PMDS];
29651+ pxd_t *pxds[PREALLOCATED_PXDS];
29652
29653 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
29654
29655@@ -272,11 +333,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
29656
29657 mm->pgd = pgd;
29658
29659- if (preallocate_pmds(pmds) != 0)
29660+ if (preallocate_pxds(pxds) != 0)
29661 goto out_free_pgd;
29662
29663 if (paravirt_pgd_alloc(mm) != 0)
29664- goto out_free_pmds;
29665+ goto out_free_pxds;
29666
29667 /*
29668 * Make sure that pre-populating the pmds is atomic with
29669@@ -286,14 +347,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
29670 spin_lock(&pgd_lock);
29671
29672 pgd_ctor(mm, pgd);
29673- pgd_prepopulate_pmd(mm, pgd, pmds);
29674+ pgd_prepopulate_pxd(mm, pgd, pxds);
29675
29676 spin_unlock(&pgd_lock);
29677
29678 return pgd;
29679
29680-out_free_pmds:
29681- free_pmds(pmds);
29682+out_free_pxds:
29683+ free_pxds(pxds);
29684 out_free_pgd:
29685 free_page((unsigned long)pgd);
29686 out:
29687@@ -302,7 +363,7 @@ out:
29688
29689 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
29690 {
29691- pgd_mop_up_pmds(mm, pgd);
29692+ pgd_mop_up_pxds(mm, pgd);
29693 pgd_dtor(pgd);
29694 paravirt_pgd_free(mm, pgd);
29695 free_page((unsigned long)pgd);
29696diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
29697index a69bcb8..19068ab 100644
29698--- a/arch/x86/mm/pgtable_32.c
29699+++ b/arch/x86/mm/pgtable_32.c
29700@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
29701 return;
29702 }
29703 pte = pte_offset_kernel(pmd, vaddr);
29704+
29705+ pax_open_kernel();
29706 if (pte_val(pteval))
29707 set_pte_at(&init_mm, vaddr, pte, pteval);
29708 else
29709 pte_clear(&init_mm, vaddr, pte);
29710+ pax_close_kernel();
29711
29712 /*
29713 * It's enough to flush this one mapping.
29714diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
29715index d2e2735..5c6586f 100644
29716--- a/arch/x86/mm/physaddr.c
29717+++ b/arch/x86/mm/physaddr.c
29718@@ -8,7 +8,7 @@
29719
29720 #ifdef CONFIG_X86_64
29721
29722-unsigned long __phys_addr(unsigned long x)
29723+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
29724 {
29725 if (x >= __START_KERNEL_map) {
29726 x -= __START_KERNEL_map;
29727@@ -45,7 +45,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
29728 #else
29729
29730 #ifdef CONFIG_DEBUG_VIRTUAL
29731-unsigned long __phys_addr(unsigned long x)
29732+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
29733 {
29734 /* VMALLOC_* aren't constants */
29735 VIRTUAL_BUG_ON(x < PAGE_OFFSET);
29736diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
29737index 410531d..0f16030 100644
29738--- a/arch/x86/mm/setup_nx.c
29739+++ b/arch/x86/mm/setup_nx.c
29740@@ -5,8 +5,10 @@
29741 #include <asm/pgtable.h>
29742 #include <asm/proto.h>
29743
29744+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29745 static int disable_nx __cpuinitdata;
29746
29747+#ifndef CONFIG_PAX_PAGEEXEC
29748 /*
29749 * noexec = on|off
29750 *
29751@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
29752 return 0;
29753 }
29754 early_param("noexec", noexec_setup);
29755+#endif
29756+
29757+#endif
29758
29759 void __cpuinit x86_configure_nx(void)
29760 {
29761+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29762 if (cpu_has_nx && !disable_nx)
29763 __supported_pte_mask |= _PAGE_NX;
29764 else
29765+#endif
29766 __supported_pte_mask &= ~_PAGE_NX;
29767 }
29768
29769diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
29770index 13a6b29..c2fff23 100644
29771--- a/arch/x86/mm/tlb.c
29772+++ b/arch/x86/mm/tlb.c
29773@@ -48,7 +48,11 @@ void leave_mm(int cpu)
29774 BUG();
29775 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
29776 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
29777+
29778+#ifndef CONFIG_PAX_PER_CPU_PGD
29779 load_cr3(swapper_pg_dir);
29780+#endif
29781+
29782 }
29783 }
29784 EXPORT_SYMBOL_GPL(leave_mm);
29785diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
29786index 877b9a1..a8ecf42 100644
29787--- a/arch/x86/net/bpf_jit.S
29788+++ b/arch/x86/net/bpf_jit.S
29789@@ -9,6 +9,7 @@
29790 */
29791 #include <linux/linkage.h>
29792 #include <asm/dwarf2.h>
29793+#include <asm/alternative-asm.h>
29794
29795 /*
29796 * Calling convention :
29797@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
29798 jle bpf_slow_path_word
29799 mov (SKBDATA,%rsi),%eax
29800 bswap %eax /* ntohl() */
29801+ pax_force_retaddr
29802 ret
29803
29804 sk_load_half:
29805@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
29806 jle bpf_slow_path_half
29807 movzwl (SKBDATA,%rsi),%eax
29808 rol $8,%ax # ntohs()
29809+ pax_force_retaddr
29810 ret
29811
29812 sk_load_byte:
29813@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
29814 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
29815 jle bpf_slow_path_byte
29816 movzbl (SKBDATA,%rsi),%eax
29817+ pax_force_retaddr
29818 ret
29819
29820 /**
29821@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
29822 movzbl (SKBDATA,%rsi),%ebx
29823 and $15,%bl
29824 shl $2,%bl
29825+ pax_force_retaddr
29826 ret
29827
29828 /* rsi contains offset and can be scratched */
29829@@ -109,6 +114,7 @@ bpf_slow_path_word:
29830 js bpf_error
29831 mov -12(%rbp),%eax
29832 bswap %eax
29833+ pax_force_retaddr
29834 ret
29835
29836 bpf_slow_path_half:
29837@@ -117,12 +123,14 @@ bpf_slow_path_half:
29838 mov -12(%rbp),%ax
29839 rol $8,%ax
29840 movzwl %ax,%eax
29841+ pax_force_retaddr
29842 ret
29843
29844 bpf_slow_path_byte:
29845 bpf_slow_path_common(1)
29846 js bpf_error
29847 movzbl -12(%rbp),%eax
29848+ pax_force_retaddr
29849 ret
29850
29851 bpf_slow_path_byte_msh:
29852@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
29853 and $15,%al
29854 shl $2,%al
29855 xchg %eax,%ebx
29856+ pax_force_retaddr
29857 ret
29858
29859 #define sk_negative_common(SIZE) \
29860@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
29861 sk_negative_common(4)
29862 mov (%rax), %eax
29863 bswap %eax
29864+ pax_force_retaddr
29865 ret
29866
29867 bpf_slow_path_half_neg:
29868@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
29869 mov (%rax),%ax
29870 rol $8,%ax
29871 movzwl %ax,%eax
29872+ pax_force_retaddr
29873 ret
29874
29875 bpf_slow_path_byte_neg:
29876@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
29877 .globl sk_load_byte_negative_offset
29878 sk_negative_common(1)
29879 movzbl (%rax), %eax
29880+ pax_force_retaddr
29881 ret
29882
29883 bpf_slow_path_byte_msh_neg:
29884@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
29885 and $15,%al
29886 shl $2,%al
29887 xchg %eax,%ebx
29888+ pax_force_retaddr
29889 ret
29890
29891 bpf_error:
29892@@ -197,4 +210,5 @@ bpf_error:
29893 xor %eax,%eax
29894 mov -8(%rbp),%rbx
29895 leaveq
29896+ pax_force_retaddr
29897 ret
29898diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
29899index d11a470..3f9adff3 100644
29900--- a/arch/x86/net/bpf_jit_comp.c
29901+++ b/arch/x86/net/bpf_jit_comp.c
29902@@ -12,6 +12,7 @@
29903 #include <linux/netdevice.h>
29904 #include <linux/filter.h>
29905 #include <linux/if_vlan.h>
29906+#include <linux/random.h>
29907
29908 /*
29909 * Conventions :
29910@@ -49,13 +50,87 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
29911 return ptr + len;
29912 }
29913
29914+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29915+#define MAX_INSTR_CODE_SIZE 96
29916+#else
29917+#define MAX_INSTR_CODE_SIZE 64
29918+#endif
29919+
29920 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
29921
29922 #define EMIT1(b1) EMIT(b1, 1)
29923 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
29924 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
29925 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
29926+
29927+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29928+/* original constant will appear in ecx */
29929+#define DILUTE_CONST_SEQUENCE(_off, _key) \
29930+do { \
29931+ /* mov ecx, randkey */ \
29932+ EMIT1(0xb9); \
29933+ EMIT(_key, 4); \
29934+ /* xor ecx, randkey ^ off */ \
29935+ EMIT2(0x81, 0xf1); \
29936+ EMIT((_key) ^ (_off), 4); \
29937+} while (0)
29938+
29939+#define EMIT1_off32(b1, _off) \
29940+do { \
29941+ switch (b1) { \
29942+ case 0x05: /* add eax, imm32 */ \
29943+ case 0x2d: /* sub eax, imm32 */ \
29944+ case 0x25: /* and eax, imm32 */ \
29945+ case 0x0d: /* or eax, imm32 */ \
29946+ case 0xb8: /* mov eax, imm32 */ \
29947+ case 0x3d: /* cmp eax, imm32 */ \
29948+ case 0xa9: /* test eax, imm32 */ \
29949+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29950+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
29951+ break; \
29952+ case 0xbb: /* mov ebx, imm32 */ \
29953+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29954+ /* mov ebx, ecx */ \
29955+ EMIT2(0x89, 0xcb); \
29956+ break; \
29957+ case 0xbe: /* mov esi, imm32 */ \
29958+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29959+ /* mov esi, ecx */ \
29960+ EMIT2(0x89, 0xce); \
29961+ break; \
29962+ case 0xe9: /* jmp rel imm32 */ \
29963+ EMIT1(b1); \
29964+ EMIT(_off, 4); \
29965+ /* prevent fall-through, we're not called if off = 0 */ \
29966+ EMIT(0xcccccccc, 4); \
29967+ EMIT(0xcccccccc, 4); \
29968+ break; \
29969+ default: \
29970+ EMIT1(b1); \
29971+ EMIT(_off, 4); \
29972+ } \
29973+} while (0)
29974+
29975+#define EMIT2_off32(b1, b2, _off) \
29976+do { \
29977+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
29978+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
29979+ EMIT(randkey, 4); \
29980+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
29981+ EMIT((_off) - randkey, 4); \
29982+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
29983+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29984+ /* imul eax, ecx */ \
29985+ EMIT3(0x0f, 0xaf, 0xc1); \
29986+ } else { \
29987+ EMIT2(b1, b2); \
29988+ EMIT(_off, 4); \
29989+ } \
29990+} while (0)
29991+#else
29992 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
29993+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
29994+#endif
29995
29996 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
29997 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
29998@@ -90,6 +165,24 @@ do { \
29999 #define X86_JBE 0x76
30000 #define X86_JA 0x77
30001
30002+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
30003+#define APPEND_FLOW_VERIFY() \
30004+do { \
30005+ /* mov ecx, randkey */ \
30006+ EMIT1(0xb9); \
30007+ EMIT(randkey, 4); \
30008+ /* cmp ecx, randkey */ \
30009+ EMIT2(0x81, 0xf9); \
30010+ EMIT(randkey, 4); \
30011+ /* jz after 8 int 3s */ \
30012+ EMIT2(0x74, 0x08); \
30013+ EMIT(0xcccccccc, 4); \
30014+ EMIT(0xcccccccc, 4); \
30015+} while (0)
30016+#else
30017+#define APPEND_FLOW_VERIFY() do { } while (0)
30018+#endif
30019+
30020 #define EMIT_COND_JMP(op, offset) \
30021 do { \
30022 if (is_near(offset)) \
30023@@ -97,6 +190,7 @@ do { \
30024 else { \
30025 EMIT2(0x0f, op + 0x10); \
30026 EMIT(offset, 4); /* jxx .+off32 */ \
30027+ APPEND_FLOW_VERIFY(); \
30028 } \
30029 } while (0)
30030
30031@@ -121,12 +215,17 @@ static inline void bpf_flush_icache(void *start, void *end)
30032 set_fs(old_fs);
30033 }
30034
30035+struct bpf_jit_work {
30036+ struct work_struct work;
30037+ void *image;
30038+};
30039+
30040 #define CHOOSE_LOAD_FUNC(K, func) \
30041 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
30042
30043 void bpf_jit_compile(struct sk_filter *fp)
30044 {
30045- u8 temp[64];
30046+ u8 temp[MAX_INSTR_CODE_SIZE];
30047 u8 *prog;
30048 unsigned int proglen, oldproglen = 0;
30049 int ilen, i;
30050@@ -139,6 +238,9 @@ void bpf_jit_compile(struct sk_filter *fp)
30051 unsigned int *addrs;
30052 const struct sock_filter *filter = fp->insns;
30053 int flen = fp->len;
30054+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
30055+ unsigned int randkey;
30056+#endif
30057
30058 if (!bpf_jit_enable)
30059 return;
30060@@ -147,11 +249,19 @@ void bpf_jit_compile(struct sk_filter *fp)
30061 if (addrs == NULL)
30062 return;
30063
30064+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
30065+ if (!fp->work)
30066+ goto out;
30067+
30068+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
30069+ randkey = get_random_int();
30070+#endif
30071+
30072 /* Before first pass, make a rough estimation of addrs[]
30073- * each bpf instruction is translated to less than 64 bytes
30074+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
30075 */
30076 for (proglen = 0, i = 0; i < flen; i++) {
30077- proglen += 64;
30078+ proglen += MAX_INSTR_CODE_SIZE;
30079 addrs[i] = proglen;
30080 }
30081 cleanup_addr = proglen; /* epilogue address */
30082@@ -261,10 +371,8 @@ void bpf_jit_compile(struct sk_filter *fp)
30083 case BPF_S_ALU_MUL_K: /* A *= K */
30084 if (is_imm8(K))
30085 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
30086- else {
30087- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
30088- EMIT(K, 4);
30089- }
30090+ else
30091+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
30092 break;
30093 case BPF_S_ALU_DIV_X: /* A /= X; */
30094 seen |= SEEN_XREG;
30095@@ -304,13 +412,23 @@ void bpf_jit_compile(struct sk_filter *fp)
30096 break;
30097 case BPF_S_ALU_MOD_K: /* A %= K; */
30098 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
30099+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
30100+ DILUTE_CONST_SEQUENCE(K, randkey);
30101+#else
30102 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
30103+#endif
30104 EMIT2(0xf7, 0xf1); /* div %ecx */
30105 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
30106 break;
30107 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
30108+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
30109+ DILUTE_CONST_SEQUENCE(K, randkey);
30110+ // imul rax, rcx
30111+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
30112+#else
30113 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
30114 EMIT(K, 4);
30115+#endif
30116 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
30117 break;
30118 case BPF_S_ALU_AND_X:
30119@@ -564,8 +682,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
30120 if (is_imm8(K)) {
30121 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
30122 } else {
30123- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
30124- EMIT(K, 4);
30125+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
30126 }
30127 } else {
30128 EMIT2(0x89,0xde); /* mov %ebx,%esi */
30129@@ -648,17 +765,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
30130 break;
30131 default:
30132 /* hmm, too complex filter, give up with jit compiler */
30133- goto out;
30134+ goto error;
30135 }
30136 ilen = prog - temp;
30137 if (image) {
30138 if (unlikely(proglen + ilen > oldproglen)) {
30139 pr_err("bpb_jit_compile fatal error\n");
30140- kfree(addrs);
30141- module_free(NULL, image);
30142- return;
30143+ module_free_exec(NULL, image);
30144+ goto error;
30145 }
30146+ pax_open_kernel();
30147 memcpy(image + proglen, temp, ilen);
30148+ pax_close_kernel();
30149 }
30150 proglen += ilen;
30151 addrs[i] = proglen;
30152@@ -679,11 +797,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
30153 break;
30154 }
30155 if (proglen == oldproglen) {
30156- image = module_alloc(max_t(unsigned int,
30157- proglen,
30158- sizeof(struct work_struct)));
30159+ image = module_alloc_exec(proglen);
30160 if (!image)
30161- goto out;
30162+ goto error;
30163 }
30164 oldproglen = proglen;
30165 }
30166@@ -699,7 +815,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
30167 bpf_flush_icache(image, image + proglen);
30168
30169 fp->bpf_func = (void *)image;
30170- }
30171+ } else
30172+error:
30173+ kfree(fp->work);
30174+
30175 out:
30176 kfree(addrs);
30177 return;
30178@@ -707,18 +826,20 @@ out:
30179
30180 static void jit_free_defer(struct work_struct *arg)
30181 {
30182- module_free(NULL, arg);
30183+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
30184+ kfree(arg);
30185 }
30186
30187 /* run from softirq, we must use a work_struct to call
30188- * module_free() from process context
30189+ * module_free_exec() from process context
30190 */
30191 void bpf_jit_free(struct sk_filter *fp)
30192 {
30193 if (fp->bpf_func != sk_run_filter) {
30194- struct work_struct *work = (struct work_struct *)fp->bpf_func;
30195+ struct work_struct *work = &fp->work->work;
30196
30197 INIT_WORK(work, jit_free_defer);
30198+ fp->work->image = fp->bpf_func;
30199 schedule_work(work);
30200 }
30201 }
30202diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
30203index d6aa6e8..266395a 100644
30204--- a/arch/x86/oprofile/backtrace.c
30205+++ b/arch/x86/oprofile/backtrace.c
30206@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
30207 struct stack_frame_ia32 *fp;
30208 unsigned long bytes;
30209
30210- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
30211+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
30212 if (bytes != sizeof(bufhead))
30213 return NULL;
30214
30215- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
30216+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
30217
30218 oprofile_add_trace(bufhead[0].return_address);
30219
30220@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
30221 struct stack_frame bufhead[2];
30222 unsigned long bytes;
30223
30224- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
30225+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
30226 if (bytes != sizeof(bufhead))
30227 return NULL;
30228
30229@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
30230 {
30231 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
30232
30233- if (!user_mode_vm(regs)) {
30234+ if (!user_mode(regs)) {
30235 unsigned long stack = kernel_stack_pointer(regs);
30236 if (depth)
30237 dump_trace(NULL, regs, (unsigned long *)stack, 0,
30238diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
30239index 48768df..ba9143c 100644
30240--- a/arch/x86/oprofile/nmi_int.c
30241+++ b/arch/x86/oprofile/nmi_int.c
30242@@ -23,6 +23,7 @@
30243 #include <asm/nmi.h>
30244 #include <asm/msr.h>
30245 #include <asm/apic.h>
30246+#include <asm/pgtable.h>
30247
30248 #include "op_counter.h"
30249 #include "op_x86_model.h"
30250@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
30251 if (ret)
30252 return ret;
30253
30254- if (!model->num_virt_counters)
30255- model->num_virt_counters = model->num_counters;
30256+ if (!model->num_virt_counters) {
30257+ pax_open_kernel();
30258+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
30259+ pax_close_kernel();
30260+ }
30261
30262 mux_init(ops);
30263
30264diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
30265index b2b9443..be58856 100644
30266--- a/arch/x86/oprofile/op_model_amd.c
30267+++ b/arch/x86/oprofile/op_model_amd.c
30268@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
30269 num_counters = AMD64_NUM_COUNTERS;
30270 }
30271
30272- op_amd_spec.num_counters = num_counters;
30273- op_amd_spec.num_controls = num_counters;
30274- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
30275+ pax_open_kernel();
30276+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
30277+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
30278+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
30279+ pax_close_kernel();
30280
30281 return 0;
30282 }
30283diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
30284index d90528e..0127e2b 100644
30285--- a/arch/x86/oprofile/op_model_ppro.c
30286+++ b/arch/x86/oprofile/op_model_ppro.c
30287@@ -19,6 +19,7 @@
30288 #include <asm/msr.h>
30289 #include <asm/apic.h>
30290 #include <asm/nmi.h>
30291+#include <asm/pgtable.h>
30292
30293 #include "op_x86_model.h"
30294 #include "op_counter.h"
30295@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
30296
30297 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
30298
30299- op_arch_perfmon_spec.num_counters = num_counters;
30300- op_arch_perfmon_spec.num_controls = num_counters;
30301+ pax_open_kernel();
30302+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
30303+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
30304+ pax_close_kernel();
30305 }
30306
30307 static int arch_perfmon_init(struct oprofile_operations *ignore)
30308diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
30309index 71e8a67..6a313bb 100644
30310--- a/arch/x86/oprofile/op_x86_model.h
30311+++ b/arch/x86/oprofile/op_x86_model.h
30312@@ -52,7 +52,7 @@ struct op_x86_model_spec {
30313 void (*switch_ctrl)(struct op_x86_model_spec const *model,
30314 struct op_msrs const * const msrs);
30315 #endif
30316-};
30317+} __do_const;
30318
30319 struct op_counter_config;
30320
30321diff --git a/arch/x86/pci/amd_bus.c b/arch/x86/pci/amd_bus.c
30322index e9e6ed5..e47ae67 100644
30323--- a/arch/x86/pci/amd_bus.c
30324+++ b/arch/x86/pci/amd_bus.c
30325@@ -337,7 +337,7 @@ static int __cpuinit amd_cpu_notify(struct notifier_block *self,
30326 return NOTIFY_OK;
30327 }
30328
30329-static struct notifier_block __cpuinitdata amd_cpu_notifier = {
30330+static struct notifier_block amd_cpu_notifier = {
30331 .notifier_call = amd_cpu_notify,
30332 };
30333
30334diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
30335index 372e9b8..e775a6c 100644
30336--- a/arch/x86/pci/irq.c
30337+++ b/arch/x86/pci/irq.c
30338@@ -50,7 +50,7 @@ struct irq_router {
30339 struct irq_router_handler {
30340 u16 vendor;
30341 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
30342-};
30343+} __do_const;
30344
30345 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
30346 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
30347@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
30348 return 0;
30349 }
30350
30351-static __initdata struct irq_router_handler pirq_routers[] = {
30352+static __initconst const struct irq_router_handler pirq_routers[] = {
30353 { PCI_VENDOR_ID_INTEL, intel_router_probe },
30354 { PCI_VENDOR_ID_AL, ali_router_probe },
30355 { PCI_VENDOR_ID_ITE, ite_router_probe },
30356@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
30357 static void __init pirq_find_router(struct irq_router *r)
30358 {
30359 struct irq_routing_table *rt = pirq_table;
30360- struct irq_router_handler *h;
30361+ const struct irq_router_handler *h;
30362
30363 #ifdef CONFIG_PCI_BIOS
30364 if (!rt->signature) {
30365@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
30366 return 0;
30367 }
30368
30369-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
30370+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
30371 {
30372 .callback = fix_broken_hp_bios_irq9,
30373 .ident = "HP Pavilion N5400 Series Laptop",
30374diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
30375index 6eb18c4..20d83de 100644
30376--- a/arch/x86/pci/mrst.c
30377+++ b/arch/x86/pci/mrst.c
30378@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
30379 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
30380 pci_mmcfg_late_init();
30381 pcibios_enable_irq = mrst_pci_irq_enable;
30382- pci_root_ops = pci_mrst_ops;
30383+ pax_open_kernel();
30384+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
30385+ pax_close_kernel();
30386 pci_soc_mode = 1;
30387 /* Continue with standard init */
30388 return 1;
30389diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
30390index c77b24a..c979855 100644
30391--- a/arch/x86/pci/pcbios.c
30392+++ b/arch/x86/pci/pcbios.c
30393@@ -79,7 +79,7 @@ union bios32 {
30394 static struct {
30395 unsigned long address;
30396 unsigned short segment;
30397-} bios32_indirect = { 0, __KERNEL_CS };
30398+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
30399
30400 /*
30401 * Returns the entry point for the given service, NULL on error
30402@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
30403 unsigned long length; /* %ecx */
30404 unsigned long entry; /* %edx */
30405 unsigned long flags;
30406+ struct desc_struct d, *gdt;
30407
30408 local_irq_save(flags);
30409- __asm__("lcall *(%%edi); cld"
30410+
30411+ gdt = get_cpu_gdt_table(smp_processor_id());
30412+
30413+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
30414+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
30415+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
30416+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
30417+
30418+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
30419 : "=a" (return_code),
30420 "=b" (address),
30421 "=c" (length),
30422 "=d" (entry)
30423 : "0" (service),
30424 "1" (0),
30425- "D" (&bios32_indirect));
30426+ "D" (&bios32_indirect),
30427+ "r"(__PCIBIOS_DS)
30428+ : "memory");
30429+
30430+ pax_open_kernel();
30431+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
30432+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
30433+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
30434+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
30435+ pax_close_kernel();
30436+
30437 local_irq_restore(flags);
30438
30439 switch (return_code) {
30440- case 0:
30441- return address + entry;
30442- case 0x80: /* Not present */
30443- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
30444- return 0;
30445- default: /* Shouldn't happen */
30446- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
30447- service, return_code);
30448+ case 0: {
30449+ int cpu;
30450+ unsigned char flags;
30451+
30452+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
30453+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
30454+ printk(KERN_WARNING "bios32_service: not valid\n");
30455 return 0;
30456+ }
30457+ address = address + PAGE_OFFSET;
30458+ length += 16UL; /* some BIOSs underreport this... */
30459+ flags = 4;
30460+ if (length >= 64*1024*1024) {
30461+ length >>= PAGE_SHIFT;
30462+ flags |= 8;
30463+ }
30464+
30465+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
30466+ gdt = get_cpu_gdt_table(cpu);
30467+ pack_descriptor(&d, address, length, 0x9b, flags);
30468+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
30469+ pack_descriptor(&d, address, length, 0x93, flags);
30470+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
30471+ }
30472+ return entry;
30473+ }
30474+ case 0x80: /* Not present */
30475+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
30476+ return 0;
30477+ default: /* Shouldn't happen */
30478+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
30479+ service, return_code);
30480+ return 0;
30481 }
30482 }
30483
30484 static struct {
30485 unsigned long address;
30486 unsigned short segment;
30487-} pci_indirect = { 0, __KERNEL_CS };
30488+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
30489
30490-static int pci_bios_present;
30491+static int pci_bios_present __read_only;
30492
30493 static int check_pcibios(void)
30494 {
30495@@ -131,11 +174,13 @@ static int check_pcibios(void)
30496 unsigned long flags, pcibios_entry;
30497
30498 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
30499- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
30500+ pci_indirect.address = pcibios_entry;
30501
30502 local_irq_save(flags);
30503- __asm__(
30504- "lcall *(%%edi); cld\n\t"
30505+ __asm__("movw %w6, %%ds\n\t"
30506+ "lcall *%%ss:(%%edi); cld\n\t"
30507+ "push %%ss\n\t"
30508+ "pop %%ds\n\t"
30509 "jc 1f\n\t"
30510 "xor %%ah, %%ah\n"
30511 "1:"
30512@@ -144,7 +189,8 @@ static int check_pcibios(void)
30513 "=b" (ebx),
30514 "=c" (ecx)
30515 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
30516- "D" (&pci_indirect)
30517+ "D" (&pci_indirect),
30518+ "r" (__PCIBIOS_DS)
30519 : "memory");
30520 local_irq_restore(flags);
30521
30522@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30523
30524 switch (len) {
30525 case 1:
30526- __asm__("lcall *(%%esi); cld\n\t"
30527+ __asm__("movw %w6, %%ds\n\t"
30528+ "lcall *%%ss:(%%esi); cld\n\t"
30529+ "push %%ss\n\t"
30530+ "pop %%ds\n\t"
30531 "jc 1f\n\t"
30532 "xor %%ah, %%ah\n"
30533 "1:"
30534@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30535 : "1" (PCIBIOS_READ_CONFIG_BYTE),
30536 "b" (bx),
30537 "D" ((long)reg),
30538- "S" (&pci_indirect));
30539+ "S" (&pci_indirect),
30540+ "r" (__PCIBIOS_DS));
30541 /*
30542 * Zero-extend the result beyond 8 bits, do not trust the
30543 * BIOS having done it:
30544@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30545 *value &= 0xff;
30546 break;
30547 case 2:
30548- __asm__("lcall *(%%esi); cld\n\t"
30549+ __asm__("movw %w6, %%ds\n\t"
30550+ "lcall *%%ss:(%%esi); cld\n\t"
30551+ "push %%ss\n\t"
30552+ "pop %%ds\n\t"
30553 "jc 1f\n\t"
30554 "xor %%ah, %%ah\n"
30555 "1:"
30556@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30557 : "1" (PCIBIOS_READ_CONFIG_WORD),
30558 "b" (bx),
30559 "D" ((long)reg),
30560- "S" (&pci_indirect));
30561+ "S" (&pci_indirect),
30562+ "r" (__PCIBIOS_DS));
30563 /*
30564 * Zero-extend the result beyond 16 bits, do not trust the
30565 * BIOS having done it:
30566@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30567 *value &= 0xffff;
30568 break;
30569 case 4:
30570- __asm__("lcall *(%%esi); cld\n\t"
30571+ __asm__("movw %w6, %%ds\n\t"
30572+ "lcall *%%ss:(%%esi); cld\n\t"
30573+ "push %%ss\n\t"
30574+ "pop %%ds\n\t"
30575 "jc 1f\n\t"
30576 "xor %%ah, %%ah\n"
30577 "1:"
30578@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30579 : "1" (PCIBIOS_READ_CONFIG_DWORD),
30580 "b" (bx),
30581 "D" ((long)reg),
30582- "S" (&pci_indirect));
30583+ "S" (&pci_indirect),
30584+ "r" (__PCIBIOS_DS));
30585 break;
30586 }
30587
30588@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30589
30590 switch (len) {
30591 case 1:
30592- __asm__("lcall *(%%esi); cld\n\t"
30593+ __asm__("movw %w6, %%ds\n\t"
30594+ "lcall *%%ss:(%%esi); cld\n\t"
30595+ "push %%ss\n\t"
30596+ "pop %%ds\n\t"
30597 "jc 1f\n\t"
30598 "xor %%ah, %%ah\n"
30599 "1:"
30600@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30601 "c" (value),
30602 "b" (bx),
30603 "D" ((long)reg),
30604- "S" (&pci_indirect));
30605+ "S" (&pci_indirect),
30606+ "r" (__PCIBIOS_DS));
30607 break;
30608 case 2:
30609- __asm__("lcall *(%%esi); cld\n\t"
30610+ __asm__("movw %w6, %%ds\n\t"
30611+ "lcall *%%ss:(%%esi); cld\n\t"
30612+ "push %%ss\n\t"
30613+ "pop %%ds\n\t"
30614 "jc 1f\n\t"
30615 "xor %%ah, %%ah\n"
30616 "1:"
30617@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30618 "c" (value),
30619 "b" (bx),
30620 "D" ((long)reg),
30621- "S" (&pci_indirect));
30622+ "S" (&pci_indirect),
30623+ "r" (__PCIBIOS_DS));
30624 break;
30625 case 4:
30626- __asm__("lcall *(%%esi); cld\n\t"
30627+ __asm__("movw %w6, %%ds\n\t"
30628+ "lcall *%%ss:(%%esi); cld\n\t"
30629+ "push %%ss\n\t"
30630+ "pop %%ds\n\t"
30631 "jc 1f\n\t"
30632 "xor %%ah, %%ah\n"
30633 "1:"
30634@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30635 "c" (value),
30636 "b" (bx),
30637 "D" ((long)reg),
30638- "S" (&pci_indirect));
30639+ "S" (&pci_indirect),
30640+ "r" (__PCIBIOS_DS));
30641 break;
30642 }
30643
30644@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
30645
30646 DBG("PCI: Fetching IRQ routing table... ");
30647 __asm__("push %%es\n\t"
30648+ "movw %w8, %%ds\n\t"
30649 "push %%ds\n\t"
30650 "pop %%es\n\t"
30651- "lcall *(%%esi); cld\n\t"
30652+ "lcall *%%ss:(%%esi); cld\n\t"
30653 "pop %%es\n\t"
30654+ "push %%ss\n\t"
30655+ "pop %%ds\n"
30656 "jc 1f\n\t"
30657 "xor %%ah, %%ah\n"
30658 "1:"
30659@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
30660 "1" (0),
30661 "D" ((long) &opt),
30662 "S" (&pci_indirect),
30663- "m" (opt)
30664+ "m" (opt),
30665+ "r" (__PCIBIOS_DS)
30666 : "memory");
30667 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
30668 if (ret & 0xff00)
30669@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
30670 {
30671 int ret;
30672
30673- __asm__("lcall *(%%esi); cld\n\t"
30674+ __asm__("movw %w5, %%ds\n\t"
30675+ "lcall *%%ss:(%%esi); cld\n\t"
30676+ "push %%ss\n\t"
30677+ "pop %%ds\n"
30678 "jc 1f\n\t"
30679 "xor %%ah, %%ah\n"
30680 "1:"
30681@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
30682 : "0" (PCIBIOS_SET_PCI_HW_INT),
30683 "b" ((dev->bus->number << 8) | dev->devfn),
30684 "c" ((irq << 8) | (pin + 10)),
30685- "S" (&pci_indirect));
30686+ "S" (&pci_indirect),
30687+ "r" (__PCIBIOS_DS));
30688 return !(ret & 0xff00);
30689 }
30690 EXPORT_SYMBOL(pcibios_set_irq_routing);
30691diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
30692index 40e4469..1ab536e 100644
30693--- a/arch/x86/platform/efi/efi_32.c
30694+++ b/arch/x86/platform/efi/efi_32.c
30695@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
30696 {
30697 struct desc_ptr gdt_descr;
30698
30699+#ifdef CONFIG_PAX_KERNEXEC
30700+ struct desc_struct d;
30701+#endif
30702+
30703 local_irq_save(efi_rt_eflags);
30704
30705 load_cr3(initial_page_table);
30706 __flush_tlb_all();
30707
30708+#ifdef CONFIG_PAX_KERNEXEC
30709+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
30710+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
30711+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
30712+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
30713+#endif
30714+
30715 gdt_descr.address = __pa(get_cpu_gdt_table(0));
30716 gdt_descr.size = GDT_SIZE - 1;
30717 load_gdt(&gdt_descr);
30718@@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
30719 {
30720 struct desc_ptr gdt_descr;
30721
30722+#ifdef CONFIG_PAX_KERNEXEC
30723+ struct desc_struct d;
30724+
30725+ memset(&d, 0, sizeof d);
30726+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
30727+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
30728+#endif
30729+
30730 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
30731 gdt_descr.size = GDT_SIZE - 1;
30732 load_gdt(&gdt_descr);
30733diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
30734index fbe66e6..eae5e38 100644
30735--- a/arch/x86/platform/efi/efi_stub_32.S
30736+++ b/arch/x86/platform/efi/efi_stub_32.S
30737@@ -6,7 +6,9 @@
30738 */
30739
30740 #include <linux/linkage.h>
30741+#include <linux/init.h>
30742 #include <asm/page_types.h>
30743+#include <asm/segment.h>
30744
30745 /*
30746 * efi_call_phys(void *, ...) is a function with variable parameters.
30747@@ -20,7 +22,7 @@
30748 * service functions will comply with gcc calling convention, too.
30749 */
30750
30751-.text
30752+__INIT
30753 ENTRY(efi_call_phys)
30754 /*
30755 * 0. The function can only be called in Linux kernel. So CS has been
30756@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
30757 * The mapping of lower virtual memory has been created in prelog and
30758 * epilog.
30759 */
30760- movl $1f, %edx
30761- subl $__PAGE_OFFSET, %edx
30762- jmp *%edx
30763+#ifdef CONFIG_PAX_KERNEXEC
30764+ movl $(__KERNEXEC_EFI_DS), %edx
30765+ mov %edx, %ds
30766+ mov %edx, %es
30767+ mov %edx, %ss
30768+ addl $2f,(1f)
30769+ ljmp *(1f)
30770+
30771+__INITDATA
30772+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
30773+.previous
30774+
30775+2:
30776+ subl $2b,(1b)
30777+#else
30778+ jmp 1f-__PAGE_OFFSET
30779 1:
30780+#endif
30781
30782 /*
30783 * 2. Now on the top of stack is the return
30784@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
30785 * parameter 2, ..., param n. To make things easy, we save the return
30786 * address of efi_call_phys in a global variable.
30787 */
30788- popl %edx
30789- movl %edx, saved_return_addr
30790- /* get the function pointer into ECX*/
30791- popl %ecx
30792- movl %ecx, efi_rt_function_ptr
30793- movl $2f, %edx
30794- subl $__PAGE_OFFSET, %edx
30795- pushl %edx
30796+ popl (saved_return_addr)
30797+ popl (efi_rt_function_ptr)
30798
30799 /*
30800 * 3. Clear PG bit in %CR0.
30801@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
30802 /*
30803 * 5. Call the physical function.
30804 */
30805- jmp *%ecx
30806+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
30807
30808-2:
30809 /*
30810 * 6. After EFI runtime service returns, control will return to
30811 * following instruction. We'd better readjust stack pointer first.
30812@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
30813 movl %cr0, %edx
30814 orl $0x80000000, %edx
30815 movl %edx, %cr0
30816- jmp 1f
30817-1:
30818+
30819 /*
30820 * 8. Now restore the virtual mode from flat mode by
30821 * adding EIP with PAGE_OFFSET.
30822 */
30823- movl $1f, %edx
30824- jmp *%edx
30825+#ifdef CONFIG_PAX_KERNEXEC
30826+ movl $(__KERNEL_DS), %edx
30827+ mov %edx, %ds
30828+ mov %edx, %es
30829+ mov %edx, %ss
30830+ ljmp $(__KERNEL_CS),$1f
30831+#else
30832+ jmp 1f+__PAGE_OFFSET
30833+#endif
30834 1:
30835
30836 /*
30837 * 9. Balance the stack. And because EAX contain the return value,
30838 * we'd better not clobber it.
30839 */
30840- leal efi_rt_function_ptr, %edx
30841- movl (%edx), %ecx
30842- pushl %ecx
30843+ pushl (efi_rt_function_ptr)
30844
30845 /*
30846- * 10. Push the saved return address onto the stack and return.
30847+ * 10. Return to the saved return address.
30848 */
30849- leal saved_return_addr, %edx
30850- movl (%edx), %ecx
30851- pushl %ecx
30852- ret
30853+ jmpl *(saved_return_addr)
30854 ENDPROC(efi_call_phys)
30855 .previous
30856
30857-.data
30858+__INITDATA
30859 saved_return_addr:
30860 .long 0
30861 efi_rt_function_ptr:
30862diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
30863index 4c07cca..2c8427d 100644
30864--- a/arch/x86/platform/efi/efi_stub_64.S
30865+++ b/arch/x86/platform/efi/efi_stub_64.S
30866@@ -7,6 +7,7 @@
30867 */
30868
30869 #include <linux/linkage.h>
30870+#include <asm/alternative-asm.h>
30871
30872 #define SAVE_XMM \
30873 mov %rsp, %rax; \
30874@@ -40,6 +41,7 @@ ENTRY(efi_call0)
30875 call *%rdi
30876 addq $32, %rsp
30877 RESTORE_XMM
30878+ pax_force_retaddr 0, 1
30879 ret
30880 ENDPROC(efi_call0)
30881
30882@@ -50,6 +52,7 @@ ENTRY(efi_call1)
30883 call *%rdi
30884 addq $32, %rsp
30885 RESTORE_XMM
30886+ pax_force_retaddr 0, 1
30887 ret
30888 ENDPROC(efi_call1)
30889
30890@@ -60,6 +63,7 @@ ENTRY(efi_call2)
30891 call *%rdi
30892 addq $32, %rsp
30893 RESTORE_XMM
30894+ pax_force_retaddr 0, 1
30895 ret
30896 ENDPROC(efi_call2)
30897
30898@@ -71,6 +75,7 @@ ENTRY(efi_call3)
30899 call *%rdi
30900 addq $32, %rsp
30901 RESTORE_XMM
30902+ pax_force_retaddr 0, 1
30903 ret
30904 ENDPROC(efi_call3)
30905
30906@@ -83,6 +88,7 @@ ENTRY(efi_call4)
30907 call *%rdi
30908 addq $32, %rsp
30909 RESTORE_XMM
30910+ pax_force_retaddr 0, 1
30911 ret
30912 ENDPROC(efi_call4)
30913
30914@@ -96,6 +102,7 @@ ENTRY(efi_call5)
30915 call *%rdi
30916 addq $48, %rsp
30917 RESTORE_XMM
30918+ pax_force_retaddr 0, 1
30919 ret
30920 ENDPROC(efi_call5)
30921
30922@@ -112,5 +119,6 @@ ENTRY(efi_call6)
30923 call *%rdi
30924 addq $48, %rsp
30925 RESTORE_XMM
30926+ pax_force_retaddr 0, 1
30927 ret
30928 ENDPROC(efi_call6)
30929diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
30930index e31bcd8..f12dc46 100644
30931--- a/arch/x86/platform/mrst/mrst.c
30932+++ b/arch/x86/platform/mrst/mrst.c
30933@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
30934 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
30935 int sfi_mrtc_num;
30936
30937-static void mrst_power_off(void)
30938+static __noreturn void mrst_power_off(void)
30939 {
30940+ BUG();
30941 }
30942
30943-static void mrst_reboot(void)
30944+static __noreturn void mrst_reboot(void)
30945 {
30946 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
30947+ BUG();
30948 }
30949
30950 /* parse all the mtimer info to a static mtimer array */
30951diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
30952index d6ee929..3637cb5 100644
30953--- a/arch/x86/platform/olpc/olpc_dt.c
30954+++ b/arch/x86/platform/olpc/olpc_dt.c
30955@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
30956 return res;
30957 }
30958
30959-static struct of_pdt_ops prom_olpc_ops __initdata = {
30960+static struct of_pdt_ops prom_olpc_ops __initconst = {
30961 .nextprop = olpc_dt_nextprop,
30962 .getproplen = olpc_dt_getproplen,
30963 .getproperty = olpc_dt_getproperty,
30964diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
30965index 3c68768..07e82b8 100644
30966--- a/arch/x86/power/cpu.c
30967+++ b/arch/x86/power/cpu.c
30968@@ -134,7 +134,7 @@ static void do_fpu_end(void)
30969 static void fix_processor_context(void)
30970 {
30971 int cpu = smp_processor_id();
30972- struct tss_struct *t = &per_cpu(init_tss, cpu);
30973+ struct tss_struct *t = init_tss + cpu;
30974
30975 set_tss_desc(cpu, t); /*
30976 * This just modifies memory; should not be
30977@@ -144,8 +144,6 @@ static void fix_processor_context(void)
30978 */
30979
30980 #ifdef CONFIG_X86_64
30981- get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
30982-
30983 syscall_init(); /* This sets MSR_*STAR and related */
30984 #endif
30985 load_TR_desc(); /* This does ltr */
30986diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
30987index cbca565..bae7133 100644
30988--- a/arch/x86/realmode/init.c
30989+++ b/arch/x86/realmode/init.c
30990@@ -62,7 +62,13 @@ void __init setup_real_mode(void)
30991 __va(real_mode_header->trampoline_header);
30992
30993 #ifdef CONFIG_X86_32
30994- trampoline_header->start = __pa(startup_32_smp);
30995+ trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
30996+
30997+#ifdef CONFIG_PAX_KERNEXEC
30998+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
30999+#endif
31000+
31001+ trampoline_header->boot_cs = __BOOT_CS;
31002 trampoline_header->gdt_limit = __BOOT_DS + 7;
31003 trampoline_header->gdt_base = __pa(boot_gdt);
31004 #else
31005diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
31006index 8869287..d577672 100644
31007--- a/arch/x86/realmode/rm/Makefile
31008+++ b/arch/x86/realmode/rm/Makefile
31009@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
31010 $(call cc-option, -fno-unit-at-a-time)) \
31011 $(call cc-option, -fno-stack-protector) \
31012 $(call cc-option, -mpreferred-stack-boundary=2)
31013+ifdef CONSTIFY_PLUGIN
31014+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
31015+endif
31016 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
31017 GCOV_PROFILE := n
31018diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
31019index a28221d..93c40f1 100644
31020--- a/arch/x86/realmode/rm/header.S
31021+++ b/arch/x86/realmode/rm/header.S
31022@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
31023 #endif
31024 /* APM/BIOS reboot */
31025 .long pa_machine_real_restart_asm
31026-#ifdef CONFIG_X86_64
31027+#ifdef CONFIG_X86_32
31028+ .long __KERNEL_CS
31029+#else
31030 .long __KERNEL32_CS
31031 #endif
31032 END(real_mode_header)
31033diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
31034index c1b2791..f9e31c7 100644
31035--- a/arch/x86/realmode/rm/trampoline_32.S
31036+++ b/arch/x86/realmode/rm/trampoline_32.S
31037@@ -25,6 +25,12 @@
31038 #include <asm/page_types.h>
31039 #include "realmode.h"
31040
31041+#ifdef CONFIG_PAX_KERNEXEC
31042+#define ta(X) (X)
31043+#else
31044+#define ta(X) (pa_ ## X)
31045+#endif
31046+
31047 .text
31048 .code16
31049
31050@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
31051
31052 cli # We should be safe anyway
31053
31054- movl tr_start, %eax # where we need to go
31055-
31056 movl $0xA5A5A5A5, trampoline_status
31057 # write marker for master knows we're running
31058
31059@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
31060 movw $1, %dx # protected mode (PE) bit
31061 lmsw %dx # into protected mode
31062
31063- ljmpl $__BOOT_CS, $pa_startup_32
31064+ ljmpl *(trampoline_header)
31065
31066 .section ".text32","ax"
31067 .code32
31068@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
31069 .balign 8
31070 GLOBAL(trampoline_header)
31071 tr_start: .space 4
31072- tr_gdt_pad: .space 2
31073+ tr_boot_cs: .space 2
31074 tr_gdt: .space 6
31075 END(trampoline_header)
31076
31077diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
31078index bb360dc..3e5945f 100644
31079--- a/arch/x86/realmode/rm/trampoline_64.S
31080+++ b/arch/x86/realmode/rm/trampoline_64.S
31081@@ -107,7 +107,7 @@ ENTRY(startup_32)
31082 wrmsr
31083
31084 # Enable paging and in turn activate Long Mode
31085- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
31086+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
31087 movl %eax, %cr0
31088
31089 /*
31090diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
31091index 79d67bd..c7e1b90 100644
31092--- a/arch/x86/tools/relocs.c
31093+++ b/arch/x86/tools/relocs.c
31094@@ -12,10 +12,13 @@
31095 #include <regex.h>
31096 #include <tools/le_byteshift.h>
31097
31098+#include "../../../include/generated/autoconf.h"
31099+
31100 static void die(char *fmt, ...);
31101
31102 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
31103 static Elf32_Ehdr ehdr;
31104+static Elf32_Phdr *phdr;
31105 static unsigned long reloc_count, reloc_idx;
31106 static unsigned long *relocs;
31107 static unsigned long reloc16_count, reloc16_idx;
31108@@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
31109 }
31110 }
31111
31112+static void read_phdrs(FILE *fp)
31113+{
31114+ unsigned int i;
31115+
31116+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
31117+ if (!phdr) {
31118+ die("Unable to allocate %d program headers\n",
31119+ ehdr.e_phnum);
31120+ }
31121+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
31122+ die("Seek to %d failed: %s\n",
31123+ ehdr.e_phoff, strerror(errno));
31124+ }
31125+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
31126+ die("Cannot read ELF program headers: %s\n",
31127+ strerror(errno));
31128+ }
31129+ for(i = 0; i < ehdr.e_phnum; i++) {
31130+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
31131+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
31132+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
31133+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
31134+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
31135+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
31136+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
31137+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
31138+ }
31139+
31140+}
31141+
31142 static void read_shdrs(FILE *fp)
31143 {
31144- int i;
31145+ unsigned int i;
31146 Elf32_Shdr shdr;
31147
31148 secs = calloc(ehdr.e_shnum, sizeof(struct section));
31149@@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
31150
31151 static void read_strtabs(FILE *fp)
31152 {
31153- int i;
31154+ unsigned int i;
31155 for (i = 0; i < ehdr.e_shnum; i++) {
31156 struct section *sec = &secs[i];
31157 if (sec->shdr.sh_type != SHT_STRTAB) {
31158@@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
31159
31160 static void read_symtabs(FILE *fp)
31161 {
31162- int i,j;
31163+ unsigned int i,j;
31164 for (i = 0; i < ehdr.e_shnum; i++) {
31165 struct section *sec = &secs[i];
31166 if (sec->shdr.sh_type != SHT_SYMTAB) {
31167@@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
31168 }
31169
31170
31171-static void read_relocs(FILE *fp)
31172+static void read_relocs(FILE *fp, int use_real_mode)
31173 {
31174- int i,j;
31175+ unsigned int i,j;
31176+ uint32_t base;
31177+
31178 for (i = 0; i < ehdr.e_shnum; i++) {
31179 struct section *sec = &secs[i];
31180 if (sec->shdr.sh_type != SHT_REL) {
31181@@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
31182 die("Cannot read symbol table: %s\n",
31183 strerror(errno));
31184 }
31185+ base = 0;
31186+
31187+#ifdef CONFIG_X86_32
31188+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
31189+ if (phdr[j].p_type != PT_LOAD )
31190+ continue;
31191+ 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)
31192+ continue;
31193+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
31194+ break;
31195+ }
31196+#endif
31197+
31198 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
31199 Elf32_Rel *rel = &sec->reltab[j];
31200- rel->r_offset = elf32_to_cpu(rel->r_offset);
31201+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
31202 rel->r_info = elf32_to_cpu(rel->r_info);
31203 }
31204 }
31205@@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
31206
31207 static void print_absolute_symbols(void)
31208 {
31209- int i;
31210+ unsigned int i;
31211 printf("Absolute symbols\n");
31212 printf(" Num: Value Size Type Bind Visibility Name\n");
31213 for (i = 0; i < ehdr.e_shnum; i++) {
31214 struct section *sec = &secs[i];
31215 char *sym_strtab;
31216- int j;
31217+ unsigned int j;
31218
31219 if (sec->shdr.sh_type != SHT_SYMTAB) {
31220 continue;
31221@@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
31222
31223 static void print_absolute_relocs(void)
31224 {
31225- int i, printed = 0;
31226+ unsigned int i, printed = 0;
31227
31228 for (i = 0; i < ehdr.e_shnum; i++) {
31229 struct section *sec = &secs[i];
31230 struct section *sec_applies, *sec_symtab;
31231 char *sym_strtab;
31232 Elf32_Sym *sh_symtab;
31233- int j;
31234+ unsigned int j;
31235 if (sec->shdr.sh_type != SHT_REL) {
31236 continue;
31237 }
31238@@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
31239 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
31240 int use_real_mode)
31241 {
31242- int i;
31243+ unsigned int i;
31244 /* Walk through the relocations */
31245 for (i = 0; i < ehdr.e_shnum; i++) {
31246 char *sym_strtab;
31247 Elf32_Sym *sh_symtab;
31248 struct section *sec_applies, *sec_symtab;
31249- int j;
31250+ unsigned int j;
31251 struct section *sec = &secs[i];
31252
31253 if (sec->shdr.sh_type != SHT_REL) {
31254@@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
31255 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
31256 r_type = ELF32_R_TYPE(rel->r_info);
31257
31258+ if (!use_real_mode) {
31259+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
31260+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
31261+ continue;
31262+
31263+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
31264+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
31265+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
31266+ continue;
31267+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
31268+ continue;
31269+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
31270+ continue;
31271+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
31272+ continue;
31273+#endif
31274+ }
31275+
31276 shn_abs = sym->st_shndx == SHN_ABS;
31277
31278 switch (r_type) {
31279@@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
31280
31281 static void emit_relocs(int as_text, int use_real_mode)
31282 {
31283- int i;
31284+ unsigned int i;
31285 /* Count how many relocations I have and allocate space for them. */
31286 reloc_count = 0;
31287 walk_relocs(count_reloc, use_real_mode);
31288@@ -808,10 +874,11 @@ int main(int argc, char **argv)
31289 fname, strerror(errno));
31290 }
31291 read_ehdr(fp);
31292+ read_phdrs(fp);
31293 read_shdrs(fp);
31294 read_strtabs(fp);
31295 read_symtabs(fp);
31296- read_relocs(fp);
31297+ read_relocs(fp, use_real_mode);
31298 if (show_absolute_syms) {
31299 print_absolute_symbols();
31300 goto out;
31301diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
31302index fd14be1..e3c79c0 100644
31303--- a/arch/x86/vdso/Makefile
31304+++ b/arch/x86/vdso/Makefile
31305@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
31306 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
31307 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
31308
31309-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
31310+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
31311 GCOV_PROFILE := n
31312
31313 #
31314diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
31315index 0faad64..39ef157 100644
31316--- a/arch/x86/vdso/vdso32-setup.c
31317+++ b/arch/x86/vdso/vdso32-setup.c
31318@@ -25,6 +25,7 @@
31319 #include <asm/tlbflush.h>
31320 #include <asm/vdso.h>
31321 #include <asm/proto.h>
31322+#include <asm/mman.h>
31323
31324 enum {
31325 VDSO_DISABLED = 0,
31326@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
31327 void enable_sep_cpu(void)
31328 {
31329 int cpu = get_cpu();
31330- struct tss_struct *tss = &per_cpu(init_tss, cpu);
31331+ struct tss_struct *tss = init_tss + cpu;
31332
31333 if (!boot_cpu_has(X86_FEATURE_SEP)) {
31334 put_cpu();
31335@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
31336 gate_vma.vm_start = FIXADDR_USER_START;
31337 gate_vma.vm_end = FIXADDR_USER_END;
31338 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
31339- gate_vma.vm_page_prot = __P101;
31340+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
31341
31342 return 0;
31343 }
31344@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
31345 if (compat)
31346 addr = VDSO_HIGH_BASE;
31347 else {
31348- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
31349+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
31350 if (IS_ERR_VALUE(addr)) {
31351 ret = addr;
31352 goto up_fail;
31353 }
31354 }
31355
31356- current->mm->context.vdso = (void *)addr;
31357+ current->mm->context.vdso = addr;
31358
31359 if (compat_uses_vma || !compat) {
31360 /*
31361@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
31362 }
31363
31364 current_thread_info()->sysenter_return =
31365- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
31366+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
31367
31368 up_fail:
31369 if (ret)
31370- current->mm->context.vdso = NULL;
31371+ current->mm->context.vdso = 0;
31372
31373 up_write(&mm->mmap_sem);
31374
31375@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
31376
31377 const char *arch_vma_name(struct vm_area_struct *vma)
31378 {
31379- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
31380+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
31381 return "[vdso]";
31382+
31383+#ifdef CONFIG_PAX_SEGMEXEC
31384+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
31385+ return "[vdso]";
31386+#endif
31387+
31388 return NULL;
31389 }
31390
31391@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
31392 * Check to see if the corresponding task was created in compat vdso
31393 * mode.
31394 */
31395- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
31396+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
31397 return &gate_vma;
31398 return NULL;
31399 }
31400diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
31401index 431e875..cbb23f3 100644
31402--- a/arch/x86/vdso/vma.c
31403+++ b/arch/x86/vdso/vma.c
31404@@ -16,8 +16,6 @@
31405 #include <asm/vdso.h>
31406 #include <asm/page.h>
31407
31408-unsigned int __read_mostly vdso_enabled = 1;
31409-
31410 extern char vdso_start[], vdso_end[];
31411 extern unsigned short vdso_sync_cpuid;
31412
31413@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
31414 * unaligned here as a result of stack start randomization.
31415 */
31416 addr = PAGE_ALIGN(addr);
31417- addr = align_vdso_addr(addr);
31418
31419 return addr;
31420 }
31421@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
31422 unsigned size)
31423 {
31424 struct mm_struct *mm = current->mm;
31425- unsigned long addr;
31426+ unsigned long addr = 0;
31427 int ret;
31428
31429- if (!vdso_enabled)
31430- return 0;
31431-
31432 down_write(&mm->mmap_sem);
31433+
31434+#ifdef CONFIG_PAX_RANDMMAP
31435+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
31436+#endif
31437+
31438 addr = vdso_addr(mm->start_stack, size);
31439+ addr = align_vdso_addr(addr);
31440 addr = get_unmapped_area(NULL, addr, size, 0, 0);
31441 if (IS_ERR_VALUE(addr)) {
31442 ret = addr;
31443 goto up_fail;
31444 }
31445
31446- current->mm->context.vdso = (void *)addr;
31447+ mm->context.vdso = addr;
31448
31449 ret = install_special_mapping(mm, addr, size,
31450 VM_READ|VM_EXEC|
31451 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
31452 pages);
31453- if (ret) {
31454- current->mm->context.vdso = NULL;
31455- goto up_fail;
31456- }
31457+ if (ret)
31458+ mm->context.vdso = 0;
31459
31460 up_fail:
31461 up_write(&mm->mmap_sem);
31462@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
31463 vdsox32_size);
31464 }
31465 #endif
31466-
31467-static __init int vdso_setup(char *s)
31468-{
31469- vdso_enabled = simple_strtoul(s, NULL, 0);
31470- return 0;
31471-}
31472-__setup("vdso=", vdso_setup);
31473diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
31474index 2262003..3ee61cf 100644
31475--- a/arch/x86/xen/enlighten.c
31476+++ b/arch/x86/xen/enlighten.c
31477@@ -100,8 +100,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
31478
31479 struct shared_info xen_dummy_shared_info;
31480
31481-void *xen_initial_gdt;
31482-
31483 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
31484 __read_mostly int xen_have_vector_callback;
31485 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
31486@@ -496,8 +494,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
31487 {
31488 unsigned long va = dtr->address;
31489 unsigned int size = dtr->size + 1;
31490- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
31491- unsigned long frames[pages];
31492+ unsigned long frames[65536 / PAGE_SIZE];
31493 int f;
31494
31495 /*
31496@@ -545,8 +542,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
31497 {
31498 unsigned long va = dtr->address;
31499 unsigned int size = dtr->size + 1;
31500- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
31501- unsigned long frames[pages];
31502+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
31503 int f;
31504
31505 /*
31506@@ -554,7 +550,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
31507 * 8-byte entries, or 16 4k pages..
31508 */
31509
31510- BUG_ON(size > 65536);
31511+ BUG_ON(size > GDT_SIZE);
31512 BUG_ON(va & ~PAGE_MASK);
31513
31514 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
31515@@ -939,7 +935,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
31516 return 0;
31517 }
31518
31519-static void set_xen_basic_apic_ops(void)
31520+static void __init set_xen_basic_apic_ops(void)
31521 {
31522 apic->read = xen_apic_read;
31523 apic->write = xen_apic_write;
31524@@ -1245,30 +1241,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
31525 #endif
31526 };
31527
31528-static void xen_reboot(int reason)
31529+static __noreturn void xen_reboot(int reason)
31530 {
31531 struct sched_shutdown r = { .reason = reason };
31532
31533- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
31534- BUG();
31535+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
31536+ BUG();
31537 }
31538
31539-static void xen_restart(char *msg)
31540+static __noreturn void xen_restart(char *msg)
31541 {
31542 xen_reboot(SHUTDOWN_reboot);
31543 }
31544
31545-static void xen_emergency_restart(void)
31546+static __noreturn void xen_emergency_restart(void)
31547 {
31548 xen_reboot(SHUTDOWN_reboot);
31549 }
31550
31551-static void xen_machine_halt(void)
31552+static __noreturn void xen_machine_halt(void)
31553 {
31554 xen_reboot(SHUTDOWN_poweroff);
31555 }
31556
31557-static void xen_machine_power_off(void)
31558+static __noreturn void xen_machine_power_off(void)
31559 {
31560 if (pm_power_off)
31561 pm_power_off();
31562@@ -1370,7 +1366,17 @@ asmlinkage void __init xen_start_kernel(void)
31563 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
31564
31565 /* Work out if we support NX */
31566- x86_configure_nx();
31567+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
31568+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
31569+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
31570+ unsigned l, h;
31571+
31572+ __supported_pte_mask |= _PAGE_NX;
31573+ rdmsr(MSR_EFER, l, h);
31574+ l |= EFER_NX;
31575+ wrmsr(MSR_EFER, l, h);
31576+ }
31577+#endif
31578
31579 xen_setup_features();
31580
31581@@ -1401,13 +1407,6 @@ asmlinkage void __init xen_start_kernel(void)
31582
31583 machine_ops = xen_machine_ops;
31584
31585- /*
31586- * The only reliable way to retain the initial address of the
31587- * percpu gdt_page is to remember it here, so we can go and
31588- * mark it RW later, when the initial percpu area is freed.
31589- */
31590- xen_initial_gdt = &per_cpu(gdt_page, 0);
31591-
31592 xen_smp_init();
31593
31594 #ifdef CONFIG_ACPI_NUMA
31595@@ -1598,7 +1597,7 @@ static int __cpuinit xen_hvm_cpu_notify(struct notifier_block *self,
31596 return NOTIFY_OK;
31597 }
31598
31599-static struct notifier_block xen_hvm_cpu_notifier __cpuinitdata = {
31600+static struct notifier_block xen_hvm_cpu_notifier = {
31601 .notifier_call = xen_hvm_cpu_notify,
31602 };
31603
31604diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
31605index cab96b6..8c629ba 100644
31606--- a/arch/x86/xen/mmu.c
31607+++ b/arch/x86/xen/mmu.c
31608@@ -1739,14 +1739,18 @@ static void *m2v(phys_addr_t maddr)
31609 }
31610
31611 /* Set the page permissions on an identity-mapped pages */
31612-static void set_page_prot(void *addr, pgprot_t prot)
31613+static void set_page_prot_flags(void *addr, pgprot_t prot, unsigned long flags)
31614 {
31615 unsigned long pfn = __pa(addr) >> PAGE_SHIFT;
31616 pte_t pte = pfn_pte(pfn, prot);
31617
31618- if (HYPERVISOR_update_va_mapping((unsigned long)addr, pte, 0))
31619+ if (HYPERVISOR_update_va_mapping((unsigned long)addr, pte, flags))
31620 BUG();
31621 }
31622+static void set_page_prot(void *addr, pgprot_t prot)
31623+{
31624+ return set_page_prot_flags(addr, prot, UVMF_NONE);
31625+}
31626 #ifdef CONFIG_X86_32
31627 static void __init xen_map_identity_early(pmd_t *pmd, unsigned long max_pfn)
31628 {
31629@@ -1830,12 +1834,12 @@ static void __init check_pt_base(unsigned long *pt_base, unsigned long *pt_end,
31630 unsigned long addr)
31631 {
31632 if (*pt_base == PFN_DOWN(__pa(addr))) {
31633- set_page_prot((void *)addr, PAGE_KERNEL);
31634+ set_page_prot_flags((void *)addr, PAGE_KERNEL, UVMF_INVLPG);
31635 clear_page((void *)addr);
31636 (*pt_base)++;
31637 }
31638 if (*pt_end == PFN_DOWN(__pa(addr))) {
31639- set_page_prot((void *)addr, PAGE_KERNEL);
31640+ set_page_prot_flags((void *)addr, PAGE_KERNEL, UVMF_INVLPG);
31641 clear_page((void *)addr);
31642 (*pt_end)--;
31643 }
31644@@ -1881,6 +1885,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
31645 /* L3_k[510] -> level2_kernel_pgt
31646 * L3_i[511] -> level2_fixmap_pgt */
31647 convert_pfn_mfn(level3_kernel_pgt);
31648+ convert_pfn_mfn(level3_vmalloc_start_pgt);
31649+ convert_pfn_mfn(level3_vmalloc_end_pgt);
31650+ convert_pfn_mfn(level3_vmemmap_pgt);
31651
31652 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
31653 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
31654@@ -1910,8 +1917,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
31655 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
31656 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
31657 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
31658+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
31659+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
31660+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
31661 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
31662 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
31663+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
31664 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
31665 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
31666
31667@@ -2097,6 +2108,7 @@ static void __init xen_post_allocator_init(void)
31668 pv_mmu_ops.set_pud = xen_set_pud;
31669 #if PAGETABLE_LEVELS == 4
31670 pv_mmu_ops.set_pgd = xen_set_pgd;
31671+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
31672 #endif
31673
31674 /* This will work as long as patching hasn't happened yet
31675@@ -2178,6 +2190,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
31676 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
31677 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
31678 .set_pgd = xen_set_pgd_hyper,
31679+ .set_pgd_batched = xen_set_pgd_hyper,
31680
31681 .alloc_pud = xen_alloc_pmd_init,
31682 .release_pud = xen_release_pmd_init,
31683diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
31684index 34bc4ce..c34aa24 100644
31685--- a/arch/x86/xen/smp.c
31686+++ b/arch/x86/xen/smp.c
31687@@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
31688 {
31689 BUG_ON(smp_processor_id() != 0);
31690 native_smp_prepare_boot_cpu();
31691-
31692- /* We've switched to the "real" per-cpu gdt, so make sure the
31693- old memory can be recycled */
31694- make_lowmem_page_readwrite(xen_initial_gdt);
31695-
31696 xen_filter_cpu_maps();
31697 xen_setup_vcpu_info_placement();
31698 }
31699@@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
31700 gdt = get_cpu_gdt_table(cpu);
31701
31702 ctxt->flags = VGCF_IN_KERNEL;
31703- ctxt->user_regs.ds = __USER_DS;
31704- ctxt->user_regs.es = __USER_DS;
31705+ ctxt->user_regs.ds = __KERNEL_DS;
31706+ ctxt->user_regs.es = __KERNEL_DS;
31707 ctxt->user_regs.ss = __KERNEL_DS;
31708 #ifdef CONFIG_X86_32
31709 ctxt->user_regs.fs = __KERNEL_PERCPU;
31710- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
31711+ savesegment(gs, ctxt->user_regs.gs);
31712 #else
31713 ctxt->gs_base_kernel = per_cpu_offset(cpu);
31714 #endif
31715@@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
31716 int rc;
31717
31718 per_cpu(current_task, cpu) = idle;
31719+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
31720 #ifdef CONFIG_X86_32
31721 irq_ctx_init(cpu);
31722 #else
31723 clear_tsk_thread_flag(idle, TIF_FORK);
31724- per_cpu(kernel_stack, cpu) =
31725- (unsigned long)task_stack_page(idle) -
31726- KERNEL_STACK_OFFSET + THREAD_SIZE;
31727+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
31728 #endif
31729 xen_setup_runstate_info(cpu);
31730 xen_setup_timer(cpu);
31731@@ -630,7 +624,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
31732
31733 void __init xen_smp_init(void)
31734 {
31735- smp_ops = xen_smp_ops;
31736+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
31737 xen_fill_possible_map();
31738 xen_init_spinlocks();
31739 }
31740diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
31741index 33ca6e4..0ded929 100644
31742--- a/arch/x86/xen/xen-asm_32.S
31743+++ b/arch/x86/xen/xen-asm_32.S
31744@@ -84,14 +84,14 @@ ENTRY(xen_iret)
31745 ESP_OFFSET=4 # bytes pushed onto stack
31746
31747 /*
31748- * Store vcpu_info pointer for easy access. Do it this way to
31749- * avoid having to reload %fs
31750+ * Store vcpu_info pointer for easy access.
31751 */
31752 #ifdef CONFIG_SMP
31753- GET_THREAD_INFO(%eax)
31754- movl %ss:TI_cpu(%eax), %eax
31755- movl %ss:__per_cpu_offset(,%eax,4), %eax
31756- mov %ss:xen_vcpu(%eax), %eax
31757+ push %fs
31758+ mov $(__KERNEL_PERCPU), %eax
31759+ mov %eax, %fs
31760+ mov PER_CPU_VAR(xen_vcpu), %eax
31761+ pop %fs
31762 #else
31763 movl %ss:xen_vcpu, %eax
31764 #endif
31765diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
31766index 7faed58..ba4427c 100644
31767--- a/arch/x86/xen/xen-head.S
31768+++ b/arch/x86/xen/xen-head.S
31769@@ -19,6 +19,17 @@ ENTRY(startup_xen)
31770 #ifdef CONFIG_X86_32
31771 mov %esi,xen_start_info
31772 mov $init_thread_union+THREAD_SIZE,%esp
31773+#ifdef CONFIG_SMP
31774+ movl $cpu_gdt_table,%edi
31775+ movl $__per_cpu_load,%eax
31776+ movw %ax,__KERNEL_PERCPU + 2(%edi)
31777+ rorl $16,%eax
31778+ movb %al,__KERNEL_PERCPU + 4(%edi)
31779+ movb %ah,__KERNEL_PERCPU + 7(%edi)
31780+ movl $__per_cpu_end - 1,%eax
31781+ subl $__per_cpu_start,%eax
31782+ movw %ax,__KERNEL_PERCPU + 0(%edi)
31783+#endif
31784 #else
31785 mov %rsi,xen_start_info
31786 mov $init_thread_union+THREAD_SIZE,%rsp
31787diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
31788index a95b417..b6dbd0b 100644
31789--- a/arch/x86/xen/xen-ops.h
31790+++ b/arch/x86/xen/xen-ops.h
31791@@ -10,8 +10,6 @@
31792 extern const char xen_hypervisor_callback[];
31793 extern const char xen_failsafe_callback[];
31794
31795-extern void *xen_initial_gdt;
31796-
31797 struct trap_info;
31798 void xen_copy_trap_info(struct trap_info *traps);
31799
31800diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
31801index 525bd3d..ef888b1 100644
31802--- a/arch/xtensa/variants/dc232b/include/variant/core.h
31803+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
31804@@ -119,9 +119,9 @@
31805 ----------------------------------------------------------------------*/
31806
31807 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
31808-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
31809 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
31810 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
31811+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31812
31813 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
31814 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
31815diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
31816index 2f33760..835e50a 100644
31817--- a/arch/xtensa/variants/fsf/include/variant/core.h
31818+++ b/arch/xtensa/variants/fsf/include/variant/core.h
31819@@ -11,6 +11,7 @@
31820 #ifndef _XTENSA_CORE_H
31821 #define _XTENSA_CORE_H
31822
31823+#include <linux/const.h>
31824
31825 /****************************************************************************
31826 Parameters Useful for Any Code, USER or PRIVILEGED
31827@@ -112,9 +113,9 @@
31828 ----------------------------------------------------------------------*/
31829
31830 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
31831-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
31832 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
31833 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
31834+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31835
31836 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
31837 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
31838diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
31839index af00795..2bb8105 100644
31840--- a/arch/xtensa/variants/s6000/include/variant/core.h
31841+++ b/arch/xtensa/variants/s6000/include/variant/core.h
31842@@ -11,6 +11,7 @@
31843 #ifndef _XTENSA_CORE_CONFIGURATION_H
31844 #define _XTENSA_CORE_CONFIGURATION_H
31845
31846+#include <linux/const.h>
31847
31848 /****************************************************************************
31849 Parameters Useful for Any Code, USER or PRIVILEGED
31850@@ -118,9 +119,9 @@
31851 ----------------------------------------------------------------------*/
31852
31853 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
31854-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
31855 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
31856 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
31857+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31858
31859 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
31860 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
31861diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
31862index 58916af..eb9dbcf6 100644
31863--- a/block/blk-iopoll.c
31864+++ b/block/blk-iopoll.c
31865@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
31866 }
31867 EXPORT_SYMBOL(blk_iopoll_complete);
31868
31869-static void blk_iopoll_softirq(struct softirq_action *h)
31870+static void blk_iopoll_softirq(void)
31871 {
31872 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
31873 int rearm = 0, budget = blk_iopoll_budget;
31874@@ -209,7 +209,7 @@ static int __cpuinit blk_iopoll_cpu_notify(struct notifier_block *self,
31875 return NOTIFY_OK;
31876 }
31877
31878-static struct notifier_block __cpuinitdata blk_iopoll_cpu_notifier = {
31879+static struct notifier_block blk_iopoll_cpu_notifier = {
31880 .notifier_call = blk_iopoll_cpu_notify,
31881 };
31882
31883diff --git a/block/blk-map.c b/block/blk-map.c
31884index 623e1cd..ca1e109 100644
31885--- a/block/blk-map.c
31886+++ b/block/blk-map.c
31887@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
31888 if (!len || !kbuf)
31889 return -EINVAL;
31890
31891- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
31892+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
31893 if (do_copy)
31894 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
31895 else
31896diff --git a/block/blk-softirq.c b/block/blk-softirq.c
31897index 467c8de..f3628c5 100644
31898--- a/block/blk-softirq.c
31899+++ b/block/blk-softirq.c
31900@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
31901 * Softirq action handler - move entries to local list and loop over them
31902 * while passing them to the queue registered handler.
31903 */
31904-static void blk_done_softirq(struct softirq_action *h)
31905+static void blk_done_softirq(void)
31906 {
31907 struct list_head *cpu_list, local_list;
31908
31909@@ -98,7 +98,7 @@ static int __cpuinit blk_cpu_notify(struct notifier_block *self,
31910 return NOTIFY_OK;
31911 }
31912
31913-static struct notifier_block __cpuinitdata blk_cpu_notifier = {
31914+static struct notifier_block blk_cpu_notifier = {
31915 .notifier_call = blk_cpu_notify,
31916 };
31917
31918diff --git a/block/bsg.c b/block/bsg.c
31919index ff64ae3..593560c 100644
31920--- a/block/bsg.c
31921+++ b/block/bsg.c
31922@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
31923 struct sg_io_v4 *hdr, struct bsg_device *bd,
31924 fmode_t has_write_perm)
31925 {
31926+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31927+ unsigned char *cmdptr;
31928+
31929 if (hdr->request_len > BLK_MAX_CDB) {
31930 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
31931 if (!rq->cmd)
31932 return -ENOMEM;
31933- }
31934+ cmdptr = rq->cmd;
31935+ } else
31936+ cmdptr = tmpcmd;
31937
31938- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
31939+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
31940 hdr->request_len))
31941 return -EFAULT;
31942
31943+ if (cmdptr != rq->cmd)
31944+ memcpy(rq->cmd, cmdptr, hdr->request_len);
31945+
31946 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
31947 if (blk_verify_command(rq->cmd, has_write_perm))
31948 return -EPERM;
31949diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
31950index 7c668c8..db3521c 100644
31951--- a/block/compat_ioctl.c
31952+++ b/block/compat_ioctl.c
31953@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
31954 err |= __get_user(f->spec1, &uf->spec1);
31955 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
31956 err |= __get_user(name, &uf->name);
31957- f->name = compat_ptr(name);
31958+ f->name = (void __force_kernel *)compat_ptr(name);
31959 if (err) {
31960 err = -EFAULT;
31961 goto out;
31962diff --git a/block/partitions/efi.c b/block/partitions/efi.c
31963index b62fb88..bdab4c4 100644
31964--- a/block/partitions/efi.c
31965+++ b/block/partitions/efi.c
31966@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
31967 if (!gpt)
31968 return NULL;
31969
31970+ if (!le32_to_cpu(gpt->num_partition_entries))
31971+ return NULL;
31972+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
31973+ if (!pte)
31974+ return NULL;
31975+
31976 count = le32_to_cpu(gpt->num_partition_entries) *
31977 le32_to_cpu(gpt->sizeof_partition_entry);
31978- if (!count)
31979- return NULL;
31980- pte = kzalloc(count, GFP_KERNEL);
31981- if (!pte)
31982- return NULL;
31983-
31984 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
31985 (u8 *) pte,
31986 count) < count) {
31987diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
31988index 9a87daa..fb17486 100644
31989--- a/block/scsi_ioctl.c
31990+++ b/block/scsi_ioctl.c
31991@@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
31992 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
31993 struct sg_io_hdr *hdr, fmode_t mode)
31994 {
31995- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
31996+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31997+ unsigned char *cmdptr;
31998+
31999+ if (rq->cmd != rq->__cmd)
32000+ cmdptr = rq->cmd;
32001+ else
32002+ cmdptr = tmpcmd;
32003+
32004+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
32005 return -EFAULT;
32006+
32007+ if (cmdptr != rq->cmd)
32008+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
32009+
32010 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
32011 return -EPERM;
32012
32013@@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
32014 int err;
32015 unsigned int in_len, out_len, bytes, opcode, cmdlen;
32016 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
32017+ unsigned char tmpcmd[sizeof(rq->__cmd)];
32018+ unsigned char *cmdptr;
32019
32020 if (!sic)
32021 return -EINVAL;
32022@@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
32023 */
32024 err = -EFAULT;
32025 rq->cmd_len = cmdlen;
32026- if (copy_from_user(rq->cmd, sic->data, cmdlen))
32027+
32028+ if (rq->cmd != rq->__cmd)
32029+ cmdptr = rq->cmd;
32030+ else
32031+ cmdptr = tmpcmd;
32032+
32033+ if (copy_from_user(cmdptr, sic->data, cmdlen))
32034 goto error;
32035
32036+ if (rq->cmd != cmdptr)
32037+ memcpy(rq->cmd, cmdptr, cmdlen);
32038+
32039 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
32040 goto error;
32041
32042diff --git a/crypto/cryptd.c b/crypto/cryptd.c
32043index 7bdd61b..afec999 100644
32044--- a/crypto/cryptd.c
32045+++ b/crypto/cryptd.c
32046@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
32047
32048 struct cryptd_blkcipher_request_ctx {
32049 crypto_completion_t complete;
32050-};
32051+} __no_const;
32052
32053 struct cryptd_hash_ctx {
32054 struct crypto_shash *child;
32055@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
32056
32057 struct cryptd_aead_request_ctx {
32058 crypto_completion_t complete;
32059-};
32060+} __no_const;
32061
32062 static void cryptd_queue_worker(struct work_struct *work);
32063
32064diff --git a/crypto/crypto_user.c b/crypto/crypto_user.c
32065index f6d9baf..dfd511f 100644
32066--- a/crypto/crypto_user.c
32067+++ b/crypto/crypto_user.c
32068@@ -30,6 +30,8 @@
32069
32070 #include "internal.h"
32071
32072+#define null_terminated(x) (strnlen(x, sizeof(x)) < sizeof(x))
32073+
32074 static DEFINE_MUTEX(crypto_cfg_mutex);
32075
32076 /* The crypto netlink socket */
32077@@ -196,7 +198,10 @@ static int crypto_report(struct sk_buff *in_skb, struct nlmsghdr *in_nlh,
32078 struct crypto_dump_info info;
32079 int err;
32080
32081- if (!p->cru_driver_name)
32082+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
32083+ return -EINVAL;
32084+
32085+ if (!p->cru_driver_name[0])
32086 return -EINVAL;
32087
32088 alg = crypto_alg_match(p, 1);
32089@@ -260,6 +265,9 @@ static int crypto_update_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
32090 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
32091 LIST_HEAD(list);
32092
32093+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
32094+ return -EINVAL;
32095+
32096 if (priority && !strlen(p->cru_driver_name))
32097 return -EINVAL;
32098
32099@@ -287,6 +295,9 @@ static int crypto_del_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
32100 struct crypto_alg *alg;
32101 struct crypto_user_alg *p = nlmsg_data(nlh);
32102
32103+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
32104+ return -EINVAL;
32105+
32106 alg = crypto_alg_match(p, 1);
32107 if (!alg)
32108 return -ENOENT;
32109@@ -368,6 +379,9 @@ static int crypto_add_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
32110 struct crypto_user_alg *p = nlmsg_data(nlh);
32111 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
32112
32113+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
32114+ return -EINVAL;
32115+
32116 if (strlen(p->cru_driver_name))
32117 exact = 1;
32118
32119diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
32120index f220d64..d359ad6 100644
32121--- a/drivers/acpi/apei/apei-internal.h
32122+++ b/drivers/acpi/apei/apei-internal.h
32123@@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
32124 struct apei_exec_ins_type {
32125 u32 flags;
32126 apei_exec_ins_func_t run;
32127-};
32128+} __do_const;
32129
32130 struct apei_exec_context {
32131 u32 ip;
32132diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
32133index e6defd8..c26a225 100644
32134--- a/drivers/acpi/apei/cper.c
32135+++ b/drivers/acpi/apei/cper.c
32136@@ -38,12 +38,12 @@
32137 */
32138 u64 cper_next_record_id(void)
32139 {
32140- static atomic64_t seq;
32141+ static atomic64_unchecked_t seq;
32142
32143- if (!atomic64_read(&seq))
32144- atomic64_set(&seq, ((u64)get_seconds()) << 32);
32145+ if (!atomic64_read_unchecked(&seq))
32146+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
32147
32148- return atomic64_inc_return(&seq);
32149+ return atomic64_inc_return_unchecked(&seq);
32150 }
32151 EXPORT_SYMBOL_GPL(cper_next_record_id);
32152
32153diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
32154index be60399..778b33e8 100644
32155--- a/drivers/acpi/bgrt.c
32156+++ b/drivers/acpi/bgrt.c
32157@@ -87,8 +87,10 @@ static int __init bgrt_init(void)
32158 return -ENODEV;
32159
32160 sysfs_bin_attr_init(&image_attr);
32161- image_attr.private = bgrt_image;
32162- image_attr.size = bgrt_image_size;
32163+ pax_open_kernel();
32164+ *(void **)&image_attr.private = bgrt_image;
32165+ *(size_t *)&image_attr.size = bgrt_image_size;
32166+ pax_close_kernel();
32167
32168 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
32169 if (!bgrt_kobj)
32170diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
32171index cb96296..b81293b 100644
32172--- a/drivers/acpi/blacklist.c
32173+++ b/drivers/acpi/blacklist.c
32174@@ -52,7 +52,7 @@ struct acpi_blacklist_item {
32175 u32 is_critical_error;
32176 };
32177
32178-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
32179+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
32180
32181 /*
32182 * POLICY: If *anything* doesn't work, put it on the blacklist.
32183@@ -193,7 +193,7 @@ static int __init dmi_disable_osi_win7(const struct dmi_system_id *d)
32184 return 0;
32185 }
32186
32187-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
32188+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
32189 {
32190 .callback = dmi_disable_osi_vista,
32191 .ident = "Fujitsu Siemens",
32192diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
32193index 7586544..636a2f0 100644
32194--- a/drivers/acpi/ec_sys.c
32195+++ b/drivers/acpi/ec_sys.c
32196@@ -12,6 +12,7 @@
32197 #include <linux/acpi.h>
32198 #include <linux/debugfs.h>
32199 #include <linux/module.h>
32200+#include <linux/uaccess.h>
32201 #include "internal.h"
32202
32203 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
32204@@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
32205 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
32206 */
32207 unsigned int size = EC_SPACE_SIZE;
32208- u8 *data = (u8 *) buf;
32209+ u8 data;
32210 loff_t init_off = *off;
32211 int err = 0;
32212
32213@@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
32214 size = count;
32215
32216 while (size) {
32217- err = ec_read(*off, &data[*off - init_off]);
32218+ err = ec_read(*off, &data);
32219 if (err)
32220 return err;
32221+ if (put_user(data, &buf[*off - init_off]))
32222+ return -EFAULT;
32223 *off += 1;
32224 size--;
32225 }
32226@@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
32227
32228 unsigned int size = count;
32229 loff_t init_off = *off;
32230- u8 *data = (u8 *) buf;
32231 int err = 0;
32232
32233 if (*off >= EC_SPACE_SIZE)
32234@@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
32235 }
32236
32237 while (size) {
32238- u8 byte_write = data[*off - init_off];
32239+ u8 byte_write;
32240+ if (get_user(byte_write, &buf[*off - init_off]))
32241+ return -EFAULT;
32242 err = ec_write(*off, byte_write);
32243 if (err)
32244 return err;
32245diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
32246index e83311b..142b5cc 100644
32247--- a/drivers/acpi/processor_driver.c
32248+++ b/drivers/acpi/processor_driver.c
32249@@ -558,7 +558,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
32250 return 0;
32251 #endif
32252
32253- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
32254+ BUG_ON(pr->id >= nr_cpu_ids);
32255
32256 /*
32257 * Buggy BIOS check
32258diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
32259index ed9a1cc..f4a354c 100644
32260--- a/drivers/acpi/processor_idle.c
32261+++ b/drivers/acpi/processor_idle.c
32262@@ -1005,7 +1005,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
32263 {
32264 int i, count = CPUIDLE_DRIVER_STATE_START;
32265 struct acpi_processor_cx *cx;
32266- struct cpuidle_state *state;
32267+ cpuidle_state_no_const *state;
32268 struct cpuidle_driver *drv = &acpi_idle_driver;
32269
32270 if (!pr->flags.power_setup_done)
32271diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
32272index ea61ca9..3fdd70d 100644
32273--- a/drivers/acpi/sysfs.c
32274+++ b/drivers/acpi/sysfs.c
32275@@ -420,11 +420,11 @@ static u32 num_counters;
32276 static struct attribute **all_attrs;
32277 static u32 acpi_gpe_count;
32278
32279-static struct attribute_group interrupt_stats_attr_group = {
32280+static attribute_group_no_const interrupt_stats_attr_group = {
32281 .name = "interrupts",
32282 };
32283
32284-static struct kobj_attribute *counter_attrs;
32285+static kobj_attribute_no_const *counter_attrs;
32286
32287 static void delete_gpe_attr_array(void)
32288 {
32289diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
32290index 6cd7805..07facb3 100644
32291--- a/drivers/ata/libahci.c
32292+++ b/drivers/ata/libahci.c
32293@@ -1230,7 +1230,7 @@ int ahci_kick_engine(struct ata_port *ap)
32294 }
32295 EXPORT_SYMBOL_GPL(ahci_kick_engine);
32296
32297-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
32298+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
32299 struct ata_taskfile *tf, int is_cmd, u16 flags,
32300 unsigned long timeout_msec)
32301 {
32302diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
32303index 501c209..5f28b4d 100644
32304--- a/drivers/ata/libata-core.c
32305+++ b/drivers/ata/libata-core.c
32306@@ -4784,7 +4784,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
32307 struct ata_port *ap;
32308 unsigned int tag;
32309
32310- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32311+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32312 ap = qc->ap;
32313
32314 qc->flags = 0;
32315@@ -4800,7 +4800,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
32316 struct ata_port *ap;
32317 struct ata_link *link;
32318
32319- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32320+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32321 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
32322 ap = qc->ap;
32323 link = qc->dev->link;
32324@@ -5896,6 +5896,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
32325 return;
32326
32327 spin_lock(&lock);
32328+ pax_open_kernel();
32329
32330 for (cur = ops->inherits; cur; cur = cur->inherits) {
32331 void **inherit = (void **)cur;
32332@@ -5909,8 +5910,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
32333 if (IS_ERR(*pp))
32334 *pp = NULL;
32335
32336- ops->inherits = NULL;
32337+ *(struct ata_port_operations **)&ops->inherits = NULL;
32338
32339+ pax_close_kernel();
32340 spin_unlock(&lock);
32341 }
32342
32343diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
32344index 405022d..fb70e53 100644
32345--- a/drivers/ata/pata_arasan_cf.c
32346+++ b/drivers/ata/pata_arasan_cf.c
32347@@ -864,7 +864,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
32348 /* Handle platform specific quirks */
32349 if (pdata->quirk) {
32350 if (pdata->quirk & CF_BROKEN_PIO) {
32351- ap->ops->set_piomode = NULL;
32352+ pax_open_kernel();
32353+ *(void **)&ap->ops->set_piomode = NULL;
32354+ pax_close_kernel();
32355 ap->pio_mask = 0;
32356 }
32357 if (pdata->quirk & CF_BROKEN_MWDMA)
32358diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
32359index f9b983a..887b9d8 100644
32360--- a/drivers/atm/adummy.c
32361+++ b/drivers/atm/adummy.c
32362@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
32363 vcc->pop(vcc, skb);
32364 else
32365 dev_kfree_skb_any(skb);
32366- atomic_inc(&vcc->stats->tx);
32367+ atomic_inc_unchecked(&vcc->stats->tx);
32368
32369 return 0;
32370 }
32371diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
32372index 77a7480..05cde58 100644
32373--- a/drivers/atm/ambassador.c
32374+++ b/drivers/atm/ambassador.c
32375@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
32376 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
32377
32378 // VC layer stats
32379- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32380+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32381
32382 // free the descriptor
32383 kfree (tx_descr);
32384@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
32385 dump_skb ("<<<", vc, skb);
32386
32387 // VC layer stats
32388- atomic_inc(&atm_vcc->stats->rx);
32389+ atomic_inc_unchecked(&atm_vcc->stats->rx);
32390 __net_timestamp(skb);
32391 // end of our responsibility
32392 atm_vcc->push (atm_vcc, skb);
32393@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
32394 } else {
32395 PRINTK (KERN_INFO, "dropped over-size frame");
32396 // should we count this?
32397- atomic_inc(&atm_vcc->stats->rx_drop);
32398+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32399 }
32400
32401 } else {
32402@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
32403 }
32404
32405 if (check_area (skb->data, skb->len)) {
32406- atomic_inc(&atm_vcc->stats->tx_err);
32407+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
32408 return -ENOMEM; // ?
32409 }
32410
32411diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
32412index b22d71c..d6e1049 100644
32413--- a/drivers/atm/atmtcp.c
32414+++ b/drivers/atm/atmtcp.c
32415@@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
32416 if (vcc->pop) vcc->pop(vcc,skb);
32417 else dev_kfree_skb(skb);
32418 if (dev_data) return 0;
32419- atomic_inc(&vcc->stats->tx_err);
32420+ atomic_inc_unchecked(&vcc->stats->tx_err);
32421 return -ENOLINK;
32422 }
32423 size = skb->len+sizeof(struct atmtcp_hdr);
32424@@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
32425 if (!new_skb) {
32426 if (vcc->pop) vcc->pop(vcc,skb);
32427 else dev_kfree_skb(skb);
32428- atomic_inc(&vcc->stats->tx_err);
32429+ atomic_inc_unchecked(&vcc->stats->tx_err);
32430 return -ENOBUFS;
32431 }
32432 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
32433@@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
32434 if (vcc->pop) vcc->pop(vcc,skb);
32435 else dev_kfree_skb(skb);
32436 out_vcc->push(out_vcc,new_skb);
32437- atomic_inc(&vcc->stats->tx);
32438- atomic_inc(&out_vcc->stats->rx);
32439+ atomic_inc_unchecked(&vcc->stats->tx);
32440+ atomic_inc_unchecked(&out_vcc->stats->rx);
32441 return 0;
32442 }
32443
32444@@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
32445 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
32446 read_unlock(&vcc_sklist_lock);
32447 if (!out_vcc) {
32448- atomic_inc(&vcc->stats->tx_err);
32449+ atomic_inc_unchecked(&vcc->stats->tx_err);
32450 goto done;
32451 }
32452 skb_pull(skb,sizeof(struct atmtcp_hdr));
32453@@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
32454 __net_timestamp(new_skb);
32455 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
32456 out_vcc->push(out_vcc,new_skb);
32457- atomic_inc(&vcc->stats->tx);
32458- atomic_inc(&out_vcc->stats->rx);
32459+ atomic_inc_unchecked(&vcc->stats->tx);
32460+ atomic_inc_unchecked(&out_vcc->stats->rx);
32461 done:
32462 if (vcc->pop) vcc->pop(vcc,skb);
32463 else dev_kfree_skb(skb);
32464diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
32465index c1eb6fa..4c71be9 100644
32466--- a/drivers/atm/eni.c
32467+++ b/drivers/atm/eni.c
32468@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
32469 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
32470 vcc->dev->number);
32471 length = 0;
32472- atomic_inc(&vcc->stats->rx_err);
32473+ atomic_inc_unchecked(&vcc->stats->rx_err);
32474 }
32475 else {
32476 length = ATM_CELL_SIZE-1; /* no HEC */
32477@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
32478 size);
32479 }
32480 eff = length = 0;
32481- atomic_inc(&vcc->stats->rx_err);
32482+ atomic_inc_unchecked(&vcc->stats->rx_err);
32483 }
32484 else {
32485 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
32486@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
32487 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
32488 vcc->dev->number,vcc->vci,length,size << 2,descr);
32489 length = eff = 0;
32490- atomic_inc(&vcc->stats->rx_err);
32491+ atomic_inc_unchecked(&vcc->stats->rx_err);
32492 }
32493 }
32494 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
32495@@ -767,7 +767,7 @@ rx_dequeued++;
32496 vcc->push(vcc,skb);
32497 pushed++;
32498 }
32499- atomic_inc(&vcc->stats->rx);
32500+ atomic_inc_unchecked(&vcc->stats->rx);
32501 }
32502 wake_up(&eni_dev->rx_wait);
32503 }
32504@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
32505 PCI_DMA_TODEVICE);
32506 if (vcc->pop) vcc->pop(vcc,skb);
32507 else dev_kfree_skb_irq(skb);
32508- atomic_inc(&vcc->stats->tx);
32509+ atomic_inc_unchecked(&vcc->stats->tx);
32510 wake_up(&eni_dev->tx_wait);
32511 dma_complete++;
32512 }
32513diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
32514index b41c948..a002b17 100644
32515--- a/drivers/atm/firestream.c
32516+++ b/drivers/atm/firestream.c
32517@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
32518 }
32519 }
32520
32521- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32522+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32523
32524 fs_dprintk (FS_DEBUG_TXMEM, "i");
32525 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
32526@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
32527 #endif
32528 skb_put (skb, qe->p1 & 0xffff);
32529 ATM_SKB(skb)->vcc = atm_vcc;
32530- atomic_inc(&atm_vcc->stats->rx);
32531+ atomic_inc_unchecked(&atm_vcc->stats->rx);
32532 __net_timestamp(skb);
32533 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
32534 atm_vcc->push (atm_vcc, skb);
32535@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
32536 kfree (pe);
32537 }
32538 if (atm_vcc)
32539- atomic_inc(&atm_vcc->stats->rx_drop);
32540+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32541 break;
32542 case 0x1f: /* Reassembly abort: no buffers. */
32543 /* Silently increment error counter. */
32544 if (atm_vcc)
32545- atomic_inc(&atm_vcc->stats->rx_drop);
32546+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32547 break;
32548 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
32549 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
32550diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
32551index 204814e..cede831 100644
32552--- a/drivers/atm/fore200e.c
32553+++ b/drivers/atm/fore200e.c
32554@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
32555 #endif
32556 /* check error condition */
32557 if (*entry->status & STATUS_ERROR)
32558- atomic_inc(&vcc->stats->tx_err);
32559+ atomic_inc_unchecked(&vcc->stats->tx_err);
32560 else
32561- atomic_inc(&vcc->stats->tx);
32562+ atomic_inc_unchecked(&vcc->stats->tx);
32563 }
32564 }
32565
32566@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
32567 if (skb == NULL) {
32568 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
32569
32570- atomic_inc(&vcc->stats->rx_drop);
32571+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32572 return -ENOMEM;
32573 }
32574
32575@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
32576
32577 dev_kfree_skb_any(skb);
32578
32579- atomic_inc(&vcc->stats->rx_drop);
32580+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32581 return -ENOMEM;
32582 }
32583
32584 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
32585
32586 vcc->push(vcc, skb);
32587- atomic_inc(&vcc->stats->rx);
32588+ atomic_inc_unchecked(&vcc->stats->rx);
32589
32590 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
32591
32592@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
32593 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
32594 fore200e->atm_dev->number,
32595 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
32596- atomic_inc(&vcc->stats->rx_err);
32597+ atomic_inc_unchecked(&vcc->stats->rx_err);
32598 }
32599 }
32600
32601@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
32602 goto retry_here;
32603 }
32604
32605- atomic_inc(&vcc->stats->tx_err);
32606+ atomic_inc_unchecked(&vcc->stats->tx_err);
32607
32608 fore200e->tx_sat++;
32609 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
32610diff --git a/drivers/atm/he.c b/drivers/atm/he.c
32611index 72b6960..cf9167a 100644
32612--- a/drivers/atm/he.c
32613+++ b/drivers/atm/he.c
32614@@ -1699,7 +1699,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32615
32616 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
32617 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
32618- atomic_inc(&vcc->stats->rx_drop);
32619+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32620 goto return_host_buffers;
32621 }
32622
32623@@ -1726,7 +1726,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32624 RBRQ_LEN_ERR(he_dev->rbrq_head)
32625 ? "LEN_ERR" : "",
32626 vcc->vpi, vcc->vci);
32627- atomic_inc(&vcc->stats->rx_err);
32628+ atomic_inc_unchecked(&vcc->stats->rx_err);
32629 goto return_host_buffers;
32630 }
32631
32632@@ -1778,7 +1778,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32633 vcc->push(vcc, skb);
32634 spin_lock(&he_dev->global_lock);
32635
32636- atomic_inc(&vcc->stats->rx);
32637+ atomic_inc_unchecked(&vcc->stats->rx);
32638
32639 return_host_buffers:
32640 ++pdus_assembled;
32641@@ -2104,7 +2104,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
32642 tpd->vcc->pop(tpd->vcc, tpd->skb);
32643 else
32644 dev_kfree_skb_any(tpd->skb);
32645- atomic_inc(&tpd->vcc->stats->tx_err);
32646+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
32647 }
32648 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
32649 return;
32650@@ -2516,7 +2516,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32651 vcc->pop(vcc, skb);
32652 else
32653 dev_kfree_skb_any(skb);
32654- atomic_inc(&vcc->stats->tx_err);
32655+ atomic_inc_unchecked(&vcc->stats->tx_err);
32656 return -EINVAL;
32657 }
32658
32659@@ -2527,7 +2527,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32660 vcc->pop(vcc, skb);
32661 else
32662 dev_kfree_skb_any(skb);
32663- atomic_inc(&vcc->stats->tx_err);
32664+ atomic_inc_unchecked(&vcc->stats->tx_err);
32665 return -EINVAL;
32666 }
32667 #endif
32668@@ -2539,7 +2539,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32669 vcc->pop(vcc, skb);
32670 else
32671 dev_kfree_skb_any(skb);
32672- atomic_inc(&vcc->stats->tx_err);
32673+ atomic_inc_unchecked(&vcc->stats->tx_err);
32674 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32675 return -ENOMEM;
32676 }
32677@@ -2581,7 +2581,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32678 vcc->pop(vcc, skb);
32679 else
32680 dev_kfree_skb_any(skb);
32681- atomic_inc(&vcc->stats->tx_err);
32682+ atomic_inc_unchecked(&vcc->stats->tx_err);
32683 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32684 return -ENOMEM;
32685 }
32686@@ -2612,7 +2612,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32687 __enqueue_tpd(he_dev, tpd, cid);
32688 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32689
32690- atomic_inc(&vcc->stats->tx);
32691+ atomic_inc_unchecked(&vcc->stats->tx);
32692
32693 return 0;
32694 }
32695diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
32696index 1dc0519..1aadaf7 100644
32697--- a/drivers/atm/horizon.c
32698+++ b/drivers/atm/horizon.c
32699@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
32700 {
32701 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
32702 // VC layer stats
32703- atomic_inc(&vcc->stats->rx);
32704+ atomic_inc_unchecked(&vcc->stats->rx);
32705 __net_timestamp(skb);
32706 // end of our responsibility
32707 vcc->push (vcc, skb);
32708@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
32709 dev->tx_iovec = NULL;
32710
32711 // VC layer stats
32712- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32713+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32714
32715 // free the skb
32716 hrz_kfree_skb (skb);
32717diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
32718index 272f009..a18ba55 100644
32719--- a/drivers/atm/idt77252.c
32720+++ b/drivers/atm/idt77252.c
32721@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
32722 else
32723 dev_kfree_skb(skb);
32724
32725- atomic_inc(&vcc->stats->tx);
32726+ atomic_inc_unchecked(&vcc->stats->tx);
32727 }
32728
32729 atomic_dec(&scq->used);
32730@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32731 if ((sb = dev_alloc_skb(64)) == NULL) {
32732 printk("%s: Can't allocate buffers for aal0.\n",
32733 card->name);
32734- atomic_add(i, &vcc->stats->rx_drop);
32735+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
32736 break;
32737 }
32738 if (!atm_charge(vcc, sb->truesize)) {
32739 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
32740 card->name);
32741- atomic_add(i - 1, &vcc->stats->rx_drop);
32742+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
32743 dev_kfree_skb(sb);
32744 break;
32745 }
32746@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32747 ATM_SKB(sb)->vcc = vcc;
32748 __net_timestamp(sb);
32749 vcc->push(vcc, sb);
32750- atomic_inc(&vcc->stats->rx);
32751+ atomic_inc_unchecked(&vcc->stats->rx);
32752
32753 cell += ATM_CELL_PAYLOAD;
32754 }
32755@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32756 "(CDC: %08x)\n",
32757 card->name, len, rpp->len, readl(SAR_REG_CDC));
32758 recycle_rx_pool_skb(card, rpp);
32759- atomic_inc(&vcc->stats->rx_err);
32760+ atomic_inc_unchecked(&vcc->stats->rx_err);
32761 return;
32762 }
32763 if (stat & SAR_RSQE_CRC) {
32764 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
32765 recycle_rx_pool_skb(card, rpp);
32766- atomic_inc(&vcc->stats->rx_err);
32767+ atomic_inc_unchecked(&vcc->stats->rx_err);
32768 return;
32769 }
32770 if (skb_queue_len(&rpp->queue) > 1) {
32771@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32772 RXPRINTK("%s: Can't alloc RX skb.\n",
32773 card->name);
32774 recycle_rx_pool_skb(card, rpp);
32775- atomic_inc(&vcc->stats->rx_err);
32776+ atomic_inc_unchecked(&vcc->stats->rx_err);
32777 return;
32778 }
32779 if (!atm_charge(vcc, skb->truesize)) {
32780@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32781 __net_timestamp(skb);
32782
32783 vcc->push(vcc, skb);
32784- atomic_inc(&vcc->stats->rx);
32785+ atomic_inc_unchecked(&vcc->stats->rx);
32786
32787 return;
32788 }
32789@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32790 __net_timestamp(skb);
32791
32792 vcc->push(vcc, skb);
32793- atomic_inc(&vcc->stats->rx);
32794+ atomic_inc_unchecked(&vcc->stats->rx);
32795
32796 if (skb->truesize > SAR_FB_SIZE_3)
32797 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
32798@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
32799 if (vcc->qos.aal != ATM_AAL0) {
32800 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
32801 card->name, vpi, vci);
32802- atomic_inc(&vcc->stats->rx_drop);
32803+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32804 goto drop;
32805 }
32806
32807 if ((sb = dev_alloc_skb(64)) == NULL) {
32808 printk("%s: Can't allocate buffers for AAL0.\n",
32809 card->name);
32810- atomic_inc(&vcc->stats->rx_err);
32811+ atomic_inc_unchecked(&vcc->stats->rx_err);
32812 goto drop;
32813 }
32814
32815@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
32816 ATM_SKB(sb)->vcc = vcc;
32817 __net_timestamp(sb);
32818 vcc->push(vcc, sb);
32819- atomic_inc(&vcc->stats->rx);
32820+ atomic_inc_unchecked(&vcc->stats->rx);
32821
32822 drop:
32823 skb_pull(queue, 64);
32824@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32825
32826 if (vc == NULL) {
32827 printk("%s: NULL connection in send().\n", card->name);
32828- atomic_inc(&vcc->stats->tx_err);
32829+ atomic_inc_unchecked(&vcc->stats->tx_err);
32830 dev_kfree_skb(skb);
32831 return -EINVAL;
32832 }
32833 if (!test_bit(VCF_TX, &vc->flags)) {
32834 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
32835- atomic_inc(&vcc->stats->tx_err);
32836+ atomic_inc_unchecked(&vcc->stats->tx_err);
32837 dev_kfree_skb(skb);
32838 return -EINVAL;
32839 }
32840@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32841 break;
32842 default:
32843 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
32844- atomic_inc(&vcc->stats->tx_err);
32845+ atomic_inc_unchecked(&vcc->stats->tx_err);
32846 dev_kfree_skb(skb);
32847 return -EINVAL;
32848 }
32849
32850 if (skb_shinfo(skb)->nr_frags != 0) {
32851 printk("%s: No scatter-gather yet.\n", card->name);
32852- atomic_inc(&vcc->stats->tx_err);
32853+ atomic_inc_unchecked(&vcc->stats->tx_err);
32854 dev_kfree_skb(skb);
32855 return -EINVAL;
32856 }
32857@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32858
32859 err = queue_skb(card, vc, skb, oam);
32860 if (err) {
32861- atomic_inc(&vcc->stats->tx_err);
32862+ atomic_inc_unchecked(&vcc->stats->tx_err);
32863 dev_kfree_skb(skb);
32864 return err;
32865 }
32866@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
32867 skb = dev_alloc_skb(64);
32868 if (!skb) {
32869 printk("%s: Out of memory in send_oam().\n", card->name);
32870- atomic_inc(&vcc->stats->tx_err);
32871+ atomic_inc_unchecked(&vcc->stats->tx_err);
32872 return -ENOMEM;
32873 }
32874 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
32875diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
32876index 4217f29..88f547a 100644
32877--- a/drivers/atm/iphase.c
32878+++ b/drivers/atm/iphase.c
32879@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
32880 status = (u_short) (buf_desc_ptr->desc_mode);
32881 if (status & (RX_CER | RX_PTE | RX_OFL))
32882 {
32883- atomic_inc(&vcc->stats->rx_err);
32884+ atomic_inc_unchecked(&vcc->stats->rx_err);
32885 IF_ERR(printk("IA: bad packet, dropping it");)
32886 if (status & RX_CER) {
32887 IF_ERR(printk(" cause: packet CRC error\n");)
32888@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
32889 len = dma_addr - buf_addr;
32890 if (len > iadev->rx_buf_sz) {
32891 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
32892- atomic_inc(&vcc->stats->rx_err);
32893+ atomic_inc_unchecked(&vcc->stats->rx_err);
32894 goto out_free_desc;
32895 }
32896
32897@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32898 ia_vcc = INPH_IA_VCC(vcc);
32899 if (ia_vcc == NULL)
32900 {
32901- atomic_inc(&vcc->stats->rx_err);
32902+ atomic_inc_unchecked(&vcc->stats->rx_err);
32903 atm_return(vcc, skb->truesize);
32904 dev_kfree_skb_any(skb);
32905 goto INCR_DLE;
32906@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32907 if ((length > iadev->rx_buf_sz) || (length >
32908 (skb->len - sizeof(struct cpcs_trailer))))
32909 {
32910- atomic_inc(&vcc->stats->rx_err);
32911+ atomic_inc_unchecked(&vcc->stats->rx_err);
32912 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
32913 length, skb->len);)
32914 atm_return(vcc, skb->truesize);
32915@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32916
32917 IF_RX(printk("rx_dle_intr: skb push");)
32918 vcc->push(vcc,skb);
32919- atomic_inc(&vcc->stats->rx);
32920+ atomic_inc_unchecked(&vcc->stats->rx);
32921 iadev->rx_pkt_cnt++;
32922 }
32923 INCR_DLE:
32924@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
32925 {
32926 struct k_sonet_stats *stats;
32927 stats = &PRIV(_ia_dev[board])->sonet_stats;
32928- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
32929- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
32930- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
32931- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
32932- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
32933- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
32934- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
32935- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
32936- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
32937+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
32938+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
32939+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
32940+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
32941+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
32942+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
32943+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
32944+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
32945+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
32946 }
32947 ia_cmds.status = 0;
32948 break;
32949@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
32950 if ((desc == 0) || (desc > iadev->num_tx_desc))
32951 {
32952 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
32953- atomic_inc(&vcc->stats->tx);
32954+ atomic_inc_unchecked(&vcc->stats->tx);
32955 if (vcc->pop)
32956 vcc->pop(vcc, skb);
32957 else
32958@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
32959 ATM_DESC(skb) = vcc->vci;
32960 skb_queue_tail(&iadev->tx_dma_q, skb);
32961
32962- atomic_inc(&vcc->stats->tx);
32963+ atomic_inc_unchecked(&vcc->stats->tx);
32964 iadev->tx_pkt_cnt++;
32965 /* Increment transaction counter */
32966 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
32967
32968 #if 0
32969 /* add flow control logic */
32970- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
32971+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
32972 if (iavcc->vc_desc_cnt > 10) {
32973 vcc->tx_quota = vcc->tx_quota * 3 / 4;
32974 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
32975diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
32976index fa7d701..1e404c7 100644
32977--- a/drivers/atm/lanai.c
32978+++ b/drivers/atm/lanai.c
32979@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
32980 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
32981 lanai_endtx(lanai, lvcc);
32982 lanai_free_skb(lvcc->tx.atmvcc, skb);
32983- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
32984+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
32985 }
32986
32987 /* Try to fill the buffer - don't call unless there is backlog */
32988@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
32989 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
32990 __net_timestamp(skb);
32991 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
32992- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
32993+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
32994 out:
32995 lvcc->rx.buf.ptr = end;
32996 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
32997@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32998 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
32999 "vcc %d\n", lanai->number, (unsigned int) s, vci);
33000 lanai->stats.service_rxnotaal5++;
33001- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
33002+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
33003 return 0;
33004 }
33005 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
33006@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
33007 int bytes;
33008 read_unlock(&vcc_sklist_lock);
33009 DPRINTK("got trashed rx pdu on vci %d\n", vci);
33010- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
33011+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
33012 lvcc->stats.x.aal5.service_trash++;
33013 bytes = (SERVICE_GET_END(s) * 16) -
33014 (((unsigned long) lvcc->rx.buf.ptr) -
33015@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
33016 }
33017 if (s & SERVICE_STREAM) {
33018 read_unlock(&vcc_sklist_lock);
33019- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
33020+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
33021 lvcc->stats.x.aal5.service_stream++;
33022 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
33023 "PDU on VCI %d!\n", lanai->number, vci);
33024@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
33025 return 0;
33026 }
33027 DPRINTK("got rx crc error on vci %d\n", vci);
33028- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
33029+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
33030 lvcc->stats.x.aal5.service_rxcrc++;
33031 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
33032 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
33033diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
33034index ed1d2b7..8cffc1f 100644
33035--- a/drivers/atm/nicstar.c
33036+++ b/drivers/atm/nicstar.c
33037@@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
33038 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
33039 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
33040 card->index);
33041- atomic_inc(&vcc->stats->tx_err);
33042+ atomic_inc_unchecked(&vcc->stats->tx_err);
33043 dev_kfree_skb_any(skb);
33044 return -EINVAL;
33045 }
33046@@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
33047 if (!vc->tx) {
33048 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
33049 card->index);
33050- atomic_inc(&vcc->stats->tx_err);
33051+ atomic_inc_unchecked(&vcc->stats->tx_err);
33052 dev_kfree_skb_any(skb);
33053 return -EINVAL;
33054 }
33055@@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
33056 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
33057 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
33058 card->index);
33059- atomic_inc(&vcc->stats->tx_err);
33060+ atomic_inc_unchecked(&vcc->stats->tx_err);
33061 dev_kfree_skb_any(skb);
33062 return -EINVAL;
33063 }
33064
33065 if (skb_shinfo(skb)->nr_frags != 0) {
33066 printk("nicstar%d: No scatter-gather yet.\n", card->index);
33067- atomic_inc(&vcc->stats->tx_err);
33068+ atomic_inc_unchecked(&vcc->stats->tx_err);
33069 dev_kfree_skb_any(skb);
33070 return -EINVAL;
33071 }
33072@@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
33073 }
33074
33075 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
33076- atomic_inc(&vcc->stats->tx_err);
33077+ atomic_inc_unchecked(&vcc->stats->tx_err);
33078 dev_kfree_skb_any(skb);
33079 return -EIO;
33080 }
33081- atomic_inc(&vcc->stats->tx);
33082+ atomic_inc_unchecked(&vcc->stats->tx);
33083
33084 return 0;
33085 }
33086@@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33087 printk
33088 ("nicstar%d: Can't allocate buffers for aal0.\n",
33089 card->index);
33090- atomic_add(i, &vcc->stats->rx_drop);
33091+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
33092 break;
33093 }
33094 if (!atm_charge(vcc, sb->truesize)) {
33095 RXPRINTK
33096 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
33097 card->index);
33098- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
33099+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
33100 dev_kfree_skb_any(sb);
33101 break;
33102 }
33103@@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33104 ATM_SKB(sb)->vcc = vcc;
33105 __net_timestamp(sb);
33106 vcc->push(vcc, sb);
33107- atomic_inc(&vcc->stats->rx);
33108+ atomic_inc_unchecked(&vcc->stats->rx);
33109 cell += ATM_CELL_PAYLOAD;
33110 }
33111
33112@@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33113 if (iovb == NULL) {
33114 printk("nicstar%d: Out of iovec buffers.\n",
33115 card->index);
33116- atomic_inc(&vcc->stats->rx_drop);
33117+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33118 recycle_rx_buf(card, skb);
33119 return;
33120 }
33121@@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33122 small or large buffer itself. */
33123 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
33124 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
33125- atomic_inc(&vcc->stats->rx_err);
33126+ atomic_inc_unchecked(&vcc->stats->rx_err);
33127 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
33128 NS_MAX_IOVECS);
33129 NS_PRV_IOVCNT(iovb) = 0;
33130@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33131 ("nicstar%d: Expected a small buffer, and this is not one.\n",
33132 card->index);
33133 which_list(card, skb);
33134- atomic_inc(&vcc->stats->rx_err);
33135+ atomic_inc_unchecked(&vcc->stats->rx_err);
33136 recycle_rx_buf(card, skb);
33137 vc->rx_iov = NULL;
33138 recycle_iov_buf(card, iovb);
33139@@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33140 ("nicstar%d: Expected a large buffer, and this is not one.\n",
33141 card->index);
33142 which_list(card, skb);
33143- atomic_inc(&vcc->stats->rx_err);
33144+ atomic_inc_unchecked(&vcc->stats->rx_err);
33145 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
33146 NS_PRV_IOVCNT(iovb));
33147 vc->rx_iov = NULL;
33148@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33149 printk(" - PDU size mismatch.\n");
33150 else
33151 printk(".\n");
33152- atomic_inc(&vcc->stats->rx_err);
33153+ atomic_inc_unchecked(&vcc->stats->rx_err);
33154 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
33155 NS_PRV_IOVCNT(iovb));
33156 vc->rx_iov = NULL;
33157@@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33158 /* skb points to a small buffer */
33159 if (!atm_charge(vcc, skb->truesize)) {
33160 push_rxbufs(card, skb);
33161- atomic_inc(&vcc->stats->rx_drop);
33162+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33163 } else {
33164 skb_put(skb, len);
33165 dequeue_sm_buf(card, skb);
33166@@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33167 ATM_SKB(skb)->vcc = vcc;
33168 __net_timestamp(skb);
33169 vcc->push(vcc, skb);
33170- atomic_inc(&vcc->stats->rx);
33171+ atomic_inc_unchecked(&vcc->stats->rx);
33172 }
33173 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
33174 struct sk_buff *sb;
33175@@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33176 if (len <= NS_SMBUFSIZE) {
33177 if (!atm_charge(vcc, sb->truesize)) {
33178 push_rxbufs(card, sb);
33179- atomic_inc(&vcc->stats->rx_drop);
33180+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33181 } else {
33182 skb_put(sb, len);
33183 dequeue_sm_buf(card, sb);
33184@@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33185 ATM_SKB(sb)->vcc = vcc;
33186 __net_timestamp(sb);
33187 vcc->push(vcc, sb);
33188- atomic_inc(&vcc->stats->rx);
33189+ atomic_inc_unchecked(&vcc->stats->rx);
33190 }
33191
33192 push_rxbufs(card, skb);
33193@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33194
33195 if (!atm_charge(vcc, skb->truesize)) {
33196 push_rxbufs(card, skb);
33197- atomic_inc(&vcc->stats->rx_drop);
33198+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33199 } else {
33200 dequeue_lg_buf(card, skb);
33201 #ifdef NS_USE_DESTRUCTORS
33202@@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33203 ATM_SKB(skb)->vcc = vcc;
33204 __net_timestamp(skb);
33205 vcc->push(vcc, skb);
33206- atomic_inc(&vcc->stats->rx);
33207+ atomic_inc_unchecked(&vcc->stats->rx);
33208 }
33209
33210 push_rxbufs(card, sb);
33211@@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33212 printk
33213 ("nicstar%d: Out of huge buffers.\n",
33214 card->index);
33215- atomic_inc(&vcc->stats->rx_drop);
33216+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33217 recycle_iovec_rx_bufs(card,
33218 (struct iovec *)
33219 iovb->data,
33220@@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33221 card->hbpool.count++;
33222 } else
33223 dev_kfree_skb_any(hb);
33224- atomic_inc(&vcc->stats->rx_drop);
33225+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33226 } else {
33227 /* Copy the small buffer to the huge buffer */
33228 sb = (struct sk_buff *)iov->iov_base;
33229@@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33230 #endif /* NS_USE_DESTRUCTORS */
33231 __net_timestamp(hb);
33232 vcc->push(vcc, hb);
33233- atomic_inc(&vcc->stats->rx);
33234+ atomic_inc_unchecked(&vcc->stats->rx);
33235 }
33236 }
33237
33238diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
33239index 0474a89..06ea4a1 100644
33240--- a/drivers/atm/solos-pci.c
33241+++ b/drivers/atm/solos-pci.c
33242@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
33243 }
33244 atm_charge(vcc, skb->truesize);
33245 vcc->push(vcc, skb);
33246- atomic_inc(&vcc->stats->rx);
33247+ atomic_inc_unchecked(&vcc->stats->rx);
33248 break;
33249
33250 case PKT_STATUS:
33251@@ -1117,7 +1117,7 @@ static uint32_t fpga_tx(struct solos_card *card)
33252 vcc = SKB_CB(oldskb)->vcc;
33253
33254 if (vcc) {
33255- atomic_inc(&vcc->stats->tx);
33256+ atomic_inc_unchecked(&vcc->stats->tx);
33257 solos_pop(vcc, oldskb);
33258 } else {
33259 dev_kfree_skb_irq(oldskb);
33260diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
33261index 0215934..ce9f5b1 100644
33262--- a/drivers/atm/suni.c
33263+++ b/drivers/atm/suni.c
33264@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
33265
33266
33267 #define ADD_LIMITED(s,v) \
33268- atomic_add((v),&stats->s); \
33269- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
33270+ atomic_add_unchecked((v),&stats->s); \
33271+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
33272
33273
33274 static void suni_hz(unsigned long from_timer)
33275diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
33276index 5120a96..e2572bd 100644
33277--- a/drivers/atm/uPD98402.c
33278+++ b/drivers/atm/uPD98402.c
33279@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
33280 struct sonet_stats tmp;
33281 int error = 0;
33282
33283- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
33284+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
33285 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
33286 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
33287 if (zero && !error) {
33288@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
33289
33290
33291 #define ADD_LIMITED(s,v) \
33292- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
33293- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
33294- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
33295+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
33296+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
33297+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
33298
33299
33300 static void stat_event(struct atm_dev *dev)
33301@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
33302 if (reason & uPD98402_INT_PFM) stat_event(dev);
33303 if (reason & uPD98402_INT_PCO) {
33304 (void) GET(PCOCR); /* clear interrupt cause */
33305- atomic_add(GET(HECCT),
33306+ atomic_add_unchecked(GET(HECCT),
33307 &PRIV(dev)->sonet_stats.uncorr_hcs);
33308 }
33309 if ((reason & uPD98402_INT_RFO) &&
33310@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
33311 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
33312 uPD98402_INT_LOS),PIMR); /* enable them */
33313 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
33314- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
33315- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
33316- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
33317+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
33318+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
33319+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
33320 return 0;
33321 }
33322
33323diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
33324index 969c3c2..9b72956 100644
33325--- a/drivers/atm/zatm.c
33326+++ b/drivers/atm/zatm.c
33327@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
33328 }
33329 if (!size) {
33330 dev_kfree_skb_irq(skb);
33331- if (vcc) atomic_inc(&vcc->stats->rx_err);
33332+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
33333 continue;
33334 }
33335 if (!atm_charge(vcc,skb->truesize)) {
33336@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
33337 skb->len = size;
33338 ATM_SKB(skb)->vcc = vcc;
33339 vcc->push(vcc,skb);
33340- atomic_inc(&vcc->stats->rx);
33341+ atomic_inc_unchecked(&vcc->stats->rx);
33342 }
33343 zout(pos & 0xffff,MTA(mbx));
33344 #if 0 /* probably a stupid idea */
33345@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
33346 skb_queue_head(&zatm_vcc->backlog,skb);
33347 break;
33348 }
33349- atomic_inc(&vcc->stats->tx);
33350+ atomic_inc_unchecked(&vcc->stats->tx);
33351 wake_up(&zatm_vcc->tx_wait);
33352 }
33353
33354diff --git a/drivers/base/bus.c b/drivers/base/bus.c
33355index 6856303..0602d70 100644
33356--- a/drivers/base/bus.c
33357+++ b/drivers/base/bus.c
33358@@ -1163,7 +1163,7 @@ int subsys_interface_register(struct subsys_interface *sif)
33359 return -EINVAL;
33360
33361 mutex_lock(&subsys->p->mutex);
33362- list_add_tail(&sif->node, &subsys->p->interfaces);
33363+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
33364 if (sif->add_dev) {
33365 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
33366 while ((dev = subsys_dev_iter_next(&iter)))
33367@@ -1188,7 +1188,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
33368 subsys = sif->subsys;
33369
33370 mutex_lock(&subsys->p->mutex);
33371- list_del_init(&sif->node);
33372+ pax_list_del_init((struct list_head *)&sif->node);
33373 if (sif->remove_dev) {
33374 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
33375 while ((dev = subsys_dev_iter_next(&iter)))
33376diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
33377index 17cf7ca..7e553e1 100644
33378--- a/drivers/base/devtmpfs.c
33379+++ b/drivers/base/devtmpfs.c
33380@@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
33381 if (!thread)
33382 return 0;
33383
33384- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
33385+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
33386 if (err)
33387 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
33388 else
33389diff --git a/drivers/base/node.c b/drivers/base/node.c
33390index fac124a..66bd4ab 100644
33391--- a/drivers/base/node.c
33392+++ b/drivers/base/node.c
33393@@ -625,7 +625,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
33394 struct node_attr {
33395 struct device_attribute attr;
33396 enum node_states state;
33397-};
33398+} __do_const;
33399
33400 static ssize_t show_node_state(struct device *dev,
33401 struct device_attribute *attr, char *buf)
33402diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
33403index acc3a8d..981c236 100644
33404--- a/drivers/base/power/domain.c
33405+++ b/drivers/base/power/domain.c
33406@@ -1851,7 +1851,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
33407 {
33408 struct cpuidle_driver *cpuidle_drv;
33409 struct gpd_cpu_data *cpu_data;
33410- struct cpuidle_state *idle_state;
33411+ cpuidle_state_no_const *idle_state;
33412 int ret = 0;
33413
33414 if (IS_ERR_OR_NULL(genpd) || state < 0)
33415@@ -1919,7 +1919,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
33416 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
33417 {
33418 struct gpd_cpu_data *cpu_data;
33419- struct cpuidle_state *idle_state;
33420+ cpuidle_state_no_const *idle_state;
33421 int ret = 0;
33422
33423 if (IS_ERR_OR_NULL(genpd))
33424diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
33425index e6ee5e8..98ad7fc 100644
33426--- a/drivers/base/power/wakeup.c
33427+++ b/drivers/base/power/wakeup.c
33428@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
33429 * They need to be modified together atomically, so it's better to use one
33430 * atomic variable to hold them both.
33431 */
33432-static atomic_t combined_event_count = ATOMIC_INIT(0);
33433+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
33434
33435 #define IN_PROGRESS_BITS (sizeof(int) * 4)
33436 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
33437
33438 static void split_counters(unsigned int *cnt, unsigned int *inpr)
33439 {
33440- unsigned int comb = atomic_read(&combined_event_count);
33441+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
33442
33443 *cnt = (comb >> IN_PROGRESS_BITS);
33444 *inpr = comb & MAX_IN_PROGRESS;
33445@@ -389,7 +389,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
33446 ws->start_prevent_time = ws->last_time;
33447
33448 /* Increment the counter of events in progress. */
33449- cec = atomic_inc_return(&combined_event_count);
33450+ cec = atomic_inc_return_unchecked(&combined_event_count);
33451
33452 trace_wakeup_source_activate(ws->name, cec);
33453 }
33454@@ -515,7 +515,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
33455 * Increment the counter of registered wakeup events and decrement the
33456 * couter of wakeup events in progress simultaneously.
33457 */
33458- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
33459+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
33460 trace_wakeup_source_deactivate(ws->name, cec);
33461
33462 split_counters(&cnt, &inpr);
33463diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
33464index e8d11b6..7b1b36f 100644
33465--- a/drivers/base/syscore.c
33466+++ b/drivers/base/syscore.c
33467@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
33468 void register_syscore_ops(struct syscore_ops *ops)
33469 {
33470 mutex_lock(&syscore_ops_lock);
33471- list_add_tail(&ops->node, &syscore_ops_list);
33472+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
33473 mutex_unlock(&syscore_ops_lock);
33474 }
33475 EXPORT_SYMBOL_GPL(register_syscore_ops);
33476@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
33477 void unregister_syscore_ops(struct syscore_ops *ops)
33478 {
33479 mutex_lock(&syscore_ops_lock);
33480- list_del(&ops->node);
33481+ pax_list_del((struct list_head *)&ops->node);
33482 mutex_unlock(&syscore_ops_lock);
33483 }
33484 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
33485diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
33486index ade58bc..867143d 100644
33487--- a/drivers/block/cciss.c
33488+++ b/drivers/block/cciss.c
33489@@ -1196,6 +1196,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
33490 int err;
33491 u32 cp;
33492
33493+ memset(&arg64, 0, sizeof(arg64));
33494+
33495 err = 0;
33496 err |=
33497 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
33498@@ -3005,7 +3007,7 @@ static void start_io(ctlr_info_t *h)
33499 while (!list_empty(&h->reqQ)) {
33500 c = list_entry(h->reqQ.next, CommandList_struct, list);
33501 /* can't do anything if fifo is full */
33502- if ((h->access.fifo_full(h))) {
33503+ if ((h->access->fifo_full(h))) {
33504 dev_warn(&h->pdev->dev, "fifo full\n");
33505 break;
33506 }
33507@@ -3015,7 +3017,7 @@ static void start_io(ctlr_info_t *h)
33508 h->Qdepth--;
33509
33510 /* Tell the controller execute command */
33511- h->access.submit_command(h, c);
33512+ h->access->submit_command(h, c);
33513
33514 /* Put job onto the completed Q */
33515 addQ(&h->cmpQ, c);
33516@@ -3441,17 +3443,17 @@ startio:
33517
33518 static inline unsigned long get_next_completion(ctlr_info_t *h)
33519 {
33520- return h->access.command_completed(h);
33521+ return h->access->command_completed(h);
33522 }
33523
33524 static inline int interrupt_pending(ctlr_info_t *h)
33525 {
33526- return h->access.intr_pending(h);
33527+ return h->access->intr_pending(h);
33528 }
33529
33530 static inline long interrupt_not_for_us(ctlr_info_t *h)
33531 {
33532- return ((h->access.intr_pending(h) == 0) ||
33533+ return ((h->access->intr_pending(h) == 0) ||
33534 (h->interrupts_enabled == 0));
33535 }
33536
33537@@ -3484,7 +3486,7 @@ static inline u32 next_command(ctlr_info_t *h)
33538 u32 a;
33539
33540 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
33541- return h->access.command_completed(h);
33542+ return h->access->command_completed(h);
33543
33544 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
33545 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
33546@@ -4041,7 +4043,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
33547 trans_support & CFGTBL_Trans_use_short_tags);
33548
33549 /* Change the access methods to the performant access methods */
33550- h->access = SA5_performant_access;
33551+ h->access = &SA5_performant_access;
33552 h->transMethod = CFGTBL_Trans_Performant;
33553
33554 return;
33555@@ -4310,7 +4312,7 @@ static int cciss_pci_init(ctlr_info_t *h)
33556 if (prod_index < 0)
33557 return -ENODEV;
33558 h->product_name = products[prod_index].product_name;
33559- h->access = *(products[prod_index].access);
33560+ h->access = products[prod_index].access;
33561
33562 if (cciss_board_disabled(h)) {
33563 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
33564@@ -5032,7 +5034,7 @@ reinit_after_soft_reset:
33565 }
33566
33567 /* make sure the board interrupts are off */
33568- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33569+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33570 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
33571 if (rc)
33572 goto clean2;
33573@@ -5082,7 +5084,7 @@ reinit_after_soft_reset:
33574 * fake ones to scoop up any residual completions.
33575 */
33576 spin_lock_irqsave(&h->lock, flags);
33577- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33578+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33579 spin_unlock_irqrestore(&h->lock, flags);
33580 free_irq(h->intr[h->intr_mode], h);
33581 rc = cciss_request_irq(h, cciss_msix_discard_completions,
33582@@ -5102,9 +5104,9 @@ reinit_after_soft_reset:
33583 dev_info(&h->pdev->dev, "Board READY.\n");
33584 dev_info(&h->pdev->dev,
33585 "Waiting for stale completions to drain.\n");
33586- h->access.set_intr_mask(h, CCISS_INTR_ON);
33587+ h->access->set_intr_mask(h, CCISS_INTR_ON);
33588 msleep(10000);
33589- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33590+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33591
33592 rc = controller_reset_failed(h->cfgtable);
33593 if (rc)
33594@@ -5127,7 +5129,7 @@ reinit_after_soft_reset:
33595 cciss_scsi_setup(h);
33596
33597 /* Turn the interrupts on so we can service requests */
33598- h->access.set_intr_mask(h, CCISS_INTR_ON);
33599+ h->access->set_intr_mask(h, CCISS_INTR_ON);
33600
33601 /* Get the firmware version */
33602 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
33603@@ -5199,7 +5201,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
33604 kfree(flush_buf);
33605 if (return_code != IO_OK)
33606 dev_warn(&h->pdev->dev, "Error flushing cache\n");
33607- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33608+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33609 free_irq(h->intr[h->intr_mode], h);
33610 }
33611
33612diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
33613index 7fda30e..eb5dfe0 100644
33614--- a/drivers/block/cciss.h
33615+++ b/drivers/block/cciss.h
33616@@ -101,7 +101,7 @@ struct ctlr_info
33617 /* information about each logical volume */
33618 drive_info_struct *drv[CISS_MAX_LUN];
33619
33620- struct access_method access;
33621+ struct access_method *access;
33622
33623 /* queue and queue Info */
33624 struct list_head reqQ;
33625diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
33626index 3f08713..56a586a 100644
33627--- a/drivers/block/cpqarray.c
33628+++ b/drivers/block/cpqarray.c
33629@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
33630 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
33631 goto Enomem4;
33632 }
33633- hba[i]->access.set_intr_mask(hba[i], 0);
33634+ hba[i]->access->set_intr_mask(hba[i], 0);
33635 if (request_irq(hba[i]->intr, do_ida_intr,
33636 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
33637 {
33638@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
33639 add_timer(&hba[i]->timer);
33640
33641 /* Enable IRQ now that spinlock and rate limit timer are set up */
33642- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
33643+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
33644
33645 for(j=0; j<NWD; j++) {
33646 struct gendisk *disk = ida_gendisk[i][j];
33647@@ -694,7 +694,7 @@ DBGINFO(
33648 for(i=0; i<NR_PRODUCTS; i++) {
33649 if (board_id == products[i].board_id) {
33650 c->product_name = products[i].product_name;
33651- c->access = *(products[i].access);
33652+ c->access = products[i].access;
33653 break;
33654 }
33655 }
33656@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
33657 hba[ctlr]->intr = intr;
33658 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
33659 hba[ctlr]->product_name = products[j].product_name;
33660- hba[ctlr]->access = *(products[j].access);
33661+ hba[ctlr]->access = products[j].access;
33662 hba[ctlr]->ctlr = ctlr;
33663 hba[ctlr]->board_id = board_id;
33664 hba[ctlr]->pci_dev = NULL; /* not PCI */
33665@@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
33666
33667 while((c = h->reqQ) != NULL) {
33668 /* Can't do anything if we're busy */
33669- if (h->access.fifo_full(h) == 0)
33670+ if (h->access->fifo_full(h) == 0)
33671 return;
33672
33673 /* Get the first entry from the request Q */
33674@@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
33675 h->Qdepth--;
33676
33677 /* Tell the controller to do our bidding */
33678- h->access.submit_command(h, c);
33679+ h->access->submit_command(h, c);
33680
33681 /* Get onto the completion Q */
33682 addQ(&h->cmpQ, c);
33683@@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
33684 unsigned long flags;
33685 __u32 a,a1;
33686
33687- istat = h->access.intr_pending(h);
33688+ istat = h->access->intr_pending(h);
33689 /* Is this interrupt for us? */
33690 if (istat == 0)
33691 return IRQ_NONE;
33692@@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
33693 */
33694 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
33695 if (istat & FIFO_NOT_EMPTY) {
33696- while((a = h->access.command_completed(h))) {
33697+ while((a = h->access->command_completed(h))) {
33698 a1 = a; a &= ~3;
33699 if ((c = h->cmpQ) == NULL)
33700 {
33701@@ -1449,11 +1449,11 @@ static int sendcmd(
33702 /*
33703 * Disable interrupt
33704 */
33705- info_p->access.set_intr_mask(info_p, 0);
33706+ info_p->access->set_intr_mask(info_p, 0);
33707 /* Make sure there is room in the command FIFO */
33708 /* Actually it should be completely empty at this time. */
33709 for (i = 200000; i > 0; i--) {
33710- temp = info_p->access.fifo_full(info_p);
33711+ temp = info_p->access->fifo_full(info_p);
33712 if (temp != 0) {
33713 break;
33714 }
33715@@ -1466,7 +1466,7 @@ DBG(
33716 /*
33717 * Send the cmd
33718 */
33719- info_p->access.submit_command(info_p, c);
33720+ info_p->access->submit_command(info_p, c);
33721 complete = pollcomplete(ctlr);
33722
33723 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
33724@@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
33725 * we check the new geometry. Then turn interrupts back on when
33726 * we're done.
33727 */
33728- host->access.set_intr_mask(host, 0);
33729+ host->access->set_intr_mask(host, 0);
33730 getgeometry(ctlr);
33731- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
33732+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
33733
33734 for(i=0; i<NWD; i++) {
33735 struct gendisk *disk = ida_gendisk[ctlr][i];
33736@@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
33737 /* Wait (up to 2 seconds) for a command to complete */
33738
33739 for (i = 200000; i > 0; i--) {
33740- done = hba[ctlr]->access.command_completed(hba[ctlr]);
33741+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
33742 if (done == 0) {
33743 udelay(10); /* a short fixed delay */
33744 } else
33745diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
33746index be73e9d..7fbf140 100644
33747--- a/drivers/block/cpqarray.h
33748+++ b/drivers/block/cpqarray.h
33749@@ -99,7 +99,7 @@ struct ctlr_info {
33750 drv_info_t drv[NWD];
33751 struct proc_dir_entry *proc;
33752
33753- struct access_method access;
33754+ struct access_method *access;
33755
33756 cmdlist_t *reqQ;
33757 cmdlist_t *cmpQ;
33758diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
33759index 6b51afa..17e1191 100644
33760--- a/drivers/block/drbd/drbd_int.h
33761+++ b/drivers/block/drbd/drbd_int.h
33762@@ -582,7 +582,7 @@ struct drbd_epoch {
33763 struct drbd_tconn *tconn;
33764 struct list_head list;
33765 unsigned int barrier_nr;
33766- atomic_t epoch_size; /* increased on every request added. */
33767+ atomic_unchecked_t epoch_size; /* increased on every request added. */
33768 atomic_t active; /* increased on every req. added, and dec on every finished. */
33769 unsigned long flags;
33770 };
33771@@ -1011,7 +1011,7 @@ struct drbd_conf {
33772 int al_tr_cycle;
33773 int al_tr_pos; /* position of the next transaction in the journal */
33774 wait_queue_head_t seq_wait;
33775- atomic_t packet_seq;
33776+ atomic_unchecked_t packet_seq;
33777 unsigned int peer_seq;
33778 spinlock_t peer_seq_lock;
33779 unsigned int minor;
33780@@ -1527,7 +1527,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
33781 char __user *uoptval;
33782 int err;
33783
33784- uoptval = (char __user __force *)optval;
33785+ uoptval = (char __force_user *)optval;
33786
33787 set_fs(KERNEL_DS);
33788 if (level == SOL_SOCKET)
33789diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
33790index 8c13eeb..217adee 100644
33791--- a/drivers/block/drbd/drbd_main.c
33792+++ b/drivers/block/drbd/drbd_main.c
33793@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
33794 p->sector = sector;
33795 p->block_id = block_id;
33796 p->blksize = blksize;
33797- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
33798+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
33799 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
33800 }
33801
33802@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
33803 return -EIO;
33804 p->sector = cpu_to_be64(req->i.sector);
33805 p->block_id = (unsigned long)req;
33806- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
33807+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
33808 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
33809 if (mdev->state.conn >= C_SYNC_SOURCE &&
33810 mdev->state.conn <= C_PAUSED_SYNC_T)
33811@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
33812 {
33813 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
33814
33815- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
33816- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
33817+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
33818+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
33819 kfree(tconn->current_epoch);
33820
33821 idr_destroy(&tconn->volumes);
33822diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
33823index a9eccfc..f5efe87 100644
33824--- a/drivers/block/drbd/drbd_receiver.c
33825+++ b/drivers/block/drbd/drbd_receiver.c
33826@@ -833,7 +833,7 @@ int drbd_connected(struct drbd_conf *mdev)
33827 {
33828 int err;
33829
33830- atomic_set(&mdev->packet_seq, 0);
33831+ atomic_set_unchecked(&mdev->packet_seq, 0);
33832 mdev->peer_seq = 0;
33833
33834 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
33835@@ -1191,7 +1191,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
33836 do {
33837 next_epoch = NULL;
33838
33839- epoch_size = atomic_read(&epoch->epoch_size);
33840+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
33841
33842 switch (ev & ~EV_CLEANUP) {
33843 case EV_PUT:
33844@@ -1231,7 +1231,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
33845 rv = FE_DESTROYED;
33846 } else {
33847 epoch->flags = 0;
33848- atomic_set(&epoch->epoch_size, 0);
33849+ atomic_set_unchecked(&epoch->epoch_size, 0);
33850 /* atomic_set(&epoch->active, 0); is already zero */
33851 if (rv == FE_STILL_LIVE)
33852 rv = FE_RECYCLED;
33853@@ -1449,7 +1449,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
33854 conn_wait_active_ee_empty(tconn);
33855 drbd_flush(tconn);
33856
33857- if (atomic_read(&tconn->current_epoch->epoch_size)) {
33858+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
33859 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
33860 if (epoch)
33861 break;
33862@@ -1462,11 +1462,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
33863 }
33864
33865 epoch->flags = 0;
33866- atomic_set(&epoch->epoch_size, 0);
33867+ atomic_set_unchecked(&epoch->epoch_size, 0);
33868 atomic_set(&epoch->active, 0);
33869
33870 spin_lock(&tconn->epoch_lock);
33871- if (atomic_read(&tconn->current_epoch->epoch_size)) {
33872+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
33873 list_add(&epoch->list, &tconn->current_epoch->list);
33874 tconn->current_epoch = epoch;
33875 tconn->epochs++;
33876@@ -2170,7 +2170,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
33877
33878 err = wait_for_and_update_peer_seq(mdev, peer_seq);
33879 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
33880- atomic_inc(&tconn->current_epoch->epoch_size);
33881+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
33882 err2 = drbd_drain_block(mdev, pi->size);
33883 if (!err)
33884 err = err2;
33885@@ -2204,7 +2204,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
33886
33887 spin_lock(&tconn->epoch_lock);
33888 peer_req->epoch = tconn->current_epoch;
33889- atomic_inc(&peer_req->epoch->epoch_size);
33890+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
33891 atomic_inc(&peer_req->epoch->active);
33892 spin_unlock(&tconn->epoch_lock);
33893
33894@@ -4346,7 +4346,7 @@ struct data_cmd {
33895 int expect_payload;
33896 size_t pkt_size;
33897 int (*fn)(struct drbd_tconn *, struct packet_info *);
33898-};
33899+} __do_const;
33900
33901 static struct data_cmd drbd_cmd_handler[] = {
33902 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
33903@@ -4466,7 +4466,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
33904 if (!list_empty(&tconn->current_epoch->list))
33905 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
33906 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
33907- atomic_set(&tconn->current_epoch->epoch_size, 0);
33908+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
33909 tconn->send.seen_any_write_yet = false;
33910
33911 conn_info(tconn, "Connection closed\n");
33912@@ -5222,7 +5222,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
33913 struct asender_cmd {
33914 size_t pkt_size;
33915 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
33916-};
33917+} __do_const;
33918
33919 static struct asender_cmd asender_tbl[] = {
33920 [P_PING] = { 0, got_Ping },
33921diff --git a/drivers/block/loop.c b/drivers/block/loop.c
33922index f74f2c0..bb668af 100644
33923--- a/drivers/block/loop.c
33924+++ b/drivers/block/loop.c
33925@@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
33926 mm_segment_t old_fs = get_fs();
33927
33928 set_fs(get_ds());
33929- bw = file->f_op->write(file, buf, len, &pos);
33930+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
33931 set_fs(old_fs);
33932 if (likely(bw == len))
33933 return 0;
33934diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
33935index d620b44..587561e 100644
33936--- a/drivers/cdrom/cdrom.c
33937+++ b/drivers/cdrom/cdrom.c
33938@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
33939 ENSURE(reset, CDC_RESET);
33940 ENSURE(generic_packet, CDC_GENERIC_PACKET);
33941 cdi->mc_flags = 0;
33942- cdo->n_minors = 0;
33943 cdi->options = CDO_USE_FFLAGS;
33944
33945 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
33946@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
33947 else
33948 cdi->cdda_method = CDDA_OLD;
33949
33950- if (!cdo->generic_packet)
33951- cdo->generic_packet = cdrom_dummy_generic_packet;
33952+ if (!cdo->generic_packet) {
33953+ pax_open_kernel();
33954+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
33955+ pax_close_kernel();
33956+ }
33957
33958 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
33959 mutex_lock(&cdrom_mutex);
33960@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
33961 if (cdi->exit)
33962 cdi->exit(cdi);
33963
33964- cdi->ops->n_minors--;
33965 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
33966 }
33967
33968diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
33969index d59cdcb..11afddf 100644
33970--- a/drivers/cdrom/gdrom.c
33971+++ b/drivers/cdrom/gdrom.c
33972@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
33973 .audio_ioctl = gdrom_audio_ioctl,
33974 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
33975 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
33976- .n_minors = 1,
33977 };
33978
33979 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
33980diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
33981index 72bedad..8181ce1 100644
33982--- a/drivers/char/Kconfig
33983+++ b/drivers/char/Kconfig
33984@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
33985
33986 config DEVKMEM
33987 bool "/dev/kmem virtual device support"
33988- default y
33989+ default n
33990+ depends on !GRKERNSEC_KMEM
33991 help
33992 Say Y here if you want to support the /dev/kmem device. The
33993 /dev/kmem device is rarely used, but can be used for certain
33994@@ -581,6 +582,7 @@ config DEVPORT
33995 bool
33996 depends on !M68K
33997 depends on ISA || PCI
33998+ depends on !GRKERNSEC_KMEM
33999 default y
34000
34001 source "drivers/s390/char/Kconfig"
34002diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
34003index 2e04433..22afc64 100644
34004--- a/drivers/char/agp/frontend.c
34005+++ b/drivers/char/agp/frontend.c
34006@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
34007 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
34008 return -EFAULT;
34009
34010- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
34011+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
34012 return -EFAULT;
34013
34014 client = agp_find_client_by_pid(reserve.pid);
34015diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
34016index 21cb980..f15107c 100644
34017--- a/drivers/char/genrtc.c
34018+++ b/drivers/char/genrtc.c
34019@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
34020 switch (cmd) {
34021
34022 case RTC_PLL_GET:
34023+ memset(&pll, 0, sizeof(pll));
34024 if (get_rtc_pll(&pll))
34025 return -EINVAL;
34026 else
34027diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
34028index fe6d4be..89f32100 100644
34029--- a/drivers/char/hpet.c
34030+++ b/drivers/char/hpet.c
34031@@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
34032 }
34033
34034 static int
34035-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
34036+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
34037 struct hpet_info *info)
34038 {
34039 struct hpet_timer __iomem *timer;
34040diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
34041index 053201b0..8335cce 100644
34042--- a/drivers/char/ipmi/ipmi_msghandler.c
34043+++ b/drivers/char/ipmi/ipmi_msghandler.c
34044@@ -420,7 +420,7 @@ struct ipmi_smi {
34045 struct proc_dir_entry *proc_dir;
34046 char proc_dir_name[10];
34047
34048- atomic_t stats[IPMI_NUM_STATS];
34049+ atomic_unchecked_t stats[IPMI_NUM_STATS];
34050
34051 /*
34052 * run_to_completion duplicate of smb_info, smi_info
34053@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
34054
34055
34056 #define ipmi_inc_stat(intf, stat) \
34057- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
34058+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
34059 #define ipmi_get_stat(intf, stat) \
34060- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
34061+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
34062
34063 static int is_lan_addr(struct ipmi_addr *addr)
34064 {
34065@@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
34066 INIT_LIST_HEAD(&intf->cmd_rcvrs);
34067 init_waitqueue_head(&intf->waitq);
34068 for (i = 0; i < IPMI_NUM_STATS; i++)
34069- atomic_set(&intf->stats[i], 0);
34070+ atomic_set_unchecked(&intf->stats[i], 0);
34071
34072 intf->proc_dir = NULL;
34073
34074diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
34075index 1c7fdcd..4899100 100644
34076--- a/drivers/char/ipmi/ipmi_si_intf.c
34077+++ b/drivers/char/ipmi/ipmi_si_intf.c
34078@@ -275,7 +275,7 @@ struct smi_info {
34079 unsigned char slave_addr;
34080
34081 /* Counters and things for the proc filesystem. */
34082- atomic_t stats[SI_NUM_STATS];
34083+ atomic_unchecked_t stats[SI_NUM_STATS];
34084
34085 struct task_struct *thread;
34086
34087@@ -284,9 +284,9 @@ struct smi_info {
34088 };
34089
34090 #define smi_inc_stat(smi, stat) \
34091- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
34092+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
34093 #define smi_get_stat(smi, stat) \
34094- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
34095+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
34096
34097 #define SI_MAX_PARMS 4
34098
34099@@ -3225,7 +3225,7 @@ static int try_smi_init(struct smi_info *new_smi)
34100 atomic_set(&new_smi->req_events, 0);
34101 new_smi->run_to_completion = 0;
34102 for (i = 0; i < SI_NUM_STATS; i++)
34103- atomic_set(&new_smi->stats[i], 0);
34104+ atomic_set_unchecked(&new_smi->stats[i], 0);
34105
34106 new_smi->interrupt_disabled = 1;
34107 atomic_set(&new_smi->stop_operation, 0);
34108diff --git a/drivers/char/mem.c b/drivers/char/mem.c
34109index c6fa3bc..4ca3e42 100644
34110--- a/drivers/char/mem.c
34111+++ b/drivers/char/mem.c
34112@@ -18,6 +18,7 @@
34113 #include <linux/raw.h>
34114 #include <linux/tty.h>
34115 #include <linux/capability.h>
34116+#include <linux/security.h>
34117 #include <linux/ptrace.h>
34118 #include <linux/device.h>
34119 #include <linux/highmem.h>
34120@@ -37,6 +38,10 @@
34121
34122 #define DEVPORT_MINOR 4
34123
34124+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
34125+extern const struct file_operations grsec_fops;
34126+#endif
34127+
34128 static inline unsigned long size_inside_page(unsigned long start,
34129 unsigned long size)
34130 {
34131@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34132
34133 while (cursor < to) {
34134 if (!devmem_is_allowed(pfn)) {
34135+#ifdef CONFIG_GRKERNSEC_KMEM
34136+ gr_handle_mem_readwrite(from, to);
34137+#else
34138 printk(KERN_INFO
34139 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
34140 current->comm, from, to);
34141+#endif
34142 return 0;
34143 }
34144 cursor += PAGE_SIZE;
34145@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34146 }
34147 return 1;
34148 }
34149+#elif defined(CONFIG_GRKERNSEC_KMEM)
34150+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34151+{
34152+ return 0;
34153+}
34154 #else
34155 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34156 {
34157@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
34158
34159 while (count > 0) {
34160 unsigned long remaining;
34161+ char *temp;
34162
34163 sz = size_inside_page(p, count);
34164
34165@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
34166 if (!ptr)
34167 return -EFAULT;
34168
34169- remaining = copy_to_user(buf, ptr, sz);
34170+#ifdef CONFIG_PAX_USERCOPY
34171+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
34172+ if (!temp) {
34173+ unxlate_dev_mem_ptr(p, ptr);
34174+ return -ENOMEM;
34175+ }
34176+ memcpy(temp, ptr, sz);
34177+#else
34178+ temp = ptr;
34179+#endif
34180+
34181+ remaining = copy_to_user(buf, temp, sz);
34182+
34183+#ifdef CONFIG_PAX_USERCOPY
34184+ kfree(temp);
34185+#endif
34186+
34187 unxlate_dev_mem_ptr(p, ptr);
34188 if (remaining)
34189 return -EFAULT;
34190@@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
34191 size_t count, loff_t *ppos)
34192 {
34193 unsigned long p = *ppos;
34194- ssize_t low_count, read, sz;
34195+ ssize_t low_count, read, sz, err = 0;
34196 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
34197- int err = 0;
34198
34199 read = 0;
34200 if (p < (unsigned long) high_memory) {
34201@@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
34202 }
34203 #endif
34204 while (low_count > 0) {
34205+ char *temp;
34206+
34207 sz = size_inside_page(p, low_count);
34208
34209 /*
34210@@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
34211 */
34212 kbuf = xlate_dev_kmem_ptr((char *)p);
34213
34214- if (copy_to_user(buf, kbuf, sz))
34215+#ifdef CONFIG_PAX_USERCOPY
34216+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
34217+ if (!temp)
34218+ return -ENOMEM;
34219+ memcpy(temp, kbuf, sz);
34220+#else
34221+ temp = kbuf;
34222+#endif
34223+
34224+ err = copy_to_user(buf, temp, sz);
34225+
34226+#ifdef CONFIG_PAX_USERCOPY
34227+ kfree(temp);
34228+#endif
34229+
34230+ if (err)
34231 return -EFAULT;
34232 buf += sz;
34233 p += sz;
34234@@ -833,6 +880,9 @@ static const struct memdev {
34235 #ifdef CONFIG_CRASH_DUMP
34236 [12] = { "oldmem", 0, &oldmem_fops, NULL },
34237 #endif
34238+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
34239+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
34240+#endif
34241 };
34242
34243 static int memory_open(struct inode *inode, struct file *filp)
34244diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
34245index 9df78e2..01ba9ae 100644
34246--- a/drivers/char/nvram.c
34247+++ b/drivers/char/nvram.c
34248@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
34249
34250 spin_unlock_irq(&rtc_lock);
34251
34252- if (copy_to_user(buf, contents, tmp - contents))
34253+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
34254 return -EFAULT;
34255
34256 *ppos = i;
34257diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
34258index b66eaa0..2619d1b 100644
34259--- a/drivers/char/pcmcia/synclink_cs.c
34260+++ b/drivers/char/pcmcia/synclink_cs.c
34261@@ -2348,9 +2348,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
34262
34263 if (debug_level >= DEBUG_LEVEL_INFO)
34264 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
34265- __FILE__,__LINE__, info->device_name, port->count);
34266+ __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
34267
34268- WARN_ON(!port->count);
34269+ WARN_ON(!atomic_read(&port->count));
34270
34271 if (tty_port_close_start(port, tty, filp) == 0)
34272 goto cleanup;
34273@@ -2368,7 +2368,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
34274 cleanup:
34275 if (debug_level >= DEBUG_LEVEL_INFO)
34276 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
34277- tty->driver->name, port->count);
34278+ tty->driver->name, atomic_read(&port->count));
34279 }
34280
34281 /* Wait until the transmitter is empty.
34282@@ -2510,7 +2510,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
34283
34284 if (debug_level >= DEBUG_LEVEL_INFO)
34285 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
34286- __FILE__,__LINE__,tty->driver->name, port->count);
34287+ __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
34288
34289 /* If port is closing, signal caller to try again */
34290 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
34291@@ -2530,11 +2530,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
34292 goto cleanup;
34293 }
34294 spin_lock(&port->lock);
34295- port->count++;
34296+ atomic_inc(&port->count);
34297 spin_unlock(&port->lock);
34298 spin_unlock_irqrestore(&info->netlock, flags);
34299
34300- if (port->count == 1) {
34301+ if (atomic_read(&port->count) == 1) {
34302 /* 1st open on this device, init hardware */
34303 retval = startup(info, tty);
34304 if (retval < 0)
34305@@ -3889,7 +3889,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
34306 unsigned short new_crctype;
34307
34308 /* return error if TTY interface open */
34309- if (info->port.count)
34310+ if (atomic_read(&info->port.count))
34311 return -EBUSY;
34312
34313 switch (encoding)
34314@@ -3992,7 +3992,7 @@ static int hdlcdev_open(struct net_device *dev)
34315
34316 /* arbitrate between network and tty opens */
34317 spin_lock_irqsave(&info->netlock, flags);
34318- if (info->port.count != 0 || info->netcount != 0) {
34319+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
34320 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
34321 spin_unlock_irqrestore(&info->netlock, flags);
34322 return -EBUSY;
34323@@ -4081,7 +4081,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
34324 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
34325
34326 /* return error if TTY interface open */
34327- if (info->port.count)
34328+ if (atomic_read(&info->port.count))
34329 return -EBUSY;
34330
34331 if (cmd != SIOCWANDEV)
34332diff --git a/drivers/char/random.c b/drivers/char/random.c
34333index 57d4b15..253207b 100644
34334--- a/drivers/char/random.c
34335+++ b/drivers/char/random.c
34336@@ -272,8 +272,13 @@
34337 /*
34338 * Configuration information
34339 */
34340+#ifdef CONFIG_GRKERNSEC_RANDNET
34341+#define INPUT_POOL_WORDS 512
34342+#define OUTPUT_POOL_WORDS 128
34343+#else
34344 #define INPUT_POOL_WORDS 128
34345 #define OUTPUT_POOL_WORDS 32
34346+#endif
34347 #define SEC_XFER_SIZE 512
34348 #define EXTRACT_SIZE 10
34349
34350@@ -313,10 +318,17 @@ static struct poolinfo {
34351 int poolwords;
34352 int tap1, tap2, tap3, tap4, tap5;
34353 } poolinfo_table[] = {
34354+#ifdef CONFIG_GRKERNSEC_RANDNET
34355+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
34356+ { 512, 411, 308, 208, 104, 1 },
34357+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
34358+ { 128, 103, 76, 51, 25, 1 },
34359+#else
34360 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
34361 { 128, 103, 76, 51, 25, 1 },
34362 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
34363 { 32, 26, 20, 14, 7, 1 },
34364+#endif
34365 #if 0
34366 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
34367 { 2048, 1638, 1231, 819, 411, 1 },
34368@@ -524,8 +536,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
34369 input_rotate += i ? 7 : 14;
34370 }
34371
34372- ACCESS_ONCE(r->input_rotate) = input_rotate;
34373- ACCESS_ONCE(r->add_ptr) = i;
34374+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
34375+ ACCESS_ONCE_RW(r->add_ptr) = i;
34376 smp_wmb();
34377
34378 if (out)
34379@@ -1024,7 +1036,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
34380
34381 extract_buf(r, tmp);
34382 i = min_t(int, nbytes, EXTRACT_SIZE);
34383- if (copy_to_user(buf, tmp, i)) {
34384+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
34385 ret = -EFAULT;
34386 break;
34387 }
34388@@ -1360,7 +1372,7 @@ EXPORT_SYMBOL(generate_random_uuid);
34389 #include <linux/sysctl.h>
34390
34391 static int min_read_thresh = 8, min_write_thresh;
34392-static int max_read_thresh = INPUT_POOL_WORDS * 32;
34393+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
34394 static int max_write_thresh = INPUT_POOL_WORDS * 32;
34395 static char sysctl_bootid[16];
34396
34397@@ -1376,7 +1388,7 @@ static char sysctl_bootid[16];
34398 static int proc_do_uuid(ctl_table *table, int write,
34399 void __user *buffer, size_t *lenp, loff_t *ppos)
34400 {
34401- ctl_table fake_table;
34402+ ctl_table_no_const fake_table;
34403 unsigned char buf[64], tmp_uuid[16], *uuid;
34404
34405 uuid = table->data;
34406diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
34407index d780295..b29f3a8 100644
34408--- a/drivers/char/sonypi.c
34409+++ b/drivers/char/sonypi.c
34410@@ -54,6 +54,7 @@
34411
34412 #include <asm/uaccess.h>
34413 #include <asm/io.h>
34414+#include <asm/local.h>
34415
34416 #include <linux/sonypi.h>
34417
34418@@ -490,7 +491,7 @@ static struct sonypi_device {
34419 spinlock_t fifo_lock;
34420 wait_queue_head_t fifo_proc_list;
34421 struct fasync_struct *fifo_async;
34422- int open_count;
34423+ local_t open_count;
34424 int model;
34425 struct input_dev *input_jog_dev;
34426 struct input_dev *input_key_dev;
34427@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
34428 static int sonypi_misc_release(struct inode *inode, struct file *file)
34429 {
34430 mutex_lock(&sonypi_device.lock);
34431- sonypi_device.open_count--;
34432+ local_dec(&sonypi_device.open_count);
34433 mutex_unlock(&sonypi_device.lock);
34434 return 0;
34435 }
34436@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
34437 {
34438 mutex_lock(&sonypi_device.lock);
34439 /* Flush input queue on first open */
34440- if (!sonypi_device.open_count)
34441+ if (!local_read(&sonypi_device.open_count))
34442 kfifo_reset(&sonypi_device.fifo);
34443- sonypi_device.open_count++;
34444+ local_inc(&sonypi_device.open_count);
34445 mutex_unlock(&sonypi_device.lock);
34446
34447 return 0;
34448diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
34449index 93211df..c7805f7 100644
34450--- a/drivers/char/tpm/tpm.c
34451+++ b/drivers/char/tpm/tpm.c
34452@@ -410,7 +410,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
34453 chip->vendor.req_complete_val)
34454 goto out_recv;
34455
34456- if ((status == chip->vendor.req_canceled)) {
34457+ if (status == chip->vendor.req_canceled) {
34458 dev_err(chip->dev, "Operation Canceled\n");
34459 rc = -ECANCELED;
34460 goto out;
34461diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
34462index 56051d0..11cf3b7 100644
34463--- a/drivers/char/tpm/tpm_acpi.c
34464+++ b/drivers/char/tpm/tpm_acpi.c
34465@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
34466 virt = acpi_os_map_memory(start, len);
34467 if (!virt) {
34468 kfree(log->bios_event_log);
34469+ log->bios_event_log = NULL;
34470 printk("%s: ERROR - Unable to map memory\n", __func__);
34471 return -EIO;
34472 }
34473
34474- memcpy_fromio(log->bios_event_log, virt, len);
34475+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
34476
34477 acpi_os_unmap_memory(virt, len);
34478 return 0;
34479diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
34480index 84ddc55..1d32f1e 100644
34481--- a/drivers/char/tpm/tpm_eventlog.c
34482+++ b/drivers/char/tpm/tpm_eventlog.c
34483@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
34484 event = addr;
34485
34486 if ((event->event_type == 0 && event->event_size == 0) ||
34487- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
34488+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
34489 return NULL;
34490
34491 return addr;
34492@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
34493 return NULL;
34494
34495 if ((event->event_type == 0 && event->event_size == 0) ||
34496- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
34497+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
34498 return NULL;
34499
34500 (*pos)++;
34501@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
34502 int i;
34503
34504 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
34505- seq_putc(m, data[i]);
34506+ if (!seq_putc(m, data[i]))
34507+ return -EFAULT;
34508
34509 return 0;
34510 }
34511diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
34512index a4b7aa0..2faa0bc 100644
34513--- a/drivers/char/virtio_console.c
34514+++ b/drivers/char/virtio_console.c
34515@@ -685,7 +685,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
34516 if (to_user) {
34517 ssize_t ret;
34518
34519- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
34520+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
34521 if (ret)
34522 return -EFAULT;
34523 } else {
34524@@ -784,7 +784,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
34525 if (!port_has_data(port) && !port->host_connected)
34526 return 0;
34527
34528- return fill_readbuf(port, ubuf, count, true);
34529+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
34530 }
34531
34532 static int wait_port_writable(struct port *port, bool nonblock)
34533diff --git a/drivers/clocksource/arm_generic.c b/drivers/clocksource/arm_generic.c
34534index 8ae1a61..9c00613 100644
34535--- a/drivers/clocksource/arm_generic.c
34536+++ b/drivers/clocksource/arm_generic.c
34537@@ -181,7 +181,7 @@ static int __cpuinit arch_timer_cpu_notify(struct notifier_block *self,
34538 return NOTIFY_OK;
34539 }
34540
34541-static struct notifier_block __cpuinitdata arch_timer_cpu_nb = {
34542+static struct notifier_block arch_timer_cpu_nb = {
34543 .notifier_call = arch_timer_cpu_notify,
34544 };
34545
34546diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
34547index 7b0d49d..134fac9 100644
34548--- a/drivers/cpufreq/acpi-cpufreq.c
34549+++ b/drivers/cpufreq/acpi-cpufreq.c
34550@@ -172,7 +172,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
34551 return sprintf(buf, "%u\n", boost_enabled);
34552 }
34553
34554-static struct global_attr global_boost = __ATTR(boost, 0644,
34555+static global_attr_no_const global_boost = __ATTR(boost, 0644,
34556 show_global_boost,
34557 store_global_boost);
34558
34559@@ -712,8 +712,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34560 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
34561 per_cpu(acfreq_data, cpu) = data;
34562
34563- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
34564- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
34565+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
34566+ pax_open_kernel();
34567+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
34568+ pax_close_kernel();
34569+ }
34570
34571 result = acpi_processor_register_performance(data->acpi_data, cpu);
34572 if (result)
34573@@ -835,7 +838,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34574 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
34575 break;
34576 case ACPI_ADR_SPACE_FIXED_HARDWARE:
34577- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
34578+ pax_open_kernel();
34579+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
34580+ pax_close_kernel();
34581 policy->cur = get_cur_freq_on_cpu(cpu);
34582 break;
34583 default:
34584@@ -846,8 +851,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34585 acpi_processor_notify_smm(THIS_MODULE);
34586
34587 /* Check for APERF/MPERF support in hardware */
34588- if (boot_cpu_has(X86_FEATURE_APERFMPERF))
34589- acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
34590+ if (boot_cpu_has(X86_FEATURE_APERFMPERF)) {
34591+ pax_open_kernel();
34592+ *(void **)&acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
34593+ pax_close_kernel();
34594+ }
34595
34596 pr_debug("CPU%u - ACPI performance management activated.\n", cpu);
34597 for (i = 0; i < perf->state_count; i++)
34598diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
34599index 1f93dbd..305cef1 100644
34600--- a/drivers/cpufreq/cpufreq.c
34601+++ b/drivers/cpufreq/cpufreq.c
34602@@ -1843,7 +1843,7 @@ static int __cpuinit cpufreq_cpu_callback(struct notifier_block *nfb,
34603 return NOTIFY_OK;
34604 }
34605
34606-static struct notifier_block __refdata cpufreq_cpu_notifier = {
34607+static struct notifier_block cpufreq_cpu_notifier = {
34608 .notifier_call = cpufreq_cpu_callback,
34609 };
34610
34611@@ -1875,8 +1875,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
34612
34613 pr_debug("trying to register driver %s\n", driver_data->name);
34614
34615- if (driver_data->setpolicy)
34616- driver_data->flags |= CPUFREQ_CONST_LOOPS;
34617+ if (driver_data->setpolicy) {
34618+ pax_open_kernel();
34619+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
34620+ pax_close_kernel();
34621+ }
34622
34623 spin_lock_irqsave(&cpufreq_driver_lock, flags);
34624 if (cpufreq_driver) {
34625diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
34626index 6c5f1d3..c7e2f35e 100644
34627--- a/drivers/cpufreq/cpufreq_governor.c
34628+++ b/drivers/cpufreq/cpufreq_governor.c
34629@@ -243,7 +243,7 @@ int cpufreq_governor_dbs(struct dbs_data *dbs_data,
34630 * governor, thus we are bound to jiffes/HZ
34631 */
34632 if (dbs_data->governor == GOV_CONSERVATIVE) {
34633- struct cs_ops *ops = dbs_data->gov_ops;
34634+ const struct cs_ops *ops = dbs_data->gov_ops;
34635
34636 cpufreq_register_notifier(ops->notifier_block,
34637 CPUFREQ_TRANSITION_NOTIFIER);
34638@@ -251,7 +251,7 @@ int cpufreq_governor_dbs(struct dbs_data *dbs_data,
34639 dbs_data->min_sampling_rate = MIN_SAMPLING_RATE_RATIO *
34640 jiffies_to_usecs(10);
34641 } else {
34642- struct od_ops *ops = dbs_data->gov_ops;
34643+ const struct od_ops *ops = dbs_data->gov_ops;
34644
34645 od_tuners->io_is_busy = ops->io_busy();
34646 }
34647@@ -268,7 +268,7 @@ second_time:
34648 cs_dbs_info->enable = 1;
34649 cs_dbs_info->requested_freq = policy->cur;
34650 } else {
34651- struct od_ops *ops = dbs_data->gov_ops;
34652+ const struct od_ops *ops = dbs_data->gov_ops;
34653 od_dbs_info->rate_mult = 1;
34654 od_dbs_info->sample_type = OD_NORMAL_SAMPLE;
34655 ops->powersave_bias_init_cpu(cpu);
34656@@ -289,7 +289,7 @@ second_time:
34657 mutex_destroy(&cpu_cdbs->timer_mutex);
34658 dbs_data->enable--;
34659 if (!dbs_data->enable) {
34660- struct cs_ops *ops = dbs_data->gov_ops;
34661+ const struct cs_ops *ops = dbs_data->gov_ops;
34662
34663 sysfs_remove_group(cpufreq_global_kobject,
34664 dbs_data->attr_group);
34665diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
34666index f661654..6c8e638 100644
34667--- a/drivers/cpufreq/cpufreq_governor.h
34668+++ b/drivers/cpufreq/cpufreq_governor.h
34669@@ -142,7 +142,7 @@ struct dbs_data {
34670 void (*gov_check_cpu)(int cpu, unsigned int load);
34671
34672 /* Governor specific ops, see below */
34673- void *gov_ops;
34674+ const void *gov_ops;
34675 };
34676
34677 /* Governor specific ops, will be passed to dbs_data->gov_ops */
34678diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
34679index 9d7732b..0b1a793 100644
34680--- a/drivers/cpufreq/cpufreq_stats.c
34681+++ b/drivers/cpufreq/cpufreq_stats.c
34682@@ -340,7 +340,7 @@ static int __cpuinit cpufreq_stat_cpu_callback(struct notifier_block *nfb,
34683 }
34684
34685 /* priority=1 so this will get called before cpufreq_remove_dev */
34686-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
34687+static struct notifier_block cpufreq_stat_cpu_notifier = {
34688 .notifier_call = cpufreq_stat_cpu_callback,
34689 .priority = 1,
34690 };
34691diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
34692index 827629c9..0bc6a03 100644
34693--- a/drivers/cpufreq/p4-clockmod.c
34694+++ b/drivers/cpufreq/p4-clockmod.c
34695@@ -167,10 +167,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
34696 case 0x0F: /* Core Duo */
34697 case 0x16: /* Celeron Core */
34698 case 0x1C: /* Atom */
34699- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34700+ pax_open_kernel();
34701+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34702+ pax_close_kernel();
34703 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
34704 case 0x0D: /* Pentium M (Dothan) */
34705- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34706+ pax_open_kernel();
34707+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34708+ pax_close_kernel();
34709 /* fall through */
34710 case 0x09: /* Pentium M (Banias) */
34711 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
34712@@ -182,7 +186,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
34713
34714 /* on P-4s, the TSC runs with constant frequency independent whether
34715 * throttling is active or not. */
34716- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34717+ pax_open_kernel();
34718+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34719+ pax_close_kernel();
34720
34721 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
34722 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
34723diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
34724index 3a953d5..f5993f6 100644
34725--- a/drivers/cpufreq/speedstep-centrino.c
34726+++ b/drivers/cpufreq/speedstep-centrino.c
34727@@ -353,8 +353,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
34728 !cpu_has(cpu, X86_FEATURE_EST))
34729 return -ENODEV;
34730
34731- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
34732- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
34733+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
34734+ pax_open_kernel();
34735+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
34736+ pax_close_kernel();
34737+ }
34738
34739 if (policy->cpu != 0)
34740 return -ENODEV;
34741diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
34742index e1f6860..f8de20b 100644
34743--- a/drivers/cpuidle/cpuidle.c
34744+++ b/drivers/cpuidle/cpuidle.c
34745@@ -279,7 +279,7 @@ static int poll_idle(struct cpuidle_device *dev,
34746
34747 static void poll_idle_init(struct cpuidle_driver *drv)
34748 {
34749- struct cpuidle_state *state = &drv->states[0];
34750+ cpuidle_state_no_const *state = &drv->states[0];
34751
34752 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
34753 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
34754diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
34755index ea2f8e7..70ac501 100644
34756--- a/drivers/cpuidle/governor.c
34757+++ b/drivers/cpuidle/governor.c
34758@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
34759 mutex_lock(&cpuidle_lock);
34760 if (__cpuidle_find_governor(gov->name) == NULL) {
34761 ret = 0;
34762- list_add_tail(&gov->governor_list, &cpuidle_governors);
34763+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
34764 if (!cpuidle_curr_governor ||
34765 cpuidle_curr_governor->rating < gov->rating)
34766 cpuidle_switch_governor(gov);
34767@@ -135,7 +135,7 @@ void cpuidle_unregister_governor(struct cpuidle_governor *gov)
34768 new_gov = cpuidle_replace_governor(gov->rating);
34769 cpuidle_switch_governor(new_gov);
34770 }
34771- list_del(&gov->governor_list);
34772+ pax_list_del((struct list_head *)&gov->governor_list);
34773 mutex_unlock(&cpuidle_lock);
34774 }
34775
34776diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
34777index 428754a..8bdf9cc 100644
34778--- a/drivers/cpuidle/sysfs.c
34779+++ b/drivers/cpuidle/sysfs.c
34780@@ -131,7 +131,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
34781 NULL
34782 };
34783
34784-static struct attribute_group cpuidle_attr_group = {
34785+static attribute_group_no_const cpuidle_attr_group = {
34786 .attrs = cpuidle_default_attrs,
34787 .name = "cpuidle",
34788 };
34789diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
34790index 3b36797..289c16a 100644
34791--- a/drivers/devfreq/devfreq.c
34792+++ b/drivers/devfreq/devfreq.c
34793@@ -588,7 +588,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
34794 goto err_out;
34795 }
34796
34797- list_add(&governor->node, &devfreq_governor_list);
34798+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
34799
34800 list_for_each_entry(devfreq, &devfreq_list, node) {
34801 int ret = 0;
34802@@ -676,7 +676,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
34803 }
34804 }
34805
34806- list_del(&governor->node);
34807+ pax_list_del((struct list_head *)&governor->node);
34808 err_out:
34809 mutex_unlock(&devfreq_list_lock);
34810
34811diff --git a/drivers/dma/sh/shdma.c b/drivers/dma/sh/shdma.c
34812index b70709b..1d8d02a 100644
34813--- a/drivers/dma/sh/shdma.c
34814+++ b/drivers/dma/sh/shdma.c
34815@@ -476,7 +476,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
34816 return ret;
34817 }
34818
34819-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
34820+static struct notifier_block sh_dmae_nmi_notifier = {
34821 .notifier_call = sh_dmae_nmi_handler,
34822
34823 /* Run before NMI debug handler and KGDB */
34824diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
34825index 0ca1ca7..6e6f454 100644
34826--- a/drivers/edac/edac_mc_sysfs.c
34827+++ b/drivers/edac/edac_mc_sysfs.c
34828@@ -148,7 +148,7 @@ static const char *edac_caps[] = {
34829 struct dev_ch_attribute {
34830 struct device_attribute attr;
34831 int channel;
34832-};
34833+} __do_const;
34834
34835 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
34836 struct dev_ch_attribute dev_attr_legacy_##_name = \
34837diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
34838index 0056c4d..23b54d9 100644
34839--- a/drivers/edac/edac_pci_sysfs.c
34840+++ b/drivers/edac/edac_pci_sysfs.c
34841@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
34842 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
34843 static int edac_pci_poll_msec = 1000; /* one second workq period */
34844
34845-static atomic_t pci_parity_count = ATOMIC_INIT(0);
34846-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
34847+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
34848+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
34849
34850 static struct kobject *edac_pci_top_main_kobj;
34851 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
34852@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
34853 void *value;
34854 ssize_t(*show) (void *, char *);
34855 ssize_t(*store) (void *, const char *, size_t);
34856-};
34857+} __do_const;
34858
34859 /* Set of show/store abstract level functions for PCI Parity object */
34860 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
34861@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34862 edac_printk(KERN_CRIT, EDAC_PCI,
34863 "Signaled System Error on %s\n",
34864 pci_name(dev));
34865- atomic_inc(&pci_nonparity_count);
34866+ atomic_inc_unchecked(&pci_nonparity_count);
34867 }
34868
34869 if (status & (PCI_STATUS_PARITY)) {
34870@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34871 "Master Data Parity Error on %s\n",
34872 pci_name(dev));
34873
34874- atomic_inc(&pci_parity_count);
34875+ atomic_inc_unchecked(&pci_parity_count);
34876 }
34877
34878 if (status & (PCI_STATUS_DETECTED_PARITY)) {
34879@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34880 "Detected Parity Error on %s\n",
34881 pci_name(dev));
34882
34883- atomic_inc(&pci_parity_count);
34884+ atomic_inc_unchecked(&pci_parity_count);
34885 }
34886 }
34887
34888@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34889 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
34890 "Signaled System Error on %s\n",
34891 pci_name(dev));
34892- atomic_inc(&pci_nonparity_count);
34893+ atomic_inc_unchecked(&pci_nonparity_count);
34894 }
34895
34896 if (status & (PCI_STATUS_PARITY)) {
34897@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34898 "Master Data Parity Error on "
34899 "%s\n", pci_name(dev));
34900
34901- atomic_inc(&pci_parity_count);
34902+ atomic_inc_unchecked(&pci_parity_count);
34903 }
34904
34905 if (status & (PCI_STATUS_DETECTED_PARITY)) {
34906@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34907 "Detected Parity Error on %s\n",
34908 pci_name(dev));
34909
34910- atomic_inc(&pci_parity_count);
34911+ atomic_inc_unchecked(&pci_parity_count);
34912 }
34913 }
34914 }
34915@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
34916 if (!check_pci_errors)
34917 return;
34918
34919- before_count = atomic_read(&pci_parity_count);
34920+ before_count = atomic_read_unchecked(&pci_parity_count);
34921
34922 /* scan all PCI devices looking for a Parity Error on devices and
34923 * bridges.
34924@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
34925 /* Only if operator has selected panic on PCI Error */
34926 if (edac_pci_get_panic_on_pe()) {
34927 /* If the count is different 'after' from 'before' */
34928- if (before_count != atomic_read(&pci_parity_count))
34929+ if (before_count != atomic_read_unchecked(&pci_parity_count))
34930 panic("EDAC: PCI Parity Error");
34931 }
34932 }
34933diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
34934index 6796799..99e8377 100644
34935--- a/drivers/edac/mce_amd.h
34936+++ b/drivers/edac/mce_amd.h
34937@@ -78,7 +78,7 @@ extern const char * const ii_msgs[];
34938 struct amd_decoder_ops {
34939 bool (*mc0_mce)(u16, u8);
34940 bool (*mc1_mce)(u16, u8);
34941-};
34942+} __no_const;
34943
34944 void amd_report_gart_errors(bool);
34945 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
34946diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
34947index 57ea7f4..789e3c3 100644
34948--- a/drivers/firewire/core-card.c
34949+++ b/drivers/firewire/core-card.c
34950@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
34951
34952 void fw_core_remove_card(struct fw_card *card)
34953 {
34954- struct fw_card_driver dummy_driver = dummy_driver_template;
34955+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
34956
34957 card->driver->update_phy_reg(card, 4,
34958 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
34959diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
34960index f8d2287..5aaf4db 100644
34961--- a/drivers/firewire/core-cdev.c
34962+++ b/drivers/firewire/core-cdev.c
34963@@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
34964 int ret;
34965
34966 if ((request->channels == 0 && request->bandwidth == 0) ||
34967- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
34968- request->bandwidth < 0)
34969+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
34970 return -EINVAL;
34971
34972 r = kmalloc(sizeof(*r), GFP_KERNEL);
34973diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
34974index af3e8aa..eb2f227 100644
34975--- a/drivers/firewire/core-device.c
34976+++ b/drivers/firewire/core-device.c
34977@@ -232,7 +232,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
34978 struct config_rom_attribute {
34979 struct device_attribute attr;
34980 u32 key;
34981-};
34982+} __do_const;
34983
34984 static ssize_t show_immediate(struct device *dev,
34985 struct device_attribute *dattr, char *buf)
34986diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
34987index 28a94c7..58da63a 100644
34988--- a/drivers/firewire/core-transaction.c
34989+++ b/drivers/firewire/core-transaction.c
34990@@ -38,6 +38,7 @@
34991 #include <linux/timer.h>
34992 #include <linux/types.h>
34993 #include <linux/workqueue.h>
34994+#include <linux/sched.h>
34995
34996 #include <asm/byteorder.h>
34997
34998diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
34999index 515a42c..5ecf3ba 100644
35000--- a/drivers/firewire/core.h
35001+++ b/drivers/firewire/core.h
35002@@ -111,6 +111,7 @@ struct fw_card_driver {
35003
35004 int (*stop_iso)(struct fw_iso_context *ctx);
35005 };
35006+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
35007
35008 void fw_card_initialize(struct fw_card *card,
35009 const struct fw_card_driver *driver, struct device *device);
35010diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
35011index 94a58a0..f5eba42 100644
35012--- a/drivers/firmware/dmi-id.c
35013+++ b/drivers/firmware/dmi-id.c
35014@@ -16,7 +16,7 @@
35015 struct dmi_device_attribute{
35016 struct device_attribute dev_attr;
35017 int field;
35018-};
35019+} __do_const;
35020 #define to_dmi_dev_attr(_dev_attr) \
35021 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
35022
35023diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
35024index 4cd392d..4b629e1 100644
35025--- a/drivers/firmware/dmi_scan.c
35026+++ b/drivers/firmware/dmi_scan.c
35027@@ -490,11 +490,6 @@ void __init dmi_scan_machine(void)
35028 }
35029 }
35030 else {
35031- /*
35032- * no iounmap() for that ioremap(); it would be a no-op, but
35033- * it's so early in setup that sucker gets confused into doing
35034- * what it shouldn't if we actually call it.
35035- */
35036 p = dmi_ioremap(0xF0000, 0x10000);
35037 if (p == NULL)
35038 goto error;
35039@@ -769,7 +764,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
35040 if (buf == NULL)
35041 return -1;
35042
35043- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
35044+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
35045
35046 iounmap(buf);
35047 return 0;
35048diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
35049index b07cb37..2a51037 100644
35050--- a/drivers/firmware/efivars.c
35051+++ b/drivers/firmware/efivars.c
35052@@ -138,7 +138,7 @@ struct efivar_attribute {
35053 };
35054
35055 static struct efivars __efivars;
35056-static struct efivar_operations ops;
35057+static efivar_operations_no_const ops __read_only;
35058
35059 #define PSTORE_EFI_ATTRIBUTES \
35060 (EFI_VARIABLE_NON_VOLATILE | \
35061@@ -1834,7 +1834,7 @@ efivar_create_sysfs_entry(struct efivars *efivars,
35062 static int
35063 create_efivars_bin_attributes(struct efivars *efivars)
35064 {
35065- struct bin_attribute *attr;
35066+ bin_attribute_no_const *attr;
35067 int error;
35068
35069 /* new_var */
35070diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
35071index 2a90ba6..07f3733 100644
35072--- a/drivers/firmware/google/memconsole.c
35073+++ b/drivers/firmware/google/memconsole.c
35074@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
35075 if (!found_memconsole())
35076 return -ENODEV;
35077
35078- memconsole_bin_attr.size = memconsole_length;
35079+ pax_open_kernel();
35080+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
35081+ pax_close_kernel();
35082
35083 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
35084
35085diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
35086index 6f2306d..af9476a 100644
35087--- a/drivers/gpio/gpio-ich.c
35088+++ b/drivers/gpio/gpio-ich.c
35089@@ -69,7 +69,7 @@ struct ichx_desc {
35090 /* Some chipsets have quirks, let these use their own request/get */
35091 int (*request)(struct gpio_chip *chip, unsigned offset);
35092 int (*get)(struct gpio_chip *chip, unsigned offset);
35093-};
35094+} __do_const;
35095
35096 static struct {
35097 spinlock_t lock;
35098diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
35099index 9902732..64b62dd 100644
35100--- a/drivers/gpio/gpio-vr41xx.c
35101+++ b/drivers/gpio/gpio-vr41xx.c
35102@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
35103 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
35104 maskl, pendl, maskh, pendh);
35105
35106- atomic_inc(&irq_err_count);
35107+ atomic_inc_unchecked(&irq_err_count);
35108
35109 return -EINVAL;
35110 }
35111diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
35112index 7b2d378..cc947ea 100644
35113--- a/drivers/gpu/drm/drm_crtc_helper.c
35114+++ b/drivers/gpu/drm/drm_crtc_helper.c
35115@@ -319,7 +319,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
35116 struct drm_crtc *tmp;
35117 int crtc_mask = 1;
35118
35119- WARN(!crtc, "checking null crtc?\n");
35120+ BUG_ON(!crtc);
35121
35122 dev = crtc->dev;
35123
35124diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
35125index be174ca..7f38143 100644
35126--- a/drivers/gpu/drm/drm_drv.c
35127+++ b/drivers/gpu/drm/drm_drv.c
35128@@ -307,7 +307,7 @@ module_exit(drm_core_exit);
35129 /**
35130 * Copy and IOCTL return string to user space
35131 */
35132-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
35133+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
35134 {
35135 int len;
35136
35137@@ -377,7 +377,7 @@ long drm_ioctl(struct file *filp,
35138 struct drm_file *file_priv = filp->private_data;
35139 struct drm_device *dev;
35140 struct drm_ioctl_desc *ioctl;
35141- drm_ioctl_t *func;
35142+ drm_ioctl_no_const_t func;
35143 unsigned int nr = DRM_IOCTL_NR(cmd);
35144 int retcode = -EINVAL;
35145 char stack_kdata[128];
35146@@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
35147 return -ENODEV;
35148
35149 atomic_inc(&dev->ioctl_count);
35150- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
35151+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
35152 ++file_priv->ioctl_count;
35153
35154 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
35155diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
35156index 32d7775..c8be5e1 100644
35157--- a/drivers/gpu/drm/drm_fops.c
35158+++ b/drivers/gpu/drm/drm_fops.c
35159@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
35160 }
35161
35162 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
35163- atomic_set(&dev->counts[i], 0);
35164+ atomic_set_unchecked(&dev->counts[i], 0);
35165
35166 dev->sigdata.lock = NULL;
35167
35168@@ -135,7 +135,7 @@ int drm_open(struct inode *inode, struct file *filp)
35169 if (drm_device_is_unplugged(dev))
35170 return -ENODEV;
35171
35172- if (!dev->open_count++)
35173+ if (local_inc_return(&dev->open_count) == 1)
35174 need_setup = 1;
35175 mutex_lock(&dev->struct_mutex);
35176 old_imapping = inode->i_mapping;
35177@@ -151,7 +151,7 @@ int drm_open(struct inode *inode, struct file *filp)
35178 retcode = drm_open_helper(inode, filp, dev);
35179 if (retcode)
35180 goto err_undo;
35181- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
35182+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
35183 if (need_setup) {
35184 retcode = drm_setup(dev);
35185 if (retcode)
35186@@ -166,7 +166,7 @@ err_undo:
35187 iput(container_of(dev->dev_mapping, struct inode, i_data));
35188 dev->dev_mapping = old_mapping;
35189 mutex_unlock(&dev->struct_mutex);
35190- dev->open_count--;
35191+ local_dec(&dev->open_count);
35192 return retcode;
35193 }
35194 EXPORT_SYMBOL(drm_open);
35195@@ -440,7 +440,7 @@ int drm_release(struct inode *inode, struct file *filp)
35196
35197 mutex_lock(&drm_global_mutex);
35198
35199- DRM_DEBUG("open_count = %d\n", dev->open_count);
35200+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
35201
35202 if (dev->driver->preclose)
35203 dev->driver->preclose(dev, file_priv);
35204@@ -449,10 +449,10 @@ int drm_release(struct inode *inode, struct file *filp)
35205 * Begin inline drm_release
35206 */
35207
35208- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
35209+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
35210 task_pid_nr(current),
35211 (long)old_encode_dev(file_priv->minor->device),
35212- dev->open_count);
35213+ local_read(&dev->open_count));
35214
35215 /* Release any auth tokens that might point to this file_priv,
35216 (do that under the drm_global_mutex) */
35217@@ -549,8 +549,8 @@ int drm_release(struct inode *inode, struct file *filp)
35218 * End inline drm_release
35219 */
35220
35221- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
35222- if (!--dev->open_count) {
35223+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
35224+ if (local_dec_and_test(&dev->open_count)) {
35225 if (atomic_read(&dev->ioctl_count)) {
35226 DRM_ERROR("Device busy: %d\n",
35227 atomic_read(&dev->ioctl_count));
35228diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
35229index f731116..629842c 100644
35230--- a/drivers/gpu/drm/drm_global.c
35231+++ b/drivers/gpu/drm/drm_global.c
35232@@ -36,7 +36,7 @@
35233 struct drm_global_item {
35234 struct mutex mutex;
35235 void *object;
35236- int refcount;
35237+ atomic_t refcount;
35238 };
35239
35240 static struct drm_global_item glob[DRM_GLOBAL_NUM];
35241@@ -49,7 +49,7 @@ void drm_global_init(void)
35242 struct drm_global_item *item = &glob[i];
35243 mutex_init(&item->mutex);
35244 item->object = NULL;
35245- item->refcount = 0;
35246+ atomic_set(&item->refcount, 0);
35247 }
35248 }
35249
35250@@ -59,7 +59,7 @@ void drm_global_release(void)
35251 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
35252 struct drm_global_item *item = &glob[i];
35253 BUG_ON(item->object != NULL);
35254- BUG_ON(item->refcount != 0);
35255+ BUG_ON(atomic_read(&item->refcount) != 0);
35256 }
35257 }
35258
35259@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
35260 void *object;
35261
35262 mutex_lock(&item->mutex);
35263- if (item->refcount == 0) {
35264+ if (atomic_read(&item->refcount) == 0) {
35265 item->object = kzalloc(ref->size, GFP_KERNEL);
35266 if (unlikely(item->object == NULL)) {
35267 ret = -ENOMEM;
35268@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
35269 goto out_err;
35270
35271 }
35272- ++item->refcount;
35273+ atomic_inc(&item->refcount);
35274 ref->object = item->object;
35275 object = item->object;
35276 mutex_unlock(&item->mutex);
35277@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
35278 struct drm_global_item *item = &glob[ref->global_type];
35279
35280 mutex_lock(&item->mutex);
35281- BUG_ON(item->refcount == 0);
35282+ BUG_ON(atomic_read(&item->refcount) == 0);
35283 BUG_ON(ref->object != item->object);
35284- if (--item->refcount == 0) {
35285+ if (atomic_dec_and_test(&item->refcount)) {
35286 ref->release(ref);
35287 item->object = NULL;
35288 }
35289diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
35290index d4b20ce..77a8d41 100644
35291--- a/drivers/gpu/drm/drm_info.c
35292+++ b/drivers/gpu/drm/drm_info.c
35293@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
35294 struct drm_local_map *map;
35295 struct drm_map_list *r_list;
35296
35297- /* Hardcoded from _DRM_FRAME_BUFFER,
35298- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
35299- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
35300- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
35301+ static const char * const types[] = {
35302+ [_DRM_FRAME_BUFFER] = "FB",
35303+ [_DRM_REGISTERS] = "REG",
35304+ [_DRM_SHM] = "SHM",
35305+ [_DRM_AGP] = "AGP",
35306+ [_DRM_SCATTER_GATHER] = "SG",
35307+ [_DRM_CONSISTENT] = "PCI",
35308+ [_DRM_GEM] = "GEM" };
35309 const char *type;
35310 int i;
35311
35312@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
35313 map = r_list->map;
35314 if (!map)
35315 continue;
35316- if (map->type < 0 || map->type > 5)
35317+ if (map->type >= ARRAY_SIZE(types))
35318 type = "??";
35319 else
35320 type = types[map->type];
35321@@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
35322 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
35323 vma->vm_flags & VM_LOCKED ? 'l' : '-',
35324 vma->vm_flags & VM_IO ? 'i' : '-',
35325+#ifdef CONFIG_GRKERNSEC_HIDESYM
35326+ 0);
35327+#else
35328 vma->vm_pgoff);
35329+#endif
35330
35331 #if defined(__i386__)
35332 pgprot = pgprot_val(vma->vm_page_prot);
35333diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
35334index 2f4c434..dd12cd2 100644
35335--- a/drivers/gpu/drm/drm_ioc32.c
35336+++ b/drivers/gpu/drm/drm_ioc32.c
35337@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
35338 request = compat_alloc_user_space(nbytes);
35339 if (!access_ok(VERIFY_WRITE, request, nbytes))
35340 return -EFAULT;
35341- list = (struct drm_buf_desc *) (request + 1);
35342+ list = (struct drm_buf_desc __user *) (request + 1);
35343
35344 if (__put_user(count, &request->count)
35345 || __put_user(list, &request->list))
35346@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
35347 request = compat_alloc_user_space(nbytes);
35348 if (!access_ok(VERIFY_WRITE, request, nbytes))
35349 return -EFAULT;
35350- list = (struct drm_buf_pub *) (request + 1);
35351+ list = (struct drm_buf_pub __user *) (request + 1);
35352
35353 if (__put_user(count, &request->count)
35354 || __put_user(list, &request->list))
35355@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
35356 return 0;
35357 }
35358
35359-drm_ioctl_compat_t *drm_compat_ioctls[] = {
35360+drm_ioctl_compat_t drm_compat_ioctls[] = {
35361 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
35362 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
35363 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
35364@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
35365 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35366 {
35367 unsigned int nr = DRM_IOCTL_NR(cmd);
35368- drm_ioctl_compat_t *fn;
35369 int ret;
35370
35371 /* Assume that ioctls without an explicit compat routine will just
35372@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35373 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
35374 return drm_ioctl(filp, cmd, arg);
35375
35376- fn = drm_compat_ioctls[nr];
35377-
35378- if (fn != NULL)
35379- ret = (*fn) (filp, cmd, arg);
35380+ if (drm_compat_ioctls[nr] != NULL)
35381+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
35382 else
35383 ret = drm_ioctl(filp, cmd, arg);
35384
35385diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
35386index e77bd8b..1571b85 100644
35387--- a/drivers/gpu/drm/drm_ioctl.c
35388+++ b/drivers/gpu/drm/drm_ioctl.c
35389@@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
35390 stats->data[i].value =
35391 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
35392 else
35393- stats->data[i].value = atomic_read(&dev->counts[i]);
35394+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
35395 stats->data[i].type = dev->types[i];
35396 }
35397
35398diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
35399index d752c96..fe08455 100644
35400--- a/drivers/gpu/drm/drm_lock.c
35401+++ b/drivers/gpu/drm/drm_lock.c
35402@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
35403 if (drm_lock_take(&master->lock, lock->context)) {
35404 master->lock.file_priv = file_priv;
35405 master->lock.lock_time = jiffies;
35406- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
35407+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
35408 break; /* Got lock */
35409 }
35410
35411@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
35412 return -EINVAL;
35413 }
35414
35415- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
35416+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
35417
35418 if (drm_lock_free(&master->lock, lock->context)) {
35419 /* FIXME: Should really bail out here. */
35420diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
35421index 200e104..59facda 100644
35422--- a/drivers/gpu/drm/drm_stub.c
35423+++ b/drivers/gpu/drm/drm_stub.c
35424@@ -516,7 +516,7 @@ void drm_unplug_dev(struct drm_device *dev)
35425
35426 drm_device_set_unplugged(dev);
35427
35428- if (dev->open_count == 0) {
35429+ if (local_read(&dev->open_count) == 0) {
35430 drm_put_dev(dev);
35431 }
35432 mutex_unlock(&drm_global_mutex);
35433diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
35434index 004ecdf..db1f6e0 100644
35435--- a/drivers/gpu/drm/i810/i810_dma.c
35436+++ b/drivers/gpu/drm/i810/i810_dma.c
35437@@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
35438 dma->buflist[vertex->idx],
35439 vertex->discard, vertex->used);
35440
35441- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
35442- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
35443+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
35444+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
35445 sarea_priv->last_enqueue = dev_priv->counter - 1;
35446 sarea_priv->last_dispatch = (int)hw_status[5];
35447
35448@@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
35449 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
35450 mc->last_render);
35451
35452- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
35453- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
35454+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
35455+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
35456 sarea_priv->last_enqueue = dev_priv->counter - 1;
35457 sarea_priv->last_dispatch = (int)hw_status[5];
35458
35459diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
35460index 6e0acad..93c8289 100644
35461--- a/drivers/gpu/drm/i810/i810_drv.h
35462+++ b/drivers/gpu/drm/i810/i810_drv.h
35463@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
35464 int page_flipping;
35465
35466 wait_queue_head_t irq_queue;
35467- atomic_t irq_received;
35468- atomic_t irq_emitted;
35469+ atomic_unchecked_t irq_received;
35470+ atomic_unchecked_t irq_emitted;
35471
35472 int front_offset;
35473 } drm_i810_private_t;
35474diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
35475index 261efc8e..27af8a5 100644
35476--- a/drivers/gpu/drm/i915/i915_debugfs.c
35477+++ b/drivers/gpu/drm/i915/i915_debugfs.c
35478@@ -496,7 +496,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
35479 I915_READ(GTIMR));
35480 }
35481 seq_printf(m, "Interrupts received: %d\n",
35482- atomic_read(&dev_priv->irq_received));
35483+ atomic_read_unchecked(&dev_priv->irq_received));
35484 for_each_ring(ring, dev_priv, i) {
35485 if (IS_GEN6(dev) || IS_GEN7(dev)) {
35486 seq_printf(m,
35487diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
35488index 99daa89..84ebd44 100644
35489--- a/drivers/gpu/drm/i915/i915_dma.c
35490+++ b/drivers/gpu/drm/i915/i915_dma.c
35491@@ -1253,7 +1253,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
35492 bool can_switch;
35493
35494 spin_lock(&dev->count_lock);
35495- can_switch = (dev->open_count == 0);
35496+ can_switch = (local_read(&dev->open_count) == 0);
35497 spin_unlock(&dev->count_lock);
35498 return can_switch;
35499 }
35500diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
35501index 7339a4b..445aaba 100644
35502--- a/drivers/gpu/drm/i915/i915_drv.h
35503+++ b/drivers/gpu/drm/i915/i915_drv.h
35504@@ -656,7 +656,7 @@ typedef struct drm_i915_private {
35505 drm_dma_handle_t *status_page_dmah;
35506 struct resource mch_res;
35507
35508- atomic_t irq_received;
35509+ atomic_unchecked_t irq_received;
35510
35511 /* protects the irq masks */
35512 spinlock_t irq_lock;
35513@@ -1102,7 +1102,7 @@ struct drm_i915_gem_object {
35514 * will be page flipped away on the next vblank. When it
35515 * reaches 0, dev_priv->pending_flip_queue will be woken up.
35516 */
35517- atomic_t pending_flip;
35518+ atomic_unchecked_t pending_flip;
35519 };
35520 #define to_gem_object(obj) (&((struct drm_i915_gem_object *)(obj))->base)
35521
35522@@ -1633,7 +1633,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
35523 struct drm_i915_private *dev_priv, unsigned port);
35524 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
35525 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
35526-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
35527+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
35528 {
35529 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
35530 }
35531diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35532index ba8805a..39d5330 100644
35533--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35534+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35535@@ -672,7 +672,7 @@ i915_gem_execbuffer_move_to_gpu(struct intel_ring_buffer *ring,
35536 i915_gem_clflush_object(obj);
35537
35538 if (obj->base.pending_write_domain)
35539- flips |= atomic_read(&obj->pending_flip);
35540+ flips |= atomic_read_unchecked(&obj->pending_flip);
35541
35542 flush_domains |= obj->base.write_domain;
35543 }
35544@@ -703,9 +703,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
35545
35546 static int
35547 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
35548- int count)
35549+ unsigned int count)
35550 {
35551- int i;
35552+ unsigned int i;
35553 int relocs_total = 0;
35554 int relocs_max = INT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
35555
35556@@ -1202,7 +1202,7 @@ i915_gem_execbuffer2(struct drm_device *dev, void *data,
35557 return -ENOMEM;
35558 }
35559 ret = copy_from_user(exec2_list,
35560- (struct drm_i915_relocation_entry __user *)
35561+ (struct drm_i915_gem_exec_object2 __user *)
35562 (uintptr_t) args->buffers_ptr,
35563 sizeof(*exec2_list) * args->buffer_count);
35564 if (ret != 0) {
35565diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
35566index 3c59584..500f2e9 100644
35567--- a/drivers/gpu/drm/i915/i915_ioc32.c
35568+++ b/drivers/gpu/drm/i915/i915_ioc32.c
35569@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
35570 (unsigned long)request);
35571 }
35572
35573-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
35574+static drm_ioctl_compat_t i915_compat_ioctls[] = {
35575 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
35576 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
35577 [DRM_I915_GETPARAM] = compat_i915_getparam,
35578@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
35579 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35580 {
35581 unsigned int nr = DRM_IOCTL_NR(cmd);
35582- drm_ioctl_compat_t *fn = NULL;
35583 int ret;
35584
35585 if (nr < DRM_COMMAND_BASE)
35586 return drm_compat_ioctl(filp, cmd, arg);
35587
35588- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
35589- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
35590-
35591- if (fn != NULL)
35592+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
35593+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
35594 ret = (*fn) (filp, cmd, arg);
35595- else
35596+ } else
35597 ret = drm_ioctl(filp, cmd, arg);
35598
35599 return ret;
35600diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
35601index fe84338..a863190 100644
35602--- a/drivers/gpu/drm/i915/i915_irq.c
35603+++ b/drivers/gpu/drm/i915/i915_irq.c
35604@@ -535,7 +535,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
35605 u32 pipe_stats[I915_MAX_PIPES];
35606 bool blc_event;
35607
35608- atomic_inc(&dev_priv->irq_received);
35609+ atomic_inc_unchecked(&dev_priv->irq_received);
35610
35611 while (true) {
35612 iir = I915_READ(VLV_IIR);
35613@@ -688,7 +688,7 @@ static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
35614 irqreturn_t ret = IRQ_NONE;
35615 int i;
35616
35617- atomic_inc(&dev_priv->irq_received);
35618+ atomic_inc_unchecked(&dev_priv->irq_received);
35619
35620 /* disable master interrupt before clearing iir */
35621 de_ier = I915_READ(DEIER);
35622@@ -760,7 +760,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
35623 int ret = IRQ_NONE;
35624 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
35625
35626- atomic_inc(&dev_priv->irq_received);
35627+ atomic_inc_unchecked(&dev_priv->irq_received);
35628
35629 /* disable master interrupt before clearing iir */
35630 de_ier = I915_READ(DEIER);
35631@@ -1787,7 +1787,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
35632 {
35633 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35634
35635- atomic_set(&dev_priv->irq_received, 0);
35636+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35637
35638 I915_WRITE(HWSTAM, 0xeffe);
35639
35640@@ -1813,7 +1813,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
35641 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35642 int pipe;
35643
35644- atomic_set(&dev_priv->irq_received, 0);
35645+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35646
35647 /* VLV magic */
35648 I915_WRITE(VLV_IMR, 0);
35649@@ -2108,7 +2108,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
35650 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35651 int pipe;
35652
35653- atomic_set(&dev_priv->irq_received, 0);
35654+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35655
35656 for_each_pipe(pipe)
35657 I915_WRITE(PIPESTAT(pipe), 0);
35658@@ -2159,7 +2159,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
35659 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
35660 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
35661
35662- atomic_inc(&dev_priv->irq_received);
35663+ atomic_inc_unchecked(&dev_priv->irq_received);
35664
35665 iir = I915_READ16(IIR);
35666 if (iir == 0)
35667@@ -2244,7 +2244,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
35668 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35669 int pipe;
35670
35671- atomic_set(&dev_priv->irq_received, 0);
35672+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35673
35674 if (I915_HAS_HOTPLUG(dev)) {
35675 I915_WRITE(PORT_HOTPLUG_EN, 0);
35676@@ -2339,7 +2339,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
35677 };
35678 int pipe, ret = IRQ_NONE;
35679
35680- atomic_inc(&dev_priv->irq_received);
35681+ atomic_inc_unchecked(&dev_priv->irq_received);
35682
35683 iir = I915_READ(IIR);
35684 do {
35685@@ -2465,7 +2465,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
35686 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35687 int pipe;
35688
35689- atomic_set(&dev_priv->irq_received, 0);
35690+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35691
35692 I915_WRITE(PORT_HOTPLUG_EN, 0);
35693 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
35694@@ -2572,7 +2572,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
35695 int irq_received;
35696 int ret = IRQ_NONE, pipe;
35697
35698- atomic_inc(&dev_priv->irq_received);
35699+ atomic_inc_unchecked(&dev_priv->irq_received);
35700
35701 iir = I915_READ(IIR);
35702
35703diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
35704index d3f834a..0ad1b37 100644
35705--- a/drivers/gpu/drm/i915/intel_display.c
35706+++ b/drivers/gpu/drm/i915/intel_display.c
35707@@ -2255,7 +2255,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
35708
35709 wait_event(dev_priv->pending_flip_queue,
35710 atomic_read(&dev_priv->mm.wedged) ||
35711- atomic_read(&obj->pending_flip) == 0);
35712+ atomic_read_unchecked(&obj->pending_flip) == 0);
35713
35714 /* Big Hammer, we also need to ensure that any pending
35715 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
35716@@ -7122,8 +7122,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
35717
35718 obj = work->old_fb_obj;
35719
35720- atomic_clear_mask(1 << intel_crtc->plane,
35721- &obj->pending_flip.counter);
35722+ atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
35723 wake_up(&dev_priv->pending_flip_queue);
35724
35725 queue_work(dev_priv->wq, &work->work);
35726@@ -7486,7 +7485,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
35727 /* Block clients from rendering to the new back buffer until
35728 * the flip occurs and the object is no longer visible.
35729 */
35730- atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
35731+ atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
35732 atomic_inc(&intel_crtc->unpin_work_count);
35733
35734 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
35735@@ -7504,7 +7503,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
35736 cleanup_pending:
35737 atomic_dec(&intel_crtc->unpin_work_count);
35738 crtc->fb = old_fb;
35739- atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
35740+ atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
35741 drm_gem_object_unreference(&work->old_fb_obj->base);
35742 drm_gem_object_unreference(&obj->base);
35743 mutex_unlock(&dev->struct_mutex);
35744@@ -8846,13 +8845,13 @@ struct intel_quirk {
35745 int subsystem_vendor;
35746 int subsystem_device;
35747 void (*hook)(struct drm_device *dev);
35748-};
35749+} __do_const;
35750
35751 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
35752 struct intel_dmi_quirk {
35753 void (*hook)(struct drm_device *dev);
35754 const struct dmi_system_id (*dmi_id_list)[];
35755-};
35756+} __do_const;
35757
35758 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
35759 {
35760@@ -8860,18 +8859,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
35761 return 1;
35762 }
35763
35764+static const struct dmi_system_id intel_dmi_quirks_table[] = {
35765+ {
35766+ .callback = intel_dmi_reverse_brightness,
35767+ .ident = "NCR Corporation",
35768+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
35769+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
35770+ },
35771+ },
35772+ { } /* terminating entry */
35773+};
35774+
35775 static const struct intel_dmi_quirk intel_dmi_quirks[] = {
35776 {
35777- .dmi_id_list = &(const struct dmi_system_id[]) {
35778- {
35779- .callback = intel_dmi_reverse_brightness,
35780- .ident = "NCR Corporation",
35781- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
35782- DMI_MATCH(DMI_PRODUCT_NAME, ""),
35783- },
35784- },
35785- { } /* terminating entry */
35786- },
35787+ .dmi_id_list = &intel_dmi_quirks_table,
35788 .hook = quirk_invert_brightness,
35789 },
35790 };
35791diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
35792index 54558a0..2d97005 100644
35793--- a/drivers/gpu/drm/mga/mga_drv.h
35794+++ b/drivers/gpu/drm/mga/mga_drv.h
35795@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
35796 u32 clear_cmd;
35797 u32 maccess;
35798
35799- atomic_t vbl_received; /**< Number of vblanks received. */
35800+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
35801 wait_queue_head_t fence_queue;
35802- atomic_t last_fence_retired;
35803+ atomic_unchecked_t last_fence_retired;
35804 u32 next_fence_to_post;
35805
35806 unsigned int fb_cpp;
35807diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
35808index 709e90d..89a1c0d 100644
35809--- a/drivers/gpu/drm/mga/mga_ioc32.c
35810+++ b/drivers/gpu/drm/mga/mga_ioc32.c
35811@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
35812 return 0;
35813 }
35814
35815-drm_ioctl_compat_t *mga_compat_ioctls[] = {
35816+drm_ioctl_compat_t mga_compat_ioctls[] = {
35817 [DRM_MGA_INIT] = compat_mga_init,
35818 [DRM_MGA_GETPARAM] = compat_mga_getparam,
35819 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
35820@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
35821 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35822 {
35823 unsigned int nr = DRM_IOCTL_NR(cmd);
35824- drm_ioctl_compat_t *fn = NULL;
35825 int ret;
35826
35827 if (nr < DRM_COMMAND_BASE)
35828 return drm_compat_ioctl(filp, cmd, arg);
35829
35830- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
35831- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
35832-
35833- if (fn != NULL)
35834+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
35835+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
35836 ret = (*fn) (filp, cmd, arg);
35837- else
35838+ } else
35839 ret = drm_ioctl(filp, cmd, arg);
35840
35841 return ret;
35842diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
35843index 598c281..60d590e 100644
35844--- a/drivers/gpu/drm/mga/mga_irq.c
35845+++ b/drivers/gpu/drm/mga/mga_irq.c
35846@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
35847 if (crtc != 0)
35848 return 0;
35849
35850- return atomic_read(&dev_priv->vbl_received);
35851+ return atomic_read_unchecked(&dev_priv->vbl_received);
35852 }
35853
35854
35855@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
35856 /* VBLANK interrupt */
35857 if (status & MGA_VLINEPEN) {
35858 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
35859- atomic_inc(&dev_priv->vbl_received);
35860+ atomic_inc_unchecked(&dev_priv->vbl_received);
35861 drm_handle_vblank(dev, 0);
35862 handled = 1;
35863 }
35864@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
35865 if ((prim_start & ~0x03) != (prim_end & ~0x03))
35866 MGA_WRITE(MGA_PRIMEND, prim_end);
35867
35868- atomic_inc(&dev_priv->last_fence_retired);
35869+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
35870 DRM_WAKEUP(&dev_priv->fence_queue);
35871 handled = 1;
35872 }
35873@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
35874 * using fences.
35875 */
35876 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
35877- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
35878+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
35879 - *sequence) <= (1 << 23)));
35880
35881 *sequence = cur_fence;
35882diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
35883index 865eddf..62c4cc3 100644
35884--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
35885+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
35886@@ -1015,7 +1015,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
35887 struct bit_table {
35888 const char id;
35889 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
35890-};
35891+} __no_const;
35892
35893 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
35894
35895diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
35896index aa89eb9..d45d38b 100644
35897--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
35898+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
35899@@ -80,7 +80,7 @@ struct nouveau_drm {
35900 struct drm_global_reference mem_global_ref;
35901 struct ttm_bo_global_ref bo_global_ref;
35902 struct ttm_bo_device bdev;
35903- atomic_t validate_sequence;
35904+ atomic_unchecked_t validate_sequence;
35905 int (*move)(struct nouveau_channel *,
35906 struct ttm_buffer_object *,
35907 struct ttm_mem_reg *, struct ttm_mem_reg *);
35908diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.h b/drivers/gpu/drm/nouveau/nouveau_fence.h
35909index cdb83ac..27f0a16 100644
35910--- a/drivers/gpu/drm/nouveau/nouveau_fence.h
35911+++ b/drivers/gpu/drm/nouveau/nouveau_fence.h
35912@@ -43,7 +43,7 @@ struct nouveau_fence_priv {
35913 int (*sync)(struct nouveau_fence *, struct nouveau_channel *,
35914 struct nouveau_channel *);
35915 u32 (*read)(struct nouveau_channel *);
35916-};
35917+} __no_const;
35918
35919 #define nouveau_fence(drm) ((struct nouveau_fence_priv *)(drm)->fence)
35920
35921diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
35922index 8bf695c..9fbc90a 100644
35923--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
35924+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
35925@@ -321,7 +321,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
35926 int trycnt = 0;
35927 int ret, i;
35928
35929- sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
35930+ sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
35931 retry:
35932 if (++trycnt > 100000) {
35933 NV_ERROR(drm, "%s failed and gave up.\n", __func__);
35934diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35935index 08214bc..9208577 100644
35936--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35937+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35938@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
35939 unsigned long arg)
35940 {
35941 unsigned int nr = DRM_IOCTL_NR(cmd);
35942- drm_ioctl_compat_t *fn = NULL;
35943+ drm_ioctl_compat_t fn = NULL;
35944 int ret;
35945
35946 if (nr < DRM_COMMAND_BASE)
35947diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
35948index 25d3495..d81aaf6 100644
35949--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
35950+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
35951@@ -62,7 +62,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
35952 bool can_switch;
35953
35954 spin_lock(&dev->count_lock);
35955- can_switch = (dev->open_count == 0);
35956+ can_switch = (local_read(&dev->open_count) == 0);
35957 spin_unlock(&dev->count_lock);
35958 return can_switch;
35959 }
35960diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
35961index d4660cf..70dbe65 100644
35962--- a/drivers/gpu/drm/r128/r128_cce.c
35963+++ b/drivers/gpu/drm/r128/r128_cce.c
35964@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
35965
35966 /* GH: Simple idle check.
35967 */
35968- atomic_set(&dev_priv->idle_count, 0);
35969+ atomic_set_unchecked(&dev_priv->idle_count, 0);
35970
35971 /* We don't support anything other than bus-mastering ring mode,
35972 * but the ring can be in either AGP or PCI space for the ring
35973diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
35974index 930c71b..499aded 100644
35975--- a/drivers/gpu/drm/r128/r128_drv.h
35976+++ b/drivers/gpu/drm/r128/r128_drv.h
35977@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
35978 int is_pci;
35979 unsigned long cce_buffers_offset;
35980
35981- atomic_t idle_count;
35982+ atomic_unchecked_t idle_count;
35983
35984 int page_flipping;
35985 int current_page;
35986 u32 crtc_offset;
35987 u32 crtc_offset_cntl;
35988
35989- atomic_t vbl_received;
35990+ atomic_unchecked_t vbl_received;
35991
35992 u32 color_fmt;
35993 unsigned int front_offset;
35994diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
35995index a954c54..9cc595c 100644
35996--- a/drivers/gpu/drm/r128/r128_ioc32.c
35997+++ b/drivers/gpu/drm/r128/r128_ioc32.c
35998@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
35999 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
36000 }
36001
36002-drm_ioctl_compat_t *r128_compat_ioctls[] = {
36003+drm_ioctl_compat_t r128_compat_ioctls[] = {
36004 [DRM_R128_INIT] = compat_r128_init,
36005 [DRM_R128_DEPTH] = compat_r128_depth,
36006 [DRM_R128_STIPPLE] = compat_r128_stipple,
36007@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
36008 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
36009 {
36010 unsigned int nr = DRM_IOCTL_NR(cmd);
36011- drm_ioctl_compat_t *fn = NULL;
36012 int ret;
36013
36014 if (nr < DRM_COMMAND_BASE)
36015 return drm_compat_ioctl(filp, cmd, arg);
36016
36017- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
36018- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
36019-
36020- if (fn != NULL)
36021+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
36022+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
36023 ret = (*fn) (filp, cmd, arg);
36024- else
36025+ } else
36026 ret = drm_ioctl(filp, cmd, arg);
36027
36028 return ret;
36029diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
36030index 2ea4f09..d391371 100644
36031--- a/drivers/gpu/drm/r128/r128_irq.c
36032+++ b/drivers/gpu/drm/r128/r128_irq.c
36033@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
36034 if (crtc != 0)
36035 return 0;
36036
36037- return atomic_read(&dev_priv->vbl_received);
36038+ return atomic_read_unchecked(&dev_priv->vbl_received);
36039 }
36040
36041 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
36042@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
36043 /* VBLANK interrupt */
36044 if (status & R128_CRTC_VBLANK_INT) {
36045 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
36046- atomic_inc(&dev_priv->vbl_received);
36047+ atomic_inc_unchecked(&dev_priv->vbl_received);
36048 drm_handle_vblank(dev, 0);
36049 return IRQ_HANDLED;
36050 }
36051diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
36052index 19bb7e6..de7e2a2 100644
36053--- a/drivers/gpu/drm/r128/r128_state.c
36054+++ b/drivers/gpu/drm/r128/r128_state.c
36055@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
36056
36057 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
36058 {
36059- if (atomic_read(&dev_priv->idle_count) == 0)
36060+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
36061 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
36062 else
36063- atomic_set(&dev_priv->idle_count, 0);
36064+ atomic_set_unchecked(&dev_priv->idle_count, 0);
36065 }
36066
36067 #endif
36068diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
36069index 5a82b6b..9e69c73 100644
36070--- a/drivers/gpu/drm/radeon/mkregtable.c
36071+++ b/drivers/gpu/drm/radeon/mkregtable.c
36072@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
36073 regex_t mask_rex;
36074 regmatch_t match[4];
36075 char buf[1024];
36076- size_t end;
36077+ long end;
36078 int len;
36079 int done = 0;
36080 int r;
36081 unsigned o;
36082 struct offset *offset;
36083 char last_reg_s[10];
36084- int last_reg;
36085+ unsigned long last_reg;
36086
36087 if (regcomp
36088 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
36089diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
36090index 0d6562b..a154330 100644
36091--- a/drivers/gpu/drm/radeon/radeon_device.c
36092+++ b/drivers/gpu/drm/radeon/radeon_device.c
36093@@ -969,7 +969,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
36094 bool can_switch;
36095
36096 spin_lock(&dev->count_lock);
36097- can_switch = (dev->open_count == 0);
36098+ can_switch = (local_read(&dev->open_count) == 0);
36099 spin_unlock(&dev->count_lock);
36100 return can_switch;
36101 }
36102diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
36103index e7fdf16..f4f6490 100644
36104--- a/drivers/gpu/drm/radeon/radeon_drv.h
36105+++ b/drivers/gpu/drm/radeon/radeon_drv.h
36106@@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
36107
36108 /* SW interrupt */
36109 wait_queue_head_t swi_queue;
36110- atomic_t swi_emitted;
36111+ atomic_unchecked_t swi_emitted;
36112 int vblank_crtc;
36113 uint32_t irq_enable_reg;
36114 uint32_t r500_disp_irq_reg;
36115diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
36116index c180df8..5fd8186 100644
36117--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
36118+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
36119@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
36120 request = compat_alloc_user_space(sizeof(*request));
36121 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
36122 || __put_user(req32.param, &request->param)
36123- || __put_user((void __user *)(unsigned long)req32.value,
36124+ || __put_user((unsigned long)req32.value,
36125 &request->value))
36126 return -EFAULT;
36127
36128@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
36129 #define compat_radeon_cp_setparam NULL
36130 #endif /* X86_64 || IA64 */
36131
36132-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
36133+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
36134 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
36135 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
36136 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
36137@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
36138 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
36139 {
36140 unsigned int nr = DRM_IOCTL_NR(cmd);
36141- drm_ioctl_compat_t *fn = NULL;
36142 int ret;
36143
36144 if (nr < DRM_COMMAND_BASE)
36145 return drm_compat_ioctl(filp, cmd, arg);
36146
36147- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
36148- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
36149-
36150- if (fn != NULL)
36151+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
36152+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
36153 ret = (*fn) (filp, cmd, arg);
36154- else
36155+ } else
36156 ret = drm_ioctl(filp, cmd, arg);
36157
36158 return ret;
36159diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
36160index e771033..a0bc6b3 100644
36161--- a/drivers/gpu/drm/radeon/radeon_irq.c
36162+++ b/drivers/gpu/drm/radeon/radeon_irq.c
36163@@ -224,8 +224,8 @@ static int radeon_emit_irq(struct drm_device * dev)
36164 unsigned int ret;
36165 RING_LOCALS;
36166
36167- atomic_inc(&dev_priv->swi_emitted);
36168- ret = atomic_read(&dev_priv->swi_emitted);
36169+ atomic_inc_unchecked(&dev_priv->swi_emitted);
36170+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
36171
36172 BEGIN_RING(4);
36173 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
36174@@ -351,7 +351,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
36175 drm_radeon_private_t *dev_priv =
36176 (drm_radeon_private_t *) dev->dev_private;
36177
36178- atomic_set(&dev_priv->swi_emitted, 0);
36179+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
36180 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
36181
36182 dev->max_vblank_count = 0x001fffff;
36183diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
36184index 8e9057b..af6dacb 100644
36185--- a/drivers/gpu/drm/radeon/radeon_state.c
36186+++ b/drivers/gpu/drm/radeon/radeon_state.c
36187@@ -2166,7 +2166,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
36188 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
36189 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
36190
36191- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
36192+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
36193 sarea_priv->nbox * sizeof(depth_boxes[0])))
36194 return -EFAULT;
36195
36196@@ -3029,7 +3029,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
36197 {
36198 drm_radeon_private_t *dev_priv = dev->dev_private;
36199 drm_radeon_getparam_t *param = data;
36200- int value;
36201+ int value = 0;
36202
36203 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
36204
36205diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
36206index 93f760e..8088227 100644
36207--- a/drivers/gpu/drm/radeon/radeon_ttm.c
36208+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
36209@@ -782,7 +782,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
36210 man->size = size >> PAGE_SHIFT;
36211 }
36212
36213-static struct vm_operations_struct radeon_ttm_vm_ops;
36214+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
36215 static const struct vm_operations_struct *ttm_vm_ops = NULL;
36216
36217 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
36218@@ -823,8 +823,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
36219 }
36220 if (unlikely(ttm_vm_ops == NULL)) {
36221 ttm_vm_ops = vma->vm_ops;
36222+ pax_open_kernel();
36223 radeon_ttm_vm_ops = *ttm_vm_ops;
36224 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
36225+ pax_close_kernel();
36226 }
36227 vma->vm_ops = &radeon_ttm_vm_ops;
36228 return 0;
36229@@ -862,28 +864,33 @@ static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
36230 sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
36231 else
36232 sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
36233- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36234- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
36235- radeon_mem_types_list[i].driver_features = 0;
36236+ pax_open_kernel();
36237+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36238+ *(void **)&radeon_mem_types_list[i].show = &radeon_mm_dump_table;
36239+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
36240 if (i == 0)
36241- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
36242+ *(void **)&radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
36243 else
36244- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
36245-
36246+ *(void **)&radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
36247+ pax_close_kernel();
36248 }
36249 /* Add ttm page pool to debugfs */
36250 sprintf(radeon_mem_types_names[i], "ttm_page_pool");
36251- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36252- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
36253- radeon_mem_types_list[i].driver_features = 0;
36254- radeon_mem_types_list[i++].data = NULL;
36255+ pax_open_kernel();
36256+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36257+ *(void **)&radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
36258+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
36259+ *(void **)&radeon_mem_types_list[i++].data = NULL;
36260+ pax_close_kernel();
36261 #ifdef CONFIG_SWIOTLB
36262 if (swiotlb_nr_tbl()) {
36263 sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
36264- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36265- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
36266- radeon_mem_types_list[i].driver_features = 0;
36267- radeon_mem_types_list[i++].data = NULL;
36268+ pax_open_kernel();
36269+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36270+ *(void **)&radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
36271+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
36272+ *(void **)&radeon_mem_types_list[i++].data = NULL;
36273+ pax_close_kernel();
36274 }
36275 #endif
36276 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
36277diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
36278index 5706d2a..17aedaa 100644
36279--- a/drivers/gpu/drm/radeon/rs690.c
36280+++ b/drivers/gpu/drm/radeon/rs690.c
36281@@ -304,9 +304,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
36282 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
36283 rdev->pm.sideport_bandwidth.full)
36284 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
36285- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
36286+ read_delay_latency.full = dfixed_const(800 * 1000);
36287 read_delay_latency.full = dfixed_div(read_delay_latency,
36288 rdev->pm.igp_sideport_mclk);
36289+ a.full = dfixed_const(370);
36290+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
36291 } else {
36292 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
36293 rdev->pm.k8_bandwidth.full)
36294diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
36295index bd2a3b4..122d9ad 100644
36296--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
36297+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
36298@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
36299 static int ttm_pool_mm_shrink(struct shrinker *shrink,
36300 struct shrink_control *sc)
36301 {
36302- static atomic_t start_pool = ATOMIC_INIT(0);
36303+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
36304 unsigned i;
36305- unsigned pool_offset = atomic_add_return(1, &start_pool);
36306+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
36307 struct ttm_page_pool *pool;
36308 int shrink_pages = sc->nr_to_scan;
36309
36310diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
36311index 1eb060c..188b1fc 100644
36312--- a/drivers/gpu/drm/udl/udl_fb.c
36313+++ b/drivers/gpu/drm/udl/udl_fb.c
36314@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
36315 fb_deferred_io_cleanup(info);
36316 kfree(info->fbdefio);
36317 info->fbdefio = NULL;
36318- info->fbops->fb_mmap = udl_fb_mmap;
36319 }
36320
36321 pr_warn("released /dev/fb%d user=%d count=%d\n",
36322diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
36323index 893a650..6190d3b 100644
36324--- a/drivers/gpu/drm/via/via_drv.h
36325+++ b/drivers/gpu/drm/via/via_drv.h
36326@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
36327 typedef uint32_t maskarray_t[5];
36328
36329 typedef struct drm_via_irq {
36330- atomic_t irq_received;
36331+ atomic_unchecked_t irq_received;
36332 uint32_t pending_mask;
36333 uint32_t enable_mask;
36334 wait_queue_head_t irq_queue;
36335@@ -75,7 +75,7 @@ typedef struct drm_via_private {
36336 struct timeval last_vblank;
36337 int last_vblank_valid;
36338 unsigned usec_per_vblank;
36339- atomic_t vbl_received;
36340+ atomic_unchecked_t vbl_received;
36341 drm_via_state_t hc_state;
36342 char pci_buf[VIA_PCI_BUF_SIZE];
36343 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
36344diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
36345index ac98964..5dbf512 100644
36346--- a/drivers/gpu/drm/via/via_irq.c
36347+++ b/drivers/gpu/drm/via/via_irq.c
36348@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
36349 if (crtc != 0)
36350 return 0;
36351
36352- return atomic_read(&dev_priv->vbl_received);
36353+ return atomic_read_unchecked(&dev_priv->vbl_received);
36354 }
36355
36356 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36357@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36358
36359 status = VIA_READ(VIA_REG_INTERRUPT);
36360 if (status & VIA_IRQ_VBLANK_PENDING) {
36361- atomic_inc(&dev_priv->vbl_received);
36362- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
36363+ atomic_inc_unchecked(&dev_priv->vbl_received);
36364+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
36365 do_gettimeofday(&cur_vblank);
36366 if (dev_priv->last_vblank_valid) {
36367 dev_priv->usec_per_vblank =
36368@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36369 dev_priv->last_vblank = cur_vblank;
36370 dev_priv->last_vblank_valid = 1;
36371 }
36372- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
36373+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
36374 DRM_DEBUG("US per vblank is: %u\n",
36375 dev_priv->usec_per_vblank);
36376 }
36377@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36378
36379 for (i = 0; i < dev_priv->num_irqs; ++i) {
36380 if (status & cur_irq->pending_mask) {
36381- atomic_inc(&cur_irq->irq_received);
36382+ atomic_inc_unchecked(&cur_irq->irq_received);
36383 DRM_WAKEUP(&cur_irq->irq_queue);
36384 handled = 1;
36385 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
36386@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
36387 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
36388 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
36389 masks[irq][4]));
36390- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
36391+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
36392 } else {
36393 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
36394 (((cur_irq_sequence =
36395- atomic_read(&cur_irq->irq_received)) -
36396+ atomic_read_unchecked(&cur_irq->irq_received)) -
36397 *sequence) <= (1 << 23)));
36398 }
36399 *sequence = cur_irq_sequence;
36400@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
36401 }
36402
36403 for (i = 0; i < dev_priv->num_irqs; ++i) {
36404- atomic_set(&cur_irq->irq_received, 0);
36405+ atomic_set_unchecked(&cur_irq->irq_received, 0);
36406 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
36407 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
36408 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
36409@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
36410 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
36411 case VIA_IRQ_RELATIVE:
36412 irqwait->request.sequence +=
36413- atomic_read(&cur_irq->irq_received);
36414+ atomic_read_unchecked(&cur_irq->irq_received);
36415 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
36416 case VIA_IRQ_ABSOLUTE:
36417 break;
36418diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
36419index 13aeda7..4a952d1 100644
36420--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
36421+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
36422@@ -290,7 +290,7 @@ struct vmw_private {
36423 * Fencing and IRQs.
36424 */
36425
36426- atomic_t marker_seq;
36427+ atomic_unchecked_t marker_seq;
36428 wait_queue_head_t fence_queue;
36429 wait_queue_head_t fifo_queue;
36430 int fence_queue_waiters; /* Protected by hw_mutex */
36431diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
36432index 3eb1486..0a47ee9 100644
36433--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
36434+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
36435@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
36436 (unsigned int) min,
36437 (unsigned int) fifo->capabilities);
36438
36439- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
36440+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
36441 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
36442 vmw_marker_queue_init(&fifo->marker_queue);
36443 return vmw_fifo_send_fence(dev_priv, &dummy);
36444@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
36445 if (reserveable)
36446 iowrite32(bytes, fifo_mem +
36447 SVGA_FIFO_RESERVED);
36448- return fifo_mem + (next_cmd >> 2);
36449+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
36450 } else {
36451 need_bounce = true;
36452 }
36453@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
36454
36455 fm = vmw_fifo_reserve(dev_priv, bytes);
36456 if (unlikely(fm == NULL)) {
36457- *seqno = atomic_read(&dev_priv->marker_seq);
36458+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
36459 ret = -ENOMEM;
36460 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
36461 false, 3*HZ);
36462@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
36463 }
36464
36465 do {
36466- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
36467+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
36468 } while (*seqno == 0);
36469
36470 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
36471diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36472index 4640adb..e1384ed 100644
36473--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36474+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36475@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
36476 * emitted. Then the fence is stale and signaled.
36477 */
36478
36479- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
36480+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
36481 > VMW_FENCE_WRAP);
36482
36483 return ret;
36484@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
36485
36486 if (fifo_idle)
36487 down_read(&fifo_state->rwsem);
36488- signal_seq = atomic_read(&dev_priv->marker_seq);
36489+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
36490 ret = 0;
36491
36492 for (;;) {
36493diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36494index 8a8725c..afed796 100644
36495--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36496+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36497@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
36498 while (!vmw_lag_lt(queue, us)) {
36499 spin_lock(&queue->lock);
36500 if (list_empty(&queue->head))
36501- seqno = atomic_read(&dev_priv->marker_seq);
36502+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
36503 else {
36504 marker = list_first_entry(&queue->head,
36505 struct vmw_marker, head);
36506diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
36507index ceb3040..6160c5c 100644
36508--- a/drivers/hid/hid-core.c
36509+++ b/drivers/hid/hid-core.c
36510@@ -2242,7 +2242,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
36511
36512 int hid_add_device(struct hid_device *hdev)
36513 {
36514- static atomic_t id = ATOMIC_INIT(0);
36515+ static atomic_unchecked_t id = ATOMIC_INIT(0);
36516 int ret;
36517
36518 if (WARN_ON(hdev->status & HID_STAT_ADDED))
36519@@ -2276,7 +2276,7 @@ int hid_add_device(struct hid_device *hdev)
36520 /* XXX hack, any other cleaner solution after the driver core
36521 * is converted to allow more than 20 bytes as the device name? */
36522 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
36523- hdev->vendor, hdev->product, atomic_inc_return(&id));
36524+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
36525
36526 hid_debug_register(hdev, dev_name(&hdev->dev));
36527 ret = device_add(&hdev->dev);
36528diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
36529index eec3291..8ed706b 100644
36530--- a/drivers/hid/hid-wiimote-debug.c
36531+++ b/drivers/hid/hid-wiimote-debug.c
36532@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
36533 else if (size == 0)
36534 return -EIO;
36535
36536- if (copy_to_user(u, buf, size))
36537+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
36538 return -EFAULT;
36539
36540 *off += size;
36541diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
36542index 773a2f2..7ce08bc 100644
36543--- a/drivers/hv/channel.c
36544+++ b/drivers/hv/channel.c
36545@@ -394,8 +394,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
36546 int ret = 0;
36547 int t;
36548
36549- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
36550- atomic_inc(&vmbus_connection.next_gpadl_handle);
36551+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
36552+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
36553
36554 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
36555 if (ret)
36556diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
36557index 3648f8f..30ef30d 100644
36558--- a/drivers/hv/hv.c
36559+++ b/drivers/hv/hv.c
36560@@ -111,7 +111,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
36561 u64 output_address = (output) ? virt_to_phys(output) : 0;
36562 u32 output_address_hi = output_address >> 32;
36563 u32 output_address_lo = output_address & 0xFFFFFFFF;
36564- void *hypercall_page = hv_context.hypercall_page;
36565+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
36566
36567 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
36568 "=a"(hv_status_lo) : "d" (control_hi),
36569diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
36570index d8d1fad..b91caf7 100644
36571--- a/drivers/hv/hyperv_vmbus.h
36572+++ b/drivers/hv/hyperv_vmbus.h
36573@@ -594,7 +594,7 @@ enum vmbus_connect_state {
36574 struct vmbus_connection {
36575 enum vmbus_connect_state conn_state;
36576
36577- atomic_t next_gpadl_handle;
36578+ atomic_unchecked_t next_gpadl_handle;
36579
36580 /*
36581 * Represents channel interrupts. Each bit position represents a
36582diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
36583index 8e1a9ec..4687821 100644
36584--- a/drivers/hv/vmbus_drv.c
36585+++ b/drivers/hv/vmbus_drv.c
36586@@ -629,10 +629,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
36587 {
36588 int ret = 0;
36589
36590- static atomic_t device_num = ATOMIC_INIT(0);
36591+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
36592
36593 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
36594- atomic_inc_return(&device_num));
36595+ atomic_inc_return_unchecked(&device_num));
36596
36597 child_device_obj->device.bus = &hv_bus;
36598 child_device_obj->device.parent = &hv_acpi_dev->dev;
36599diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
36600index 1672e2a..4a6297c 100644
36601--- a/drivers/hwmon/acpi_power_meter.c
36602+++ b/drivers/hwmon/acpi_power_meter.c
36603@@ -117,7 +117,7 @@ struct sensor_template {
36604 struct device_attribute *devattr,
36605 const char *buf, size_t count);
36606 int index;
36607-};
36608+} __do_const;
36609
36610 /* Averaging interval */
36611 static int update_avg_interval(struct acpi_power_meter_resource *resource)
36612@@ -629,7 +629,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
36613 struct sensor_template *attrs)
36614 {
36615 struct device *dev = &resource->acpi_dev->dev;
36616- struct sensor_device_attribute *sensors =
36617+ sensor_device_attribute_no_const *sensors =
36618 &resource->sensors[resource->num_sensors];
36619 int res = 0;
36620
36621diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
36622index b41baff..4953e4d 100644
36623--- a/drivers/hwmon/applesmc.c
36624+++ b/drivers/hwmon/applesmc.c
36625@@ -1084,7 +1084,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
36626 {
36627 struct applesmc_node_group *grp;
36628 struct applesmc_dev_attr *node;
36629- struct attribute *attr;
36630+ attribute_no_const *attr;
36631 int ret, i;
36632
36633 for (grp = groups; grp->format; grp++) {
36634diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
36635index 56dbcfb..9874bf1 100644
36636--- a/drivers/hwmon/asus_atk0110.c
36637+++ b/drivers/hwmon/asus_atk0110.c
36638@@ -152,10 +152,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
36639 struct atk_sensor_data {
36640 struct list_head list;
36641 struct atk_data *data;
36642- struct device_attribute label_attr;
36643- struct device_attribute input_attr;
36644- struct device_attribute limit1_attr;
36645- struct device_attribute limit2_attr;
36646+ device_attribute_no_const label_attr;
36647+ device_attribute_no_const input_attr;
36648+ device_attribute_no_const limit1_attr;
36649+ device_attribute_no_const limit2_attr;
36650 char label_attr_name[ATTR_NAME_SIZE];
36651 char input_attr_name[ATTR_NAME_SIZE];
36652 char limit1_attr_name[ATTR_NAME_SIZE];
36653@@ -275,7 +275,7 @@ static ssize_t atk_name_show(struct device *dev,
36654 static struct device_attribute atk_name_attr =
36655 __ATTR(name, 0444, atk_name_show, NULL);
36656
36657-static void atk_init_attribute(struct device_attribute *attr, char *name,
36658+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
36659 sysfs_show_func show)
36660 {
36661 sysfs_attr_init(&attr->attr);
36662diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
36663index d64923d..72591e8 100644
36664--- a/drivers/hwmon/coretemp.c
36665+++ b/drivers/hwmon/coretemp.c
36666@@ -790,7 +790,7 @@ static int __cpuinit coretemp_cpu_callback(struct notifier_block *nfb,
36667 return NOTIFY_OK;
36668 }
36669
36670-static struct notifier_block coretemp_cpu_notifier __refdata = {
36671+static struct notifier_block coretemp_cpu_notifier = {
36672 .notifier_call = coretemp_cpu_callback,
36673 };
36674
36675diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
36676index a14f634..2916ee2 100644
36677--- a/drivers/hwmon/ibmaem.c
36678+++ b/drivers/hwmon/ibmaem.c
36679@@ -925,7 +925,7 @@ static int aem_register_sensors(struct aem_data *data,
36680 struct aem_rw_sensor_template *rw)
36681 {
36682 struct device *dev = &data->pdev->dev;
36683- struct sensor_device_attribute *sensors = data->sensors;
36684+ sensor_device_attribute_no_const *sensors = data->sensors;
36685 int err;
36686
36687 /* Set up read-only sensors */
36688diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
36689index 7d19b1b..8fdaaac 100644
36690--- a/drivers/hwmon/pmbus/pmbus_core.c
36691+++ b/drivers/hwmon/pmbus/pmbus_core.c
36692@@ -811,7 +811,7 @@ static ssize_t pmbus_show_label(struct device *dev,
36693
36694 #define PMBUS_ADD_ATTR(data, _name, _idx, _mode, _type, _show, _set) \
36695 do { \
36696- struct sensor_device_attribute *a \
36697+ sensor_device_attribute_no_const *a \
36698 = &data->_type##s[data->num_##_type##s].attribute; \
36699 BUG_ON(data->num_attributes >= data->max_attributes); \
36700 sysfs_attr_init(&a->dev_attr.attr); \
36701diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
36702index 8047fed..1e956f0 100644
36703--- a/drivers/hwmon/sht15.c
36704+++ b/drivers/hwmon/sht15.c
36705@@ -169,7 +169,7 @@ struct sht15_data {
36706 int supply_uV;
36707 bool supply_uV_valid;
36708 struct work_struct update_supply_work;
36709- atomic_t interrupt_handled;
36710+ atomic_unchecked_t interrupt_handled;
36711 };
36712
36713 /**
36714@@ -512,13 +512,13 @@ static int sht15_measurement(struct sht15_data *data,
36715 return ret;
36716
36717 gpio_direction_input(data->pdata->gpio_data);
36718- atomic_set(&data->interrupt_handled, 0);
36719+ atomic_set_unchecked(&data->interrupt_handled, 0);
36720
36721 enable_irq(gpio_to_irq(data->pdata->gpio_data));
36722 if (gpio_get_value(data->pdata->gpio_data) == 0) {
36723 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
36724 /* Only relevant if the interrupt hasn't occurred. */
36725- if (!atomic_read(&data->interrupt_handled))
36726+ if (!atomic_read_unchecked(&data->interrupt_handled))
36727 schedule_work(&data->read_work);
36728 }
36729 ret = wait_event_timeout(data->wait_queue,
36730@@ -785,7 +785,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
36731
36732 /* First disable the interrupt */
36733 disable_irq_nosync(irq);
36734- atomic_inc(&data->interrupt_handled);
36735+ atomic_inc_unchecked(&data->interrupt_handled);
36736 /* Then schedule a reading work struct */
36737 if (data->state != SHT15_READING_NOTHING)
36738 schedule_work(&data->read_work);
36739@@ -807,11 +807,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
36740 * If not, then start the interrupt again - care here as could
36741 * have gone low in meantime so verify it hasn't!
36742 */
36743- atomic_set(&data->interrupt_handled, 0);
36744+ atomic_set_unchecked(&data->interrupt_handled, 0);
36745 enable_irq(gpio_to_irq(data->pdata->gpio_data));
36746 /* If still not occurred or another handler was scheduled */
36747 if (gpio_get_value(data->pdata->gpio_data)
36748- || atomic_read(&data->interrupt_handled))
36749+ || atomic_read_unchecked(&data->interrupt_handled))
36750 return;
36751 }
36752
36753diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
36754index 76f157b..9c0db1b 100644
36755--- a/drivers/hwmon/via-cputemp.c
36756+++ b/drivers/hwmon/via-cputemp.c
36757@@ -296,7 +296,7 @@ static int __cpuinit via_cputemp_cpu_callback(struct notifier_block *nfb,
36758 return NOTIFY_OK;
36759 }
36760
36761-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
36762+static struct notifier_block via_cputemp_cpu_notifier = {
36763 .notifier_call = via_cputemp_cpu_callback,
36764 };
36765
36766diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
36767index 378fcb5..5e91fa8 100644
36768--- a/drivers/i2c/busses/i2c-amd756-s4882.c
36769+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
36770@@ -43,7 +43,7 @@
36771 extern struct i2c_adapter amd756_smbus;
36772
36773 static struct i2c_adapter *s4882_adapter;
36774-static struct i2c_algorithm *s4882_algo;
36775+static i2c_algorithm_no_const *s4882_algo;
36776
36777 /* Wrapper access functions for multiplexed SMBus */
36778 static DEFINE_MUTEX(amd756_lock);
36779diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
36780index 29015eb..af2d8e9 100644
36781--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
36782+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
36783@@ -41,7 +41,7 @@
36784 extern struct i2c_adapter *nforce2_smbus;
36785
36786 static struct i2c_adapter *s4985_adapter;
36787-static struct i2c_algorithm *s4985_algo;
36788+static i2c_algorithm_no_const *s4985_algo;
36789
36790 /* Wrapper access functions for multiplexed SMBus */
36791 static DEFINE_MUTEX(nforce2_lock);
36792diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
36793index 8126824..55a2798 100644
36794--- a/drivers/ide/ide-cd.c
36795+++ b/drivers/ide/ide-cd.c
36796@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
36797 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
36798 if ((unsigned long)buf & alignment
36799 || blk_rq_bytes(rq) & q->dma_pad_mask
36800- || object_is_on_stack(buf))
36801+ || object_starts_on_stack(buf))
36802 drive->dma = 0;
36803 }
36804 }
36805diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
36806index 8848f16..f8e6dd8 100644
36807--- a/drivers/iio/industrialio-core.c
36808+++ b/drivers/iio/industrialio-core.c
36809@@ -506,7 +506,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
36810 }
36811
36812 static
36813-int __iio_device_attr_init(struct device_attribute *dev_attr,
36814+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
36815 const char *postfix,
36816 struct iio_chan_spec const *chan,
36817 ssize_t (*readfunc)(struct device *dev,
36818diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
36819index 394fea2..c833880 100644
36820--- a/drivers/infiniband/core/cm.c
36821+++ b/drivers/infiniband/core/cm.c
36822@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
36823
36824 struct cm_counter_group {
36825 struct kobject obj;
36826- atomic_long_t counter[CM_ATTR_COUNT];
36827+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
36828 };
36829
36830 struct cm_counter_attribute {
36831@@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
36832 struct ib_mad_send_buf *msg = NULL;
36833 int ret;
36834
36835- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36836+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36837 counter[CM_REQ_COUNTER]);
36838
36839 /* Quick state check to discard duplicate REQs. */
36840@@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
36841 if (!cm_id_priv)
36842 return;
36843
36844- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36845+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36846 counter[CM_REP_COUNTER]);
36847 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
36848 if (ret)
36849@@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
36850 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
36851 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
36852 spin_unlock_irq(&cm_id_priv->lock);
36853- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36854+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36855 counter[CM_RTU_COUNTER]);
36856 goto out;
36857 }
36858@@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
36859 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
36860 dreq_msg->local_comm_id);
36861 if (!cm_id_priv) {
36862- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36863+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36864 counter[CM_DREQ_COUNTER]);
36865 cm_issue_drep(work->port, work->mad_recv_wc);
36866 return -EINVAL;
36867@@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
36868 case IB_CM_MRA_REP_RCVD:
36869 break;
36870 case IB_CM_TIMEWAIT:
36871- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36872+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36873 counter[CM_DREQ_COUNTER]);
36874 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
36875 goto unlock;
36876@@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
36877 cm_free_msg(msg);
36878 goto deref;
36879 case IB_CM_DREQ_RCVD:
36880- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36881+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36882 counter[CM_DREQ_COUNTER]);
36883 goto unlock;
36884 default:
36885@@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
36886 ib_modify_mad(cm_id_priv->av.port->mad_agent,
36887 cm_id_priv->msg, timeout)) {
36888 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
36889- atomic_long_inc(&work->port->
36890+ atomic_long_inc_unchecked(&work->port->
36891 counter_group[CM_RECV_DUPLICATES].
36892 counter[CM_MRA_COUNTER]);
36893 goto out;
36894@@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
36895 break;
36896 case IB_CM_MRA_REQ_RCVD:
36897 case IB_CM_MRA_REP_RCVD:
36898- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36899+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36900 counter[CM_MRA_COUNTER]);
36901 /* fall through */
36902 default:
36903@@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
36904 case IB_CM_LAP_IDLE:
36905 break;
36906 case IB_CM_MRA_LAP_SENT:
36907- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36908+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36909 counter[CM_LAP_COUNTER]);
36910 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
36911 goto unlock;
36912@@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
36913 cm_free_msg(msg);
36914 goto deref;
36915 case IB_CM_LAP_RCVD:
36916- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36917+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36918 counter[CM_LAP_COUNTER]);
36919 goto unlock;
36920 default:
36921@@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
36922 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
36923 if (cur_cm_id_priv) {
36924 spin_unlock_irq(&cm.lock);
36925- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36926+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36927 counter[CM_SIDR_REQ_COUNTER]);
36928 goto out; /* Duplicate message. */
36929 }
36930@@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
36931 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
36932 msg->retries = 1;
36933
36934- atomic_long_add(1 + msg->retries,
36935+ atomic_long_add_unchecked(1 + msg->retries,
36936 &port->counter_group[CM_XMIT].counter[attr_index]);
36937 if (msg->retries)
36938- atomic_long_add(msg->retries,
36939+ atomic_long_add_unchecked(msg->retries,
36940 &port->counter_group[CM_XMIT_RETRIES].
36941 counter[attr_index]);
36942
36943@@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
36944 }
36945
36946 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
36947- atomic_long_inc(&port->counter_group[CM_RECV].
36948+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
36949 counter[attr_id - CM_ATTR_ID_OFFSET]);
36950
36951 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
36952@@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
36953 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
36954
36955 return sprintf(buf, "%ld\n",
36956- atomic_long_read(&group->counter[cm_attr->index]));
36957+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
36958 }
36959
36960 static const struct sysfs_ops cm_counter_ops = {
36961diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
36962index 176c8f9..2627b62 100644
36963--- a/drivers/infiniband/core/fmr_pool.c
36964+++ b/drivers/infiniband/core/fmr_pool.c
36965@@ -98,8 +98,8 @@ struct ib_fmr_pool {
36966
36967 struct task_struct *thread;
36968
36969- atomic_t req_ser;
36970- atomic_t flush_ser;
36971+ atomic_unchecked_t req_ser;
36972+ atomic_unchecked_t flush_ser;
36973
36974 wait_queue_head_t force_wait;
36975 };
36976@@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
36977 struct ib_fmr_pool *pool = pool_ptr;
36978
36979 do {
36980- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
36981+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
36982 ib_fmr_batch_release(pool);
36983
36984- atomic_inc(&pool->flush_ser);
36985+ atomic_inc_unchecked(&pool->flush_ser);
36986 wake_up_interruptible(&pool->force_wait);
36987
36988 if (pool->flush_function)
36989@@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
36990 }
36991
36992 set_current_state(TASK_INTERRUPTIBLE);
36993- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
36994+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
36995 !kthread_should_stop())
36996 schedule();
36997 __set_current_state(TASK_RUNNING);
36998@@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
36999 pool->dirty_watermark = params->dirty_watermark;
37000 pool->dirty_len = 0;
37001 spin_lock_init(&pool->pool_lock);
37002- atomic_set(&pool->req_ser, 0);
37003- atomic_set(&pool->flush_ser, 0);
37004+ atomic_set_unchecked(&pool->req_ser, 0);
37005+ atomic_set_unchecked(&pool->flush_ser, 0);
37006 init_waitqueue_head(&pool->force_wait);
37007
37008 pool->thread = kthread_run(ib_fmr_cleanup_thread,
37009@@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
37010 }
37011 spin_unlock_irq(&pool->pool_lock);
37012
37013- serial = atomic_inc_return(&pool->req_ser);
37014+ serial = atomic_inc_return_unchecked(&pool->req_ser);
37015 wake_up_process(pool->thread);
37016
37017 if (wait_event_interruptible(pool->force_wait,
37018- atomic_read(&pool->flush_ser) - serial >= 0))
37019+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
37020 return -EINTR;
37021
37022 return 0;
37023@@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
37024 } else {
37025 list_add_tail(&fmr->list, &pool->dirty_list);
37026 if (++pool->dirty_len >= pool->dirty_watermark) {
37027- atomic_inc(&pool->req_ser);
37028+ atomic_inc_unchecked(&pool->req_ser);
37029 wake_up_process(pool->thread);
37030 }
37031 }
37032diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
37033index afd8179..598063f 100644
37034--- a/drivers/infiniband/hw/cxgb4/mem.c
37035+++ b/drivers/infiniband/hw/cxgb4/mem.c
37036@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
37037 int err;
37038 struct fw_ri_tpte tpt;
37039 u32 stag_idx;
37040- static atomic_t key;
37041+ static atomic_unchecked_t key;
37042
37043 if (c4iw_fatal_error(rdev))
37044 return -EIO;
37045@@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
37046 if (rdev->stats.stag.cur > rdev->stats.stag.max)
37047 rdev->stats.stag.max = rdev->stats.stag.cur;
37048 mutex_unlock(&rdev->stats.lock);
37049- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
37050+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
37051 }
37052 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
37053 __func__, stag_state, type, pdid, stag_idx);
37054diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
37055index 79b3dbc..96e5fcc 100644
37056--- a/drivers/infiniband/hw/ipath/ipath_rc.c
37057+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
37058@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
37059 struct ib_atomic_eth *ateth;
37060 struct ipath_ack_entry *e;
37061 u64 vaddr;
37062- atomic64_t *maddr;
37063+ atomic64_unchecked_t *maddr;
37064 u64 sdata;
37065 u32 rkey;
37066 u8 next;
37067@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
37068 IB_ACCESS_REMOTE_ATOMIC)))
37069 goto nack_acc_unlck;
37070 /* Perform atomic OP and save result. */
37071- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
37072+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
37073 sdata = be64_to_cpu(ateth->swap_data);
37074 e = &qp->s_ack_queue[qp->r_head_ack_queue];
37075 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
37076- (u64) atomic64_add_return(sdata, maddr) - sdata :
37077+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
37078 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
37079 be64_to_cpu(ateth->compare_data),
37080 sdata);
37081diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
37082index 1f95bba..9530f87 100644
37083--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
37084+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
37085@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
37086 unsigned long flags;
37087 struct ib_wc wc;
37088 u64 sdata;
37089- atomic64_t *maddr;
37090+ atomic64_unchecked_t *maddr;
37091 enum ib_wc_status send_status;
37092
37093 /*
37094@@ -382,11 +382,11 @@ again:
37095 IB_ACCESS_REMOTE_ATOMIC)))
37096 goto acc_err;
37097 /* Perform atomic OP and save result. */
37098- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
37099+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
37100 sdata = wqe->wr.wr.atomic.compare_add;
37101 *(u64 *) sqp->s_sge.sge.vaddr =
37102 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
37103- (u64) atomic64_add_return(sdata, maddr) - sdata :
37104+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
37105 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
37106 sdata, wqe->wr.wr.atomic.swap);
37107 goto send_comp;
37108diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
37109index 9d3e5c1..d9afe4a 100644
37110--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
37111+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
37112@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
37113 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
37114 }
37115
37116-int mthca_QUERY_FW(struct mthca_dev *dev)
37117+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
37118 {
37119 struct mthca_mailbox *mailbox;
37120 u32 *outbox;
37121diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
37122index ed9a989..e0c5871 100644
37123--- a/drivers/infiniband/hw/mthca/mthca_mr.c
37124+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
37125@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
37126 return key;
37127 }
37128
37129-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
37130+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
37131 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
37132 {
37133 struct mthca_mailbox *mailbox;
37134diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
37135index 5b152a3..c1f3e83 100644
37136--- a/drivers/infiniband/hw/nes/nes.c
37137+++ b/drivers/infiniband/hw/nes/nes.c
37138@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
37139 LIST_HEAD(nes_adapter_list);
37140 static LIST_HEAD(nes_dev_list);
37141
37142-atomic_t qps_destroyed;
37143+atomic_unchecked_t qps_destroyed;
37144
37145 static unsigned int ee_flsh_adapter;
37146 static unsigned int sysfs_nonidx_addr;
37147@@ -267,7 +267,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
37148 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
37149 struct nes_adapter *nesadapter = nesdev->nesadapter;
37150
37151- atomic_inc(&qps_destroyed);
37152+ atomic_inc_unchecked(&qps_destroyed);
37153
37154 /* Free the control structures */
37155
37156diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
37157index 33cc589..3bd6538 100644
37158--- a/drivers/infiniband/hw/nes/nes.h
37159+++ b/drivers/infiniband/hw/nes/nes.h
37160@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
37161 extern unsigned int wqm_quanta;
37162 extern struct list_head nes_adapter_list;
37163
37164-extern atomic_t cm_connects;
37165-extern atomic_t cm_accepts;
37166-extern atomic_t cm_disconnects;
37167-extern atomic_t cm_closes;
37168-extern atomic_t cm_connecteds;
37169-extern atomic_t cm_connect_reqs;
37170-extern atomic_t cm_rejects;
37171-extern atomic_t mod_qp_timouts;
37172-extern atomic_t qps_created;
37173-extern atomic_t qps_destroyed;
37174-extern atomic_t sw_qps_destroyed;
37175+extern atomic_unchecked_t cm_connects;
37176+extern atomic_unchecked_t cm_accepts;
37177+extern atomic_unchecked_t cm_disconnects;
37178+extern atomic_unchecked_t cm_closes;
37179+extern atomic_unchecked_t cm_connecteds;
37180+extern atomic_unchecked_t cm_connect_reqs;
37181+extern atomic_unchecked_t cm_rejects;
37182+extern atomic_unchecked_t mod_qp_timouts;
37183+extern atomic_unchecked_t qps_created;
37184+extern atomic_unchecked_t qps_destroyed;
37185+extern atomic_unchecked_t sw_qps_destroyed;
37186 extern u32 mh_detected;
37187 extern u32 mh_pauses_sent;
37188 extern u32 cm_packets_sent;
37189@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
37190 extern u32 cm_packets_received;
37191 extern u32 cm_packets_dropped;
37192 extern u32 cm_packets_retrans;
37193-extern atomic_t cm_listens_created;
37194-extern atomic_t cm_listens_destroyed;
37195+extern atomic_unchecked_t cm_listens_created;
37196+extern atomic_unchecked_t cm_listens_destroyed;
37197 extern u32 cm_backlog_drops;
37198-extern atomic_t cm_loopbacks;
37199-extern atomic_t cm_nodes_created;
37200-extern atomic_t cm_nodes_destroyed;
37201-extern atomic_t cm_accel_dropped_pkts;
37202-extern atomic_t cm_resets_recvd;
37203-extern atomic_t pau_qps_created;
37204-extern atomic_t pau_qps_destroyed;
37205+extern atomic_unchecked_t cm_loopbacks;
37206+extern atomic_unchecked_t cm_nodes_created;
37207+extern atomic_unchecked_t cm_nodes_destroyed;
37208+extern atomic_unchecked_t cm_accel_dropped_pkts;
37209+extern atomic_unchecked_t cm_resets_recvd;
37210+extern atomic_unchecked_t pau_qps_created;
37211+extern atomic_unchecked_t pau_qps_destroyed;
37212
37213 extern u32 int_mod_timer_init;
37214 extern u32 int_mod_cq_depth_256;
37215diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
37216index 22ea67e..dcbe3bc 100644
37217--- a/drivers/infiniband/hw/nes/nes_cm.c
37218+++ b/drivers/infiniband/hw/nes/nes_cm.c
37219@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
37220 u32 cm_packets_retrans;
37221 u32 cm_packets_created;
37222 u32 cm_packets_received;
37223-atomic_t cm_listens_created;
37224-atomic_t cm_listens_destroyed;
37225+atomic_unchecked_t cm_listens_created;
37226+atomic_unchecked_t cm_listens_destroyed;
37227 u32 cm_backlog_drops;
37228-atomic_t cm_loopbacks;
37229-atomic_t cm_nodes_created;
37230-atomic_t cm_nodes_destroyed;
37231-atomic_t cm_accel_dropped_pkts;
37232-atomic_t cm_resets_recvd;
37233+atomic_unchecked_t cm_loopbacks;
37234+atomic_unchecked_t cm_nodes_created;
37235+atomic_unchecked_t cm_nodes_destroyed;
37236+atomic_unchecked_t cm_accel_dropped_pkts;
37237+atomic_unchecked_t cm_resets_recvd;
37238
37239 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
37240 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
37241@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
37242
37243 static struct nes_cm_core *g_cm_core;
37244
37245-atomic_t cm_connects;
37246-atomic_t cm_accepts;
37247-atomic_t cm_disconnects;
37248-atomic_t cm_closes;
37249-atomic_t cm_connecteds;
37250-atomic_t cm_connect_reqs;
37251-atomic_t cm_rejects;
37252+atomic_unchecked_t cm_connects;
37253+atomic_unchecked_t cm_accepts;
37254+atomic_unchecked_t cm_disconnects;
37255+atomic_unchecked_t cm_closes;
37256+atomic_unchecked_t cm_connecteds;
37257+atomic_unchecked_t cm_connect_reqs;
37258+atomic_unchecked_t cm_rejects;
37259
37260 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
37261 {
37262@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
37263 kfree(listener);
37264 listener = NULL;
37265 ret = 0;
37266- atomic_inc(&cm_listens_destroyed);
37267+ atomic_inc_unchecked(&cm_listens_destroyed);
37268 } else {
37269 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
37270 }
37271@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
37272 cm_node->rem_mac);
37273
37274 add_hte_node(cm_core, cm_node);
37275- atomic_inc(&cm_nodes_created);
37276+ atomic_inc_unchecked(&cm_nodes_created);
37277
37278 return cm_node;
37279 }
37280@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
37281 }
37282
37283 atomic_dec(&cm_core->node_cnt);
37284- atomic_inc(&cm_nodes_destroyed);
37285+ atomic_inc_unchecked(&cm_nodes_destroyed);
37286 nesqp = cm_node->nesqp;
37287 if (nesqp) {
37288 nesqp->cm_node = NULL;
37289@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
37290
37291 static void drop_packet(struct sk_buff *skb)
37292 {
37293- atomic_inc(&cm_accel_dropped_pkts);
37294+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
37295 dev_kfree_skb_any(skb);
37296 }
37297
37298@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
37299 {
37300
37301 int reset = 0; /* whether to send reset in case of err.. */
37302- atomic_inc(&cm_resets_recvd);
37303+ atomic_inc_unchecked(&cm_resets_recvd);
37304 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
37305 " refcnt=%d\n", cm_node, cm_node->state,
37306 atomic_read(&cm_node->ref_count));
37307@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
37308 rem_ref_cm_node(cm_node->cm_core, cm_node);
37309 return NULL;
37310 }
37311- atomic_inc(&cm_loopbacks);
37312+ atomic_inc_unchecked(&cm_loopbacks);
37313 loopbackremotenode->loopbackpartner = cm_node;
37314 loopbackremotenode->tcp_cntxt.rcv_wscale =
37315 NES_CM_DEFAULT_RCV_WND_SCALE;
37316@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
37317 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
37318 else {
37319 rem_ref_cm_node(cm_core, cm_node);
37320- atomic_inc(&cm_accel_dropped_pkts);
37321+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
37322 dev_kfree_skb_any(skb);
37323 }
37324 break;
37325@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
37326
37327 if ((cm_id) && (cm_id->event_handler)) {
37328 if (issue_disconn) {
37329- atomic_inc(&cm_disconnects);
37330+ atomic_inc_unchecked(&cm_disconnects);
37331 cm_event.event = IW_CM_EVENT_DISCONNECT;
37332 cm_event.status = disconn_status;
37333 cm_event.local_addr = cm_id->local_addr;
37334@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
37335 }
37336
37337 if (issue_close) {
37338- atomic_inc(&cm_closes);
37339+ atomic_inc_unchecked(&cm_closes);
37340 nes_disconnect(nesqp, 1);
37341
37342 cm_id->provider_data = nesqp;
37343@@ -3033,7 +3033,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
37344
37345 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
37346 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
37347- atomic_inc(&cm_accepts);
37348+ atomic_inc_unchecked(&cm_accepts);
37349
37350 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
37351 netdev_refcnt_read(nesvnic->netdev));
37352@@ -3228,7 +3228,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
37353 struct nes_cm_core *cm_core;
37354 u8 *start_buff;
37355
37356- atomic_inc(&cm_rejects);
37357+ atomic_inc_unchecked(&cm_rejects);
37358 cm_node = (struct nes_cm_node *)cm_id->provider_data;
37359 loopback = cm_node->loopbackpartner;
37360 cm_core = cm_node->cm_core;
37361@@ -3288,7 +3288,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
37362 ntohl(cm_id->local_addr.sin_addr.s_addr),
37363 ntohs(cm_id->local_addr.sin_port));
37364
37365- atomic_inc(&cm_connects);
37366+ atomic_inc_unchecked(&cm_connects);
37367 nesqp->active_conn = 1;
37368
37369 /* cache the cm_id in the qp */
37370@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
37371 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
37372 return err;
37373 }
37374- atomic_inc(&cm_listens_created);
37375+ atomic_inc_unchecked(&cm_listens_created);
37376 }
37377
37378 cm_id->add_ref(cm_id);
37379@@ -3499,7 +3499,7 @@ static void cm_event_connected(struct nes_cm_event *event)
37380
37381 if (nesqp->destroyed)
37382 return;
37383- atomic_inc(&cm_connecteds);
37384+ atomic_inc_unchecked(&cm_connecteds);
37385 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
37386 " local port 0x%04X. jiffies = %lu.\n",
37387 nesqp->hwqp.qp_id,
37388@@ -3679,7 +3679,7 @@ static void cm_event_reset(struct nes_cm_event *event)
37389
37390 cm_id->add_ref(cm_id);
37391 ret = cm_id->event_handler(cm_id, &cm_event);
37392- atomic_inc(&cm_closes);
37393+ atomic_inc_unchecked(&cm_closes);
37394 cm_event.event = IW_CM_EVENT_CLOSE;
37395 cm_event.status = 0;
37396 cm_event.provider_data = cm_id->provider_data;
37397@@ -3715,7 +3715,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
37398 return;
37399 cm_id = cm_node->cm_id;
37400
37401- atomic_inc(&cm_connect_reqs);
37402+ atomic_inc_unchecked(&cm_connect_reqs);
37403 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
37404 cm_node, cm_id, jiffies);
37405
37406@@ -3755,7 +3755,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
37407 return;
37408 cm_id = cm_node->cm_id;
37409
37410- atomic_inc(&cm_connect_reqs);
37411+ atomic_inc_unchecked(&cm_connect_reqs);
37412 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
37413 cm_node, cm_id, jiffies);
37414
37415diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
37416index 4166452..fc952c3 100644
37417--- a/drivers/infiniband/hw/nes/nes_mgt.c
37418+++ b/drivers/infiniband/hw/nes/nes_mgt.c
37419@@ -40,8 +40,8 @@
37420 #include "nes.h"
37421 #include "nes_mgt.h"
37422
37423-atomic_t pau_qps_created;
37424-atomic_t pau_qps_destroyed;
37425+atomic_unchecked_t pau_qps_created;
37426+atomic_unchecked_t pau_qps_destroyed;
37427
37428 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
37429 {
37430@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
37431 {
37432 struct sk_buff *skb;
37433 unsigned long flags;
37434- atomic_inc(&pau_qps_destroyed);
37435+ atomic_inc_unchecked(&pau_qps_destroyed);
37436
37437 /* Free packets that have not yet been forwarded */
37438 /* Lock is acquired by skb_dequeue when removing the skb */
37439@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
37440 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
37441 skb_queue_head_init(&nesqp->pau_list);
37442 spin_lock_init(&nesqp->pau_lock);
37443- atomic_inc(&pau_qps_created);
37444+ atomic_inc_unchecked(&pau_qps_created);
37445 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
37446 }
37447
37448diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
37449index 9542e16..a008c40 100644
37450--- a/drivers/infiniband/hw/nes/nes_nic.c
37451+++ b/drivers/infiniband/hw/nes/nes_nic.c
37452@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
37453 target_stat_values[++index] = mh_detected;
37454 target_stat_values[++index] = mh_pauses_sent;
37455 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
37456- target_stat_values[++index] = atomic_read(&cm_connects);
37457- target_stat_values[++index] = atomic_read(&cm_accepts);
37458- target_stat_values[++index] = atomic_read(&cm_disconnects);
37459- target_stat_values[++index] = atomic_read(&cm_connecteds);
37460- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
37461- target_stat_values[++index] = atomic_read(&cm_rejects);
37462- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
37463- target_stat_values[++index] = atomic_read(&qps_created);
37464- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
37465- target_stat_values[++index] = atomic_read(&qps_destroyed);
37466- target_stat_values[++index] = atomic_read(&cm_closes);
37467+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
37468+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
37469+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
37470+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
37471+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
37472+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
37473+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
37474+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
37475+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
37476+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
37477+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
37478 target_stat_values[++index] = cm_packets_sent;
37479 target_stat_values[++index] = cm_packets_bounced;
37480 target_stat_values[++index] = cm_packets_created;
37481 target_stat_values[++index] = cm_packets_received;
37482 target_stat_values[++index] = cm_packets_dropped;
37483 target_stat_values[++index] = cm_packets_retrans;
37484- target_stat_values[++index] = atomic_read(&cm_listens_created);
37485- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
37486+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
37487+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
37488 target_stat_values[++index] = cm_backlog_drops;
37489- target_stat_values[++index] = atomic_read(&cm_loopbacks);
37490- target_stat_values[++index] = atomic_read(&cm_nodes_created);
37491- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
37492- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
37493- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
37494+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
37495+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
37496+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
37497+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
37498+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
37499 target_stat_values[++index] = nesadapter->free_4kpbl;
37500 target_stat_values[++index] = nesadapter->free_256pbl;
37501 target_stat_values[++index] = int_mod_timer_init;
37502 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
37503 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
37504 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
37505- target_stat_values[++index] = atomic_read(&pau_qps_created);
37506- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
37507+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
37508+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
37509 }
37510
37511 /**
37512diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
37513index 07e4fba..685f041 100644
37514--- a/drivers/infiniband/hw/nes/nes_verbs.c
37515+++ b/drivers/infiniband/hw/nes/nes_verbs.c
37516@@ -46,9 +46,9 @@
37517
37518 #include <rdma/ib_umem.h>
37519
37520-atomic_t mod_qp_timouts;
37521-atomic_t qps_created;
37522-atomic_t sw_qps_destroyed;
37523+atomic_unchecked_t mod_qp_timouts;
37524+atomic_unchecked_t qps_created;
37525+atomic_unchecked_t sw_qps_destroyed;
37526
37527 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
37528
37529@@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
37530 if (init_attr->create_flags)
37531 return ERR_PTR(-EINVAL);
37532
37533- atomic_inc(&qps_created);
37534+ atomic_inc_unchecked(&qps_created);
37535 switch (init_attr->qp_type) {
37536 case IB_QPT_RC:
37537 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
37538@@ -1462,7 +1462,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
37539 struct iw_cm_event cm_event;
37540 int ret = 0;
37541
37542- atomic_inc(&sw_qps_destroyed);
37543+ atomic_inc_unchecked(&sw_qps_destroyed);
37544 nesqp->destroyed = 1;
37545
37546 /* Blow away the connection if it exists. */
37547diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
37548index 4d11575..3e890e5 100644
37549--- a/drivers/infiniband/hw/qib/qib.h
37550+++ b/drivers/infiniband/hw/qib/qib.h
37551@@ -51,6 +51,7 @@
37552 #include <linux/completion.h>
37553 #include <linux/kref.h>
37554 #include <linux/sched.h>
37555+#include <linux/slab.h>
37556
37557 #include "qib_common.h"
37558 #include "qib_verbs.h"
37559diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
37560index da739d9..da1c7f4 100644
37561--- a/drivers/input/gameport/gameport.c
37562+++ b/drivers/input/gameport/gameport.c
37563@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
37564 */
37565 static void gameport_init_port(struct gameport *gameport)
37566 {
37567- static atomic_t gameport_no = ATOMIC_INIT(0);
37568+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
37569
37570 __module_get(THIS_MODULE);
37571
37572 mutex_init(&gameport->drv_mutex);
37573 device_initialize(&gameport->dev);
37574 dev_set_name(&gameport->dev, "gameport%lu",
37575- (unsigned long)atomic_inc_return(&gameport_no) - 1);
37576+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
37577 gameport->dev.bus = &gameport_bus;
37578 gameport->dev.release = gameport_release_port;
37579 if (gameport->parent)
37580diff --git a/drivers/input/input.c b/drivers/input/input.c
37581index c044699..174d71a 100644
37582--- a/drivers/input/input.c
37583+++ b/drivers/input/input.c
37584@@ -2019,7 +2019,7 @@ static void devm_input_device_unregister(struct device *dev, void *res)
37585 */
37586 int input_register_device(struct input_dev *dev)
37587 {
37588- static atomic_t input_no = ATOMIC_INIT(0);
37589+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
37590 struct input_devres *devres = NULL;
37591 struct input_handler *handler;
37592 unsigned int packet_size;
37593@@ -2074,7 +2074,7 @@ int input_register_device(struct input_dev *dev)
37594 dev->setkeycode = input_default_setkeycode;
37595
37596 dev_set_name(&dev->dev, "input%ld",
37597- (unsigned long) atomic_inc_return(&input_no) - 1);
37598+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
37599
37600 error = device_add(&dev->dev);
37601 if (error)
37602diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
37603index 04c69af..5f92d00 100644
37604--- a/drivers/input/joystick/sidewinder.c
37605+++ b/drivers/input/joystick/sidewinder.c
37606@@ -30,6 +30,7 @@
37607 #include <linux/kernel.h>
37608 #include <linux/module.h>
37609 #include <linux/slab.h>
37610+#include <linux/sched.h>
37611 #include <linux/init.h>
37612 #include <linux/input.h>
37613 #include <linux/gameport.h>
37614diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
37615index d6cbfe9..6225402 100644
37616--- a/drivers/input/joystick/xpad.c
37617+++ b/drivers/input/joystick/xpad.c
37618@@ -735,7 +735,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
37619
37620 static int xpad_led_probe(struct usb_xpad *xpad)
37621 {
37622- static atomic_t led_seq = ATOMIC_INIT(0);
37623+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
37624 long led_no;
37625 struct xpad_led *led;
37626 struct led_classdev *led_cdev;
37627@@ -748,7 +748,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
37628 if (!led)
37629 return -ENOMEM;
37630
37631- led_no = (long)atomic_inc_return(&led_seq) - 1;
37632+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
37633
37634 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
37635 led->xpad = xpad;
37636diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
37637index fe1df23..5b710f3 100644
37638--- a/drivers/input/mouse/psmouse.h
37639+++ b/drivers/input/mouse/psmouse.h
37640@@ -115,7 +115,7 @@ struct psmouse_attribute {
37641 ssize_t (*set)(struct psmouse *psmouse, void *data,
37642 const char *buf, size_t count);
37643 bool protect;
37644-};
37645+} __do_const;
37646 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
37647
37648 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
37649diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
37650index 4c842c3..590b0bf 100644
37651--- a/drivers/input/mousedev.c
37652+++ b/drivers/input/mousedev.c
37653@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
37654
37655 spin_unlock_irq(&client->packet_lock);
37656
37657- if (copy_to_user(buffer, data, count))
37658+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
37659 return -EFAULT;
37660
37661 return count;
37662diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
37663index 25fc597..558bf3b 100644
37664--- a/drivers/input/serio/serio.c
37665+++ b/drivers/input/serio/serio.c
37666@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
37667 */
37668 static void serio_init_port(struct serio *serio)
37669 {
37670- static atomic_t serio_no = ATOMIC_INIT(0);
37671+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
37672
37673 __module_get(THIS_MODULE);
37674
37675@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
37676 mutex_init(&serio->drv_mutex);
37677 device_initialize(&serio->dev);
37678 dev_set_name(&serio->dev, "serio%ld",
37679- (long)atomic_inc_return(&serio_no) - 1);
37680+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
37681 serio->dev.bus = &serio_bus;
37682 serio->dev.release = serio_release_port;
37683 serio->dev.groups = serio_device_attr_groups;
37684diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
37685index ddbdaca..be18a78 100644
37686--- a/drivers/iommu/iommu.c
37687+++ b/drivers/iommu/iommu.c
37688@@ -554,7 +554,7 @@ static struct notifier_block iommu_bus_nb = {
37689 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
37690 {
37691 bus_register_notifier(bus, &iommu_bus_nb);
37692- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
37693+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
37694 }
37695
37696 /**
37697diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
37698index 89562a8..218999b 100644
37699--- a/drivers/isdn/capi/capi.c
37700+++ b/drivers/isdn/capi/capi.c
37701@@ -81,8 +81,8 @@ struct capiminor {
37702
37703 struct capi20_appl *ap;
37704 u32 ncci;
37705- atomic_t datahandle;
37706- atomic_t msgid;
37707+ atomic_unchecked_t datahandle;
37708+ atomic_unchecked_t msgid;
37709
37710 struct tty_port port;
37711 int ttyinstop;
37712@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
37713 capimsg_setu16(s, 2, mp->ap->applid);
37714 capimsg_setu8 (s, 4, CAPI_DATA_B3);
37715 capimsg_setu8 (s, 5, CAPI_RESP);
37716- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
37717+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
37718 capimsg_setu32(s, 8, mp->ncci);
37719 capimsg_setu16(s, 12, datahandle);
37720 }
37721@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
37722 mp->outbytes -= len;
37723 spin_unlock_bh(&mp->outlock);
37724
37725- datahandle = atomic_inc_return(&mp->datahandle);
37726+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
37727 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
37728 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
37729 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
37730 capimsg_setu16(skb->data, 2, mp->ap->applid);
37731 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
37732 capimsg_setu8 (skb->data, 5, CAPI_REQ);
37733- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
37734+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
37735 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
37736 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
37737 capimsg_setu16(skb->data, 16, len); /* Data length */
37738diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
37739index 67abf3f..076b3a6 100644
37740--- a/drivers/isdn/gigaset/interface.c
37741+++ b/drivers/isdn/gigaset/interface.c
37742@@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
37743 }
37744 tty->driver_data = cs;
37745
37746- ++cs->port.count;
37747+ atomic_inc(&cs->port.count);
37748
37749- if (cs->port.count == 1) {
37750+ if (atomic_read(&cs->port.count) == 1) {
37751 tty_port_tty_set(&cs->port, tty);
37752 tty->low_latency = 1;
37753 }
37754@@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
37755
37756 if (!cs->connected)
37757 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
37758- else if (!cs->port.count)
37759+ else if (!atomic_read(&cs->port.count))
37760 dev_warn(cs->dev, "%s: device not opened\n", __func__);
37761- else if (!--cs->port.count)
37762+ else if (!atomic_dec_return(&cs->port.count))
37763 tty_port_tty_set(&cs->port, NULL);
37764
37765 mutex_unlock(&cs->mutex);
37766diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
37767index 821f7ac..28d4030 100644
37768--- a/drivers/isdn/hardware/avm/b1.c
37769+++ b/drivers/isdn/hardware/avm/b1.c
37770@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
37771 }
37772 if (left) {
37773 if (t4file->user) {
37774- if (copy_from_user(buf, dp, left))
37775+ if (left > sizeof buf || copy_from_user(buf, dp, left))
37776 return -EFAULT;
37777 } else {
37778 memcpy(buf, dp, left);
37779@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
37780 }
37781 if (left) {
37782 if (config->user) {
37783- if (copy_from_user(buf, dp, left))
37784+ if (left > sizeof buf || copy_from_user(buf, dp, left))
37785 return -EFAULT;
37786 } else {
37787 memcpy(buf, dp, left);
37788diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
37789index e09dc8a..15e2efb 100644
37790--- a/drivers/isdn/i4l/isdn_tty.c
37791+++ b/drivers/isdn/i4l/isdn_tty.c
37792@@ -1513,9 +1513,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
37793
37794 #ifdef ISDN_DEBUG_MODEM_OPEN
37795 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
37796- port->count);
37797+ atomic_read(&port->count));
37798 #endif
37799- port->count++;
37800+ atomic_inc(&port->count);
37801 port->tty = tty;
37802 /*
37803 * Start up serial port
37804@@ -1559,7 +1559,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
37805 #endif
37806 return;
37807 }
37808- if ((tty->count == 1) && (port->count != 1)) {
37809+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
37810 /*
37811 * Uh, oh. tty->count is 1, which means that the tty
37812 * structure will be freed. Info->count should always
37813@@ -1568,15 +1568,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
37814 * serial port won't be shutdown.
37815 */
37816 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
37817- "info->count is %d\n", port->count);
37818- port->count = 1;
37819+ "info->count is %d\n", atomic_read(&port->count));
37820+ atomic_set(&port->count, 1);
37821 }
37822- if (--port->count < 0) {
37823+ if (atomic_dec_return(&port->count) < 0) {
37824 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
37825- info->line, port->count);
37826- port->count = 0;
37827+ info->line, atomic_read(&port->count));
37828+ atomic_set(&port->count, 0);
37829 }
37830- if (port->count) {
37831+ if (atomic_read(&port->count)) {
37832 #ifdef ISDN_DEBUG_MODEM_OPEN
37833 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
37834 #endif
37835@@ -1630,7 +1630,7 @@ isdn_tty_hangup(struct tty_struct *tty)
37836 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
37837 return;
37838 isdn_tty_shutdown(info);
37839- port->count = 0;
37840+ atomic_set(&port->count, 0);
37841 port->flags &= ~ASYNC_NORMAL_ACTIVE;
37842 port->tty = NULL;
37843 wake_up_interruptible(&port->open_wait);
37844@@ -1975,7 +1975,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
37845 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
37846 modem_info *info = &dev->mdm.info[i];
37847
37848- if (info->port.count == 0)
37849+ if (atomic_read(&info->port.count) == 0)
37850 continue;
37851 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
37852 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
37853diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
37854index e74df7c..03a03ba 100644
37855--- a/drivers/isdn/icn/icn.c
37856+++ b/drivers/isdn/icn/icn.c
37857@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
37858 if (count > len)
37859 count = len;
37860 if (user) {
37861- if (copy_from_user(msg, buf, count))
37862+ if (count > sizeof msg || copy_from_user(msg, buf, count))
37863 return -EFAULT;
37864 } else
37865 memcpy(msg, buf, count);
37866diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
37867index 6a8405d..0bd1c7e 100644
37868--- a/drivers/leds/leds-clevo-mail.c
37869+++ b/drivers/leds/leds-clevo-mail.c
37870@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
37871 * detected as working, but in reality it is not) as low as
37872 * possible.
37873 */
37874-static struct dmi_system_id __initdata clevo_mail_led_dmi_table[] = {
37875+static const struct dmi_system_id __initconst clevo_mail_led_dmi_table[] = {
37876 {
37877 .callback = clevo_mail_led_dmi_callback,
37878 .ident = "Clevo D410J",
37879diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
37880index ec9b287..65c9bf4 100644
37881--- a/drivers/leds/leds-ss4200.c
37882+++ b/drivers/leds/leds-ss4200.c
37883@@ -92,7 +92,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
37884 * detected as working, but in reality it is not) as low as
37885 * possible.
37886 */
37887-static struct dmi_system_id __initdata nas_led_whitelist[] = {
37888+static const struct dmi_system_id __initconst nas_led_whitelist[] = {
37889 {
37890 .callback = ss4200_led_dmi_callback,
37891 .ident = "Intel SS4200-E",
37892diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
37893index a5ebc00..982886f 100644
37894--- a/drivers/lguest/core.c
37895+++ b/drivers/lguest/core.c
37896@@ -92,9 +92,17 @@ static __init int map_switcher(void)
37897 * it's worked so far. The end address needs +1 because __get_vm_area
37898 * allocates an extra guard page, so we need space for that.
37899 */
37900+
37901+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
37902+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
37903+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
37904+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
37905+#else
37906 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
37907 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
37908 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
37909+#endif
37910+
37911 if (!switcher_vma) {
37912 err = -ENOMEM;
37913 printk("lguest: could not map switcher pages high\n");
37914@@ -119,7 +127,7 @@ static __init int map_switcher(void)
37915 * Now the Switcher is mapped at the right address, we can't fail!
37916 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
37917 */
37918- memcpy(switcher_vma->addr, start_switcher_text,
37919+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
37920 end_switcher_text - start_switcher_text);
37921
37922 printk(KERN_INFO "lguest: mapped switcher at %p\n",
37923diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
37924index 3b62be16..e33134a 100644
37925--- a/drivers/lguest/page_tables.c
37926+++ b/drivers/lguest/page_tables.c
37927@@ -532,7 +532,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
37928 /*:*/
37929
37930 #ifdef CONFIG_X86_PAE
37931-static void release_pmd(pmd_t *spmd)
37932+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
37933 {
37934 /* If the entry's not present, there's nothing to release. */
37935 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
37936diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
37937index 4af12e1..0e89afe 100644
37938--- a/drivers/lguest/x86/core.c
37939+++ b/drivers/lguest/x86/core.c
37940@@ -59,7 +59,7 @@ static struct {
37941 /* Offset from where switcher.S was compiled to where we've copied it */
37942 static unsigned long switcher_offset(void)
37943 {
37944- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
37945+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
37946 }
37947
37948 /* This cpu's struct lguest_pages. */
37949@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
37950 * These copies are pretty cheap, so we do them unconditionally: */
37951 /* Save the current Host top-level page directory.
37952 */
37953+
37954+#ifdef CONFIG_PAX_PER_CPU_PGD
37955+ pages->state.host_cr3 = read_cr3();
37956+#else
37957 pages->state.host_cr3 = __pa(current->mm->pgd);
37958+#endif
37959+
37960 /*
37961 * Set up the Guest's page tables to see this CPU's pages (and no
37962 * other CPU's pages).
37963@@ -476,7 +482,7 @@ void __init lguest_arch_host_init(void)
37964 * compiled-in switcher code and the high-mapped copy we just made.
37965 */
37966 for (i = 0; i < IDT_ENTRIES; i++)
37967- default_idt_entries[i] += switcher_offset();
37968+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
37969
37970 /*
37971 * Set up the Switcher's per-cpu areas.
37972@@ -559,7 +565,7 @@ void __init lguest_arch_host_init(void)
37973 * it will be undisturbed when we switch. To change %cs and jump we
37974 * need this structure to feed to Intel's "lcall" instruction.
37975 */
37976- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
37977+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
37978 lguest_entry.segment = LGUEST_CS;
37979
37980 /*
37981diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
37982index 40634b0..4f5855e 100644
37983--- a/drivers/lguest/x86/switcher_32.S
37984+++ b/drivers/lguest/x86/switcher_32.S
37985@@ -87,6 +87,7 @@
37986 #include <asm/page.h>
37987 #include <asm/segment.h>
37988 #include <asm/lguest.h>
37989+#include <asm/processor-flags.h>
37990
37991 // We mark the start of the code to copy
37992 // It's placed in .text tho it's never run here
37993@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
37994 // Changes type when we load it: damn Intel!
37995 // For after we switch over our page tables
37996 // That entry will be read-only: we'd crash.
37997+
37998+#ifdef CONFIG_PAX_KERNEXEC
37999+ mov %cr0, %edx
38000+ xor $X86_CR0_WP, %edx
38001+ mov %edx, %cr0
38002+#endif
38003+
38004 movl $(GDT_ENTRY_TSS*8), %edx
38005 ltr %dx
38006
38007@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
38008 // Let's clear it again for our return.
38009 // The GDT descriptor of the Host
38010 // Points to the table after two "size" bytes
38011- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
38012+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
38013 // Clear "used" from type field (byte 5, bit 2)
38014- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
38015+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
38016+
38017+#ifdef CONFIG_PAX_KERNEXEC
38018+ mov %cr0, %eax
38019+ xor $X86_CR0_WP, %eax
38020+ mov %eax, %cr0
38021+#endif
38022
38023 // Once our page table's switched, the Guest is live!
38024 // The Host fades as we run this final step.
38025@@ -295,13 +309,12 @@ deliver_to_host:
38026 // I consulted gcc, and it gave
38027 // These instructions, which I gladly credit:
38028 leal (%edx,%ebx,8), %eax
38029- movzwl (%eax),%edx
38030- movl 4(%eax), %eax
38031- xorw %ax, %ax
38032- orl %eax, %edx
38033+ movl 4(%eax), %edx
38034+ movw (%eax), %dx
38035 // Now the address of the handler's in %edx
38036 // We call it now: its "iret" drops us home.
38037- jmp *%edx
38038+ ljmp $__KERNEL_CS, $1f
38039+1: jmp *%edx
38040
38041 // Every interrupt can come to us here
38042 // But we must truly tell each apart.
38043diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
38044index 7155945..4bcc562 100644
38045--- a/drivers/md/bitmap.c
38046+++ b/drivers/md/bitmap.c
38047@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
38048 chunk_kb ? "KB" : "B");
38049 if (bitmap->storage.file) {
38050 seq_printf(seq, ", file: ");
38051- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
38052+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
38053 }
38054
38055 seq_printf(seq, "\n");
38056diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
38057index eee353d..74504c4 100644
38058--- a/drivers/md/dm-ioctl.c
38059+++ b/drivers/md/dm-ioctl.c
38060@@ -1632,7 +1632,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
38061 cmd == DM_LIST_VERSIONS_CMD)
38062 return 0;
38063
38064- if ((cmd == DM_DEV_CREATE_CMD)) {
38065+ if (cmd == DM_DEV_CREATE_CMD) {
38066 if (!*param->name) {
38067 DMWARN("name not supplied when creating device");
38068 return -EINVAL;
38069diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
38070index 7f24190..0e18099 100644
38071--- a/drivers/md/dm-raid1.c
38072+++ b/drivers/md/dm-raid1.c
38073@@ -40,7 +40,7 @@ enum dm_raid1_error {
38074
38075 struct mirror {
38076 struct mirror_set *ms;
38077- atomic_t error_count;
38078+ atomic_unchecked_t error_count;
38079 unsigned long error_type;
38080 struct dm_dev *dev;
38081 sector_t offset;
38082@@ -183,7 +183,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
38083 struct mirror *m;
38084
38085 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
38086- if (!atomic_read(&m->error_count))
38087+ if (!atomic_read_unchecked(&m->error_count))
38088 return m;
38089
38090 return NULL;
38091@@ -215,7 +215,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
38092 * simple way to tell if a device has encountered
38093 * errors.
38094 */
38095- atomic_inc(&m->error_count);
38096+ atomic_inc_unchecked(&m->error_count);
38097
38098 if (test_and_set_bit(error_type, &m->error_type))
38099 return;
38100@@ -406,7 +406,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
38101 struct mirror *m = get_default_mirror(ms);
38102
38103 do {
38104- if (likely(!atomic_read(&m->error_count)))
38105+ if (likely(!atomic_read_unchecked(&m->error_count)))
38106 return m;
38107
38108 if (m-- == ms->mirror)
38109@@ -420,7 +420,7 @@ static int default_ok(struct mirror *m)
38110 {
38111 struct mirror *default_mirror = get_default_mirror(m->ms);
38112
38113- return !atomic_read(&default_mirror->error_count);
38114+ return !atomic_read_unchecked(&default_mirror->error_count);
38115 }
38116
38117 static int mirror_available(struct mirror_set *ms, struct bio *bio)
38118@@ -557,7 +557,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
38119 */
38120 if (likely(region_in_sync(ms, region, 1)))
38121 m = choose_mirror(ms, bio->bi_sector);
38122- else if (m && atomic_read(&m->error_count))
38123+ else if (m && atomic_read_unchecked(&m->error_count))
38124 m = NULL;
38125
38126 if (likely(m))
38127@@ -924,7 +924,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
38128 }
38129
38130 ms->mirror[mirror].ms = ms;
38131- atomic_set(&(ms->mirror[mirror].error_count), 0);
38132+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
38133 ms->mirror[mirror].error_type = 0;
38134 ms->mirror[mirror].offset = offset;
38135
38136@@ -1337,7 +1337,7 @@ static void mirror_resume(struct dm_target *ti)
38137 */
38138 static char device_status_char(struct mirror *m)
38139 {
38140- if (!atomic_read(&(m->error_count)))
38141+ if (!atomic_read_unchecked(&(m->error_count)))
38142 return 'A';
38143
38144 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
38145diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
38146index aaecefa..23b3026 100644
38147--- a/drivers/md/dm-stripe.c
38148+++ b/drivers/md/dm-stripe.c
38149@@ -20,7 +20,7 @@ struct stripe {
38150 struct dm_dev *dev;
38151 sector_t physical_start;
38152
38153- atomic_t error_count;
38154+ atomic_unchecked_t error_count;
38155 };
38156
38157 struct stripe_c {
38158@@ -184,7 +184,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
38159 kfree(sc);
38160 return r;
38161 }
38162- atomic_set(&(sc->stripe[i].error_count), 0);
38163+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
38164 }
38165
38166 ti->private = sc;
38167@@ -325,7 +325,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
38168 DMEMIT("%d ", sc->stripes);
38169 for (i = 0; i < sc->stripes; i++) {
38170 DMEMIT("%s ", sc->stripe[i].dev->name);
38171- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
38172+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
38173 'D' : 'A';
38174 }
38175 buffer[i] = '\0';
38176@@ -370,8 +370,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
38177 */
38178 for (i = 0; i < sc->stripes; i++)
38179 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
38180- atomic_inc(&(sc->stripe[i].error_count));
38181- if (atomic_read(&(sc->stripe[i].error_count)) <
38182+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
38183+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
38184 DM_IO_ERROR_THRESHOLD)
38185 schedule_work(&sc->trigger_event);
38186 }
38187diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
38188index daf25d0..d74f49f 100644
38189--- a/drivers/md/dm-table.c
38190+++ b/drivers/md/dm-table.c
38191@@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
38192 if (!dev_size)
38193 return 0;
38194
38195- if ((start >= dev_size) || (start + len > dev_size)) {
38196+ if ((start >= dev_size) || (len > dev_size - start)) {
38197 DMWARN("%s: %s too small for target: "
38198 "start=%llu, len=%llu, dev_size=%llu",
38199 dm_device_name(ti->table->md), bdevname(bdev, b),
38200diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
38201index 4d6e853..a234157 100644
38202--- a/drivers/md/dm-thin-metadata.c
38203+++ b/drivers/md/dm-thin-metadata.c
38204@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
38205 {
38206 pmd->info.tm = pmd->tm;
38207 pmd->info.levels = 2;
38208- pmd->info.value_type.context = pmd->data_sm;
38209+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
38210 pmd->info.value_type.size = sizeof(__le64);
38211 pmd->info.value_type.inc = data_block_inc;
38212 pmd->info.value_type.dec = data_block_dec;
38213@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
38214
38215 pmd->bl_info.tm = pmd->tm;
38216 pmd->bl_info.levels = 1;
38217- pmd->bl_info.value_type.context = pmd->data_sm;
38218+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
38219 pmd->bl_info.value_type.size = sizeof(__le64);
38220 pmd->bl_info.value_type.inc = data_block_inc;
38221 pmd->bl_info.value_type.dec = data_block_dec;
38222diff --git a/drivers/md/dm.c b/drivers/md/dm.c
38223index 0d8f086..f5a91d5 100644
38224--- a/drivers/md/dm.c
38225+++ b/drivers/md/dm.c
38226@@ -170,9 +170,9 @@ struct mapped_device {
38227 /*
38228 * Event handling.
38229 */
38230- atomic_t event_nr;
38231+ atomic_unchecked_t event_nr;
38232 wait_queue_head_t eventq;
38233- atomic_t uevent_seq;
38234+ atomic_unchecked_t uevent_seq;
38235 struct list_head uevent_list;
38236 spinlock_t uevent_lock; /* Protect access to uevent_list */
38237
38238@@ -1872,8 +1872,8 @@ static struct mapped_device *alloc_dev(int minor)
38239 rwlock_init(&md->map_lock);
38240 atomic_set(&md->holders, 1);
38241 atomic_set(&md->open_count, 0);
38242- atomic_set(&md->event_nr, 0);
38243- atomic_set(&md->uevent_seq, 0);
38244+ atomic_set_unchecked(&md->event_nr, 0);
38245+ atomic_set_unchecked(&md->uevent_seq, 0);
38246 INIT_LIST_HEAD(&md->uevent_list);
38247 spin_lock_init(&md->uevent_lock);
38248
38249@@ -2026,7 +2026,7 @@ static void event_callback(void *context)
38250
38251 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
38252
38253- atomic_inc(&md->event_nr);
38254+ atomic_inc_unchecked(&md->event_nr);
38255 wake_up(&md->eventq);
38256 }
38257
38258@@ -2683,18 +2683,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
38259
38260 uint32_t dm_next_uevent_seq(struct mapped_device *md)
38261 {
38262- return atomic_add_return(1, &md->uevent_seq);
38263+ return atomic_add_return_unchecked(1, &md->uevent_seq);
38264 }
38265
38266 uint32_t dm_get_event_nr(struct mapped_device *md)
38267 {
38268- return atomic_read(&md->event_nr);
38269+ return atomic_read_unchecked(&md->event_nr);
38270 }
38271
38272 int dm_wait_event(struct mapped_device *md, int event_nr)
38273 {
38274 return wait_event_interruptible(md->eventq,
38275- (event_nr != atomic_read(&md->event_nr)));
38276+ (event_nr != atomic_read_unchecked(&md->event_nr)));
38277 }
38278
38279 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
38280diff --git a/drivers/md/md.c b/drivers/md/md.c
38281index f363135..9b38815 100644
38282--- a/drivers/md/md.c
38283+++ b/drivers/md/md.c
38284@@ -240,10 +240,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
38285 * start build, activate spare
38286 */
38287 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
38288-static atomic_t md_event_count;
38289+static atomic_unchecked_t md_event_count;
38290 void md_new_event(struct mddev *mddev)
38291 {
38292- atomic_inc(&md_event_count);
38293+ atomic_inc_unchecked(&md_event_count);
38294 wake_up(&md_event_waiters);
38295 }
38296 EXPORT_SYMBOL_GPL(md_new_event);
38297@@ -253,7 +253,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
38298 */
38299 static void md_new_event_inintr(struct mddev *mddev)
38300 {
38301- atomic_inc(&md_event_count);
38302+ atomic_inc_unchecked(&md_event_count);
38303 wake_up(&md_event_waiters);
38304 }
38305
38306@@ -1507,7 +1507,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
38307 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
38308 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
38309 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
38310- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
38311+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
38312
38313 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
38314 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
38315@@ -1751,7 +1751,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
38316 else
38317 sb->resync_offset = cpu_to_le64(0);
38318
38319- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
38320+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
38321
38322 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
38323 sb->size = cpu_to_le64(mddev->dev_sectors);
38324@@ -2751,7 +2751,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
38325 static ssize_t
38326 errors_show(struct md_rdev *rdev, char *page)
38327 {
38328- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
38329+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
38330 }
38331
38332 static ssize_t
38333@@ -2760,7 +2760,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
38334 char *e;
38335 unsigned long n = simple_strtoul(buf, &e, 10);
38336 if (*buf && (*e == 0 || *e == '\n')) {
38337- atomic_set(&rdev->corrected_errors, n);
38338+ atomic_set_unchecked(&rdev->corrected_errors, n);
38339 return len;
38340 }
38341 return -EINVAL;
38342@@ -3210,8 +3210,8 @@ int md_rdev_init(struct md_rdev *rdev)
38343 rdev->sb_loaded = 0;
38344 rdev->bb_page = NULL;
38345 atomic_set(&rdev->nr_pending, 0);
38346- atomic_set(&rdev->read_errors, 0);
38347- atomic_set(&rdev->corrected_errors, 0);
38348+ atomic_set_unchecked(&rdev->read_errors, 0);
38349+ atomic_set_unchecked(&rdev->corrected_errors, 0);
38350
38351 INIT_LIST_HEAD(&rdev->same_set);
38352 init_waitqueue_head(&rdev->blocked_wait);
38353@@ -6987,7 +6987,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
38354
38355 spin_unlock(&pers_lock);
38356 seq_printf(seq, "\n");
38357- seq->poll_event = atomic_read(&md_event_count);
38358+ seq->poll_event = atomic_read_unchecked(&md_event_count);
38359 return 0;
38360 }
38361 if (v == (void*)2) {
38362@@ -7090,7 +7090,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
38363 return error;
38364
38365 seq = file->private_data;
38366- seq->poll_event = atomic_read(&md_event_count);
38367+ seq->poll_event = atomic_read_unchecked(&md_event_count);
38368 return error;
38369 }
38370
38371@@ -7104,7 +7104,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
38372 /* always allow read */
38373 mask = POLLIN | POLLRDNORM;
38374
38375- if (seq->poll_event != atomic_read(&md_event_count))
38376+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
38377 mask |= POLLERR | POLLPRI;
38378 return mask;
38379 }
38380@@ -7148,7 +7148,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
38381 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
38382 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
38383 (int)part_stat_read(&disk->part0, sectors[1]) -
38384- atomic_read(&disk->sync_io);
38385+ atomic_read_unchecked(&disk->sync_io);
38386 /* sync IO will cause sync_io to increase before the disk_stats
38387 * as sync_io is counted when a request starts, and
38388 * disk_stats is counted when it completes.
38389diff --git a/drivers/md/md.h b/drivers/md/md.h
38390index eca59c3..7c42285 100644
38391--- a/drivers/md/md.h
38392+++ b/drivers/md/md.h
38393@@ -94,13 +94,13 @@ struct md_rdev {
38394 * only maintained for arrays that
38395 * support hot removal
38396 */
38397- atomic_t read_errors; /* number of consecutive read errors that
38398+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
38399 * we have tried to ignore.
38400 */
38401 struct timespec last_read_error; /* monotonic time since our
38402 * last read error
38403 */
38404- atomic_t corrected_errors; /* number of corrected read errors,
38405+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
38406 * for reporting to userspace and storing
38407 * in superblock.
38408 */
38409@@ -434,7 +434,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
38410
38411 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
38412 {
38413- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
38414+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
38415 }
38416
38417 struct md_personality
38418diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
38419index 1cbfc6b..56e1dbb 100644
38420--- a/drivers/md/persistent-data/dm-space-map.h
38421+++ b/drivers/md/persistent-data/dm-space-map.h
38422@@ -60,6 +60,7 @@ struct dm_space_map {
38423 int (*root_size)(struct dm_space_map *sm, size_t *result);
38424 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
38425 };
38426+typedef struct dm_space_map __no_const dm_space_map_no_const;
38427
38428 /*----------------------------------------------------------------*/
38429
38430diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
38431index 75b1f89..00ba344 100644
38432--- a/drivers/md/raid1.c
38433+++ b/drivers/md/raid1.c
38434@@ -1819,7 +1819,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
38435 if (r1_sync_page_io(rdev, sect, s,
38436 bio->bi_io_vec[idx].bv_page,
38437 READ) != 0)
38438- atomic_add(s, &rdev->corrected_errors);
38439+ atomic_add_unchecked(s, &rdev->corrected_errors);
38440 }
38441 sectors -= s;
38442 sect += s;
38443@@ -2041,7 +2041,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
38444 test_bit(In_sync, &rdev->flags)) {
38445 if (r1_sync_page_io(rdev, sect, s,
38446 conf->tmppage, READ)) {
38447- atomic_add(s, &rdev->corrected_errors);
38448+ atomic_add_unchecked(s, &rdev->corrected_errors);
38449 printk(KERN_INFO
38450 "md/raid1:%s: read error corrected "
38451 "(%d sectors at %llu on %s)\n",
38452diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
38453index 8d925dc..11d674f 100644
38454--- a/drivers/md/raid10.c
38455+++ b/drivers/md/raid10.c
38456@@ -1878,7 +1878,7 @@ static void end_sync_read(struct bio *bio, int error)
38457 /* The write handler will notice the lack of
38458 * R10BIO_Uptodate and record any errors etc
38459 */
38460- atomic_add(r10_bio->sectors,
38461+ atomic_add_unchecked(r10_bio->sectors,
38462 &conf->mirrors[d].rdev->corrected_errors);
38463
38464 /* for reconstruct, we always reschedule after a read.
38465@@ -2227,7 +2227,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
38466 {
38467 struct timespec cur_time_mon;
38468 unsigned long hours_since_last;
38469- unsigned int read_errors = atomic_read(&rdev->read_errors);
38470+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
38471
38472 ktime_get_ts(&cur_time_mon);
38473
38474@@ -2249,9 +2249,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
38475 * overflowing the shift of read_errors by hours_since_last.
38476 */
38477 if (hours_since_last >= 8 * sizeof(read_errors))
38478- atomic_set(&rdev->read_errors, 0);
38479+ atomic_set_unchecked(&rdev->read_errors, 0);
38480 else
38481- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
38482+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
38483 }
38484
38485 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
38486@@ -2305,8 +2305,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38487 return;
38488
38489 check_decay_read_errors(mddev, rdev);
38490- atomic_inc(&rdev->read_errors);
38491- if (atomic_read(&rdev->read_errors) > max_read_errors) {
38492+ atomic_inc_unchecked(&rdev->read_errors);
38493+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
38494 char b[BDEVNAME_SIZE];
38495 bdevname(rdev->bdev, b);
38496
38497@@ -2314,7 +2314,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38498 "md/raid10:%s: %s: Raid device exceeded "
38499 "read_error threshold [cur %d:max %d]\n",
38500 mdname(mddev), b,
38501- atomic_read(&rdev->read_errors), max_read_errors);
38502+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
38503 printk(KERN_NOTICE
38504 "md/raid10:%s: %s: Failing raid device\n",
38505 mdname(mddev), b);
38506@@ -2469,7 +2469,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38507 sect +
38508 choose_data_offset(r10_bio, rdev)),
38509 bdevname(rdev->bdev, b));
38510- atomic_add(s, &rdev->corrected_errors);
38511+ atomic_add_unchecked(s, &rdev->corrected_errors);
38512 }
38513
38514 rdev_dec_pending(rdev, mddev);
38515diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
38516index 94ce78e..df99e24 100644
38517--- a/drivers/md/raid5.c
38518+++ b/drivers/md/raid5.c
38519@@ -1800,21 +1800,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
38520 mdname(conf->mddev), STRIPE_SECTORS,
38521 (unsigned long long)s,
38522 bdevname(rdev->bdev, b));
38523- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
38524+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
38525 clear_bit(R5_ReadError, &sh->dev[i].flags);
38526 clear_bit(R5_ReWrite, &sh->dev[i].flags);
38527 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
38528 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
38529
38530- if (atomic_read(&rdev->read_errors))
38531- atomic_set(&rdev->read_errors, 0);
38532+ if (atomic_read_unchecked(&rdev->read_errors))
38533+ atomic_set_unchecked(&rdev->read_errors, 0);
38534 } else {
38535 const char *bdn = bdevname(rdev->bdev, b);
38536 int retry = 0;
38537 int set_bad = 0;
38538
38539 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
38540- atomic_inc(&rdev->read_errors);
38541+ atomic_inc_unchecked(&rdev->read_errors);
38542 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
38543 printk_ratelimited(
38544 KERN_WARNING
38545@@ -1842,7 +1842,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
38546 mdname(conf->mddev),
38547 (unsigned long long)s,
38548 bdn);
38549- } else if (atomic_read(&rdev->read_errors)
38550+ } else if (atomic_read_unchecked(&rdev->read_errors)
38551 > conf->max_nr_stripes)
38552 printk(KERN_WARNING
38553 "md/raid:%s: Too many read errors, failing device %s.\n",
38554diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
38555index d33101a..6b13069 100644
38556--- a/drivers/media/dvb-core/dvbdev.c
38557+++ b/drivers/media/dvb-core/dvbdev.c
38558@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
38559 const struct dvb_device *template, void *priv, int type)
38560 {
38561 struct dvb_device *dvbdev;
38562- struct file_operations *dvbdevfops;
38563+ file_operations_no_const *dvbdevfops;
38564 struct device *clsdev;
38565 int minor;
38566 int id;
38567diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
38568index 404f63a..4796533 100644
38569--- a/drivers/media/dvb-frontends/dib3000.h
38570+++ b/drivers/media/dvb-frontends/dib3000.h
38571@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
38572 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
38573 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
38574 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
38575-};
38576+} __no_const;
38577
38578 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
38579 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
38580diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
38581index bc78354..42c9459 100644
38582--- a/drivers/media/pci/cx88/cx88-video.c
38583+++ b/drivers/media/pci/cx88/cx88-video.c
38584@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
38585
38586 /* ------------------------------------------------------------------ */
38587
38588-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38589-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38590-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38591+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38592+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38593+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38594
38595 module_param_array(video_nr, int, NULL, 0444);
38596 module_param_array(vbi_nr, int, NULL, 0444);
38597diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
38598index 8e9a668..78d6310 100644
38599--- a/drivers/media/platform/omap/omap_vout.c
38600+++ b/drivers/media/platform/omap/omap_vout.c
38601@@ -63,7 +63,6 @@ enum omap_vout_channels {
38602 OMAP_VIDEO2,
38603 };
38604
38605-static struct videobuf_queue_ops video_vbq_ops;
38606 /* Variables configurable through module params*/
38607 static u32 video1_numbuffers = 3;
38608 static u32 video2_numbuffers = 3;
38609@@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
38610 {
38611 struct videobuf_queue *q;
38612 struct omap_vout_device *vout = NULL;
38613+ static struct videobuf_queue_ops video_vbq_ops = {
38614+ .buf_setup = omap_vout_buffer_setup,
38615+ .buf_prepare = omap_vout_buffer_prepare,
38616+ .buf_release = omap_vout_buffer_release,
38617+ .buf_queue = omap_vout_buffer_queue,
38618+ };
38619
38620 vout = video_drvdata(file);
38621 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
38622@@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
38623 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
38624
38625 q = &vout->vbq;
38626- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
38627- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
38628- video_vbq_ops.buf_release = omap_vout_buffer_release;
38629- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
38630 spin_lock_init(&vout->vbq_lock);
38631
38632 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
38633diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
38634index b671e20..34088b7 100644
38635--- a/drivers/media/platform/s5p-tv/mixer.h
38636+++ b/drivers/media/platform/s5p-tv/mixer.h
38637@@ -155,7 +155,7 @@ struct mxr_layer {
38638 /** layer index (unique identifier) */
38639 int idx;
38640 /** callbacks for layer methods */
38641- struct mxr_layer_ops ops;
38642+ struct mxr_layer_ops *ops;
38643 /** format array */
38644 const struct mxr_format **fmt_array;
38645 /** size of format array */
38646diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38647index b93a21f..2535195 100644
38648--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38649+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38650@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
38651 {
38652 struct mxr_layer *layer;
38653 int ret;
38654- struct mxr_layer_ops ops = {
38655+ static struct mxr_layer_ops ops = {
38656 .release = mxr_graph_layer_release,
38657 .buffer_set = mxr_graph_buffer_set,
38658 .stream_set = mxr_graph_stream_set,
38659diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
38660index 3b1670a..595c939 100644
38661--- a/drivers/media/platform/s5p-tv/mixer_reg.c
38662+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
38663@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
38664 layer->update_buf = next;
38665 }
38666
38667- layer->ops.buffer_set(layer, layer->update_buf);
38668+ layer->ops->buffer_set(layer, layer->update_buf);
38669
38670 if (done && done != layer->shadow_buf)
38671 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
38672diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
38673index 1f3b743..e839271 100644
38674--- a/drivers/media/platform/s5p-tv/mixer_video.c
38675+++ b/drivers/media/platform/s5p-tv/mixer_video.c
38676@@ -208,7 +208,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
38677 layer->geo.src.height = layer->geo.src.full_height;
38678
38679 mxr_geometry_dump(mdev, &layer->geo);
38680- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38681+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38682 mxr_geometry_dump(mdev, &layer->geo);
38683 }
38684
38685@@ -226,7 +226,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
38686 layer->geo.dst.full_width = mbus_fmt.width;
38687 layer->geo.dst.full_height = mbus_fmt.height;
38688 layer->geo.dst.field = mbus_fmt.field;
38689- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38690+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38691
38692 mxr_geometry_dump(mdev, &layer->geo);
38693 }
38694@@ -332,7 +332,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
38695 /* set source size to highest accepted value */
38696 geo->src.full_width = max(geo->dst.full_width, pix->width);
38697 geo->src.full_height = max(geo->dst.full_height, pix->height);
38698- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38699+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38700 mxr_geometry_dump(mdev, &layer->geo);
38701 /* set cropping to total visible screen */
38702 geo->src.width = pix->width;
38703@@ -340,12 +340,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
38704 geo->src.x_offset = 0;
38705 geo->src.y_offset = 0;
38706 /* assure consistency of geometry */
38707- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
38708+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
38709 mxr_geometry_dump(mdev, &layer->geo);
38710 /* set full size to lowest possible value */
38711 geo->src.full_width = 0;
38712 geo->src.full_height = 0;
38713- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38714+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38715 mxr_geometry_dump(mdev, &layer->geo);
38716
38717 /* returning results */
38718@@ -472,7 +472,7 @@ static int mxr_s_selection(struct file *file, void *fh,
38719 target->width = s->r.width;
38720 target->height = s->r.height;
38721
38722- layer->ops.fix_geometry(layer, stage, s->flags);
38723+ layer->ops->fix_geometry(layer, stage, s->flags);
38724
38725 /* retrieve update selection rectangle */
38726 res.left = target->x_offset;
38727@@ -937,13 +937,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
38728 mxr_output_get(mdev);
38729
38730 mxr_layer_update_output(layer);
38731- layer->ops.format_set(layer);
38732+ layer->ops->format_set(layer);
38733 /* enabling layer in hardware */
38734 spin_lock_irqsave(&layer->enq_slock, flags);
38735 layer->state = MXR_LAYER_STREAMING;
38736 spin_unlock_irqrestore(&layer->enq_slock, flags);
38737
38738- layer->ops.stream_set(layer, MXR_ENABLE);
38739+ layer->ops->stream_set(layer, MXR_ENABLE);
38740 mxr_streamer_get(mdev);
38741
38742 return 0;
38743@@ -1013,7 +1013,7 @@ static int stop_streaming(struct vb2_queue *vq)
38744 spin_unlock_irqrestore(&layer->enq_slock, flags);
38745
38746 /* disabling layer in hardware */
38747- layer->ops.stream_set(layer, MXR_DISABLE);
38748+ layer->ops->stream_set(layer, MXR_DISABLE);
38749 /* remove one streamer */
38750 mxr_streamer_put(mdev);
38751 /* allow changes in output configuration */
38752@@ -1052,8 +1052,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
38753
38754 void mxr_layer_release(struct mxr_layer *layer)
38755 {
38756- if (layer->ops.release)
38757- layer->ops.release(layer);
38758+ if (layer->ops->release)
38759+ layer->ops->release(layer);
38760 }
38761
38762 void mxr_base_layer_release(struct mxr_layer *layer)
38763@@ -1079,7 +1079,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
38764
38765 layer->mdev = mdev;
38766 layer->idx = idx;
38767- layer->ops = *ops;
38768+ layer->ops = ops;
38769
38770 spin_lock_init(&layer->enq_slock);
38771 INIT_LIST_HEAD(&layer->enq_list);
38772diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
38773index 3d13a63..da31bf1 100644
38774--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
38775+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
38776@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
38777 {
38778 struct mxr_layer *layer;
38779 int ret;
38780- struct mxr_layer_ops ops = {
38781+ static struct mxr_layer_ops ops = {
38782 .release = mxr_vp_layer_release,
38783 .buffer_set = mxr_vp_buffer_set,
38784 .stream_set = mxr_vp_stream_set,
38785diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
38786index 643d80a..56bb96b 100644
38787--- a/drivers/media/radio/radio-cadet.c
38788+++ b/drivers/media/radio/radio-cadet.c
38789@@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
38790 unsigned char readbuf[RDS_BUFFER];
38791 int i = 0;
38792
38793+ if (count > RDS_BUFFER)
38794+ return -EFAULT;
38795 mutex_lock(&dev->lock);
38796 if (dev->rdsstat == 0)
38797 cadet_start_rds(dev);
38798@@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
38799 while (i < count && dev->rdsin != dev->rdsout)
38800 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
38801
38802- if (i && copy_to_user(data, readbuf, i))
38803+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
38804 i = -EFAULT;
38805 unlock:
38806 mutex_unlock(&dev->lock);
38807diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
38808index 3940bb0..fb3952a 100644
38809--- a/drivers/media/usb/dvb-usb/cxusb.c
38810+++ b/drivers/media/usb/dvb-usb/cxusb.c
38811@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
38812
38813 struct dib0700_adapter_state {
38814 int (*set_param_save) (struct dvb_frontend *);
38815-};
38816+} __no_const;
38817
38818 static int dib7070_set_param_override(struct dvb_frontend *fe)
38819 {
38820diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
38821index 9382895..ac8093c 100644
38822--- a/drivers/media/usb/dvb-usb/dw2102.c
38823+++ b/drivers/media/usb/dvb-usb/dw2102.c
38824@@ -95,7 +95,7 @@ struct su3000_state {
38825
38826 struct s6x0_state {
38827 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
38828-};
38829+} __no_const;
38830
38831 /* debug */
38832 static int dvb_usb_dw2102_debug;
38833diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
38834index aa6e7c7..4cd8061 100644
38835--- a/drivers/media/v4l2-core/v4l2-ioctl.c
38836+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
38837@@ -1923,7 +1923,8 @@ struct v4l2_ioctl_info {
38838 struct file *file, void *fh, void *p);
38839 } u;
38840 void (*debug)(const void *arg, bool write_only);
38841-};
38842+} __do_const;
38843+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
38844
38845 /* This control needs a priority check */
38846 #define INFO_FL_PRIO (1 << 0)
38847@@ -2108,7 +2109,7 @@ static long __video_do_ioctl(struct file *file,
38848 struct video_device *vfd = video_devdata(file);
38849 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
38850 bool write_only = false;
38851- struct v4l2_ioctl_info default_info;
38852+ v4l2_ioctl_info_no_const default_info;
38853 const struct v4l2_ioctl_info *info;
38854 void *fh = file->private_data;
38855 struct v4l2_fh *vfh = NULL;
38856diff --git a/drivers/memstick/host/r592.c b/drivers/memstick/host/r592.c
38857index 29b2172..a7c5b31 100644
38858--- a/drivers/memstick/host/r592.c
38859+++ b/drivers/memstick/host/r592.c
38860@@ -454,7 +454,7 @@ static int r592_transfer_fifo_pio(struct r592_device *dev)
38861 /* Executes one TPC (data is read/written from small or large fifo) */
38862 static void r592_execute_tpc(struct r592_device *dev)
38863 {
38864- bool is_write = dev->req->tpc >= MS_TPC_SET_RW_REG_ADRS;
38865+ bool is_write;
38866 int len, error;
38867 u32 status, reg;
38868
38869@@ -463,6 +463,7 @@ static void r592_execute_tpc(struct r592_device *dev)
38870 return;
38871 }
38872
38873+ is_write = dev->req->tpc >= MS_TPC_SET_RW_REG_ADRS;
38874 len = dev->req->long_data ?
38875 dev->req->sg.length : dev->req->data_len;
38876
38877diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
38878index fb69baa..3aeea2e 100644
38879--- a/drivers/message/fusion/mptbase.c
38880+++ b/drivers/message/fusion/mptbase.c
38881@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
38882 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
38883 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
38884
38885+#ifdef CONFIG_GRKERNSEC_HIDESYM
38886+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
38887+#else
38888 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
38889 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
38890+#endif
38891+
38892 /*
38893 * Rounding UP to nearest 4-kB boundary here...
38894 */
38895@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
38896 ioc->facts.GlobalCredits);
38897
38898 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
38899+#ifdef CONFIG_GRKERNSEC_HIDESYM
38900+ NULL, NULL);
38901+#else
38902 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
38903+#endif
38904 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
38905 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
38906 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
38907diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
38908index fa43c39..daeb158 100644
38909--- a/drivers/message/fusion/mptsas.c
38910+++ b/drivers/message/fusion/mptsas.c
38911@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
38912 return 0;
38913 }
38914
38915+static inline void
38916+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
38917+{
38918+ if (phy_info->port_details) {
38919+ phy_info->port_details->rphy = rphy;
38920+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
38921+ ioc->name, rphy));
38922+ }
38923+
38924+ if (rphy) {
38925+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
38926+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
38927+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
38928+ ioc->name, rphy, rphy->dev.release));
38929+ }
38930+}
38931+
38932 /* no mutex */
38933 static void
38934 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
38935@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
38936 return NULL;
38937 }
38938
38939-static inline void
38940-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
38941-{
38942- if (phy_info->port_details) {
38943- phy_info->port_details->rphy = rphy;
38944- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
38945- ioc->name, rphy));
38946- }
38947-
38948- if (rphy) {
38949- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
38950- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
38951- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
38952- ioc->name, rphy, rphy->dev.release));
38953- }
38954-}
38955-
38956 static inline struct sas_port *
38957 mptsas_get_port(struct mptsas_phyinfo *phy_info)
38958 {
38959diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
38960index 164afa7..b6b2e74 100644
38961--- a/drivers/message/fusion/mptscsih.c
38962+++ b/drivers/message/fusion/mptscsih.c
38963@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
38964
38965 h = shost_priv(SChost);
38966
38967- if (h) {
38968- if (h->info_kbuf == NULL)
38969- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
38970- return h->info_kbuf;
38971- h->info_kbuf[0] = '\0';
38972+ if (!h)
38973+ return NULL;
38974
38975- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
38976- h->info_kbuf[size-1] = '\0';
38977- }
38978+ if (h->info_kbuf == NULL)
38979+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
38980+ return h->info_kbuf;
38981+ h->info_kbuf[0] = '\0';
38982+
38983+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
38984+ h->info_kbuf[size-1] = '\0';
38985
38986 return h->info_kbuf;
38987 }
38988diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
38989index 8001aa6..b137580 100644
38990--- a/drivers/message/i2o/i2o_proc.c
38991+++ b/drivers/message/i2o/i2o_proc.c
38992@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
38993 "Array Controller Device"
38994 };
38995
38996-static char *chtostr(char *tmp, u8 *chars, int n)
38997-{
38998- tmp[0] = 0;
38999- return strncat(tmp, (char *)chars, n);
39000-}
39001-
39002 static int i2o_report_query_status(struct seq_file *seq, int block_status,
39003 char *group)
39004 {
39005@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
39006 } *result;
39007
39008 i2o_exec_execute_ddm_table ddm_table;
39009- char tmp[28 + 1];
39010
39011 result = kmalloc(sizeof(*result), GFP_KERNEL);
39012 if (!result)
39013@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
39014
39015 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
39016 seq_printf(seq, "%-#8x", ddm_table.module_id);
39017- seq_printf(seq, "%-29s",
39018- chtostr(tmp, ddm_table.module_name_version, 28));
39019+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
39020 seq_printf(seq, "%9d ", ddm_table.data_size);
39021 seq_printf(seq, "%8d", ddm_table.code_size);
39022
39023@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
39024
39025 i2o_driver_result_table *result;
39026 i2o_driver_store_table *dst;
39027- char tmp[28 + 1];
39028
39029 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
39030 if (result == NULL)
39031@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
39032
39033 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
39034 seq_printf(seq, "%-#8x", dst->module_id);
39035- seq_printf(seq, "%-29s",
39036- chtostr(tmp, dst->module_name_version, 28));
39037- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
39038+ seq_printf(seq, "%-.28s", dst->module_name_version);
39039+ seq_printf(seq, "%-.8s", dst->date);
39040 seq_printf(seq, "%8d ", dst->module_size);
39041 seq_printf(seq, "%8d ", dst->mpb_size);
39042 seq_printf(seq, "0x%04x", dst->module_flags);
39043@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
39044 // == (allow) 512d bytes (max)
39045 static u16 *work16 = (u16 *) work32;
39046 int token;
39047- char tmp[16 + 1];
39048
39049 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
39050
39051@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
39052 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
39053 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
39054 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
39055- seq_printf(seq, "Vendor info : %s\n",
39056- chtostr(tmp, (u8 *) (work32 + 2), 16));
39057- seq_printf(seq, "Product info : %s\n",
39058- chtostr(tmp, (u8 *) (work32 + 6), 16));
39059- seq_printf(seq, "Description : %s\n",
39060- chtostr(tmp, (u8 *) (work32 + 10), 16));
39061- seq_printf(seq, "Product rev. : %s\n",
39062- chtostr(tmp, (u8 *) (work32 + 14), 8));
39063+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
39064+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
39065+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
39066+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
39067
39068 seq_printf(seq, "Serial number : ");
39069 print_serial_number(seq, (u8 *) (work32 + 16),
39070@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
39071 u8 pad[256]; // allow up to 256 byte (max) serial number
39072 } result;
39073
39074- char tmp[24 + 1];
39075-
39076 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
39077
39078 if (token < 0) {
39079@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
39080 }
39081
39082 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
39083- seq_printf(seq, "Module name : %s\n",
39084- chtostr(tmp, result.module_name, 24));
39085- seq_printf(seq, "Module revision : %s\n",
39086- chtostr(tmp, result.module_rev, 8));
39087+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
39088+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
39089
39090 seq_printf(seq, "Serial number : ");
39091 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
39092@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
39093 u8 instance_number[4];
39094 } result;
39095
39096- char tmp[64 + 1];
39097-
39098 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
39099
39100 if (token < 0) {
39101@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
39102 return 0;
39103 }
39104
39105- seq_printf(seq, "Device name : %s\n",
39106- chtostr(tmp, result.device_name, 64));
39107- seq_printf(seq, "Service name : %s\n",
39108- chtostr(tmp, result.service_name, 64));
39109- seq_printf(seq, "Physical name : %s\n",
39110- chtostr(tmp, result.physical_location, 64));
39111- seq_printf(seq, "Instance number : %s\n",
39112- chtostr(tmp, result.instance_number, 4));
39113+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
39114+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
39115+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
39116+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
39117
39118 return 0;
39119 }
39120diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
39121index a8c08f3..155fe3d 100644
39122--- a/drivers/message/i2o/iop.c
39123+++ b/drivers/message/i2o/iop.c
39124@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
39125
39126 spin_lock_irqsave(&c->context_list_lock, flags);
39127
39128- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
39129- atomic_inc(&c->context_list_counter);
39130+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
39131+ atomic_inc_unchecked(&c->context_list_counter);
39132
39133- entry->context = atomic_read(&c->context_list_counter);
39134+ entry->context = atomic_read_unchecked(&c->context_list_counter);
39135
39136 list_add(&entry->list, &c->context_list);
39137
39138@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
39139
39140 #if BITS_PER_LONG == 64
39141 spin_lock_init(&c->context_list_lock);
39142- atomic_set(&c->context_list_counter, 0);
39143+ atomic_set_unchecked(&c->context_list_counter, 0);
39144 INIT_LIST_HEAD(&c->context_list);
39145 #endif
39146
39147diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
39148index 45ece11..8efa218 100644
39149--- a/drivers/mfd/janz-cmodio.c
39150+++ b/drivers/mfd/janz-cmodio.c
39151@@ -13,6 +13,7 @@
39152
39153 #include <linux/kernel.h>
39154 #include <linux/module.h>
39155+#include <linux/slab.h>
39156 #include <linux/init.h>
39157 #include <linux/pci.h>
39158 #include <linux/interrupt.h>
39159diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
39160index a5f9888..1c0ed56 100644
39161--- a/drivers/mfd/twl4030-irq.c
39162+++ b/drivers/mfd/twl4030-irq.c
39163@@ -35,6 +35,7 @@
39164 #include <linux/of.h>
39165 #include <linux/irqdomain.h>
39166 #include <linux/i2c/twl.h>
39167+#include <asm/pgtable.h>
39168
39169 #include "twl-core.h"
39170
39171@@ -728,10 +729,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
39172 * Install an irq handler for each of the SIH modules;
39173 * clone dummy irq_chip since PIH can't *do* anything
39174 */
39175- twl4030_irq_chip = dummy_irq_chip;
39176- twl4030_irq_chip.name = "twl4030";
39177+ pax_open_kernel();
39178+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
39179+ *(const char **)&twl4030_irq_chip.name = "twl4030";
39180
39181- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
39182+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
39183+ pax_close_kernel();
39184
39185 for (i = irq_base; i < irq_end; i++) {
39186 irq_set_chip_and_handler(i, &twl4030_irq_chip,
39187diff --git a/drivers/mfd/twl6030-irq.c b/drivers/mfd/twl6030-irq.c
39188index 277a8db..0e0b754 100644
39189--- a/drivers/mfd/twl6030-irq.c
39190+++ b/drivers/mfd/twl6030-irq.c
39191@@ -387,10 +387,12 @@ int twl6030_init_irq(struct device *dev, int irq_num)
39192 * install an irq handler for each of the modules;
39193 * clone dummy irq_chip since PIH can't *do* anything
39194 */
39195- twl6030_irq_chip = dummy_irq_chip;
39196- twl6030_irq_chip.name = "twl6030";
39197- twl6030_irq_chip.irq_set_type = NULL;
39198- twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
39199+ pax_open_kernel();
39200+ memcpy((void *)&twl6030_irq_chip, &dummy_irq_chip, sizeof twl6030_irq_chip);
39201+ *(const char **)&twl6030_irq_chip.name = "twl6030";
39202+ *(void **)&twl6030_irq_chip.irq_set_type = NULL;
39203+ *(void **)&twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
39204+ pax_close_kernel();
39205
39206 for (i = irq_base; i < irq_end; i++) {
39207 irq_set_chip_and_handler(i, &twl6030_irq_chip,
39208diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
39209index f428d86..274c368 100644
39210--- a/drivers/misc/c2port/core.c
39211+++ b/drivers/misc/c2port/core.c
39212@@ -924,7 +924,9 @@ struct c2port_device *c2port_device_register(char *name,
39213 mutex_init(&c2dev->mutex);
39214
39215 /* Create binary file */
39216- c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
39217+ pax_open_kernel();
39218+ *(size_t *)&c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
39219+ pax_close_kernel();
39220 ret = device_create_bin_file(c2dev->dev, &c2port_bin_attrs);
39221 if (unlikely(ret))
39222 goto error_device_create_bin_file;
39223diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
39224index 3aa9a96..59cf685 100644
39225--- a/drivers/misc/kgdbts.c
39226+++ b/drivers/misc/kgdbts.c
39227@@ -832,7 +832,7 @@ static void run_plant_and_detach_test(int is_early)
39228 char before[BREAK_INSTR_SIZE];
39229 char after[BREAK_INSTR_SIZE];
39230
39231- probe_kernel_read(before, (char *)kgdbts_break_test,
39232+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
39233 BREAK_INSTR_SIZE);
39234 init_simple_test();
39235 ts.tst = plant_and_detach_test;
39236@@ -840,7 +840,7 @@ static void run_plant_and_detach_test(int is_early)
39237 /* Activate test with initial breakpoint */
39238 if (!is_early)
39239 kgdb_breakpoint();
39240- probe_kernel_read(after, (char *)kgdbts_break_test,
39241+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
39242 BREAK_INSTR_SIZE);
39243 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
39244 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
39245diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
39246index 4a87e5c..76bdf5c 100644
39247--- a/drivers/misc/lis3lv02d/lis3lv02d.c
39248+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
39249@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
39250 * the lid is closed. This leads to interrupts as soon as a little move
39251 * is done.
39252 */
39253- atomic_inc(&lis3->count);
39254+ atomic_inc_unchecked(&lis3->count);
39255
39256 wake_up_interruptible(&lis3->misc_wait);
39257 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
39258@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
39259 if (lis3->pm_dev)
39260 pm_runtime_get_sync(lis3->pm_dev);
39261
39262- atomic_set(&lis3->count, 0);
39263+ atomic_set_unchecked(&lis3->count, 0);
39264 return 0;
39265 }
39266
39267@@ -617,7 +617,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
39268 add_wait_queue(&lis3->misc_wait, &wait);
39269 while (true) {
39270 set_current_state(TASK_INTERRUPTIBLE);
39271- data = atomic_xchg(&lis3->count, 0);
39272+ data = atomic_xchg_unchecked(&lis3->count, 0);
39273 if (data)
39274 break;
39275
39276@@ -658,7 +658,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
39277 struct lis3lv02d, miscdev);
39278
39279 poll_wait(file, &lis3->misc_wait, wait);
39280- if (atomic_read(&lis3->count))
39281+ if (atomic_read_unchecked(&lis3->count))
39282 return POLLIN | POLLRDNORM;
39283 return 0;
39284 }
39285diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
39286index c439c82..1f20f57 100644
39287--- a/drivers/misc/lis3lv02d/lis3lv02d.h
39288+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
39289@@ -297,7 +297,7 @@ struct lis3lv02d {
39290 struct input_polled_dev *idev; /* input device */
39291 struct platform_device *pdev; /* platform device */
39292 struct regulator_bulk_data regulators[2];
39293- atomic_t count; /* interrupt count after last read */
39294+ atomic_unchecked_t count; /* interrupt count after last read */
39295 union axis_conversion ac; /* hw -> logical axis */
39296 int mapped_btns[3];
39297
39298diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
39299index 2f30bad..c4c13d0 100644
39300--- a/drivers/misc/sgi-gru/gruhandles.c
39301+++ b/drivers/misc/sgi-gru/gruhandles.c
39302@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
39303 unsigned long nsec;
39304
39305 nsec = CLKS2NSEC(clks);
39306- atomic_long_inc(&mcs_op_statistics[op].count);
39307- atomic_long_add(nsec, &mcs_op_statistics[op].total);
39308+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
39309+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
39310 if (mcs_op_statistics[op].max < nsec)
39311 mcs_op_statistics[op].max = nsec;
39312 }
39313diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
39314index 950dbe9..eeef0f8 100644
39315--- a/drivers/misc/sgi-gru/gruprocfs.c
39316+++ b/drivers/misc/sgi-gru/gruprocfs.c
39317@@ -32,9 +32,9 @@
39318
39319 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
39320
39321-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
39322+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
39323 {
39324- unsigned long val = atomic_long_read(v);
39325+ unsigned long val = atomic_long_read_unchecked(v);
39326
39327 seq_printf(s, "%16lu %s\n", val, id);
39328 }
39329@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
39330
39331 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
39332 for (op = 0; op < mcsop_last; op++) {
39333- count = atomic_long_read(&mcs_op_statistics[op].count);
39334- total = atomic_long_read(&mcs_op_statistics[op].total);
39335+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
39336+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
39337 max = mcs_op_statistics[op].max;
39338 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
39339 count ? total / count : 0, max);
39340diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
39341index 5c3ce24..4915ccb 100644
39342--- a/drivers/misc/sgi-gru/grutables.h
39343+++ b/drivers/misc/sgi-gru/grutables.h
39344@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
39345 * GRU statistics.
39346 */
39347 struct gru_stats_s {
39348- atomic_long_t vdata_alloc;
39349- atomic_long_t vdata_free;
39350- atomic_long_t gts_alloc;
39351- atomic_long_t gts_free;
39352- atomic_long_t gms_alloc;
39353- atomic_long_t gms_free;
39354- atomic_long_t gts_double_allocate;
39355- atomic_long_t assign_context;
39356- atomic_long_t assign_context_failed;
39357- atomic_long_t free_context;
39358- atomic_long_t load_user_context;
39359- atomic_long_t load_kernel_context;
39360- atomic_long_t lock_kernel_context;
39361- atomic_long_t unlock_kernel_context;
39362- atomic_long_t steal_user_context;
39363- atomic_long_t steal_kernel_context;
39364- atomic_long_t steal_context_failed;
39365- atomic_long_t nopfn;
39366- atomic_long_t asid_new;
39367- atomic_long_t asid_next;
39368- atomic_long_t asid_wrap;
39369- atomic_long_t asid_reuse;
39370- atomic_long_t intr;
39371- atomic_long_t intr_cbr;
39372- atomic_long_t intr_tfh;
39373- atomic_long_t intr_spurious;
39374- atomic_long_t intr_mm_lock_failed;
39375- atomic_long_t call_os;
39376- atomic_long_t call_os_wait_queue;
39377- atomic_long_t user_flush_tlb;
39378- atomic_long_t user_unload_context;
39379- atomic_long_t user_exception;
39380- atomic_long_t set_context_option;
39381- atomic_long_t check_context_retarget_intr;
39382- atomic_long_t check_context_unload;
39383- atomic_long_t tlb_dropin;
39384- atomic_long_t tlb_preload_page;
39385- atomic_long_t tlb_dropin_fail_no_asid;
39386- atomic_long_t tlb_dropin_fail_upm;
39387- atomic_long_t tlb_dropin_fail_invalid;
39388- atomic_long_t tlb_dropin_fail_range_active;
39389- atomic_long_t tlb_dropin_fail_idle;
39390- atomic_long_t tlb_dropin_fail_fmm;
39391- atomic_long_t tlb_dropin_fail_no_exception;
39392- atomic_long_t tfh_stale_on_fault;
39393- atomic_long_t mmu_invalidate_range;
39394- atomic_long_t mmu_invalidate_page;
39395- atomic_long_t flush_tlb;
39396- atomic_long_t flush_tlb_gru;
39397- atomic_long_t flush_tlb_gru_tgh;
39398- atomic_long_t flush_tlb_gru_zero_asid;
39399+ atomic_long_unchecked_t vdata_alloc;
39400+ atomic_long_unchecked_t vdata_free;
39401+ atomic_long_unchecked_t gts_alloc;
39402+ atomic_long_unchecked_t gts_free;
39403+ atomic_long_unchecked_t gms_alloc;
39404+ atomic_long_unchecked_t gms_free;
39405+ atomic_long_unchecked_t gts_double_allocate;
39406+ atomic_long_unchecked_t assign_context;
39407+ atomic_long_unchecked_t assign_context_failed;
39408+ atomic_long_unchecked_t free_context;
39409+ atomic_long_unchecked_t load_user_context;
39410+ atomic_long_unchecked_t load_kernel_context;
39411+ atomic_long_unchecked_t lock_kernel_context;
39412+ atomic_long_unchecked_t unlock_kernel_context;
39413+ atomic_long_unchecked_t steal_user_context;
39414+ atomic_long_unchecked_t steal_kernel_context;
39415+ atomic_long_unchecked_t steal_context_failed;
39416+ atomic_long_unchecked_t nopfn;
39417+ atomic_long_unchecked_t asid_new;
39418+ atomic_long_unchecked_t asid_next;
39419+ atomic_long_unchecked_t asid_wrap;
39420+ atomic_long_unchecked_t asid_reuse;
39421+ atomic_long_unchecked_t intr;
39422+ atomic_long_unchecked_t intr_cbr;
39423+ atomic_long_unchecked_t intr_tfh;
39424+ atomic_long_unchecked_t intr_spurious;
39425+ atomic_long_unchecked_t intr_mm_lock_failed;
39426+ atomic_long_unchecked_t call_os;
39427+ atomic_long_unchecked_t call_os_wait_queue;
39428+ atomic_long_unchecked_t user_flush_tlb;
39429+ atomic_long_unchecked_t user_unload_context;
39430+ atomic_long_unchecked_t user_exception;
39431+ atomic_long_unchecked_t set_context_option;
39432+ atomic_long_unchecked_t check_context_retarget_intr;
39433+ atomic_long_unchecked_t check_context_unload;
39434+ atomic_long_unchecked_t tlb_dropin;
39435+ atomic_long_unchecked_t tlb_preload_page;
39436+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
39437+ atomic_long_unchecked_t tlb_dropin_fail_upm;
39438+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
39439+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
39440+ atomic_long_unchecked_t tlb_dropin_fail_idle;
39441+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
39442+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
39443+ atomic_long_unchecked_t tfh_stale_on_fault;
39444+ atomic_long_unchecked_t mmu_invalidate_range;
39445+ atomic_long_unchecked_t mmu_invalidate_page;
39446+ atomic_long_unchecked_t flush_tlb;
39447+ atomic_long_unchecked_t flush_tlb_gru;
39448+ atomic_long_unchecked_t flush_tlb_gru_tgh;
39449+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
39450
39451- atomic_long_t copy_gpa;
39452- atomic_long_t read_gpa;
39453+ atomic_long_unchecked_t copy_gpa;
39454+ atomic_long_unchecked_t read_gpa;
39455
39456- atomic_long_t mesq_receive;
39457- atomic_long_t mesq_receive_none;
39458- atomic_long_t mesq_send;
39459- atomic_long_t mesq_send_failed;
39460- atomic_long_t mesq_noop;
39461- atomic_long_t mesq_send_unexpected_error;
39462- atomic_long_t mesq_send_lb_overflow;
39463- atomic_long_t mesq_send_qlimit_reached;
39464- atomic_long_t mesq_send_amo_nacked;
39465- atomic_long_t mesq_send_put_nacked;
39466- atomic_long_t mesq_page_overflow;
39467- atomic_long_t mesq_qf_locked;
39468- atomic_long_t mesq_qf_noop_not_full;
39469- atomic_long_t mesq_qf_switch_head_failed;
39470- atomic_long_t mesq_qf_unexpected_error;
39471- atomic_long_t mesq_noop_unexpected_error;
39472- atomic_long_t mesq_noop_lb_overflow;
39473- atomic_long_t mesq_noop_qlimit_reached;
39474- atomic_long_t mesq_noop_amo_nacked;
39475- atomic_long_t mesq_noop_put_nacked;
39476- atomic_long_t mesq_noop_page_overflow;
39477+ atomic_long_unchecked_t mesq_receive;
39478+ atomic_long_unchecked_t mesq_receive_none;
39479+ atomic_long_unchecked_t mesq_send;
39480+ atomic_long_unchecked_t mesq_send_failed;
39481+ atomic_long_unchecked_t mesq_noop;
39482+ atomic_long_unchecked_t mesq_send_unexpected_error;
39483+ atomic_long_unchecked_t mesq_send_lb_overflow;
39484+ atomic_long_unchecked_t mesq_send_qlimit_reached;
39485+ atomic_long_unchecked_t mesq_send_amo_nacked;
39486+ atomic_long_unchecked_t mesq_send_put_nacked;
39487+ atomic_long_unchecked_t mesq_page_overflow;
39488+ atomic_long_unchecked_t mesq_qf_locked;
39489+ atomic_long_unchecked_t mesq_qf_noop_not_full;
39490+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
39491+ atomic_long_unchecked_t mesq_qf_unexpected_error;
39492+ atomic_long_unchecked_t mesq_noop_unexpected_error;
39493+ atomic_long_unchecked_t mesq_noop_lb_overflow;
39494+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
39495+ atomic_long_unchecked_t mesq_noop_amo_nacked;
39496+ atomic_long_unchecked_t mesq_noop_put_nacked;
39497+ atomic_long_unchecked_t mesq_noop_page_overflow;
39498
39499 };
39500
39501@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
39502 tghop_invalidate, mcsop_last};
39503
39504 struct mcs_op_statistic {
39505- atomic_long_t count;
39506- atomic_long_t total;
39507+ atomic_long_unchecked_t count;
39508+ atomic_long_unchecked_t total;
39509 unsigned long max;
39510 };
39511
39512@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
39513
39514 #define STAT(id) do { \
39515 if (gru_options & OPT_STATS) \
39516- atomic_long_inc(&gru_stats.id); \
39517+ atomic_long_inc_unchecked(&gru_stats.id); \
39518 } while (0)
39519
39520 #ifdef CONFIG_SGI_GRU_DEBUG
39521diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
39522index c862cd4..0d176fe 100644
39523--- a/drivers/misc/sgi-xp/xp.h
39524+++ b/drivers/misc/sgi-xp/xp.h
39525@@ -288,7 +288,7 @@ struct xpc_interface {
39526 xpc_notify_func, void *);
39527 void (*received) (short, int, void *);
39528 enum xp_retval (*partid_to_nasids) (short, void *);
39529-};
39530+} __no_const;
39531
39532 extern struct xpc_interface xpc_interface;
39533
39534diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
39535index b94d5f7..7f494c5 100644
39536--- a/drivers/misc/sgi-xp/xpc.h
39537+++ b/drivers/misc/sgi-xp/xpc.h
39538@@ -835,6 +835,7 @@ struct xpc_arch_operations {
39539 void (*received_payload) (struct xpc_channel *, void *);
39540 void (*notify_senders_of_disconnect) (struct xpc_channel *);
39541 };
39542+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
39543
39544 /* struct xpc_partition act_state values (for XPC HB) */
39545
39546@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
39547 /* found in xpc_main.c */
39548 extern struct device *xpc_part;
39549 extern struct device *xpc_chan;
39550-extern struct xpc_arch_operations xpc_arch_ops;
39551+extern xpc_arch_operations_no_const xpc_arch_ops;
39552 extern int xpc_disengage_timelimit;
39553 extern int xpc_disengage_timedout;
39554 extern int xpc_activate_IRQ_rcvd;
39555diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
39556index d971817..33bdca5 100644
39557--- a/drivers/misc/sgi-xp/xpc_main.c
39558+++ b/drivers/misc/sgi-xp/xpc_main.c
39559@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
39560 .notifier_call = xpc_system_die,
39561 };
39562
39563-struct xpc_arch_operations xpc_arch_ops;
39564+xpc_arch_operations_no_const xpc_arch_ops;
39565
39566 /*
39567 * Timer function to enforce the timelimit on the partition disengage.
39568@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
39569
39570 if (((die_args->trapnr == X86_TRAP_MF) ||
39571 (die_args->trapnr == X86_TRAP_XF)) &&
39572- !user_mode_vm(die_args->regs))
39573+ !user_mode(die_args->regs))
39574 xpc_die_deactivate();
39575
39576 break;
39577diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
39578index 6d8f701..35b6369 100644
39579--- a/drivers/mmc/core/mmc_ops.c
39580+++ b/drivers/mmc/core/mmc_ops.c
39581@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
39582 void *data_buf;
39583 int is_on_stack;
39584
39585- is_on_stack = object_is_on_stack(buf);
39586+ is_on_stack = object_starts_on_stack(buf);
39587 if (is_on_stack) {
39588 /*
39589 * dma onto stack is unsafe/nonportable, but callers to this
39590diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
39591index 53b8fd9..615b462 100644
39592--- a/drivers/mmc/host/dw_mmc.h
39593+++ b/drivers/mmc/host/dw_mmc.h
39594@@ -205,5 +205,5 @@ struct dw_mci_drv_data {
39595 int (*parse_dt)(struct dw_mci *host);
39596 int (*setup_bus)(struct dw_mci *host,
39597 struct device_node *slot_np, u8 bus_width);
39598-};
39599+} __do_const;
39600 #endif /* _DW_MMC_H_ */
39601diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
39602index 82a8de1..3c56ccb 100644
39603--- a/drivers/mmc/host/sdhci-s3c.c
39604+++ b/drivers/mmc/host/sdhci-s3c.c
39605@@ -721,9 +721,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
39606 * we can use overriding functions instead of default.
39607 */
39608 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
39609- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
39610- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
39611- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
39612+ pax_open_kernel();
39613+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
39614+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
39615+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
39616+ pax_close_kernel();
39617 }
39618
39619 /* It supports additional host capabilities if needed */
39620diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
39621index a4eb8b5..8c0628f 100644
39622--- a/drivers/mtd/devices/doc2000.c
39623+++ b/drivers/mtd/devices/doc2000.c
39624@@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
39625
39626 /* The ECC will not be calculated correctly if less than 512 is written */
39627 /* DBB-
39628- if (len != 0x200 && eccbuf)
39629+ if (len != 0x200)
39630 printk(KERN_WARNING
39631 "ECC needs a full sector write (adr: %lx size %lx)\n",
39632 (long) to, (long) len);
39633diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
39634index 0c8bb6b..6f35deb 100644
39635--- a/drivers/mtd/nand/denali.c
39636+++ b/drivers/mtd/nand/denali.c
39637@@ -24,6 +24,7 @@
39638 #include <linux/slab.h>
39639 #include <linux/mtd/mtd.h>
39640 #include <linux/module.h>
39641+#include <linux/slab.h>
39642
39643 #include "denali.h"
39644
39645diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
39646index 51b9d6a..52af9a7 100644
39647--- a/drivers/mtd/nftlmount.c
39648+++ b/drivers/mtd/nftlmount.c
39649@@ -24,6 +24,7 @@
39650 #include <asm/errno.h>
39651 #include <linux/delay.h>
39652 #include <linux/slab.h>
39653+#include <linux/sched.h>
39654 #include <linux/mtd/mtd.h>
39655 #include <linux/mtd/nand.h>
39656 #include <linux/mtd/nftl.h>
39657diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
39658index 8dd6ba5..419cc1d 100644
39659--- a/drivers/mtd/sm_ftl.c
39660+++ b/drivers/mtd/sm_ftl.c
39661@@ -56,7 +56,7 @@ ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
39662 #define SM_CIS_VENDOR_OFFSET 0x59
39663 struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
39664 {
39665- struct attribute_group *attr_group;
39666+ attribute_group_no_const *attr_group;
39667 struct attribute **attributes;
39668 struct sm_sysfs_attribute *vendor_attribute;
39669
39670diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
39671index 27cdf1f..8c37357 100644
39672--- a/drivers/net/bonding/bond_main.c
39673+++ b/drivers/net/bonding/bond_main.c
39674@@ -4859,7 +4859,7 @@ static unsigned int bond_get_num_tx_queues(void)
39675 return tx_queues;
39676 }
39677
39678-static struct rtnl_link_ops bond_link_ops __read_mostly = {
39679+static struct rtnl_link_ops bond_link_ops = {
39680 .kind = "bond",
39681 .priv_size = sizeof(struct bonding),
39682 .setup = bond_setup,
39683@@ -4975,8 +4975,8 @@ static void __exit bonding_exit(void)
39684
39685 bond_destroy_debugfs();
39686
39687- rtnl_link_unregister(&bond_link_ops);
39688 unregister_pernet_subsys(&bond_net_ops);
39689+ rtnl_link_unregister(&bond_link_ops);
39690
39691 #ifdef CONFIG_NET_POLL_CONTROLLER
39692 /*
39693diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
39694index 70dba5d..11a0919 100644
39695--- a/drivers/net/ethernet/8390/ax88796.c
39696+++ b/drivers/net/ethernet/8390/ax88796.c
39697@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
39698 if (ax->plat->reg_offsets)
39699 ei_local->reg_offset = ax->plat->reg_offsets;
39700 else {
39701+ resource_size_t _mem_size = mem_size;
39702+ do_div(_mem_size, 0x18);
39703 ei_local->reg_offset = ax->reg_offsets;
39704 for (ret = 0; ret < 0x18; ret++)
39705- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
39706+ ax->reg_offsets[ret] = _mem_size * ret;
39707 }
39708
39709 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
39710diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
39711index 0991534..8098e92 100644
39712--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
39713+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
39714@@ -1094,7 +1094,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
39715 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
39716 {
39717 /* RX_MODE controlling object */
39718- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
39719+ bnx2x_init_rx_mode_obj(bp);
39720
39721 /* multicast configuration controlling object */
39722 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
39723diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c
39724index 10bc093..a2fb42a 100644
39725--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c
39726+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c
39727@@ -2136,12 +2136,12 @@ static u8 bnx2x_dcbnl_get_cap(struct net_device *netdev, int capid, u8 *cap)
39728 break;
39729 default:
39730 BNX2X_ERR("Non valid capability ID\n");
39731- rval = -EINVAL;
39732+ rval = 1;
39733 break;
39734 }
39735 } else {
39736 DP(BNX2X_MSG_DCB, "DCB disabled\n");
39737- rval = -EINVAL;
39738+ rval = 1;
39739 }
39740
39741 DP(BNX2X_MSG_DCB, "capid %d:%x\n", capid, *cap);
39742@@ -2167,12 +2167,12 @@ static int bnx2x_dcbnl_get_numtcs(struct net_device *netdev, int tcid, u8 *num)
39743 break;
39744 default:
39745 BNX2X_ERR("Non valid TC-ID\n");
39746- rval = -EINVAL;
39747+ rval = 1;
39748 break;
39749 }
39750 } else {
39751 DP(BNX2X_MSG_DCB, "DCB disabled\n");
39752- rval = -EINVAL;
39753+ rval = 1;
39754 }
39755
39756 return rval;
39757@@ -2185,7 +2185,7 @@ static int bnx2x_dcbnl_set_numtcs(struct net_device *netdev, int tcid, u8 num)
39758 return -EINVAL;
39759 }
39760
39761-static u8 bnx2x_dcbnl_get_pfc_state(struct net_device *netdev)
39762+static u8 bnx2x_dcbnl_get_pfc_state(struct net_device *netdev)
39763 {
39764 struct bnx2x *bp = netdev_priv(netdev);
39765 DP(BNX2X_MSG_DCB, "state = %d\n", bp->dcbx_local_feat.pfc.enabled);
39766@@ -2387,12 +2387,12 @@ static u8 bnx2x_dcbnl_get_featcfg(struct net_device *netdev, int featid,
39767 break;
39768 default:
39769 BNX2X_ERR("Non valid featrue-ID\n");
39770- rval = -EINVAL;
39771+ rval = 1;
39772 break;
39773 }
39774 } else {
39775 DP(BNX2X_MSG_DCB, "DCB disabled\n");
39776- rval = -EINVAL;
39777+ rval = 1;
39778 }
39779
39780 return rval;
39781@@ -2428,12 +2428,12 @@ static u8 bnx2x_dcbnl_set_featcfg(struct net_device *netdev, int featid,
39782 break;
39783 default:
39784 BNX2X_ERR("Non valid featrue-ID\n");
39785- rval = -EINVAL;
39786+ rval = 1;
39787 break;
39788 }
39789 } else {
39790 DP(BNX2X_MSG_DCB, "dcbnl call not valid\n");
39791- rval = -EINVAL;
39792+ rval = 1;
39793 }
39794
39795 return rval;
39796diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
39797index 5523da3..4fcf274 100644
39798--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
39799+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
39800@@ -4767,7 +4767,7 @@ static void bnx2x_after_function_update(struct bnx2x *bp)
39801 q);
39802 }
39803
39804- if (!NO_FCOE(bp)) {
39805+ if (!NO_FCOE(bp) && CNIC_ENABLED(bp)) {
39806 fp = &bp->fp[FCOE_IDX(bp)];
39807 queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
39808
39809@@ -13047,6 +13047,7 @@ static int bnx2x_unregister_cnic(struct net_device *dev)
39810 RCU_INIT_POINTER(bp->cnic_ops, NULL);
39811 mutex_unlock(&bp->cnic_mutex);
39812 synchronize_rcu();
39813+ bp->cnic_enabled = false;
39814 kfree(bp->cnic_kwq);
39815 bp->cnic_kwq = NULL;
39816
39817diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
39818index 09b625e..15b16fe 100644
39819--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
39820+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
39821@@ -2375,15 +2375,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
39822 return rc;
39823 }
39824
39825-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
39826- struct bnx2x_rx_mode_obj *o)
39827+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
39828 {
39829 if (CHIP_IS_E1x(bp)) {
39830- o->wait_comp = bnx2x_empty_rx_mode_wait;
39831- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
39832+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
39833+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
39834 } else {
39835- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
39836- o->config_rx_mode = bnx2x_set_rx_mode_e2;
39837+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
39838+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
39839 }
39840 }
39841
39842diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
39843index adbd91b..58ec94a 100644
39844--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
39845+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
39846@@ -1293,8 +1293,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
39847
39848 /********************* RX MODE ****************/
39849
39850-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
39851- struct bnx2x_rx_mode_obj *o);
39852+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
39853
39854 /**
39855 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
39856diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
39857index d330e81..ce1fb9a 100644
39858--- a/drivers/net/ethernet/broadcom/tg3.h
39859+++ b/drivers/net/ethernet/broadcom/tg3.h
39860@@ -146,6 +146,7 @@
39861 #define CHIPREV_ID_5750_A0 0x4000
39862 #define CHIPREV_ID_5750_A1 0x4001
39863 #define CHIPREV_ID_5750_A3 0x4003
39864+#define CHIPREV_ID_5750_C1 0x4201
39865 #define CHIPREV_ID_5750_C2 0x4202
39866 #define CHIPREV_ID_5752_A0_HW 0x5000
39867 #define CHIPREV_ID_5752_A0 0x6000
39868diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
39869index 8cffcdf..aadf043 100644
39870--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
39871+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
39872@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
39873 */
39874 struct l2t_skb_cb {
39875 arp_failure_handler_func arp_failure_handler;
39876-};
39877+} __no_const;
39878
39879 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
39880
39881diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
39882index 4c83003..2a2a5b9 100644
39883--- a/drivers/net/ethernet/dec/tulip/de4x5.c
39884+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
39885@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
39886 for (i=0; i<ETH_ALEN; i++) {
39887 tmp.addr[i] = dev->dev_addr[i];
39888 }
39889- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
39890+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
39891 break;
39892
39893 case DE4X5_SET_HWADDR: /* Set the hardware address */
39894@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
39895 spin_lock_irqsave(&lp->lock, flags);
39896 memcpy(&statbuf, &lp->pktStats, ioc->len);
39897 spin_unlock_irqrestore(&lp->lock, flags);
39898- if (copy_to_user(ioc->data, &statbuf, ioc->len))
39899+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
39900 return -EFAULT;
39901 break;
39902 }
39903diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
39904index 4d6f3c5..449bc5c 100644
39905--- a/drivers/net/ethernet/emulex/benet/be_main.c
39906+++ b/drivers/net/ethernet/emulex/benet/be_main.c
39907@@ -455,7 +455,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
39908
39909 if (wrapped)
39910 newacc += 65536;
39911- ACCESS_ONCE(*acc) = newacc;
39912+ ACCESS_ONCE_RW(*acc) = newacc;
39913 }
39914
39915 void be_parse_stats(struct be_adapter *adapter)
39916@@ -759,8 +759,9 @@ static struct sk_buff *be_insert_vlan_in_pkt(struct be_adapter *adapter,
39917
39918 if (vlan_tx_tag_present(skb)) {
39919 vlan_tag = be_get_tx_vlan_tag(adapter, skb);
39920- __vlan_put_tag(skb, vlan_tag);
39921- skb->vlan_tci = 0;
39922+ skb = __vlan_put_tag(skb, vlan_tag);
39923+ if (skb)
39924+ skb->vlan_tci = 0;
39925 }
39926
39927 return skb;
39928diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
39929index 74d749e..eefb1bd 100644
39930--- a/drivers/net/ethernet/faraday/ftgmac100.c
39931+++ b/drivers/net/ethernet/faraday/ftgmac100.c
39932@@ -31,6 +31,8 @@
39933 #include <linux/netdevice.h>
39934 #include <linux/phy.h>
39935 #include <linux/platform_device.h>
39936+#include <linux/interrupt.h>
39937+#include <linux/irqreturn.h>
39938 #include <net/ip.h>
39939
39940 #include "ftgmac100.h"
39941diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
39942index b901a01..1ff32ee 100644
39943--- a/drivers/net/ethernet/faraday/ftmac100.c
39944+++ b/drivers/net/ethernet/faraday/ftmac100.c
39945@@ -31,6 +31,8 @@
39946 #include <linux/module.h>
39947 #include <linux/netdevice.h>
39948 #include <linux/platform_device.h>
39949+#include <linux/interrupt.h>
39950+#include <linux/irqreturn.h>
39951
39952 #include "ftmac100.h"
39953
39954diff --git a/drivers/net/ethernet/intel/e100.c b/drivers/net/ethernet/intel/e100.c
39955index a59f077..7925d77 100644
39956--- a/drivers/net/ethernet/intel/e100.c
39957+++ b/drivers/net/ethernet/intel/e100.c
39958@@ -870,7 +870,7 @@ err_unlock:
39959 }
39960
39961 static int e100_exec_cb(struct nic *nic, struct sk_buff *skb,
39962- void (*cb_prepare)(struct nic *, struct cb *, struct sk_buff *))
39963+ int (*cb_prepare)(struct nic *, struct cb *, struct sk_buff *))
39964 {
39965 struct cb *cb;
39966 unsigned long flags;
39967@@ -888,10 +888,13 @@ static int e100_exec_cb(struct nic *nic, struct sk_buff *skb,
39968 nic->cbs_avail--;
39969 cb->skb = skb;
39970
39971+ err = cb_prepare(nic, cb, skb);
39972+ if (err)
39973+ goto err_unlock;
39974+
39975 if (unlikely(!nic->cbs_avail))
39976 err = -ENOSPC;
39977
39978- cb_prepare(nic, cb, skb);
39979
39980 /* Order is important otherwise we'll be in a race with h/w:
39981 * set S-bit in current first, then clear S-bit in previous. */
39982@@ -1091,7 +1094,7 @@ static void e100_get_defaults(struct nic *nic)
39983 nic->mii.mdio_write = mdio_write;
39984 }
39985
39986-static void e100_configure(struct nic *nic, struct cb *cb, struct sk_buff *skb)
39987+static int e100_configure(struct nic *nic, struct cb *cb, struct sk_buff *skb)
39988 {
39989 struct config *config = &cb->u.config;
39990 u8 *c = (u8 *)config;
39991@@ -1181,6 +1184,7 @@ static void e100_configure(struct nic *nic, struct cb *cb, struct sk_buff *skb)
39992 netif_printk(nic, hw, KERN_DEBUG, nic->netdev,
39993 "[16-23]=%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
39994 c[16], c[17], c[18], c[19], c[20], c[21], c[22], c[23]);
39995+ return 0;
39996 }
39997
39998 /*************************************************************************
39999@@ -1331,7 +1335,7 @@ static const struct firmware *e100_request_firmware(struct nic *nic)
40000 return fw;
40001 }
40002
40003-static void e100_setup_ucode(struct nic *nic, struct cb *cb,
40004+static int e100_setup_ucode(struct nic *nic, struct cb *cb,
40005 struct sk_buff *skb)
40006 {
40007 const struct firmware *fw = (void *)skb;
40008@@ -1358,6 +1362,7 @@ static void e100_setup_ucode(struct nic *nic, struct cb *cb,
40009 cb->u.ucode[min_size] |= cpu_to_le32((BUNDLESMALL) ? 0xFFFF : 0xFF80);
40010
40011 cb->command = cpu_to_le16(cb_ucode | cb_el);
40012+ return 0;
40013 }
40014
40015 static inline int e100_load_ucode_wait(struct nic *nic)
40016@@ -1400,18 +1405,20 @@ static inline int e100_load_ucode_wait(struct nic *nic)
40017 return err;
40018 }
40019
40020-static void e100_setup_iaaddr(struct nic *nic, struct cb *cb,
40021+static int e100_setup_iaaddr(struct nic *nic, struct cb *cb,
40022 struct sk_buff *skb)
40023 {
40024 cb->command = cpu_to_le16(cb_iaaddr);
40025 memcpy(cb->u.iaaddr, nic->netdev->dev_addr, ETH_ALEN);
40026+ return 0;
40027 }
40028
40029-static void e100_dump(struct nic *nic, struct cb *cb, struct sk_buff *skb)
40030+static int e100_dump(struct nic *nic, struct cb *cb, struct sk_buff *skb)
40031 {
40032 cb->command = cpu_to_le16(cb_dump);
40033 cb->u.dump_buffer_addr = cpu_to_le32(nic->dma_addr +
40034 offsetof(struct mem, dump_buf));
40035+ return 0;
40036 }
40037
40038 static int e100_phy_check_without_mii(struct nic *nic)
40039@@ -1581,7 +1588,7 @@ static int e100_hw_init(struct nic *nic)
40040 return 0;
40041 }
40042
40043-static void e100_multi(struct nic *nic, struct cb *cb, struct sk_buff *skb)
40044+static int e100_multi(struct nic *nic, struct cb *cb, struct sk_buff *skb)
40045 {
40046 struct net_device *netdev = nic->netdev;
40047 struct netdev_hw_addr *ha;
40048@@ -1596,6 +1603,7 @@ static void e100_multi(struct nic *nic, struct cb *cb, struct sk_buff *skb)
40049 memcpy(&cb->u.multi.addr[i++ * ETH_ALEN], &ha->addr,
40050 ETH_ALEN);
40051 }
40052+ return 0;
40053 }
40054
40055 static void e100_set_multicast_list(struct net_device *netdev)
40056@@ -1756,11 +1764,18 @@ static void e100_watchdog(unsigned long data)
40057 round_jiffies(jiffies + E100_WATCHDOG_PERIOD));
40058 }
40059
40060-static void e100_xmit_prepare(struct nic *nic, struct cb *cb,
40061+static int e100_xmit_prepare(struct nic *nic, struct cb *cb,
40062 struct sk_buff *skb)
40063 {
40064+ dma_addr_t dma_addr;
40065 cb->command = nic->tx_command;
40066
40067+ dma_addr = pci_map_single(nic->pdev,
40068+ skb->data, skb->len, PCI_DMA_TODEVICE);
40069+ /* If we can't map the skb, have the upper layer try later */
40070+ if (pci_dma_mapping_error(nic->pdev, dma_addr))
40071+ return -ENOMEM;
40072+
40073 /*
40074 * Use the last 4 bytes of the SKB payload packet as the CRC, used for
40075 * testing, ie sending frames with bad CRC.
40076@@ -1777,11 +1792,10 @@ static void e100_xmit_prepare(struct nic *nic, struct cb *cb,
40077 cb->u.tcb.tcb_byte_count = 0;
40078 cb->u.tcb.threshold = nic->tx_threshold;
40079 cb->u.tcb.tbd_count = 1;
40080- cb->u.tcb.tbd.buf_addr = cpu_to_le32(pci_map_single(nic->pdev,
40081- skb->data, skb->len, PCI_DMA_TODEVICE));
40082- /* check for mapping failure? */
40083+ cb->u.tcb.tbd.buf_addr = cpu_to_le32(dma_addr);
40084 cb->u.tcb.tbd.size = cpu_to_le16(skb->len);
40085 skb_tx_timestamp(skb);
40086+ return 0;
40087 }
40088
40089 static netdev_tx_t e100_xmit_frame(struct sk_buff *skb,
40090diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
40091index bb9256a..56d8752 100644
40092--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
40093+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
40094@@ -806,7 +806,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
40095 }
40096
40097 /* update the base incval used to calculate frequency adjustment */
40098- ACCESS_ONCE(adapter->base_incval) = incval;
40099+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
40100 smp_mb();
40101
40102 /* need lock to prevent incorrect read while modifying cyclecounter */
40103diff --git a/drivers/net/ethernet/lantiq_etop.c b/drivers/net/ethernet/lantiq_etop.c
40104index c124e67..db9b897 100644
40105--- a/drivers/net/ethernet/lantiq_etop.c
40106+++ b/drivers/net/ethernet/lantiq_etop.c
40107@@ -769,7 +769,7 @@ ltq_etop_probe(struct platform_device *pdev)
40108 return 0;
40109
40110 err_free:
40111- kfree(dev);
40112+ free_netdev(dev);
40113 err_out:
40114 return err;
40115 }
40116diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
40117index fbe5363..266b4e3 100644
40118--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
40119+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
40120@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
40121 struct __vxge_hw_fifo *fifo;
40122 struct vxge_hw_fifo_config *config;
40123 u32 txdl_size, txdl_per_memblock;
40124- struct vxge_hw_mempool_cbs fifo_mp_callback;
40125+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
40126+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
40127+ };
40128+
40129 struct __vxge_hw_virtualpath *vpath;
40130
40131 if ((vp == NULL) || (attr == NULL)) {
40132@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
40133 goto exit;
40134 }
40135
40136- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
40137-
40138 fifo->mempool =
40139 __vxge_hw_mempool_create(vpath->hldev,
40140 fifo->config->memblock_size,
40141diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
40142index 2d849da..23bba3b 100644
40143--- a/drivers/net/ethernet/realtek/r8169.c
40144+++ b/drivers/net/ethernet/realtek/r8169.c
40145@@ -741,22 +741,22 @@ struct rtl8169_private {
40146 struct mdio_ops {
40147 void (*write)(struct rtl8169_private *, int, int);
40148 int (*read)(struct rtl8169_private *, int);
40149- } mdio_ops;
40150+ } __no_const mdio_ops;
40151
40152 struct pll_power_ops {
40153 void (*down)(struct rtl8169_private *);
40154 void (*up)(struct rtl8169_private *);
40155- } pll_power_ops;
40156+ } __no_const pll_power_ops;
40157
40158 struct jumbo_ops {
40159 void (*enable)(struct rtl8169_private *);
40160 void (*disable)(struct rtl8169_private *);
40161- } jumbo_ops;
40162+ } __no_const jumbo_ops;
40163
40164 struct csi_ops {
40165 void (*write)(struct rtl8169_private *, int, int);
40166 u32 (*read)(struct rtl8169_private *, int);
40167- } csi_ops;
40168+ } __no_const csi_ops;
40169
40170 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
40171 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
40172diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
40173index 3f93624..cf01144 100644
40174--- a/drivers/net/ethernet/sfc/ptp.c
40175+++ b/drivers/net/ethernet/sfc/ptp.c
40176@@ -553,7 +553,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
40177 (u32)((u64)ptp->start.dma_addr >> 32));
40178
40179 /* Clear flag that signals MC ready */
40180- ACCESS_ONCE(*start) = 0;
40181+ ACCESS_ONCE_RW(*start) = 0;
40182 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
40183 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
40184
40185diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
40186index 0c74a70..3bc6f68 100644
40187--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
40188+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
40189@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
40190
40191 writel(value, ioaddr + MMC_CNTRL);
40192
40193- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
40194- MMC_CNTRL, value);
40195+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
40196+// MMC_CNTRL, value);
40197 }
40198
40199 /* To mask all all interrupts.*/
40200diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
40201index e6fe0d8..2b7d752 100644
40202--- a/drivers/net/hyperv/hyperv_net.h
40203+++ b/drivers/net/hyperv/hyperv_net.h
40204@@ -101,7 +101,7 @@ struct rndis_device {
40205
40206 enum rndis_device_state state;
40207 bool link_state;
40208- atomic_t new_req_id;
40209+ atomic_unchecked_t new_req_id;
40210
40211 spinlock_t request_lock;
40212 struct list_head req_list;
40213diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
40214index 2b657d4..9903bc0 100644
40215--- a/drivers/net/hyperv/rndis_filter.c
40216+++ b/drivers/net/hyperv/rndis_filter.c
40217@@ -107,7 +107,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
40218 * template
40219 */
40220 set = &rndis_msg->msg.set_req;
40221- set->req_id = atomic_inc_return(&dev->new_req_id);
40222+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
40223
40224 /* Add to the request list */
40225 spin_lock_irqsave(&dev->request_lock, flags);
40226@@ -758,7 +758,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
40227
40228 /* Setup the rndis set */
40229 halt = &request->request_msg.msg.halt_req;
40230- halt->req_id = atomic_inc_return(&dev->new_req_id);
40231+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
40232
40233 /* Ignore return since this msg is optional. */
40234 rndis_filter_send_request(dev, request);
40235diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
40236index 1e9cb0b..7839125 100644
40237--- a/drivers/net/ieee802154/fakehard.c
40238+++ b/drivers/net/ieee802154/fakehard.c
40239@@ -386,7 +386,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
40240 phy->transmit_power = 0xbf;
40241
40242 dev->netdev_ops = &fake_ops;
40243- dev->ml_priv = &fake_mlme;
40244+ dev->ml_priv = (void *)&fake_mlme;
40245
40246 priv = netdev_priv(dev);
40247 priv->phy = phy;
40248diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
40249index e5cb723..1fc0461 100644
40250--- a/drivers/net/macvlan.c
40251+++ b/drivers/net/macvlan.c
40252@@ -852,13 +852,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
40253 int macvlan_link_register(struct rtnl_link_ops *ops)
40254 {
40255 /* common fields */
40256- ops->priv_size = sizeof(struct macvlan_dev);
40257- ops->validate = macvlan_validate;
40258- ops->maxtype = IFLA_MACVLAN_MAX;
40259- ops->policy = macvlan_policy;
40260- ops->changelink = macvlan_changelink;
40261- ops->get_size = macvlan_get_size;
40262- ops->fill_info = macvlan_fill_info;
40263+ pax_open_kernel();
40264+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
40265+ *(void **)&ops->validate = macvlan_validate;
40266+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
40267+ *(const void **)&ops->policy = macvlan_policy;
40268+ *(void **)&ops->changelink = macvlan_changelink;
40269+ *(void **)&ops->get_size = macvlan_get_size;
40270+ *(void **)&ops->fill_info = macvlan_fill_info;
40271+ pax_close_kernel();
40272
40273 return rtnl_link_register(ops);
40274 };
40275@@ -914,7 +916,7 @@ static int macvlan_device_event(struct notifier_block *unused,
40276 return NOTIFY_DONE;
40277 }
40278
40279-static struct notifier_block macvlan_notifier_block __read_mostly = {
40280+static struct notifier_block macvlan_notifier_block = {
40281 .notifier_call = macvlan_device_event,
40282 };
40283
40284diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
40285index 0f0f9ce..0ca5819 100644
40286--- a/drivers/net/macvtap.c
40287+++ b/drivers/net/macvtap.c
40288@@ -1100,7 +1100,7 @@ static int macvtap_device_event(struct notifier_block *unused,
40289 return NOTIFY_DONE;
40290 }
40291
40292-static struct notifier_block macvtap_notifier_block __read_mostly = {
40293+static struct notifier_block macvtap_notifier_block = {
40294 .notifier_call = macvtap_device_event,
40295 };
40296
40297diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
40298index daec9b0..6428fcb 100644
40299--- a/drivers/net/phy/mdio-bitbang.c
40300+++ b/drivers/net/phy/mdio-bitbang.c
40301@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
40302 struct mdiobb_ctrl *ctrl = bus->priv;
40303
40304 module_put(ctrl->ops->owner);
40305+ mdiobus_unregister(bus);
40306 mdiobus_free(bus);
40307 }
40308 EXPORT_SYMBOL(free_mdio_bitbang);
40309diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
40310index 508570e..f706dc7 100644
40311--- a/drivers/net/ppp/ppp_generic.c
40312+++ b/drivers/net/ppp/ppp_generic.c
40313@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40314 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
40315 struct ppp_stats stats;
40316 struct ppp_comp_stats cstats;
40317- char *vers;
40318
40319 switch (cmd) {
40320 case SIOCGPPPSTATS:
40321@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40322 break;
40323
40324 case SIOCGPPPVER:
40325- vers = PPP_VERSION;
40326- if (copy_to_user(addr, vers, strlen(vers) + 1))
40327+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
40328 break;
40329 err = 0;
40330 break;
40331diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
40332index 8efe47a..a8075c5 100644
40333--- a/drivers/net/team/team.c
40334+++ b/drivers/net/team/team.c
40335@@ -2603,7 +2603,7 @@ static int team_device_event(struct notifier_block *unused,
40336 return NOTIFY_DONE;
40337 }
40338
40339-static struct notifier_block team_notifier_block __read_mostly = {
40340+static struct notifier_block team_notifier_block = {
40341 .notifier_call = team_device_event,
40342 };
40343
40344diff --git a/drivers/net/tun.c b/drivers/net/tun.c
40345index cb95fe5..16909e2 100644
40346--- a/drivers/net/tun.c
40347+++ b/drivers/net/tun.c
40348@@ -1594,7 +1594,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
40349
40350 if (tun->flags & TUN_TAP_MQ &&
40351 (tun->numqueues + tun->numdisabled > 1))
40352- return err;
40353+ return -EBUSY;
40354 }
40355 else {
40356 char *name;
40357@@ -1838,7 +1838,7 @@ unlock:
40358 }
40359
40360 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
40361- unsigned long arg, int ifreq_len)
40362+ unsigned long arg, size_t ifreq_len)
40363 {
40364 struct tun_file *tfile = file->private_data;
40365 struct tun_struct *tun;
40366@@ -1850,6 +1850,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
40367 int vnet_hdr_sz;
40368 int ret;
40369
40370+ if (ifreq_len > sizeof ifr)
40371+ return -EFAULT;
40372+
40373 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
40374 if (copy_from_user(&ifr, argp, ifreq_len))
40375 return -EFAULT;
40376diff --git a/drivers/net/usb/cdc_mbim.c b/drivers/net/usb/cdc_mbim.c
40377index 16c8429..6bd9167 100644
40378--- a/drivers/net/usb/cdc_mbim.c
40379+++ b/drivers/net/usb/cdc_mbim.c
40380@@ -134,7 +134,7 @@ static struct sk_buff *cdc_mbim_tx_fixup(struct usbnet *dev, struct sk_buff *skb
40381 goto error;
40382
40383 if (skb) {
40384- if (skb->len <= sizeof(ETH_HLEN))
40385+ if (skb->len <= ETH_HLEN)
40386 goto error;
40387
40388 /* mapping VLANs to MBIM sessions:
40389diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
40390index cd8ccb2..cff5144 100644
40391--- a/drivers/net/usb/hso.c
40392+++ b/drivers/net/usb/hso.c
40393@@ -71,7 +71,7 @@
40394 #include <asm/byteorder.h>
40395 #include <linux/serial_core.h>
40396 #include <linux/serial.h>
40397-
40398+#include <asm/local.h>
40399
40400 #define MOD_AUTHOR "Option Wireless"
40401 #define MOD_DESCRIPTION "USB High Speed Option driver"
40402@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
40403 struct urb *urb;
40404
40405 urb = serial->rx_urb[0];
40406- if (serial->port.count > 0) {
40407+ if (atomic_read(&serial->port.count) > 0) {
40408 count = put_rxbuf_data(urb, serial);
40409 if (count == -1)
40410 return;
40411@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
40412 DUMP1(urb->transfer_buffer, urb->actual_length);
40413
40414 /* Anyone listening? */
40415- if (serial->port.count == 0)
40416+ if (atomic_read(&serial->port.count) == 0)
40417 return;
40418
40419 if (status == 0) {
40420@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
40421 tty_port_tty_set(&serial->port, tty);
40422
40423 /* check for port already opened, if not set the termios */
40424- serial->port.count++;
40425- if (serial->port.count == 1) {
40426+ if (atomic_inc_return(&serial->port.count) == 1) {
40427 serial->rx_state = RX_IDLE;
40428 /* Force default termio settings */
40429 _hso_serial_set_termios(tty, NULL);
40430@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
40431 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
40432 if (result) {
40433 hso_stop_serial_device(serial->parent);
40434- serial->port.count--;
40435+ atomic_dec(&serial->port.count);
40436 kref_put(&serial->parent->ref, hso_serial_ref_free);
40437 }
40438 } else {
40439@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
40440
40441 /* reset the rts and dtr */
40442 /* do the actual close */
40443- serial->port.count--;
40444+ atomic_dec(&serial->port.count);
40445
40446- if (serial->port.count <= 0) {
40447- serial->port.count = 0;
40448+ if (atomic_read(&serial->port.count) <= 0) {
40449+ atomic_set(&serial->port.count, 0);
40450 tty_port_tty_set(&serial->port, NULL);
40451 if (!usb_gone)
40452 hso_stop_serial_device(serial->parent);
40453@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
40454
40455 /* the actual setup */
40456 spin_lock_irqsave(&serial->serial_lock, flags);
40457- if (serial->port.count)
40458+ if (atomic_read(&serial->port.count))
40459 _hso_serial_set_termios(tty, old);
40460 else
40461 tty->termios = *old;
40462@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
40463 D1("Pending read interrupt on port %d\n", i);
40464 spin_lock(&serial->serial_lock);
40465 if (serial->rx_state == RX_IDLE &&
40466- serial->port.count > 0) {
40467+ atomic_read(&serial->port.count) > 0) {
40468 /* Setup and send a ctrl req read on
40469 * port i */
40470 if (!serial->rx_urb_filled[0]) {
40471@@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
40472 /* Start all serial ports */
40473 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
40474 if (serial_table[i] && (serial_table[i]->interface == iface)) {
40475- if (dev2ser(serial_table[i])->port.count) {
40476+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
40477 result =
40478 hso_start_serial_device(serial_table[i], GFP_NOIO);
40479 hso_kick_transmit(dev2ser(serial_table[i]));
40480diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
40481index 6993bfa..9053a34 100644
40482--- a/drivers/net/vxlan.c
40483+++ b/drivers/net/vxlan.c
40484@@ -1428,7 +1428,7 @@ nla_put_failure:
40485 return -EMSGSIZE;
40486 }
40487
40488-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
40489+static struct rtnl_link_ops vxlan_link_ops = {
40490 .kind = "vxlan",
40491 .maxtype = IFLA_VXLAN_MAX,
40492 .policy = vxlan_policy,
40493diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
40494index 77fa428..996b355 100644
40495--- a/drivers/net/wireless/at76c50x-usb.c
40496+++ b/drivers/net/wireless/at76c50x-usb.c
40497@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
40498 }
40499
40500 /* Convert timeout from the DFU status to jiffies */
40501-static inline unsigned long at76_get_timeout(struct dfu_status *s)
40502+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
40503 {
40504 return msecs_to_jiffies((s->poll_timeout[2] << 16)
40505 | (s->poll_timeout[1] << 8)
40506diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
40507index 8d78253..bebbb68 100644
40508--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
40509+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
40510@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40511 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
40512 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
40513
40514- ACCESS_ONCE(ads->ds_link) = i->link;
40515- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
40516+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
40517+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
40518
40519 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
40520 ctl6 = SM(i->keytype, AR_EncrType);
40521@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40522
40523 if ((i->is_first || i->is_last) &&
40524 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
40525- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
40526+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
40527 | set11nTries(i->rates, 1)
40528 | set11nTries(i->rates, 2)
40529 | set11nTries(i->rates, 3)
40530 | (i->dur_update ? AR_DurUpdateEna : 0)
40531 | SM(0, AR_BurstDur);
40532
40533- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
40534+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
40535 | set11nRate(i->rates, 1)
40536 | set11nRate(i->rates, 2)
40537 | set11nRate(i->rates, 3);
40538 } else {
40539- ACCESS_ONCE(ads->ds_ctl2) = 0;
40540- ACCESS_ONCE(ads->ds_ctl3) = 0;
40541+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
40542+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
40543 }
40544
40545 if (!i->is_first) {
40546- ACCESS_ONCE(ads->ds_ctl0) = 0;
40547- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
40548- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
40549+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
40550+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
40551+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
40552 return;
40553 }
40554
40555@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40556 break;
40557 }
40558
40559- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
40560+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
40561 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
40562 | SM(i->txpower, AR_XmitPower)
40563 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
40564@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40565 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
40566 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
40567
40568- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
40569- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
40570+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
40571+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
40572
40573 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
40574 return;
40575
40576- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
40577+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
40578 | set11nPktDurRTSCTS(i->rates, 1);
40579
40580- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
40581+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
40582 | set11nPktDurRTSCTS(i->rates, 3);
40583
40584- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
40585+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
40586 | set11nRateFlags(i->rates, 1)
40587 | set11nRateFlags(i->rates, 2)
40588 | set11nRateFlags(i->rates, 3)
40589diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
40590index 301bf72..3f5654f 100644
40591--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
40592+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
40593@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40594 (i->qcu << AR_TxQcuNum_S) | desc_len;
40595
40596 checksum += val;
40597- ACCESS_ONCE(ads->info) = val;
40598+ ACCESS_ONCE_RW(ads->info) = val;
40599
40600 checksum += i->link;
40601- ACCESS_ONCE(ads->link) = i->link;
40602+ ACCESS_ONCE_RW(ads->link) = i->link;
40603
40604 checksum += i->buf_addr[0];
40605- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
40606+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
40607 checksum += i->buf_addr[1];
40608- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
40609+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
40610 checksum += i->buf_addr[2];
40611- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
40612+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
40613 checksum += i->buf_addr[3];
40614- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
40615+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
40616
40617 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
40618- ACCESS_ONCE(ads->ctl3) = val;
40619+ ACCESS_ONCE_RW(ads->ctl3) = val;
40620 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
40621- ACCESS_ONCE(ads->ctl5) = val;
40622+ ACCESS_ONCE_RW(ads->ctl5) = val;
40623 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
40624- ACCESS_ONCE(ads->ctl7) = val;
40625+ ACCESS_ONCE_RW(ads->ctl7) = val;
40626 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
40627- ACCESS_ONCE(ads->ctl9) = val;
40628+ ACCESS_ONCE_RW(ads->ctl9) = val;
40629
40630 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
40631- ACCESS_ONCE(ads->ctl10) = checksum;
40632+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
40633
40634 if (i->is_first || i->is_last) {
40635- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
40636+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
40637 | set11nTries(i->rates, 1)
40638 | set11nTries(i->rates, 2)
40639 | set11nTries(i->rates, 3)
40640 | (i->dur_update ? AR_DurUpdateEna : 0)
40641 | SM(0, AR_BurstDur);
40642
40643- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
40644+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
40645 | set11nRate(i->rates, 1)
40646 | set11nRate(i->rates, 2)
40647 | set11nRate(i->rates, 3);
40648 } else {
40649- ACCESS_ONCE(ads->ctl13) = 0;
40650- ACCESS_ONCE(ads->ctl14) = 0;
40651+ ACCESS_ONCE_RW(ads->ctl13) = 0;
40652+ ACCESS_ONCE_RW(ads->ctl14) = 0;
40653 }
40654
40655 ads->ctl20 = 0;
40656@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40657
40658 ctl17 = SM(i->keytype, AR_EncrType);
40659 if (!i->is_first) {
40660- ACCESS_ONCE(ads->ctl11) = 0;
40661- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
40662- ACCESS_ONCE(ads->ctl15) = 0;
40663- ACCESS_ONCE(ads->ctl16) = 0;
40664- ACCESS_ONCE(ads->ctl17) = ctl17;
40665- ACCESS_ONCE(ads->ctl18) = 0;
40666- ACCESS_ONCE(ads->ctl19) = 0;
40667+ ACCESS_ONCE_RW(ads->ctl11) = 0;
40668+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
40669+ ACCESS_ONCE_RW(ads->ctl15) = 0;
40670+ ACCESS_ONCE_RW(ads->ctl16) = 0;
40671+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
40672+ ACCESS_ONCE_RW(ads->ctl18) = 0;
40673+ ACCESS_ONCE_RW(ads->ctl19) = 0;
40674 return;
40675 }
40676
40677- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
40678+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
40679 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
40680 | SM(i->txpower, AR_XmitPower)
40681 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
40682@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40683 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
40684 ctl12 |= SM(val, AR_PAPRDChainMask);
40685
40686- ACCESS_ONCE(ads->ctl12) = ctl12;
40687- ACCESS_ONCE(ads->ctl17) = ctl17;
40688+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
40689+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
40690
40691- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
40692+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
40693 | set11nPktDurRTSCTS(i->rates, 1);
40694
40695- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
40696+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
40697 | set11nPktDurRTSCTS(i->rates, 3);
40698
40699- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
40700+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
40701 | set11nRateFlags(i->rates, 1)
40702 | set11nRateFlags(i->rates, 2)
40703 | set11nRateFlags(i->rates, 3)
40704 | SM(i->rtscts_rate, AR_RTSCTSRate);
40705
40706- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
40707+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
40708 }
40709
40710 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
40711diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
40712index 9d26fc5..60d9f14 100644
40713--- a/drivers/net/wireless/ath/ath9k/hw.h
40714+++ b/drivers/net/wireless/ath/ath9k/hw.h
40715@@ -658,7 +658,7 @@ struct ath_hw_private_ops {
40716
40717 /* ANI */
40718 void (*ani_cache_ini_regs)(struct ath_hw *ah);
40719-};
40720+} __no_const;
40721
40722 /**
40723 * struct ath_hw_ops - callbacks used by hardware code and driver code
40724@@ -688,7 +688,7 @@ struct ath_hw_ops {
40725 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
40726 struct ath_hw_antcomb_conf *antconf);
40727 void (*antctrl_shared_chain_lnadiv)(struct ath_hw *hw, bool enable);
40728-};
40729+} __no_const;
40730
40731 struct ath_nf_limits {
40732 s16 max;
40733diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
40734index 3726cd6..b655808 100644
40735--- a/drivers/net/wireless/iwlegacy/3945-mac.c
40736+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
40737@@ -3615,7 +3615,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
40738 */
40739 if (il3945_mod_params.disable_hw_scan) {
40740 D_INFO("Disabling hw_scan\n");
40741- il3945_mac_ops.hw_scan = NULL;
40742+ pax_open_kernel();
40743+ *(void **)&il3945_mac_ops.hw_scan = NULL;
40744+ pax_close_kernel();
40745 }
40746
40747 D_INFO("*** LOAD DRIVER ***\n");
40748diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40749index 5b9533e..7733880 100644
40750--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40751+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40752@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
40753 {
40754 struct iwl_priv *priv = file->private_data;
40755 char buf[64];
40756- int buf_size;
40757+ size_t buf_size;
40758 u32 offset, len;
40759
40760 memset(buf, 0, sizeof(buf));
40761@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
40762 struct iwl_priv *priv = file->private_data;
40763
40764 char buf[8];
40765- int buf_size;
40766+ size_t buf_size;
40767 u32 reset_flag;
40768
40769 memset(buf, 0, sizeof(buf));
40770@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
40771 {
40772 struct iwl_priv *priv = file->private_data;
40773 char buf[8];
40774- int buf_size;
40775+ size_t buf_size;
40776 int ht40;
40777
40778 memset(buf, 0, sizeof(buf));
40779@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
40780 {
40781 struct iwl_priv *priv = file->private_data;
40782 char buf[8];
40783- int buf_size;
40784+ size_t buf_size;
40785 int value;
40786
40787 memset(buf, 0, sizeof(buf));
40788@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
40789 {
40790 struct iwl_priv *priv = file->private_data;
40791 char buf[8];
40792- int buf_size;
40793+ size_t buf_size;
40794 int clear;
40795
40796 memset(buf, 0, sizeof(buf));
40797@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
40798 {
40799 struct iwl_priv *priv = file->private_data;
40800 char buf[8];
40801- int buf_size;
40802+ size_t buf_size;
40803 int trace;
40804
40805 memset(buf, 0, sizeof(buf));
40806@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
40807 {
40808 struct iwl_priv *priv = file->private_data;
40809 char buf[8];
40810- int buf_size;
40811+ size_t buf_size;
40812 int missed;
40813
40814 memset(buf, 0, sizeof(buf));
40815@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
40816
40817 struct iwl_priv *priv = file->private_data;
40818 char buf[8];
40819- int buf_size;
40820+ size_t buf_size;
40821 int plcp;
40822
40823 memset(buf, 0, sizeof(buf));
40824@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
40825
40826 struct iwl_priv *priv = file->private_data;
40827 char buf[8];
40828- int buf_size;
40829+ size_t buf_size;
40830 int flush;
40831
40832 memset(buf, 0, sizeof(buf));
40833@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
40834
40835 struct iwl_priv *priv = file->private_data;
40836 char buf[8];
40837- int buf_size;
40838+ size_t buf_size;
40839 int rts;
40840
40841 if (!priv->cfg->ht_params)
40842@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
40843 {
40844 struct iwl_priv *priv = file->private_data;
40845 char buf[8];
40846- int buf_size;
40847+ size_t buf_size;
40848
40849 memset(buf, 0, sizeof(buf));
40850 buf_size = min(count, sizeof(buf) - 1);
40851@@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
40852 struct iwl_priv *priv = file->private_data;
40853 u32 event_log_flag;
40854 char buf[8];
40855- int buf_size;
40856+ size_t buf_size;
40857
40858 /* check that the interface is up */
40859 if (!iwl_is_ready(priv))
40860@@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
40861 struct iwl_priv *priv = file->private_data;
40862 char buf[8];
40863 u32 calib_disabled;
40864- int buf_size;
40865+ size_t buf_size;
40866
40867 memset(buf, 0, sizeof(buf));
40868 buf_size = min(count, sizeof(buf) - 1);
40869diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
40870index 35708b9..31f7754 100644
40871--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
40872+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
40873@@ -1100,7 +1100,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
40874 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
40875
40876 char buf[8];
40877- int buf_size;
40878+ size_t buf_size;
40879 u32 reset_flag;
40880
40881 memset(buf, 0, sizeof(buf));
40882@@ -1121,7 +1121,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
40883 {
40884 struct iwl_trans *trans = file->private_data;
40885 char buf[8];
40886- int buf_size;
40887+ size_t buf_size;
40888 int csr;
40889
40890 memset(buf, 0, sizeof(buf));
40891diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
40892index ff90855..e46d223 100644
40893--- a/drivers/net/wireless/mac80211_hwsim.c
40894+++ b/drivers/net/wireless/mac80211_hwsim.c
40895@@ -2062,25 +2062,19 @@ static int __init init_mac80211_hwsim(void)
40896
40897 if (channels > 1) {
40898 hwsim_if_comb.num_different_channels = channels;
40899- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
40900- mac80211_hwsim_ops.cancel_hw_scan =
40901- mac80211_hwsim_cancel_hw_scan;
40902- mac80211_hwsim_ops.sw_scan_start = NULL;
40903- mac80211_hwsim_ops.sw_scan_complete = NULL;
40904- mac80211_hwsim_ops.remain_on_channel =
40905- mac80211_hwsim_roc;
40906- mac80211_hwsim_ops.cancel_remain_on_channel =
40907- mac80211_hwsim_croc;
40908- mac80211_hwsim_ops.add_chanctx =
40909- mac80211_hwsim_add_chanctx;
40910- mac80211_hwsim_ops.remove_chanctx =
40911- mac80211_hwsim_remove_chanctx;
40912- mac80211_hwsim_ops.change_chanctx =
40913- mac80211_hwsim_change_chanctx;
40914- mac80211_hwsim_ops.assign_vif_chanctx =
40915- mac80211_hwsim_assign_vif_chanctx;
40916- mac80211_hwsim_ops.unassign_vif_chanctx =
40917- mac80211_hwsim_unassign_vif_chanctx;
40918+ pax_open_kernel();
40919+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
40920+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
40921+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
40922+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
40923+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
40924+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
40925+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
40926+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
40927+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
40928+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
40929+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
40930+ pax_close_kernel();
40931 }
40932
40933 spin_lock_init(&hwsim_radio_lock);
40934diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
40935index abe1d03..fb02c22 100644
40936--- a/drivers/net/wireless/rndis_wlan.c
40937+++ b/drivers/net/wireless/rndis_wlan.c
40938@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
40939
40940 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
40941
40942- if (rts_threshold < 0 || rts_threshold > 2347)
40943+ if (rts_threshold > 2347)
40944 rts_threshold = 2347;
40945
40946 tmp = cpu_to_le32(rts_threshold);
40947diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
40948index 0751b35..246ba3e 100644
40949--- a/drivers/net/wireless/rt2x00/rt2x00.h
40950+++ b/drivers/net/wireless/rt2x00/rt2x00.h
40951@@ -398,7 +398,7 @@ struct rt2x00_intf {
40952 * for hardware which doesn't support hardware
40953 * sequence counting.
40954 */
40955- atomic_t seqno;
40956+ atomic_unchecked_t seqno;
40957 };
40958
40959 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
40960diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
40961index e488b94..14b6a0c 100644
40962--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
40963+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
40964@@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
40965 * sequence counter given by mac80211.
40966 */
40967 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
40968- seqno = atomic_add_return(0x10, &intf->seqno);
40969+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
40970 else
40971- seqno = atomic_read(&intf->seqno);
40972+ seqno = atomic_read_unchecked(&intf->seqno);
40973
40974 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
40975 hdr->seq_ctrl |= cpu_to_le16(seqno);
40976diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
40977index e57ee48..541cf6c 100644
40978--- a/drivers/net/wireless/ti/wl1251/sdio.c
40979+++ b/drivers/net/wireless/ti/wl1251/sdio.c
40980@@ -269,13 +269,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
40981
40982 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
40983
40984- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
40985- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
40986+ pax_open_kernel();
40987+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
40988+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
40989+ pax_close_kernel();
40990
40991 wl1251_info("using dedicated interrupt line");
40992 } else {
40993- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
40994- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
40995+ pax_open_kernel();
40996+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
40997+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
40998+ pax_close_kernel();
40999
41000 wl1251_info("using SDIO interrupt");
41001 }
41002diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
41003index e5f5f8f..fdf15b7 100644
41004--- a/drivers/net/wireless/ti/wl12xx/main.c
41005+++ b/drivers/net/wireless/ti/wl12xx/main.c
41006@@ -644,7 +644,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
41007 sizeof(wl->conf.mem));
41008
41009 /* read data preparation is only needed by wl127x */
41010- wl->ops->prepare_read = wl127x_prepare_read;
41011+ pax_open_kernel();
41012+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
41013+ pax_close_kernel();
41014
41015 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
41016 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
41017@@ -665,7 +667,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
41018 sizeof(wl->conf.mem));
41019
41020 /* read data preparation is only needed by wl127x */
41021- wl->ops->prepare_read = wl127x_prepare_read;
41022+ pax_open_kernel();
41023+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
41024+ pax_close_kernel();
41025
41026 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
41027 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
41028diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
41029index 8d8c1f8..e754844 100644
41030--- a/drivers/net/wireless/ti/wl18xx/main.c
41031+++ b/drivers/net/wireless/ti/wl18xx/main.c
41032@@ -1489,8 +1489,10 @@ static int wl18xx_setup(struct wl1271 *wl)
41033 }
41034
41035 if (!checksum_param) {
41036- wl18xx_ops.set_rx_csum = NULL;
41037- wl18xx_ops.init_vif = NULL;
41038+ pax_open_kernel();
41039+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
41040+ *(void **)&wl18xx_ops.init_vif = NULL;
41041+ pax_close_kernel();
41042 }
41043
41044 /* Enable 11a Band only if we have 5G antennas */
41045diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
41046index ef2b171..bb513a6 100644
41047--- a/drivers/net/wireless/zd1211rw/zd_usb.c
41048+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
41049@@ -387,7 +387,7 @@ static inline void handle_regs_int(struct urb *urb)
41050 {
41051 struct zd_usb *usb = urb->context;
41052 struct zd_usb_interrupt *intr = &usb->intr;
41053- int len;
41054+ unsigned int len;
41055 u16 int_num;
41056
41057 ZD_ASSERT(in_interrupt());
41058diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
41059index d93b2b6..ae50401 100644
41060--- a/drivers/oprofile/buffer_sync.c
41061+++ b/drivers/oprofile/buffer_sync.c
41062@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
41063 if (cookie == NO_COOKIE)
41064 offset = pc;
41065 if (cookie == INVALID_COOKIE) {
41066- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
41067+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
41068 offset = pc;
41069 }
41070 if (cookie != last_cookie) {
41071@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
41072 /* add userspace sample */
41073
41074 if (!mm) {
41075- atomic_inc(&oprofile_stats.sample_lost_no_mm);
41076+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
41077 return 0;
41078 }
41079
41080 cookie = lookup_dcookie(mm, s->eip, &offset);
41081
41082 if (cookie == INVALID_COOKIE) {
41083- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
41084+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
41085 return 0;
41086 }
41087
41088@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
41089 /* ignore backtraces if failed to add a sample */
41090 if (state == sb_bt_start) {
41091 state = sb_bt_ignore;
41092- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
41093+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
41094 }
41095 }
41096 release_mm(mm);
41097diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
41098index c0cc4e7..44d4e54 100644
41099--- a/drivers/oprofile/event_buffer.c
41100+++ b/drivers/oprofile/event_buffer.c
41101@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
41102 }
41103
41104 if (buffer_pos == buffer_size) {
41105- atomic_inc(&oprofile_stats.event_lost_overflow);
41106+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
41107 return;
41108 }
41109
41110diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
41111index ed2c3ec..deda85a 100644
41112--- a/drivers/oprofile/oprof.c
41113+++ b/drivers/oprofile/oprof.c
41114@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
41115 if (oprofile_ops.switch_events())
41116 return;
41117
41118- atomic_inc(&oprofile_stats.multiplex_counter);
41119+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
41120 start_switch_worker();
41121 }
41122
41123diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
41124index 84a208d..d61b0a1 100644
41125--- a/drivers/oprofile/oprofile_files.c
41126+++ b/drivers/oprofile/oprofile_files.c
41127@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
41128
41129 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
41130
41131-static ssize_t timeout_read(struct file *file, char __user *buf,
41132+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
41133 size_t count, loff_t *offset)
41134 {
41135 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
41136diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
41137index 917d28e..d62d981 100644
41138--- a/drivers/oprofile/oprofile_stats.c
41139+++ b/drivers/oprofile/oprofile_stats.c
41140@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
41141 cpu_buf->sample_invalid_eip = 0;
41142 }
41143
41144- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
41145- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
41146- atomic_set(&oprofile_stats.event_lost_overflow, 0);
41147- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
41148- atomic_set(&oprofile_stats.multiplex_counter, 0);
41149+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
41150+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
41151+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
41152+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
41153+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
41154 }
41155
41156
41157diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
41158index 38b6fc0..b5cbfce 100644
41159--- a/drivers/oprofile/oprofile_stats.h
41160+++ b/drivers/oprofile/oprofile_stats.h
41161@@ -13,11 +13,11 @@
41162 #include <linux/atomic.h>
41163
41164 struct oprofile_stat_struct {
41165- atomic_t sample_lost_no_mm;
41166- atomic_t sample_lost_no_mapping;
41167- atomic_t bt_lost_no_mapping;
41168- atomic_t event_lost_overflow;
41169- atomic_t multiplex_counter;
41170+ atomic_unchecked_t sample_lost_no_mm;
41171+ atomic_unchecked_t sample_lost_no_mapping;
41172+ atomic_unchecked_t bt_lost_no_mapping;
41173+ atomic_unchecked_t event_lost_overflow;
41174+ atomic_unchecked_t multiplex_counter;
41175 };
41176
41177 extern struct oprofile_stat_struct oprofile_stats;
41178diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
41179index 849357c..b83c1e0 100644
41180--- a/drivers/oprofile/oprofilefs.c
41181+++ b/drivers/oprofile/oprofilefs.c
41182@@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
41183
41184
41185 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
41186- char const *name, atomic_t *val)
41187+ char const *name, atomic_unchecked_t *val)
41188 {
41189 return __oprofilefs_create_file(sb, root, name,
41190 &atomic_ro_fops, 0444, val);
41191diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
41192index 93404f7..4a313d8 100644
41193--- a/drivers/oprofile/timer_int.c
41194+++ b/drivers/oprofile/timer_int.c
41195@@ -93,7 +93,7 @@ static int __cpuinit oprofile_cpu_notify(struct notifier_block *self,
41196 return NOTIFY_OK;
41197 }
41198
41199-static struct notifier_block __refdata oprofile_cpu_notifier = {
41200+static struct notifier_block oprofile_cpu_notifier = {
41201 .notifier_call = oprofile_cpu_notify,
41202 };
41203
41204diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
41205index 3f56bc0..707d642 100644
41206--- a/drivers/parport/procfs.c
41207+++ b/drivers/parport/procfs.c
41208@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
41209
41210 *ppos += len;
41211
41212- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
41213+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
41214 }
41215
41216 #ifdef CONFIG_PARPORT_1284
41217@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
41218
41219 *ppos += len;
41220
41221- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
41222+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
41223 }
41224 #endif /* IEEE1284.3 support. */
41225
41226diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
41227index c35e8ad..fc33beb 100644
41228--- a/drivers/pci/hotplug/acpiphp_ibm.c
41229+++ b/drivers/pci/hotplug/acpiphp_ibm.c
41230@@ -464,7 +464,9 @@ static int __init ibm_acpiphp_init(void)
41231 goto init_cleanup;
41232 }
41233
41234- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
41235+ pax_open_kernel();
41236+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
41237+ pax_close_kernel();
41238 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
41239
41240 return retval;
41241diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
41242index a6a71c4..c91097b 100644
41243--- a/drivers/pci/hotplug/cpcihp_generic.c
41244+++ b/drivers/pci/hotplug/cpcihp_generic.c
41245@@ -73,7 +73,6 @@ static u16 port;
41246 static unsigned int enum_bit;
41247 static u8 enum_mask;
41248
41249-static struct cpci_hp_controller_ops generic_hpc_ops;
41250 static struct cpci_hp_controller generic_hpc;
41251
41252 static int __init validate_parameters(void)
41253@@ -139,6 +138,10 @@ static int query_enum(void)
41254 return ((value & enum_mask) == enum_mask);
41255 }
41256
41257+static struct cpci_hp_controller_ops generic_hpc_ops = {
41258+ .query_enum = query_enum,
41259+};
41260+
41261 static int __init cpcihp_generic_init(void)
41262 {
41263 int status;
41264@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
41265 pci_dev_put(dev);
41266
41267 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
41268- generic_hpc_ops.query_enum = query_enum;
41269 generic_hpc.ops = &generic_hpc_ops;
41270
41271 status = cpci_hp_register_controller(&generic_hpc);
41272diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
41273index 449b4bb..257e2e8 100644
41274--- a/drivers/pci/hotplug/cpcihp_zt5550.c
41275+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
41276@@ -59,7 +59,6 @@
41277 /* local variables */
41278 static bool debug;
41279 static bool poll;
41280-static struct cpci_hp_controller_ops zt5550_hpc_ops;
41281 static struct cpci_hp_controller zt5550_hpc;
41282
41283 /* Primary cPCI bus bridge device */
41284@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
41285 return 0;
41286 }
41287
41288+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
41289+ .query_enum = zt5550_hc_query_enum,
41290+};
41291+
41292 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
41293 {
41294 int status;
41295@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
41296 dbg("returned from zt5550_hc_config");
41297
41298 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
41299- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
41300 zt5550_hpc.ops = &zt5550_hpc_ops;
41301 if(!poll) {
41302 zt5550_hpc.irq = hc_dev->irq;
41303 zt5550_hpc.irq_flags = IRQF_SHARED;
41304 zt5550_hpc.dev_id = hc_dev;
41305
41306- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
41307- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
41308- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
41309+ pax_open_kernel();
41310+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
41311+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
41312+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
41313+ pax_open_kernel();
41314 } else {
41315 info("using ENUM# polling mode");
41316 }
41317diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
41318index 76ba8a1..20ca857 100644
41319--- a/drivers/pci/hotplug/cpqphp_nvram.c
41320+++ b/drivers/pci/hotplug/cpqphp_nvram.c
41321@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
41322
41323 void compaq_nvram_init (void __iomem *rom_start)
41324 {
41325+
41326+#ifndef CONFIG_PAX_KERNEXEC
41327 if (rom_start) {
41328 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
41329 }
41330+#endif
41331+
41332 dbg("int15 entry = %p\n", compaq_int15_entry_point);
41333
41334 /* initialize our int15 lock */
41335diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
41336index 202f4a9..8ee47d0 100644
41337--- a/drivers/pci/hotplug/pci_hotplug_core.c
41338+++ b/drivers/pci/hotplug/pci_hotplug_core.c
41339@@ -448,8 +448,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
41340 return -EINVAL;
41341 }
41342
41343- slot->ops->owner = owner;
41344- slot->ops->mod_name = mod_name;
41345+ pax_open_kernel();
41346+ *(struct module **)&slot->ops->owner = owner;
41347+ *(const char **)&slot->ops->mod_name = mod_name;
41348+ pax_close_kernel();
41349
41350 mutex_lock(&pci_hp_mutex);
41351 /*
41352diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
41353index 939bd1d..a1459c9 100644
41354--- a/drivers/pci/hotplug/pciehp_core.c
41355+++ b/drivers/pci/hotplug/pciehp_core.c
41356@@ -91,7 +91,7 @@ static int init_slot(struct controller *ctrl)
41357 struct slot *slot = ctrl->slot;
41358 struct hotplug_slot *hotplug = NULL;
41359 struct hotplug_slot_info *info = NULL;
41360- struct hotplug_slot_ops *ops = NULL;
41361+ hotplug_slot_ops_no_const *ops = NULL;
41362 char name[SLOT_NAME_SIZE];
41363 int retval = -ENOMEM;
41364
41365diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
41366index 9c6e9bb..2916736 100644
41367--- a/drivers/pci/pci-sysfs.c
41368+++ b/drivers/pci/pci-sysfs.c
41369@@ -1071,7 +1071,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
41370 {
41371 /* allocate attribute structure, piggyback attribute name */
41372 int name_len = write_combine ? 13 : 10;
41373- struct bin_attribute *res_attr;
41374+ bin_attribute_no_const *res_attr;
41375 int retval;
41376
41377 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
41378@@ -1256,7 +1256,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
41379 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
41380 {
41381 int retval;
41382- struct bin_attribute *attr;
41383+ bin_attribute_no_const *attr;
41384
41385 /* If the device has VPD, try to expose it in sysfs. */
41386 if (dev->vpd) {
41387@@ -1303,7 +1303,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
41388 {
41389 int retval;
41390 int rom_size = 0;
41391- struct bin_attribute *attr;
41392+ bin_attribute_no_const *attr;
41393
41394 if (!sysfs_initialized)
41395 return -EACCES;
41396diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
41397index e851829..a1a7196 100644
41398--- a/drivers/pci/pci.h
41399+++ b/drivers/pci/pci.h
41400@@ -98,7 +98,7 @@ struct pci_vpd_ops {
41401 struct pci_vpd {
41402 unsigned int len;
41403 const struct pci_vpd_ops *ops;
41404- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
41405+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
41406 };
41407
41408 extern int pci_vpd_pci22_init(struct pci_dev *dev);
41409diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
41410index 8474b6a..ee81993 100644
41411--- a/drivers/pci/pcie/aspm.c
41412+++ b/drivers/pci/pcie/aspm.c
41413@@ -27,9 +27,9 @@
41414 #define MODULE_PARAM_PREFIX "pcie_aspm."
41415
41416 /* Note: those are not register definitions */
41417-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
41418-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
41419-#define ASPM_STATE_L1 (4) /* L1 state */
41420+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
41421+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
41422+#define ASPM_STATE_L1 (4U) /* L1 state */
41423 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
41424 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
41425
41426diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
41427index 6186f03..1a78714 100644
41428--- a/drivers/pci/probe.c
41429+++ b/drivers/pci/probe.c
41430@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
41431 struct pci_bus_region region;
41432 bool bar_too_big = false, bar_disabled = false;
41433
41434- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
41435+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
41436
41437 /* No printks while decoding is disabled! */
41438 if (!dev->mmio_always_on) {
41439diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
41440index 9b8505c..f00870a 100644
41441--- a/drivers/pci/proc.c
41442+++ b/drivers/pci/proc.c
41443@@ -465,7 +465,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
41444 static int __init pci_proc_init(void)
41445 {
41446 struct pci_dev *dev = NULL;
41447+
41448+#ifdef CONFIG_GRKERNSEC_PROC_ADD
41449+#ifdef CONFIG_GRKERNSEC_PROC_USER
41450+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
41451+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
41452+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
41453+#endif
41454+#else
41455 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
41456+#endif
41457 proc_create("devices", 0, proc_bus_pci_dir,
41458 &proc_bus_pci_dev_operations);
41459 proc_initialized = 1;
41460diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
41461index 2111dbb..79e434b 100644
41462--- a/drivers/platform/x86/msi-laptop.c
41463+++ b/drivers/platform/x86/msi-laptop.c
41464@@ -820,12 +820,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
41465 int result;
41466
41467 /* allow userland write sysfs file */
41468- dev_attr_bluetooth.store = store_bluetooth;
41469- dev_attr_wlan.store = store_wlan;
41470- dev_attr_threeg.store = store_threeg;
41471- dev_attr_bluetooth.attr.mode |= S_IWUSR;
41472- dev_attr_wlan.attr.mode |= S_IWUSR;
41473- dev_attr_threeg.attr.mode |= S_IWUSR;
41474+ pax_open_kernel();
41475+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
41476+ *(void **)&dev_attr_wlan.store = store_wlan;
41477+ *(void **)&dev_attr_threeg.store = store_threeg;
41478+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
41479+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
41480+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
41481+ pax_close_kernel();
41482
41483 /* disable hardware control by fn key */
41484 result = ec_read(MSI_STANDARD_EC_SCM_LOAD_ADDRESS, &data);
41485diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
41486index 0fe987f..6f3d5c3 100644
41487--- a/drivers/platform/x86/sony-laptop.c
41488+++ b/drivers/platform/x86/sony-laptop.c
41489@@ -2356,7 +2356,7 @@ static void sony_nc_lid_resume_cleanup(struct platform_device *pd)
41490 }
41491
41492 /* High speed charging function */
41493-static struct device_attribute *hsc_handle;
41494+static device_attribute_no_const *hsc_handle;
41495
41496 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
41497 struct device_attribute *attr,
41498diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
41499index f946ca7..f25c833 100644
41500--- a/drivers/platform/x86/thinkpad_acpi.c
41501+++ b/drivers/platform/x86/thinkpad_acpi.c
41502@@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
41503 return 0;
41504 }
41505
41506-void static hotkey_mask_warn_incomplete_mask(void)
41507+static void hotkey_mask_warn_incomplete_mask(void)
41508 {
41509 /* log only what the user can fix... */
41510 const u32 wantedmask = hotkey_driver_mask &
41511@@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
41512 }
41513 }
41514
41515-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41516- struct tp_nvram_state *newn,
41517- const u32 event_mask)
41518-{
41519-
41520 #define TPACPI_COMPARE_KEY(__scancode, __member) \
41521 do { \
41522 if ((event_mask & (1 << __scancode)) && \
41523@@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41524 tpacpi_hotkey_send_key(__scancode); \
41525 } while (0)
41526
41527- void issue_volchange(const unsigned int oldvol,
41528- const unsigned int newvol)
41529- {
41530- unsigned int i = oldvol;
41531+static void issue_volchange(const unsigned int oldvol,
41532+ const unsigned int newvol,
41533+ const u32 event_mask)
41534+{
41535+ unsigned int i = oldvol;
41536
41537- while (i > newvol) {
41538- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
41539- i--;
41540- }
41541- while (i < newvol) {
41542- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
41543- i++;
41544- }
41545+ while (i > newvol) {
41546+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
41547+ i--;
41548 }
41549+ while (i < newvol) {
41550+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
41551+ i++;
41552+ }
41553+}
41554
41555- void issue_brightnesschange(const unsigned int oldbrt,
41556- const unsigned int newbrt)
41557- {
41558- unsigned int i = oldbrt;
41559+static void issue_brightnesschange(const unsigned int oldbrt,
41560+ const unsigned int newbrt,
41561+ const u32 event_mask)
41562+{
41563+ unsigned int i = oldbrt;
41564
41565- while (i > newbrt) {
41566- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
41567- i--;
41568- }
41569- while (i < newbrt) {
41570- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
41571- i++;
41572- }
41573+ while (i > newbrt) {
41574+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
41575+ i--;
41576+ }
41577+ while (i < newbrt) {
41578+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
41579+ i++;
41580 }
41581+}
41582
41583+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41584+ struct tp_nvram_state *newn,
41585+ const u32 event_mask)
41586+{
41587 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
41588 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
41589 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
41590@@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41591 oldn->volume_level != newn->volume_level) {
41592 /* recently muted, or repeated mute keypress, or
41593 * multiple presses ending in mute */
41594- issue_volchange(oldn->volume_level, newn->volume_level);
41595+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
41596 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
41597 }
41598 } else {
41599@@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41600 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
41601 }
41602 if (oldn->volume_level != newn->volume_level) {
41603- issue_volchange(oldn->volume_level, newn->volume_level);
41604+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
41605 } else if (oldn->volume_toggle != newn->volume_toggle) {
41606 /* repeated vol up/down keypress at end of scale ? */
41607 if (newn->volume_level == 0)
41608@@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41609 /* handle brightness */
41610 if (oldn->brightness_level != newn->brightness_level) {
41611 issue_brightnesschange(oldn->brightness_level,
41612- newn->brightness_level);
41613+ newn->brightness_level,
41614+ event_mask);
41615 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
41616 /* repeated key presses that didn't change state */
41617 if (newn->brightness_level == 0)
41618@@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41619 && !tp_features.bright_unkfw)
41620 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
41621 }
41622+}
41623
41624 #undef TPACPI_COMPARE_KEY
41625 #undef TPACPI_MAY_SEND_KEY
41626-}
41627
41628 /*
41629 * Polling driver
41630diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
41631index 769d265..a3a05ca 100644
41632--- a/drivers/pnp/pnpbios/bioscalls.c
41633+++ b/drivers/pnp/pnpbios/bioscalls.c
41634@@ -58,7 +58,7 @@ do { \
41635 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
41636 } while(0)
41637
41638-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
41639+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
41640 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
41641
41642 /*
41643@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
41644
41645 cpu = get_cpu();
41646 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
41647+
41648+ pax_open_kernel();
41649 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
41650+ pax_close_kernel();
41651
41652 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
41653 spin_lock_irqsave(&pnp_bios_lock, flags);
41654@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
41655 :"memory");
41656 spin_unlock_irqrestore(&pnp_bios_lock, flags);
41657
41658+ pax_open_kernel();
41659 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
41660+ pax_close_kernel();
41661+
41662 put_cpu();
41663
41664 /* If we get here and this is set then the PnP BIOS faulted on us. */
41665@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
41666 return status;
41667 }
41668
41669-void pnpbios_calls_init(union pnp_bios_install_struct *header)
41670+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
41671 {
41672 int i;
41673
41674@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
41675 pnp_bios_callpoint.offset = header->fields.pm16offset;
41676 pnp_bios_callpoint.segment = PNP_CS16;
41677
41678+ pax_open_kernel();
41679+
41680 for_each_possible_cpu(i) {
41681 struct desc_struct *gdt = get_cpu_gdt_table(i);
41682 if (!gdt)
41683@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
41684 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
41685 (unsigned long)__va(header->fields.pm16dseg));
41686 }
41687+
41688+ pax_close_kernel();
41689 }
41690diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
41691index 3e6db1c..1fbbdae 100644
41692--- a/drivers/pnp/resource.c
41693+++ b/drivers/pnp/resource.c
41694@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
41695 return 1;
41696
41697 /* check if the resource is valid */
41698- if (*irq < 0 || *irq > 15)
41699+ if (*irq > 15)
41700 return 0;
41701
41702 /* check if the resource is reserved */
41703@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
41704 return 1;
41705
41706 /* check if the resource is valid */
41707- if (*dma < 0 || *dma == 4 || *dma > 7)
41708+ if (*dma == 4 || *dma > 7)
41709 return 0;
41710
41711 /* check if the resource is reserved */
41712diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
41713index 7df7c5f..bd48c47 100644
41714--- a/drivers/power/pda_power.c
41715+++ b/drivers/power/pda_power.c
41716@@ -37,7 +37,11 @@ static int polling;
41717
41718 #ifdef CONFIG_USB_OTG_UTILS
41719 static struct usb_phy *transceiver;
41720-static struct notifier_block otg_nb;
41721+static int otg_handle_notification(struct notifier_block *nb,
41722+ unsigned long event, void *unused);
41723+static struct notifier_block otg_nb = {
41724+ .notifier_call = otg_handle_notification
41725+};
41726 #endif
41727
41728 static struct regulator *ac_draw;
41729@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
41730
41731 #ifdef CONFIG_USB_OTG_UTILS
41732 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
41733- otg_nb.notifier_call = otg_handle_notification;
41734 ret = usb_register_notifier(transceiver, &otg_nb);
41735 if (ret) {
41736 dev_err(dev, "failure to register otg notifier\n");
41737diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
41738index cc439fd..8fa30df 100644
41739--- a/drivers/power/power_supply.h
41740+++ b/drivers/power/power_supply.h
41741@@ -16,12 +16,12 @@ struct power_supply;
41742
41743 #ifdef CONFIG_SYSFS
41744
41745-extern void power_supply_init_attrs(struct device_type *dev_type);
41746+extern void power_supply_init_attrs(void);
41747 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
41748
41749 #else
41750
41751-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
41752+static inline void power_supply_init_attrs(void) {}
41753 #define power_supply_uevent NULL
41754
41755 #endif /* CONFIG_SYSFS */
41756diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
41757index 8a7cfb3..72e6e9b 100644
41758--- a/drivers/power/power_supply_core.c
41759+++ b/drivers/power/power_supply_core.c
41760@@ -24,7 +24,10 @@
41761 struct class *power_supply_class;
41762 EXPORT_SYMBOL_GPL(power_supply_class);
41763
41764-static struct device_type power_supply_dev_type;
41765+extern const struct attribute_group *power_supply_attr_groups[];
41766+static struct device_type power_supply_dev_type = {
41767+ .groups = power_supply_attr_groups,
41768+};
41769
41770 static int __power_supply_changed_work(struct device *dev, void *data)
41771 {
41772@@ -393,7 +396,7 @@ static int __init power_supply_class_init(void)
41773 return PTR_ERR(power_supply_class);
41774
41775 power_supply_class->dev_uevent = power_supply_uevent;
41776- power_supply_init_attrs(&power_supply_dev_type);
41777+ power_supply_init_attrs();
41778
41779 return 0;
41780 }
41781diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
41782index 40fa3b7..d9c2e0e 100644
41783--- a/drivers/power/power_supply_sysfs.c
41784+++ b/drivers/power/power_supply_sysfs.c
41785@@ -229,17 +229,15 @@ static struct attribute_group power_supply_attr_group = {
41786 .is_visible = power_supply_attr_is_visible,
41787 };
41788
41789-static const struct attribute_group *power_supply_attr_groups[] = {
41790+const struct attribute_group *power_supply_attr_groups[] = {
41791 &power_supply_attr_group,
41792 NULL,
41793 };
41794
41795-void power_supply_init_attrs(struct device_type *dev_type)
41796+void power_supply_init_attrs(void)
41797 {
41798 int i;
41799
41800- dev_type->groups = power_supply_attr_groups;
41801-
41802 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
41803 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
41804 }
41805diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
41806index 4d7c635..9860196 100644
41807--- a/drivers/regulator/max8660.c
41808+++ b/drivers/regulator/max8660.c
41809@@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
41810 max8660->shadow_regs[MAX8660_OVER1] = 5;
41811 } else {
41812 /* Otherwise devices can be toggled via software */
41813- max8660_dcdc_ops.enable = max8660_dcdc_enable;
41814- max8660_dcdc_ops.disable = max8660_dcdc_disable;
41815+ pax_open_kernel();
41816+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
41817+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
41818+ pax_close_kernel();
41819 }
41820
41821 /*
41822diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
41823index 9a8ea91..c483dd9 100644
41824--- a/drivers/regulator/max8973-regulator.c
41825+++ b/drivers/regulator/max8973-regulator.c
41826@@ -401,9 +401,11 @@ static int max8973_probe(struct i2c_client *client,
41827 if (!pdata->enable_ext_control) {
41828 max->desc.enable_reg = MAX8973_VOUT;
41829 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
41830- max8973_dcdc_ops.enable = regulator_enable_regmap;
41831- max8973_dcdc_ops.disable = regulator_disable_regmap;
41832- max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
41833+ pax_open_kernel();
41834+ *(void **)&max8973_dcdc_ops.enable = regulator_enable_regmap;
41835+ *(void **)&max8973_dcdc_ops.disable = regulator_disable_regmap;
41836+ *(void **)&max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
41837+ pax_close_kernel();
41838 }
41839
41840 max->enable_external_control = pdata->enable_ext_control;
41841diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
41842index 0d84b1f..c2da6ac 100644
41843--- a/drivers/regulator/mc13892-regulator.c
41844+++ b/drivers/regulator/mc13892-regulator.c
41845@@ -540,10 +540,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
41846 }
41847 mc13xxx_unlock(mc13892);
41848
41849- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
41850+ pax_open_kernel();
41851+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
41852 = mc13892_vcam_set_mode;
41853- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
41854+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
41855 = mc13892_vcam_get_mode;
41856+ pax_close_kernel();
41857
41858 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
41859 ARRAY_SIZE(mc13892_regulators));
41860diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
41861index 16630aa..6afc992 100644
41862--- a/drivers/rtc/rtc-cmos.c
41863+++ b/drivers/rtc/rtc-cmos.c
41864@@ -724,7 +724,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
41865 hpet_rtc_timer_init();
41866
41867 /* export at least the first block of NVRAM */
41868- nvram.size = address_space - NVRAM_OFFSET;
41869+ pax_open_kernel();
41870+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
41871+ pax_close_kernel();
41872 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
41873 if (retval < 0) {
41874 dev_dbg(dev, "can't create nvram file? %d\n", retval);
41875diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
41876index 9a86b4b..3a383dc 100644
41877--- a/drivers/rtc/rtc-dev.c
41878+++ b/drivers/rtc/rtc-dev.c
41879@@ -14,6 +14,7 @@
41880 #include <linux/module.h>
41881 #include <linux/rtc.h>
41882 #include <linux/sched.h>
41883+#include <linux/grsecurity.h>
41884 #include "rtc-core.h"
41885
41886 static dev_t rtc_devt;
41887@@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
41888 if (copy_from_user(&tm, uarg, sizeof(tm)))
41889 return -EFAULT;
41890
41891+ gr_log_timechange();
41892+
41893 return rtc_set_time(rtc, &tm);
41894
41895 case RTC_PIE_ON:
41896diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
41897index e0d0ba4..3c65868 100644
41898--- a/drivers/rtc/rtc-ds1307.c
41899+++ b/drivers/rtc/rtc-ds1307.c
41900@@ -106,7 +106,7 @@ struct ds1307 {
41901 u8 offset; /* register's offset */
41902 u8 regs[11];
41903 u16 nvram_offset;
41904- struct bin_attribute *nvram;
41905+ bin_attribute_no_const *nvram;
41906 enum ds_type type;
41907 unsigned long flags;
41908 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
41909diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
41910index 130f29a..6179d03 100644
41911--- a/drivers/rtc/rtc-m48t59.c
41912+++ b/drivers/rtc/rtc-m48t59.c
41913@@ -482,7 +482,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
41914 goto out;
41915 }
41916
41917- m48t59_nvram_attr.size = pdata->offset;
41918+ pax_open_kernel();
41919+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
41920+ pax_close_kernel();
41921
41922 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
41923 if (ret) {
41924diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
41925index e693af6..2e525b6 100644
41926--- a/drivers/scsi/bfa/bfa_fcpim.h
41927+++ b/drivers/scsi/bfa/bfa_fcpim.h
41928@@ -36,7 +36,7 @@ struct bfa_iotag_s {
41929
41930 struct bfa_itn_s {
41931 bfa_isr_func_t isr;
41932-};
41933+} __no_const;
41934
41935 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
41936 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
41937diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
41938index 23a90e7..9cf04ee 100644
41939--- a/drivers/scsi/bfa/bfa_ioc.h
41940+++ b/drivers/scsi/bfa/bfa_ioc.h
41941@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
41942 bfa_ioc_disable_cbfn_t disable_cbfn;
41943 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
41944 bfa_ioc_reset_cbfn_t reset_cbfn;
41945-};
41946+} __no_const;
41947
41948 /*
41949 * IOC event notification mechanism.
41950@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
41951 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
41952 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
41953 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
41954-};
41955+} __no_const;
41956
41957 /*
41958 * Queue element to wait for room in request queue. FIFO order is
41959diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
41960index 593085a..47aa999 100644
41961--- a/drivers/scsi/hosts.c
41962+++ b/drivers/scsi/hosts.c
41963@@ -42,7 +42,7 @@
41964 #include "scsi_logging.h"
41965
41966
41967-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
41968+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
41969
41970
41971 static void scsi_host_cls_release(struct device *dev)
41972@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
41973 * subtract one because we increment first then return, but we need to
41974 * know what the next host number was before increment
41975 */
41976- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
41977+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
41978 shost->dma_channel = 0xff;
41979
41980 /* These three are default values which can be overridden */
41981diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
41982index 4f33806..afd6f60 100644
41983--- a/drivers/scsi/hpsa.c
41984+++ b/drivers/scsi/hpsa.c
41985@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
41986 unsigned long flags;
41987
41988 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
41989- return h->access.command_completed(h, q);
41990+ return h->access->command_completed(h, q);
41991
41992 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
41993 a = rq->head[rq->current_entry];
41994@@ -3374,7 +3374,7 @@ static void start_io(struct ctlr_info *h)
41995 while (!list_empty(&h->reqQ)) {
41996 c = list_entry(h->reqQ.next, struct CommandList, list);
41997 /* can't do anything if fifo is full */
41998- if ((h->access.fifo_full(h))) {
41999+ if ((h->access->fifo_full(h))) {
42000 dev_warn(&h->pdev->dev, "fifo full\n");
42001 break;
42002 }
42003@@ -3396,7 +3396,7 @@ static void start_io(struct ctlr_info *h)
42004
42005 /* Tell the controller execute command */
42006 spin_unlock_irqrestore(&h->lock, flags);
42007- h->access.submit_command(h, c);
42008+ h->access->submit_command(h, c);
42009 spin_lock_irqsave(&h->lock, flags);
42010 }
42011 spin_unlock_irqrestore(&h->lock, flags);
42012@@ -3404,17 +3404,17 @@ static void start_io(struct ctlr_info *h)
42013
42014 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
42015 {
42016- return h->access.command_completed(h, q);
42017+ return h->access->command_completed(h, q);
42018 }
42019
42020 static inline bool interrupt_pending(struct ctlr_info *h)
42021 {
42022- return h->access.intr_pending(h);
42023+ return h->access->intr_pending(h);
42024 }
42025
42026 static inline long interrupt_not_for_us(struct ctlr_info *h)
42027 {
42028- return (h->access.intr_pending(h) == 0) ||
42029+ return (h->access->intr_pending(h) == 0) ||
42030 (h->interrupts_enabled == 0);
42031 }
42032
42033@@ -4316,7 +4316,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
42034 if (prod_index < 0)
42035 return -ENODEV;
42036 h->product_name = products[prod_index].product_name;
42037- h->access = *(products[prod_index].access);
42038+ h->access = products[prod_index].access;
42039
42040 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
42041 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
42042@@ -4598,7 +4598,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
42043
42044 assert_spin_locked(&lockup_detector_lock);
42045 remove_ctlr_from_lockup_detector_list(h);
42046- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42047+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42048 spin_lock_irqsave(&h->lock, flags);
42049 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
42050 spin_unlock_irqrestore(&h->lock, flags);
42051@@ -4775,7 +4775,7 @@ reinit_after_soft_reset:
42052 }
42053
42054 /* make sure the board interrupts are off */
42055- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42056+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42057
42058 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
42059 goto clean2;
42060@@ -4809,7 +4809,7 @@ reinit_after_soft_reset:
42061 * fake ones to scoop up any residual completions.
42062 */
42063 spin_lock_irqsave(&h->lock, flags);
42064- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42065+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42066 spin_unlock_irqrestore(&h->lock, flags);
42067 free_irqs(h);
42068 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
42069@@ -4828,9 +4828,9 @@ reinit_after_soft_reset:
42070 dev_info(&h->pdev->dev, "Board READY.\n");
42071 dev_info(&h->pdev->dev,
42072 "Waiting for stale completions to drain.\n");
42073- h->access.set_intr_mask(h, HPSA_INTR_ON);
42074+ h->access->set_intr_mask(h, HPSA_INTR_ON);
42075 msleep(10000);
42076- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42077+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42078
42079 rc = controller_reset_failed(h->cfgtable);
42080 if (rc)
42081@@ -4851,7 +4851,7 @@ reinit_after_soft_reset:
42082 }
42083
42084 /* Turn the interrupts on so we can service requests */
42085- h->access.set_intr_mask(h, HPSA_INTR_ON);
42086+ h->access->set_intr_mask(h, HPSA_INTR_ON);
42087
42088 hpsa_hba_inquiry(h);
42089 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
42090@@ -4903,7 +4903,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
42091 * To write all data in the battery backed cache to disks
42092 */
42093 hpsa_flush_cache(h);
42094- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42095+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42096 hpsa_free_irqs_and_disable_msix(h);
42097 }
42098
42099@@ -5071,7 +5071,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
42100 return;
42101 }
42102 /* Change the access methods to the performant access methods */
42103- h->access = SA5_performant_access;
42104+ h->access = &SA5_performant_access;
42105 h->transMethod = CFGTBL_Trans_Performant;
42106 }
42107
42108diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
42109index 9816479..c5d4e97 100644
42110--- a/drivers/scsi/hpsa.h
42111+++ b/drivers/scsi/hpsa.h
42112@@ -79,7 +79,7 @@ struct ctlr_info {
42113 unsigned int msix_vector;
42114 unsigned int msi_vector;
42115 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
42116- struct access_method access;
42117+ struct access_method *access;
42118
42119 /* queue and queue Info */
42120 struct list_head reqQ;
42121diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
42122index c772d8d..35c362c 100644
42123--- a/drivers/scsi/libfc/fc_exch.c
42124+++ b/drivers/scsi/libfc/fc_exch.c
42125@@ -100,12 +100,12 @@ struct fc_exch_mgr {
42126 u16 pool_max_index;
42127
42128 struct {
42129- atomic_t no_free_exch;
42130- atomic_t no_free_exch_xid;
42131- atomic_t xid_not_found;
42132- atomic_t xid_busy;
42133- atomic_t seq_not_found;
42134- atomic_t non_bls_resp;
42135+ atomic_unchecked_t no_free_exch;
42136+ atomic_unchecked_t no_free_exch_xid;
42137+ atomic_unchecked_t xid_not_found;
42138+ atomic_unchecked_t xid_busy;
42139+ atomic_unchecked_t seq_not_found;
42140+ atomic_unchecked_t non_bls_resp;
42141 } stats;
42142 };
42143
42144@@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
42145 /* allocate memory for exchange */
42146 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
42147 if (!ep) {
42148- atomic_inc(&mp->stats.no_free_exch);
42149+ atomic_inc_unchecked(&mp->stats.no_free_exch);
42150 goto out;
42151 }
42152 memset(ep, 0, sizeof(*ep));
42153@@ -786,7 +786,7 @@ out:
42154 return ep;
42155 err:
42156 spin_unlock_bh(&pool->lock);
42157- atomic_inc(&mp->stats.no_free_exch_xid);
42158+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
42159 mempool_free(ep, mp->ep_pool);
42160 return NULL;
42161 }
42162@@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42163 xid = ntohs(fh->fh_ox_id); /* we originated exch */
42164 ep = fc_exch_find(mp, xid);
42165 if (!ep) {
42166- atomic_inc(&mp->stats.xid_not_found);
42167+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42168 reject = FC_RJT_OX_ID;
42169 goto out;
42170 }
42171@@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42172 ep = fc_exch_find(mp, xid);
42173 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
42174 if (ep) {
42175- atomic_inc(&mp->stats.xid_busy);
42176+ atomic_inc_unchecked(&mp->stats.xid_busy);
42177 reject = FC_RJT_RX_ID;
42178 goto rel;
42179 }
42180@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42181 }
42182 xid = ep->xid; /* get our XID */
42183 } else if (!ep) {
42184- atomic_inc(&mp->stats.xid_not_found);
42185+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42186 reject = FC_RJT_RX_ID; /* XID not found */
42187 goto out;
42188 }
42189@@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42190 } else {
42191 sp = &ep->seq;
42192 if (sp->id != fh->fh_seq_id) {
42193- atomic_inc(&mp->stats.seq_not_found);
42194+ atomic_inc_unchecked(&mp->stats.seq_not_found);
42195 if (f_ctl & FC_FC_END_SEQ) {
42196 /*
42197 * Update sequence_id based on incoming last
42198@@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
42199
42200 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
42201 if (!ep) {
42202- atomic_inc(&mp->stats.xid_not_found);
42203+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42204 goto out;
42205 }
42206 if (ep->esb_stat & ESB_ST_COMPLETE) {
42207- atomic_inc(&mp->stats.xid_not_found);
42208+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42209 goto rel;
42210 }
42211 if (ep->rxid == FC_XID_UNKNOWN)
42212 ep->rxid = ntohs(fh->fh_rx_id);
42213 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
42214- atomic_inc(&mp->stats.xid_not_found);
42215+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42216 goto rel;
42217 }
42218 if (ep->did != ntoh24(fh->fh_s_id) &&
42219 ep->did != FC_FID_FLOGI) {
42220- atomic_inc(&mp->stats.xid_not_found);
42221+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42222 goto rel;
42223 }
42224 sof = fr_sof(fp);
42225@@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
42226 sp->ssb_stat |= SSB_ST_RESP;
42227 sp->id = fh->fh_seq_id;
42228 } else if (sp->id != fh->fh_seq_id) {
42229- atomic_inc(&mp->stats.seq_not_found);
42230+ atomic_inc_unchecked(&mp->stats.seq_not_found);
42231 goto rel;
42232 }
42233
42234@@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
42235 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
42236
42237 if (!sp)
42238- atomic_inc(&mp->stats.xid_not_found);
42239+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42240 else
42241- atomic_inc(&mp->stats.non_bls_resp);
42242+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
42243
42244 fc_frame_free(fp);
42245 }
42246@@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
42247
42248 list_for_each_entry(ema, &lport->ema_list, ema_list) {
42249 mp = ema->mp;
42250- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
42251+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
42252 st->fc_no_free_exch_xid +=
42253- atomic_read(&mp->stats.no_free_exch_xid);
42254- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
42255- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
42256- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
42257- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
42258+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
42259+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
42260+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
42261+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
42262+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
42263 }
42264 }
42265 EXPORT_SYMBOL(fc_exch_update_stats);
42266diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
42267index bdb81cd..d3c7c2c 100644
42268--- a/drivers/scsi/libsas/sas_ata.c
42269+++ b/drivers/scsi/libsas/sas_ata.c
42270@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
42271 .postreset = ata_std_postreset,
42272 .error_handler = ata_std_error_handler,
42273 .post_internal_cmd = sas_ata_post_internal,
42274- .qc_defer = ata_std_qc_defer,
42275+ .qc_defer = ata_std_qc_defer,
42276 .qc_prep = ata_noop_qc_prep,
42277 .qc_issue = sas_ata_qc_issue,
42278 .qc_fill_rtf = sas_ata_qc_fill_rtf,
42279diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
42280index df4c13a..a51e90c 100644
42281--- a/drivers/scsi/lpfc/lpfc.h
42282+++ b/drivers/scsi/lpfc/lpfc.h
42283@@ -424,7 +424,7 @@ struct lpfc_vport {
42284 struct dentry *debug_nodelist;
42285 struct dentry *vport_debugfs_root;
42286 struct lpfc_debugfs_trc *disc_trc;
42287- atomic_t disc_trc_cnt;
42288+ atomic_unchecked_t disc_trc_cnt;
42289 #endif
42290 uint8_t stat_data_enabled;
42291 uint8_t stat_data_blocked;
42292@@ -842,8 +842,8 @@ struct lpfc_hba {
42293 struct timer_list fabric_block_timer;
42294 unsigned long bit_flags;
42295 #define FABRIC_COMANDS_BLOCKED 0
42296- atomic_t num_rsrc_err;
42297- atomic_t num_cmd_success;
42298+ atomic_unchecked_t num_rsrc_err;
42299+ atomic_unchecked_t num_cmd_success;
42300 unsigned long last_rsrc_error_time;
42301 unsigned long last_ramp_down_time;
42302 unsigned long last_ramp_up_time;
42303@@ -879,7 +879,7 @@ struct lpfc_hba {
42304
42305 struct dentry *debug_slow_ring_trc;
42306 struct lpfc_debugfs_trc *slow_ring_trc;
42307- atomic_t slow_ring_trc_cnt;
42308+ atomic_unchecked_t slow_ring_trc_cnt;
42309 /* iDiag debugfs sub-directory */
42310 struct dentry *idiag_root;
42311 struct dentry *idiag_pci_cfg;
42312diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
42313index f63f5ff..de29189 100644
42314--- a/drivers/scsi/lpfc/lpfc_debugfs.c
42315+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
42316@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
42317
42318 #include <linux/debugfs.h>
42319
42320-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
42321+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
42322 static unsigned long lpfc_debugfs_start_time = 0L;
42323
42324 /* iDiag */
42325@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
42326 lpfc_debugfs_enable = 0;
42327
42328 len = 0;
42329- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
42330+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
42331 (lpfc_debugfs_max_disc_trc - 1);
42332 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
42333 dtp = vport->disc_trc + i;
42334@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
42335 lpfc_debugfs_enable = 0;
42336
42337 len = 0;
42338- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
42339+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
42340 (lpfc_debugfs_max_slow_ring_trc - 1);
42341 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
42342 dtp = phba->slow_ring_trc + i;
42343@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
42344 !vport || !vport->disc_trc)
42345 return;
42346
42347- index = atomic_inc_return(&vport->disc_trc_cnt) &
42348+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
42349 (lpfc_debugfs_max_disc_trc - 1);
42350 dtp = vport->disc_trc + index;
42351 dtp->fmt = fmt;
42352 dtp->data1 = data1;
42353 dtp->data2 = data2;
42354 dtp->data3 = data3;
42355- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
42356+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
42357 dtp->jif = jiffies;
42358 #endif
42359 return;
42360@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
42361 !phba || !phba->slow_ring_trc)
42362 return;
42363
42364- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
42365+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
42366 (lpfc_debugfs_max_slow_ring_trc - 1);
42367 dtp = phba->slow_ring_trc + index;
42368 dtp->fmt = fmt;
42369 dtp->data1 = data1;
42370 dtp->data2 = data2;
42371 dtp->data3 = data3;
42372- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
42373+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
42374 dtp->jif = jiffies;
42375 #endif
42376 return;
42377@@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
42378 "slow_ring buffer\n");
42379 goto debug_failed;
42380 }
42381- atomic_set(&phba->slow_ring_trc_cnt, 0);
42382+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
42383 memset(phba->slow_ring_trc, 0,
42384 (sizeof(struct lpfc_debugfs_trc) *
42385 lpfc_debugfs_max_slow_ring_trc));
42386@@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
42387 "buffer\n");
42388 goto debug_failed;
42389 }
42390- atomic_set(&vport->disc_trc_cnt, 0);
42391+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
42392
42393 snprintf(name, sizeof(name), "discovery_trace");
42394 vport->debug_disc_trc =
42395diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
42396index 89ad558..76956c4 100644
42397--- a/drivers/scsi/lpfc/lpfc_init.c
42398+++ b/drivers/scsi/lpfc/lpfc_init.c
42399@@ -10618,8 +10618,10 @@ lpfc_init(void)
42400 "misc_register returned with status %d", error);
42401
42402 if (lpfc_enable_npiv) {
42403- lpfc_transport_functions.vport_create = lpfc_vport_create;
42404- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
42405+ pax_open_kernel();
42406+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
42407+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
42408+ pax_close_kernel();
42409 }
42410 lpfc_transport_template =
42411 fc_attach_transport(&lpfc_transport_functions);
42412diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
42413index 60e5a17..ff7a793 100644
42414--- a/drivers/scsi/lpfc/lpfc_scsi.c
42415+++ b/drivers/scsi/lpfc/lpfc_scsi.c
42416@@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
42417 uint32_t evt_posted;
42418
42419 spin_lock_irqsave(&phba->hbalock, flags);
42420- atomic_inc(&phba->num_rsrc_err);
42421+ atomic_inc_unchecked(&phba->num_rsrc_err);
42422 phba->last_rsrc_error_time = jiffies;
42423
42424 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
42425@@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
42426 unsigned long flags;
42427 struct lpfc_hba *phba = vport->phba;
42428 uint32_t evt_posted;
42429- atomic_inc(&phba->num_cmd_success);
42430+ atomic_inc_unchecked(&phba->num_cmd_success);
42431
42432 if (vport->cfg_lun_queue_depth <= queue_depth)
42433 return;
42434@@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
42435 unsigned long num_rsrc_err, num_cmd_success;
42436 int i;
42437
42438- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
42439- num_cmd_success = atomic_read(&phba->num_cmd_success);
42440+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
42441+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
42442
42443 /*
42444 * The error and success command counters are global per
42445@@ -419,8 +419,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
42446 }
42447 }
42448 lpfc_destroy_vport_work_array(phba, vports);
42449- atomic_set(&phba->num_rsrc_err, 0);
42450- atomic_set(&phba->num_cmd_success, 0);
42451+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
42452+ atomic_set_unchecked(&phba->num_cmd_success, 0);
42453 }
42454
42455 /**
42456@@ -454,8 +454,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
42457 }
42458 }
42459 lpfc_destroy_vport_work_array(phba, vports);
42460- atomic_set(&phba->num_rsrc_err, 0);
42461- atomic_set(&phba->num_cmd_success, 0);
42462+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
42463+ atomic_set_unchecked(&phba->num_cmd_success, 0);
42464 }
42465
42466 /**
42467diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
42468index b46f5e9..c4c4ccb 100644
42469--- a/drivers/scsi/pmcraid.c
42470+++ b/drivers/scsi/pmcraid.c
42471@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
42472 res->scsi_dev = scsi_dev;
42473 scsi_dev->hostdata = res;
42474 res->change_detected = 0;
42475- atomic_set(&res->read_failures, 0);
42476- atomic_set(&res->write_failures, 0);
42477+ atomic_set_unchecked(&res->read_failures, 0);
42478+ atomic_set_unchecked(&res->write_failures, 0);
42479 rc = 0;
42480 }
42481 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
42482@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
42483
42484 /* If this was a SCSI read/write command keep count of errors */
42485 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
42486- atomic_inc(&res->read_failures);
42487+ atomic_inc_unchecked(&res->read_failures);
42488 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
42489- atomic_inc(&res->write_failures);
42490+ atomic_inc_unchecked(&res->write_failures);
42491
42492 if (!RES_IS_GSCSI(res->cfg_entry) &&
42493 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
42494@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
42495 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
42496 * hrrq_id assigned here in queuecommand
42497 */
42498- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
42499+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
42500 pinstance->num_hrrq;
42501 cmd->cmd_done = pmcraid_io_done;
42502
42503@@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
42504 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
42505 * hrrq_id assigned here in queuecommand
42506 */
42507- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
42508+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
42509 pinstance->num_hrrq;
42510
42511 if (request_size) {
42512@@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
42513
42514 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
42515 /* add resources only after host is added into system */
42516- if (!atomic_read(&pinstance->expose_resources))
42517+ if (!atomic_read_unchecked(&pinstance->expose_resources))
42518 return;
42519
42520 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
42521@@ -5324,8 +5324,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
42522 init_waitqueue_head(&pinstance->reset_wait_q);
42523
42524 atomic_set(&pinstance->outstanding_cmds, 0);
42525- atomic_set(&pinstance->last_message_id, 0);
42526- atomic_set(&pinstance->expose_resources, 0);
42527+ atomic_set_unchecked(&pinstance->last_message_id, 0);
42528+ atomic_set_unchecked(&pinstance->expose_resources, 0);
42529
42530 INIT_LIST_HEAD(&pinstance->free_res_q);
42531 INIT_LIST_HEAD(&pinstance->used_res_q);
42532@@ -6038,7 +6038,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
42533 /* Schedule worker thread to handle CCN and take care of adding and
42534 * removing devices to OS
42535 */
42536- atomic_set(&pinstance->expose_resources, 1);
42537+ atomic_set_unchecked(&pinstance->expose_resources, 1);
42538 schedule_work(&pinstance->worker_q);
42539 return rc;
42540
42541diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
42542index e1d150f..6c6df44 100644
42543--- a/drivers/scsi/pmcraid.h
42544+++ b/drivers/scsi/pmcraid.h
42545@@ -748,7 +748,7 @@ struct pmcraid_instance {
42546 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
42547
42548 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
42549- atomic_t last_message_id;
42550+ atomic_unchecked_t last_message_id;
42551
42552 /* configuration table */
42553 struct pmcraid_config_table *cfg_table;
42554@@ -777,7 +777,7 @@ struct pmcraid_instance {
42555 atomic_t outstanding_cmds;
42556
42557 /* should add/delete resources to mid-layer now ?*/
42558- atomic_t expose_resources;
42559+ atomic_unchecked_t expose_resources;
42560
42561
42562
42563@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
42564 struct pmcraid_config_table_entry_ext cfg_entry_ext;
42565 };
42566 struct scsi_device *scsi_dev; /* Link scsi_device structure */
42567- atomic_t read_failures; /* count of failed READ commands */
42568- atomic_t write_failures; /* count of failed WRITE commands */
42569+ atomic_unchecked_t read_failures; /* count of failed READ commands */
42570+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
42571
42572 /* To indicate add/delete/modify during CCN */
42573 u8 change_detected;
42574diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
42575index 83d7984..a27d947 100644
42576--- a/drivers/scsi/qla2xxx/qla_attr.c
42577+++ b/drivers/scsi/qla2xxx/qla_attr.c
42578@@ -1969,7 +1969,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
42579 return 0;
42580 }
42581
42582-struct fc_function_template qla2xxx_transport_functions = {
42583+fc_function_template_no_const qla2xxx_transport_functions = {
42584
42585 .show_host_node_name = 1,
42586 .show_host_port_name = 1,
42587@@ -2016,7 +2016,7 @@ struct fc_function_template qla2xxx_transport_functions = {
42588 .bsg_timeout = qla24xx_bsg_timeout,
42589 };
42590
42591-struct fc_function_template qla2xxx_transport_vport_functions = {
42592+fc_function_template_no_const qla2xxx_transport_vport_functions = {
42593
42594 .show_host_node_name = 1,
42595 .show_host_port_name = 1,
42596diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
42597index 2411d1a..4673766 100644
42598--- a/drivers/scsi/qla2xxx/qla_gbl.h
42599+++ b/drivers/scsi/qla2xxx/qla_gbl.h
42600@@ -515,8 +515,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
42601 struct device_attribute;
42602 extern struct device_attribute *qla2x00_host_attrs[];
42603 struct fc_function_template;
42604-extern struct fc_function_template qla2xxx_transport_functions;
42605-extern struct fc_function_template qla2xxx_transport_vport_functions;
42606+extern fc_function_template_no_const qla2xxx_transport_functions;
42607+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
42608 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
42609 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
42610 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
42611diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
42612index 10d23f8..a7d5d4c 100644
42613--- a/drivers/scsi/qla2xxx/qla_os.c
42614+++ b/drivers/scsi/qla2xxx/qla_os.c
42615@@ -1472,8 +1472,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
42616 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
42617 /* Ok, a 64bit DMA mask is applicable. */
42618 ha->flags.enable_64bit_addressing = 1;
42619- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
42620- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
42621+ pax_open_kernel();
42622+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
42623+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
42624+ pax_close_kernel();
42625 return;
42626 }
42627 }
42628diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
42629index 329d553..f20d31d 100644
42630--- a/drivers/scsi/qla4xxx/ql4_def.h
42631+++ b/drivers/scsi/qla4xxx/ql4_def.h
42632@@ -273,7 +273,7 @@ struct ddb_entry {
42633 * (4000 only) */
42634 atomic_t relogin_timer; /* Max Time to wait for
42635 * relogin to complete */
42636- atomic_t relogin_retry_count; /* Num of times relogin has been
42637+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
42638 * retried */
42639 uint32_t default_time2wait; /* Default Min time between
42640 * relogins (+aens) */
42641diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
42642index 4cec123..7c1329f 100644
42643--- a/drivers/scsi/qla4xxx/ql4_os.c
42644+++ b/drivers/scsi/qla4xxx/ql4_os.c
42645@@ -2621,12 +2621,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
42646 */
42647 if (!iscsi_is_session_online(cls_sess)) {
42648 /* Reset retry relogin timer */
42649- atomic_inc(&ddb_entry->relogin_retry_count);
42650+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
42651 DEBUG2(ql4_printk(KERN_INFO, ha,
42652 "%s: index[%d] relogin timed out-retrying"
42653 " relogin (%d), retry (%d)\n", __func__,
42654 ddb_entry->fw_ddb_index,
42655- atomic_read(&ddb_entry->relogin_retry_count),
42656+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
42657 ddb_entry->default_time2wait + 4));
42658 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
42659 atomic_set(&ddb_entry->retry_relogin_timer,
42660@@ -4738,7 +4738,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
42661
42662 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
42663 atomic_set(&ddb_entry->relogin_timer, 0);
42664- atomic_set(&ddb_entry->relogin_retry_count, 0);
42665+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
42666 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
42667 ddb_entry->default_relogin_timeout =
42668 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
42669diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
42670index 2c0d0ec..4e8681a 100644
42671--- a/drivers/scsi/scsi.c
42672+++ b/drivers/scsi/scsi.c
42673@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
42674 unsigned long timeout;
42675 int rtn = 0;
42676
42677- atomic_inc(&cmd->device->iorequest_cnt);
42678+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
42679
42680 /* check if the device is still usable */
42681 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
42682diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
42683index f1bf5af..f67e943 100644
42684--- a/drivers/scsi/scsi_lib.c
42685+++ b/drivers/scsi/scsi_lib.c
42686@@ -1454,7 +1454,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
42687 shost = sdev->host;
42688 scsi_init_cmd_errh(cmd);
42689 cmd->result = DID_NO_CONNECT << 16;
42690- atomic_inc(&cmd->device->iorequest_cnt);
42691+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
42692
42693 /*
42694 * SCSI request completion path will do scsi_device_unbusy(),
42695@@ -1480,9 +1480,9 @@ static void scsi_softirq_done(struct request *rq)
42696
42697 INIT_LIST_HEAD(&cmd->eh_entry);
42698
42699- atomic_inc(&cmd->device->iodone_cnt);
42700+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
42701 if (cmd->result)
42702- atomic_inc(&cmd->device->ioerr_cnt);
42703+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
42704
42705 disposition = scsi_decide_disposition(cmd);
42706 if (disposition != SUCCESS &&
42707diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
42708index 931a7d9..0c2a754 100644
42709--- a/drivers/scsi/scsi_sysfs.c
42710+++ b/drivers/scsi/scsi_sysfs.c
42711@@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
42712 char *buf) \
42713 { \
42714 struct scsi_device *sdev = to_scsi_device(dev); \
42715- unsigned long long count = atomic_read(&sdev->field); \
42716+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
42717 return snprintf(buf, 20, "0x%llx\n", count); \
42718 } \
42719 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
42720diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
42721index 84a1fdf..693b0d6 100644
42722--- a/drivers/scsi/scsi_tgt_lib.c
42723+++ b/drivers/scsi/scsi_tgt_lib.c
42724@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
42725 int err;
42726
42727 dprintk("%lx %u\n", uaddr, len);
42728- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
42729+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
42730 if (err) {
42731 /*
42732 * TODO: need to fixup sg_tablesize, max_segment_size,
42733diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
42734index e894ca7..de9d7660 100644
42735--- a/drivers/scsi/scsi_transport_fc.c
42736+++ b/drivers/scsi/scsi_transport_fc.c
42737@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
42738 * Netlink Infrastructure
42739 */
42740
42741-static atomic_t fc_event_seq;
42742+static atomic_unchecked_t fc_event_seq;
42743
42744 /**
42745 * fc_get_event_number - Obtain the next sequential FC event number
42746@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
42747 u32
42748 fc_get_event_number(void)
42749 {
42750- return atomic_add_return(1, &fc_event_seq);
42751+ return atomic_add_return_unchecked(1, &fc_event_seq);
42752 }
42753 EXPORT_SYMBOL(fc_get_event_number);
42754
42755@@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
42756 {
42757 int error;
42758
42759- atomic_set(&fc_event_seq, 0);
42760+ atomic_set_unchecked(&fc_event_seq, 0);
42761
42762 error = transport_class_register(&fc_host_class);
42763 if (error)
42764@@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
42765 char *cp;
42766
42767 *val = simple_strtoul(buf, &cp, 0);
42768- if ((*cp && (*cp != '\n')) || (*val < 0))
42769+ if (*cp && (*cp != '\n'))
42770 return -EINVAL;
42771 /*
42772 * Check for overflow; dev_loss_tmo is u32
42773diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
42774index 31969f2..2b348f0 100644
42775--- a/drivers/scsi/scsi_transport_iscsi.c
42776+++ b/drivers/scsi/scsi_transport_iscsi.c
42777@@ -79,7 +79,7 @@ struct iscsi_internal {
42778 struct transport_container session_cont;
42779 };
42780
42781-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
42782+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
42783 static struct workqueue_struct *iscsi_eh_timer_workq;
42784
42785 static DEFINE_IDA(iscsi_sess_ida);
42786@@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
42787 int err;
42788
42789 ihost = shost->shost_data;
42790- session->sid = atomic_add_return(1, &iscsi_session_nr);
42791+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
42792
42793 if (target_id == ISCSI_MAX_TARGET) {
42794 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
42795@@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
42796 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
42797 ISCSI_TRANSPORT_VERSION);
42798
42799- atomic_set(&iscsi_session_nr, 0);
42800+ atomic_set_unchecked(&iscsi_session_nr, 0);
42801
42802 err = class_register(&iscsi_transport_class);
42803 if (err)
42804diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
42805index f379c7f..e8fc69c 100644
42806--- a/drivers/scsi/scsi_transport_srp.c
42807+++ b/drivers/scsi/scsi_transport_srp.c
42808@@ -33,7 +33,7 @@
42809 #include "scsi_transport_srp_internal.h"
42810
42811 struct srp_host_attrs {
42812- atomic_t next_port_id;
42813+ atomic_unchecked_t next_port_id;
42814 };
42815 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
42816
42817@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
42818 struct Scsi_Host *shost = dev_to_shost(dev);
42819 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
42820
42821- atomic_set(&srp_host->next_port_id, 0);
42822+ atomic_set_unchecked(&srp_host->next_port_id, 0);
42823 return 0;
42824 }
42825
42826@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
42827 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
42828 rport->roles = ids->roles;
42829
42830- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
42831+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
42832 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
42833
42834 transport_setup_device(&rport->dev);
42835diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
42836index 7992635..609faf8 100644
42837--- a/drivers/scsi/sd.c
42838+++ b/drivers/scsi/sd.c
42839@@ -2909,7 +2909,7 @@ static int sd_probe(struct device *dev)
42840 sdkp->disk = gd;
42841 sdkp->index = index;
42842 atomic_set(&sdkp->openers, 0);
42843- atomic_set(&sdkp->device->ioerr_cnt, 0);
42844+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
42845
42846 if (!sdp->request_queue->rq_timeout) {
42847 if (sdp->type != TYPE_MOD)
42848diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
42849index be2c9a6..275525c 100644
42850--- a/drivers/scsi/sg.c
42851+++ b/drivers/scsi/sg.c
42852@@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
42853 sdp->disk->disk_name,
42854 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
42855 NULL,
42856- (char *)arg);
42857+ (char __user *)arg);
42858 case BLKTRACESTART:
42859 return blk_trace_startstop(sdp->device->request_queue, 1);
42860 case BLKTRACESTOP:
42861diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
42862index 19ee901..6e8c2ef 100644
42863--- a/drivers/spi/spi.c
42864+++ b/drivers/spi/spi.c
42865@@ -1616,7 +1616,7 @@ int spi_bus_unlock(struct spi_master *master)
42866 EXPORT_SYMBOL_GPL(spi_bus_unlock);
42867
42868 /* portable code must never pass more than 32 bytes */
42869-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
42870+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
42871
42872 static u8 *buf;
42873
42874diff --git a/drivers/staging/iio/iio_hwmon.c b/drivers/staging/iio/iio_hwmon.c
42875index c7a5f97..71ecd35 100644
42876--- a/drivers/staging/iio/iio_hwmon.c
42877+++ b/drivers/staging/iio/iio_hwmon.c
42878@@ -72,7 +72,7 @@ static void iio_hwmon_free_attrs(struct iio_hwmon_state *st)
42879 static int iio_hwmon_probe(struct platform_device *pdev)
42880 {
42881 struct iio_hwmon_state *st;
42882- struct sensor_device_attribute *a;
42883+ sensor_device_attribute_no_const *a;
42884 int ret, i;
42885 int in_i = 1, temp_i = 1, curr_i = 1;
42886 enum iio_chan_type type;
42887diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
42888index 34afc16..ffe44dd 100644
42889--- a/drivers/staging/octeon/ethernet-rx.c
42890+++ b/drivers/staging/octeon/ethernet-rx.c
42891@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
42892 /* Increment RX stats for virtual ports */
42893 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
42894 #ifdef CONFIG_64BIT
42895- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
42896- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
42897+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
42898+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
42899 #else
42900- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
42901- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
42902+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
42903+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
42904 #endif
42905 }
42906 netif_receive_skb(skb);
42907@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
42908 dev->name);
42909 */
42910 #ifdef CONFIG_64BIT
42911- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
42912+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
42913 #else
42914- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
42915+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
42916 #endif
42917 dev_kfree_skb_irq(skb);
42918 }
42919diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
42920index ef32dc1..a159d68 100644
42921--- a/drivers/staging/octeon/ethernet.c
42922+++ b/drivers/staging/octeon/ethernet.c
42923@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
42924 * since the RX tasklet also increments it.
42925 */
42926 #ifdef CONFIG_64BIT
42927- atomic64_add(rx_status.dropped_packets,
42928- (atomic64_t *)&priv->stats.rx_dropped);
42929+ atomic64_add_unchecked(rx_status.dropped_packets,
42930+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
42931 #else
42932- atomic_add(rx_status.dropped_packets,
42933- (atomic_t *)&priv->stats.rx_dropped);
42934+ atomic_add_unchecked(rx_status.dropped_packets,
42935+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
42936 #endif
42937 }
42938
42939diff --git a/drivers/staging/ramster/tmem.c b/drivers/staging/ramster/tmem.c
42940index a2b7e03..aaf3630 100644
42941--- a/drivers/staging/ramster/tmem.c
42942+++ b/drivers/staging/ramster/tmem.c
42943@@ -50,25 +50,25 @@
42944 * A tmem host implementation must use this function to register callbacks
42945 * for memory allocation.
42946 */
42947-static struct tmem_hostops tmem_hostops;
42948+static struct tmem_hostops *tmem_hostops;
42949
42950 static void tmem_objnode_tree_init(void);
42951
42952 void tmem_register_hostops(struct tmem_hostops *m)
42953 {
42954 tmem_objnode_tree_init();
42955- tmem_hostops = *m;
42956+ tmem_hostops = m;
42957 }
42958
42959 /*
42960 * A tmem host implementation must use this function to register
42961 * callbacks for a page-accessible memory (PAM) implementation.
42962 */
42963-static struct tmem_pamops tmem_pamops;
42964+static struct tmem_pamops *tmem_pamops;
42965
42966 void tmem_register_pamops(struct tmem_pamops *m)
42967 {
42968- tmem_pamops = *m;
42969+ tmem_pamops = m;
42970 }
42971
42972 /*
42973@@ -174,7 +174,7 @@ static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb,
42974 obj->pampd_count = 0;
42975 #ifdef CONFIG_RAMSTER
42976 if (tmem_pamops.new_obj != NULL)
42977- (*tmem_pamops.new_obj)(obj);
42978+ (tmem_pamops->new_obj)(obj);
42979 #endif
42980 SET_SENTINEL(obj, OBJ);
42981
42982@@ -210,7 +210,7 @@ static void tmem_pool_flush(struct tmem_pool *pool, bool destroy)
42983 rbnode = rb_next(rbnode);
42984 tmem_pampd_destroy_all_in_obj(obj, true);
42985 tmem_obj_free(obj, hb);
42986- (*tmem_hostops.obj_free)(obj, pool);
42987+ (tmem_hostops->obj_free)(obj, pool);
42988 }
42989 spin_unlock(&hb->lock);
42990 }
42991@@ -261,7 +261,7 @@ static struct tmem_objnode *tmem_objnode_alloc(struct tmem_obj *obj)
42992 ASSERT_SENTINEL(obj, OBJ);
42993 BUG_ON(obj->pool == NULL);
42994 ASSERT_SENTINEL(obj->pool, POOL);
42995- objnode = (*tmem_hostops.objnode_alloc)(obj->pool);
42996+ objnode = (tmem_hostops->objnode_alloc)(obj->pool);
42997 if (unlikely(objnode == NULL))
42998 goto out;
42999 objnode->obj = obj;
43000@@ -290,7 +290,7 @@ static void tmem_objnode_free(struct tmem_objnode *objnode)
43001 ASSERT_SENTINEL(pool, POOL);
43002 objnode->obj->objnode_count--;
43003 objnode->obj = NULL;
43004- (*tmem_hostops.objnode_free)(objnode, pool);
43005+ (tmem_hostops->objnode_free)(objnode, pool);
43006 }
43007
43008 /*
43009@@ -348,7 +348,7 @@ static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index,
43010 void *old_pampd = *(void **)slot;
43011 *(void **)slot = new_pampd;
43012 if (!no_free)
43013- (*tmem_pamops.free)(old_pampd, obj->pool,
43014+ (tmem_pamops->free)(old_pampd, obj->pool,
43015 NULL, 0, false);
43016 ret = new_pampd;
43017 }
43018@@ -505,7 +505,7 @@ static void tmem_objnode_node_destroy(struct tmem_obj *obj,
43019 if (objnode->slots[i]) {
43020 if (ht == 1) {
43021 obj->pampd_count--;
43022- (*tmem_pamops.free)(objnode->slots[i],
43023+ (tmem_pamops->free)(objnode->slots[i],
43024 obj->pool, NULL, 0, true);
43025 objnode->slots[i] = NULL;
43026 continue;
43027@@ -524,7 +524,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
43028 return;
43029 if (obj->objnode_tree_height == 0) {
43030 obj->pampd_count--;
43031- (*tmem_pamops.free)(obj->objnode_tree_root,
43032+ (tmem_pamops->free)(obj->objnode_tree_root,
43033 obj->pool, NULL, 0, true);
43034 } else {
43035 tmem_objnode_node_destroy(obj, obj->objnode_tree_root,
43036@@ -535,7 +535,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
43037 obj->objnode_tree_root = NULL;
43038 #ifdef CONFIG_RAMSTER
43039 if (tmem_pamops.free_obj != NULL)
43040- (*tmem_pamops.free_obj)(obj->pool, obj, pool_destroy);
43041+ (tmem_pamops->free_obj)(obj->pool, obj, pool_destroy);
43042 #endif
43043 }
43044
43045@@ -574,7 +574,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
43046 /* if found, is a dup put, flush the old one */
43047 pampd_del = tmem_pampd_delete_from_obj(obj, index);
43048 BUG_ON(pampd_del != pampd);
43049- (*tmem_pamops.free)(pampd, pool, oidp, index, true);
43050+ (tmem_pamops->free)(pampd, pool, oidp, index, true);
43051 if (obj->pampd_count == 0) {
43052 objnew = obj;
43053 objfound = NULL;
43054@@ -582,7 +582,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
43055 pampd = NULL;
43056 }
43057 } else {
43058- obj = objnew = (*tmem_hostops.obj_alloc)(pool);
43059+ obj = objnew = (tmem_hostops->obj_alloc)(pool);
43060 if (unlikely(obj == NULL)) {
43061 ret = -ENOMEM;
43062 goto out;
43063@@ -597,16 +597,16 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
43064 if (unlikely(ret == -ENOMEM))
43065 /* may have partially built objnode tree ("stump") */
43066 goto delete_and_free;
43067- (*tmem_pamops.create_finish)(pampd, is_ephemeral(pool));
43068+ (tmem_pamops->create_finish)(pampd, is_ephemeral(pool));
43069 goto out;
43070
43071 delete_and_free:
43072 (void)tmem_pampd_delete_from_obj(obj, index);
43073 if (pampd)
43074- (*tmem_pamops.free)(pampd, pool, NULL, 0, true);
43075+ (tmem_pamops->free)(pampd, pool, NULL, 0, true);
43076 if (objnew) {
43077 tmem_obj_free(objnew, hb);
43078- (*tmem_hostops.obj_free)(objnew, pool);
43079+ (tmem_hostops->obj_free)(objnew, pool);
43080 }
43081 out:
43082 spin_unlock(&hb->lock);
43083@@ -651,7 +651,7 @@ void tmem_localify_finish(struct tmem_obj *obj, uint32_t index,
43084 if (pampd != NULL) {
43085 BUG_ON(obj == NULL);
43086 (void)tmem_pampd_replace_in_obj(obj, index, pampd, 1);
43087- (*tmem_pamops.create_finish)(pampd, is_ephemeral(obj->pool));
43088+ (tmem_pamops->create_finish)(pampd, is_ephemeral(obj->pool));
43089 } else if (delete) {
43090 BUG_ON(obj == NULL);
43091 (void)tmem_pampd_delete_from_obj(obj, index);
43092@@ -671,7 +671,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
43093 int ret = 0;
43094
43095 if (!is_ephemeral(pool))
43096- new_pampd = (*tmem_pamops.repatriate_preload)(
43097+ new_pampd = (tmem_pamops->repatriate_preload)(
43098 old_pampd, pool, oidp, index, &intransit);
43099 if (intransit)
43100 ret = -EAGAIN;
43101@@ -680,7 +680,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
43102 /* must release the hb->lock else repatriate can't sleep */
43103 spin_unlock(&hb->lock);
43104 if (!intransit)
43105- ret = (*tmem_pamops.repatriate)(old_pampd, new_pampd, pool,
43106+ ret = (tmem_pamops->repatriate)(old_pampd, new_pampd, pool,
43107 oidp, index, free, data);
43108 if (ret == -EAGAIN) {
43109 /* rare I think, but should cond_resched()??? */
43110@@ -714,7 +714,7 @@ int tmem_replace(struct tmem_pool *pool, struct tmem_oid *oidp,
43111 new_pampd = tmem_pampd_replace_in_obj(obj, index, new_pampd, 0);
43112 /* if we bug here, pamops wasn't properly set up for ramster */
43113 BUG_ON(tmem_pamops.replace_in_obj == NULL);
43114- ret = (*tmem_pamops.replace_in_obj)(new_pampd, obj);
43115+ ret = (tmem_pamops->replace_in_obj)(new_pampd, obj);
43116 out:
43117 spin_unlock(&hb->lock);
43118 return ret;
43119@@ -776,15 +776,15 @@ int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
43120 if (free) {
43121 if (obj->pampd_count == 0) {
43122 tmem_obj_free(obj, hb);
43123- (*tmem_hostops.obj_free)(obj, pool);
43124+ (tmem_hostops->obj_free)(obj, pool);
43125 obj = NULL;
43126 }
43127 }
43128 if (free)
43129- ret = (*tmem_pamops.get_data_and_free)(
43130+ ret = (tmem_pamops->get_data_and_free)(
43131 data, sizep, raw, pampd, pool, oidp, index);
43132 else
43133- ret = (*tmem_pamops.get_data)(
43134+ ret = (tmem_pamops->get_data)(
43135 data, sizep, raw, pampd, pool, oidp, index);
43136 if (ret < 0)
43137 goto out;
43138@@ -816,10 +816,10 @@ int tmem_flush_page(struct tmem_pool *pool,
43139 pampd = tmem_pampd_delete_from_obj(obj, index);
43140 if (pampd == NULL)
43141 goto out;
43142- (*tmem_pamops.free)(pampd, pool, oidp, index, true);
43143+ (tmem_pamops->free)(pampd, pool, oidp, index, true);
43144 if (obj->pampd_count == 0) {
43145 tmem_obj_free(obj, hb);
43146- (*tmem_hostops.obj_free)(obj, pool);
43147+ (tmem_hostops->obj_free)(obj, pool);
43148 }
43149 ret = 0;
43150
43151@@ -844,7 +844,7 @@ int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp)
43152 goto out;
43153 tmem_pampd_destroy_all_in_obj(obj, false);
43154 tmem_obj_free(obj, hb);
43155- (*tmem_hostops.obj_free)(obj, pool);
43156+ (tmem_hostops->obj_free)(obj, pool);
43157 ret = 0;
43158
43159 out:
43160diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
43161index dc23395..cf7e9b1 100644
43162--- a/drivers/staging/rtl8712/rtl871x_io.h
43163+++ b/drivers/staging/rtl8712/rtl871x_io.h
43164@@ -108,7 +108,7 @@ struct _io_ops {
43165 u8 *pmem);
43166 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
43167 u8 *pmem);
43168-};
43169+} __no_const;
43170
43171 struct io_req {
43172 struct list_head list;
43173diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
43174index 1f5088b..0e59820 100644
43175--- a/drivers/staging/sbe-2t3e3/netdev.c
43176+++ b/drivers/staging/sbe-2t3e3/netdev.c
43177@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43178 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
43179
43180 if (rlen)
43181- if (copy_to_user(data, &resp, rlen))
43182+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
43183 return -EFAULT;
43184
43185 return 0;
43186diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
43187index 5dddc4d..34fcb2f 100644
43188--- a/drivers/staging/usbip/vhci.h
43189+++ b/drivers/staging/usbip/vhci.h
43190@@ -83,7 +83,7 @@ struct vhci_hcd {
43191 unsigned resuming:1;
43192 unsigned long re_timeout;
43193
43194- atomic_t seqnum;
43195+ atomic_unchecked_t seqnum;
43196
43197 /*
43198 * NOTE:
43199diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
43200index c3aa219..bf8b3de 100644
43201--- a/drivers/staging/usbip/vhci_hcd.c
43202+++ b/drivers/staging/usbip/vhci_hcd.c
43203@@ -451,7 +451,7 @@ static void vhci_tx_urb(struct urb *urb)
43204 return;
43205 }
43206
43207- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
43208+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
43209 if (priv->seqnum == 0xffff)
43210 dev_info(&urb->dev->dev, "seqnum max\n");
43211
43212@@ -703,7 +703,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
43213 return -ENOMEM;
43214 }
43215
43216- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
43217+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
43218 if (unlink->seqnum == 0xffff)
43219 pr_info("seqnum max\n");
43220
43221@@ -907,7 +907,7 @@ static int vhci_start(struct usb_hcd *hcd)
43222 vdev->rhport = rhport;
43223 }
43224
43225- atomic_set(&vhci->seqnum, 0);
43226+ atomic_set_unchecked(&vhci->seqnum, 0);
43227 spin_lock_init(&vhci->lock);
43228
43229 hcd->power_budget = 0; /* no limit */
43230diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
43231index ba5f1c0..11d8122 100644
43232--- a/drivers/staging/usbip/vhci_rx.c
43233+++ b/drivers/staging/usbip/vhci_rx.c
43234@@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
43235 if (!urb) {
43236 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
43237 pr_info("max seqnum %d\n",
43238- atomic_read(&the_controller->seqnum));
43239+ atomic_read_unchecked(&the_controller->seqnum));
43240 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
43241 return;
43242 }
43243diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
43244index 5f13890..36a044b 100644
43245--- a/drivers/staging/vt6655/hostap.c
43246+++ b/drivers/staging/vt6655/hostap.c
43247@@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
43248 *
43249 */
43250
43251+static net_device_ops_no_const apdev_netdev_ops;
43252+
43253 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
43254 {
43255 PSDevice apdev_priv;
43256 struct net_device *dev = pDevice->dev;
43257 int ret;
43258- const struct net_device_ops apdev_netdev_ops = {
43259- .ndo_start_xmit = pDevice->tx_80211,
43260- };
43261
43262 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
43263
43264@@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
43265 *apdev_priv = *pDevice;
43266 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
43267
43268+ /* only half broken now */
43269+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
43270 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
43271
43272 pDevice->apdev->type = ARPHRD_IEEE80211;
43273diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
43274index 26a7d0e..897b083 100644
43275--- a/drivers/staging/vt6656/hostap.c
43276+++ b/drivers/staging/vt6656/hostap.c
43277@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
43278 *
43279 */
43280
43281+static net_device_ops_no_const apdev_netdev_ops;
43282+
43283 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
43284 {
43285 PSDevice apdev_priv;
43286 struct net_device *dev = pDevice->dev;
43287 int ret;
43288- const struct net_device_ops apdev_netdev_ops = {
43289- .ndo_start_xmit = pDevice->tx_80211,
43290- };
43291
43292 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
43293
43294@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
43295 *apdev_priv = *pDevice;
43296 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
43297
43298+ /* only half broken now */
43299+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
43300 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
43301
43302 pDevice->apdev->type = ARPHRD_IEEE80211;
43303diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
43304index 56c8e60..1920c63 100644
43305--- a/drivers/staging/zcache/tmem.c
43306+++ b/drivers/staging/zcache/tmem.c
43307@@ -39,7 +39,7 @@
43308 * A tmem host implementation must use this function to register callbacks
43309 * for memory allocation.
43310 */
43311-static struct tmem_hostops tmem_hostops;
43312+static tmem_hostops_no_const tmem_hostops;
43313
43314 static void tmem_objnode_tree_init(void);
43315
43316@@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
43317 * A tmem host implementation must use this function to register
43318 * callbacks for a page-accessible memory (PAM) implementation
43319 */
43320-static struct tmem_pamops tmem_pamops;
43321+static tmem_pamops_no_const tmem_pamops;
43322
43323 void tmem_register_pamops(struct tmem_pamops *m)
43324 {
43325diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
43326index 0d4aa82..f7832d4 100644
43327--- a/drivers/staging/zcache/tmem.h
43328+++ b/drivers/staging/zcache/tmem.h
43329@@ -180,6 +180,7 @@ struct tmem_pamops {
43330 void (*new_obj)(struct tmem_obj *);
43331 int (*replace_in_obj)(void *, struct tmem_obj *);
43332 };
43333+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
43334 extern void tmem_register_pamops(struct tmem_pamops *m);
43335
43336 /* memory allocation methods provided by the host implementation */
43337@@ -189,6 +190,7 @@ struct tmem_hostops {
43338 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
43339 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
43340 };
43341+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
43342 extern void tmem_register_hostops(struct tmem_hostops *m);
43343
43344 /* core tmem accessor functions */
43345diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
43346index 96f4981..4daaa7e 100644
43347--- a/drivers/target/target_core_device.c
43348+++ b/drivers/target/target_core_device.c
43349@@ -1370,7 +1370,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
43350 spin_lock_init(&dev->se_port_lock);
43351 spin_lock_init(&dev->se_tmr_lock);
43352 spin_lock_init(&dev->qf_cmd_lock);
43353- atomic_set(&dev->dev_ordered_id, 0);
43354+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
43355 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
43356 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
43357 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
43358diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
43359index fcf880f..a4d1e8f 100644
43360--- a/drivers/target/target_core_transport.c
43361+++ b/drivers/target/target_core_transport.c
43362@@ -1077,7 +1077,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
43363 * Used to determine when ORDERED commands should go from
43364 * Dormant to Active status.
43365 */
43366- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
43367+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
43368 smp_mb__after_atomic_inc();
43369 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
43370 cmd->se_ordered_id, cmd->sam_task_attr,
43371diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
43372index b09c8d1f..c4225c0 100644
43373--- a/drivers/tty/cyclades.c
43374+++ b/drivers/tty/cyclades.c
43375@@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
43376 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
43377 info->port.count);
43378 #endif
43379- info->port.count++;
43380+ atomic_inc(&info->port.count);
43381 #ifdef CY_DEBUG_COUNT
43382 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
43383- current->pid, info->port.count);
43384+ current->pid, atomic_read(&info->port.count));
43385 #endif
43386
43387 /*
43388@@ -3991,7 +3991,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
43389 for (j = 0; j < cy_card[i].nports; j++) {
43390 info = &cy_card[i].ports[j];
43391
43392- if (info->port.count) {
43393+ if (atomic_read(&info->port.count)) {
43394 /* XXX is the ldisc num worth this? */
43395 struct tty_struct *tty;
43396 struct tty_ldisc *ld;
43397diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
43398index 13ee53b..418d164 100644
43399--- a/drivers/tty/hvc/hvc_console.c
43400+++ b/drivers/tty/hvc/hvc_console.c
43401@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
43402
43403 spin_lock_irqsave(&hp->port.lock, flags);
43404 /* Check and then increment for fast path open. */
43405- if (hp->port.count++ > 0) {
43406+ if (atomic_inc_return(&hp->port.count) > 1) {
43407 spin_unlock_irqrestore(&hp->port.lock, flags);
43408 hvc_kick();
43409 return 0;
43410@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
43411
43412 spin_lock_irqsave(&hp->port.lock, flags);
43413
43414- if (--hp->port.count == 0) {
43415+ if (atomic_dec_return(&hp->port.count) == 0) {
43416 spin_unlock_irqrestore(&hp->port.lock, flags);
43417 /* We are done with the tty pointer now. */
43418 tty_port_tty_set(&hp->port, NULL);
43419@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
43420 */
43421 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
43422 } else {
43423- if (hp->port.count < 0)
43424+ if (atomic_read(&hp->port.count) < 0)
43425 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
43426- hp->vtermno, hp->port.count);
43427+ hp->vtermno, atomic_read(&hp->port.count));
43428 spin_unlock_irqrestore(&hp->port.lock, flags);
43429 }
43430 }
43431@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
43432 * open->hangup case this can be called after the final close so prevent
43433 * that from happening for now.
43434 */
43435- if (hp->port.count <= 0) {
43436+ if (atomic_read(&hp->port.count) <= 0) {
43437 spin_unlock_irqrestore(&hp->port.lock, flags);
43438 return;
43439 }
43440
43441- hp->port.count = 0;
43442+ atomic_set(&hp->port.count, 0);
43443 spin_unlock_irqrestore(&hp->port.lock, flags);
43444 tty_port_tty_set(&hp->port, NULL);
43445
43446@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
43447 return -EPIPE;
43448
43449 /* FIXME what's this (unprotected) check for? */
43450- if (hp->port.count <= 0)
43451+ if (atomic_read(&hp->port.count) <= 0)
43452 return -EIO;
43453
43454 spin_lock_irqsave(&hp->lock, flags);
43455diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
43456index 8776357..b2d4afd 100644
43457--- a/drivers/tty/hvc/hvcs.c
43458+++ b/drivers/tty/hvc/hvcs.c
43459@@ -83,6 +83,7 @@
43460 #include <asm/hvcserver.h>
43461 #include <asm/uaccess.h>
43462 #include <asm/vio.h>
43463+#include <asm/local.h>
43464
43465 /*
43466 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
43467@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
43468
43469 spin_lock_irqsave(&hvcsd->lock, flags);
43470
43471- if (hvcsd->port.count > 0) {
43472+ if (atomic_read(&hvcsd->port.count) > 0) {
43473 spin_unlock_irqrestore(&hvcsd->lock, flags);
43474 printk(KERN_INFO "HVCS: vterm state unchanged. "
43475 "The hvcs device node is still in use.\n");
43476@@ -1132,7 +1133,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
43477 }
43478 }
43479
43480- hvcsd->port.count = 0;
43481+ atomic_set(&hvcsd->port.count, 0);
43482 hvcsd->port.tty = tty;
43483 tty->driver_data = hvcsd;
43484
43485@@ -1185,7 +1186,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
43486 unsigned long flags;
43487
43488 spin_lock_irqsave(&hvcsd->lock, flags);
43489- hvcsd->port.count++;
43490+ atomic_inc(&hvcsd->port.count);
43491 hvcsd->todo_mask |= HVCS_SCHED_READ;
43492 spin_unlock_irqrestore(&hvcsd->lock, flags);
43493
43494@@ -1221,7 +1222,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
43495 hvcsd = tty->driver_data;
43496
43497 spin_lock_irqsave(&hvcsd->lock, flags);
43498- if (--hvcsd->port.count == 0) {
43499+ if (atomic_dec_and_test(&hvcsd->port.count)) {
43500
43501 vio_disable_interrupts(hvcsd->vdev);
43502
43503@@ -1246,10 +1247,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
43504
43505 free_irq(irq, hvcsd);
43506 return;
43507- } else if (hvcsd->port.count < 0) {
43508+ } else if (atomic_read(&hvcsd->port.count) < 0) {
43509 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
43510 " is missmanaged.\n",
43511- hvcsd->vdev->unit_address, hvcsd->port.count);
43512+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
43513 }
43514
43515 spin_unlock_irqrestore(&hvcsd->lock, flags);
43516@@ -1271,7 +1272,7 @@ static void hvcs_hangup(struct tty_struct * tty)
43517
43518 spin_lock_irqsave(&hvcsd->lock, flags);
43519 /* Preserve this so that we know how many kref refs to put */
43520- temp_open_count = hvcsd->port.count;
43521+ temp_open_count = atomic_read(&hvcsd->port.count);
43522
43523 /*
43524 * Don't kref put inside the spinlock because the destruction
43525@@ -1286,7 +1287,7 @@ static void hvcs_hangup(struct tty_struct * tty)
43526 tty->driver_data = NULL;
43527 hvcsd->port.tty = NULL;
43528
43529- hvcsd->port.count = 0;
43530+ atomic_set(&hvcsd->port.count, 0);
43531
43532 /* This will drop any buffered data on the floor which is OK in a hangup
43533 * scenario. */
43534@@ -1357,7 +1358,7 @@ static int hvcs_write(struct tty_struct *tty,
43535 * the middle of a write operation? This is a crummy place to do this
43536 * but we want to keep it all in the spinlock.
43537 */
43538- if (hvcsd->port.count <= 0) {
43539+ if (atomic_read(&hvcsd->port.count) <= 0) {
43540 spin_unlock_irqrestore(&hvcsd->lock, flags);
43541 return -ENODEV;
43542 }
43543@@ -1431,7 +1432,7 @@ static int hvcs_write_room(struct tty_struct *tty)
43544 {
43545 struct hvcs_struct *hvcsd = tty->driver_data;
43546
43547- if (!hvcsd || hvcsd->port.count <= 0)
43548+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
43549 return 0;
43550
43551 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
43552diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
43553index 2cde13d..645d78f 100644
43554--- a/drivers/tty/ipwireless/tty.c
43555+++ b/drivers/tty/ipwireless/tty.c
43556@@ -29,6 +29,7 @@
43557 #include <linux/tty_driver.h>
43558 #include <linux/tty_flip.h>
43559 #include <linux/uaccess.h>
43560+#include <asm/local.h>
43561
43562 #include "tty.h"
43563 #include "network.h"
43564@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
43565 mutex_unlock(&tty->ipw_tty_mutex);
43566 return -ENODEV;
43567 }
43568- if (tty->port.count == 0)
43569+ if (atomic_read(&tty->port.count) == 0)
43570 tty->tx_bytes_queued = 0;
43571
43572- tty->port.count++;
43573+ atomic_inc(&tty->port.count);
43574
43575 tty->port.tty = linux_tty;
43576 linux_tty->driver_data = tty;
43577@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
43578
43579 static void do_ipw_close(struct ipw_tty *tty)
43580 {
43581- tty->port.count--;
43582-
43583- if (tty->port.count == 0) {
43584+ if (atomic_dec_return(&tty->port.count) == 0) {
43585 struct tty_struct *linux_tty = tty->port.tty;
43586
43587 if (linux_tty != NULL) {
43588@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
43589 return;
43590
43591 mutex_lock(&tty->ipw_tty_mutex);
43592- if (tty->port.count == 0) {
43593+ if (atomic_read(&tty->port.count) == 0) {
43594 mutex_unlock(&tty->ipw_tty_mutex);
43595 return;
43596 }
43597@@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
43598 return;
43599 }
43600
43601- if (!tty->port.count) {
43602+ if (!atomic_read(&tty->port.count)) {
43603 mutex_unlock(&tty->ipw_tty_mutex);
43604 return;
43605 }
43606@@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
43607 return -ENODEV;
43608
43609 mutex_lock(&tty->ipw_tty_mutex);
43610- if (!tty->port.count) {
43611+ if (!atomic_read(&tty->port.count)) {
43612 mutex_unlock(&tty->ipw_tty_mutex);
43613 return -EINVAL;
43614 }
43615@@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
43616 if (!tty)
43617 return -ENODEV;
43618
43619- if (!tty->port.count)
43620+ if (!atomic_read(&tty->port.count))
43621 return -EINVAL;
43622
43623 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
43624@@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
43625 if (!tty)
43626 return 0;
43627
43628- if (!tty->port.count)
43629+ if (!atomic_read(&tty->port.count))
43630 return 0;
43631
43632 return tty->tx_bytes_queued;
43633@@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
43634 if (!tty)
43635 return -ENODEV;
43636
43637- if (!tty->port.count)
43638+ if (!atomic_read(&tty->port.count))
43639 return -EINVAL;
43640
43641 return get_control_lines(tty);
43642@@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
43643 if (!tty)
43644 return -ENODEV;
43645
43646- if (!tty->port.count)
43647+ if (!atomic_read(&tty->port.count))
43648 return -EINVAL;
43649
43650 return set_control_lines(tty, set, clear);
43651@@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
43652 if (!tty)
43653 return -ENODEV;
43654
43655- if (!tty->port.count)
43656+ if (!atomic_read(&tty->port.count))
43657 return -EINVAL;
43658
43659 /* FIXME: Exactly how is the tty object locked here .. */
43660@@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
43661 * are gone */
43662 mutex_lock(&ttyj->ipw_tty_mutex);
43663 }
43664- while (ttyj->port.count)
43665+ while (atomic_read(&ttyj->port.count))
43666 do_ipw_close(ttyj);
43667 ipwireless_disassociate_network_ttys(network,
43668 ttyj->channel_idx);
43669diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
43670index f9d2850..b006f04 100644
43671--- a/drivers/tty/moxa.c
43672+++ b/drivers/tty/moxa.c
43673@@ -1193,7 +1193,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
43674 }
43675
43676 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
43677- ch->port.count++;
43678+ atomic_inc(&ch->port.count);
43679 tty->driver_data = ch;
43680 tty_port_tty_set(&ch->port, tty);
43681 mutex_lock(&ch->port.mutex);
43682diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
43683index bfd6771..e0d93c4 100644
43684--- a/drivers/tty/n_gsm.c
43685+++ b/drivers/tty/n_gsm.c
43686@@ -1636,7 +1636,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
43687 spin_lock_init(&dlci->lock);
43688 mutex_init(&dlci->mutex);
43689 dlci->fifo = &dlci->_fifo;
43690- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
43691+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
43692 kfree(dlci);
43693 return NULL;
43694 }
43695@@ -2936,7 +2936,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
43696 struct gsm_dlci *dlci = tty->driver_data;
43697 struct tty_port *port = &dlci->port;
43698
43699- port->count++;
43700+ atomic_inc(&port->count);
43701 dlci_get(dlci);
43702 dlci_get(dlci->gsm->dlci[0]);
43703 mux_get(dlci->gsm);
43704diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
43705index 19083ef..6e34e97 100644
43706--- a/drivers/tty/n_tty.c
43707+++ b/drivers/tty/n_tty.c
43708@@ -2196,6 +2196,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
43709 {
43710 *ops = tty_ldisc_N_TTY;
43711 ops->owner = NULL;
43712- ops->refcount = ops->flags = 0;
43713+ atomic_set(&ops->refcount, 0);
43714+ ops->flags = 0;
43715 }
43716 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
43717diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
43718index ac35c90..c47deac 100644
43719--- a/drivers/tty/pty.c
43720+++ b/drivers/tty/pty.c
43721@@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
43722 panic("Couldn't register Unix98 pts driver");
43723
43724 /* Now create the /dev/ptmx special device */
43725+ pax_open_kernel();
43726 tty_default_fops(&ptmx_fops);
43727- ptmx_fops.open = ptmx_open;
43728+ *(void **)&ptmx_fops.open = ptmx_open;
43729+ pax_close_kernel();
43730
43731 cdev_init(&ptmx_cdev, &ptmx_fops);
43732 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
43733diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
43734index e42009a..566a036 100644
43735--- a/drivers/tty/rocket.c
43736+++ b/drivers/tty/rocket.c
43737@@ -925,7 +925,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
43738 tty->driver_data = info;
43739 tty_port_tty_set(port, tty);
43740
43741- if (port->count++ == 0) {
43742+ if (atomic_inc_return(&port->count) == 1) {
43743 atomic_inc(&rp_num_ports_open);
43744
43745 #ifdef ROCKET_DEBUG_OPEN
43746@@ -934,7 +934,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
43747 #endif
43748 }
43749 #ifdef ROCKET_DEBUG_OPEN
43750- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
43751+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
43752 #endif
43753
43754 /*
43755@@ -1529,7 +1529,7 @@ static void rp_hangup(struct tty_struct *tty)
43756 spin_unlock_irqrestore(&info->port.lock, flags);
43757 return;
43758 }
43759- if (info->port.count)
43760+ if (atomic_read(&info->port.count))
43761 atomic_dec(&rp_num_ports_open);
43762 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
43763 spin_unlock_irqrestore(&info->port.lock, flags);
43764diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
43765index 1002054..dd644a8 100644
43766--- a/drivers/tty/serial/kgdboc.c
43767+++ b/drivers/tty/serial/kgdboc.c
43768@@ -24,8 +24,9 @@
43769 #define MAX_CONFIG_LEN 40
43770
43771 static struct kgdb_io kgdboc_io_ops;
43772+static struct kgdb_io kgdboc_io_ops_console;
43773
43774-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
43775+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
43776 static int configured = -1;
43777
43778 static char config[MAX_CONFIG_LEN];
43779@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
43780 kgdboc_unregister_kbd();
43781 if (configured == 1)
43782 kgdb_unregister_io_module(&kgdboc_io_ops);
43783+ else if (configured == 2)
43784+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
43785 }
43786
43787 static int configure_kgdboc(void)
43788@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
43789 int err;
43790 char *cptr = config;
43791 struct console *cons;
43792+ int is_console = 0;
43793
43794 err = kgdboc_option_setup(config);
43795 if (err || !strlen(config) || isspace(config[0]))
43796 goto noconfig;
43797
43798 err = -ENODEV;
43799- kgdboc_io_ops.is_console = 0;
43800 kgdb_tty_driver = NULL;
43801
43802 kgdboc_use_kms = 0;
43803@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
43804 int idx;
43805 if (cons->device && cons->device(cons, &idx) == p &&
43806 idx == tty_line) {
43807- kgdboc_io_ops.is_console = 1;
43808+ is_console = 1;
43809 break;
43810 }
43811 cons = cons->next;
43812@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
43813 kgdb_tty_line = tty_line;
43814
43815 do_register:
43816- err = kgdb_register_io_module(&kgdboc_io_ops);
43817+ if (is_console) {
43818+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
43819+ configured = 2;
43820+ } else {
43821+ err = kgdb_register_io_module(&kgdboc_io_ops);
43822+ configured = 1;
43823+ }
43824 if (err)
43825 goto noconfig;
43826
43827@@ -205,8 +214,6 @@ do_register:
43828 if (err)
43829 goto nmi_con_failed;
43830
43831- configured = 1;
43832-
43833 return 0;
43834
43835 nmi_con_failed:
43836@@ -223,7 +230,7 @@ noconfig:
43837 static int __init init_kgdboc(void)
43838 {
43839 /* Already configured? */
43840- if (configured == 1)
43841+ if (configured >= 1)
43842 return 0;
43843
43844 return configure_kgdboc();
43845@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
43846 if (config[len - 1] == '\n')
43847 config[len - 1] = '\0';
43848
43849- if (configured == 1)
43850+ if (configured >= 1)
43851 cleanup_kgdboc();
43852
43853 /* Go and configure with the new params. */
43854@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
43855 .post_exception = kgdboc_post_exp_handler,
43856 };
43857
43858+static struct kgdb_io kgdboc_io_ops_console = {
43859+ .name = "kgdboc",
43860+ .read_char = kgdboc_get_char,
43861+ .write_char = kgdboc_put_char,
43862+ .pre_exception = kgdboc_pre_exp_handler,
43863+ .post_exception = kgdboc_post_exp_handler,
43864+ .is_console = 1
43865+};
43866+
43867 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
43868 /* This is only available if kgdboc is a built in for early debugging */
43869 static int __init kgdboc_early_init(char *opt)
43870diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
43871index e514b3a..c73d614 100644
43872--- a/drivers/tty/serial/samsung.c
43873+++ b/drivers/tty/serial/samsung.c
43874@@ -453,11 +453,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
43875 }
43876 }
43877
43878+static int s3c64xx_serial_startup(struct uart_port *port);
43879 static int s3c24xx_serial_startup(struct uart_port *port)
43880 {
43881 struct s3c24xx_uart_port *ourport = to_ourport(port);
43882 int ret;
43883
43884+ /* Startup sequence is different for s3c64xx and higher SoC's */
43885+ if (s3c24xx_serial_has_interrupt_mask(port))
43886+ return s3c64xx_serial_startup(port);
43887+
43888 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
43889 port->mapbase, port->membase);
43890
43891@@ -1122,10 +1127,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
43892 /* setup info for port */
43893 port->dev = &platdev->dev;
43894
43895- /* Startup sequence is different for s3c64xx and higher SoC's */
43896- if (s3c24xx_serial_has_interrupt_mask(port))
43897- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
43898-
43899 port->uartclk = 1;
43900
43901 if (cfg->uart_flags & UPF_CONS_FLOW) {
43902diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
43903index 2c7230a..2104f16 100644
43904--- a/drivers/tty/serial/serial_core.c
43905+++ b/drivers/tty/serial/serial_core.c
43906@@ -1455,7 +1455,7 @@ static void uart_hangup(struct tty_struct *tty)
43907 uart_flush_buffer(tty);
43908 uart_shutdown(tty, state);
43909 spin_lock_irqsave(&port->lock, flags);
43910- port->count = 0;
43911+ atomic_set(&port->count, 0);
43912 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
43913 spin_unlock_irqrestore(&port->lock, flags);
43914 tty_port_tty_set(port, NULL);
43915@@ -1551,7 +1551,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43916 goto end;
43917 }
43918
43919- port->count++;
43920+ atomic_inc(&port->count);
43921 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
43922 retval = -ENXIO;
43923 goto err_dec_count;
43924@@ -1578,7 +1578,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43925 /*
43926 * Make sure the device is in D0 state.
43927 */
43928- if (port->count == 1)
43929+ if (atomic_read(&port->count) == 1)
43930 uart_change_pm(state, 0);
43931
43932 /*
43933@@ -1596,7 +1596,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43934 end:
43935 return retval;
43936 err_dec_count:
43937- port->count--;
43938+ atomic_inc(&port->count);
43939 mutex_unlock(&port->mutex);
43940 goto end;
43941 }
43942diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
43943index 9e071f6..f30ae69 100644
43944--- a/drivers/tty/synclink.c
43945+++ b/drivers/tty/synclink.c
43946@@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
43947
43948 if (debug_level >= DEBUG_LEVEL_INFO)
43949 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
43950- __FILE__,__LINE__, info->device_name, info->port.count);
43951+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
43952
43953 if (tty_port_close_start(&info->port, tty, filp) == 0)
43954 goto cleanup;
43955@@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
43956 cleanup:
43957 if (debug_level >= DEBUG_LEVEL_INFO)
43958 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
43959- tty->driver->name, info->port.count);
43960+ tty->driver->name, atomic_read(&info->port.count));
43961
43962 } /* end of mgsl_close() */
43963
43964@@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
43965
43966 mgsl_flush_buffer(tty);
43967 shutdown(info);
43968-
43969- info->port.count = 0;
43970+
43971+ atomic_set(&info->port.count, 0);
43972 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
43973 info->port.tty = NULL;
43974
43975@@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43976
43977 if (debug_level >= DEBUG_LEVEL_INFO)
43978 printk("%s(%d):block_til_ready before block on %s count=%d\n",
43979- __FILE__,__LINE__, tty->driver->name, port->count );
43980+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43981
43982 spin_lock_irqsave(&info->irq_spinlock, flags);
43983 if (!tty_hung_up_p(filp)) {
43984 extra_count = true;
43985- port->count--;
43986+ atomic_dec(&port->count);
43987 }
43988 spin_unlock_irqrestore(&info->irq_spinlock, flags);
43989 port->blocked_open++;
43990@@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43991
43992 if (debug_level >= DEBUG_LEVEL_INFO)
43993 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
43994- __FILE__,__LINE__, tty->driver->name, port->count );
43995+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43996
43997 tty_unlock(tty);
43998 schedule();
43999@@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
44000
44001 /* FIXME: Racy on hangup during close wait */
44002 if (extra_count)
44003- port->count++;
44004+ atomic_inc(&port->count);
44005 port->blocked_open--;
44006
44007 if (debug_level >= DEBUG_LEVEL_INFO)
44008 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
44009- __FILE__,__LINE__, tty->driver->name, port->count );
44010+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44011
44012 if (!retval)
44013 port->flags |= ASYNC_NORMAL_ACTIVE;
44014@@ -3405,7 +3405,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
44015
44016 if (debug_level >= DEBUG_LEVEL_INFO)
44017 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
44018- __FILE__,__LINE__,tty->driver->name, info->port.count);
44019+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
44020
44021 /* If port is closing, signal caller to try again */
44022 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
44023@@ -3424,10 +3424,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
44024 spin_unlock_irqrestore(&info->netlock, flags);
44025 goto cleanup;
44026 }
44027- info->port.count++;
44028+ atomic_inc(&info->port.count);
44029 spin_unlock_irqrestore(&info->netlock, flags);
44030
44031- if (info->port.count == 1) {
44032+ if (atomic_read(&info->port.count) == 1) {
44033 /* 1st open on this device, init hardware */
44034 retval = startup(info);
44035 if (retval < 0)
44036@@ -3451,8 +3451,8 @@ cleanup:
44037 if (retval) {
44038 if (tty->count == 1)
44039 info->port.tty = NULL; /* tty layer will release tty struct */
44040- if(info->port.count)
44041- info->port.count--;
44042+ if (atomic_read(&info->port.count))
44043+ atomic_dec(&info->port.count);
44044 }
44045
44046 return retval;
44047@@ -7662,7 +7662,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
44048 unsigned short new_crctype;
44049
44050 /* return error if TTY interface open */
44051- if (info->port.count)
44052+ if (atomic_read(&info->port.count))
44053 return -EBUSY;
44054
44055 switch (encoding)
44056@@ -7757,7 +7757,7 @@ static int hdlcdev_open(struct net_device *dev)
44057
44058 /* arbitrate between network and tty opens */
44059 spin_lock_irqsave(&info->netlock, flags);
44060- if (info->port.count != 0 || info->netcount != 0) {
44061+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
44062 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
44063 spin_unlock_irqrestore(&info->netlock, flags);
44064 return -EBUSY;
44065@@ -7843,7 +7843,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44066 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
44067
44068 /* return error if TTY interface open */
44069- if (info->port.count)
44070+ if (atomic_read(&info->port.count))
44071 return -EBUSY;
44072
44073 if (cmd != SIOCWANDEV)
44074diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
44075index aba1e59..877ac33 100644
44076--- a/drivers/tty/synclink_gt.c
44077+++ b/drivers/tty/synclink_gt.c
44078@@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
44079 tty->driver_data = info;
44080 info->port.tty = tty;
44081
44082- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
44083+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
44084
44085 /* If port is closing, signal caller to try again */
44086 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
44087@@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
44088 mutex_unlock(&info->port.mutex);
44089 goto cleanup;
44090 }
44091- info->port.count++;
44092+ atomic_inc(&info->port.count);
44093 spin_unlock_irqrestore(&info->netlock, flags);
44094
44095- if (info->port.count == 1) {
44096+ if (atomic_read(&info->port.count) == 1) {
44097 /* 1st open on this device, init hardware */
44098 retval = startup(info);
44099 if (retval < 0) {
44100@@ -716,8 +716,8 @@ cleanup:
44101 if (retval) {
44102 if (tty->count == 1)
44103 info->port.tty = NULL; /* tty layer will release tty struct */
44104- if(info->port.count)
44105- info->port.count--;
44106+ if(atomic_read(&info->port.count))
44107+ atomic_dec(&info->port.count);
44108 }
44109
44110 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
44111@@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44112
44113 if (sanity_check(info, tty->name, "close"))
44114 return;
44115- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
44116+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
44117
44118 if (tty_port_close_start(&info->port, tty, filp) == 0)
44119 goto cleanup;
44120@@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44121 tty_port_close_end(&info->port, tty);
44122 info->port.tty = NULL;
44123 cleanup:
44124- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
44125+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
44126 }
44127
44128 static void hangup(struct tty_struct *tty)
44129@@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
44130 shutdown(info);
44131
44132 spin_lock_irqsave(&info->port.lock, flags);
44133- info->port.count = 0;
44134+ atomic_set(&info->port.count, 0);
44135 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
44136 info->port.tty = NULL;
44137 spin_unlock_irqrestore(&info->port.lock, flags);
44138@@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
44139 unsigned short new_crctype;
44140
44141 /* return error if TTY interface open */
44142- if (info->port.count)
44143+ if (atomic_read(&info->port.count))
44144 return -EBUSY;
44145
44146 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
44147@@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
44148
44149 /* arbitrate between network and tty opens */
44150 spin_lock_irqsave(&info->netlock, flags);
44151- if (info->port.count != 0 || info->netcount != 0) {
44152+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
44153 DBGINFO(("%s hdlc_open busy\n", dev->name));
44154 spin_unlock_irqrestore(&info->netlock, flags);
44155 return -EBUSY;
44156@@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44157 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
44158
44159 /* return error if TTY interface open */
44160- if (info->port.count)
44161+ if (atomic_read(&info->port.count))
44162 return -EBUSY;
44163
44164 if (cmd != SIOCWANDEV)
44165@@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
44166 if (port == NULL)
44167 continue;
44168 spin_lock(&port->lock);
44169- if ((port->port.count || port->netcount) &&
44170+ if ((atomic_read(&port->port.count) || port->netcount) &&
44171 port->pending_bh && !port->bh_running &&
44172 !port->bh_requested) {
44173 DBGISR(("%s bh queued\n", port->device_name));
44174@@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44175 spin_lock_irqsave(&info->lock, flags);
44176 if (!tty_hung_up_p(filp)) {
44177 extra_count = true;
44178- port->count--;
44179+ atomic_dec(&port->count);
44180 }
44181 spin_unlock_irqrestore(&info->lock, flags);
44182 port->blocked_open++;
44183@@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44184 remove_wait_queue(&port->open_wait, &wait);
44185
44186 if (extra_count)
44187- port->count++;
44188+ atomic_inc(&port->count);
44189 port->blocked_open--;
44190
44191 if (!retval)
44192diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
44193index fd43fb6..34704ad 100644
44194--- a/drivers/tty/synclinkmp.c
44195+++ b/drivers/tty/synclinkmp.c
44196@@ -751,7 +751,7 @@ static int open(struct tty_struct *tty, struct file *filp)
44197
44198 if (debug_level >= DEBUG_LEVEL_INFO)
44199 printk("%s(%d):%s open(), old ref count = %d\n",
44200- __FILE__,__LINE__,tty->driver->name, info->port.count);
44201+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
44202
44203 /* If port is closing, signal caller to try again */
44204 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
44205@@ -770,10 +770,10 @@ static int open(struct tty_struct *tty, struct file *filp)
44206 spin_unlock_irqrestore(&info->netlock, flags);
44207 goto cleanup;
44208 }
44209- info->port.count++;
44210+ atomic_inc(&info->port.count);
44211 spin_unlock_irqrestore(&info->netlock, flags);
44212
44213- if (info->port.count == 1) {
44214+ if (atomic_read(&info->port.count) == 1) {
44215 /* 1st open on this device, init hardware */
44216 retval = startup(info);
44217 if (retval < 0)
44218@@ -797,8 +797,8 @@ cleanup:
44219 if (retval) {
44220 if (tty->count == 1)
44221 info->port.tty = NULL; /* tty layer will release tty struct */
44222- if(info->port.count)
44223- info->port.count--;
44224+ if(atomic_read(&info->port.count))
44225+ atomic_dec(&info->port.count);
44226 }
44227
44228 return retval;
44229@@ -816,7 +816,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44230
44231 if (debug_level >= DEBUG_LEVEL_INFO)
44232 printk("%s(%d):%s close() entry, count=%d\n",
44233- __FILE__,__LINE__, info->device_name, info->port.count);
44234+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
44235
44236 if (tty_port_close_start(&info->port, tty, filp) == 0)
44237 goto cleanup;
44238@@ -835,7 +835,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44239 cleanup:
44240 if (debug_level >= DEBUG_LEVEL_INFO)
44241 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
44242- tty->driver->name, info->port.count);
44243+ tty->driver->name, atomic_read(&info->port.count));
44244 }
44245
44246 /* Called by tty_hangup() when a hangup is signaled.
44247@@ -858,7 +858,7 @@ static void hangup(struct tty_struct *tty)
44248 shutdown(info);
44249
44250 spin_lock_irqsave(&info->port.lock, flags);
44251- info->port.count = 0;
44252+ atomic_set(&info->port.count, 0);
44253 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
44254 info->port.tty = NULL;
44255 spin_unlock_irqrestore(&info->port.lock, flags);
44256@@ -1566,7 +1566,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
44257 unsigned short new_crctype;
44258
44259 /* return error if TTY interface open */
44260- if (info->port.count)
44261+ if (atomic_read(&info->port.count))
44262 return -EBUSY;
44263
44264 switch (encoding)
44265@@ -1661,7 +1661,7 @@ static int hdlcdev_open(struct net_device *dev)
44266
44267 /* arbitrate between network and tty opens */
44268 spin_lock_irqsave(&info->netlock, flags);
44269- if (info->port.count != 0 || info->netcount != 0) {
44270+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
44271 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
44272 spin_unlock_irqrestore(&info->netlock, flags);
44273 return -EBUSY;
44274@@ -1747,7 +1747,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44275 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
44276
44277 /* return error if TTY interface open */
44278- if (info->port.count)
44279+ if (atomic_read(&info->port.count))
44280 return -EBUSY;
44281
44282 if (cmd != SIOCWANDEV)
44283@@ -2632,7 +2632,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
44284 * do not request bottom half processing if the
44285 * device is not open in a normal mode.
44286 */
44287- if ( port && (port->port.count || port->netcount) &&
44288+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
44289 port->pending_bh && !port->bh_running &&
44290 !port->bh_requested ) {
44291 if ( debug_level >= DEBUG_LEVEL_ISR )
44292@@ -3330,12 +3330,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44293
44294 if (debug_level >= DEBUG_LEVEL_INFO)
44295 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
44296- __FILE__,__LINE__, tty->driver->name, port->count );
44297+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44298
44299 spin_lock_irqsave(&info->lock, flags);
44300 if (!tty_hung_up_p(filp)) {
44301 extra_count = true;
44302- port->count--;
44303+ atomic_dec(&port->count);
44304 }
44305 spin_unlock_irqrestore(&info->lock, flags);
44306 port->blocked_open++;
44307@@ -3364,7 +3364,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44308
44309 if (debug_level >= DEBUG_LEVEL_INFO)
44310 printk("%s(%d):%s block_til_ready() count=%d\n",
44311- __FILE__,__LINE__, tty->driver->name, port->count );
44312+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44313
44314 tty_unlock(tty);
44315 schedule();
44316@@ -3375,12 +3375,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44317 remove_wait_queue(&port->open_wait, &wait);
44318
44319 if (extra_count)
44320- port->count++;
44321+ atomic_inc(&port->count);
44322 port->blocked_open--;
44323
44324 if (debug_level >= DEBUG_LEVEL_INFO)
44325 printk("%s(%d):%s block_til_ready() after, count=%d\n",
44326- __FILE__,__LINE__, tty->driver->name, port->count );
44327+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44328
44329 if (!retval)
44330 port->flags |= ASYNC_NORMAL_ACTIVE;
44331diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
44332index b3c4a25..723916f 100644
44333--- a/drivers/tty/sysrq.c
44334+++ b/drivers/tty/sysrq.c
44335@@ -867,7 +867,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
44336 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
44337 size_t count, loff_t *ppos)
44338 {
44339- if (count) {
44340+ if (count && capable(CAP_SYS_ADMIN)) {
44341 char c;
44342
44343 if (get_user(c, buf))
44344diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
44345index da9fde8..c07975f 100644
44346--- a/drivers/tty/tty_io.c
44347+++ b/drivers/tty/tty_io.c
44348@@ -3391,7 +3391,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
44349
44350 void tty_default_fops(struct file_operations *fops)
44351 {
44352- *fops = tty_fops;
44353+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
44354 }
44355
44356 /*
44357diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
44358index 78f1be2..3e98910 100644
44359--- a/drivers/tty/tty_ldisc.c
44360+++ b/drivers/tty/tty_ldisc.c
44361@@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
44362 if (atomic_dec_and_test(&ld->users)) {
44363 struct tty_ldisc_ops *ldo = ld->ops;
44364
44365- ldo->refcount--;
44366+ atomic_dec(&ldo->refcount);
44367 module_put(ldo->owner);
44368 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
44369
44370@@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
44371 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
44372 tty_ldiscs[disc] = new_ldisc;
44373 new_ldisc->num = disc;
44374- new_ldisc->refcount = 0;
44375+ atomic_set(&new_ldisc->refcount, 0);
44376 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
44377
44378 return ret;
44379@@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
44380 return -EINVAL;
44381
44382 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
44383- if (tty_ldiscs[disc]->refcount)
44384+ if (atomic_read(&tty_ldiscs[disc]->refcount))
44385 ret = -EBUSY;
44386 else
44387 tty_ldiscs[disc] = NULL;
44388@@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
44389 if (ldops) {
44390 ret = ERR_PTR(-EAGAIN);
44391 if (try_module_get(ldops->owner)) {
44392- ldops->refcount++;
44393+ atomic_inc(&ldops->refcount);
44394 ret = ldops;
44395 }
44396 }
44397@@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
44398 unsigned long flags;
44399
44400 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
44401- ldops->refcount--;
44402+ atomic_dec(&ldops->refcount);
44403 module_put(ldops->owner);
44404 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
44405 }
44406diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
44407index b7ff59d..7c6105e 100644
44408--- a/drivers/tty/tty_port.c
44409+++ b/drivers/tty/tty_port.c
44410@@ -218,7 +218,7 @@ void tty_port_hangup(struct tty_port *port)
44411 unsigned long flags;
44412
44413 spin_lock_irqsave(&port->lock, flags);
44414- port->count = 0;
44415+ atomic_set(&port->count, 0);
44416 port->flags &= ~ASYNC_NORMAL_ACTIVE;
44417 if (port->tty) {
44418 set_bit(TTY_IO_ERROR, &port->tty->flags);
44419@@ -344,7 +344,7 @@ int tty_port_block_til_ready(struct tty_port *port,
44420 /* The port lock protects the port counts */
44421 spin_lock_irqsave(&port->lock, flags);
44422 if (!tty_hung_up_p(filp))
44423- port->count--;
44424+ atomic_dec(&port->count);
44425 port->blocked_open++;
44426 spin_unlock_irqrestore(&port->lock, flags);
44427
44428@@ -386,7 +386,7 @@ int tty_port_block_til_ready(struct tty_port *port,
44429 we must not mess that up further */
44430 spin_lock_irqsave(&port->lock, flags);
44431 if (!tty_hung_up_p(filp))
44432- port->count++;
44433+ atomic_inc(&port->count);
44434 port->blocked_open--;
44435 if (retval == 0)
44436 port->flags |= ASYNC_NORMAL_ACTIVE;
44437@@ -406,19 +406,19 @@ int tty_port_close_start(struct tty_port *port,
44438 return 0;
44439 }
44440
44441- if (tty->count == 1 && port->count != 1) {
44442+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
44443 printk(KERN_WARNING
44444 "tty_port_close_start: tty->count = 1 port count = %d.\n",
44445- port->count);
44446- port->count = 1;
44447+ atomic_read(&port->count));
44448+ atomic_set(&port->count, 1);
44449 }
44450- if (--port->count < 0) {
44451+ if (atomic_dec_return(&port->count) < 0) {
44452 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
44453- port->count);
44454- port->count = 0;
44455+ atomic_read(&port->count));
44456+ atomic_set(&port->count, 0);
44457 }
44458
44459- if (port->count) {
44460+ if (atomic_read(&port->count)) {
44461 spin_unlock_irqrestore(&port->lock, flags);
44462 if (port->ops->drop)
44463 port->ops->drop(port);
44464@@ -516,7 +516,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
44465 {
44466 spin_lock_irq(&port->lock);
44467 if (!tty_hung_up_p(filp))
44468- ++port->count;
44469+ atomic_inc(&port->count);
44470 spin_unlock_irq(&port->lock);
44471 tty_port_tty_set(port, tty);
44472
44473diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
44474index 681765b..d3ccdf2 100644
44475--- a/drivers/tty/vt/keyboard.c
44476+++ b/drivers/tty/vt/keyboard.c
44477@@ -660,6 +660,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
44478 kbd->kbdmode == VC_OFF) &&
44479 value != KVAL(K_SAK))
44480 return; /* SAK is allowed even in raw mode */
44481+
44482+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
44483+ {
44484+ void *func = fn_handler[value];
44485+ if (func == fn_show_state || func == fn_show_ptregs ||
44486+ func == fn_show_mem)
44487+ return;
44488+ }
44489+#endif
44490+
44491 fn_handler[value](vc);
44492 }
44493
44494@@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
44495 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
44496 return -EFAULT;
44497
44498- if (!capable(CAP_SYS_TTY_CONFIG))
44499- perm = 0;
44500-
44501 switch (cmd) {
44502 case KDGKBENT:
44503 /* Ensure another thread doesn't free it under us */
44504@@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
44505 spin_unlock_irqrestore(&kbd_event_lock, flags);
44506 return put_user(val, &user_kbe->kb_value);
44507 case KDSKBENT:
44508+ if (!capable(CAP_SYS_TTY_CONFIG))
44509+ perm = 0;
44510+
44511 if (!perm)
44512 return -EPERM;
44513 if (!i && v == K_NOSUCHMAP) {
44514@@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
44515 int i, j, k;
44516 int ret;
44517
44518- if (!capable(CAP_SYS_TTY_CONFIG))
44519- perm = 0;
44520-
44521 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
44522 if (!kbs) {
44523 ret = -ENOMEM;
44524@@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
44525 kfree(kbs);
44526 return ((p && *p) ? -EOVERFLOW : 0);
44527 case KDSKBSENT:
44528+ if (!capable(CAP_SYS_TTY_CONFIG))
44529+ perm = 0;
44530+
44531 if (!perm) {
44532 ret = -EPERM;
44533 goto reterr;
44534diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
44535index 5110f36..8dc0a74 100644
44536--- a/drivers/uio/uio.c
44537+++ b/drivers/uio/uio.c
44538@@ -25,6 +25,7 @@
44539 #include <linux/kobject.h>
44540 #include <linux/cdev.h>
44541 #include <linux/uio_driver.h>
44542+#include <asm/local.h>
44543
44544 #define UIO_MAX_DEVICES (1U << MINORBITS)
44545
44546@@ -32,10 +33,10 @@ struct uio_device {
44547 struct module *owner;
44548 struct device *dev;
44549 int minor;
44550- atomic_t event;
44551+ atomic_unchecked_t event;
44552 struct fasync_struct *async_queue;
44553 wait_queue_head_t wait;
44554- int vma_count;
44555+ local_t vma_count;
44556 struct uio_info *info;
44557 struct kobject *map_dir;
44558 struct kobject *portio_dir;
44559@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
44560 struct device_attribute *attr, char *buf)
44561 {
44562 struct uio_device *idev = dev_get_drvdata(dev);
44563- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
44564+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
44565 }
44566
44567 static struct device_attribute uio_class_attributes[] = {
44568@@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
44569 {
44570 struct uio_device *idev = info->uio_dev;
44571
44572- atomic_inc(&idev->event);
44573+ atomic_inc_unchecked(&idev->event);
44574 wake_up_interruptible(&idev->wait);
44575 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
44576 }
44577@@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
44578 }
44579
44580 listener->dev = idev;
44581- listener->event_count = atomic_read(&idev->event);
44582+ listener->event_count = atomic_read_unchecked(&idev->event);
44583 filep->private_data = listener;
44584
44585 if (idev->info->open) {
44586@@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
44587 return -EIO;
44588
44589 poll_wait(filep, &idev->wait, wait);
44590- if (listener->event_count != atomic_read(&idev->event))
44591+ if (listener->event_count != atomic_read_unchecked(&idev->event))
44592 return POLLIN | POLLRDNORM;
44593 return 0;
44594 }
44595@@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
44596 do {
44597 set_current_state(TASK_INTERRUPTIBLE);
44598
44599- event_count = atomic_read(&idev->event);
44600+ event_count = atomic_read_unchecked(&idev->event);
44601 if (event_count != listener->event_count) {
44602 if (copy_to_user(buf, &event_count, count))
44603 retval = -EFAULT;
44604@@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
44605 static void uio_vma_open(struct vm_area_struct *vma)
44606 {
44607 struct uio_device *idev = vma->vm_private_data;
44608- idev->vma_count++;
44609+ local_inc(&idev->vma_count);
44610 }
44611
44612 static void uio_vma_close(struct vm_area_struct *vma)
44613 {
44614 struct uio_device *idev = vma->vm_private_data;
44615- idev->vma_count--;
44616+ local_dec(&idev->vma_count);
44617 }
44618
44619 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
44620@@ -819,7 +820,7 @@ int __uio_register_device(struct module *owner,
44621 idev->owner = owner;
44622 idev->info = info;
44623 init_waitqueue_head(&idev->wait);
44624- atomic_set(&idev->event, 0);
44625+ atomic_set_unchecked(&idev->event, 0);
44626
44627 ret = uio_get_minor(idev);
44628 if (ret)
44629diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
44630index b7eb86a..36d28af 100644
44631--- a/drivers/usb/atm/cxacru.c
44632+++ b/drivers/usb/atm/cxacru.c
44633@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
44634 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
44635 if (ret < 2)
44636 return -EINVAL;
44637- if (index < 0 || index > 0x7f)
44638+ if (index > 0x7f)
44639 return -EINVAL;
44640 pos += tmp;
44641
44642diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
44643index 35f10bf..6a38a0b 100644
44644--- a/drivers/usb/atm/usbatm.c
44645+++ b/drivers/usb/atm/usbatm.c
44646@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44647 if (printk_ratelimit())
44648 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
44649 __func__, vpi, vci);
44650- atomic_inc(&vcc->stats->rx_err);
44651+ atomic_inc_unchecked(&vcc->stats->rx_err);
44652 return;
44653 }
44654
44655@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44656 if (length > ATM_MAX_AAL5_PDU) {
44657 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
44658 __func__, length, vcc);
44659- atomic_inc(&vcc->stats->rx_err);
44660+ atomic_inc_unchecked(&vcc->stats->rx_err);
44661 goto out;
44662 }
44663
44664@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44665 if (sarb->len < pdu_length) {
44666 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
44667 __func__, pdu_length, sarb->len, vcc);
44668- atomic_inc(&vcc->stats->rx_err);
44669+ atomic_inc_unchecked(&vcc->stats->rx_err);
44670 goto out;
44671 }
44672
44673 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
44674 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
44675 __func__, vcc);
44676- atomic_inc(&vcc->stats->rx_err);
44677+ atomic_inc_unchecked(&vcc->stats->rx_err);
44678 goto out;
44679 }
44680
44681@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44682 if (printk_ratelimit())
44683 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
44684 __func__, length);
44685- atomic_inc(&vcc->stats->rx_drop);
44686+ atomic_inc_unchecked(&vcc->stats->rx_drop);
44687 goto out;
44688 }
44689
44690@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44691
44692 vcc->push(vcc, skb);
44693
44694- atomic_inc(&vcc->stats->rx);
44695+ atomic_inc_unchecked(&vcc->stats->rx);
44696 out:
44697 skb_trim(sarb, 0);
44698 }
44699@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
44700 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
44701
44702 usbatm_pop(vcc, skb);
44703- atomic_inc(&vcc->stats->tx);
44704+ atomic_inc_unchecked(&vcc->stats->tx);
44705
44706 skb = skb_dequeue(&instance->sndqueue);
44707 }
44708@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
44709 if (!left--)
44710 return sprintf(page,
44711 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
44712- atomic_read(&atm_dev->stats.aal5.tx),
44713- atomic_read(&atm_dev->stats.aal5.tx_err),
44714- atomic_read(&atm_dev->stats.aal5.rx),
44715- atomic_read(&atm_dev->stats.aal5.rx_err),
44716- atomic_read(&atm_dev->stats.aal5.rx_drop));
44717+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
44718+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
44719+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
44720+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
44721+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
44722
44723 if (!left--) {
44724 if (instance->disconnected)
44725diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
44726index cbacea9..246cccd 100644
44727--- a/drivers/usb/core/devices.c
44728+++ b/drivers/usb/core/devices.c
44729@@ -126,7 +126,7 @@ static const char format_endpt[] =
44730 * time it gets called.
44731 */
44732 static struct device_connect_event {
44733- atomic_t count;
44734+ atomic_unchecked_t count;
44735 wait_queue_head_t wait;
44736 } device_event = {
44737 .count = ATOMIC_INIT(1),
44738@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
44739
44740 void usbfs_conn_disc_event(void)
44741 {
44742- atomic_add(2, &device_event.count);
44743+ atomic_add_unchecked(2, &device_event.count);
44744 wake_up(&device_event.wait);
44745 }
44746
44747@@ -645,7 +645,7 @@ static unsigned int usb_device_poll(struct file *file,
44748
44749 poll_wait(file, &device_event.wait, wait);
44750
44751- event_count = atomic_read(&device_event.count);
44752+ event_count = atomic_read_unchecked(&device_event.count);
44753 if (file->f_version != event_count) {
44754 file->f_version = event_count;
44755 return POLLIN | POLLRDNORM;
44756diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
44757index 8e64adf..9a33a3c 100644
44758--- a/drivers/usb/core/hcd.c
44759+++ b/drivers/usb/core/hcd.c
44760@@ -1522,7 +1522,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
44761 */
44762 usb_get_urb(urb);
44763 atomic_inc(&urb->use_count);
44764- atomic_inc(&urb->dev->urbnum);
44765+ atomic_inc_unchecked(&urb->dev->urbnum);
44766 usbmon_urb_submit(&hcd->self, urb);
44767
44768 /* NOTE requirements on root-hub callers (usbfs and the hub
44769@@ -1549,7 +1549,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
44770 urb->hcpriv = NULL;
44771 INIT_LIST_HEAD(&urb->urb_list);
44772 atomic_dec(&urb->use_count);
44773- atomic_dec(&urb->dev->urbnum);
44774+ atomic_dec_unchecked(&urb->dev->urbnum);
44775 if (atomic_read(&urb->reject))
44776 wake_up(&usb_kill_urb_queue);
44777 usb_put_urb(urb);
44778diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
44779index 131f736..99004c3 100644
44780--- a/drivers/usb/core/message.c
44781+++ b/drivers/usb/core/message.c
44782@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
44783 * method can wait for it to complete. Since you don't have a handle on the
44784 * URB used, you can't cancel the request.
44785 */
44786-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
44787+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
44788 __u8 requesttype, __u16 value, __u16 index, void *data,
44789 __u16 size, int timeout)
44790 {
44791diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
44792index 818e4a0..0fc9589 100644
44793--- a/drivers/usb/core/sysfs.c
44794+++ b/drivers/usb/core/sysfs.c
44795@@ -226,7 +226,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
44796 struct usb_device *udev;
44797
44798 udev = to_usb_device(dev);
44799- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
44800+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
44801 }
44802 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
44803
44804diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
44805index f81b925..78d22ec 100644
44806--- a/drivers/usb/core/usb.c
44807+++ b/drivers/usb/core/usb.c
44808@@ -388,7 +388,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
44809 set_dev_node(&dev->dev, dev_to_node(bus->controller));
44810 dev->state = USB_STATE_ATTACHED;
44811 dev->lpm_disable_count = 1;
44812- atomic_set(&dev->urbnum, 0);
44813+ atomic_set_unchecked(&dev->urbnum, 0);
44814
44815 INIT_LIST_HEAD(&dev->ep0.urb_list);
44816 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
44817diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
44818index 5e29dde..eca992f 100644
44819--- a/drivers/usb/early/ehci-dbgp.c
44820+++ b/drivers/usb/early/ehci-dbgp.c
44821@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
44822
44823 #ifdef CONFIG_KGDB
44824 static struct kgdb_io kgdbdbgp_io_ops;
44825-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
44826+static struct kgdb_io kgdbdbgp_io_ops_console;
44827+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
44828 #else
44829 #define dbgp_kgdb_mode (0)
44830 #endif
44831@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
44832 .write_char = kgdbdbgp_write_char,
44833 };
44834
44835+static struct kgdb_io kgdbdbgp_io_ops_console = {
44836+ .name = "kgdbdbgp",
44837+ .read_char = kgdbdbgp_read_char,
44838+ .write_char = kgdbdbgp_write_char,
44839+ .is_console = 1
44840+};
44841+
44842 static int kgdbdbgp_wait_time;
44843
44844 static int __init kgdbdbgp_parse_config(char *str)
44845@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
44846 ptr++;
44847 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
44848 }
44849- kgdb_register_io_module(&kgdbdbgp_io_ops);
44850- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
44851+ if (early_dbgp_console.index != -1)
44852+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
44853+ else
44854+ kgdb_register_io_module(&kgdbdbgp_io_ops);
44855
44856 return 0;
44857 }
44858diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
44859index 598dcc1..032dd4f 100644
44860--- a/drivers/usb/gadget/u_serial.c
44861+++ b/drivers/usb/gadget/u_serial.c
44862@@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
44863 spin_lock_irq(&port->port_lock);
44864
44865 /* already open? Great. */
44866- if (port->port.count) {
44867+ if (atomic_read(&port->port.count)) {
44868 status = 0;
44869- port->port.count++;
44870+ atomic_inc(&port->port.count);
44871
44872 /* currently opening/closing? wait ... */
44873 } else if (port->openclose) {
44874@@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
44875 tty->driver_data = port;
44876 port->port.tty = tty;
44877
44878- port->port.count = 1;
44879+ atomic_set(&port->port.count, 1);
44880 port->openclose = false;
44881
44882 /* if connected, start the I/O stream */
44883@@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
44884
44885 spin_lock_irq(&port->port_lock);
44886
44887- if (port->port.count != 1) {
44888- if (port->port.count == 0)
44889+ if (atomic_read(&port->port.count) != 1) {
44890+ if (atomic_read(&port->port.count) == 0)
44891 WARN_ON(1);
44892 else
44893- --port->port.count;
44894+ atomic_dec(&port->port.count);
44895 goto exit;
44896 }
44897
44898@@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
44899 * and sleep if necessary
44900 */
44901 port->openclose = true;
44902- port->port.count = 0;
44903+ atomic_set(&port->port.count, 0);
44904
44905 gser = port->port_usb;
44906 if (gser && gser->disconnect)
44907@@ -1159,7 +1159,7 @@ static int gs_closed(struct gs_port *port)
44908 int cond;
44909
44910 spin_lock_irq(&port->port_lock);
44911- cond = (port->port.count == 0) && !port->openclose;
44912+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
44913 spin_unlock_irq(&port->port_lock);
44914 return cond;
44915 }
44916@@ -1273,7 +1273,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
44917 /* if it's already open, start I/O ... and notify the serial
44918 * protocol about open/close status (connect/disconnect).
44919 */
44920- if (port->port.count) {
44921+ if (atomic_read(&port->port.count)) {
44922 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
44923 gs_start_io(port);
44924 if (gser->connect)
44925@@ -1320,7 +1320,7 @@ void gserial_disconnect(struct gserial *gser)
44926
44927 port->port_usb = NULL;
44928 gser->ioport = NULL;
44929- if (port->port.count > 0 || port->openclose) {
44930+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
44931 wake_up_interruptible(&port->drain_wait);
44932 if (port->port.tty)
44933 tty_hangup(port->port.tty);
44934@@ -1336,7 +1336,7 @@ void gserial_disconnect(struct gserial *gser)
44935
44936 /* finally, free any unused/unusable I/O buffers */
44937 spin_lock_irqsave(&port->port_lock, flags);
44938- if (port->port.count == 0 && !port->openclose)
44939+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
44940 gs_buf_free(&port->port_write_buf);
44941 gs_free_requests(gser->out, &port->read_pool, NULL);
44942 gs_free_requests(gser->out, &port->read_queue, NULL);
44943diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
44944index 5f3bcd3..bfca43f 100644
44945--- a/drivers/usb/serial/console.c
44946+++ b/drivers/usb/serial/console.c
44947@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
44948
44949 info->port = port;
44950
44951- ++port->port.count;
44952+ atomic_inc(&port->port.count);
44953 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
44954 if (serial->type->set_termios) {
44955 /*
44956@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
44957 }
44958 /* Now that any required fake tty operations are completed restore
44959 * the tty port count */
44960- --port->port.count;
44961+ atomic_dec(&port->port.count);
44962 /* The console is special in terms of closing the device so
44963 * indicate this port is now acting as a system console. */
44964 port->port.console = 1;
44965@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
44966 free_tty:
44967 kfree(tty);
44968 reset_open_count:
44969- port->port.count = 0;
44970+ atomic_set(&port->port.count, 0);
44971 usb_autopm_put_interface(serial->interface);
44972 error_get_interface:
44973 usb_serial_put(serial);
44974diff --git a/drivers/usb/storage/realtek_cr.c b/drivers/usb/storage/realtek_cr.c
44975index 6c3586a..a94e621 100644
44976--- a/drivers/usb/storage/realtek_cr.c
44977+++ b/drivers/usb/storage/realtek_cr.c
44978@@ -429,7 +429,7 @@ static int rts51x_read_status(struct us_data *us,
44979
44980 buf = kmalloc(len, GFP_NOIO);
44981 if (buf == NULL)
44982- return USB_STOR_TRANSPORT_ERROR;
44983+ return -ENOMEM;
44984
44985 US_DEBUGP("%s, lun = %d\n", __func__, lun);
44986
44987diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
44988index 75f70f0..d467e1a 100644
44989--- a/drivers/usb/storage/usb.h
44990+++ b/drivers/usb/storage/usb.h
44991@@ -63,7 +63,7 @@ struct us_unusual_dev {
44992 __u8 useProtocol;
44993 __u8 useTransport;
44994 int (*initFunction)(struct us_data *);
44995-};
44996+} __do_const;
44997
44998
44999 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
45000diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
45001index d6bea3e..60b250e 100644
45002--- a/drivers/usb/wusbcore/wa-hc.h
45003+++ b/drivers/usb/wusbcore/wa-hc.h
45004@@ -192,7 +192,7 @@ struct wahc {
45005 struct list_head xfer_delayed_list;
45006 spinlock_t xfer_list_lock;
45007 struct work_struct xfer_work;
45008- atomic_t xfer_id_count;
45009+ atomic_unchecked_t xfer_id_count;
45010 };
45011
45012
45013@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
45014 INIT_LIST_HEAD(&wa->xfer_delayed_list);
45015 spin_lock_init(&wa->xfer_list_lock);
45016 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
45017- atomic_set(&wa->xfer_id_count, 1);
45018+ atomic_set_unchecked(&wa->xfer_id_count, 1);
45019 }
45020
45021 /**
45022diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
45023index 57c01ab..8a05959 100644
45024--- a/drivers/usb/wusbcore/wa-xfer.c
45025+++ b/drivers/usb/wusbcore/wa-xfer.c
45026@@ -296,7 +296,7 @@ out:
45027 */
45028 static void wa_xfer_id_init(struct wa_xfer *xfer)
45029 {
45030- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
45031+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
45032 }
45033
45034 /*
45035diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
45036index 8c55011..eed4ae1a 100644
45037--- a/drivers/video/aty/aty128fb.c
45038+++ b/drivers/video/aty/aty128fb.c
45039@@ -149,7 +149,7 @@ enum {
45040 };
45041
45042 /* Must match above enum */
45043-static char * const r128_family[] = {
45044+static const char * const r128_family[] = {
45045 "AGP",
45046 "PCI",
45047 "PRO AGP",
45048diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
45049index 4f27fdc..d3537e6 100644
45050--- a/drivers/video/aty/atyfb_base.c
45051+++ b/drivers/video/aty/atyfb_base.c
45052@@ -1325,10 +1325,14 @@ static int atyfb_set_par(struct fb_info *info)
45053 par->accel_flags = var->accel_flags; /* hack */
45054
45055 if (var->accel_flags) {
45056- info->fbops->fb_sync = atyfb_sync;
45057+ pax_open_kernel();
45058+ *(void **)&info->fbops->fb_sync = atyfb_sync;
45059+ pax_close_kernel();
45060 info->flags &= ~FBINFO_HWACCEL_DISABLED;
45061 } else {
45062- info->fbops->fb_sync = NULL;
45063+ pax_open_kernel();
45064+ *(void **)&info->fbops->fb_sync = NULL;
45065+ pax_close_kernel();
45066 info->flags |= FBINFO_HWACCEL_DISABLED;
45067 }
45068
45069diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
45070index 95ec042..e6affdd 100644
45071--- a/drivers/video/aty/mach64_cursor.c
45072+++ b/drivers/video/aty/mach64_cursor.c
45073@@ -7,6 +7,7 @@
45074 #include <linux/string.h>
45075
45076 #include <asm/io.h>
45077+#include <asm/pgtable.h>
45078
45079 #ifdef __sparc__
45080 #include <asm/fbio.h>
45081@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
45082 info->sprite.buf_align = 16; /* and 64 lines tall. */
45083 info->sprite.flags = FB_PIXMAP_IO;
45084
45085- info->fbops->fb_cursor = atyfb_cursor;
45086+ pax_open_kernel();
45087+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
45088+ pax_close_kernel();
45089
45090 return 0;
45091 }
45092diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
45093index 6c5ed6b..b727c88 100644
45094--- a/drivers/video/backlight/kb3886_bl.c
45095+++ b/drivers/video/backlight/kb3886_bl.c
45096@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
45097 static unsigned long kb3886bl_flags;
45098 #define KB3886BL_SUSPENDED 0x01
45099
45100-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
45101+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
45102 {
45103 .ident = "Sahara Touch-iT",
45104 .matches = {
45105diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
45106index 88cad6b..dd746c7 100644
45107--- a/drivers/video/fb_defio.c
45108+++ b/drivers/video/fb_defio.c
45109@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
45110
45111 BUG_ON(!fbdefio);
45112 mutex_init(&fbdefio->lock);
45113- info->fbops->fb_mmap = fb_deferred_io_mmap;
45114+ pax_open_kernel();
45115+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
45116+ pax_close_kernel();
45117 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
45118 INIT_LIST_HEAD(&fbdefio->pagelist);
45119 if (fbdefio->delay == 0) /* set a default of 1 s */
45120@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
45121 page->mapping = NULL;
45122 }
45123
45124- info->fbops->fb_mmap = NULL;
45125+ *(void **)&info->fbops->fb_mmap = NULL;
45126 mutex_destroy(&fbdefio->lock);
45127 }
45128 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
45129diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
45130index 5c3960d..15cf8fc 100644
45131--- a/drivers/video/fbcmap.c
45132+++ b/drivers/video/fbcmap.c
45133@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
45134 rc = -ENODEV;
45135 goto out;
45136 }
45137- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
45138- !info->fbops->fb_setcmap)) {
45139+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
45140 rc = -EINVAL;
45141 goto out1;
45142 }
45143diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
45144index dc61c12..e29796e 100644
45145--- a/drivers/video/fbmem.c
45146+++ b/drivers/video/fbmem.c
45147@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
45148 image->dx += image->width + 8;
45149 }
45150 } else if (rotate == FB_ROTATE_UD) {
45151- for (x = 0; x < num && image->dx >= 0; x++) {
45152+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
45153 info->fbops->fb_imageblit(info, image);
45154 image->dx -= image->width + 8;
45155 }
45156@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
45157 image->dy += image->height + 8;
45158 }
45159 } else if (rotate == FB_ROTATE_CCW) {
45160- for (x = 0; x < num && image->dy >= 0; x++) {
45161+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
45162 info->fbops->fb_imageblit(info, image);
45163 image->dy -= image->height + 8;
45164 }
45165@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
45166 return -EFAULT;
45167 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
45168 return -EINVAL;
45169- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
45170+ if (con2fb.framebuffer >= FB_MAX)
45171 return -EINVAL;
45172 if (!registered_fb[con2fb.framebuffer])
45173 request_module("fb%d", con2fb.framebuffer);
45174diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
45175index 7672d2e..b56437f 100644
45176--- a/drivers/video/i810/i810_accel.c
45177+++ b/drivers/video/i810/i810_accel.c
45178@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
45179 }
45180 }
45181 printk("ringbuffer lockup!!!\n");
45182+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
45183 i810_report_error(mmio);
45184 par->dev_flags |= LOCKUP;
45185 info->pixmap.scan_align = 1;
45186diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
45187index 3c14e43..eafa544 100644
45188--- a/drivers/video/logo/logo_linux_clut224.ppm
45189+++ b/drivers/video/logo/logo_linux_clut224.ppm
45190@@ -1,1604 +1,1123 @@
45191 P3
45192-# Standard 224-color Linux logo
45193 80 80
45194 255
45195- 0 0 0 0 0 0 0 0 0 0 0 0
45196- 0 0 0 0 0 0 0 0 0 0 0 0
45197- 0 0 0 0 0 0 0 0 0 0 0 0
45198- 0 0 0 0 0 0 0 0 0 0 0 0
45199- 0 0 0 0 0 0 0 0 0 0 0 0
45200- 0 0 0 0 0 0 0 0 0 0 0 0
45201- 0 0 0 0 0 0 0 0 0 0 0 0
45202- 0 0 0 0 0 0 0 0 0 0 0 0
45203- 0 0 0 0 0 0 0 0 0 0 0 0
45204- 6 6 6 6 6 6 10 10 10 10 10 10
45205- 10 10 10 6 6 6 6 6 6 6 6 6
45206- 0 0 0 0 0 0 0 0 0 0 0 0
45207- 0 0 0 0 0 0 0 0 0 0 0 0
45208- 0 0 0 0 0 0 0 0 0 0 0 0
45209- 0 0 0 0 0 0 0 0 0 0 0 0
45210- 0 0 0 0 0 0 0 0 0 0 0 0
45211- 0 0 0 0 0 0 0 0 0 0 0 0
45212- 0 0 0 0 0 0 0 0 0 0 0 0
45213- 0 0 0 0 0 0 0 0 0 0 0 0
45214- 0 0 0 0 0 0 0 0 0 0 0 0
45215- 0 0 0 0 0 0 0 0 0 0 0 0
45216- 0 0 0 0 0 0 0 0 0 0 0 0
45217- 0 0 0 0 0 0 0 0 0 0 0 0
45218- 0 0 0 0 0 0 0 0 0 0 0 0
45219- 0 0 0 0 0 0 0 0 0 0 0 0
45220- 0 0 0 0 0 0 0 0 0 0 0 0
45221- 0 0 0 0 0 0 0 0 0 0 0 0
45222- 0 0 0 0 0 0 0 0 0 0 0 0
45223- 0 0 0 6 6 6 10 10 10 14 14 14
45224- 22 22 22 26 26 26 30 30 30 34 34 34
45225- 30 30 30 30 30 30 26 26 26 18 18 18
45226- 14 14 14 10 10 10 6 6 6 0 0 0
45227- 0 0 0 0 0 0 0 0 0 0 0 0
45228- 0 0 0 0 0 0 0 0 0 0 0 0
45229- 0 0 0 0 0 0 0 0 0 0 0 0
45230- 0 0 0 0 0 0 0 0 0 0 0 0
45231- 0 0 0 0 0 0 0 0 0 0 0 0
45232- 0 0 0 0 0 0 0 0 0 0 0 0
45233- 0 0 0 0 0 0 0 0 0 0 0 0
45234- 0 0 0 0 0 0 0 0 0 0 0 0
45235- 0 0 0 0 0 0 0 0 0 0 0 0
45236- 0 0 0 0 0 1 0 0 1 0 0 0
45237- 0 0 0 0 0 0 0 0 0 0 0 0
45238- 0 0 0 0 0 0 0 0 0 0 0 0
45239- 0 0 0 0 0 0 0 0 0 0 0 0
45240- 0 0 0 0 0 0 0 0 0 0 0 0
45241- 0 0 0 0 0 0 0 0 0 0 0 0
45242- 0 0 0 0 0 0 0 0 0 0 0 0
45243- 6 6 6 14 14 14 26 26 26 42 42 42
45244- 54 54 54 66 66 66 78 78 78 78 78 78
45245- 78 78 78 74 74 74 66 66 66 54 54 54
45246- 42 42 42 26 26 26 18 18 18 10 10 10
45247- 6 6 6 0 0 0 0 0 0 0 0 0
45248- 0 0 0 0 0 0 0 0 0 0 0 0
45249- 0 0 0 0 0 0 0 0 0 0 0 0
45250- 0 0 0 0 0 0 0 0 0 0 0 0
45251- 0 0 0 0 0 0 0 0 0 0 0 0
45252- 0 0 0 0 0 0 0 0 0 0 0 0
45253- 0 0 0 0 0 0 0 0 0 0 0 0
45254- 0 0 0 0 0 0 0 0 0 0 0 0
45255- 0 0 0 0 0 0 0 0 0 0 0 0
45256- 0 0 1 0 0 0 0 0 0 0 0 0
45257- 0 0 0 0 0 0 0 0 0 0 0 0
45258- 0 0 0 0 0 0 0 0 0 0 0 0
45259- 0 0 0 0 0 0 0 0 0 0 0 0
45260- 0 0 0 0 0 0 0 0 0 0 0 0
45261- 0 0 0 0 0 0 0 0 0 0 0 0
45262- 0 0 0 0 0 0 0 0 0 10 10 10
45263- 22 22 22 42 42 42 66 66 66 86 86 86
45264- 66 66 66 38 38 38 38 38 38 22 22 22
45265- 26 26 26 34 34 34 54 54 54 66 66 66
45266- 86 86 86 70 70 70 46 46 46 26 26 26
45267- 14 14 14 6 6 6 0 0 0 0 0 0
45268- 0 0 0 0 0 0 0 0 0 0 0 0
45269- 0 0 0 0 0 0 0 0 0 0 0 0
45270- 0 0 0 0 0 0 0 0 0 0 0 0
45271- 0 0 0 0 0 0 0 0 0 0 0 0
45272- 0 0 0 0 0 0 0 0 0 0 0 0
45273- 0 0 0 0 0 0 0 0 0 0 0 0
45274- 0 0 0 0 0 0 0 0 0 0 0 0
45275- 0 0 0 0 0 0 0 0 0 0 0 0
45276- 0 0 1 0 0 1 0 0 1 0 0 0
45277- 0 0 0 0 0 0 0 0 0 0 0 0
45278- 0 0 0 0 0 0 0 0 0 0 0 0
45279- 0 0 0 0 0 0 0 0 0 0 0 0
45280- 0 0 0 0 0 0 0 0 0 0 0 0
45281- 0 0 0 0 0 0 0 0 0 0 0 0
45282- 0 0 0 0 0 0 10 10 10 26 26 26
45283- 50 50 50 82 82 82 58 58 58 6 6 6
45284- 2 2 6 2 2 6 2 2 6 2 2 6
45285- 2 2 6 2 2 6 2 2 6 2 2 6
45286- 6 6 6 54 54 54 86 86 86 66 66 66
45287- 38 38 38 18 18 18 6 6 6 0 0 0
45288- 0 0 0 0 0 0 0 0 0 0 0 0
45289- 0 0 0 0 0 0 0 0 0 0 0 0
45290- 0 0 0 0 0 0 0 0 0 0 0 0
45291- 0 0 0 0 0 0 0 0 0 0 0 0
45292- 0 0 0 0 0 0 0 0 0 0 0 0
45293- 0 0 0 0 0 0 0 0 0 0 0 0
45294- 0 0 0 0 0 0 0 0 0 0 0 0
45295- 0 0 0 0 0 0 0 0 0 0 0 0
45296- 0 0 0 0 0 0 0 0 0 0 0 0
45297- 0 0 0 0 0 0 0 0 0 0 0 0
45298- 0 0 0 0 0 0 0 0 0 0 0 0
45299- 0 0 0 0 0 0 0 0 0 0 0 0
45300- 0 0 0 0 0 0 0 0 0 0 0 0
45301- 0 0 0 0 0 0 0 0 0 0 0 0
45302- 0 0 0 6 6 6 22 22 22 50 50 50
45303- 78 78 78 34 34 34 2 2 6 2 2 6
45304- 2 2 6 2 2 6 2 2 6 2 2 6
45305- 2 2 6 2 2 6 2 2 6 2 2 6
45306- 2 2 6 2 2 6 6 6 6 70 70 70
45307- 78 78 78 46 46 46 22 22 22 6 6 6
45308- 0 0 0 0 0 0 0 0 0 0 0 0
45309- 0 0 0 0 0 0 0 0 0 0 0 0
45310- 0 0 0 0 0 0 0 0 0 0 0 0
45311- 0 0 0 0 0 0 0 0 0 0 0 0
45312- 0 0 0 0 0 0 0 0 0 0 0 0
45313- 0 0 0 0 0 0 0 0 0 0 0 0
45314- 0 0 0 0 0 0 0 0 0 0 0 0
45315- 0 0 0 0 0 0 0 0 0 0 0 0
45316- 0 0 1 0 0 1 0 0 1 0 0 0
45317- 0 0 0 0 0 0 0 0 0 0 0 0
45318- 0 0 0 0 0 0 0 0 0 0 0 0
45319- 0 0 0 0 0 0 0 0 0 0 0 0
45320- 0 0 0 0 0 0 0 0 0 0 0 0
45321- 0 0 0 0 0 0 0 0 0 0 0 0
45322- 6 6 6 18 18 18 42 42 42 82 82 82
45323- 26 26 26 2 2 6 2 2 6 2 2 6
45324- 2 2 6 2 2 6 2 2 6 2 2 6
45325- 2 2 6 2 2 6 2 2 6 14 14 14
45326- 46 46 46 34 34 34 6 6 6 2 2 6
45327- 42 42 42 78 78 78 42 42 42 18 18 18
45328- 6 6 6 0 0 0 0 0 0 0 0 0
45329- 0 0 0 0 0 0 0 0 0 0 0 0
45330- 0 0 0 0 0 0 0 0 0 0 0 0
45331- 0 0 0 0 0 0 0 0 0 0 0 0
45332- 0 0 0 0 0 0 0 0 0 0 0 0
45333- 0 0 0 0 0 0 0 0 0 0 0 0
45334- 0 0 0 0 0 0 0 0 0 0 0 0
45335- 0 0 0 0 0 0 0 0 0 0 0 0
45336- 0 0 1 0 0 0 0 0 1 0 0 0
45337- 0 0 0 0 0 0 0 0 0 0 0 0
45338- 0 0 0 0 0 0 0 0 0 0 0 0
45339- 0 0 0 0 0 0 0 0 0 0 0 0
45340- 0 0 0 0 0 0 0 0 0 0 0 0
45341- 0 0 0 0 0 0 0 0 0 0 0 0
45342- 10 10 10 30 30 30 66 66 66 58 58 58
45343- 2 2 6 2 2 6 2 2 6 2 2 6
45344- 2 2 6 2 2 6 2 2 6 2 2 6
45345- 2 2 6 2 2 6 2 2 6 26 26 26
45346- 86 86 86 101 101 101 46 46 46 10 10 10
45347- 2 2 6 58 58 58 70 70 70 34 34 34
45348- 10 10 10 0 0 0 0 0 0 0 0 0
45349- 0 0 0 0 0 0 0 0 0 0 0 0
45350- 0 0 0 0 0 0 0 0 0 0 0 0
45351- 0 0 0 0 0 0 0 0 0 0 0 0
45352- 0 0 0 0 0 0 0 0 0 0 0 0
45353- 0 0 0 0 0 0 0 0 0 0 0 0
45354- 0 0 0 0 0 0 0 0 0 0 0 0
45355- 0 0 0 0 0 0 0 0 0 0 0 0
45356- 0 0 1 0 0 1 0 0 1 0 0 0
45357- 0 0 0 0 0 0 0 0 0 0 0 0
45358- 0 0 0 0 0 0 0 0 0 0 0 0
45359- 0 0 0 0 0 0 0 0 0 0 0 0
45360- 0 0 0 0 0 0 0 0 0 0 0 0
45361- 0 0 0 0 0 0 0 0 0 0 0 0
45362- 14 14 14 42 42 42 86 86 86 10 10 10
45363- 2 2 6 2 2 6 2 2 6 2 2 6
45364- 2 2 6 2 2 6 2 2 6 2 2 6
45365- 2 2 6 2 2 6 2 2 6 30 30 30
45366- 94 94 94 94 94 94 58 58 58 26 26 26
45367- 2 2 6 6 6 6 78 78 78 54 54 54
45368- 22 22 22 6 6 6 0 0 0 0 0 0
45369- 0 0 0 0 0 0 0 0 0 0 0 0
45370- 0 0 0 0 0 0 0 0 0 0 0 0
45371- 0 0 0 0 0 0 0 0 0 0 0 0
45372- 0 0 0 0 0 0 0 0 0 0 0 0
45373- 0 0 0 0 0 0 0 0 0 0 0 0
45374- 0 0 0 0 0 0 0 0 0 0 0 0
45375- 0 0 0 0 0 0 0 0 0 0 0 0
45376- 0 0 0 0 0 0 0 0 0 0 0 0
45377- 0 0 0 0 0 0 0 0 0 0 0 0
45378- 0 0 0 0 0 0 0 0 0 0 0 0
45379- 0 0 0 0 0 0 0 0 0 0 0 0
45380- 0 0 0 0 0 0 0 0 0 0 0 0
45381- 0 0 0 0 0 0 0 0 0 6 6 6
45382- 22 22 22 62 62 62 62 62 62 2 2 6
45383- 2 2 6 2 2 6 2 2 6 2 2 6
45384- 2 2 6 2 2 6 2 2 6 2 2 6
45385- 2 2 6 2 2 6 2 2 6 26 26 26
45386- 54 54 54 38 38 38 18 18 18 10 10 10
45387- 2 2 6 2 2 6 34 34 34 82 82 82
45388- 38 38 38 14 14 14 0 0 0 0 0 0
45389- 0 0 0 0 0 0 0 0 0 0 0 0
45390- 0 0 0 0 0 0 0 0 0 0 0 0
45391- 0 0 0 0 0 0 0 0 0 0 0 0
45392- 0 0 0 0 0 0 0 0 0 0 0 0
45393- 0 0 0 0 0 0 0 0 0 0 0 0
45394- 0 0 0 0 0 0 0 0 0 0 0 0
45395- 0 0 0 0 0 0 0 0 0 0 0 0
45396- 0 0 0 0 0 1 0 0 1 0 0 0
45397- 0 0 0 0 0 0 0 0 0 0 0 0
45398- 0 0 0 0 0 0 0 0 0 0 0 0
45399- 0 0 0 0 0 0 0 0 0 0 0 0
45400- 0 0 0 0 0 0 0 0 0 0 0 0
45401- 0 0 0 0 0 0 0 0 0 6 6 6
45402- 30 30 30 78 78 78 30 30 30 2 2 6
45403- 2 2 6 2 2 6 2 2 6 2 2 6
45404- 2 2 6 2 2 6 2 2 6 2 2 6
45405- 2 2 6 2 2 6 2 2 6 10 10 10
45406- 10 10 10 2 2 6 2 2 6 2 2 6
45407- 2 2 6 2 2 6 2 2 6 78 78 78
45408- 50 50 50 18 18 18 6 6 6 0 0 0
45409- 0 0 0 0 0 0 0 0 0 0 0 0
45410- 0 0 0 0 0 0 0 0 0 0 0 0
45411- 0 0 0 0 0 0 0 0 0 0 0 0
45412- 0 0 0 0 0 0 0 0 0 0 0 0
45413- 0 0 0 0 0 0 0 0 0 0 0 0
45414- 0 0 0 0 0 0 0 0 0 0 0 0
45415- 0 0 0 0 0 0 0 0 0 0 0 0
45416- 0 0 1 0 0 0 0 0 0 0 0 0
45417- 0 0 0 0 0 0 0 0 0 0 0 0
45418- 0 0 0 0 0 0 0 0 0 0 0 0
45419- 0 0 0 0 0 0 0 0 0 0 0 0
45420- 0 0 0 0 0 0 0 0 0 0 0 0
45421- 0 0 0 0 0 0 0 0 0 10 10 10
45422- 38 38 38 86 86 86 14 14 14 2 2 6
45423- 2 2 6 2 2 6 2 2 6 2 2 6
45424- 2 2 6 2 2 6 2 2 6 2 2 6
45425- 2 2 6 2 2 6 2 2 6 2 2 6
45426- 2 2 6 2 2 6 2 2 6 2 2 6
45427- 2 2 6 2 2 6 2 2 6 54 54 54
45428- 66 66 66 26 26 26 6 6 6 0 0 0
45429- 0 0 0 0 0 0 0 0 0 0 0 0
45430- 0 0 0 0 0 0 0 0 0 0 0 0
45431- 0 0 0 0 0 0 0 0 0 0 0 0
45432- 0 0 0 0 0 0 0 0 0 0 0 0
45433- 0 0 0 0 0 0 0 0 0 0 0 0
45434- 0 0 0 0 0 0 0 0 0 0 0 0
45435- 0 0 0 0 0 0 0 0 0 0 0 0
45436- 0 0 0 0 0 1 0 0 1 0 0 0
45437- 0 0 0 0 0 0 0 0 0 0 0 0
45438- 0 0 0 0 0 0 0 0 0 0 0 0
45439- 0 0 0 0 0 0 0 0 0 0 0 0
45440- 0 0 0 0 0 0 0 0 0 0 0 0
45441- 0 0 0 0 0 0 0 0 0 14 14 14
45442- 42 42 42 82 82 82 2 2 6 2 2 6
45443- 2 2 6 6 6 6 10 10 10 2 2 6
45444- 2 2 6 2 2 6 2 2 6 2 2 6
45445- 2 2 6 2 2 6 2 2 6 6 6 6
45446- 14 14 14 10 10 10 2 2 6 2 2 6
45447- 2 2 6 2 2 6 2 2 6 18 18 18
45448- 82 82 82 34 34 34 10 10 10 0 0 0
45449- 0 0 0 0 0 0 0 0 0 0 0 0
45450- 0 0 0 0 0 0 0 0 0 0 0 0
45451- 0 0 0 0 0 0 0 0 0 0 0 0
45452- 0 0 0 0 0 0 0 0 0 0 0 0
45453- 0 0 0 0 0 0 0 0 0 0 0 0
45454- 0 0 0 0 0 0 0 0 0 0 0 0
45455- 0 0 0 0 0 0 0 0 0 0 0 0
45456- 0 0 1 0 0 0 0 0 0 0 0 0
45457- 0 0 0 0 0 0 0 0 0 0 0 0
45458- 0 0 0 0 0 0 0 0 0 0 0 0
45459- 0 0 0 0 0 0 0 0 0 0 0 0
45460- 0 0 0 0 0 0 0 0 0 0 0 0
45461- 0 0 0 0 0 0 0 0 0 14 14 14
45462- 46 46 46 86 86 86 2 2 6 2 2 6
45463- 6 6 6 6 6 6 22 22 22 34 34 34
45464- 6 6 6 2 2 6 2 2 6 2 2 6
45465- 2 2 6 2 2 6 18 18 18 34 34 34
45466- 10 10 10 50 50 50 22 22 22 2 2 6
45467- 2 2 6 2 2 6 2 2 6 10 10 10
45468- 86 86 86 42 42 42 14 14 14 0 0 0
45469- 0 0 0 0 0 0 0 0 0 0 0 0
45470- 0 0 0 0 0 0 0 0 0 0 0 0
45471- 0 0 0 0 0 0 0 0 0 0 0 0
45472- 0 0 0 0 0 0 0 0 0 0 0 0
45473- 0 0 0 0 0 0 0 0 0 0 0 0
45474- 0 0 0 0 0 0 0 0 0 0 0 0
45475- 0 0 0 0 0 0 0 0 0 0 0 0
45476- 0 0 1 0 0 1 0 0 1 0 0 0
45477- 0 0 0 0 0 0 0 0 0 0 0 0
45478- 0 0 0 0 0 0 0 0 0 0 0 0
45479- 0 0 0 0 0 0 0 0 0 0 0 0
45480- 0 0 0 0 0 0 0 0 0 0 0 0
45481- 0 0 0 0 0 0 0 0 0 14 14 14
45482- 46 46 46 86 86 86 2 2 6 2 2 6
45483- 38 38 38 116 116 116 94 94 94 22 22 22
45484- 22 22 22 2 2 6 2 2 6 2 2 6
45485- 14 14 14 86 86 86 138 138 138 162 162 162
45486-154 154 154 38 38 38 26 26 26 6 6 6
45487- 2 2 6 2 2 6 2 2 6 2 2 6
45488- 86 86 86 46 46 46 14 14 14 0 0 0
45489- 0 0 0 0 0 0 0 0 0 0 0 0
45490- 0 0 0 0 0 0 0 0 0 0 0 0
45491- 0 0 0 0 0 0 0 0 0 0 0 0
45492- 0 0 0 0 0 0 0 0 0 0 0 0
45493- 0 0 0 0 0 0 0 0 0 0 0 0
45494- 0 0 0 0 0 0 0 0 0 0 0 0
45495- 0 0 0 0 0 0 0 0 0 0 0 0
45496- 0 0 0 0 0 0 0 0 0 0 0 0
45497- 0 0 0 0 0 0 0 0 0 0 0 0
45498- 0 0 0 0 0 0 0 0 0 0 0 0
45499- 0 0 0 0 0 0 0 0 0 0 0 0
45500- 0 0 0 0 0 0 0 0 0 0 0 0
45501- 0 0 0 0 0 0 0 0 0 14 14 14
45502- 46 46 46 86 86 86 2 2 6 14 14 14
45503-134 134 134 198 198 198 195 195 195 116 116 116
45504- 10 10 10 2 2 6 2 2 6 6 6 6
45505-101 98 89 187 187 187 210 210 210 218 218 218
45506-214 214 214 134 134 134 14 14 14 6 6 6
45507- 2 2 6 2 2 6 2 2 6 2 2 6
45508- 86 86 86 50 50 50 18 18 18 6 6 6
45509- 0 0 0 0 0 0 0 0 0 0 0 0
45510- 0 0 0 0 0 0 0 0 0 0 0 0
45511- 0 0 0 0 0 0 0 0 0 0 0 0
45512- 0 0 0 0 0 0 0 0 0 0 0 0
45513- 0 0 0 0 0 0 0 0 0 0 0 0
45514- 0 0 0 0 0 0 0 0 0 0 0 0
45515- 0 0 0 0 0 0 0 0 1 0 0 0
45516- 0 0 1 0 0 1 0 0 1 0 0 0
45517- 0 0 0 0 0 0 0 0 0 0 0 0
45518- 0 0 0 0 0 0 0 0 0 0 0 0
45519- 0 0 0 0 0 0 0 0 0 0 0 0
45520- 0 0 0 0 0 0 0 0 0 0 0 0
45521- 0 0 0 0 0 0 0 0 0 14 14 14
45522- 46 46 46 86 86 86 2 2 6 54 54 54
45523-218 218 218 195 195 195 226 226 226 246 246 246
45524- 58 58 58 2 2 6 2 2 6 30 30 30
45525-210 210 210 253 253 253 174 174 174 123 123 123
45526-221 221 221 234 234 234 74 74 74 2 2 6
45527- 2 2 6 2 2 6 2 2 6 2 2 6
45528- 70 70 70 58 58 58 22 22 22 6 6 6
45529- 0 0 0 0 0 0 0 0 0 0 0 0
45530- 0 0 0 0 0 0 0 0 0 0 0 0
45531- 0 0 0 0 0 0 0 0 0 0 0 0
45532- 0 0 0 0 0 0 0 0 0 0 0 0
45533- 0 0 0 0 0 0 0 0 0 0 0 0
45534- 0 0 0 0 0 0 0 0 0 0 0 0
45535- 0 0 0 0 0 0 0 0 0 0 0 0
45536- 0 0 0 0 0 0 0 0 0 0 0 0
45537- 0 0 0 0 0 0 0 0 0 0 0 0
45538- 0 0 0 0 0 0 0 0 0 0 0 0
45539- 0 0 0 0 0 0 0 0 0 0 0 0
45540- 0 0 0 0 0 0 0 0 0 0 0 0
45541- 0 0 0 0 0 0 0 0 0 14 14 14
45542- 46 46 46 82 82 82 2 2 6 106 106 106
45543-170 170 170 26 26 26 86 86 86 226 226 226
45544-123 123 123 10 10 10 14 14 14 46 46 46
45545-231 231 231 190 190 190 6 6 6 70 70 70
45546- 90 90 90 238 238 238 158 158 158 2 2 6
45547- 2 2 6 2 2 6 2 2 6 2 2 6
45548- 70 70 70 58 58 58 22 22 22 6 6 6
45549- 0 0 0 0 0 0 0 0 0 0 0 0
45550- 0 0 0 0 0 0 0 0 0 0 0 0
45551- 0 0 0 0 0 0 0 0 0 0 0 0
45552- 0 0 0 0 0 0 0 0 0 0 0 0
45553- 0 0 0 0 0 0 0 0 0 0 0 0
45554- 0 0 0 0 0 0 0 0 0 0 0 0
45555- 0 0 0 0 0 0 0 0 1 0 0 0
45556- 0 0 1 0 0 1 0 0 1 0 0 0
45557- 0 0 0 0 0 0 0 0 0 0 0 0
45558- 0 0 0 0 0 0 0 0 0 0 0 0
45559- 0 0 0 0 0 0 0 0 0 0 0 0
45560- 0 0 0 0 0 0 0 0 0 0 0 0
45561- 0 0 0 0 0 0 0 0 0 14 14 14
45562- 42 42 42 86 86 86 6 6 6 116 116 116
45563-106 106 106 6 6 6 70 70 70 149 149 149
45564-128 128 128 18 18 18 38 38 38 54 54 54
45565-221 221 221 106 106 106 2 2 6 14 14 14
45566- 46 46 46 190 190 190 198 198 198 2 2 6
45567- 2 2 6 2 2 6 2 2 6 2 2 6
45568- 74 74 74 62 62 62 22 22 22 6 6 6
45569- 0 0 0 0 0 0 0 0 0 0 0 0
45570- 0 0 0 0 0 0 0 0 0 0 0 0
45571- 0 0 0 0 0 0 0 0 0 0 0 0
45572- 0 0 0 0 0 0 0 0 0 0 0 0
45573- 0 0 0 0 0 0 0 0 0 0 0 0
45574- 0 0 0 0 0 0 0 0 0 0 0 0
45575- 0 0 0 0 0 0 0 0 1 0 0 0
45576- 0 0 1 0 0 0 0 0 1 0 0 0
45577- 0 0 0 0 0 0 0 0 0 0 0 0
45578- 0 0 0 0 0 0 0 0 0 0 0 0
45579- 0 0 0 0 0 0 0 0 0 0 0 0
45580- 0 0 0 0 0 0 0 0 0 0 0 0
45581- 0 0 0 0 0 0 0 0 0 14 14 14
45582- 42 42 42 94 94 94 14 14 14 101 101 101
45583-128 128 128 2 2 6 18 18 18 116 116 116
45584-118 98 46 121 92 8 121 92 8 98 78 10
45585-162 162 162 106 106 106 2 2 6 2 2 6
45586- 2 2 6 195 195 195 195 195 195 6 6 6
45587- 2 2 6 2 2 6 2 2 6 2 2 6
45588- 74 74 74 62 62 62 22 22 22 6 6 6
45589- 0 0 0 0 0 0 0 0 0 0 0 0
45590- 0 0 0 0 0 0 0 0 0 0 0 0
45591- 0 0 0 0 0 0 0 0 0 0 0 0
45592- 0 0 0 0 0 0 0 0 0 0 0 0
45593- 0 0 0 0 0 0 0 0 0 0 0 0
45594- 0 0 0 0 0 0 0 0 0 0 0 0
45595- 0 0 0 0 0 0 0 0 1 0 0 1
45596- 0 0 1 0 0 0 0 0 1 0 0 0
45597- 0 0 0 0 0 0 0 0 0 0 0 0
45598- 0 0 0 0 0 0 0 0 0 0 0 0
45599- 0 0 0 0 0 0 0 0 0 0 0 0
45600- 0 0 0 0 0 0 0 0 0 0 0 0
45601- 0 0 0 0 0 0 0 0 0 10 10 10
45602- 38 38 38 90 90 90 14 14 14 58 58 58
45603-210 210 210 26 26 26 54 38 6 154 114 10
45604-226 170 11 236 186 11 225 175 15 184 144 12
45605-215 174 15 175 146 61 37 26 9 2 2 6
45606- 70 70 70 246 246 246 138 138 138 2 2 6
45607- 2 2 6 2 2 6 2 2 6 2 2 6
45608- 70 70 70 66 66 66 26 26 26 6 6 6
45609- 0 0 0 0 0 0 0 0 0 0 0 0
45610- 0 0 0 0 0 0 0 0 0 0 0 0
45611- 0 0 0 0 0 0 0 0 0 0 0 0
45612- 0 0 0 0 0 0 0 0 0 0 0 0
45613- 0 0 0 0 0 0 0 0 0 0 0 0
45614- 0 0 0 0 0 0 0 0 0 0 0 0
45615- 0 0 0 0 0 0 0 0 0 0 0 0
45616- 0 0 0 0 0 0 0 0 0 0 0 0
45617- 0 0 0 0 0 0 0 0 0 0 0 0
45618- 0 0 0 0 0 0 0 0 0 0 0 0
45619- 0 0 0 0 0 0 0 0 0 0 0 0
45620- 0 0 0 0 0 0 0 0 0 0 0 0
45621- 0 0 0 0 0 0 0 0 0 10 10 10
45622- 38 38 38 86 86 86 14 14 14 10 10 10
45623-195 195 195 188 164 115 192 133 9 225 175 15
45624-239 182 13 234 190 10 232 195 16 232 200 30
45625-245 207 45 241 208 19 232 195 16 184 144 12
45626-218 194 134 211 206 186 42 42 42 2 2 6
45627- 2 2 6 2 2 6 2 2 6 2 2 6
45628- 50 50 50 74 74 74 30 30 30 6 6 6
45629- 0 0 0 0 0 0 0 0 0 0 0 0
45630- 0 0 0 0 0 0 0 0 0 0 0 0
45631- 0 0 0 0 0 0 0 0 0 0 0 0
45632- 0 0 0 0 0 0 0 0 0 0 0 0
45633- 0 0 0 0 0 0 0 0 0 0 0 0
45634- 0 0 0 0 0 0 0 0 0 0 0 0
45635- 0 0 0 0 0 0 0 0 0 0 0 0
45636- 0 0 0 0 0 0 0 0 0 0 0 0
45637- 0 0 0 0 0 0 0 0 0 0 0 0
45638- 0 0 0 0 0 0 0 0 0 0 0 0
45639- 0 0 0 0 0 0 0 0 0 0 0 0
45640- 0 0 0 0 0 0 0 0 0 0 0 0
45641- 0 0 0 0 0 0 0 0 0 10 10 10
45642- 34 34 34 86 86 86 14 14 14 2 2 6
45643-121 87 25 192 133 9 219 162 10 239 182 13
45644-236 186 11 232 195 16 241 208 19 244 214 54
45645-246 218 60 246 218 38 246 215 20 241 208 19
45646-241 208 19 226 184 13 121 87 25 2 2 6
45647- 2 2 6 2 2 6 2 2 6 2 2 6
45648- 50 50 50 82 82 82 34 34 34 10 10 10
45649- 0 0 0 0 0 0 0 0 0 0 0 0
45650- 0 0 0 0 0 0 0 0 0 0 0 0
45651- 0 0 0 0 0 0 0 0 0 0 0 0
45652- 0 0 0 0 0 0 0 0 0 0 0 0
45653- 0 0 0 0 0 0 0 0 0 0 0 0
45654- 0 0 0 0 0 0 0 0 0 0 0 0
45655- 0 0 0 0 0 0 0 0 0 0 0 0
45656- 0 0 0 0 0 0 0 0 0 0 0 0
45657- 0 0 0 0 0 0 0 0 0 0 0 0
45658- 0 0 0 0 0 0 0 0 0 0 0 0
45659- 0 0 0 0 0 0 0 0 0 0 0 0
45660- 0 0 0 0 0 0 0 0 0 0 0 0
45661- 0 0 0 0 0 0 0 0 0 10 10 10
45662- 34 34 34 82 82 82 30 30 30 61 42 6
45663-180 123 7 206 145 10 230 174 11 239 182 13
45664-234 190 10 238 202 15 241 208 19 246 218 74
45665-246 218 38 246 215 20 246 215 20 246 215 20
45666-226 184 13 215 174 15 184 144 12 6 6 6
45667- 2 2 6 2 2 6 2 2 6 2 2 6
45668- 26 26 26 94 94 94 42 42 42 14 14 14
45669- 0 0 0 0 0 0 0 0 0 0 0 0
45670- 0 0 0 0 0 0 0 0 0 0 0 0
45671- 0 0 0 0 0 0 0 0 0 0 0 0
45672- 0 0 0 0 0 0 0 0 0 0 0 0
45673- 0 0 0 0 0 0 0 0 0 0 0 0
45674- 0 0 0 0 0 0 0 0 0 0 0 0
45675- 0 0 0 0 0 0 0 0 0 0 0 0
45676- 0 0 0 0 0 0 0 0 0 0 0 0
45677- 0 0 0 0 0 0 0 0 0 0 0 0
45678- 0 0 0 0 0 0 0 0 0 0 0 0
45679- 0 0 0 0 0 0 0 0 0 0 0 0
45680- 0 0 0 0 0 0 0 0 0 0 0 0
45681- 0 0 0 0 0 0 0 0 0 10 10 10
45682- 30 30 30 78 78 78 50 50 50 104 69 6
45683-192 133 9 216 158 10 236 178 12 236 186 11
45684-232 195 16 241 208 19 244 214 54 245 215 43
45685-246 215 20 246 215 20 241 208 19 198 155 10
45686-200 144 11 216 158 10 156 118 10 2 2 6
45687- 2 2 6 2 2 6 2 2 6 2 2 6
45688- 6 6 6 90 90 90 54 54 54 18 18 18
45689- 6 6 6 0 0 0 0 0 0 0 0 0
45690- 0 0 0 0 0 0 0 0 0 0 0 0
45691- 0 0 0 0 0 0 0 0 0 0 0 0
45692- 0 0 0 0 0 0 0 0 0 0 0 0
45693- 0 0 0 0 0 0 0 0 0 0 0 0
45694- 0 0 0 0 0 0 0 0 0 0 0 0
45695- 0 0 0 0 0 0 0 0 0 0 0 0
45696- 0 0 0 0 0 0 0 0 0 0 0 0
45697- 0 0 0 0 0 0 0 0 0 0 0 0
45698- 0 0 0 0 0 0 0 0 0 0 0 0
45699- 0 0 0 0 0 0 0 0 0 0 0 0
45700- 0 0 0 0 0 0 0 0 0 0 0 0
45701- 0 0 0 0 0 0 0 0 0 10 10 10
45702- 30 30 30 78 78 78 46 46 46 22 22 22
45703-137 92 6 210 162 10 239 182 13 238 190 10
45704-238 202 15 241 208 19 246 215 20 246 215 20
45705-241 208 19 203 166 17 185 133 11 210 150 10
45706-216 158 10 210 150 10 102 78 10 2 2 6
45707- 6 6 6 54 54 54 14 14 14 2 2 6
45708- 2 2 6 62 62 62 74 74 74 30 30 30
45709- 10 10 10 0 0 0 0 0 0 0 0 0
45710- 0 0 0 0 0 0 0 0 0 0 0 0
45711- 0 0 0 0 0 0 0 0 0 0 0 0
45712- 0 0 0 0 0 0 0 0 0 0 0 0
45713- 0 0 0 0 0 0 0 0 0 0 0 0
45714- 0 0 0 0 0 0 0 0 0 0 0 0
45715- 0 0 0 0 0 0 0 0 0 0 0 0
45716- 0 0 0 0 0 0 0 0 0 0 0 0
45717- 0 0 0 0 0 0 0 0 0 0 0 0
45718- 0 0 0 0 0 0 0 0 0 0 0 0
45719- 0 0 0 0 0 0 0 0 0 0 0 0
45720- 0 0 0 0 0 0 0 0 0 0 0 0
45721- 0 0 0 0 0 0 0 0 0 10 10 10
45722- 34 34 34 78 78 78 50 50 50 6 6 6
45723- 94 70 30 139 102 15 190 146 13 226 184 13
45724-232 200 30 232 195 16 215 174 15 190 146 13
45725-168 122 10 192 133 9 210 150 10 213 154 11
45726-202 150 34 182 157 106 101 98 89 2 2 6
45727- 2 2 6 78 78 78 116 116 116 58 58 58
45728- 2 2 6 22 22 22 90 90 90 46 46 46
45729- 18 18 18 6 6 6 0 0 0 0 0 0
45730- 0 0 0 0 0 0 0 0 0 0 0 0
45731- 0 0 0 0 0 0 0 0 0 0 0 0
45732- 0 0 0 0 0 0 0 0 0 0 0 0
45733- 0 0 0 0 0 0 0 0 0 0 0 0
45734- 0 0 0 0 0 0 0 0 0 0 0 0
45735- 0 0 0 0 0 0 0 0 0 0 0 0
45736- 0 0 0 0 0 0 0 0 0 0 0 0
45737- 0 0 0 0 0 0 0 0 0 0 0 0
45738- 0 0 0 0 0 0 0 0 0 0 0 0
45739- 0 0 0 0 0 0 0 0 0 0 0 0
45740- 0 0 0 0 0 0 0 0 0 0 0 0
45741- 0 0 0 0 0 0 0 0 0 10 10 10
45742- 38 38 38 86 86 86 50 50 50 6 6 6
45743-128 128 128 174 154 114 156 107 11 168 122 10
45744-198 155 10 184 144 12 197 138 11 200 144 11
45745-206 145 10 206 145 10 197 138 11 188 164 115
45746-195 195 195 198 198 198 174 174 174 14 14 14
45747- 2 2 6 22 22 22 116 116 116 116 116 116
45748- 22 22 22 2 2 6 74 74 74 70 70 70
45749- 30 30 30 10 10 10 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 0 0 0 6 6 6 18 18 18
45762- 50 50 50 101 101 101 26 26 26 10 10 10
45763-138 138 138 190 190 190 174 154 114 156 107 11
45764-197 138 11 200 144 11 197 138 11 192 133 9
45765-180 123 7 190 142 34 190 178 144 187 187 187
45766-202 202 202 221 221 221 214 214 214 66 66 66
45767- 2 2 6 2 2 6 50 50 50 62 62 62
45768- 6 6 6 2 2 6 10 10 10 90 90 90
45769- 50 50 50 18 18 18 6 6 6 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 0 0 0 0 0 0 0
45775- 0 0 0 0 0 0 0 0 0 0 0 0
45776- 0 0 0 0 0 0 0 0 0 0 0 0
45777- 0 0 0 0 0 0 0 0 0 0 0 0
45778- 0 0 0 0 0 0 0 0 0 0 0 0
45779- 0 0 0 0 0 0 0 0 0 0 0 0
45780- 0 0 0 0 0 0 0 0 0 0 0 0
45781- 0 0 0 0 0 0 10 10 10 34 34 34
45782- 74 74 74 74 74 74 2 2 6 6 6 6
45783-144 144 144 198 198 198 190 190 190 178 166 146
45784-154 121 60 156 107 11 156 107 11 168 124 44
45785-174 154 114 187 187 187 190 190 190 210 210 210
45786-246 246 246 253 253 253 253 253 253 182 182 182
45787- 6 6 6 2 2 6 2 2 6 2 2 6
45788- 2 2 6 2 2 6 2 2 6 62 62 62
45789- 74 74 74 34 34 34 14 14 14 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 0 0 0 0 0 0 0 0 0 0
45795- 0 0 0 0 0 0 0 0 0 0 0 0
45796- 0 0 0 0 0 0 0 0 0 0 0 0
45797- 0 0 0 0 0 0 0 0 0 0 0 0
45798- 0 0 0 0 0 0 0 0 0 0 0 0
45799- 0 0 0 0 0 0 0 0 0 0 0 0
45800- 0 0 0 0 0 0 0 0 0 0 0 0
45801- 0 0 0 10 10 10 22 22 22 54 54 54
45802- 94 94 94 18 18 18 2 2 6 46 46 46
45803-234 234 234 221 221 221 190 190 190 190 190 190
45804-190 190 190 187 187 187 187 187 187 190 190 190
45805-190 190 190 195 195 195 214 214 214 242 242 242
45806-253 253 253 253 253 253 253 253 253 253 253 253
45807- 82 82 82 2 2 6 2 2 6 2 2 6
45808- 2 2 6 2 2 6 2 2 6 14 14 14
45809- 86 86 86 54 54 54 22 22 22 6 6 6
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 0 0 0 0 0 0 0 0 0 0
45815- 0 0 0 0 0 0 0 0 0 0 0 0
45816- 0 0 0 0 0 0 0 0 0 0 0 0
45817- 0 0 0 0 0 0 0 0 0 0 0 0
45818- 0 0 0 0 0 0 0 0 0 0 0 0
45819- 0 0 0 0 0 0 0 0 0 0 0 0
45820- 0 0 0 0 0 0 0 0 0 0 0 0
45821- 6 6 6 18 18 18 46 46 46 90 90 90
45822- 46 46 46 18 18 18 6 6 6 182 182 182
45823-253 253 253 246 246 246 206 206 206 190 190 190
45824-190 190 190 190 190 190 190 190 190 190 190 190
45825-206 206 206 231 231 231 250 250 250 253 253 253
45826-253 253 253 253 253 253 253 253 253 253 253 253
45827-202 202 202 14 14 14 2 2 6 2 2 6
45828- 2 2 6 2 2 6 2 2 6 2 2 6
45829- 42 42 42 86 86 86 42 42 42 18 18 18
45830- 6 6 6 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 0 0 0 0 0 0 6 6 6
45841- 14 14 14 38 38 38 74 74 74 66 66 66
45842- 2 2 6 6 6 6 90 90 90 250 250 250
45843-253 253 253 253 253 253 238 238 238 198 198 198
45844-190 190 190 190 190 190 195 195 195 221 221 221
45845-246 246 246 253 253 253 253 253 253 253 253 253
45846-253 253 253 253 253 253 253 253 253 253 253 253
45847-253 253 253 82 82 82 2 2 6 2 2 6
45848- 2 2 6 2 2 6 2 2 6 2 2 6
45849- 2 2 6 78 78 78 70 70 70 34 34 34
45850- 14 14 14 6 6 6 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 0 0 0 0 0 0 0 0 0 0
45855- 0 0 0 0 0 0 0 0 0 0 0 0
45856- 0 0 0 0 0 0 0 0 0 0 0 0
45857- 0 0 0 0 0 0 0 0 0 0 0 0
45858- 0 0 0 0 0 0 0 0 0 0 0 0
45859- 0 0 0 0 0 0 0 0 0 0 0 0
45860- 0 0 0 0 0 0 0 0 0 14 14 14
45861- 34 34 34 66 66 66 78 78 78 6 6 6
45862- 2 2 6 18 18 18 218 218 218 253 253 253
45863-253 253 253 253 253 253 253 253 253 246 246 246
45864-226 226 226 231 231 231 246 246 246 253 253 253
45865-253 253 253 253 253 253 253 253 253 253 253 253
45866-253 253 253 253 253 253 253 253 253 253 253 253
45867-253 253 253 178 178 178 2 2 6 2 2 6
45868- 2 2 6 2 2 6 2 2 6 2 2 6
45869- 2 2 6 18 18 18 90 90 90 62 62 62
45870- 30 30 30 10 10 10 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 0 0 0 0 0 0 0 0 0 0
45875- 0 0 0 0 0 0 0 0 0 0 0 0
45876- 0 0 0 0 0 0 0 0 0 0 0 0
45877- 0 0 0 0 0 0 0 0 0 0 0 0
45878- 0 0 0 0 0 0 0 0 0 0 0 0
45879- 0 0 0 0 0 0 0 0 0 0 0 0
45880- 0 0 0 0 0 0 10 10 10 26 26 26
45881- 58 58 58 90 90 90 18 18 18 2 2 6
45882- 2 2 6 110 110 110 253 253 253 253 253 253
45883-253 253 253 253 253 253 253 253 253 253 253 253
45884-250 250 250 253 253 253 253 253 253 253 253 253
45885-253 253 253 253 253 253 253 253 253 253 253 253
45886-253 253 253 253 253 253 253 253 253 253 253 253
45887-253 253 253 231 231 231 18 18 18 2 2 6
45888- 2 2 6 2 2 6 2 2 6 2 2 6
45889- 2 2 6 2 2 6 18 18 18 94 94 94
45890- 54 54 54 26 26 26 10 10 10 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 0 0 0 0 0 0 0 0 0 0
45895- 0 0 0 0 0 0 0 0 0 0 0 0
45896- 0 0 0 0 0 0 0 0 0 0 0 0
45897- 0 0 0 0 0 0 0 0 0 0 0 0
45898- 0 0 0 0 0 0 0 0 0 0 0 0
45899- 0 0 0 0 0 0 0 0 0 0 0 0
45900- 0 0 0 6 6 6 22 22 22 50 50 50
45901- 90 90 90 26 26 26 2 2 6 2 2 6
45902- 14 14 14 195 195 195 250 250 250 253 253 253
45903-253 253 253 253 253 253 253 253 253 253 253 253
45904-253 253 253 253 253 253 253 253 253 253 253 253
45905-253 253 253 253 253 253 253 253 253 253 253 253
45906-253 253 253 253 253 253 253 253 253 253 253 253
45907-250 250 250 242 242 242 54 54 54 2 2 6
45908- 2 2 6 2 2 6 2 2 6 2 2 6
45909- 2 2 6 2 2 6 2 2 6 38 38 38
45910- 86 86 86 50 50 50 22 22 22 6 6 6
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 0 0 0
45920- 6 6 6 14 14 14 38 38 38 82 82 82
45921- 34 34 34 2 2 6 2 2 6 2 2 6
45922- 42 42 42 195 195 195 246 246 246 253 253 253
45923-253 253 253 253 253 253 253 253 253 250 250 250
45924-242 242 242 242 242 242 250 250 250 253 253 253
45925-253 253 253 253 253 253 253 253 253 253 253 253
45926-253 253 253 250 250 250 246 246 246 238 238 238
45927-226 226 226 231 231 231 101 101 101 6 6 6
45928- 2 2 6 2 2 6 2 2 6 2 2 6
45929- 2 2 6 2 2 6 2 2 6 2 2 6
45930- 38 38 38 82 82 82 42 42 42 14 14 14
45931- 6 6 6 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 0 0 0 0 0 0 0
45935- 0 0 0 0 0 0 0 0 0 0 0 0
45936- 0 0 0 0 0 0 0 0 0 0 0 0
45937- 0 0 0 0 0 0 0 0 0 0 0 0
45938- 0 0 0 0 0 0 0 0 0 0 0 0
45939- 0 0 0 0 0 0 0 0 0 0 0 0
45940- 10 10 10 26 26 26 62 62 62 66 66 66
45941- 2 2 6 2 2 6 2 2 6 6 6 6
45942- 70 70 70 170 170 170 206 206 206 234 234 234
45943-246 246 246 250 250 250 250 250 250 238 238 238
45944-226 226 226 231 231 231 238 238 238 250 250 250
45945-250 250 250 250 250 250 246 246 246 231 231 231
45946-214 214 214 206 206 206 202 202 202 202 202 202
45947-198 198 198 202 202 202 182 182 182 18 18 18
45948- 2 2 6 2 2 6 2 2 6 2 2 6
45949- 2 2 6 2 2 6 2 2 6 2 2 6
45950- 2 2 6 62 62 62 66 66 66 30 30 30
45951- 10 10 10 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 0 0 0 0 0 0 0 0 0 0
45955- 0 0 0 0 0 0 0 0 0 0 0 0
45956- 0 0 0 0 0 0 0 0 0 0 0 0
45957- 0 0 0 0 0 0 0 0 0 0 0 0
45958- 0 0 0 0 0 0 0 0 0 0 0 0
45959- 0 0 0 0 0 0 0 0 0 0 0 0
45960- 14 14 14 42 42 42 82 82 82 18 18 18
45961- 2 2 6 2 2 6 2 2 6 10 10 10
45962- 94 94 94 182 182 182 218 218 218 242 242 242
45963-250 250 250 253 253 253 253 253 253 250 250 250
45964-234 234 234 253 253 253 253 253 253 253 253 253
45965-253 253 253 253 253 253 253 253 253 246 246 246
45966-238 238 238 226 226 226 210 210 210 202 202 202
45967-195 195 195 195 195 195 210 210 210 158 158 158
45968- 6 6 6 14 14 14 50 50 50 14 14 14
45969- 2 2 6 2 2 6 2 2 6 2 2 6
45970- 2 2 6 6 6 6 86 86 86 46 46 46
45971- 18 18 18 6 6 6 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 0 0 0 0 0 0 0
45975- 0 0 0 0 0 0 0 0 0 0 0 0
45976- 0 0 0 0 0 0 0 0 0 0 0 0
45977- 0 0 0 0 0 0 0 0 0 0 0 0
45978- 0 0 0 0 0 0 0 0 0 0 0 0
45979- 0 0 0 0 0 0 0 0 0 6 6 6
45980- 22 22 22 54 54 54 70 70 70 2 2 6
45981- 2 2 6 10 10 10 2 2 6 22 22 22
45982-166 166 166 231 231 231 250 250 250 253 253 253
45983-253 253 253 253 253 253 253 253 253 250 250 250
45984-242 242 242 253 253 253 253 253 253 253 253 253
45985-253 253 253 253 253 253 253 253 253 253 253 253
45986-253 253 253 253 253 253 253 253 253 246 246 246
45987-231 231 231 206 206 206 198 198 198 226 226 226
45988- 94 94 94 2 2 6 6 6 6 38 38 38
45989- 30 30 30 2 2 6 2 2 6 2 2 6
45990- 2 2 6 2 2 6 62 62 62 66 66 66
45991- 26 26 26 10 10 10 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 0 0 0 0 0 0 0 0 0 0
45995- 0 0 0 0 0 0 0 0 0 0 0 0
45996- 0 0 0 0 0 0 0 0 0 0 0 0
45997- 0 0 0 0 0 0 0 0 0 0 0 0
45998- 0 0 0 0 0 0 0 0 0 0 0 0
45999- 0 0 0 0 0 0 0 0 0 10 10 10
46000- 30 30 30 74 74 74 50 50 50 2 2 6
46001- 26 26 26 26 26 26 2 2 6 106 106 106
46002-238 238 238 253 253 253 253 253 253 253 253 253
46003-253 253 253 253 253 253 253 253 253 253 253 253
46004-253 253 253 253 253 253 253 253 253 253 253 253
46005-253 253 253 253 253 253 253 253 253 253 253 253
46006-253 253 253 253 253 253 253 253 253 253 253 253
46007-253 253 253 246 246 246 218 218 218 202 202 202
46008-210 210 210 14 14 14 2 2 6 2 2 6
46009- 30 30 30 22 22 22 2 2 6 2 2 6
46010- 2 2 6 2 2 6 18 18 18 86 86 86
46011- 42 42 42 14 14 14 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 0 0 0 0 0 0 0 0 0 0
46015- 0 0 0 0 0 0 0 0 0 0 0 0
46016- 0 0 0 0 0 0 0 0 0 0 0 0
46017- 0 0 0 0 0 0 0 0 0 0 0 0
46018- 0 0 0 0 0 0 0 0 0 0 0 0
46019- 0 0 0 0 0 0 0 0 0 14 14 14
46020- 42 42 42 90 90 90 22 22 22 2 2 6
46021- 42 42 42 2 2 6 18 18 18 218 218 218
46022-253 253 253 253 253 253 253 253 253 253 253 253
46023-253 253 253 253 253 253 253 253 253 253 253 253
46024-253 253 253 253 253 253 253 253 253 253 253 253
46025-253 253 253 253 253 253 253 253 253 253 253 253
46026-253 253 253 253 253 253 253 253 253 253 253 253
46027-253 253 253 253 253 253 250 250 250 221 221 221
46028-218 218 218 101 101 101 2 2 6 14 14 14
46029- 18 18 18 38 38 38 10 10 10 2 2 6
46030- 2 2 6 2 2 6 2 2 6 78 78 78
46031- 58 58 58 22 22 22 6 6 6 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 6 6 6 18 18 18
46040- 54 54 54 82 82 82 2 2 6 26 26 26
46041- 22 22 22 2 2 6 123 123 123 253 253 253
46042-253 253 253 253 253 253 253 253 253 253 253 253
46043-253 253 253 253 253 253 253 253 253 253 253 253
46044-253 253 253 253 253 253 253 253 253 253 253 253
46045-253 253 253 253 253 253 253 253 253 253 253 253
46046-253 253 253 253 253 253 253 253 253 253 253 253
46047-253 253 253 253 253 253 253 253 253 250 250 250
46048-238 238 238 198 198 198 6 6 6 38 38 38
46049- 58 58 58 26 26 26 38 38 38 2 2 6
46050- 2 2 6 2 2 6 2 2 6 46 46 46
46051- 78 78 78 30 30 30 10 10 10 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 0 0 0 0
46054- 0 0 0 0 0 0 0 0 0 0 0 0
46055- 0 0 0 0 0 0 0 0 0 0 0 0
46056- 0 0 0 0 0 0 0 0 0 0 0 0
46057- 0 0 0 0 0 0 0 0 0 0 0 0
46058- 0 0 0 0 0 0 0 0 0 0 0 0
46059- 0 0 0 0 0 0 10 10 10 30 30 30
46060- 74 74 74 58 58 58 2 2 6 42 42 42
46061- 2 2 6 22 22 22 231 231 231 253 253 253
46062-253 253 253 253 253 253 253 253 253 253 253 253
46063-253 253 253 253 253 253 253 253 253 250 250 250
46064-253 253 253 253 253 253 253 253 253 253 253 253
46065-253 253 253 253 253 253 253 253 253 253 253 253
46066-253 253 253 253 253 253 253 253 253 253 253 253
46067-253 253 253 253 253 253 253 253 253 253 253 253
46068-253 253 253 246 246 246 46 46 46 38 38 38
46069- 42 42 42 14 14 14 38 38 38 14 14 14
46070- 2 2 6 2 2 6 2 2 6 6 6 6
46071- 86 86 86 46 46 46 14 14 14 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 6 6 6 14 14 14 42 42 42
46080- 90 90 90 18 18 18 18 18 18 26 26 26
46081- 2 2 6 116 116 116 253 253 253 253 253 253
46082-253 253 253 253 253 253 253 253 253 253 253 253
46083-253 253 253 253 253 253 250 250 250 238 238 238
46084-253 253 253 253 253 253 253 253 253 253 253 253
46085-253 253 253 253 253 253 253 253 253 253 253 253
46086-253 253 253 253 253 253 253 253 253 253 253 253
46087-253 253 253 253 253 253 253 253 253 253 253 253
46088-253 253 253 253 253 253 94 94 94 6 6 6
46089- 2 2 6 2 2 6 10 10 10 34 34 34
46090- 2 2 6 2 2 6 2 2 6 2 2 6
46091- 74 74 74 58 58 58 22 22 22 6 6 6
46092- 0 0 0 0 0 0 0 0 0 0 0 0
46093- 0 0 0 0 0 0 0 0 0 0 0 0
46094- 0 0 0 0 0 0 0 0 0 0 0 0
46095- 0 0 0 0 0 0 0 0 0 0 0 0
46096- 0 0 0 0 0 0 0 0 0 0 0 0
46097- 0 0 0 0 0 0 0 0 0 0 0 0
46098- 0 0 0 0 0 0 0 0 0 0 0 0
46099- 0 0 0 10 10 10 26 26 26 66 66 66
46100- 82 82 82 2 2 6 38 38 38 6 6 6
46101- 14 14 14 210 210 210 253 253 253 253 253 253
46102-253 253 253 253 253 253 253 253 253 253 253 253
46103-253 253 253 253 253 253 246 246 246 242 242 242
46104-253 253 253 253 253 253 253 253 253 253 253 253
46105-253 253 253 253 253 253 253 253 253 253 253 253
46106-253 253 253 253 253 253 253 253 253 253 253 253
46107-253 253 253 253 253 253 253 253 253 253 253 253
46108-253 253 253 253 253 253 144 144 144 2 2 6
46109- 2 2 6 2 2 6 2 2 6 46 46 46
46110- 2 2 6 2 2 6 2 2 6 2 2 6
46111- 42 42 42 74 74 74 30 30 30 10 10 10
46112- 0 0 0 0 0 0 0 0 0 0 0 0
46113- 0 0 0 0 0 0 0 0 0 0 0 0
46114- 0 0 0 0 0 0 0 0 0 0 0 0
46115- 0 0 0 0 0 0 0 0 0 0 0 0
46116- 0 0 0 0 0 0 0 0 0 0 0 0
46117- 0 0 0 0 0 0 0 0 0 0 0 0
46118- 0 0 0 0 0 0 0 0 0 0 0 0
46119- 6 6 6 14 14 14 42 42 42 90 90 90
46120- 26 26 26 6 6 6 42 42 42 2 2 6
46121- 74 74 74 250 250 250 253 253 253 253 253 253
46122-253 253 253 253 253 253 253 253 253 253 253 253
46123-253 253 253 253 253 253 242 242 242 242 242 242
46124-253 253 253 253 253 253 253 253 253 253 253 253
46125-253 253 253 253 253 253 253 253 253 253 253 253
46126-253 253 253 253 253 253 253 253 253 253 253 253
46127-253 253 253 253 253 253 253 253 253 253 253 253
46128-253 253 253 253 253 253 182 182 182 2 2 6
46129- 2 2 6 2 2 6 2 2 6 46 46 46
46130- 2 2 6 2 2 6 2 2 6 2 2 6
46131- 10 10 10 86 86 86 38 38 38 10 10 10
46132- 0 0 0 0 0 0 0 0 0 0 0 0
46133- 0 0 0 0 0 0 0 0 0 0 0 0
46134- 0 0 0 0 0 0 0 0 0 0 0 0
46135- 0 0 0 0 0 0 0 0 0 0 0 0
46136- 0 0 0 0 0 0 0 0 0 0 0 0
46137- 0 0 0 0 0 0 0 0 0 0 0 0
46138- 0 0 0 0 0 0 0 0 0 0 0 0
46139- 10 10 10 26 26 26 66 66 66 82 82 82
46140- 2 2 6 22 22 22 18 18 18 2 2 6
46141-149 149 149 253 253 253 253 253 253 253 253 253
46142-253 253 253 253 253 253 253 253 253 253 253 253
46143-253 253 253 253 253 253 234 234 234 242 242 242
46144-253 253 253 253 253 253 253 253 253 253 253 253
46145-253 253 253 253 253 253 253 253 253 253 253 253
46146-253 253 253 253 253 253 253 253 253 253 253 253
46147-253 253 253 253 253 253 253 253 253 253 253 253
46148-253 253 253 253 253 253 206 206 206 2 2 6
46149- 2 2 6 2 2 6 2 2 6 38 38 38
46150- 2 2 6 2 2 6 2 2 6 2 2 6
46151- 6 6 6 86 86 86 46 46 46 14 14 14
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 6 6 6
46159- 18 18 18 46 46 46 86 86 86 18 18 18
46160- 2 2 6 34 34 34 10 10 10 6 6 6
46161-210 210 210 253 253 253 253 253 253 253 253 253
46162-253 253 253 253 253 253 253 253 253 253 253 253
46163-253 253 253 253 253 253 234 234 234 242 242 242
46164-253 253 253 253 253 253 253 253 253 253 253 253
46165-253 253 253 253 253 253 253 253 253 253 253 253
46166-253 253 253 253 253 253 253 253 253 253 253 253
46167-253 253 253 253 253 253 253 253 253 253 253 253
46168-253 253 253 253 253 253 221 221 221 6 6 6
46169- 2 2 6 2 2 6 6 6 6 30 30 30
46170- 2 2 6 2 2 6 2 2 6 2 2 6
46171- 2 2 6 82 82 82 54 54 54 18 18 18
46172- 6 6 6 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 10 10 10
46179- 26 26 26 66 66 66 62 62 62 2 2 6
46180- 2 2 6 38 38 38 10 10 10 26 26 26
46181-238 238 238 253 253 253 253 253 253 253 253 253
46182-253 253 253 253 253 253 253 253 253 253 253 253
46183-253 253 253 253 253 253 231 231 231 238 238 238
46184-253 253 253 253 253 253 253 253 253 253 253 253
46185-253 253 253 253 253 253 253 253 253 253 253 253
46186-253 253 253 253 253 253 253 253 253 253 253 253
46187-253 253 253 253 253 253 253 253 253 253 253 253
46188-253 253 253 253 253 253 231 231 231 6 6 6
46189- 2 2 6 2 2 6 10 10 10 30 30 30
46190- 2 2 6 2 2 6 2 2 6 2 2 6
46191- 2 2 6 66 66 66 58 58 58 22 22 22
46192- 6 6 6 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 10 10 10
46199- 38 38 38 78 78 78 6 6 6 2 2 6
46200- 2 2 6 46 46 46 14 14 14 42 42 42
46201-246 246 246 253 253 253 253 253 253 253 253 253
46202-253 253 253 253 253 253 253 253 253 253 253 253
46203-253 253 253 253 253 253 231 231 231 242 242 242
46204-253 253 253 253 253 253 253 253 253 253 253 253
46205-253 253 253 253 253 253 253 253 253 253 253 253
46206-253 253 253 253 253 253 253 253 253 253 253 253
46207-253 253 253 253 253 253 253 253 253 253 253 253
46208-253 253 253 253 253 253 234 234 234 10 10 10
46209- 2 2 6 2 2 6 22 22 22 14 14 14
46210- 2 2 6 2 2 6 2 2 6 2 2 6
46211- 2 2 6 66 66 66 62 62 62 22 22 22
46212- 6 6 6 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 6 6 6 18 18 18
46219- 50 50 50 74 74 74 2 2 6 2 2 6
46220- 14 14 14 70 70 70 34 34 34 62 62 62
46221-250 250 250 253 253 253 253 253 253 253 253 253
46222-253 253 253 253 253 253 253 253 253 253 253 253
46223-253 253 253 253 253 253 231 231 231 246 246 246
46224-253 253 253 253 253 253 253 253 253 253 253 253
46225-253 253 253 253 253 253 253 253 253 253 253 253
46226-253 253 253 253 253 253 253 253 253 253 253 253
46227-253 253 253 253 253 253 253 253 253 253 253 253
46228-253 253 253 253 253 253 234 234 234 14 14 14
46229- 2 2 6 2 2 6 30 30 30 2 2 6
46230- 2 2 6 2 2 6 2 2 6 2 2 6
46231- 2 2 6 66 66 66 62 62 62 22 22 22
46232- 6 6 6 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 6 6 6 18 18 18
46239- 54 54 54 62 62 62 2 2 6 2 2 6
46240- 2 2 6 30 30 30 46 46 46 70 70 70
46241-250 250 250 253 253 253 253 253 253 253 253 253
46242-253 253 253 253 253 253 253 253 253 253 253 253
46243-253 253 253 253 253 253 231 231 231 246 246 246
46244-253 253 253 253 253 253 253 253 253 253 253 253
46245-253 253 253 253 253 253 253 253 253 253 253 253
46246-253 253 253 253 253 253 253 253 253 253 253 253
46247-253 253 253 253 253 253 253 253 253 253 253 253
46248-253 253 253 253 253 253 226 226 226 10 10 10
46249- 2 2 6 6 6 6 30 30 30 2 2 6
46250- 2 2 6 2 2 6 2 2 6 2 2 6
46251- 2 2 6 66 66 66 58 58 58 22 22 22
46252- 6 6 6 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 6 6 6 22 22 22
46259- 58 58 58 62 62 62 2 2 6 2 2 6
46260- 2 2 6 2 2 6 30 30 30 78 78 78
46261-250 250 250 253 253 253 253 253 253 253 253 253
46262-253 253 253 253 253 253 253 253 253 253 253 253
46263-253 253 253 253 253 253 231 231 231 246 246 246
46264-253 253 253 253 253 253 253 253 253 253 253 253
46265-253 253 253 253 253 253 253 253 253 253 253 253
46266-253 253 253 253 253 253 253 253 253 253 253 253
46267-253 253 253 253 253 253 253 253 253 253 253 253
46268-253 253 253 253 253 253 206 206 206 2 2 6
46269- 22 22 22 34 34 34 18 14 6 22 22 22
46270- 26 26 26 18 18 18 6 6 6 2 2 6
46271- 2 2 6 82 82 82 54 54 54 18 18 18
46272- 6 6 6 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 6 6 6 26 26 26
46279- 62 62 62 106 106 106 74 54 14 185 133 11
46280-210 162 10 121 92 8 6 6 6 62 62 62
46281-238 238 238 253 253 253 253 253 253 253 253 253
46282-253 253 253 253 253 253 253 253 253 253 253 253
46283-253 253 253 253 253 253 231 231 231 246 246 246
46284-253 253 253 253 253 253 253 253 253 253 253 253
46285-253 253 253 253 253 253 253 253 253 253 253 253
46286-253 253 253 253 253 253 253 253 253 253 253 253
46287-253 253 253 253 253 253 253 253 253 253 253 253
46288-253 253 253 253 253 253 158 158 158 18 18 18
46289- 14 14 14 2 2 6 2 2 6 2 2 6
46290- 6 6 6 18 18 18 66 66 66 38 38 38
46291- 6 6 6 94 94 94 50 50 50 18 18 18
46292- 6 6 6 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 6 6 6
46298- 10 10 10 10 10 10 18 18 18 38 38 38
46299- 78 78 78 142 134 106 216 158 10 242 186 14
46300-246 190 14 246 190 14 156 118 10 10 10 10
46301- 90 90 90 238 238 238 253 253 253 253 253 253
46302-253 253 253 253 253 253 253 253 253 253 253 253
46303-253 253 253 253 253 253 231 231 231 250 250 250
46304-253 253 253 253 253 253 253 253 253 253 253 253
46305-253 253 253 253 253 253 253 253 253 253 253 253
46306-253 253 253 253 253 253 253 253 253 253 253 253
46307-253 253 253 253 253 253 253 253 253 246 230 190
46308-238 204 91 238 204 91 181 142 44 37 26 9
46309- 2 2 6 2 2 6 2 2 6 2 2 6
46310- 2 2 6 2 2 6 38 38 38 46 46 46
46311- 26 26 26 106 106 106 54 54 54 18 18 18
46312- 6 6 6 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 6 6 6 14 14 14 22 22 22
46318- 30 30 30 38 38 38 50 50 50 70 70 70
46319-106 106 106 190 142 34 226 170 11 242 186 14
46320-246 190 14 246 190 14 246 190 14 154 114 10
46321- 6 6 6 74 74 74 226 226 226 253 253 253
46322-253 253 253 253 253 253 253 253 253 253 253 253
46323-253 253 253 253 253 253 231 231 231 250 250 250
46324-253 253 253 253 253 253 253 253 253 253 253 253
46325-253 253 253 253 253 253 253 253 253 253 253 253
46326-253 253 253 253 253 253 253 253 253 253 253 253
46327-253 253 253 253 253 253 253 253 253 228 184 62
46328-241 196 14 241 208 19 232 195 16 38 30 10
46329- 2 2 6 2 2 6 2 2 6 2 2 6
46330- 2 2 6 6 6 6 30 30 30 26 26 26
46331-203 166 17 154 142 90 66 66 66 26 26 26
46332- 6 6 6 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- 6 6 6 18 18 18 38 38 38 58 58 58
46338- 78 78 78 86 86 86 101 101 101 123 123 123
46339-175 146 61 210 150 10 234 174 13 246 186 14
46340-246 190 14 246 190 14 246 190 14 238 190 10
46341-102 78 10 2 2 6 46 46 46 198 198 198
46342-253 253 253 253 253 253 253 253 253 253 253 253
46343-253 253 253 253 253 253 234 234 234 242 242 242
46344-253 253 253 253 253 253 253 253 253 253 253 253
46345-253 253 253 253 253 253 253 253 253 253 253 253
46346-253 253 253 253 253 253 253 253 253 253 253 253
46347-253 253 253 253 253 253 253 253 253 224 178 62
46348-242 186 14 241 196 14 210 166 10 22 18 6
46349- 2 2 6 2 2 6 2 2 6 2 2 6
46350- 2 2 6 2 2 6 6 6 6 121 92 8
46351-238 202 15 232 195 16 82 82 82 34 34 34
46352- 10 10 10 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- 14 14 14 38 38 38 70 70 70 154 122 46
46358-190 142 34 200 144 11 197 138 11 197 138 11
46359-213 154 11 226 170 11 242 186 14 246 190 14
46360-246 190 14 246 190 14 246 190 14 246 190 14
46361-225 175 15 46 32 6 2 2 6 22 22 22
46362-158 158 158 250 250 250 253 253 253 253 253 253
46363-253 253 253 253 253 253 253 253 253 253 253 253
46364-253 253 253 253 253 253 253 253 253 253 253 253
46365-253 253 253 253 253 253 253 253 253 253 253 253
46366-253 253 253 253 253 253 253 253 253 253 253 253
46367-253 253 253 250 250 250 242 242 242 224 178 62
46368-239 182 13 236 186 11 213 154 11 46 32 6
46369- 2 2 6 2 2 6 2 2 6 2 2 6
46370- 2 2 6 2 2 6 61 42 6 225 175 15
46371-238 190 10 236 186 11 112 100 78 42 42 42
46372- 14 14 14 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 6 6 6
46377- 22 22 22 54 54 54 154 122 46 213 154 11
46378-226 170 11 230 174 11 226 170 11 226 170 11
46379-236 178 12 242 186 14 246 190 14 246 190 14
46380-246 190 14 246 190 14 246 190 14 246 190 14
46381-241 196 14 184 144 12 10 10 10 2 2 6
46382- 6 6 6 116 116 116 242 242 242 253 253 253
46383-253 253 253 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 253 253 253 253 253 253 253 253 253
46386-253 253 253 253 253 253 253 253 253 253 253 253
46387-253 253 253 231 231 231 198 198 198 214 170 54
46388-236 178 12 236 178 12 210 150 10 137 92 6
46389- 18 14 6 2 2 6 2 2 6 2 2 6
46390- 6 6 6 70 47 6 200 144 11 236 178 12
46391-239 182 13 239 182 13 124 112 88 58 58 58
46392- 22 22 22 6 6 6 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 10 10 10
46397- 30 30 30 70 70 70 180 133 36 226 170 11
46398-239 182 13 242 186 14 242 186 14 246 186 14
46399-246 190 14 246 190 14 246 190 14 246 190 14
46400-246 190 14 246 190 14 246 190 14 246 190 14
46401-246 190 14 232 195 16 98 70 6 2 2 6
46402- 2 2 6 2 2 6 66 66 66 221 221 221
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 253 253 253 253 253 253 253 253 253
46406-253 253 253 253 253 253 253 253 253 253 253 253
46407-253 253 253 206 206 206 198 198 198 214 166 58
46408-230 174 11 230 174 11 216 158 10 192 133 9
46409-163 110 8 116 81 8 102 78 10 116 81 8
46410-167 114 7 197 138 11 226 170 11 239 182 13
46411-242 186 14 242 186 14 162 146 94 78 78 78
46412- 34 34 34 14 14 14 6 6 6 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 6 6 6
46417- 30 30 30 78 78 78 190 142 34 226 170 11
46418-239 182 13 246 190 14 246 190 14 246 190 14
46419-246 190 14 246 190 14 246 190 14 246 190 14
46420-246 190 14 246 190 14 246 190 14 246 190 14
46421-246 190 14 241 196 14 203 166 17 22 18 6
46422- 2 2 6 2 2 6 2 2 6 38 38 38
46423-218 218 218 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 253 253 253 253 253 253 253 253 253
46426-253 253 253 253 253 253 253 253 253 253 253 253
46427-250 250 250 206 206 206 198 198 198 202 162 69
46428-226 170 11 236 178 12 224 166 10 210 150 10
46429-200 144 11 197 138 11 192 133 9 197 138 11
46430-210 150 10 226 170 11 242 186 14 246 190 14
46431-246 190 14 246 186 14 225 175 15 124 112 88
46432- 62 62 62 30 30 30 14 14 14 6 6 6
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 10 10 10
46437- 30 30 30 78 78 78 174 135 50 224 166 10
46438-239 182 13 246 190 14 246 190 14 246 190 14
46439-246 190 14 246 190 14 246 190 14 246 190 14
46440-246 190 14 246 190 14 246 190 14 246 190 14
46441-246 190 14 246 190 14 241 196 14 139 102 15
46442- 2 2 6 2 2 6 2 2 6 2 2 6
46443- 78 78 78 250 250 250 253 253 253 253 253 253
46444-253 253 253 253 253 253 253 253 253 253 253 253
46445-253 253 253 253 253 253 253 253 253 253 253 253
46446-253 253 253 253 253 253 253 253 253 253 253 253
46447-250 250 250 214 214 214 198 198 198 190 150 46
46448-219 162 10 236 178 12 234 174 13 224 166 10
46449-216 158 10 213 154 11 213 154 11 216 158 10
46450-226 170 11 239 182 13 246 190 14 246 190 14
46451-246 190 14 246 190 14 242 186 14 206 162 42
46452-101 101 101 58 58 58 30 30 30 14 14 14
46453- 6 6 6 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 10 10 10
46457- 30 30 30 74 74 74 174 135 50 216 158 10
46458-236 178 12 246 190 14 246 190 14 246 190 14
46459-246 190 14 246 190 14 246 190 14 246 190 14
46460-246 190 14 246 190 14 246 190 14 246 190 14
46461-246 190 14 246 190 14 241 196 14 226 184 13
46462- 61 42 6 2 2 6 2 2 6 2 2 6
46463- 22 22 22 238 238 238 253 253 253 253 253 253
46464-253 253 253 253 253 253 253 253 253 253 253 253
46465-253 253 253 253 253 253 253 253 253 253 253 253
46466-253 253 253 253 253 253 253 253 253 253 253 253
46467-253 253 253 226 226 226 187 187 187 180 133 36
46468-216 158 10 236 178 12 239 182 13 236 178 12
46469-230 174 11 226 170 11 226 170 11 230 174 11
46470-236 178 12 242 186 14 246 190 14 246 190 14
46471-246 190 14 246 190 14 246 186 14 239 182 13
46472-206 162 42 106 106 106 66 66 66 34 34 34
46473- 14 14 14 6 6 6 0 0 0 0 0 0
46474- 0 0 0 0 0 0 0 0 0 0 0 0
46475- 0 0 0 0 0 0 0 0 0 0 0 0
46476- 0 0 0 0 0 0 0 0 0 6 6 6
46477- 26 26 26 70 70 70 163 133 67 213 154 11
46478-236 178 12 246 190 14 246 190 14 246 190 14
46479-246 190 14 246 190 14 246 190 14 246 190 14
46480-246 190 14 246 190 14 246 190 14 246 190 14
46481-246 190 14 246 190 14 246 190 14 241 196 14
46482-190 146 13 18 14 6 2 2 6 2 2 6
46483- 46 46 46 246 246 246 253 253 253 253 253 253
46484-253 253 253 253 253 253 253 253 253 253 253 253
46485-253 253 253 253 253 253 253 253 253 253 253 253
46486-253 253 253 253 253 253 253 253 253 253 253 253
46487-253 253 253 221 221 221 86 86 86 156 107 11
46488-216 158 10 236 178 12 242 186 14 246 186 14
46489-242 186 14 239 182 13 239 182 13 242 186 14
46490-242 186 14 246 186 14 246 190 14 246 190 14
46491-246 190 14 246 190 14 246 190 14 246 190 14
46492-242 186 14 225 175 15 142 122 72 66 66 66
46493- 30 30 30 10 10 10 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 6 6 6
46497- 26 26 26 70 70 70 163 133 67 210 150 10
46498-236 178 12 246 190 14 246 190 14 246 190 14
46499-246 190 14 246 190 14 246 190 14 246 190 14
46500-246 190 14 246 190 14 246 190 14 246 190 14
46501-246 190 14 246 190 14 246 190 14 246 190 14
46502-232 195 16 121 92 8 34 34 34 106 106 106
46503-221 221 221 253 253 253 253 253 253 253 253 253
46504-253 253 253 253 253 253 253 253 253 253 253 253
46505-253 253 253 253 253 253 253 253 253 253 253 253
46506-253 253 253 253 253 253 253 253 253 253 253 253
46507-242 242 242 82 82 82 18 14 6 163 110 8
46508-216 158 10 236 178 12 242 186 14 246 190 14
46509-246 190 14 246 190 14 246 190 14 246 190 14
46510-246 190 14 246 190 14 246 190 14 246 190 14
46511-246 190 14 246 190 14 246 190 14 246 190 14
46512-246 190 14 246 190 14 242 186 14 163 133 67
46513- 46 46 46 18 18 18 6 6 6 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 10 10 10
46517- 30 30 30 78 78 78 163 133 67 210 150 10
46518-236 178 12 246 186 14 246 190 14 246 190 14
46519-246 190 14 246 190 14 246 190 14 246 190 14
46520-246 190 14 246 190 14 246 190 14 246 190 14
46521-246 190 14 246 190 14 246 190 14 246 190 14
46522-241 196 14 215 174 15 190 178 144 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 253 253 253
46525-253 253 253 253 253 253 253 253 253 253 253 253
46526-253 253 253 253 253 253 253 253 253 218 218 218
46527- 58 58 58 2 2 6 22 18 6 167 114 7
46528-216 158 10 236 178 12 246 186 14 246 190 14
46529-246 190 14 246 190 14 246 190 14 246 190 14
46530-246 190 14 246 190 14 246 190 14 246 190 14
46531-246 190 14 246 190 14 246 190 14 246 190 14
46532-246 190 14 246 186 14 242 186 14 190 150 46
46533- 54 54 54 22 22 22 6 6 6 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 14 14 14
46537- 38 38 38 86 86 86 180 133 36 213 154 11
46538-236 178 12 246 186 14 246 190 14 246 190 14
46539-246 190 14 246 190 14 246 190 14 246 190 14
46540-246 190 14 246 190 14 246 190 14 246 190 14
46541-246 190 14 246 190 14 246 190 14 246 190 14
46542-246 190 14 232 195 16 190 146 13 214 214 214
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 253 253 253 253 253 253 253 253 253
46546-253 253 253 250 250 250 170 170 170 26 26 26
46547- 2 2 6 2 2 6 37 26 9 163 110 8
46548-219 162 10 239 182 13 246 186 14 246 190 14
46549-246 190 14 246 190 14 246 190 14 246 190 14
46550-246 190 14 246 190 14 246 190 14 246 190 14
46551-246 190 14 246 190 14 246 190 14 246 190 14
46552-246 186 14 236 178 12 224 166 10 142 122 72
46553- 46 46 46 18 18 18 6 6 6 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 6 6 6 18 18 18
46557- 50 50 50 109 106 95 192 133 9 224 166 10
46558-242 186 14 246 190 14 246 190 14 246 190 14
46559-246 190 14 246 190 14 246 190 14 246 190 14
46560-246 190 14 246 190 14 246 190 14 246 190 14
46561-246 190 14 246 190 14 246 190 14 246 190 14
46562-242 186 14 226 184 13 210 162 10 142 110 46
46563-226 226 226 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 253 253 253 253 253 253
46566-198 198 198 66 66 66 2 2 6 2 2 6
46567- 2 2 6 2 2 6 50 34 6 156 107 11
46568-219 162 10 239 182 13 246 186 14 246 190 14
46569-246 190 14 246 190 14 246 190 14 246 190 14
46570-246 190 14 246 190 14 246 190 14 246 190 14
46571-246 190 14 246 190 14 246 190 14 242 186 14
46572-234 174 13 213 154 11 154 122 46 66 66 66
46573- 30 30 30 10 10 10 0 0 0 0 0 0
46574- 0 0 0 0 0 0 0 0 0 0 0 0
46575- 0 0 0 0 0 0 0 0 0 0 0 0
46576- 0 0 0 0 0 0 6 6 6 22 22 22
46577- 58 58 58 154 121 60 206 145 10 234 174 13
46578-242 186 14 246 186 14 246 190 14 246 190 14
46579-246 190 14 246 190 14 246 190 14 246 190 14
46580-246 190 14 246 190 14 246 190 14 246 190 14
46581-246 190 14 246 190 14 246 190 14 246 190 14
46582-246 186 14 236 178 12 210 162 10 163 110 8
46583- 61 42 6 138 138 138 218 218 218 250 250 250
46584-253 253 253 253 253 253 253 253 253 250 250 250
46585-242 242 242 210 210 210 144 144 144 66 66 66
46586- 6 6 6 2 2 6 2 2 6 2 2 6
46587- 2 2 6 2 2 6 61 42 6 163 110 8
46588-216 158 10 236 178 12 246 190 14 246 190 14
46589-246 190 14 246 190 14 246 190 14 246 190 14
46590-246 190 14 246 190 14 246 190 14 246 190 14
46591-246 190 14 239 182 13 230 174 11 216 158 10
46592-190 142 34 124 112 88 70 70 70 38 38 38
46593- 18 18 18 6 6 6 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 6 6 6 22 22 22
46597- 62 62 62 168 124 44 206 145 10 224 166 10
46598-236 178 12 239 182 13 242 186 14 242 186 14
46599-246 186 14 246 190 14 246 190 14 246 190 14
46600-246 190 14 246 190 14 246 190 14 246 190 14
46601-246 190 14 246 190 14 246 190 14 246 190 14
46602-246 190 14 236 178 12 216 158 10 175 118 6
46603- 80 54 7 2 2 6 6 6 6 30 30 30
46604- 54 54 54 62 62 62 50 50 50 38 38 38
46605- 14 14 14 2 2 6 2 2 6 2 2 6
46606- 2 2 6 2 2 6 2 2 6 2 2 6
46607- 2 2 6 6 6 6 80 54 7 167 114 7
46608-213 154 11 236 178 12 246 190 14 246 190 14
46609-246 190 14 246 190 14 246 190 14 246 190 14
46610-246 190 14 242 186 14 239 182 13 239 182 13
46611-230 174 11 210 150 10 174 135 50 124 112 88
46612- 82 82 82 54 54 54 34 34 34 18 18 18
46613- 6 6 6 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 6 6 6 18 18 18
46617- 50 50 50 158 118 36 192 133 9 200 144 11
46618-216 158 10 219 162 10 224 166 10 226 170 11
46619-230 174 11 236 178 12 239 182 13 239 182 13
46620-242 186 14 246 186 14 246 190 14 246 190 14
46621-246 190 14 246 190 14 246 190 14 246 190 14
46622-246 186 14 230 174 11 210 150 10 163 110 8
46623-104 69 6 10 10 10 2 2 6 2 2 6
46624- 2 2 6 2 2 6 2 2 6 2 2 6
46625- 2 2 6 2 2 6 2 2 6 2 2 6
46626- 2 2 6 2 2 6 2 2 6 2 2 6
46627- 2 2 6 6 6 6 91 60 6 167 114 7
46628-206 145 10 230 174 11 242 186 14 246 190 14
46629-246 190 14 246 190 14 246 186 14 242 186 14
46630-239 182 13 230 174 11 224 166 10 213 154 11
46631-180 133 36 124 112 88 86 86 86 58 58 58
46632- 38 38 38 22 22 22 10 10 10 6 6 6
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 14 14 14
46637- 34 34 34 70 70 70 138 110 50 158 118 36
46638-167 114 7 180 123 7 192 133 9 197 138 11
46639-200 144 11 206 145 10 213 154 11 219 162 10
46640-224 166 10 230 174 11 239 182 13 242 186 14
46641-246 186 14 246 186 14 246 186 14 246 186 14
46642-239 182 13 216 158 10 185 133 11 152 99 6
46643-104 69 6 18 14 6 2 2 6 2 2 6
46644- 2 2 6 2 2 6 2 2 6 2 2 6
46645- 2 2 6 2 2 6 2 2 6 2 2 6
46646- 2 2 6 2 2 6 2 2 6 2 2 6
46647- 2 2 6 6 6 6 80 54 7 152 99 6
46648-192 133 9 219 162 10 236 178 12 239 182 13
46649-246 186 14 242 186 14 239 182 13 236 178 12
46650-224 166 10 206 145 10 192 133 9 154 121 60
46651- 94 94 94 62 62 62 42 42 42 22 22 22
46652- 14 14 14 6 6 6 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 6 6 6
46657- 18 18 18 34 34 34 58 58 58 78 78 78
46658-101 98 89 124 112 88 142 110 46 156 107 11
46659-163 110 8 167 114 7 175 118 6 180 123 7
46660-185 133 11 197 138 11 210 150 10 219 162 10
46661-226 170 11 236 178 12 236 178 12 234 174 13
46662-219 162 10 197 138 11 163 110 8 130 83 6
46663- 91 60 6 10 10 10 2 2 6 2 2 6
46664- 18 18 18 38 38 38 38 38 38 38 38 38
46665- 38 38 38 38 38 38 38 38 38 38 38 38
46666- 38 38 38 38 38 38 26 26 26 2 2 6
46667- 2 2 6 6 6 6 70 47 6 137 92 6
46668-175 118 6 200 144 11 219 162 10 230 174 11
46669-234 174 13 230 174 11 219 162 10 210 150 10
46670-192 133 9 163 110 8 124 112 88 82 82 82
46671- 50 50 50 30 30 30 14 14 14 6 6 6
46672- 0 0 0 0 0 0 0 0 0 0 0 0
46673- 0 0 0 0 0 0 0 0 0 0 0 0
46674- 0 0 0 0 0 0 0 0 0 0 0 0
46675- 0 0 0 0 0 0 0 0 0 0 0 0
46676- 0 0 0 0 0 0 0 0 0 0 0 0
46677- 6 6 6 14 14 14 22 22 22 34 34 34
46678- 42 42 42 58 58 58 74 74 74 86 86 86
46679-101 98 89 122 102 70 130 98 46 121 87 25
46680-137 92 6 152 99 6 163 110 8 180 123 7
46681-185 133 11 197 138 11 206 145 10 200 144 11
46682-180 123 7 156 107 11 130 83 6 104 69 6
46683- 50 34 6 54 54 54 110 110 110 101 98 89
46684- 86 86 86 82 82 82 78 78 78 78 78 78
46685- 78 78 78 78 78 78 78 78 78 78 78 78
46686- 78 78 78 82 82 82 86 86 86 94 94 94
46687-106 106 106 101 101 101 86 66 34 124 80 6
46688-156 107 11 180 123 7 192 133 9 200 144 11
46689-206 145 10 200 144 11 192 133 9 175 118 6
46690-139 102 15 109 106 95 70 70 70 42 42 42
46691- 22 22 22 10 10 10 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 0 0 0
46697- 0 0 0 0 0 0 6 6 6 10 10 10
46698- 14 14 14 22 22 22 30 30 30 38 38 38
46699- 50 50 50 62 62 62 74 74 74 90 90 90
46700-101 98 89 112 100 78 121 87 25 124 80 6
46701-137 92 6 152 99 6 152 99 6 152 99 6
46702-138 86 6 124 80 6 98 70 6 86 66 30
46703-101 98 89 82 82 82 58 58 58 46 46 46
46704- 38 38 38 34 34 34 34 34 34 34 34 34
46705- 34 34 34 34 34 34 34 34 34 34 34 34
46706- 34 34 34 34 34 34 38 38 38 42 42 42
46707- 54 54 54 82 82 82 94 86 76 91 60 6
46708-134 86 6 156 107 11 167 114 7 175 118 6
46709-175 118 6 167 114 7 152 99 6 121 87 25
46710-101 98 89 62 62 62 34 34 34 18 18 18
46711- 6 6 6 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 0 0 0
46717- 0 0 0 0 0 0 0 0 0 0 0 0
46718- 0 0 0 6 6 6 6 6 6 10 10 10
46719- 18 18 18 22 22 22 30 30 30 42 42 42
46720- 50 50 50 66 66 66 86 86 86 101 98 89
46721-106 86 58 98 70 6 104 69 6 104 69 6
46722-104 69 6 91 60 6 82 62 34 90 90 90
46723- 62 62 62 38 38 38 22 22 22 14 14 14
46724- 10 10 10 10 10 10 10 10 10 10 10 10
46725- 10 10 10 10 10 10 6 6 6 10 10 10
46726- 10 10 10 10 10 10 10 10 10 14 14 14
46727- 22 22 22 42 42 42 70 70 70 89 81 66
46728- 80 54 7 104 69 6 124 80 6 137 92 6
46729-134 86 6 116 81 8 100 82 52 86 86 86
46730- 58 58 58 30 30 30 14 14 14 6 6 6
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 0 0 0
46737- 0 0 0 0 0 0 0 0 0 0 0 0
46738- 0 0 0 0 0 0 0 0 0 0 0 0
46739- 0 0 0 6 6 6 10 10 10 14 14 14
46740- 18 18 18 26 26 26 38 38 38 54 54 54
46741- 70 70 70 86 86 86 94 86 76 89 81 66
46742- 89 81 66 86 86 86 74 74 74 50 50 50
46743- 30 30 30 14 14 14 6 6 6 0 0 0
46744- 0 0 0 0 0 0 0 0 0 0 0 0
46745- 0 0 0 0 0 0 0 0 0 0 0 0
46746- 0 0 0 0 0 0 0 0 0 0 0 0
46747- 6 6 6 18 18 18 34 34 34 58 58 58
46748- 82 82 82 89 81 66 89 81 66 89 81 66
46749- 94 86 66 94 86 76 74 74 74 50 50 50
46750- 26 26 26 14 14 14 6 6 6 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 0 0 0 0 0 0
46757- 0 0 0 0 0 0 0 0 0 0 0 0
46758- 0 0 0 0 0 0 0 0 0 0 0 0
46759- 0 0 0 0 0 0 0 0 0 0 0 0
46760- 6 6 6 6 6 6 14 14 14 18 18 18
46761- 30 30 30 38 38 38 46 46 46 54 54 54
46762- 50 50 50 42 42 42 30 30 30 18 18 18
46763- 10 10 10 0 0 0 0 0 0 0 0 0
46764- 0 0 0 0 0 0 0 0 0 0 0 0
46765- 0 0 0 0 0 0 0 0 0 0 0 0
46766- 0 0 0 0 0 0 0 0 0 0 0 0
46767- 0 0 0 6 6 6 14 14 14 26 26 26
46768- 38 38 38 50 50 50 58 58 58 58 58 58
46769- 54 54 54 42 42 42 30 30 30 18 18 18
46770- 10 10 10 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 0 0 0 0 0 0
46777- 0 0 0 0 0 0 0 0 0 0 0 0
46778- 0 0 0 0 0 0 0 0 0 0 0 0
46779- 0 0 0 0 0 0 0 0 0 0 0 0
46780- 0 0 0 0 0 0 0 0 0 6 6 6
46781- 6 6 6 10 10 10 14 14 14 18 18 18
46782- 18 18 18 14 14 14 10 10 10 6 6 6
46783- 0 0 0 0 0 0 0 0 0 0 0 0
46784- 0 0 0 0 0 0 0 0 0 0 0 0
46785- 0 0 0 0 0 0 0 0 0 0 0 0
46786- 0 0 0 0 0 0 0 0 0 0 0 0
46787- 0 0 0 0 0 0 0 0 0 6 6 6
46788- 14 14 14 18 18 18 22 22 22 22 22 22
46789- 18 18 18 14 14 14 10 10 10 6 6 6
46790- 0 0 0 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+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46796+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46797+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46798+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46799+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46800+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46801+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46802+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46803+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46804+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46805+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46806+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46807+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46808+4 4 4 4 4 4
46809+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46810+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46811+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46812+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46813+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46814+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46815+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46816+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46817+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46818+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46819+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46820+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46821+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46822+4 4 4 4 4 4
46823+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46824+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46825+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46826+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46827+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46828+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46829+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46830+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46831+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46832+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46833+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46834+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46835+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46836+4 4 4 4 4 4
46837+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46838+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46839+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46840+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46841+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46842+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46843+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46844+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46845+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46846+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46847+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46848+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46849+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46850+4 4 4 4 4 4
46851+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46852+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46853+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46854+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46855+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46856+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46857+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46858+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46859+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46860+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46861+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46862+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46863+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46864+4 4 4 4 4 4
46865+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46866+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46867+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46868+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46869+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46870+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46871+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46872+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46873+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46874+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46875+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46876+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46877+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46878+4 4 4 4 4 4
46879+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46880+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46881+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46882+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46883+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
46884+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
46885+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46886+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46887+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46888+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
46889+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46890+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
46891+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46892+4 4 4 4 4 4
46893+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46894+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46895+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46896+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46897+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
46898+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
46899+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46900+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46901+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46902+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
46903+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
46904+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
46905+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46906+4 4 4 4 4 4
46907+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46908+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46909+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46910+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46911+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
46912+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
46913+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46914+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46915+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46916+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
46917+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
46918+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
46919+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
46920+4 4 4 4 4 4
46921+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46922+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46923+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46924+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
46925+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
46926+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
46927+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
46928+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46929+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
46930+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
46931+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
46932+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
46933+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
46934+4 4 4 4 4 4
46935+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46936+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46937+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46938+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
46939+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
46940+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
46941+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
46942+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46943+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
46944+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
46945+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
46946+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
46947+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
46948+4 4 4 4 4 4
46949+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46950+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46951+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
46952+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
46953+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
46954+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
46955+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
46956+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
46957+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
46958+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
46959+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
46960+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
46961+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
46962+4 4 4 4 4 4
46963+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46964+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46965+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
46966+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
46967+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
46968+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
46969+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
46970+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
46971+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
46972+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
46973+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
46974+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
46975+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
46976+4 4 4 4 4 4
46977+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46978+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46979+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
46980+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
46981+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
46982+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
46983+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
46984+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
46985+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
46986+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
46987+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
46988+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
46989+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
46990+4 4 4 4 4 4
46991+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46992+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46993+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
46994+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
46995+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
46996+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
46997+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
46998+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
46999+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
47000+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
47001+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
47002+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
47003+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
47004+4 4 4 4 4 4
47005+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47006+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47007+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
47008+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
47009+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
47010+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
47011+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
47012+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
47013+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
47014+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
47015+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
47016+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
47017+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
47018+4 4 4 4 4 4
47019+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47020+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
47021+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
47022+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
47023+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
47024+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
47025+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
47026+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
47027+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
47028+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
47029+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
47030+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
47031+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
47032+4 4 4 4 4 4
47033+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47034+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
47035+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
47036+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
47037+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
47038+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
47039+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
47040+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
47041+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
47042+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
47043+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
47044+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
47045+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
47046+0 0 0 4 4 4
47047+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
47048+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
47049+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
47050+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
47051+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
47052+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
47053+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
47054+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
47055+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
47056+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
47057+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
47058+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
47059+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
47060+2 0 0 0 0 0
47061+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
47062+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
47063+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
47064+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
47065+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
47066+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
47067+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
47068+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
47069+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
47070+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
47071+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
47072+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
47073+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
47074+37 38 37 0 0 0
47075+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
47076+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
47077+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
47078+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
47079+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
47080+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
47081+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
47082+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
47083+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
47084+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
47085+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
47086+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
47087+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
47088+85 115 134 4 0 0
47089+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
47090+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
47091+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
47092+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
47093+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
47094+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
47095+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
47096+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
47097+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
47098+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
47099+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
47100+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
47101+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
47102+60 73 81 4 0 0
47103+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
47104+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
47105+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
47106+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
47107+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
47108+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
47109+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
47110+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
47111+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
47112+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
47113+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
47114+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
47115+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
47116+16 19 21 4 0 0
47117+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
47118+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
47119+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
47120+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
47121+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
47122+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
47123+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
47124+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
47125+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
47126+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
47127+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
47128+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
47129+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
47130+4 0 0 4 3 3
47131+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
47132+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
47133+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
47134+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
47135+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
47136+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
47137+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
47138+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
47139+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
47140+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
47141+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
47142+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
47143+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
47144+3 2 2 4 4 4
47145+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
47146+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
47147+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
47148+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
47149+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
47150+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
47151+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
47152+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
47153+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
47154+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
47155+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
47156+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
47157+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
47158+4 4 4 4 4 4
47159+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
47160+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
47161+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
47162+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
47163+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
47164+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
47165+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
47166+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
47167+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
47168+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
47169+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
47170+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
47171+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
47172+4 4 4 4 4 4
47173+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
47174+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
47175+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
47176+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
47177+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
47178+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
47179+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
47180+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
47181+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
47182+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
47183+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
47184+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
47185+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
47186+5 5 5 5 5 5
47187+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
47188+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
47189+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
47190+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
47191+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
47192+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47193+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
47194+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
47195+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
47196+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
47197+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
47198+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
47199+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
47200+5 5 5 4 4 4
47201+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
47202+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
47203+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
47204+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
47205+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
47206+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
47207+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
47208+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
47209+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
47210+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
47211+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
47212+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
47213+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47214+4 4 4 4 4 4
47215+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
47216+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
47217+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
47218+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
47219+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
47220+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47221+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47222+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
47223+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
47224+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
47225+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
47226+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
47227+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47228+4 4 4 4 4 4
47229+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
47230+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
47231+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
47232+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
47233+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
47234+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
47235+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
47236+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
47237+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
47238+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
47239+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
47240+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47241+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47242+4 4 4 4 4 4
47243+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
47244+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
47245+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
47246+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
47247+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
47248+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47249+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47250+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
47251+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
47252+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
47253+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
47254+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47255+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47256+4 4 4 4 4 4
47257+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
47258+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
47259+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
47260+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
47261+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
47262+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
47263+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
47264+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
47265+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
47266+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
47267+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47268+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47269+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47270+4 4 4 4 4 4
47271+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
47272+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
47273+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
47274+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
47275+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
47276+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
47277+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
47278+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
47279+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
47280+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
47281+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
47282+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47283+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47284+4 4 4 4 4 4
47285+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
47286+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
47287+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
47288+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
47289+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
47290+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
47291+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
47292+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
47293+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
47294+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
47295+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
47296+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47297+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47298+4 4 4 4 4 4
47299+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
47300+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
47301+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
47302+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
47303+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
47304+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
47305+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
47306+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
47307+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
47308+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
47309+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47310+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47311+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47312+4 4 4 4 4 4
47313+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
47314+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
47315+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
47316+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
47317+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47318+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
47319+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
47320+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
47321+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
47322+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
47323+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47324+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47325+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47326+4 4 4 4 4 4
47327+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
47328+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
47329+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
47330+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
47331+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47332+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
47333+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
47334+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
47335+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
47336+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
47337+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47338+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47339+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47340+4 4 4 4 4 4
47341+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
47342+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
47343+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
47344+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
47345+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47346+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
47347+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
47348+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
47349+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
47350+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47351+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47352+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47353+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47354+4 4 4 4 4 4
47355+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
47356+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
47357+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
47358+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
47359+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
47360+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
47361+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
47362+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
47363+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47364+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47365+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47366+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47367+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47368+4 4 4 4 4 4
47369+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
47370+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
47371+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
47372+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
47373+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47374+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
47375+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
47376+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
47377+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
47378+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47379+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47380+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47381+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47382+4 4 4 4 4 4
47383+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
47384+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
47385+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
47386+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
47387+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
47388+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
47389+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
47390+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
47391+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47392+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47393+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47394+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47395+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47396+4 4 4 4 4 4
47397+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
47398+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
47399+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
47400+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
47401+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
47402+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
47403+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
47404+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
47405+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
47406+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47407+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47408+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47409+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47410+4 4 4 4 4 4
47411+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
47412+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
47413+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
47414+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
47415+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
47416+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
47417+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
47418+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
47419+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47420+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47421+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47422+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47423+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47424+4 4 4 4 4 4
47425+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
47426+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
47427+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
47428+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
47429+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
47430+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
47431+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
47432+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
47433+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
47434+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47435+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47436+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47437+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47438+4 4 4 4 4 4
47439+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
47440+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
47441+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
47442+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
47443+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
47444+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
47445+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
47446+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
47447+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47448+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47449+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47450+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47451+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47452+4 4 4 4 4 4
47453+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47454+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
47455+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
47456+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
47457+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
47458+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
47459+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
47460+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
47461+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
47462+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47463+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47464+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47465+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47466+4 4 4 4 4 4
47467+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
47468+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
47469+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
47470+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
47471+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
47472+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
47473+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47474+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
47475+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47476+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47477+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47478+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47479+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47480+4 4 4 4 4 4
47481+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47482+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
47483+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
47484+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
47485+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
47486+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
47487+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47488+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
47489+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
47490+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47491+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47492+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47493+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47494+4 4 4 4 4 4
47495+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
47496+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
47497+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
47498+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
47499+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
47500+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
47501+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
47502+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
47503+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
47504+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47505+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47506+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47507+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47508+4 4 4 4 4 4
47509+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47510+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
47511+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
47512+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
47513+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
47514+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
47515+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
47516+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
47517+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
47518+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47519+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47520+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47521+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47522+4 4 4 4 4 4
47523+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
47524+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
47525+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
47526+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
47527+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
47528+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
47529+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
47530+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
47531+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
47532+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47533+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47534+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47535+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47536+4 4 4 4 4 4
47537+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47538+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
47539+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
47540+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
47541+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
47542+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
47543+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
47544+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
47545+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
47546+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47547+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47548+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47549+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47550+4 4 4 4 4 4
47551+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
47552+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
47553+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
47554+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
47555+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
47556+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
47557+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
47558+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
47559+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
47560+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
47561+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47562+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47563+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47564+4 4 4 4 4 4
47565+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
47566+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
47567+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
47568+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
47569+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
47570+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
47571+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
47572+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
47573+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
47574+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
47575+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47576+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47577+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47578+4 4 4 4 4 4
47579+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
47580+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
47581+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
47582+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
47583+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
47584+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
47585+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47586+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
47587+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
47588+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
47589+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47590+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47591+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47592+4 4 4 4 4 4
47593+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
47594+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
47595+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
47596+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
47597+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
47598+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
47599+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
47600+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
47601+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
47602+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
47603+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47604+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47605+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47606+4 4 4 4 4 4
47607+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
47608+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
47609+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
47610+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
47611+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
47612+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
47613+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
47614+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
47615+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
47616+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
47617+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47618+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47619+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47620+4 4 4 4 4 4
47621+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47622+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
47623+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
47624+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
47625+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
47626+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
47627+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
47628+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
47629+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
47630+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
47631+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47632+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47633+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47634+4 4 4 4 4 4
47635+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
47636+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
47637+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
47638+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
47639+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
47640+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
47641+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
47642+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
47643+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
47644+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
47645+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47646+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47647+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47648+4 4 4 4 4 4
47649+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
47650+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
47651+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
47652+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
47653+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
47654+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
47655+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
47656+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
47657+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
47658+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47659+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47660+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47661+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47662+4 4 4 4 4 4
47663+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
47664+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47665+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
47666+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
47667+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
47668+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
47669+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
47670+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
47671+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
47672+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47674+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47675+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47676+4 4 4 4 4 4
47677+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
47678+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
47679+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
47680+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
47681+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
47682+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
47683+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
47684+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
47685+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
47686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47687+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47688+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47689+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47690+4 4 4 4 4 4
47691+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
47692+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
47693+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
47694+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
47695+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
47696+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
47697+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
47698+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
47699+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47701+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47702+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47703+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47704+4 4 4 4 4 4
47705+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
47706+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
47707+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
47708+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
47709+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
47710+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
47711+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
47712+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
47713+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47714+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47715+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47716+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47717+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47718+4 4 4 4 4 4
47719+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
47720+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
47721+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
47722+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
47723+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
47724+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
47725+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
47726+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
47727+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47728+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47729+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47730+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47731+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47732+4 4 4 4 4 4
47733+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
47734+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
47735+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47736+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
47737+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
47738+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
47739+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
47740+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
47741+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47742+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47743+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47744+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47745+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47746+4 4 4 4 4 4
47747+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47748+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
47749+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
47750+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
47751+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
47752+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
47753+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
47754+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
47755+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47756+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47757+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47758+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47759+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47760+4 4 4 4 4 4
47761+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47762+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
47763+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
47764+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
47765+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
47766+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
47767+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
47768+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47769+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47770+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47771+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47772+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47773+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47774+4 4 4 4 4 4
47775+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47776+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47777+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
47778+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
47779+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
47780+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
47781+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
47782+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47783+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47784+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47785+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47786+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47787+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47788+4 4 4 4 4 4
47789+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47790+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47791+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
47792+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47793+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
47794+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
47795+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
47796+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47797+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47798+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47799+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47800+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47801+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47802+4 4 4 4 4 4
47803+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47804+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47805+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47806+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
47807+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
47808+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
47809+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
47810+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47811+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47812+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47813+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47814+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47815+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47816+4 4 4 4 4 4
47817+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47818+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47819+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47820+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
47821+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47822+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
47823+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
47824+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47825+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47826+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47827+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47828+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47829+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47830+4 4 4 4 4 4
47831+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47832+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47833+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47834+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
47835+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
47836+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
47837+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
47838+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47839+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47840+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47841+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47842+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47843+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47844+4 4 4 4 4 4
47845+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47846+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47847+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47848+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
47849+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
47850+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47851+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47852+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47853+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47854+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47855+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47856+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47857+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47858+4 4 4 4 4 4
47859+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47860+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47861+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47862+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47863+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
47864+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
47865+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
47866+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47867+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47868+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47869+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47870+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47871+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47872+4 4 4 4 4 4
47873+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47874+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47875+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47876+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47877+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
47878+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
47879+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47880+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47881+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47882+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47883+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47884+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47885+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47886+4 4 4 4 4 4
47887+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47888+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47889+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47890+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47891+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
47892+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
47893+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47894+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47895+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47896+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47897+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47898+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47899+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47900+4 4 4 4 4 4
47901+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47902+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47903+4 4 4 4 4 4 4 4 4 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 5 5 5 4 3 3
47906+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
47907+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47908+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47909+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47910+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47911+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47912+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47913+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47914+4 4 4 4 4 4
47915diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
47916index fe92eed..106e085 100644
47917--- a/drivers/video/mb862xx/mb862xxfb_accel.c
47918+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
47919@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
47920 struct mb862xxfb_par *par = info->par;
47921
47922 if (info->var.bits_per_pixel == 32) {
47923- info->fbops->fb_fillrect = cfb_fillrect;
47924- info->fbops->fb_copyarea = cfb_copyarea;
47925- info->fbops->fb_imageblit = cfb_imageblit;
47926+ pax_open_kernel();
47927+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
47928+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
47929+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
47930+ pax_close_kernel();
47931 } else {
47932 outreg(disp, GC_L0EM, 3);
47933- info->fbops->fb_fillrect = mb86290fb_fillrect;
47934- info->fbops->fb_copyarea = mb86290fb_copyarea;
47935- info->fbops->fb_imageblit = mb86290fb_imageblit;
47936+ pax_open_kernel();
47937+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
47938+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
47939+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
47940+ pax_close_kernel();
47941 }
47942 outreg(draw, GDC_REG_DRAW_BASE, 0);
47943 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
47944diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
47945index ff22871..b129bed 100644
47946--- a/drivers/video/nvidia/nvidia.c
47947+++ b/drivers/video/nvidia/nvidia.c
47948@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
47949 info->fix.line_length = (info->var.xres_virtual *
47950 info->var.bits_per_pixel) >> 3;
47951 if (info->var.accel_flags) {
47952- info->fbops->fb_imageblit = nvidiafb_imageblit;
47953- info->fbops->fb_fillrect = nvidiafb_fillrect;
47954- info->fbops->fb_copyarea = nvidiafb_copyarea;
47955- info->fbops->fb_sync = nvidiafb_sync;
47956+ pax_open_kernel();
47957+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
47958+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
47959+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
47960+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
47961+ pax_close_kernel();
47962 info->pixmap.scan_align = 4;
47963 info->flags &= ~FBINFO_HWACCEL_DISABLED;
47964 info->flags |= FBINFO_READS_FAST;
47965 NVResetGraphics(info);
47966 } else {
47967- info->fbops->fb_imageblit = cfb_imageblit;
47968- info->fbops->fb_fillrect = cfb_fillrect;
47969- info->fbops->fb_copyarea = cfb_copyarea;
47970- info->fbops->fb_sync = NULL;
47971+ pax_open_kernel();
47972+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
47973+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
47974+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
47975+ *(void **)&info->fbops->fb_sync = NULL;
47976+ pax_close_kernel();
47977 info->pixmap.scan_align = 1;
47978 info->flags |= FBINFO_HWACCEL_DISABLED;
47979 info->flags &= ~FBINFO_READS_FAST;
47980@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
47981 info->pixmap.size = 8 * 1024;
47982 info->pixmap.flags = FB_PIXMAP_SYSTEM;
47983
47984- if (!hwcur)
47985- info->fbops->fb_cursor = NULL;
47986+ if (!hwcur) {
47987+ pax_open_kernel();
47988+ *(void **)&info->fbops->fb_cursor = NULL;
47989+ pax_close_kernel();
47990+ }
47991
47992 info->var.accel_flags = (!noaccel);
47993
47994diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
47995index 76d9053..dec2bfd 100644
47996--- a/drivers/video/s1d13xxxfb.c
47997+++ b/drivers/video/s1d13xxxfb.c
47998@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
47999
48000 switch(prod_id) {
48001 case S1D13506_PROD_ID: /* activate acceleration */
48002- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
48003- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
48004+ pax_open_kernel();
48005+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
48006+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
48007+ pax_close_kernel();
48008 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
48009 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
48010 break;
48011diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
48012index 97bd662..39fab85 100644
48013--- a/drivers/video/smscufx.c
48014+++ b/drivers/video/smscufx.c
48015@@ -1171,7 +1171,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
48016 fb_deferred_io_cleanup(info);
48017 kfree(info->fbdefio);
48018 info->fbdefio = NULL;
48019- info->fbops->fb_mmap = ufx_ops_mmap;
48020+ pax_open_kernel();
48021+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
48022+ pax_close_kernel();
48023 }
48024
48025 pr_debug("released /dev/fb%d user=%d count=%d",
48026diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
48027index 86d449e..8e04dc5 100644
48028--- a/drivers/video/udlfb.c
48029+++ b/drivers/video/udlfb.c
48030@@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
48031 dlfb_urb_completion(urb);
48032
48033 error:
48034- atomic_add(bytes_sent, &dev->bytes_sent);
48035- atomic_add(bytes_identical, &dev->bytes_identical);
48036- atomic_add(width*height*2, &dev->bytes_rendered);
48037+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
48038+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
48039+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
48040 end_cycles = get_cycles();
48041- atomic_add(((unsigned int) ((end_cycles - start_cycles)
48042+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
48043 >> 10)), /* Kcycles */
48044 &dev->cpu_kcycles_used);
48045
48046@@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
48047 dlfb_urb_completion(urb);
48048
48049 error:
48050- atomic_add(bytes_sent, &dev->bytes_sent);
48051- atomic_add(bytes_identical, &dev->bytes_identical);
48052- atomic_add(bytes_rendered, &dev->bytes_rendered);
48053+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
48054+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
48055+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
48056 end_cycles = get_cycles();
48057- atomic_add(((unsigned int) ((end_cycles - start_cycles)
48058+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
48059 >> 10)), /* Kcycles */
48060 &dev->cpu_kcycles_used);
48061 }
48062@@ -989,7 +989,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
48063 fb_deferred_io_cleanup(info);
48064 kfree(info->fbdefio);
48065 info->fbdefio = NULL;
48066- info->fbops->fb_mmap = dlfb_ops_mmap;
48067+ pax_open_kernel();
48068+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
48069+ pax_close_kernel();
48070 }
48071
48072 pr_warn("released /dev/fb%d user=%d count=%d\n",
48073@@ -1372,7 +1374,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
48074 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48075 struct dlfb_data *dev = fb_info->par;
48076 return snprintf(buf, PAGE_SIZE, "%u\n",
48077- atomic_read(&dev->bytes_rendered));
48078+ atomic_read_unchecked(&dev->bytes_rendered));
48079 }
48080
48081 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
48082@@ -1380,7 +1382,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
48083 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48084 struct dlfb_data *dev = fb_info->par;
48085 return snprintf(buf, PAGE_SIZE, "%u\n",
48086- atomic_read(&dev->bytes_identical));
48087+ atomic_read_unchecked(&dev->bytes_identical));
48088 }
48089
48090 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
48091@@ -1388,7 +1390,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
48092 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48093 struct dlfb_data *dev = fb_info->par;
48094 return snprintf(buf, PAGE_SIZE, "%u\n",
48095- atomic_read(&dev->bytes_sent));
48096+ atomic_read_unchecked(&dev->bytes_sent));
48097 }
48098
48099 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
48100@@ -1396,7 +1398,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
48101 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48102 struct dlfb_data *dev = fb_info->par;
48103 return snprintf(buf, PAGE_SIZE, "%u\n",
48104- atomic_read(&dev->cpu_kcycles_used));
48105+ atomic_read_unchecked(&dev->cpu_kcycles_used));
48106 }
48107
48108 static ssize_t edid_show(
48109@@ -1456,10 +1458,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
48110 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48111 struct dlfb_data *dev = fb_info->par;
48112
48113- atomic_set(&dev->bytes_rendered, 0);
48114- atomic_set(&dev->bytes_identical, 0);
48115- atomic_set(&dev->bytes_sent, 0);
48116- atomic_set(&dev->cpu_kcycles_used, 0);
48117+ atomic_set_unchecked(&dev->bytes_rendered, 0);
48118+ atomic_set_unchecked(&dev->bytes_identical, 0);
48119+ atomic_set_unchecked(&dev->bytes_sent, 0);
48120+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
48121
48122 return count;
48123 }
48124diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
48125index b75db01..ad2f34a 100644
48126--- a/drivers/video/uvesafb.c
48127+++ b/drivers/video/uvesafb.c
48128@@ -19,6 +19,7 @@
48129 #include <linux/io.h>
48130 #include <linux/mutex.h>
48131 #include <linux/slab.h>
48132+#include <linux/moduleloader.h>
48133 #include <video/edid.h>
48134 #include <video/uvesafb.h>
48135 #ifdef CONFIG_X86
48136@@ -569,10 +570,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
48137 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
48138 par->pmi_setpal = par->ypan = 0;
48139 } else {
48140+
48141+#ifdef CONFIG_PAX_KERNEXEC
48142+#ifdef CONFIG_MODULES
48143+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
48144+#endif
48145+ if (!par->pmi_code) {
48146+ par->pmi_setpal = par->ypan = 0;
48147+ return 0;
48148+ }
48149+#endif
48150+
48151 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
48152 + task->t.regs.edi);
48153+
48154+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48155+ pax_open_kernel();
48156+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
48157+ pax_close_kernel();
48158+
48159+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
48160+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
48161+#else
48162 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
48163 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
48164+#endif
48165+
48166 printk(KERN_INFO "uvesafb: protected mode interface info at "
48167 "%04x:%04x\n",
48168 (u16)task->t.regs.es, (u16)task->t.regs.edi);
48169@@ -817,13 +840,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
48170 par->ypan = ypan;
48171
48172 if (par->pmi_setpal || par->ypan) {
48173+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
48174 if (__supported_pte_mask & _PAGE_NX) {
48175 par->pmi_setpal = par->ypan = 0;
48176 printk(KERN_WARNING "uvesafb: NX protection is actively."
48177 "We have better not to use the PMI.\n");
48178- } else {
48179+ } else
48180+#endif
48181 uvesafb_vbe_getpmi(task, par);
48182- }
48183 }
48184 #else
48185 /* The protected mode interface is not available on non-x86. */
48186@@ -1457,8 +1481,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
48187 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
48188
48189 /* Disable blanking if the user requested so. */
48190- if (!blank)
48191- info->fbops->fb_blank = NULL;
48192+ if (!blank) {
48193+ pax_open_kernel();
48194+ *(void **)&info->fbops->fb_blank = NULL;
48195+ pax_close_kernel();
48196+ }
48197
48198 /*
48199 * Find out how much IO memory is required for the mode with
48200@@ -1534,8 +1561,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
48201 info->flags = FBINFO_FLAG_DEFAULT |
48202 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
48203
48204- if (!par->ypan)
48205- info->fbops->fb_pan_display = NULL;
48206+ if (!par->ypan) {
48207+ pax_open_kernel();
48208+ *(void **)&info->fbops->fb_pan_display = NULL;
48209+ pax_close_kernel();
48210+ }
48211 }
48212
48213 static void uvesafb_init_mtrr(struct fb_info *info)
48214@@ -1836,6 +1866,11 @@ out:
48215 if (par->vbe_modes)
48216 kfree(par->vbe_modes);
48217
48218+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48219+ if (par->pmi_code)
48220+ module_free_exec(NULL, par->pmi_code);
48221+#endif
48222+
48223 framebuffer_release(info);
48224 return err;
48225 }
48226@@ -1862,6 +1897,12 @@ static int uvesafb_remove(struct platform_device *dev)
48227 kfree(par->vbe_state_orig);
48228 if (par->vbe_state_saved)
48229 kfree(par->vbe_state_saved);
48230+
48231+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48232+ if (par->pmi_code)
48233+ module_free_exec(NULL, par->pmi_code);
48234+#endif
48235+
48236 }
48237
48238 framebuffer_release(info);
48239diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
48240index 501b340..d80aa17 100644
48241--- a/drivers/video/vesafb.c
48242+++ b/drivers/video/vesafb.c
48243@@ -9,6 +9,7 @@
48244 */
48245
48246 #include <linux/module.h>
48247+#include <linux/moduleloader.h>
48248 #include <linux/kernel.h>
48249 #include <linux/errno.h>
48250 #include <linux/string.h>
48251@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
48252 static int vram_total __initdata; /* Set total amount of memory */
48253 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
48254 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
48255-static void (*pmi_start)(void) __read_mostly;
48256-static void (*pmi_pal) (void) __read_mostly;
48257+static void (*pmi_start)(void) __read_only;
48258+static void (*pmi_pal) (void) __read_only;
48259 static int depth __read_mostly;
48260 static int vga_compat __read_mostly;
48261 /* --------------------------------------------------------------------- */
48262@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
48263 unsigned int size_vmode;
48264 unsigned int size_remap;
48265 unsigned int size_total;
48266+ void *pmi_code = NULL;
48267
48268 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
48269 return -ENODEV;
48270@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
48271 size_remap = size_total;
48272 vesafb_fix.smem_len = size_remap;
48273
48274-#ifndef __i386__
48275- screen_info.vesapm_seg = 0;
48276-#endif
48277-
48278 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
48279 printk(KERN_WARNING
48280 "vesafb: cannot reserve video memory at 0x%lx\n",
48281@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
48282 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
48283 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
48284
48285+#ifdef __i386__
48286+
48287+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48288+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
48289+ if (!pmi_code)
48290+#elif !defined(CONFIG_PAX_KERNEXEC)
48291+ if (0)
48292+#endif
48293+
48294+#endif
48295+ screen_info.vesapm_seg = 0;
48296+
48297 if (screen_info.vesapm_seg) {
48298- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
48299- screen_info.vesapm_seg,screen_info.vesapm_off);
48300+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
48301+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
48302 }
48303
48304 if (screen_info.vesapm_seg < 0xc000)
48305@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
48306
48307 if (ypan || pmi_setpal) {
48308 unsigned short *pmi_base;
48309+
48310 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
48311- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
48312- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
48313+
48314+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48315+ pax_open_kernel();
48316+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
48317+#else
48318+ pmi_code = pmi_base;
48319+#endif
48320+
48321+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
48322+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
48323+
48324+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48325+ pmi_start = ktva_ktla(pmi_start);
48326+ pmi_pal = ktva_ktla(pmi_pal);
48327+ pax_close_kernel();
48328+#endif
48329+
48330 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
48331 if (pmi_base[3]) {
48332 printk(KERN_INFO "vesafb: pmi: ports = ");
48333@@ -472,8 +498,11 @@ static int __init vesafb_probe(struct platform_device *dev)
48334 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
48335 (ypan ? FBINFO_HWACCEL_YPAN : 0);
48336
48337- if (!ypan)
48338- info->fbops->fb_pan_display = NULL;
48339+ if (!ypan) {
48340+ pax_open_kernel();
48341+ *(void **)&info->fbops->fb_pan_display = NULL;
48342+ pax_close_kernel();
48343+ }
48344
48345 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
48346 err = -ENOMEM;
48347@@ -488,6 +517,11 @@ static int __init vesafb_probe(struct platform_device *dev)
48348 info->node, info->fix.id);
48349 return 0;
48350 err:
48351+
48352+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48353+ module_free_exec(NULL, pmi_code);
48354+#endif
48355+
48356 if (info->screen_base)
48357 iounmap(info->screen_base);
48358 framebuffer_release(info);
48359diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
48360index 88714ae..16c2e11 100644
48361--- a/drivers/video/via/via_clock.h
48362+++ b/drivers/video/via/via_clock.h
48363@@ -56,7 +56,7 @@ struct via_clock {
48364
48365 void (*set_engine_pll_state)(u8 state);
48366 void (*set_engine_pll)(struct via_pll_config config);
48367-};
48368+} __no_const;
48369
48370
48371 static inline u32 get_pll_internal_frequency(u32 ref_freq,
48372diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
48373index fef20db..d28b1ab 100644
48374--- a/drivers/xen/xenfs/xenstored.c
48375+++ b/drivers/xen/xenfs/xenstored.c
48376@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
48377 static int xsd_kva_open(struct inode *inode, struct file *file)
48378 {
48379 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
48380+#ifdef CONFIG_GRKERNSEC_HIDESYM
48381+ NULL);
48382+#else
48383 xen_store_interface);
48384+#endif
48385+
48386 if (!file->private_data)
48387 return -ENOMEM;
48388 return 0;
48389diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
48390index 890bed5..17ae73e 100644
48391--- a/fs/9p/vfs_inode.c
48392+++ b/fs/9p/vfs_inode.c
48393@@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
48394 void
48395 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
48396 {
48397- char *s = nd_get_link(nd);
48398+ const char *s = nd_get_link(nd);
48399
48400 p9_debug(P9_DEBUG_VFS, " %s %s\n",
48401 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
48402diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
48403index 0efd152..b5802ad 100644
48404--- a/fs/Kconfig.binfmt
48405+++ b/fs/Kconfig.binfmt
48406@@ -89,7 +89,7 @@ config HAVE_AOUT
48407
48408 config BINFMT_AOUT
48409 tristate "Kernel support for a.out and ECOFF binaries"
48410- depends on HAVE_AOUT
48411+ depends on HAVE_AOUT && BROKEN
48412 ---help---
48413 A.out (Assembler.OUTput) is a set of formats for libraries and
48414 executables used in the earliest versions of UNIX. Linux used
48415diff --git a/fs/aio.c b/fs/aio.c
48416index 71f613c..9d01f1f 100644
48417--- a/fs/aio.c
48418+++ b/fs/aio.c
48419@@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
48420 size += sizeof(struct io_event) * nr_events;
48421 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
48422
48423- if (nr_pages < 0)
48424+ if (nr_pages <= 0)
48425 return -EINVAL;
48426
48427 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
48428@@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
48429 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
48430 {
48431 ssize_t ret;
48432+ struct iovec iovstack;
48433
48434 #ifdef CONFIG_COMPAT
48435 if (compat)
48436 ret = compat_rw_copy_check_uvector(type,
48437 (struct compat_iovec __user *)kiocb->ki_buf,
48438- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
48439+ kiocb->ki_nbytes, 1, &iovstack,
48440 &kiocb->ki_iovec);
48441 else
48442 #endif
48443 ret = rw_copy_check_uvector(type,
48444 (struct iovec __user *)kiocb->ki_buf,
48445- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
48446+ kiocb->ki_nbytes, 1, &iovstack,
48447 &kiocb->ki_iovec);
48448 if (ret < 0)
48449 goto out;
48450@@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
48451 if (ret < 0)
48452 goto out;
48453
48454+ if (kiocb->ki_iovec == &iovstack) {
48455+ kiocb->ki_inline_vec = iovstack;
48456+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
48457+ }
48458 kiocb->ki_nr_segs = kiocb->ki_nbytes;
48459 kiocb->ki_cur_seg = 0;
48460 /* ki_nbytes/left now reflect bytes instead of segs */
48461diff --git a/fs/attr.c b/fs/attr.c
48462index 1449adb..a2038c2 100644
48463--- a/fs/attr.c
48464+++ b/fs/attr.c
48465@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
48466 unsigned long limit;
48467
48468 limit = rlimit(RLIMIT_FSIZE);
48469+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
48470 if (limit != RLIM_INFINITY && offset > limit)
48471 goto out_sig;
48472 if (offset > inode->i_sb->s_maxbytes)
48473diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
48474index 03bc1d3..6205356 100644
48475--- a/fs/autofs4/waitq.c
48476+++ b/fs/autofs4/waitq.c
48477@@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
48478 {
48479 unsigned long sigpipe, flags;
48480 mm_segment_t fs;
48481- const char *data = (const char *)addr;
48482+ const char __user *data = (const char __force_user *)addr;
48483 ssize_t wr = 0;
48484
48485 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
48486@@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
48487 return 1;
48488 }
48489
48490+#ifdef CONFIG_GRKERNSEC_HIDESYM
48491+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
48492+#endif
48493+
48494 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
48495 enum autofs_notify notify)
48496 {
48497@@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
48498
48499 /* If this is a direct mount request create a dummy name */
48500 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
48501+#ifdef CONFIG_GRKERNSEC_HIDESYM
48502+ /* this name does get written to userland via autofs4_write() */
48503+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
48504+#else
48505 qstr.len = sprintf(name, "%p", dentry);
48506+#endif
48507 else {
48508 qstr.len = autofs4_getpath(sbi, dentry, &name);
48509 if (!qstr.len) {
48510diff --git a/fs/befs/endian.h b/fs/befs/endian.h
48511index 2722387..c8dd2a7 100644
48512--- a/fs/befs/endian.h
48513+++ b/fs/befs/endian.h
48514@@ -11,7 +11,7 @@
48515
48516 #include <asm/byteorder.h>
48517
48518-static inline u64
48519+static inline u64 __intentional_overflow(-1)
48520 fs64_to_cpu(const struct super_block *sb, fs64 n)
48521 {
48522 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
48523@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
48524 return (__force fs64)cpu_to_be64(n);
48525 }
48526
48527-static inline u32
48528+static inline u32 __intentional_overflow(-1)
48529 fs32_to_cpu(const struct super_block *sb, fs32 n)
48530 {
48531 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
48532diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
48533index 2b3bda8..6a2d4be 100644
48534--- a/fs/befs/linuxvfs.c
48535+++ b/fs/befs/linuxvfs.c
48536@@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
48537 {
48538 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
48539 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
48540- char *link = nd_get_link(nd);
48541+ const char *link = nd_get_link(nd);
48542 if (!IS_ERR(link))
48543 kfree(link);
48544 }
48545diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
48546index 6043567..16a9239 100644
48547--- a/fs/binfmt_aout.c
48548+++ b/fs/binfmt_aout.c
48549@@ -16,6 +16,7 @@
48550 #include <linux/string.h>
48551 #include <linux/fs.h>
48552 #include <linux/file.h>
48553+#include <linux/security.h>
48554 #include <linux/stat.h>
48555 #include <linux/fcntl.h>
48556 #include <linux/ptrace.h>
48557@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
48558 #endif
48559 # define START_STACK(u) ((void __user *)u.start_stack)
48560
48561+ memset(&dump, 0, sizeof(dump));
48562+
48563 fs = get_fs();
48564 set_fs(KERNEL_DS);
48565 has_dumped = 1;
48566@@ -70,10 +73,12 @@ static int aout_core_dump(struct coredump_params *cprm)
48567
48568 /* If the size of the dump file exceeds the rlimit, then see what would happen
48569 if we wrote the stack, but not the data area. */
48570+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
48571 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
48572 dump.u_dsize = 0;
48573
48574 /* Make sure we have enough room to write the stack and data areas. */
48575+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
48576 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
48577 dump.u_ssize = 0;
48578
48579@@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
48580 rlim = rlimit(RLIMIT_DATA);
48581 if (rlim >= RLIM_INFINITY)
48582 rlim = ~0;
48583+
48584+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
48585 if (ex.a_data + ex.a_bss > rlim)
48586 return -ENOMEM;
48587
48588@@ -268,6 +275,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
48589
48590 install_exec_creds(bprm);
48591
48592+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48593+ current->mm->pax_flags = 0UL;
48594+#endif
48595+
48596+#ifdef CONFIG_PAX_PAGEEXEC
48597+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
48598+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
48599+
48600+#ifdef CONFIG_PAX_EMUTRAMP
48601+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
48602+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
48603+#endif
48604+
48605+#ifdef CONFIG_PAX_MPROTECT
48606+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
48607+ current->mm->pax_flags |= MF_PAX_MPROTECT;
48608+#endif
48609+
48610+ }
48611+#endif
48612+
48613 if (N_MAGIC(ex) == OMAGIC) {
48614 unsigned long text_addr, map_size;
48615 loff_t pos;
48616@@ -333,7 +361,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
48617 }
48618
48619 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
48620- PROT_READ | PROT_WRITE | PROT_EXEC,
48621+ PROT_READ | PROT_WRITE,
48622 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
48623 fd_offset + ex.a_text);
48624 if (error != N_DATADDR(ex)) {
48625diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
48626index 0c42cdb..b62581e9 100644
48627--- a/fs/binfmt_elf.c
48628+++ b/fs/binfmt_elf.c
48629@@ -33,6 +33,7 @@
48630 #include <linux/elf.h>
48631 #include <linux/utsname.h>
48632 #include <linux/coredump.h>
48633+#include <linux/xattr.h>
48634 #include <asm/uaccess.h>
48635 #include <asm/param.h>
48636 #include <asm/page.h>
48637@@ -59,6 +60,10 @@ static int elf_core_dump(struct coredump_params *cprm);
48638 #define elf_core_dump NULL
48639 #endif
48640
48641+#ifdef CONFIG_PAX_MPROTECT
48642+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
48643+#endif
48644+
48645 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
48646 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
48647 #else
48648@@ -78,6 +83,11 @@ static struct linux_binfmt elf_format = {
48649 .load_binary = load_elf_binary,
48650 .load_shlib = load_elf_library,
48651 .core_dump = elf_core_dump,
48652+
48653+#ifdef CONFIG_PAX_MPROTECT
48654+ .handle_mprotect= elf_handle_mprotect,
48655+#endif
48656+
48657 .min_coredump = ELF_EXEC_PAGESIZE,
48658 };
48659
48660@@ -85,6 +95,8 @@ static struct linux_binfmt elf_format = {
48661
48662 static int set_brk(unsigned long start, unsigned long end)
48663 {
48664+ unsigned long e = end;
48665+
48666 start = ELF_PAGEALIGN(start);
48667 end = ELF_PAGEALIGN(end);
48668 if (end > start) {
48669@@ -93,7 +105,7 @@ static int set_brk(unsigned long start, unsigned long end)
48670 if (BAD_ADDR(addr))
48671 return addr;
48672 }
48673- current->mm->start_brk = current->mm->brk = end;
48674+ current->mm->start_brk = current->mm->brk = e;
48675 return 0;
48676 }
48677
48678@@ -154,12 +166,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
48679 elf_addr_t __user *u_rand_bytes;
48680 const char *k_platform = ELF_PLATFORM;
48681 const char *k_base_platform = ELF_BASE_PLATFORM;
48682- unsigned char k_rand_bytes[16];
48683+ u32 k_rand_bytes[4];
48684 int items;
48685 elf_addr_t *elf_info;
48686 int ei_index = 0;
48687 const struct cred *cred = current_cred();
48688 struct vm_area_struct *vma;
48689+ unsigned long saved_auxv[AT_VECTOR_SIZE];
48690
48691 /*
48692 * In some cases (e.g. Hyper-Threading), we want to avoid L1
48693@@ -201,8 +214,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
48694 * Generate 16 random bytes for userspace PRNG seeding.
48695 */
48696 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
48697- u_rand_bytes = (elf_addr_t __user *)
48698- STACK_ALLOC(p, sizeof(k_rand_bytes));
48699+ srandom32(k_rand_bytes[0] ^ random32());
48700+ srandom32(k_rand_bytes[1] ^ random32());
48701+ srandom32(k_rand_bytes[2] ^ random32());
48702+ srandom32(k_rand_bytes[3] ^ random32());
48703+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
48704+ u_rand_bytes = (elf_addr_t __user *) p;
48705 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
48706 return -EFAULT;
48707
48708@@ -314,9 +331,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
48709 return -EFAULT;
48710 current->mm->env_end = p;
48711
48712+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
48713+
48714 /* Put the elf_info on the stack in the right place. */
48715 sp = (elf_addr_t __user *)envp + 1;
48716- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
48717+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
48718 return -EFAULT;
48719 return 0;
48720 }
48721@@ -380,15 +399,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
48722 an ELF header */
48723
48724 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48725- struct file *interpreter, unsigned long *interp_map_addr,
48726- unsigned long no_base)
48727+ struct file *interpreter, unsigned long no_base)
48728 {
48729 struct elf_phdr *elf_phdata;
48730 struct elf_phdr *eppnt;
48731- unsigned long load_addr = 0;
48732+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
48733 int load_addr_set = 0;
48734 unsigned long last_bss = 0, elf_bss = 0;
48735- unsigned long error = ~0UL;
48736+ unsigned long error = -EINVAL;
48737 unsigned long total_size;
48738 int retval, i, size;
48739
48740@@ -434,6 +452,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48741 goto out_close;
48742 }
48743
48744+#ifdef CONFIG_PAX_SEGMEXEC
48745+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
48746+ pax_task_size = SEGMEXEC_TASK_SIZE;
48747+#endif
48748+
48749 eppnt = elf_phdata;
48750 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
48751 if (eppnt->p_type == PT_LOAD) {
48752@@ -457,8 +480,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48753 map_addr = elf_map(interpreter, load_addr + vaddr,
48754 eppnt, elf_prot, elf_type, total_size);
48755 total_size = 0;
48756- if (!*interp_map_addr)
48757- *interp_map_addr = map_addr;
48758 error = map_addr;
48759 if (BAD_ADDR(map_addr))
48760 goto out_close;
48761@@ -477,8 +498,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48762 k = load_addr + eppnt->p_vaddr;
48763 if (BAD_ADDR(k) ||
48764 eppnt->p_filesz > eppnt->p_memsz ||
48765- eppnt->p_memsz > TASK_SIZE ||
48766- TASK_SIZE - eppnt->p_memsz < k) {
48767+ eppnt->p_memsz > pax_task_size ||
48768+ pax_task_size - eppnt->p_memsz < k) {
48769 error = -ENOMEM;
48770 goto out_close;
48771 }
48772@@ -530,6 +551,315 @@ out:
48773 return error;
48774 }
48775
48776+#ifdef CONFIG_PAX_PT_PAX_FLAGS
48777+#ifdef CONFIG_PAX_SOFTMODE
48778+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
48779+{
48780+ unsigned long pax_flags = 0UL;
48781+
48782+#ifdef CONFIG_PAX_PAGEEXEC
48783+ if (elf_phdata->p_flags & PF_PAGEEXEC)
48784+ pax_flags |= MF_PAX_PAGEEXEC;
48785+#endif
48786+
48787+#ifdef CONFIG_PAX_SEGMEXEC
48788+ if (elf_phdata->p_flags & PF_SEGMEXEC)
48789+ pax_flags |= MF_PAX_SEGMEXEC;
48790+#endif
48791+
48792+#ifdef CONFIG_PAX_EMUTRAMP
48793+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
48794+ pax_flags |= MF_PAX_EMUTRAMP;
48795+#endif
48796+
48797+#ifdef CONFIG_PAX_MPROTECT
48798+ if (elf_phdata->p_flags & PF_MPROTECT)
48799+ pax_flags |= MF_PAX_MPROTECT;
48800+#endif
48801+
48802+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48803+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
48804+ pax_flags |= MF_PAX_RANDMMAP;
48805+#endif
48806+
48807+ return pax_flags;
48808+}
48809+#endif
48810+
48811+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
48812+{
48813+ unsigned long pax_flags = 0UL;
48814+
48815+#ifdef CONFIG_PAX_PAGEEXEC
48816+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
48817+ pax_flags |= MF_PAX_PAGEEXEC;
48818+#endif
48819+
48820+#ifdef CONFIG_PAX_SEGMEXEC
48821+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
48822+ pax_flags |= MF_PAX_SEGMEXEC;
48823+#endif
48824+
48825+#ifdef CONFIG_PAX_EMUTRAMP
48826+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
48827+ pax_flags |= MF_PAX_EMUTRAMP;
48828+#endif
48829+
48830+#ifdef CONFIG_PAX_MPROTECT
48831+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
48832+ pax_flags |= MF_PAX_MPROTECT;
48833+#endif
48834+
48835+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48836+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
48837+ pax_flags |= MF_PAX_RANDMMAP;
48838+#endif
48839+
48840+ return pax_flags;
48841+}
48842+#endif
48843+
48844+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
48845+#ifdef CONFIG_PAX_SOFTMODE
48846+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
48847+{
48848+ unsigned long pax_flags = 0UL;
48849+
48850+#ifdef CONFIG_PAX_PAGEEXEC
48851+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
48852+ pax_flags |= MF_PAX_PAGEEXEC;
48853+#endif
48854+
48855+#ifdef CONFIG_PAX_SEGMEXEC
48856+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
48857+ pax_flags |= MF_PAX_SEGMEXEC;
48858+#endif
48859+
48860+#ifdef CONFIG_PAX_EMUTRAMP
48861+ if (pax_flags_softmode & MF_PAX_EMUTRAMP)
48862+ pax_flags |= MF_PAX_EMUTRAMP;
48863+#endif
48864+
48865+#ifdef CONFIG_PAX_MPROTECT
48866+ if (pax_flags_softmode & MF_PAX_MPROTECT)
48867+ pax_flags |= MF_PAX_MPROTECT;
48868+#endif
48869+
48870+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48871+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
48872+ pax_flags |= MF_PAX_RANDMMAP;
48873+#endif
48874+
48875+ return pax_flags;
48876+}
48877+#endif
48878+
48879+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
48880+{
48881+ unsigned long pax_flags = 0UL;
48882+
48883+#ifdef CONFIG_PAX_PAGEEXEC
48884+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
48885+ pax_flags |= MF_PAX_PAGEEXEC;
48886+#endif
48887+
48888+#ifdef CONFIG_PAX_SEGMEXEC
48889+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
48890+ pax_flags |= MF_PAX_SEGMEXEC;
48891+#endif
48892+
48893+#ifdef CONFIG_PAX_EMUTRAMP
48894+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
48895+ pax_flags |= MF_PAX_EMUTRAMP;
48896+#endif
48897+
48898+#ifdef CONFIG_PAX_MPROTECT
48899+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
48900+ pax_flags |= MF_PAX_MPROTECT;
48901+#endif
48902+
48903+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48904+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
48905+ pax_flags |= MF_PAX_RANDMMAP;
48906+#endif
48907+
48908+ return pax_flags;
48909+}
48910+#endif
48911+
48912+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48913+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
48914+{
48915+ unsigned long pax_flags = 0UL;
48916+
48917+#ifdef CONFIG_PAX_EI_PAX
48918+
48919+#ifdef CONFIG_PAX_PAGEEXEC
48920+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
48921+ pax_flags |= MF_PAX_PAGEEXEC;
48922+#endif
48923+
48924+#ifdef CONFIG_PAX_SEGMEXEC
48925+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
48926+ pax_flags |= MF_PAX_SEGMEXEC;
48927+#endif
48928+
48929+#ifdef CONFIG_PAX_EMUTRAMP
48930+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
48931+ pax_flags |= MF_PAX_EMUTRAMP;
48932+#endif
48933+
48934+#ifdef CONFIG_PAX_MPROTECT
48935+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
48936+ pax_flags |= MF_PAX_MPROTECT;
48937+#endif
48938+
48939+#ifdef CONFIG_PAX_ASLR
48940+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
48941+ pax_flags |= MF_PAX_RANDMMAP;
48942+#endif
48943+
48944+#else
48945+
48946+#ifdef CONFIG_PAX_PAGEEXEC
48947+ pax_flags |= MF_PAX_PAGEEXEC;
48948+#endif
48949+
48950+#ifdef CONFIG_PAX_SEGMEXEC
48951+ pax_flags |= MF_PAX_SEGMEXEC;
48952+#endif
48953+
48954+#ifdef CONFIG_PAX_MPROTECT
48955+ pax_flags |= MF_PAX_MPROTECT;
48956+#endif
48957+
48958+#ifdef CONFIG_PAX_RANDMMAP
48959+ if (randomize_va_space)
48960+ pax_flags |= MF_PAX_RANDMMAP;
48961+#endif
48962+
48963+#endif
48964+
48965+ return pax_flags;
48966+}
48967+
48968+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
48969+{
48970+
48971+#ifdef CONFIG_PAX_PT_PAX_FLAGS
48972+ unsigned long i;
48973+
48974+ for (i = 0UL; i < elf_ex->e_phnum; i++)
48975+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
48976+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
48977+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
48978+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
48979+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
48980+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
48981+ return ~0UL;
48982+
48983+#ifdef CONFIG_PAX_SOFTMODE
48984+ if (pax_softmode)
48985+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
48986+ else
48987+#endif
48988+
48989+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
48990+ break;
48991+ }
48992+#endif
48993+
48994+ return ~0UL;
48995+}
48996+
48997+static unsigned long pax_parse_xattr_pax(struct file * const file)
48998+{
48999+
49000+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
49001+ ssize_t xattr_size, i;
49002+ unsigned char xattr_value[5];
49003+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
49004+
49005+ xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
49006+ if (xattr_size <= 0 || xattr_size > 5)
49007+ return ~0UL;
49008+
49009+ for (i = 0; i < xattr_size; i++)
49010+ switch (xattr_value[i]) {
49011+ default:
49012+ return ~0UL;
49013+
49014+#define parse_flag(option1, option2, flag) \
49015+ case option1: \
49016+ if (pax_flags_hardmode & MF_PAX_##flag) \
49017+ return ~0UL; \
49018+ pax_flags_hardmode |= MF_PAX_##flag; \
49019+ break; \
49020+ case option2: \
49021+ if (pax_flags_softmode & MF_PAX_##flag) \
49022+ return ~0UL; \
49023+ pax_flags_softmode |= MF_PAX_##flag; \
49024+ break;
49025+
49026+ parse_flag('p', 'P', PAGEEXEC);
49027+ parse_flag('e', 'E', EMUTRAMP);
49028+ parse_flag('m', 'M', MPROTECT);
49029+ parse_flag('r', 'R', RANDMMAP);
49030+ parse_flag('s', 'S', SEGMEXEC);
49031+
49032+#undef parse_flag
49033+ }
49034+
49035+ if (pax_flags_hardmode & pax_flags_softmode)
49036+ return ~0UL;
49037+
49038+#ifdef CONFIG_PAX_SOFTMODE
49039+ if (pax_softmode)
49040+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
49041+ else
49042+#endif
49043+
49044+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
49045+#else
49046+ return ~0UL;
49047+#endif
49048+
49049+}
49050+
49051+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
49052+{
49053+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
49054+
49055+ pax_flags = pax_parse_ei_pax(elf_ex);
49056+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
49057+ xattr_pax_flags = pax_parse_xattr_pax(file);
49058+
49059+ if (pt_pax_flags == ~0UL)
49060+ pt_pax_flags = xattr_pax_flags;
49061+ else if (xattr_pax_flags == ~0UL)
49062+ xattr_pax_flags = pt_pax_flags;
49063+ if (pt_pax_flags != xattr_pax_flags)
49064+ return -EINVAL;
49065+ if (pt_pax_flags != ~0UL)
49066+ pax_flags = pt_pax_flags;
49067+
49068+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
49069+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
49070+ if ((__supported_pte_mask & _PAGE_NX))
49071+ pax_flags &= ~MF_PAX_SEGMEXEC;
49072+ else
49073+ pax_flags &= ~MF_PAX_PAGEEXEC;
49074+ }
49075+#endif
49076+
49077+ if (0 > pax_check_flags(&pax_flags))
49078+ return -EINVAL;
49079+
49080+ current->mm->pax_flags = pax_flags;
49081+ return 0;
49082+}
49083+#endif
49084+
49085 /*
49086 * These are the functions used to load ELF style executables and shared
49087 * libraries. There is no binary dependent code anywhere else.
49088@@ -546,6 +876,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
49089 {
49090 unsigned int random_variable = 0;
49091
49092+#ifdef CONFIG_PAX_RANDUSTACK
49093+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
49094+ return stack_top - current->mm->delta_stack;
49095+#endif
49096+
49097 if ((current->flags & PF_RANDOMIZE) &&
49098 !(current->personality & ADDR_NO_RANDOMIZE)) {
49099 random_variable = get_random_int() & STACK_RND_MASK;
49100@@ -564,7 +899,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
49101 unsigned long load_addr = 0, load_bias = 0;
49102 int load_addr_set = 0;
49103 char * elf_interpreter = NULL;
49104- unsigned long error;
49105+ unsigned long error = 0;
49106 struct elf_phdr *elf_ppnt, *elf_phdata;
49107 unsigned long elf_bss, elf_brk;
49108 int retval, i;
49109@@ -574,12 +909,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
49110 unsigned long start_code, end_code, start_data, end_data;
49111 unsigned long reloc_func_desc __maybe_unused = 0;
49112 int executable_stack = EXSTACK_DEFAULT;
49113- unsigned long def_flags = 0;
49114 struct pt_regs *regs = current_pt_regs();
49115 struct {
49116 struct elfhdr elf_ex;
49117 struct elfhdr interp_elf_ex;
49118 } *loc;
49119+ unsigned long pax_task_size = TASK_SIZE;
49120
49121 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
49122 if (!loc) {
49123@@ -715,11 +1050,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
49124 goto out_free_dentry;
49125
49126 /* OK, This is the point of no return */
49127- current->mm->def_flags = def_flags;
49128+
49129+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49130+ current->mm->pax_flags = 0UL;
49131+#endif
49132+
49133+#ifdef CONFIG_PAX_DLRESOLVE
49134+ current->mm->call_dl_resolve = 0UL;
49135+#endif
49136+
49137+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
49138+ current->mm->call_syscall = 0UL;
49139+#endif
49140+
49141+#ifdef CONFIG_PAX_ASLR
49142+ current->mm->delta_mmap = 0UL;
49143+ current->mm->delta_stack = 0UL;
49144+#endif
49145+
49146+ current->mm->def_flags = 0;
49147+
49148+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49149+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
49150+ send_sig(SIGKILL, current, 0);
49151+ goto out_free_dentry;
49152+ }
49153+#endif
49154+
49155+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
49156+ pax_set_initial_flags(bprm);
49157+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
49158+ if (pax_set_initial_flags_func)
49159+ (pax_set_initial_flags_func)(bprm);
49160+#endif
49161+
49162+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49163+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
49164+ current->mm->context.user_cs_limit = PAGE_SIZE;
49165+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
49166+ }
49167+#endif
49168+
49169+#ifdef CONFIG_PAX_SEGMEXEC
49170+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
49171+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
49172+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
49173+ pax_task_size = SEGMEXEC_TASK_SIZE;
49174+ current->mm->def_flags |= VM_NOHUGEPAGE;
49175+ }
49176+#endif
49177+
49178+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
49179+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
49180+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
49181+ put_cpu();
49182+ }
49183+#endif
49184
49185 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
49186 may depend on the personality. */
49187 SET_PERSONALITY(loc->elf_ex);
49188+
49189+#ifdef CONFIG_PAX_ASLR
49190+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
49191+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
49192+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
49193+ }
49194+#endif
49195+
49196+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
49197+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
49198+ executable_stack = EXSTACK_DISABLE_X;
49199+ current->personality &= ~READ_IMPLIES_EXEC;
49200+ } else
49201+#endif
49202+
49203 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
49204 current->personality |= READ_IMPLIES_EXEC;
49205
49206@@ -810,6 +1215,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
49207 #else
49208 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
49209 #endif
49210+
49211+#ifdef CONFIG_PAX_RANDMMAP
49212+ /* PaX: randomize base address at the default exe base if requested */
49213+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
49214+#ifdef CONFIG_SPARC64
49215+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
49216+#else
49217+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
49218+#endif
49219+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
49220+ elf_flags |= MAP_FIXED;
49221+ }
49222+#endif
49223+
49224 }
49225
49226 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
49227@@ -842,9 +1261,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
49228 * allowed task size. Note that p_filesz must always be
49229 * <= p_memsz so it is only necessary to check p_memsz.
49230 */
49231- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
49232- elf_ppnt->p_memsz > TASK_SIZE ||
49233- TASK_SIZE - elf_ppnt->p_memsz < k) {
49234+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
49235+ elf_ppnt->p_memsz > pax_task_size ||
49236+ pax_task_size - elf_ppnt->p_memsz < k) {
49237 /* set_brk can never work. Avoid overflows. */
49238 send_sig(SIGKILL, current, 0);
49239 retval = -EINVAL;
49240@@ -883,17 +1302,44 @@ static int load_elf_binary(struct linux_binprm *bprm)
49241 goto out_free_dentry;
49242 }
49243 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
49244- send_sig(SIGSEGV, current, 0);
49245- retval = -EFAULT; /* Nobody gets to see this, but.. */
49246- goto out_free_dentry;
49247+ /*
49248+ * This bss-zeroing can fail if the ELF
49249+ * file specifies odd protections. So
49250+ * we don't check the return value
49251+ */
49252 }
49253
49254+#ifdef CONFIG_PAX_RANDMMAP
49255+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
49256+ unsigned long start, size, flags, vm_flags;
49257+
49258+ start = ELF_PAGEALIGN(elf_brk);
49259+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
49260+ flags = MAP_FIXED | MAP_PRIVATE;
49261+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
49262+
49263+ down_write(&current->mm->mmap_sem);
49264+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
49265+ retval = -ENOMEM;
49266+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
49267+// if (current->personality & ADDR_NO_RANDOMIZE)
49268+// vm_flags |= VM_READ | VM_MAYREAD;
49269+ start = mmap_region(NULL, start, PAGE_ALIGN(size), flags, vm_flags, 0);
49270+ retval = IS_ERR_VALUE(start) ? start : 0;
49271+ }
49272+ up_write(&current->mm->mmap_sem);
49273+ if (retval == 0)
49274+ retval = set_brk(start + size, start + size + PAGE_SIZE);
49275+ if (retval < 0) {
49276+ send_sig(SIGKILL, current, 0);
49277+ goto out_free_dentry;
49278+ }
49279+ }
49280+#endif
49281+
49282 if (elf_interpreter) {
49283- unsigned long interp_map_addr = 0;
49284-
49285 elf_entry = load_elf_interp(&loc->interp_elf_ex,
49286 interpreter,
49287- &interp_map_addr,
49288 load_bias);
49289 if (!IS_ERR((void *)elf_entry)) {
49290 /*
49291@@ -1115,7 +1561,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
49292 * Decide what to dump of a segment, part, all or none.
49293 */
49294 static unsigned long vma_dump_size(struct vm_area_struct *vma,
49295- unsigned long mm_flags)
49296+ unsigned long mm_flags, long signr)
49297 {
49298 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
49299
49300@@ -1152,7 +1598,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
49301 if (vma->vm_file == NULL)
49302 return 0;
49303
49304- if (FILTER(MAPPED_PRIVATE))
49305+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
49306 goto whole;
49307
49308 /*
49309@@ -1374,9 +1820,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
49310 {
49311 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
49312 int i = 0;
49313- do
49314+ do {
49315 i += 2;
49316- while (auxv[i - 2] != AT_NULL);
49317+ } while (auxv[i - 2] != AT_NULL);
49318 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
49319 }
49320
49321@@ -2006,14 +2452,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
49322 }
49323
49324 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
49325- unsigned long mm_flags)
49326+ struct coredump_params *cprm)
49327 {
49328 struct vm_area_struct *vma;
49329 size_t size = 0;
49330
49331 for (vma = first_vma(current, gate_vma); vma != NULL;
49332 vma = next_vma(vma, gate_vma))
49333- size += vma_dump_size(vma, mm_flags);
49334+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
49335 return size;
49336 }
49337
49338@@ -2107,7 +2553,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49339
49340 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
49341
49342- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
49343+ offset += elf_core_vma_data_size(gate_vma, cprm);
49344 offset += elf_core_extra_data_size();
49345 e_shoff = offset;
49346
49347@@ -2121,10 +2567,12 @@ static int elf_core_dump(struct coredump_params *cprm)
49348 offset = dataoff;
49349
49350 size += sizeof(*elf);
49351+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49352 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
49353 goto end_coredump;
49354
49355 size += sizeof(*phdr4note);
49356+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49357 if (size > cprm->limit
49358 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
49359 goto end_coredump;
49360@@ -2138,7 +2586,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49361 phdr.p_offset = offset;
49362 phdr.p_vaddr = vma->vm_start;
49363 phdr.p_paddr = 0;
49364- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
49365+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
49366 phdr.p_memsz = vma->vm_end - vma->vm_start;
49367 offset += phdr.p_filesz;
49368 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
49369@@ -2149,6 +2597,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49370 phdr.p_align = ELF_EXEC_PAGESIZE;
49371
49372 size += sizeof(phdr);
49373+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49374 if (size > cprm->limit
49375 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
49376 goto end_coredump;
49377@@ -2173,7 +2622,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49378 unsigned long addr;
49379 unsigned long end;
49380
49381- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
49382+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
49383
49384 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
49385 struct page *page;
49386@@ -2182,6 +2631,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49387 page = get_dump_page(addr);
49388 if (page) {
49389 void *kaddr = kmap(page);
49390+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
49391 stop = ((size += PAGE_SIZE) > cprm->limit) ||
49392 !dump_write(cprm->file, kaddr,
49393 PAGE_SIZE);
49394@@ -2199,6 +2649,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49395
49396 if (e_phnum == PN_XNUM) {
49397 size += sizeof(*shdr4extnum);
49398+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49399 if (size > cprm->limit
49400 || !dump_write(cprm->file, shdr4extnum,
49401 sizeof(*shdr4extnum)))
49402@@ -2219,6 +2670,97 @@ out:
49403
49404 #endif /* CONFIG_ELF_CORE */
49405
49406+#ifdef CONFIG_PAX_MPROTECT
49407+/* PaX: non-PIC ELF libraries need relocations on their executable segments
49408+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
49409+ * we'll remove VM_MAYWRITE for good on RELRO segments.
49410+ *
49411+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
49412+ * basis because we want to allow the common case and not the special ones.
49413+ */
49414+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
49415+{
49416+ struct elfhdr elf_h;
49417+ struct elf_phdr elf_p;
49418+ unsigned long i;
49419+ unsigned long oldflags;
49420+ bool is_textrel_rw, is_textrel_rx, is_relro;
49421+
49422+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
49423+ return;
49424+
49425+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
49426+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
49427+
49428+#ifdef CONFIG_PAX_ELFRELOCS
49429+ /* possible TEXTREL */
49430+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
49431+ 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);
49432+#else
49433+ is_textrel_rw = false;
49434+ is_textrel_rx = false;
49435+#endif
49436+
49437+ /* possible RELRO */
49438+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
49439+
49440+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
49441+ return;
49442+
49443+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
49444+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
49445+
49446+#ifdef CONFIG_PAX_ETEXECRELOCS
49447+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
49448+#else
49449+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
49450+#endif
49451+
49452+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
49453+ !elf_check_arch(&elf_h) ||
49454+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
49455+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
49456+ return;
49457+
49458+ for (i = 0UL; i < elf_h.e_phnum; i++) {
49459+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
49460+ return;
49461+ switch (elf_p.p_type) {
49462+ case PT_DYNAMIC:
49463+ if (!is_textrel_rw && !is_textrel_rx)
49464+ continue;
49465+ i = 0UL;
49466+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
49467+ elf_dyn dyn;
49468+
49469+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
49470+ return;
49471+ if (dyn.d_tag == DT_NULL)
49472+ return;
49473+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
49474+ gr_log_textrel(vma);
49475+ if (is_textrel_rw)
49476+ vma->vm_flags |= VM_MAYWRITE;
49477+ else
49478+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
49479+ vma->vm_flags &= ~VM_MAYWRITE;
49480+ return;
49481+ }
49482+ i++;
49483+ }
49484+ return;
49485+
49486+ case PT_GNU_RELRO:
49487+ if (!is_relro)
49488+ continue;
49489+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
49490+ vma->vm_flags &= ~VM_MAYWRITE;
49491+ return;
49492+ }
49493+ }
49494+}
49495+#endif
49496+
49497 static int __init init_elf_binfmt(void)
49498 {
49499 register_binfmt(&elf_format);
49500diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
49501index b563719..3868998 100644
49502--- a/fs/binfmt_flat.c
49503+++ b/fs/binfmt_flat.c
49504@@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
49505 realdatastart = (unsigned long) -ENOMEM;
49506 printk("Unable to allocate RAM for process data, errno %d\n",
49507 (int)-realdatastart);
49508+ down_write(&current->mm->mmap_sem);
49509 vm_munmap(textpos, text_len);
49510+ up_write(&current->mm->mmap_sem);
49511 ret = realdatastart;
49512 goto err;
49513 }
49514@@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
49515 }
49516 if (IS_ERR_VALUE(result)) {
49517 printk("Unable to read data+bss, errno %d\n", (int)-result);
49518+ down_write(&current->mm->mmap_sem);
49519 vm_munmap(textpos, text_len);
49520 vm_munmap(realdatastart, len);
49521+ up_write(&current->mm->mmap_sem);
49522 ret = result;
49523 goto err;
49524 }
49525@@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
49526 }
49527 if (IS_ERR_VALUE(result)) {
49528 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
49529+ down_write(&current->mm->mmap_sem);
49530 vm_munmap(textpos, text_len + data_len + extra +
49531 MAX_SHARED_LIBS * sizeof(unsigned long));
49532+ up_write(&current->mm->mmap_sem);
49533 ret = result;
49534 goto err;
49535 }
49536diff --git a/fs/bio.c b/fs/bio.c
49537index b96fc6c..431d628 100644
49538--- a/fs/bio.c
49539+++ b/fs/bio.c
49540@@ -818,7 +818,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
49541 /*
49542 * Overflow, abort
49543 */
49544- if (end < start)
49545+ if (end < start || end - start > INT_MAX - nr_pages)
49546 return ERR_PTR(-EINVAL);
49547
49548 nr_pages += end - start;
49549@@ -952,7 +952,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
49550 /*
49551 * Overflow, abort
49552 */
49553- if (end < start)
49554+ if (end < start || end - start > INT_MAX - nr_pages)
49555 return ERR_PTR(-EINVAL);
49556
49557 nr_pages += end - start;
49558@@ -1214,7 +1214,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
49559 const int read = bio_data_dir(bio) == READ;
49560 struct bio_map_data *bmd = bio->bi_private;
49561 int i;
49562- char *p = bmd->sgvecs[0].iov_base;
49563+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
49564
49565 __bio_for_each_segment(bvec, bio, i, 0) {
49566 char *addr = page_address(bvec->bv_page);
49567diff --git a/fs/block_dev.c b/fs/block_dev.c
49568index 883dc49..f27794a 100644
49569--- a/fs/block_dev.c
49570+++ b/fs/block_dev.c
49571@@ -652,7 +652,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
49572 else if (bdev->bd_contains == bdev)
49573 return true; /* is a whole device which isn't held */
49574
49575- else if (whole->bd_holder == bd_may_claim)
49576+ else if (whole->bd_holder == (void *)bd_may_claim)
49577 return true; /* is a partition of a device that is being partitioned */
49578 else if (whole->bd_holder != NULL)
49579 return false; /* is a partition of a held device */
49580diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
49581index ce1c169..1ef484f 100644
49582--- a/fs/btrfs/ctree.c
49583+++ b/fs/btrfs/ctree.c
49584@@ -1036,9 +1036,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
49585 free_extent_buffer(buf);
49586 add_root_to_dirty_list(root);
49587 } else {
49588- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
49589- parent_start = parent->start;
49590- else
49591+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
49592+ if (parent)
49593+ parent_start = parent->start;
49594+ else
49595+ parent_start = 0;
49596+ } else
49597 parent_start = 0;
49598
49599 WARN_ON(trans->transid != btrfs_header_generation(parent));
49600diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
49601index 7c4e6cc..27bd5c2 100644
49602--- a/fs/btrfs/inode.c
49603+++ b/fs/btrfs/inode.c
49604@@ -7314,7 +7314,7 @@ fail:
49605 return -ENOMEM;
49606 }
49607
49608-static int btrfs_getattr(struct vfsmount *mnt,
49609+int btrfs_getattr(struct vfsmount *mnt,
49610 struct dentry *dentry, struct kstat *stat)
49611 {
49612 struct inode *inode = dentry->d_inode;
49613@@ -7328,6 +7328,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
49614 return 0;
49615 }
49616
49617+EXPORT_SYMBOL(btrfs_getattr);
49618+
49619+dev_t get_btrfs_dev_from_inode(struct inode *inode)
49620+{
49621+ return BTRFS_I(inode)->root->anon_dev;
49622+}
49623+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
49624+
49625 /*
49626 * If a file is moved, it will inherit the cow and compression flags of the new
49627 * directory.
49628diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
49629index 338f259..b657640 100644
49630--- a/fs/btrfs/ioctl.c
49631+++ b/fs/btrfs/ioctl.c
49632@@ -3033,9 +3033,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
49633 for (i = 0; i < num_types; i++) {
49634 struct btrfs_space_info *tmp;
49635
49636+ /* Don't copy in more than we allocated */
49637 if (!slot_count)
49638 break;
49639
49640+ slot_count--;
49641+
49642 info = NULL;
49643 rcu_read_lock();
49644 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
49645@@ -3057,10 +3060,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
49646 memcpy(dest, &space, sizeof(space));
49647 dest++;
49648 space_args.total_spaces++;
49649- slot_count--;
49650 }
49651- if (!slot_count)
49652- break;
49653 }
49654 up_read(&info->groups_sem);
49655 }
49656diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
49657index 300e09a..9fe4539 100644
49658--- a/fs/btrfs/relocation.c
49659+++ b/fs/btrfs/relocation.c
49660@@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
49661 }
49662 spin_unlock(&rc->reloc_root_tree.lock);
49663
49664- BUG_ON((struct btrfs_root *)node->data != root);
49665+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
49666
49667 if (!del) {
49668 spin_lock(&rc->reloc_root_tree.lock);
49669diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
49670index d8982e9..29a85fa 100644
49671--- a/fs/btrfs/super.c
49672+++ b/fs/btrfs/super.c
49673@@ -267,7 +267,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
49674 function, line, errstr);
49675 return;
49676 }
49677- ACCESS_ONCE(trans->transaction->aborted) = errno;
49678+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
49679 __btrfs_std_error(root->fs_info, function, line, errno, NULL);
49680 }
49681 /*
49682diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
49683index 622f469..e8d2d55 100644
49684--- a/fs/cachefiles/bind.c
49685+++ b/fs/cachefiles/bind.c
49686@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
49687 args);
49688
49689 /* start by checking things over */
49690- ASSERT(cache->fstop_percent >= 0 &&
49691- cache->fstop_percent < cache->fcull_percent &&
49692+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
49693 cache->fcull_percent < cache->frun_percent &&
49694 cache->frun_percent < 100);
49695
49696- ASSERT(cache->bstop_percent >= 0 &&
49697- cache->bstop_percent < cache->bcull_percent &&
49698+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
49699 cache->bcull_percent < cache->brun_percent &&
49700 cache->brun_percent < 100);
49701
49702diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
49703index 0a1467b..6a53245 100644
49704--- a/fs/cachefiles/daemon.c
49705+++ b/fs/cachefiles/daemon.c
49706@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
49707 if (n > buflen)
49708 return -EMSGSIZE;
49709
49710- if (copy_to_user(_buffer, buffer, n) != 0)
49711+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
49712 return -EFAULT;
49713
49714 return n;
49715@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
49716 if (test_bit(CACHEFILES_DEAD, &cache->flags))
49717 return -EIO;
49718
49719- if (datalen < 0 || datalen > PAGE_SIZE - 1)
49720+ if (datalen > PAGE_SIZE - 1)
49721 return -EOPNOTSUPP;
49722
49723 /* drag the command string into the kernel so we can parse it */
49724@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
49725 if (args[0] != '%' || args[1] != '\0')
49726 return -EINVAL;
49727
49728- if (fstop < 0 || fstop >= cache->fcull_percent)
49729+ if (fstop >= cache->fcull_percent)
49730 return cachefiles_daemon_range_error(cache, args);
49731
49732 cache->fstop_percent = fstop;
49733@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
49734 if (args[0] != '%' || args[1] != '\0')
49735 return -EINVAL;
49736
49737- if (bstop < 0 || bstop >= cache->bcull_percent)
49738+ if (bstop >= cache->bcull_percent)
49739 return cachefiles_daemon_range_error(cache, args);
49740
49741 cache->bstop_percent = bstop;
49742diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
49743index 4938251..7e01445 100644
49744--- a/fs/cachefiles/internal.h
49745+++ b/fs/cachefiles/internal.h
49746@@ -59,7 +59,7 @@ struct cachefiles_cache {
49747 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
49748 struct rb_root active_nodes; /* active nodes (can't be culled) */
49749 rwlock_t active_lock; /* lock for active_nodes */
49750- atomic_t gravecounter; /* graveyard uniquifier */
49751+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
49752 unsigned frun_percent; /* when to stop culling (% files) */
49753 unsigned fcull_percent; /* when to start culling (% files) */
49754 unsigned fstop_percent; /* when to stop allocating (% files) */
49755@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
49756 * proc.c
49757 */
49758 #ifdef CONFIG_CACHEFILES_HISTOGRAM
49759-extern atomic_t cachefiles_lookup_histogram[HZ];
49760-extern atomic_t cachefiles_mkdir_histogram[HZ];
49761-extern atomic_t cachefiles_create_histogram[HZ];
49762+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
49763+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
49764+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
49765
49766 extern int __init cachefiles_proc_init(void);
49767 extern void cachefiles_proc_cleanup(void);
49768 static inline
49769-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
49770+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
49771 {
49772 unsigned long jif = jiffies - start_jif;
49773 if (jif >= HZ)
49774 jif = HZ - 1;
49775- atomic_inc(&histogram[jif]);
49776+ atomic_inc_unchecked(&histogram[jif]);
49777 }
49778
49779 #else
49780diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
49781index 8c01c5fc..15f982e 100644
49782--- a/fs/cachefiles/namei.c
49783+++ b/fs/cachefiles/namei.c
49784@@ -317,7 +317,7 @@ try_again:
49785 /* first step is to make up a grave dentry in the graveyard */
49786 sprintf(nbuffer, "%08x%08x",
49787 (uint32_t) get_seconds(),
49788- (uint32_t) atomic_inc_return(&cache->gravecounter));
49789+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
49790
49791 /* do the multiway lock magic */
49792 trap = lock_rename(cache->graveyard, dir);
49793diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
49794index eccd339..4c1d995 100644
49795--- a/fs/cachefiles/proc.c
49796+++ b/fs/cachefiles/proc.c
49797@@ -14,9 +14,9 @@
49798 #include <linux/seq_file.h>
49799 #include "internal.h"
49800
49801-atomic_t cachefiles_lookup_histogram[HZ];
49802-atomic_t cachefiles_mkdir_histogram[HZ];
49803-atomic_t cachefiles_create_histogram[HZ];
49804+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
49805+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
49806+atomic_unchecked_t cachefiles_create_histogram[HZ];
49807
49808 /*
49809 * display the latency histogram
49810@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
49811 return 0;
49812 default:
49813 index = (unsigned long) v - 3;
49814- x = atomic_read(&cachefiles_lookup_histogram[index]);
49815- y = atomic_read(&cachefiles_mkdir_histogram[index]);
49816- z = atomic_read(&cachefiles_create_histogram[index]);
49817+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
49818+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
49819+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
49820 if (x == 0 && y == 0 && z == 0)
49821 return 0;
49822
49823diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
49824index 4809922..aab2c39 100644
49825--- a/fs/cachefiles/rdwr.c
49826+++ b/fs/cachefiles/rdwr.c
49827@@ -965,7 +965,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
49828 old_fs = get_fs();
49829 set_fs(KERNEL_DS);
49830 ret = file->f_op->write(
49831- file, (const void __user *) data, len, &pos);
49832+ file, (const void __force_user *) data, len, &pos);
49833 set_fs(old_fs);
49834 kunmap(page);
49835 if (ret != len)
49836diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
49837index 8c1aabe..bbf856a 100644
49838--- a/fs/ceph/dir.c
49839+++ b/fs/ceph/dir.c
49840@@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
49841 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
49842 struct ceph_mds_client *mdsc = fsc->mdsc;
49843 unsigned frag = fpos_frag(filp->f_pos);
49844- int off = fpos_off(filp->f_pos);
49845+ unsigned int off = fpos_off(filp->f_pos);
49846 int err;
49847 u32 ftype;
49848 struct ceph_mds_reply_info_parsed *rinfo;
49849diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
49850index d9ea6ed..1e6c8ac 100644
49851--- a/fs/cifs/cifs_debug.c
49852+++ b/fs/cifs/cifs_debug.c
49853@@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
49854
49855 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
49856 #ifdef CONFIG_CIFS_STATS2
49857- atomic_set(&totBufAllocCount, 0);
49858- atomic_set(&totSmBufAllocCount, 0);
49859+ atomic_set_unchecked(&totBufAllocCount, 0);
49860+ atomic_set_unchecked(&totSmBufAllocCount, 0);
49861 #endif /* CONFIG_CIFS_STATS2 */
49862 spin_lock(&cifs_tcp_ses_lock);
49863 list_for_each(tmp1, &cifs_tcp_ses_list) {
49864@@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
49865 tcon = list_entry(tmp3,
49866 struct cifs_tcon,
49867 tcon_list);
49868- atomic_set(&tcon->num_smbs_sent, 0);
49869+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
49870 if (server->ops->clear_stats)
49871 server->ops->clear_stats(tcon);
49872 }
49873@@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
49874 smBufAllocCount.counter, cifs_min_small);
49875 #ifdef CONFIG_CIFS_STATS2
49876 seq_printf(m, "Total Large %d Small %d Allocations\n",
49877- atomic_read(&totBufAllocCount),
49878- atomic_read(&totSmBufAllocCount));
49879+ atomic_read_unchecked(&totBufAllocCount),
49880+ atomic_read_unchecked(&totSmBufAllocCount));
49881 #endif /* CONFIG_CIFS_STATS2 */
49882
49883 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
49884@@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
49885 if (tcon->need_reconnect)
49886 seq_puts(m, "\tDISCONNECTED ");
49887 seq_printf(m, "\nSMBs: %d",
49888- atomic_read(&tcon->num_smbs_sent));
49889+ atomic_read_unchecked(&tcon->num_smbs_sent));
49890 if (server->ops->print_stats)
49891 server->ops->print_stats(m, tcon);
49892 }
49893diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
49894index b9db388..9a73d6d 100644
49895--- a/fs/cifs/cifsfs.c
49896+++ b/fs/cifs/cifsfs.c
49897@@ -1026,7 +1026,7 @@ cifs_init_request_bufs(void)
49898 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
49899 cifs_req_cachep = kmem_cache_create("cifs_request",
49900 CIFSMaxBufSize + max_hdr_size, 0,
49901- SLAB_HWCACHE_ALIGN, NULL);
49902+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
49903 if (cifs_req_cachep == NULL)
49904 return -ENOMEM;
49905
49906@@ -1053,7 +1053,7 @@ cifs_init_request_bufs(void)
49907 efficient to alloc 1 per page off the slab compared to 17K (5page)
49908 alloc of large cifs buffers even when page debugging is on */
49909 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
49910- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
49911+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
49912 NULL);
49913 if (cifs_sm_req_cachep == NULL) {
49914 mempool_destroy(cifs_req_poolp);
49915@@ -1138,8 +1138,8 @@ init_cifs(void)
49916 atomic_set(&bufAllocCount, 0);
49917 atomic_set(&smBufAllocCount, 0);
49918 #ifdef CONFIG_CIFS_STATS2
49919- atomic_set(&totBufAllocCount, 0);
49920- atomic_set(&totSmBufAllocCount, 0);
49921+ atomic_set_unchecked(&totBufAllocCount, 0);
49922+ atomic_set_unchecked(&totSmBufAllocCount, 0);
49923 #endif /* CONFIG_CIFS_STATS2 */
49924
49925 atomic_set(&midCount, 0);
49926diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
49927index e6899ce..d6b2920 100644
49928--- a/fs/cifs/cifsglob.h
49929+++ b/fs/cifs/cifsglob.h
49930@@ -751,35 +751,35 @@ struct cifs_tcon {
49931 __u16 Flags; /* optional support bits */
49932 enum statusEnum tidStatus;
49933 #ifdef CONFIG_CIFS_STATS
49934- atomic_t num_smbs_sent;
49935+ atomic_unchecked_t num_smbs_sent;
49936 union {
49937 struct {
49938- atomic_t num_writes;
49939- atomic_t num_reads;
49940- atomic_t num_flushes;
49941- atomic_t num_oplock_brks;
49942- atomic_t num_opens;
49943- atomic_t num_closes;
49944- atomic_t num_deletes;
49945- atomic_t num_mkdirs;
49946- atomic_t num_posixopens;
49947- atomic_t num_posixmkdirs;
49948- atomic_t num_rmdirs;
49949- atomic_t num_renames;
49950- atomic_t num_t2renames;
49951- atomic_t num_ffirst;
49952- atomic_t num_fnext;
49953- atomic_t num_fclose;
49954- atomic_t num_hardlinks;
49955- atomic_t num_symlinks;
49956- atomic_t num_locks;
49957- atomic_t num_acl_get;
49958- atomic_t num_acl_set;
49959+ atomic_unchecked_t num_writes;
49960+ atomic_unchecked_t num_reads;
49961+ atomic_unchecked_t num_flushes;
49962+ atomic_unchecked_t num_oplock_brks;
49963+ atomic_unchecked_t num_opens;
49964+ atomic_unchecked_t num_closes;
49965+ atomic_unchecked_t num_deletes;
49966+ atomic_unchecked_t num_mkdirs;
49967+ atomic_unchecked_t num_posixopens;
49968+ atomic_unchecked_t num_posixmkdirs;
49969+ atomic_unchecked_t num_rmdirs;
49970+ atomic_unchecked_t num_renames;
49971+ atomic_unchecked_t num_t2renames;
49972+ atomic_unchecked_t num_ffirst;
49973+ atomic_unchecked_t num_fnext;
49974+ atomic_unchecked_t num_fclose;
49975+ atomic_unchecked_t num_hardlinks;
49976+ atomic_unchecked_t num_symlinks;
49977+ atomic_unchecked_t num_locks;
49978+ atomic_unchecked_t num_acl_get;
49979+ atomic_unchecked_t num_acl_set;
49980 } cifs_stats;
49981 #ifdef CONFIG_CIFS_SMB2
49982 struct {
49983- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
49984- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
49985+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
49986+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
49987 } smb2_stats;
49988 #endif /* CONFIG_CIFS_SMB2 */
49989 } stats;
49990@@ -1080,7 +1080,7 @@ convert_delimiter(char *path, char delim)
49991 }
49992
49993 #ifdef CONFIG_CIFS_STATS
49994-#define cifs_stats_inc atomic_inc
49995+#define cifs_stats_inc atomic_inc_unchecked
49996
49997 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
49998 unsigned int bytes)
49999@@ -1445,8 +1445,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
50000 /* Various Debug counters */
50001 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
50002 #ifdef CONFIG_CIFS_STATS2
50003-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
50004-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
50005+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
50006+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
50007 #endif
50008 GLOBAL_EXTERN atomic_t smBufAllocCount;
50009 GLOBAL_EXTERN atomic_t midCount;
50010diff --git a/fs/cifs/link.c b/fs/cifs/link.c
50011index 51dc2fb..1e12a33 100644
50012--- a/fs/cifs/link.c
50013+++ b/fs/cifs/link.c
50014@@ -616,7 +616,7 @@ symlink_exit:
50015
50016 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
50017 {
50018- char *p = nd_get_link(nd);
50019+ const char *p = nd_get_link(nd);
50020 if (!IS_ERR(p))
50021 kfree(p);
50022 }
50023diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
50024index 3a00c0d..42d901c 100644
50025--- a/fs/cifs/misc.c
50026+++ b/fs/cifs/misc.c
50027@@ -169,7 +169,7 @@ cifs_buf_get(void)
50028 memset(ret_buf, 0, buf_size + 3);
50029 atomic_inc(&bufAllocCount);
50030 #ifdef CONFIG_CIFS_STATS2
50031- atomic_inc(&totBufAllocCount);
50032+ atomic_inc_unchecked(&totBufAllocCount);
50033 #endif /* CONFIG_CIFS_STATS2 */
50034 }
50035
50036@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
50037 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
50038 atomic_inc(&smBufAllocCount);
50039 #ifdef CONFIG_CIFS_STATS2
50040- atomic_inc(&totSmBufAllocCount);
50041+ atomic_inc_unchecked(&totSmBufAllocCount);
50042 #endif /* CONFIG_CIFS_STATS2 */
50043
50044 }
50045diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
50046index 47bc5a8..10decbe 100644
50047--- a/fs/cifs/smb1ops.c
50048+++ b/fs/cifs/smb1ops.c
50049@@ -586,27 +586,27 @@ static void
50050 cifs_clear_stats(struct cifs_tcon *tcon)
50051 {
50052 #ifdef CONFIG_CIFS_STATS
50053- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
50054- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
50055- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
50056- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
50057- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
50058- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
50059- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
50060- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
50061- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
50062- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
50063- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
50064- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
50065- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
50066- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
50067- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
50068- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
50069- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
50070- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
50071- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
50072- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
50073- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
50074+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
50075+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
50076+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
50077+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
50078+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
50079+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
50080+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
50081+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
50082+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
50083+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
50084+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
50085+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
50086+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
50087+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
50088+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
50089+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
50090+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
50091+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
50092+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
50093+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
50094+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
50095 #endif
50096 }
50097
50098@@ -615,36 +615,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
50099 {
50100 #ifdef CONFIG_CIFS_STATS
50101 seq_printf(m, " Oplocks breaks: %d",
50102- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
50103+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
50104 seq_printf(m, "\nReads: %d Bytes: %llu",
50105- atomic_read(&tcon->stats.cifs_stats.num_reads),
50106+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
50107 (long long)(tcon->bytes_read));
50108 seq_printf(m, "\nWrites: %d Bytes: %llu",
50109- atomic_read(&tcon->stats.cifs_stats.num_writes),
50110+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
50111 (long long)(tcon->bytes_written));
50112 seq_printf(m, "\nFlushes: %d",
50113- atomic_read(&tcon->stats.cifs_stats.num_flushes));
50114+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
50115 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
50116- atomic_read(&tcon->stats.cifs_stats.num_locks),
50117- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
50118- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
50119+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
50120+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
50121+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
50122 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
50123- atomic_read(&tcon->stats.cifs_stats.num_opens),
50124- atomic_read(&tcon->stats.cifs_stats.num_closes),
50125- atomic_read(&tcon->stats.cifs_stats.num_deletes));
50126+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
50127+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
50128+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
50129 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
50130- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
50131- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
50132+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
50133+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
50134 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
50135- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
50136- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
50137+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
50138+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
50139 seq_printf(m, "\nRenames: %d T2 Renames %d",
50140- atomic_read(&tcon->stats.cifs_stats.num_renames),
50141- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
50142+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
50143+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
50144 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
50145- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
50146- atomic_read(&tcon->stats.cifs_stats.num_fnext),
50147- atomic_read(&tcon->stats.cifs_stats.num_fclose));
50148+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
50149+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
50150+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
50151 #endif
50152 }
50153
50154diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
50155index bceffe7..cd1ae59 100644
50156--- a/fs/cifs/smb2ops.c
50157+++ b/fs/cifs/smb2ops.c
50158@@ -274,8 +274,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
50159 #ifdef CONFIG_CIFS_STATS
50160 int i;
50161 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
50162- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
50163- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
50164+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
50165+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
50166 }
50167 #endif
50168 }
50169@@ -284,66 +284,66 @@ static void
50170 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
50171 {
50172 #ifdef CONFIG_CIFS_STATS
50173- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
50174- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
50175+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
50176+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
50177 seq_printf(m, "\nNegotiates: %d sent %d failed",
50178- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
50179- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
50180+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
50181+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
50182 seq_printf(m, "\nSessionSetups: %d sent %d failed",
50183- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
50184- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
50185+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
50186+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
50187 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
50188 seq_printf(m, "\nLogoffs: %d sent %d failed",
50189- atomic_read(&sent[SMB2_LOGOFF_HE]),
50190- atomic_read(&failed[SMB2_LOGOFF_HE]));
50191+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
50192+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
50193 seq_printf(m, "\nTreeConnects: %d sent %d failed",
50194- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
50195- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
50196+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
50197+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
50198 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
50199- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
50200- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
50201+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
50202+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
50203 seq_printf(m, "\nCreates: %d sent %d failed",
50204- atomic_read(&sent[SMB2_CREATE_HE]),
50205- atomic_read(&failed[SMB2_CREATE_HE]));
50206+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
50207+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
50208 seq_printf(m, "\nCloses: %d sent %d failed",
50209- atomic_read(&sent[SMB2_CLOSE_HE]),
50210- atomic_read(&failed[SMB2_CLOSE_HE]));
50211+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
50212+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
50213 seq_printf(m, "\nFlushes: %d sent %d failed",
50214- atomic_read(&sent[SMB2_FLUSH_HE]),
50215- atomic_read(&failed[SMB2_FLUSH_HE]));
50216+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
50217+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
50218 seq_printf(m, "\nReads: %d sent %d failed",
50219- atomic_read(&sent[SMB2_READ_HE]),
50220- atomic_read(&failed[SMB2_READ_HE]));
50221+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
50222+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
50223 seq_printf(m, "\nWrites: %d sent %d failed",
50224- atomic_read(&sent[SMB2_WRITE_HE]),
50225- atomic_read(&failed[SMB2_WRITE_HE]));
50226+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
50227+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
50228 seq_printf(m, "\nLocks: %d sent %d failed",
50229- atomic_read(&sent[SMB2_LOCK_HE]),
50230- atomic_read(&failed[SMB2_LOCK_HE]));
50231+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
50232+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
50233 seq_printf(m, "\nIOCTLs: %d sent %d failed",
50234- atomic_read(&sent[SMB2_IOCTL_HE]),
50235- atomic_read(&failed[SMB2_IOCTL_HE]));
50236+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
50237+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
50238 seq_printf(m, "\nCancels: %d sent %d failed",
50239- atomic_read(&sent[SMB2_CANCEL_HE]),
50240- atomic_read(&failed[SMB2_CANCEL_HE]));
50241+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
50242+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
50243 seq_printf(m, "\nEchos: %d sent %d failed",
50244- atomic_read(&sent[SMB2_ECHO_HE]),
50245- atomic_read(&failed[SMB2_ECHO_HE]));
50246+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
50247+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
50248 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
50249- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
50250- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
50251+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
50252+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
50253 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
50254- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
50255- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
50256+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
50257+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
50258 seq_printf(m, "\nQueryInfos: %d sent %d failed",
50259- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
50260- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
50261+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
50262+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
50263 seq_printf(m, "\nSetInfos: %d sent %d failed",
50264- atomic_read(&sent[SMB2_SET_INFO_HE]),
50265- atomic_read(&failed[SMB2_SET_INFO_HE]));
50266+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
50267+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
50268 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
50269- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
50270- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
50271+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
50272+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
50273 #endif
50274 }
50275
50276diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
50277index 41d9d07..dbb4772 100644
50278--- a/fs/cifs/smb2pdu.c
50279+++ b/fs/cifs/smb2pdu.c
50280@@ -1761,8 +1761,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
50281 default:
50282 cERROR(1, "info level %u isn't supported",
50283 srch_inf->info_level);
50284- rc = -EINVAL;
50285- goto qdir_exit;
50286+ return -EINVAL;
50287 }
50288
50289 req->FileIndex = cpu_to_le32(index);
50290diff --git a/fs/coda/cache.c b/fs/coda/cache.c
50291index 958ae0e..505c9d0 100644
50292--- a/fs/coda/cache.c
50293+++ b/fs/coda/cache.c
50294@@ -24,7 +24,7 @@
50295 #include "coda_linux.h"
50296 #include "coda_cache.h"
50297
50298-static atomic_t permission_epoch = ATOMIC_INIT(0);
50299+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
50300
50301 /* replace or extend an acl cache hit */
50302 void coda_cache_enter(struct inode *inode, int mask)
50303@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
50304 struct coda_inode_info *cii = ITOC(inode);
50305
50306 spin_lock(&cii->c_lock);
50307- cii->c_cached_epoch = atomic_read(&permission_epoch);
50308+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
50309 if (cii->c_uid != current_fsuid()) {
50310 cii->c_uid = current_fsuid();
50311 cii->c_cached_perm = mask;
50312@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
50313 {
50314 struct coda_inode_info *cii = ITOC(inode);
50315 spin_lock(&cii->c_lock);
50316- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
50317+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
50318 spin_unlock(&cii->c_lock);
50319 }
50320
50321 /* remove all acl caches */
50322 void coda_cache_clear_all(struct super_block *sb)
50323 {
50324- atomic_inc(&permission_epoch);
50325+ atomic_inc_unchecked(&permission_epoch);
50326 }
50327
50328
50329@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
50330 spin_lock(&cii->c_lock);
50331 hit = (mask & cii->c_cached_perm) == mask &&
50332 cii->c_uid == current_fsuid() &&
50333- cii->c_cached_epoch == atomic_read(&permission_epoch);
50334+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
50335 spin_unlock(&cii->c_lock);
50336
50337 return hit;
50338diff --git a/fs/compat.c b/fs/compat.c
50339index a06dcbc..dacb6d3 100644
50340--- a/fs/compat.c
50341+++ b/fs/compat.c
50342@@ -54,7 +54,7 @@
50343 #include <asm/ioctls.h>
50344 #include "internal.h"
50345
50346-int compat_log = 1;
50347+int compat_log = 0;
50348
50349 int compat_printk(const char *fmt, ...)
50350 {
50351@@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
50352
50353 set_fs(KERNEL_DS);
50354 /* The __user pointer cast is valid because of the set_fs() */
50355- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
50356+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
50357 set_fs(oldfs);
50358 /* truncating is ok because it's a user address */
50359 if (!ret)
50360@@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
50361 goto out;
50362
50363 ret = -EINVAL;
50364- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
50365+ if (nr_segs > UIO_MAXIOV)
50366 goto out;
50367 if (nr_segs > fast_segs) {
50368 ret = -ENOMEM;
50369@@ -835,6 +835,7 @@ struct compat_old_linux_dirent {
50370
50371 struct compat_readdir_callback {
50372 struct compat_old_linux_dirent __user *dirent;
50373+ struct file * file;
50374 int result;
50375 };
50376
50377@@ -852,6 +853,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
50378 buf->result = -EOVERFLOW;
50379 return -EOVERFLOW;
50380 }
50381+
50382+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50383+ return 0;
50384+
50385 buf->result++;
50386 dirent = buf->dirent;
50387 if (!access_ok(VERIFY_WRITE, dirent,
50388@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
50389
50390 buf.result = 0;
50391 buf.dirent = dirent;
50392+ buf.file = f.file;
50393
50394 error = vfs_readdir(f.file, compat_fillonedir, &buf);
50395 if (buf.result)
50396@@ -901,6 +907,7 @@ struct compat_linux_dirent {
50397 struct compat_getdents_callback {
50398 struct compat_linux_dirent __user *current_dir;
50399 struct compat_linux_dirent __user *previous;
50400+ struct file * file;
50401 int count;
50402 int error;
50403 };
50404@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
50405 buf->error = -EOVERFLOW;
50406 return -EOVERFLOW;
50407 }
50408+
50409+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50410+ return 0;
50411+
50412 dirent = buf->previous;
50413 if (dirent) {
50414 if (__put_user(offset, &dirent->d_off))
50415@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
50416 buf.previous = NULL;
50417 buf.count = count;
50418 buf.error = 0;
50419+ buf.file = f.file;
50420
50421 error = vfs_readdir(f.file, compat_filldir, &buf);
50422 if (error >= 0)
50423@@ -987,6 +999,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
50424 struct compat_getdents_callback64 {
50425 struct linux_dirent64 __user *current_dir;
50426 struct linux_dirent64 __user *previous;
50427+ struct file * file;
50428 int count;
50429 int error;
50430 };
50431@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
50432 buf->error = -EINVAL; /* only used if we fail.. */
50433 if (reclen > buf->count)
50434 return -EINVAL;
50435+
50436+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50437+ return 0;
50438+
50439 dirent = buf->previous;
50440
50441 if (dirent) {
50442@@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
50443 buf.previous = NULL;
50444 buf.count = count;
50445 buf.error = 0;
50446+ buf.file = f.file;
50447
50448 error = vfs_readdir(f.file, compat_filldir64, &buf);
50449 if (error >= 0)
50450 error = buf.error;
50451 lastdirent = buf.previous;
50452 if (lastdirent) {
50453- typeof(lastdirent->d_off) d_off = f.file->f_pos;
50454+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
50455 if (__put_user_unaligned(d_off, &lastdirent->d_off))
50456 error = -EFAULT;
50457 else
50458diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
50459index a81147e..20bf2b5 100644
50460--- a/fs/compat_binfmt_elf.c
50461+++ b/fs/compat_binfmt_elf.c
50462@@ -30,11 +30,13 @@
50463 #undef elf_phdr
50464 #undef elf_shdr
50465 #undef elf_note
50466+#undef elf_dyn
50467 #undef elf_addr_t
50468 #define elfhdr elf32_hdr
50469 #define elf_phdr elf32_phdr
50470 #define elf_shdr elf32_shdr
50471 #define elf_note elf32_note
50472+#define elf_dyn Elf32_Dyn
50473 #define elf_addr_t Elf32_Addr
50474
50475 /*
50476diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
50477index e2f57a0..3c78771 100644
50478--- a/fs/compat_ioctl.c
50479+++ b/fs/compat_ioctl.c
50480@@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
50481 return -EFAULT;
50482 if (__get_user(udata, &ss32->iomem_base))
50483 return -EFAULT;
50484- ss.iomem_base = compat_ptr(udata);
50485+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
50486 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
50487 __get_user(ss.port_high, &ss32->port_high))
50488 return -EFAULT;
50489@@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
50490 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
50491 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
50492 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
50493- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
50494+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
50495 return -EFAULT;
50496
50497 return ioctl_preallocate(file, p);
50498@@ -1620,8 +1620,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
50499 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
50500 {
50501 unsigned int a, b;
50502- a = *(unsigned int *)p;
50503- b = *(unsigned int *)q;
50504+ a = *(const unsigned int *)p;
50505+ b = *(const unsigned int *)q;
50506 if (a > b)
50507 return 1;
50508 if (a < b)
50509diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
50510index 712b10f..c33c4ca 100644
50511--- a/fs/configfs/dir.c
50512+++ b/fs/configfs/dir.c
50513@@ -1037,10 +1037,11 @@ static int configfs_dump(struct configfs_dirent *sd, int level)
50514 static int configfs_depend_prep(struct dentry *origin,
50515 struct config_item *target)
50516 {
50517- struct configfs_dirent *child_sd, *sd = origin->d_fsdata;
50518+ struct configfs_dirent *child_sd, *sd;
50519 int ret = 0;
50520
50521- BUG_ON(!origin || !sd);
50522+ BUG_ON(!origin || !origin->d_fsdata);
50523+ sd = origin->d_fsdata;
50524
50525 if (sd->s_element == target) /* Boo-yah */
50526 goto out;
50527@@ -1564,7 +1565,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
50528 }
50529 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
50530 struct configfs_dirent *next;
50531- const char * name;
50532+ const unsigned char * name;
50533+ char d_name[sizeof(next->s_dentry->d_iname)];
50534 int len;
50535 struct inode *inode = NULL;
50536
50537@@ -1574,7 +1576,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
50538 continue;
50539
50540 name = configfs_get_name(next);
50541- len = strlen(name);
50542+ if (next->s_dentry && name == next->s_dentry->d_iname) {
50543+ len = next->s_dentry->d_name.len;
50544+ memcpy(d_name, name, len);
50545+ name = d_name;
50546+ } else
50547+ len = strlen(name);
50548
50549 /*
50550 * We'll have a dentry and an inode for
50551diff --git a/fs/coredump.c b/fs/coredump.c
50552index 1774932..5812106 100644
50553--- a/fs/coredump.c
50554+++ b/fs/coredump.c
50555@@ -52,7 +52,7 @@ struct core_name {
50556 char *corename;
50557 int used, size;
50558 };
50559-static atomic_t call_count = ATOMIC_INIT(1);
50560+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
50561
50562 /* The maximal length of core_pattern is also specified in sysctl.c */
50563
50564@@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
50565 {
50566 char *old_corename = cn->corename;
50567
50568- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
50569+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
50570 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
50571
50572 if (!cn->corename) {
50573@@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
50574 int pid_in_pattern = 0;
50575 int err = 0;
50576
50577- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
50578+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
50579 cn->corename = kmalloc(cn->size, GFP_KERNEL);
50580 cn->used = 0;
50581
50582@@ -414,17 +414,17 @@ static void wait_for_dump_helpers(struct file *file)
50583 pipe = file->f_path.dentry->d_inode->i_pipe;
50584
50585 pipe_lock(pipe);
50586- pipe->readers++;
50587- pipe->writers--;
50588+ atomic_inc(&pipe->readers);
50589+ atomic_dec(&pipe->writers);
50590
50591- while ((pipe->readers > 1) && (!signal_pending(current))) {
50592+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
50593 wake_up_interruptible_sync(&pipe->wait);
50594 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
50595 pipe_wait(pipe);
50596 }
50597
50598- pipe->readers--;
50599- pipe->writers++;
50600+ atomic_dec(&pipe->readers);
50601+ atomic_inc(&pipe->writers);
50602 pipe_unlock(pipe);
50603
50604 }
50605@@ -471,7 +471,8 @@ void do_coredump(siginfo_t *siginfo)
50606 int ispipe;
50607 struct files_struct *displaced;
50608 bool need_nonrelative = false;
50609- static atomic_t core_dump_count = ATOMIC_INIT(0);
50610+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
50611+ long signr = siginfo->si_signo;
50612 struct coredump_params cprm = {
50613 .siginfo = siginfo,
50614 .regs = signal_pt_regs(),
50615@@ -484,7 +485,10 @@ void do_coredump(siginfo_t *siginfo)
50616 .mm_flags = mm->flags,
50617 };
50618
50619- audit_core_dumps(siginfo->si_signo);
50620+ audit_core_dumps(signr);
50621+
50622+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
50623+ gr_handle_brute_attach(cprm.mm_flags);
50624
50625 binfmt = mm->binfmt;
50626 if (!binfmt || !binfmt->core_dump)
50627@@ -508,7 +512,7 @@ void do_coredump(siginfo_t *siginfo)
50628 need_nonrelative = true;
50629 }
50630
50631- retval = coredump_wait(siginfo->si_signo, &core_state);
50632+ retval = coredump_wait(signr, &core_state);
50633 if (retval < 0)
50634 goto fail_creds;
50635
50636@@ -556,7 +560,7 @@ void do_coredump(siginfo_t *siginfo)
50637 }
50638 cprm.limit = RLIM_INFINITY;
50639
50640- dump_count = atomic_inc_return(&core_dump_count);
50641+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
50642 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
50643 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
50644 task_tgid_vnr(current), current->comm);
50645@@ -583,6 +587,8 @@ void do_coredump(siginfo_t *siginfo)
50646 } else {
50647 struct inode *inode;
50648
50649+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
50650+
50651 if (cprm.limit < binfmt->min_coredump)
50652 goto fail_unlock;
50653
50654@@ -640,7 +646,7 @@ close_fail:
50655 filp_close(cprm.file, NULL);
50656 fail_dropcount:
50657 if (ispipe)
50658- atomic_dec(&core_dump_count);
50659+ atomic_dec_unchecked(&core_dump_count);
50660 fail_unlock:
50661 kfree(cn.corename);
50662 fail_corename:
50663@@ -659,7 +665,7 @@ fail:
50664 */
50665 int dump_write(struct file *file, const void *addr, int nr)
50666 {
50667- return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
50668+ return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
50669 }
50670 EXPORT_SYMBOL(dump_write);
50671
50672diff --git a/fs/dcache.c b/fs/dcache.c
50673index c3bbf85..5b71101 100644
50674--- a/fs/dcache.c
50675+++ b/fs/dcache.c
50676@@ -3139,7 +3139,7 @@ void __init vfs_caches_init(unsigned long mempages)
50677 mempages -= reserve;
50678
50679 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
50680- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
50681+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
50682
50683 dcache_init();
50684 inode_init();
50685diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
50686index a5f12b7..4ee8a6f 100644
50687--- a/fs/debugfs/inode.c
50688+++ b/fs/debugfs/inode.c
50689@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
50690 */
50691 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
50692 {
50693+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
50694+ return __create_file(name, S_IFDIR | S_IRWXU,
50695+#else
50696 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
50697+#endif
50698 parent, NULL, NULL);
50699 }
50700 EXPORT_SYMBOL_GPL(debugfs_create_dir);
50701diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
50702index cc7709e..7e7211f 100644
50703--- a/fs/ecryptfs/inode.c
50704+++ b/fs/ecryptfs/inode.c
50705@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
50706 old_fs = get_fs();
50707 set_fs(get_ds());
50708 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
50709- (char __user *)lower_buf,
50710+ (char __force_user *)lower_buf,
50711 PATH_MAX);
50712 set_fs(old_fs);
50713 if (rc < 0)
50714@@ -706,7 +706,7 @@ out:
50715 static void
50716 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
50717 {
50718- char *buf = nd_get_link(nd);
50719+ const char *buf = nd_get_link(nd);
50720 if (!IS_ERR(buf)) {
50721 /* Free the char* */
50722 kfree(buf);
50723diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
50724index 412e6ed..d8263e8 100644
50725--- a/fs/ecryptfs/miscdev.c
50726+++ b/fs/ecryptfs/miscdev.c
50727@@ -80,13 +80,6 @@ ecryptfs_miscdev_open(struct inode *inode, struct file *file)
50728 int rc;
50729
50730 mutex_lock(&ecryptfs_daemon_hash_mux);
50731- rc = try_module_get(THIS_MODULE);
50732- if (rc == 0) {
50733- rc = -EIO;
50734- printk(KERN_ERR "%s: Error attempting to increment module use "
50735- "count; rc = [%d]\n", __func__, rc);
50736- goto out_unlock_daemon_list;
50737- }
50738 rc = ecryptfs_find_daemon_by_euid(&daemon);
50739 if (!rc) {
50740 rc = -EINVAL;
50741@@ -96,7 +89,7 @@ ecryptfs_miscdev_open(struct inode *inode, struct file *file)
50742 if (rc) {
50743 printk(KERN_ERR "%s: Error attempting to spawn daemon; "
50744 "rc = [%d]\n", __func__, rc);
50745- goto out_module_put_unlock_daemon_list;
50746+ goto out_unlock_daemon_list;
50747 }
50748 mutex_lock(&daemon->mux);
50749 if (daemon->flags & ECRYPTFS_DAEMON_MISCDEV_OPEN) {
50750@@ -108,9 +101,6 @@ ecryptfs_miscdev_open(struct inode *inode, struct file *file)
50751 atomic_inc(&ecryptfs_num_miscdev_opens);
50752 out_unlock_daemon:
50753 mutex_unlock(&daemon->mux);
50754-out_module_put_unlock_daemon_list:
50755- if (rc)
50756- module_put(THIS_MODULE);
50757 out_unlock_daemon_list:
50758 mutex_unlock(&ecryptfs_daemon_hash_mux);
50759 return rc;
50760@@ -147,7 +137,6 @@ ecryptfs_miscdev_release(struct inode *inode, struct file *file)
50761 "bug.\n", __func__, rc);
50762 BUG();
50763 }
50764- module_put(THIS_MODULE);
50765 return rc;
50766 }
50767
50768@@ -315,7 +304,7 @@ check_list:
50769 goto out_unlock_msg_ctx;
50770 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
50771 if (msg_ctx->msg) {
50772- if (copy_to_user(&buf[i], packet_length, packet_length_size))
50773+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
50774 goto out_unlock_msg_ctx;
50775 i += packet_length_size;
50776 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
50777@@ -471,6 +460,7 @@ out_free:
50778
50779
50780 static const struct file_operations ecryptfs_miscdev_fops = {
50781+ .owner = THIS_MODULE,
50782 .open = ecryptfs_miscdev_open,
50783 .poll = ecryptfs_miscdev_poll,
50784 .read = ecryptfs_miscdev_read,
50785diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
50786index b2a34a1..162fa69 100644
50787--- a/fs/ecryptfs/read_write.c
50788+++ b/fs/ecryptfs/read_write.c
50789@@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
50790 return -EIO;
50791 fs_save = get_fs();
50792 set_fs(get_ds());
50793- rc = vfs_write(lower_file, data, size, &offset);
50794+ rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
50795 set_fs(fs_save);
50796 mark_inode_dirty_sync(ecryptfs_inode);
50797 return rc;
50798@@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
50799 return -EIO;
50800 fs_save = get_fs();
50801 set_fs(get_ds());
50802- rc = vfs_read(lower_file, data, size, &offset);
50803+ rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
50804 set_fs(fs_save);
50805 return rc;
50806 }
50807diff --git a/fs/exec.c b/fs/exec.c
50808index 20df02c..9a87617 100644
50809--- a/fs/exec.c
50810+++ b/fs/exec.c
50811@@ -55,8 +55,20 @@
50812 #include <linux/pipe_fs_i.h>
50813 #include <linux/oom.h>
50814 #include <linux/compat.h>
50815+#include <linux/random.h>
50816+#include <linux/seq_file.h>
50817+#include <linux/coredump.h>
50818+#include <linux/mman.h>
50819+
50820+#ifdef CONFIG_PAX_REFCOUNT
50821+#include <linux/kallsyms.h>
50822+#include <linux/kdebug.h>
50823+#endif
50824+
50825+#include <trace/events/fs.h>
50826
50827 #include <asm/uaccess.h>
50828+#include <asm/sections.h>
50829 #include <asm/mmu_context.h>
50830 #include <asm/tlb.h>
50831
50832@@ -66,6 +78,18 @@
50833
50834 #include <trace/events/sched.h>
50835
50836+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
50837+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
50838+{
50839+ 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");
50840+}
50841+#endif
50842+
50843+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
50844+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
50845+EXPORT_SYMBOL(pax_set_initial_flags_func);
50846+#endif
50847+
50848 int suid_dumpable = 0;
50849
50850 static LIST_HEAD(formats);
50851@@ -75,8 +99,8 @@ void __register_binfmt(struct linux_binfmt * fmt, int insert)
50852 {
50853 BUG_ON(!fmt);
50854 write_lock(&binfmt_lock);
50855- insert ? list_add(&fmt->lh, &formats) :
50856- list_add_tail(&fmt->lh, &formats);
50857+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
50858+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
50859 write_unlock(&binfmt_lock);
50860 }
50861
50862@@ -85,7 +109,7 @@ EXPORT_SYMBOL(__register_binfmt);
50863 void unregister_binfmt(struct linux_binfmt * fmt)
50864 {
50865 write_lock(&binfmt_lock);
50866- list_del(&fmt->lh);
50867+ pax_list_del((struct list_head *)&fmt->lh);
50868 write_unlock(&binfmt_lock);
50869 }
50870
50871@@ -180,18 +204,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
50872 int write)
50873 {
50874 struct page *page;
50875- int ret;
50876
50877-#ifdef CONFIG_STACK_GROWSUP
50878- if (write) {
50879- ret = expand_downwards(bprm->vma, pos);
50880- if (ret < 0)
50881- return NULL;
50882- }
50883-#endif
50884- ret = get_user_pages(current, bprm->mm, pos,
50885- 1, write, 1, &page, NULL);
50886- if (ret <= 0)
50887+ if (0 > expand_downwards(bprm->vma, pos))
50888+ return NULL;
50889+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
50890 return NULL;
50891
50892 if (write) {
50893@@ -207,6 +223,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
50894 if (size <= ARG_MAX)
50895 return page;
50896
50897+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50898+ // only allow 512KB for argv+env on suid/sgid binaries
50899+ // to prevent easy ASLR exhaustion
50900+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
50901+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
50902+ (size > (512 * 1024))) {
50903+ put_page(page);
50904+ return NULL;
50905+ }
50906+#endif
50907+
50908 /*
50909 * Limit to 1/4-th the stack size for the argv+env strings.
50910 * This ensures that:
50911@@ -266,6 +293,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
50912 vma->vm_end = STACK_TOP_MAX;
50913 vma->vm_start = vma->vm_end - PAGE_SIZE;
50914 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
50915+
50916+#ifdef CONFIG_PAX_SEGMEXEC
50917+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
50918+#endif
50919+
50920 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
50921 INIT_LIST_HEAD(&vma->anon_vma_chain);
50922
50923@@ -276,6 +308,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
50924 mm->stack_vm = mm->total_vm = 1;
50925 up_write(&mm->mmap_sem);
50926 bprm->p = vma->vm_end - sizeof(void *);
50927+
50928+#ifdef CONFIG_PAX_RANDUSTACK
50929+ if (randomize_va_space)
50930+ bprm->p ^= random32() & ~PAGE_MASK;
50931+#endif
50932+
50933 return 0;
50934 err:
50935 up_write(&mm->mmap_sem);
50936@@ -396,7 +434,7 @@ struct user_arg_ptr {
50937 } ptr;
50938 };
50939
50940-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50941+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50942 {
50943 const char __user *native;
50944
50945@@ -405,14 +443,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50946 compat_uptr_t compat;
50947
50948 if (get_user(compat, argv.ptr.compat + nr))
50949- return ERR_PTR(-EFAULT);
50950+ return (const char __force_user *)ERR_PTR(-EFAULT);
50951
50952 return compat_ptr(compat);
50953 }
50954 #endif
50955
50956 if (get_user(native, argv.ptr.native + nr))
50957- return ERR_PTR(-EFAULT);
50958+ return (const char __force_user *)ERR_PTR(-EFAULT);
50959
50960 return native;
50961 }
50962@@ -431,7 +469,7 @@ static int count(struct user_arg_ptr argv, int max)
50963 if (!p)
50964 break;
50965
50966- if (IS_ERR(p))
50967+ if (IS_ERR((const char __force_kernel *)p))
50968 return -EFAULT;
50969
50970 if (i >= max)
50971@@ -466,7 +504,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
50972
50973 ret = -EFAULT;
50974 str = get_user_arg_ptr(argv, argc);
50975- if (IS_ERR(str))
50976+ if (IS_ERR((const char __force_kernel *)str))
50977 goto out;
50978
50979 len = strnlen_user(str, MAX_ARG_STRLEN);
50980@@ -548,7 +586,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
50981 int r;
50982 mm_segment_t oldfs = get_fs();
50983 struct user_arg_ptr argv = {
50984- .ptr.native = (const char __user *const __user *)__argv,
50985+ .ptr.native = (const char __force_user *const __force_user *)__argv,
50986 };
50987
50988 set_fs(KERNEL_DS);
50989@@ -583,7 +621,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
50990 unsigned long new_end = old_end - shift;
50991 struct mmu_gather tlb;
50992
50993- BUG_ON(new_start > new_end);
50994+ if (new_start >= new_end || new_start < mmap_min_addr)
50995+ return -ENOMEM;
50996
50997 /*
50998 * ensure there are no vmas between where we want to go
50999@@ -592,6 +631,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
51000 if (vma != find_vma(mm, new_start))
51001 return -EFAULT;
51002
51003+#ifdef CONFIG_PAX_SEGMEXEC
51004+ BUG_ON(pax_find_mirror_vma(vma));
51005+#endif
51006+
51007 /*
51008 * cover the whole range: [new_start, old_end)
51009 */
51010@@ -672,10 +715,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
51011 stack_top = arch_align_stack(stack_top);
51012 stack_top = PAGE_ALIGN(stack_top);
51013
51014- if (unlikely(stack_top < mmap_min_addr) ||
51015- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
51016- return -ENOMEM;
51017-
51018 stack_shift = vma->vm_end - stack_top;
51019
51020 bprm->p -= stack_shift;
51021@@ -687,8 +726,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
51022 bprm->exec -= stack_shift;
51023
51024 down_write(&mm->mmap_sem);
51025+
51026+ /* Move stack pages down in memory. */
51027+ if (stack_shift) {
51028+ ret = shift_arg_pages(vma, stack_shift);
51029+ if (ret)
51030+ goto out_unlock;
51031+ }
51032+
51033 vm_flags = VM_STACK_FLAGS;
51034
51035+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
51036+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
51037+ vm_flags &= ~VM_EXEC;
51038+
51039+#ifdef CONFIG_PAX_MPROTECT
51040+ if (mm->pax_flags & MF_PAX_MPROTECT)
51041+ vm_flags &= ~VM_MAYEXEC;
51042+#endif
51043+
51044+ }
51045+#endif
51046+
51047 /*
51048 * Adjust stack execute permissions; explicitly enable for
51049 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
51050@@ -707,13 +766,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
51051 goto out_unlock;
51052 BUG_ON(prev != vma);
51053
51054- /* Move stack pages down in memory. */
51055- if (stack_shift) {
51056- ret = shift_arg_pages(vma, stack_shift);
51057- if (ret)
51058- goto out_unlock;
51059- }
51060-
51061 /* mprotect_fixup is overkill to remove the temporary stack flags */
51062 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
51063
51064@@ -737,6 +789,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
51065 #endif
51066 current->mm->start_stack = bprm->p;
51067 ret = expand_stack(vma, stack_base);
51068+
51069+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
51070+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
51071+ unsigned long size, flags, vm_flags;
51072+
51073+ size = STACK_TOP - vma->vm_end;
51074+ flags = MAP_FIXED | MAP_PRIVATE;
51075+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
51076+
51077+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, flags, vm_flags, 0);
51078+
51079+#ifdef CONFIG_X86
51080+ if (!ret) {
51081+ size = mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
51082+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), flags, vm_flags, 0);
51083+ }
51084+#endif
51085+
51086+ }
51087+#endif
51088+
51089 if (ret)
51090 ret = -EFAULT;
51091
51092@@ -772,6 +845,8 @@ struct file *open_exec(const char *name)
51093
51094 fsnotify_open(file);
51095
51096+ trace_open_exec(name);
51097+
51098 err = deny_write_access(file);
51099 if (err)
51100 goto exit;
51101@@ -795,7 +870,7 @@ int kernel_read(struct file *file, loff_t offset,
51102 old_fs = get_fs();
51103 set_fs(get_ds());
51104 /* The cast to a user pointer is valid due to the set_fs() */
51105- result = vfs_read(file, (void __user *)addr, count, &pos);
51106+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
51107 set_fs(old_fs);
51108 return result;
51109 }
51110@@ -1247,7 +1322,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
51111 }
51112 rcu_read_unlock();
51113
51114- if (p->fs->users > n_fs) {
51115+ if (atomic_read(&p->fs->users) > n_fs) {
51116 bprm->unsafe |= LSM_UNSAFE_SHARE;
51117 } else {
51118 res = -EAGAIN;
51119@@ -1447,6 +1522,31 @@ int search_binary_handler(struct linux_binprm *bprm)
51120
51121 EXPORT_SYMBOL(search_binary_handler);
51122
51123+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51124+static DEFINE_PER_CPU(u64, exec_counter);
51125+static int __init init_exec_counters(void)
51126+{
51127+ unsigned int cpu;
51128+
51129+ for_each_possible_cpu(cpu) {
51130+ per_cpu(exec_counter, cpu) = (u64)cpu;
51131+ }
51132+
51133+ return 0;
51134+}
51135+early_initcall(init_exec_counters);
51136+static inline void increment_exec_counter(void)
51137+{
51138+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
51139+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
51140+}
51141+#else
51142+static inline void increment_exec_counter(void) {}
51143+#endif
51144+
51145+extern void gr_handle_exec_args(struct linux_binprm *bprm,
51146+ struct user_arg_ptr argv);
51147+
51148 /*
51149 * sys_execve() executes a new program.
51150 */
51151@@ -1454,6 +1554,11 @@ static int do_execve_common(const char *filename,
51152 struct user_arg_ptr argv,
51153 struct user_arg_ptr envp)
51154 {
51155+#ifdef CONFIG_GRKERNSEC
51156+ struct file *old_exec_file;
51157+ struct acl_subject_label *old_acl;
51158+ struct rlimit old_rlim[RLIM_NLIMITS];
51159+#endif
51160 struct linux_binprm *bprm;
51161 struct file *file;
51162 struct files_struct *displaced;
51163@@ -1461,6 +1566,8 @@ static int do_execve_common(const char *filename,
51164 int retval;
51165 const struct cred *cred = current_cred();
51166
51167+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
51168+
51169 /*
51170 * We move the actual failure in case of RLIMIT_NPROC excess from
51171 * set*uid() to execve() because too many poorly written programs
51172@@ -1501,12 +1608,27 @@ static int do_execve_common(const char *filename,
51173 if (IS_ERR(file))
51174 goto out_unmark;
51175
51176+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
51177+ retval = -EPERM;
51178+ goto out_file;
51179+ }
51180+
51181 sched_exec();
51182
51183 bprm->file = file;
51184 bprm->filename = filename;
51185 bprm->interp = filename;
51186
51187+ if (gr_process_user_ban()) {
51188+ retval = -EPERM;
51189+ goto out_file;
51190+ }
51191+
51192+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
51193+ retval = -EACCES;
51194+ goto out_file;
51195+ }
51196+
51197 retval = bprm_mm_init(bprm);
51198 if (retval)
51199 goto out_file;
51200@@ -1523,24 +1645,65 @@ static int do_execve_common(const char *filename,
51201 if (retval < 0)
51202 goto out;
51203
51204+#ifdef CONFIG_GRKERNSEC
51205+ old_acl = current->acl;
51206+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
51207+ old_exec_file = current->exec_file;
51208+ get_file(file);
51209+ current->exec_file = file;
51210+#endif
51211+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51212+ /* limit suid stack to 8MB
51213+ * we saved the old limits above and will restore them if this exec fails
51214+ */
51215+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
51216+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
51217+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
51218+#endif
51219+
51220+ if (!gr_tpe_allow(file)) {
51221+ retval = -EACCES;
51222+ goto out_fail;
51223+ }
51224+
51225+ if (gr_check_crash_exec(file)) {
51226+ retval = -EACCES;
51227+ goto out_fail;
51228+ }
51229+
51230+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
51231+ bprm->unsafe);
51232+ if (retval < 0)
51233+ goto out_fail;
51234+
51235 retval = copy_strings_kernel(1, &bprm->filename, bprm);
51236 if (retval < 0)
51237- goto out;
51238+ goto out_fail;
51239
51240 bprm->exec = bprm->p;
51241 retval = copy_strings(bprm->envc, envp, bprm);
51242 if (retval < 0)
51243- goto out;
51244+ goto out_fail;
51245
51246 retval = copy_strings(bprm->argc, argv, bprm);
51247 if (retval < 0)
51248- goto out;
51249+ goto out_fail;
51250+
51251+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
51252+
51253+ gr_handle_exec_args(bprm, argv);
51254
51255 retval = search_binary_handler(bprm);
51256 if (retval < 0)
51257- goto out;
51258+ goto out_fail;
51259+#ifdef CONFIG_GRKERNSEC
51260+ if (old_exec_file)
51261+ fput(old_exec_file);
51262+#endif
51263
51264 /* execve succeeded */
51265+
51266+ increment_exec_counter();
51267 current->fs->in_exec = 0;
51268 current->in_execve = 0;
51269 acct_update_integrals(current);
51270@@ -1549,6 +1712,14 @@ static int do_execve_common(const char *filename,
51271 put_files_struct(displaced);
51272 return retval;
51273
51274+out_fail:
51275+#ifdef CONFIG_GRKERNSEC
51276+ current->acl = old_acl;
51277+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
51278+ fput(current->exec_file);
51279+ current->exec_file = old_exec_file;
51280+#endif
51281+
51282 out:
51283 if (bprm->mm) {
51284 acct_arg_size(bprm, 0);
51285@@ -1697,3 +1868,278 @@ asmlinkage long compat_sys_execve(const char __user * filename,
51286 return error;
51287 }
51288 #endif
51289+
51290+int pax_check_flags(unsigned long *flags)
51291+{
51292+ int retval = 0;
51293+
51294+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
51295+ if (*flags & MF_PAX_SEGMEXEC)
51296+ {
51297+ *flags &= ~MF_PAX_SEGMEXEC;
51298+ retval = -EINVAL;
51299+ }
51300+#endif
51301+
51302+ if ((*flags & MF_PAX_PAGEEXEC)
51303+
51304+#ifdef CONFIG_PAX_PAGEEXEC
51305+ && (*flags & MF_PAX_SEGMEXEC)
51306+#endif
51307+
51308+ )
51309+ {
51310+ *flags &= ~MF_PAX_PAGEEXEC;
51311+ retval = -EINVAL;
51312+ }
51313+
51314+ if ((*flags & MF_PAX_MPROTECT)
51315+
51316+#ifdef CONFIG_PAX_MPROTECT
51317+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
51318+#endif
51319+
51320+ )
51321+ {
51322+ *flags &= ~MF_PAX_MPROTECT;
51323+ retval = -EINVAL;
51324+ }
51325+
51326+ if ((*flags & MF_PAX_EMUTRAMP)
51327+
51328+#ifdef CONFIG_PAX_EMUTRAMP
51329+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
51330+#endif
51331+
51332+ )
51333+ {
51334+ *flags &= ~MF_PAX_EMUTRAMP;
51335+ retval = -EINVAL;
51336+ }
51337+
51338+ return retval;
51339+}
51340+
51341+EXPORT_SYMBOL(pax_check_flags);
51342+
51343+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
51344+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
51345+{
51346+ struct task_struct *tsk = current;
51347+ struct mm_struct *mm = current->mm;
51348+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
51349+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
51350+ char *path_exec = NULL;
51351+ char *path_fault = NULL;
51352+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
51353+ siginfo_t info = { };
51354+
51355+ if (buffer_exec && buffer_fault) {
51356+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
51357+
51358+ down_read(&mm->mmap_sem);
51359+ vma = mm->mmap;
51360+ while (vma && (!vma_exec || !vma_fault)) {
51361+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
51362+ vma_exec = vma;
51363+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
51364+ vma_fault = vma;
51365+ vma = vma->vm_next;
51366+ }
51367+ if (vma_exec) {
51368+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
51369+ if (IS_ERR(path_exec))
51370+ path_exec = "<path too long>";
51371+ else {
51372+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
51373+ if (path_exec) {
51374+ *path_exec = 0;
51375+ path_exec = buffer_exec;
51376+ } else
51377+ path_exec = "<path too long>";
51378+ }
51379+ }
51380+ if (vma_fault) {
51381+ start = vma_fault->vm_start;
51382+ end = vma_fault->vm_end;
51383+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
51384+ if (vma_fault->vm_file) {
51385+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
51386+ if (IS_ERR(path_fault))
51387+ path_fault = "<path too long>";
51388+ else {
51389+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
51390+ if (path_fault) {
51391+ *path_fault = 0;
51392+ path_fault = buffer_fault;
51393+ } else
51394+ path_fault = "<path too long>";
51395+ }
51396+ } else
51397+ path_fault = "<anonymous mapping>";
51398+ }
51399+ up_read(&mm->mmap_sem);
51400+ }
51401+ if (tsk->signal->curr_ip)
51402+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
51403+ else
51404+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
51405+ 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),
51406+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
51407+ free_page((unsigned long)buffer_exec);
51408+ free_page((unsigned long)buffer_fault);
51409+ pax_report_insns(regs, pc, sp);
51410+ info.si_signo = SIGKILL;
51411+ info.si_errno = 0;
51412+ info.si_code = SI_KERNEL;
51413+ info.si_pid = 0;
51414+ info.si_uid = 0;
51415+ do_coredump(&info);
51416+}
51417+#endif
51418+
51419+#ifdef CONFIG_PAX_REFCOUNT
51420+void pax_report_refcount_overflow(struct pt_regs *regs)
51421+{
51422+ if (current->signal->curr_ip)
51423+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
51424+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
51425+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
51426+ else
51427+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
51428+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
51429+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
51430+ show_regs(regs);
51431+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
51432+}
51433+#endif
51434+
51435+#ifdef CONFIG_PAX_USERCOPY
51436+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
51437+static noinline int check_stack_object(const void *obj, unsigned long len)
51438+{
51439+ const void * const stack = task_stack_page(current);
51440+ const void * const stackend = stack + THREAD_SIZE;
51441+
51442+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
51443+ const void *frame = NULL;
51444+ const void *oldframe;
51445+#endif
51446+
51447+ if (obj + len < obj)
51448+ return -1;
51449+
51450+ if (obj + len <= stack || stackend <= obj)
51451+ return 0;
51452+
51453+ if (obj < stack || stackend < obj + len)
51454+ return -1;
51455+
51456+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
51457+ oldframe = __builtin_frame_address(1);
51458+ if (oldframe)
51459+ frame = __builtin_frame_address(2);
51460+ /*
51461+ low ----------------------------------------------> high
51462+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
51463+ ^----------------^
51464+ allow copies only within here
51465+ */
51466+ while (stack <= frame && frame < stackend) {
51467+ /* if obj + len extends past the last frame, this
51468+ check won't pass and the next frame will be 0,
51469+ causing us to bail out and correctly report
51470+ the copy as invalid
51471+ */
51472+ if (obj + len <= frame)
51473+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
51474+ oldframe = frame;
51475+ frame = *(const void * const *)frame;
51476+ }
51477+ return -1;
51478+#else
51479+ return 1;
51480+#endif
51481+}
51482+
51483+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
51484+{
51485+ if (current->signal->curr_ip)
51486+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
51487+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
51488+ else
51489+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
51490+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
51491+ dump_stack();
51492+ gr_handle_kernel_exploit();
51493+ do_group_exit(SIGKILL);
51494+}
51495+#endif
51496+
51497+#ifdef CONFIG_PAX_USERCOPY
51498+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
51499+{
51500+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
51501+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
51502+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
51503+#else
51504+ unsigned long textlow = _stext;
51505+ unsigned long texthigh = _etext;
51506+#endif
51507+
51508+ if (high < textlow || low > texthigh)
51509+ return false;
51510+ else
51511+ return true;
51512+}
51513+#endif
51514+
51515+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
51516+{
51517+
51518+#ifdef CONFIG_PAX_USERCOPY
51519+ const char *type;
51520+
51521+ if (!n)
51522+ return;
51523+
51524+ type = check_heap_object(ptr, n);
51525+ if (!type) {
51526+ int ret = check_stack_object(ptr, n);
51527+ if (ret == 1 || ret == 2)
51528+ return;
51529+ if (ret == 0) {
51530+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
51531+ type = "<kernel text>";
51532+ else
51533+ return;
51534+ } else
51535+ type = "<process stack>";
51536+ }
51537+
51538+ pax_report_usercopy(ptr, n, to_user, type);
51539+#endif
51540+
51541+}
51542+EXPORT_SYMBOL(__check_object_size);
51543+
51544+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
51545+void pax_track_stack(void)
51546+{
51547+ unsigned long sp = (unsigned long)&sp;
51548+ if (sp < current_thread_info()->lowest_stack &&
51549+ sp > (unsigned long)task_stack_page(current))
51550+ current_thread_info()->lowest_stack = sp;
51551+}
51552+EXPORT_SYMBOL(pax_track_stack);
51553+#endif
51554+
51555+#ifdef CONFIG_PAX_SIZE_OVERFLOW
51556+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
51557+{
51558+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
51559+ dump_stack();
51560+ do_group_exit(SIGKILL);
51561+}
51562+EXPORT_SYMBOL(report_size_overflow);
51563+#endif
51564diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
51565index 2616d0e..2ffdec9 100644
51566--- a/fs/ext2/balloc.c
51567+++ b/fs/ext2/balloc.c
51568@@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
51569
51570 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
51571 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
51572- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
51573+ if (free_blocks < root_blocks + 1 &&
51574 !uid_eq(sbi->s_resuid, current_fsuid()) &&
51575 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
51576- !in_group_p (sbi->s_resgid))) {
51577+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
51578 return 0;
51579 }
51580 return 1;
51581diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
51582index 22548f5..41521d8 100644
51583--- a/fs/ext3/balloc.c
51584+++ b/fs/ext3/balloc.c
51585@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
51586
51587 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
51588 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
51589- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
51590+ if (free_blocks < root_blocks + 1 &&
51591 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
51592 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
51593- !in_group_p (sbi->s_resgid))) {
51594+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
51595 return 0;
51596 }
51597 return 1;
51598diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
51599index 92e68b3..115d987 100644
51600--- a/fs/ext4/balloc.c
51601+++ b/fs/ext4/balloc.c
51602@@ -505,8 +505,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
51603 /* Hm, nope. Are (enough) root reserved clusters available? */
51604 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
51605 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
51606- capable(CAP_SYS_RESOURCE) ||
51607- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
51608+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
51609+ capable_nolog(CAP_SYS_RESOURCE)) {
51610
51611 if (free_clusters >= (nclusters + dirty_clusters))
51612 return 1;
51613diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
51614index bbcd6a0..2824592 100644
51615--- a/fs/ext4/ext4.h
51616+++ b/fs/ext4/ext4.h
51617@@ -1265,19 +1265,19 @@ struct ext4_sb_info {
51618 unsigned long s_mb_last_start;
51619
51620 /* stats for buddy allocator */
51621- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
51622- atomic_t s_bal_success; /* we found long enough chunks */
51623- atomic_t s_bal_allocated; /* in blocks */
51624- atomic_t s_bal_ex_scanned; /* total extents scanned */
51625- atomic_t s_bal_goals; /* goal hits */
51626- atomic_t s_bal_breaks; /* too long searches */
51627- atomic_t s_bal_2orders; /* 2^order hits */
51628+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
51629+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
51630+ atomic_unchecked_t s_bal_allocated; /* in blocks */
51631+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
51632+ atomic_unchecked_t s_bal_goals; /* goal hits */
51633+ atomic_unchecked_t s_bal_breaks; /* too long searches */
51634+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
51635 spinlock_t s_bal_lock;
51636 unsigned long s_mb_buddies_generated;
51637 unsigned long long s_mb_generation_time;
51638- atomic_t s_mb_lost_chunks;
51639- atomic_t s_mb_preallocated;
51640- atomic_t s_mb_discarded;
51641+ atomic_unchecked_t s_mb_lost_chunks;
51642+ atomic_unchecked_t s_mb_preallocated;
51643+ atomic_unchecked_t s_mb_discarded;
51644 atomic_t s_lock_busy;
51645
51646 /* locality groups */
51647diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
51648index 82f8c2d..ce7c889 100644
51649--- a/fs/ext4/mballoc.c
51650+++ b/fs/ext4/mballoc.c
51651@@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
51652 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
51653
51654 if (EXT4_SB(sb)->s_mb_stats)
51655- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
51656+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
51657
51658 break;
51659 }
51660@@ -2044,7 +2044,7 @@ repeat:
51661 ac->ac_status = AC_STATUS_CONTINUE;
51662 ac->ac_flags |= EXT4_MB_HINT_FIRST;
51663 cr = 3;
51664- atomic_inc(&sbi->s_mb_lost_chunks);
51665+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
51666 goto repeat;
51667 }
51668 }
51669@@ -2552,25 +2552,25 @@ int ext4_mb_release(struct super_block *sb)
51670 if (sbi->s_mb_stats) {
51671 ext4_msg(sb, KERN_INFO,
51672 "mballoc: %u blocks %u reqs (%u success)",
51673- atomic_read(&sbi->s_bal_allocated),
51674- atomic_read(&sbi->s_bal_reqs),
51675- atomic_read(&sbi->s_bal_success));
51676+ atomic_read_unchecked(&sbi->s_bal_allocated),
51677+ atomic_read_unchecked(&sbi->s_bal_reqs),
51678+ atomic_read_unchecked(&sbi->s_bal_success));
51679 ext4_msg(sb, KERN_INFO,
51680 "mballoc: %u extents scanned, %u goal hits, "
51681 "%u 2^N hits, %u breaks, %u lost",
51682- atomic_read(&sbi->s_bal_ex_scanned),
51683- atomic_read(&sbi->s_bal_goals),
51684- atomic_read(&sbi->s_bal_2orders),
51685- atomic_read(&sbi->s_bal_breaks),
51686- atomic_read(&sbi->s_mb_lost_chunks));
51687+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
51688+ atomic_read_unchecked(&sbi->s_bal_goals),
51689+ atomic_read_unchecked(&sbi->s_bal_2orders),
51690+ atomic_read_unchecked(&sbi->s_bal_breaks),
51691+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
51692 ext4_msg(sb, KERN_INFO,
51693 "mballoc: %lu generated and it took %Lu",
51694 sbi->s_mb_buddies_generated,
51695 sbi->s_mb_generation_time);
51696 ext4_msg(sb, KERN_INFO,
51697 "mballoc: %u preallocated, %u discarded",
51698- atomic_read(&sbi->s_mb_preallocated),
51699- atomic_read(&sbi->s_mb_discarded));
51700+ atomic_read_unchecked(&sbi->s_mb_preallocated),
51701+ atomic_read_unchecked(&sbi->s_mb_discarded));
51702 }
51703
51704 free_percpu(sbi->s_locality_groups);
51705@@ -3060,16 +3060,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
51706 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
51707
51708 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
51709- atomic_inc(&sbi->s_bal_reqs);
51710- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
51711+ atomic_inc_unchecked(&sbi->s_bal_reqs);
51712+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
51713 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
51714- atomic_inc(&sbi->s_bal_success);
51715- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
51716+ atomic_inc_unchecked(&sbi->s_bal_success);
51717+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
51718 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
51719 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
51720- atomic_inc(&sbi->s_bal_goals);
51721+ atomic_inc_unchecked(&sbi->s_bal_goals);
51722 if (ac->ac_found > sbi->s_mb_max_to_scan)
51723- atomic_inc(&sbi->s_bal_breaks);
51724+ atomic_inc_unchecked(&sbi->s_bal_breaks);
51725 }
51726
51727 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
51728@@ -3469,7 +3469,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
51729 trace_ext4_mb_new_inode_pa(ac, pa);
51730
51731 ext4_mb_use_inode_pa(ac, pa);
51732- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
51733+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
51734
51735 ei = EXT4_I(ac->ac_inode);
51736 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
51737@@ -3529,7 +3529,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
51738 trace_ext4_mb_new_group_pa(ac, pa);
51739
51740 ext4_mb_use_group_pa(ac, pa);
51741- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
51742+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
51743
51744 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
51745 lg = ac->ac_lg;
51746@@ -3618,7 +3618,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
51747 * from the bitmap and continue.
51748 */
51749 }
51750- atomic_add(free, &sbi->s_mb_discarded);
51751+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
51752
51753 return err;
51754 }
51755@@ -3636,7 +3636,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
51756 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
51757 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
51758 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
51759- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
51760+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
51761 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
51762
51763 return 0;
51764diff --git a/fs/ext4/super.c b/fs/ext4/super.c
51765index 24c767d..893aa55 100644
51766--- a/fs/ext4/super.c
51767+++ b/fs/ext4/super.c
51768@@ -2429,7 +2429,7 @@ struct ext4_attr {
51769 ssize_t (*store)(struct ext4_attr *, struct ext4_sb_info *,
51770 const char *, size_t);
51771 int offset;
51772-};
51773+} __do_const;
51774
51775 static int parse_strtoul(const char *buf,
51776 unsigned long max, unsigned long *value)
51777diff --git a/fs/fcntl.c b/fs/fcntl.c
51778index 71a600a..20d87b1 100644
51779--- a/fs/fcntl.c
51780+++ b/fs/fcntl.c
51781@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
51782 if (err)
51783 return err;
51784
51785+ if (gr_handle_chroot_fowner(pid, type))
51786+ return -ENOENT;
51787+ if (gr_check_protected_task_fowner(pid, type))
51788+ return -EACCES;
51789+
51790 f_modown(filp, pid, type, force);
51791 return 0;
51792 }
51793diff --git a/fs/fhandle.c b/fs/fhandle.c
51794index 999ff5c..41f4109 100644
51795--- a/fs/fhandle.c
51796+++ b/fs/fhandle.c
51797@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
51798 } else
51799 retval = 0;
51800 /* copy the mount id */
51801- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
51802- sizeof(*mnt_id)) ||
51803+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
51804 copy_to_user(ufh, handle,
51805 sizeof(struct file_handle) + handle_bytes))
51806 retval = -EFAULT;
51807diff --git a/fs/fifo.c b/fs/fifo.c
51808index cf6f434..3d7942c 100644
51809--- a/fs/fifo.c
51810+++ b/fs/fifo.c
51811@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
51812 */
51813 filp->f_op = &read_pipefifo_fops;
51814 pipe->r_counter++;
51815- if (pipe->readers++ == 0)
51816+ if (atomic_inc_return(&pipe->readers) == 1)
51817 wake_up_partner(inode);
51818
51819- if (!pipe->writers) {
51820+ if (!atomic_read(&pipe->writers)) {
51821 if ((filp->f_flags & O_NONBLOCK)) {
51822 /* suppress POLLHUP until we have
51823 * seen a writer */
51824@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
51825 * errno=ENXIO when there is no process reading the FIFO.
51826 */
51827 ret = -ENXIO;
51828- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
51829+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
51830 goto err;
51831
51832 filp->f_op = &write_pipefifo_fops;
51833 pipe->w_counter++;
51834- if (!pipe->writers++)
51835+ if (atomic_inc_return(&pipe->writers) == 1)
51836 wake_up_partner(inode);
51837
51838- if (!pipe->readers) {
51839+ if (!atomic_read(&pipe->readers)) {
51840 if (wait_for_partner(inode, &pipe->r_counter))
51841 goto err_wr;
51842 }
51843@@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
51844 */
51845 filp->f_op = &rdwr_pipefifo_fops;
51846
51847- pipe->readers++;
51848- pipe->writers++;
51849+ atomic_inc(&pipe->readers);
51850+ atomic_inc(&pipe->writers);
51851 pipe->r_counter++;
51852 pipe->w_counter++;
51853- if (pipe->readers == 1 || pipe->writers == 1)
51854+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
51855 wake_up_partner(inode);
51856 break;
51857
51858@@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
51859 return 0;
51860
51861 err_rd:
51862- if (!--pipe->readers)
51863+ if (atomic_dec_and_test(&pipe->readers))
51864 wake_up_interruptible(&pipe->wait);
51865 ret = -ERESTARTSYS;
51866 goto err;
51867
51868 err_wr:
51869- if (!--pipe->writers)
51870+ if (atomic_dec_and_test(&pipe->writers))
51871 wake_up_interruptible(&pipe->wait);
51872 ret = -ERESTARTSYS;
51873 goto err;
51874
51875 err:
51876- if (!pipe->readers && !pipe->writers)
51877+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
51878 free_pipe_info(inode);
51879
51880 err_nocleanup:
51881diff --git a/fs/file.c b/fs/file.c
51882index 2b3570b..c57924b 100644
51883--- a/fs/file.c
51884+++ b/fs/file.c
51885@@ -16,6 +16,7 @@
51886 #include <linux/slab.h>
51887 #include <linux/vmalloc.h>
51888 #include <linux/file.h>
51889+#include <linux/security.h>
51890 #include <linux/fdtable.h>
51891 #include <linux/bitops.h>
51892 #include <linux/interrupt.h>
51893@@ -892,6 +893,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
51894 if (!file)
51895 return __close_fd(files, fd);
51896
51897+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
51898 if (fd >= rlimit(RLIMIT_NOFILE))
51899 return -EBADF;
51900
51901@@ -918,6 +920,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
51902 if (unlikely(oldfd == newfd))
51903 return -EINVAL;
51904
51905+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
51906 if (newfd >= rlimit(RLIMIT_NOFILE))
51907 return -EBADF;
51908
51909@@ -973,6 +976,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
51910 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
51911 {
51912 int err;
51913+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
51914 if (from >= rlimit(RLIMIT_NOFILE))
51915 return -EINVAL;
51916 err = alloc_fd(from, flags);
51917diff --git a/fs/filesystems.c b/fs/filesystems.c
51918index da165f6..3671bdb 100644
51919--- a/fs/filesystems.c
51920+++ b/fs/filesystems.c
51921@@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
51922 int len = dot ? dot - name : strlen(name);
51923
51924 fs = __get_fs_type(name, len);
51925+
51926+#ifdef CONFIG_GRKERNSEC_MODHARDEN
51927+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
51928+#else
51929 if (!fs && (request_module("%.*s", len, name) == 0))
51930+#endif
51931 fs = __get_fs_type(name, len);
51932
51933 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
51934diff --git a/fs/fs_struct.c b/fs/fs_struct.c
51935index fe6ca58..65318cf 100644
51936--- a/fs/fs_struct.c
51937+++ b/fs/fs_struct.c
51938@@ -4,6 +4,7 @@
51939 #include <linux/path.h>
51940 #include <linux/slab.h>
51941 #include <linux/fs_struct.h>
51942+#include <linux/grsecurity.h>
51943 #include "internal.h"
51944
51945 /*
51946@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
51947 write_seqcount_begin(&fs->seq);
51948 old_root = fs->root;
51949 fs->root = *path;
51950+ gr_set_chroot_entries(current, path);
51951 write_seqcount_end(&fs->seq);
51952 spin_unlock(&fs->lock);
51953 if (old_root.dentry)
51954@@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
51955 return 1;
51956 }
51957
51958+static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
51959+{
51960+ if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
51961+ return 0;
51962+ *p = *new;
51963+
51964+ /* This function is only called from pivot_root(). Leave our
51965+ gr_chroot_dentry and is_chrooted flags as-is, so that a
51966+ pivoted root isn't treated as a chroot
51967+ */
51968+ //gr_set_chroot_entries(task, new);
51969+
51970+ return 1;
51971+}
51972+
51973 void chroot_fs_refs(struct path *old_root, struct path *new_root)
51974 {
51975 struct task_struct *g, *p;
51976@@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
51977 int hits = 0;
51978 spin_lock(&fs->lock);
51979 write_seqcount_begin(&fs->seq);
51980- hits += replace_path(&fs->root, old_root, new_root);
51981+ hits += replace_root_path(p, &fs->root, old_root, new_root);
51982 hits += replace_path(&fs->pwd, old_root, new_root);
51983 write_seqcount_end(&fs->seq);
51984 while (hits--) {
51985@@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
51986 task_lock(tsk);
51987 spin_lock(&fs->lock);
51988 tsk->fs = NULL;
51989- kill = !--fs->users;
51990+ gr_clear_chroot_entries(tsk);
51991+ kill = !atomic_dec_return(&fs->users);
51992 spin_unlock(&fs->lock);
51993 task_unlock(tsk);
51994 if (kill)
51995@@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
51996 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
51997 /* We don't need to lock fs - think why ;-) */
51998 if (fs) {
51999- fs->users = 1;
52000+ atomic_set(&fs->users, 1);
52001 fs->in_exec = 0;
52002 spin_lock_init(&fs->lock);
52003 seqcount_init(&fs->seq);
52004@@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
52005 spin_lock(&old->lock);
52006 fs->root = old->root;
52007 path_get(&fs->root);
52008+ /* instead of calling gr_set_chroot_entries here,
52009+ we call it from every caller of this function
52010+ */
52011 fs->pwd = old->pwd;
52012 path_get(&fs->pwd);
52013 spin_unlock(&old->lock);
52014@@ -139,8 +160,9 @@ int unshare_fs_struct(void)
52015
52016 task_lock(current);
52017 spin_lock(&fs->lock);
52018- kill = !--fs->users;
52019+ kill = !atomic_dec_return(&fs->users);
52020 current->fs = new_fs;
52021+ gr_set_chroot_entries(current, &new_fs->root);
52022 spin_unlock(&fs->lock);
52023 task_unlock(current);
52024
52025@@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
52026
52027 int current_umask(void)
52028 {
52029- return current->fs->umask;
52030+ return current->fs->umask | gr_acl_umask();
52031 }
52032 EXPORT_SYMBOL(current_umask);
52033
52034 /* to be mentioned only in INIT_TASK */
52035 struct fs_struct init_fs = {
52036- .users = 1,
52037+ .users = ATOMIC_INIT(1),
52038 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
52039 .seq = SEQCNT_ZERO,
52040 .umask = 0022,
52041diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
52042index 8dcb114..b1072e2 100644
52043--- a/fs/fscache/cookie.c
52044+++ b/fs/fscache/cookie.c
52045@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
52046 parent ? (char *) parent->def->name : "<no-parent>",
52047 def->name, netfs_data);
52048
52049- fscache_stat(&fscache_n_acquires);
52050+ fscache_stat_unchecked(&fscache_n_acquires);
52051
52052 /* if there's no parent cookie, then we don't create one here either */
52053 if (!parent) {
52054- fscache_stat(&fscache_n_acquires_null);
52055+ fscache_stat_unchecked(&fscache_n_acquires_null);
52056 _leave(" [no parent]");
52057 return NULL;
52058 }
52059@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
52060 /* allocate and initialise a cookie */
52061 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
52062 if (!cookie) {
52063- fscache_stat(&fscache_n_acquires_oom);
52064+ fscache_stat_unchecked(&fscache_n_acquires_oom);
52065 _leave(" [ENOMEM]");
52066 return NULL;
52067 }
52068@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
52069
52070 switch (cookie->def->type) {
52071 case FSCACHE_COOKIE_TYPE_INDEX:
52072- fscache_stat(&fscache_n_cookie_index);
52073+ fscache_stat_unchecked(&fscache_n_cookie_index);
52074 break;
52075 case FSCACHE_COOKIE_TYPE_DATAFILE:
52076- fscache_stat(&fscache_n_cookie_data);
52077+ fscache_stat_unchecked(&fscache_n_cookie_data);
52078 break;
52079 default:
52080- fscache_stat(&fscache_n_cookie_special);
52081+ fscache_stat_unchecked(&fscache_n_cookie_special);
52082 break;
52083 }
52084
52085@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
52086 if (fscache_acquire_non_index_cookie(cookie) < 0) {
52087 atomic_dec(&parent->n_children);
52088 __fscache_cookie_put(cookie);
52089- fscache_stat(&fscache_n_acquires_nobufs);
52090+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
52091 _leave(" = NULL");
52092 return NULL;
52093 }
52094 }
52095
52096- fscache_stat(&fscache_n_acquires_ok);
52097+ fscache_stat_unchecked(&fscache_n_acquires_ok);
52098 _leave(" = %p", cookie);
52099 return cookie;
52100 }
52101@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
52102 cache = fscache_select_cache_for_object(cookie->parent);
52103 if (!cache) {
52104 up_read(&fscache_addremove_sem);
52105- fscache_stat(&fscache_n_acquires_no_cache);
52106+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
52107 _leave(" = -ENOMEDIUM [no cache]");
52108 return -ENOMEDIUM;
52109 }
52110@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
52111 object = cache->ops->alloc_object(cache, cookie);
52112 fscache_stat_d(&fscache_n_cop_alloc_object);
52113 if (IS_ERR(object)) {
52114- fscache_stat(&fscache_n_object_no_alloc);
52115+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
52116 ret = PTR_ERR(object);
52117 goto error;
52118 }
52119
52120- fscache_stat(&fscache_n_object_alloc);
52121+ fscache_stat_unchecked(&fscache_n_object_alloc);
52122
52123 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
52124
52125@@ -378,7 +378,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
52126
52127 _enter("{%s}", cookie->def->name);
52128
52129- fscache_stat(&fscache_n_invalidates);
52130+ fscache_stat_unchecked(&fscache_n_invalidates);
52131
52132 /* Only permit invalidation of data files. Invalidating an index will
52133 * require the caller to release all its attachments to the tree rooted
52134@@ -437,10 +437,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
52135 struct fscache_object *object;
52136 struct hlist_node *_p;
52137
52138- fscache_stat(&fscache_n_updates);
52139+ fscache_stat_unchecked(&fscache_n_updates);
52140
52141 if (!cookie) {
52142- fscache_stat(&fscache_n_updates_null);
52143+ fscache_stat_unchecked(&fscache_n_updates_null);
52144 _leave(" [no cookie]");
52145 return;
52146 }
52147@@ -474,12 +474,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
52148 struct fscache_object *object;
52149 unsigned long event;
52150
52151- fscache_stat(&fscache_n_relinquishes);
52152+ fscache_stat_unchecked(&fscache_n_relinquishes);
52153 if (retire)
52154- fscache_stat(&fscache_n_relinquishes_retire);
52155+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
52156
52157 if (!cookie) {
52158- fscache_stat(&fscache_n_relinquishes_null);
52159+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
52160 _leave(" [no cookie]");
52161 return;
52162 }
52163@@ -495,7 +495,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
52164
52165 /* wait for the cookie to finish being instantiated (or to fail) */
52166 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
52167- fscache_stat(&fscache_n_relinquishes_waitcrt);
52168+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
52169 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
52170 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
52171 }
52172diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
52173index ee38fef..0a326d4 100644
52174--- a/fs/fscache/internal.h
52175+++ b/fs/fscache/internal.h
52176@@ -148,101 +148,101 @@ extern void fscache_proc_cleanup(void);
52177 * stats.c
52178 */
52179 #ifdef CONFIG_FSCACHE_STATS
52180-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
52181-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
52182+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
52183+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
52184
52185-extern atomic_t fscache_n_op_pend;
52186-extern atomic_t fscache_n_op_run;
52187-extern atomic_t fscache_n_op_enqueue;
52188-extern atomic_t fscache_n_op_deferred_release;
52189-extern atomic_t fscache_n_op_release;
52190-extern atomic_t fscache_n_op_gc;
52191-extern atomic_t fscache_n_op_cancelled;
52192-extern atomic_t fscache_n_op_rejected;
52193+extern atomic_unchecked_t fscache_n_op_pend;
52194+extern atomic_unchecked_t fscache_n_op_run;
52195+extern atomic_unchecked_t fscache_n_op_enqueue;
52196+extern atomic_unchecked_t fscache_n_op_deferred_release;
52197+extern atomic_unchecked_t fscache_n_op_release;
52198+extern atomic_unchecked_t fscache_n_op_gc;
52199+extern atomic_unchecked_t fscache_n_op_cancelled;
52200+extern atomic_unchecked_t fscache_n_op_rejected;
52201
52202-extern atomic_t fscache_n_attr_changed;
52203-extern atomic_t fscache_n_attr_changed_ok;
52204-extern atomic_t fscache_n_attr_changed_nobufs;
52205-extern atomic_t fscache_n_attr_changed_nomem;
52206-extern atomic_t fscache_n_attr_changed_calls;
52207+extern atomic_unchecked_t fscache_n_attr_changed;
52208+extern atomic_unchecked_t fscache_n_attr_changed_ok;
52209+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
52210+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
52211+extern atomic_unchecked_t fscache_n_attr_changed_calls;
52212
52213-extern atomic_t fscache_n_allocs;
52214-extern atomic_t fscache_n_allocs_ok;
52215-extern atomic_t fscache_n_allocs_wait;
52216-extern atomic_t fscache_n_allocs_nobufs;
52217-extern atomic_t fscache_n_allocs_intr;
52218-extern atomic_t fscache_n_allocs_object_dead;
52219-extern atomic_t fscache_n_alloc_ops;
52220-extern atomic_t fscache_n_alloc_op_waits;
52221+extern atomic_unchecked_t fscache_n_allocs;
52222+extern atomic_unchecked_t fscache_n_allocs_ok;
52223+extern atomic_unchecked_t fscache_n_allocs_wait;
52224+extern atomic_unchecked_t fscache_n_allocs_nobufs;
52225+extern atomic_unchecked_t fscache_n_allocs_intr;
52226+extern atomic_unchecked_t fscache_n_allocs_object_dead;
52227+extern atomic_unchecked_t fscache_n_alloc_ops;
52228+extern atomic_unchecked_t fscache_n_alloc_op_waits;
52229
52230-extern atomic_t fscache_n_retrievals;
52231-extern atomic_t fscache_n_retrievals_ok;
52232-extern atomic_t fscache_n_retrievals_wait;
52233-extern atomic_t fscache_n_retrievals_nodata;
52234-extern atomic_t fscache_n_retrievals_nobufs;
52235-extern atomic_t fscache_n_retrievals_intr;
52236-extern atomic_t fscache_n_retrievals_nomem;
52237-extern atomic_t fscache_n_retrievals_object_dead;
52238-extern atomic_t fscache_n_retrieval_ops;
52239-extern atomic_t fscache_n_retrieval_op_waits;
52240+extern atomic_unchecked_t fscache_n_retrievals;
52241+extern atomic_unchecked_t fscache_n_retrievals_ok;
52242+extern atomic_unchecked_t fscache_n_retrievals_wait;
52243+extern atomic_unchecked_t fscache_n_retrievals_nodata;
52244+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
52245+extern atomic_unchecked_t fscache_n_retrievals_intr;
52246+extern atomic_unchecked_t fscache_n_retrievals_nomem;
52247+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
52248+extern atomic_unchecked_t fscache_n_retrieval_ops;
52249+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
52250
52251-extern atomic_t fscache_n_stores;
52252-extern atomic_t fscache_n_stores_ok;
52253-extern atomic_t fscache_n_stores_again;
52254-extern atomic_t fscache_n_stores_nobufs;
52255-extern atomic_t fscache_n_stores_oom;
52256-extern atomic_t fscache_n_store_ops;
52257-extern atomic_t fscache_n_store_calls;
52258-extern atomic_t fscache_n_store_pages;
52259-extern atomic_t fscache_n_store_radix_deletes;
52260-extern atomic_t fscache_n_store_pages_over_limit;
52261+extern atomic_unchecked_t fscache_n_stores;
52262+extern atomic_unchecked_t fscache_n_stores_ok;
52263+extern atomic_unchecked_t fscache_n_stores_again;
52264+extern atomic_unchecked_t fscache_n_stores_nobufs;
52265+extern atomic_unchecked_t fscache_n_stores_oom;
52266+extern atomic_unchecked_t fscache_n_store_ops;
52267+extern atomic_unchecked_t fscache_n_store_calls;
52268+extern atomic_unchecked_t fscache_n_store_pages;
52269+extern atomic_unchecked_t fscache_n_store_radix_deletes;
52270+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
52271
52272-extern atomic_t fscache_n_store_vmscan_not_storing;
52273-extern atomic_t fscache_n_store_vmscan_gone;
52274-extern atomic_t fscache_n_store_vmscan_busy;
52275-extern atomic_t fscache_n_store_vmscan_cancelled;
52276-extern atomic_t fscache_n_store_vmscan_wait;
52277+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
52278+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
52279+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
52280+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
52281+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
52282
52283-extern atomic_t fscache_n_marks;
52284-extern atomic_t fscache_n_uncaches;
52285+extern atomic_unchecked_t fscache_n_marks;
52286+extern atomic_unchecked_t fscache_n_uncaches;
52287
52288-extern atomic_t fscache_n_acquires;
52289-extern atomic_t fscache_n_acquires_null;
52290-extern atomic_t fscache_n_acquires_no_cache;
52291-extern atomic_t fscache_n_acquires_ok;
52292-extern atomic_t fscache_n_acquires_nobufs;
52293-extern atomic_t fscache_n_acquires_oom;
52294+extern atomic_unchecked_t fscache_n_acquires;
52295+extern atomic_unchecked_t fscache_n_acquires_null;
52296+extern atomic_unchecked_t fscache_n_acquires_no_cache;
52297+extern atomic_unchecked_t fscache_n_acquires_ok;
52298+extern atomic_unchecked_t fscache_n_acquires_nobufs;
52299+extern atomic_unchecked_t fscache_n_acquires_oom;
52300
52301-extern atomic_t fscache_n_invalidates;
52302-extern atomic_t fscache_n_invalidates_run;
52303+extern atomic_unchecked_t fscache_n_invalidates;
52304+extern atomic_unchecked_t fscache_n_invalidates_run;
52305
52306-extern atomic_t fscache_n_updates;
52307-extern atomic_t fscache_n_updates_null;
52308-extern atomic_t fscache_n_updates_run;
52309+extern atomic_unchecked_t fscache_n_updates;
52310+extern atomic_unchecked_t fscache_n_updates_null;
52311+extern atomic_unchecked_t fscache_n_updates_run;
52312
52313-extern atomic_t fscache_n_relinquishes;
52314-extern atomic_t fscache_n_relinquishes_null;
52315-extern atomic_t fscache_n_relinquishes_waitcrt;
52316-extern atomic_t fscache_n_relinquishes_retire;
52317+extern atomic_unchecked_t fscache_n_relinquishes;
52318+extern atomic_unchecked_t fscache_n_relinquishes_null;
52319+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
52320+extern atomic_unchecked_t fscache_n_relinquishes_retire;
52321
52322-extern atomic_t fscache_n_cookie_index;
52323-extern atomic_t fscache_n_cookie_data;
52324-extern atomic_t fscache_n_cookie_special;
52325+extern atomic_unchecked_t fscache_n_cookie_index;
52326+extern atomic_unchecked_t fscache_n_cookie_data;
52327+extern atomic_unchecked_t fscache_n_cookie_special;
52328
52329-extern atomic_t fscache_n_object_alloc;
52330-extern atomic_t fscache_n_object_no_alloc;
52331-extern atomic_t fscache_n_object_lookups;
52332-extern atomic_t fscache_n_object_lookups_negative;
52333-extern atomic_t fscache_n_object_lookups_positive;
52334-extern atomic_t fscache_n_object_lookups_timed_out;
52335-extern atomic_t fscache_n_object_created;
52336-extern atomic_t fscache_n_object_avail;
52337-extern atomic_t fscache_n_object_dead;
52338+extern atomic_unchecked_t fscache_n_object_alloc;
52339+extern atomic_unchecked_t fscache_n_object_no_alloc;
52340+extern atomic_unchecked_t fscache_n_object_lookups;
52341+extern atomic_unchecked_t fscache_n_object_lookups_negative;
52342+extern atomic_unchecked_t fscache_n_object_lookups_positive;
52343+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
52344+extern atomic_unchecked_t fscache_n_object_created;
52345+extern atomic_unchecked_t fscache_n_object_avail;
52346+extern atomic_unchecked_t fscache_n_object_dead;
52347
52348-extern atomic_t fscache_n_checkaux_none;
52349-extern atomic_t fscache_n_checkaux_okay;
52350-extern atomic_t fscache_n_checkaux_update;
52351-extern atomic_t fscache_n_checkaux_obsolete;
52352+extern atomic_unchecked_t fscache_n_checkaux_none;
52353+extern atomic_unchecked_t fscache_n_checkaux_okay;
52354+extern atomic_unchecked_t fscache_n_checkaux_update;
52355+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
52356
52357 extern atomic_t fscache_n_cop_alloc_object;
52358 extern atomic_t fscache_n_cop_lookup_object;
52359@@ -267,6 +267,11 @@ static inline void fscache_stat(atomic_t *stat)
52360 atomic_inc(stat);
52361 }
52362
52363+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
52364+{
52365+ atomic_inc_unchecked(stat);
52366+}
52367+
52368 static inline void fscache_stat_d(atomic_t *stat)
52369 {
52370 atomic_dec(stat);
52371@@ -279,6 +284,7 @@ extern const struct file_operations fscache_stats_fops;
52372
52373 #define __fscache_stat(stat) (NULL)
52374 #define fscache_stat(stat) do {} while (0)
52375+#define fscache_stat_unchecked(stat) do {} while (0)
52376 #define fscache_stat_d(stat) do {} while (0)
52377 #endif
52378
52379diff --git a/fs/fscache/object.c b/fs/fscache/object.c
52380index 50d41c1..10ee117 100644
52381--- a/fs/fscache/object.c
52382+++ b/fs/fscache/object.c
52383@@ -143,7 +143,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52384 /* Invalidate an object on disk */
52385 case FSCACHE_OBJECT_INVALIDATING:
52386 clear_bit(FSCACHE_OBJECT_EV_INVALIDATE, &object->events);
52387- fscache_stat(&fscache_n_invalidates_run);
52388+ fscache_stat_unchecked(&fscache_n_invalidates_run);
52389 fscache_stat(&fscache_n_cop_invalidate_object);
52390 fscache_invalidate_object(object);
52391 fscache_stat_d(&fscache_n_cop_invalidate_object);
52392@@ -153,7 +153,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52393 /* update the object metadata on disk */
52394 case FSCACHE_OBJECT_UPDATING:
52395 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
52396- fscache_stat(&fscache_n_updates_run);
52397+ fscache_stat_unchecked(&fscache_n_updates_run);
52398 fscache_stat(&fscache_n_cop_update_object);
52399 object->cache->ops->update_object(object);
52400 fscache_stat_d(&fscache_n_cop_update_object);
52401@@ -242,7 +242,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52402 spin_lock(&object->lock);
52403 object->state = FSCACHE_OBJECT_DEAD;
52404 spin_unlock(&object->lock);
52405- fscache_stat(&fscache_n_object_dead);
52406+ fscache_stat_unchecked(&fscache_n_object_dead);
52407 goto terminal_transit;
52408
52409 /* handle the parent cache of this object being withdrawn from
52410@@ -257,7 +257,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52411 spin_lock(&object->lock);
52412 object->state = FSCACHE_OBJECT_DEAD;
52413 spin_unlock(&object->lock);
52414- fscache_stat(&fscache_n_object_dead);
52415+ fscache_stat_unchecked(&fscache_n_object_dead);
52416 goto terminal_transit;
52417
52418 /* complain about the object being woken up once it is
52419@@ -495,7 +495,7 @@ static void fscache_lookup_object(struct fscache_object *object)
52420 parent->cookie->def->name, cookie->def->name,
52421 object->cache->tag->name);
52422
52423- fscache_stat(&fscache_n_object_lookups);
52424+ fscache_stat_unchecked(&fscache_n_object_lookups);
52425 fscache_stat(&fscache_n_cop_lookup_object);
52426 ret = object->cache->ops->lookup_object(object);
52427 fscache_stat_d(&fscache_n_cop_lookup_object);
52428@@ -506,7 +506,7 @@ static void fscache_lookup_object(struct fscache_object *object)
52429 if (ret == -ETIMEDOUT) {
52430 /* probably stuck behind another object, so move this one to
52431 * the back of the queue */
52432- fscache_stat(&fscache_n_object_lookups_timed_out);
52433+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
52434 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
52435 }
52436
52437@@ -529,7 +529,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
52438
52439 spin_lock(&object->lock);
52440 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
52441- fscache_stat(&fscache_n_object_lookups_negative);
52442+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
52443
52444 /* transit here to allow write requests to begin stacking up
52445 * and read requests to begin returning ENODATA */
52446@@ -575,7 +575,7 @@ void fscache_obtained_object(struct fscache_object *object)
52447 * result, in which case there may be data available */
52448 spin_lock(&object->lock);
52449 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
52450- fscache_stat(&fscache_n_object_lookups_positive);
52451+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
52452
52453 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
52454
52455@@ -589,7 +589,7 @@ void fscache_obtained_object(struct fscache_object *object)
52456 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
52457 } else {
52458 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
52459- fscache_stat(&fscache_n_object_created);
52460+ fscache_stat_unchecked(&fscache_n_object_created);
52461
52462 object->state = FSCACHE_OBJECT_AVAILABLE;
52463 spin_unlock(&object->lock);
52464@@ -634,7 +634,7 @@ static void fscache_object_available(struct fscache_object *object)
52465 fscache_enqueue_dependents(object);
52466
52467 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
52468- fscache_stat(&fscache_n_object_avail);
52469+ fscache_stat_unchecked(&fscache_n_object_avail);
52470
52471 _leave("");
52472 }
52473@@ -894,7 +894,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
52474 enum fscache_checkaux result;
52475
52476 if (!object->cookie->def->check_aux) {
52477- fscache_stat(&fscache_n_checkaux_none);
52478+ fscache_stat_unchecked(&fscache_n_checkaux_none);
52479 return FSCACHE_CHECKAUX_OKAY;
52480 }
52481
52482@@ -903,17 +903,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
52483 switch (result) {
52484 /* entry okay as is */
52485 case FSCACHE_CHECKAUX_OKAY:
52486- fscache_stat(&fscache_n_checkaux_okay);
52487+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
52488 break;
52489
52490 /* entry requires update */
52491 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
52492- fscache_stat(&fscache_n_checkaux_update);
52493+ fscache_stat_unchecked(&fscache_n_checkaux_update);
52494 break;
52495
52496 /* entry requires deletion */
52497 case FSCACHE_CHECKAUX_OBSOLETE:
52498- fscache_stat(&fscache_n_checkaux_obsolete);
52499+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
52500 break;
52501
52502 default:
52503diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
52504index 762a9ec..2023284 100644
52505--- a/fs/fscache/operation.c
52506+++ b/fs/fscache/operation.c
52507@@ -17,7 +17,7 @@
52508 #include <linux/slab.h>
52509 #include "internal.h"
52510
52511-atomic_t fscache_op_debug_id;
52512+atomic_unchecked_t fscache_op_debug_id;
52513 EXPORT_SYMBOL(fscache_op_debug_id);
52514
52515 /**
52516@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
52517 ASSERTCMP(atomic_read(&op->usage), >, 0);
52518 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
52519
52520- fscache_stat(&fscache_n_op_enqueue);
52521+ fscache_stat_unchecked(&fscache_n_op_enqueue);
52522 switch (op->flags & FSCACHE_OP_TYPE) {
52523 case FSCACHE_OP_ASYNC:
52524 _debug("queue async");
52525@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
52526 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
52527 if (op->processor)
52528 fscache_enqueue_operation(op);
52529- fscache_stat(&fscache_n_op_run);
52530+ fscache_stat_unchecked(&fscache_n_op_run);
52531 }
52532
52533 /*
52534@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
52535 if (object->n_in_progress > 0) {
52536 atomic_inc(&op->usage);
52537 list_add_tail(&op->pend_link, &object->pending_ops);
52538- fscache_stat(&fscache_n_op_pend);
52539+ fscache_stat_unchecked(&fscache_n_op_pend);
52540 } else if (!list_empty(&object->pending_ops)) {
52541 atomic_inc(&op->usage);
52542 list_add_tail(&op->pend_link, &object->pending_ops);
52543- fscache_stat(&fscache_n_op_pend);
52544+ fscache_stat_unchecked(&fscache_n_op_pend);
52545 fscache_start_operations(object);
52546 } else {
52547 ASSERTCMP(object->n_in_progress, ==, 0);
52548@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
52549 object->n_exclusive++; /* reads and writes must wait */
52550 atomic_inc(&op->usage);
52551 list_add_tail(&op->pend_link, &object->pending_ops);
52552- fscache_stat(&fscache_n_op_pend);
52553+ fscache_stat_unchecked(&fscache_n_op_pend);
52554 ret = 0;
52555 } else {
52556 /* If we're in any other state, there must have been an I/O
52557@@ -215,11 +215,11 @@ int fscache_submit_op(struct fscache_object *object,
52558 if (object->n_exclusive > 0) {
52559 atomic_inc(&op->usage);
52560 list_add_tail(&op->pend_link, &object->pending_ops);
52561- fscache_stat(&fscache_n_op_pend);
52562+ fscache_stat_unchecked(&fscache_n_op_pend);
52563 } else if (!list_empty(&object->pending_ops)) {
52564 atomic_inc(&op->usage);
52565 list_add_tail(&op->pend_link, &object->pending_ops);
52566- fscache_stat(&fscache_n_op_pend);
52567+ fscache_stat_unchecked(&fscache_n_op_pend);
52568 fscache_start_operations(object);
52569 } else {
52570 ASSERTCMP(object->n_exclusive, ==, 0);
52571@@ -231,12 +231,12 @@ int fscache_submit_op(struct fscache_object *object,
52572 object->n_ops++;
52573 atomic_inc(&op->usage);
52574 list_add_tail(&op->pend_link, &object->pending_ops);
52575- fscache_stat(&fscache_n_op_pend);
52576+ fscache_stat_unchecked(&fscache_n_op_pend);
52577 ret = 0;
52578 } else if (object->state == FSCACHE_OBJECT_DYING ||
52579 object->state == FSCACHE_OBJECT_LC_DYING ||
52580 object->state == FSCACHE_OBJECT_WITHDRAWING) {
52581- fscache_stat(&fscache_n_op_rejected);
52582+ fscache_stat_unchecked(&fscache_n_op_rejected);
52583 op->state = FSCACHE_OP_ST_CANCELLED;
52584 ret = -ENOBUFS;
52585 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
52586@@ -315,7 +315,7 @@ int fscache_cancel_op(struct fscache_operation *op,
52587 ret = -EBUSY;
52588 if (op->state == FSCACHE_OP_ST_PENDING) {
52589 ASSERT(!list_empty(&op->pend_link));
52590- fscache_stat(&fscache_n_op_cancelled);
52591+ fscache_stat_unchecked(&fscache_n_op_cancelled);
52592 list_del_init(&op->pend_link);
52593 if (do_cancel)
52594 do_cancel(op);
52595@@ -347,7 +347,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
52596 while (!list_empty(&object->pending_ops)) {
52597 op = list_entry(object->pending_ops.next,
52598 struct fscache_operation, pend_link);
52599- fscache_stat(&fscache_n_op_cancelled);
52600+ fscache_stat_unchecked(&fscache_n_op_cancelled);
52601 list_del_init(&op->pend_link);
52602
52603 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
52604@@ -419,7 +419,7 @@ void fscache_put_operation(struct fscache_operation *op)
52605 op->state, ==, FSCACHE_OP_ST_CANCELLED);
52606 op->state = FSCACHE_OP_ST_DEAD;
52607
52608- fscache_stat(&fscache_n_op_release);
52609+ fscache_stat_unchecked(&fscache_n_op_release);
52610
52611 if (op->release) {
52612 op->release(op);
52613@@ -442,7 +442,7 @@ void fscache_put_operation(struct fscache_operation *op)
52614 * lock, and defer it otherwise */
52615 if (!spin_trylock(&object->lock)) {
52616 _debug("defer put");
52617- fscache_stat(&fscache_n_op_deferred_release);
52618+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
52619
52620 cache = object->cache;
52621 spin_lock(&cache->op_gc_list_lock);
52622@@ -495,7 +495,7 @@ void fscache_operation_gc(struct work_struct *work)
52623
52624 _debug("GC DEFERRED REL OBJ%x OP%x",
52625 object->debug_id, op->debug_id);
52626- fscache_stat(&fscache_n_op_gc);
52627+ fscache_stat_unchecked(&fscache_n_op_gc);
52628
52629 ASSERTCMP(atomic_read(&op->usage), ==, 0);
52630 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
52631diff --git a/fs/fscache/page.c b/fs/fscache/page.c
52632index ff000e5..c44ec6d 100644
52633--- a/fs/fscache/page.c
52634+++ b/fs/fscache/page.c
52635@@ -61,7 +61,7 @@ try_again:
52636 val = radix_tree_lookup(&cookie->stores, page->index);
52637 if (!val) {
52638 rcu_read_unlock();
52639- fscache_stat(&fscache_n_store_vmscan_not_storing);
52640+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
52641 __fscache_uncache_page(cookie, page);
52642 return true;
52643 }
52644@@ -91,11 +91,11 @@ try_again:
52645 spin_unlock(&cookie->stores_lock);
52646
52647 if (xpage) {
52648- fscache_stat(&fscache_n_store_vmscan_cancelled);
52649- fscache_stat(&fscache_n_store_radix_deletes);
52650+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
52651+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
52652 ASSERTCMP(xpage, ==, page);
52653 } else {
52654- fscache_stat(&fscache_n_store_vmscan_gone);
52655+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
52656 }
52657
52658 wake_up_bit(&cookie->flags, 0);
52659@@ -110,11 +110,11 @@ page_busy:
52660 * sleeping on memory allocation, so we may need to impose a timeout
52661 * too. */
52662 if (!(gfp & __GFP_WAIT)) {
52663- fscache_stat(&fscache_n_store_vmscan_busy);
52664+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
52665 return false;
52666 }
52667
52668- fscache_stat(&fscache_n_store_vmscan_wait);
52669+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
52670 __fscache_wait_on_page_write(cookie, page);
52671 gfp &= ~__GFP_WAIT;
52672 goto try_again;
52673@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
52674 FSCACHE_COOKIE_STORING_TAG);
52675 if (!radix_tree_tag_get(&cookie->stores, page->index,
52676 FSCACHE_COOKIE_PENDING_TAG)) {
52677- fscache_stat(&fscache_n_store_radix_deletes);
52678+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
52679 xpage = radix_tree_delete(&cookie->stores, page->index);
52680 }
52681 spin_unlock(&cookie->stores_lock);
52682@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
52683
52684 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
52685
52686- fscache_stat(&fscache_n_attr_changed_calls);
52687+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
52688
52689 if (fscache_object_is_active(object)) {
52690 fscache_stat(&fscache_n_cop_attr_changed);
52691@@ -187,11 +187,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
52692
52693 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52694
52695- fscache_stat(&fscache_n_attr_changed);
52696+ fscache_stat_unchecked(&fscache_n_attr_changed);
52697
52698 op = kzalloc(sizeof(*op), GFP_KERNEL);
52699 if (!op) {
52700- fscache_stat(&fscache_n_attr_changed_nomem);
52701+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
52702 _leave(" = -ENOMEM");
52703 return -ENOMEM;
52704 }
52705@@ -209,7 +209,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
52706 if (fscache_submit_exclusive_op(object, op) < 0)
52707 goto nobufs;
52708 spin_unlock(&cookie->lock);
52709- fscache_stat(&fscache_n_attr_changed_ok);
52710+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
52711 fscache_put_operation(op);
52712 _leave(" = 0");
52713 return 0;
52714@@ -217,7 +217,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
52715 nobufs:
52716 spin_unlock(&cookie->lock);
52717 kfree(op);
52718- fscache_stat(&fscache_n_attr_changed_nobufs);
52719+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
52720 _leave(" = %d", -ENOBUFS);
52721 return -ENOBUFS;
52722 }
52723@@ -255,7 +255,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
52724 /* allocate a retrieval operation and attempt to submit it */
52725 op = kzalloc(sizeof(*op), GFP_NOIO);
52726 if (!op) {
52727- fscache_stat(&fscache_n_retrievals_nomem);
52728+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52729 return NULL;
52730 }
52731
52732@@ -283,13 +283,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
52733 return 0;
52734 }
52735
52736- fscache_stat(&fscache_n_retrievals_wait);
52737+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
52738
52739 jif = jiffies;
52740 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
52741 fscache_wait_bit_interruptible,
52742 TASK_INTERRUPTIBLE) != 0) {
52743- fscache_stat(&fscache_n_retrievals_intr);
52744+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52745 _leave(" = -ERESTARTSYS");
52746 return -ERESTARTSYS;
52747 }
52748@@ -318,8 +318,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
52749 */
52750 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
52751 struct fscache_retrieval *op,
52752- atomic_t *stat_op_waits,
52753- atomic_t *stat_object_dead)
52754+ atomic_unchecked_t *stat_op_waits,
52755+ atomic_unchecked_t *stat_object_dead)
52756 {
52757 int ret;
52758
52759@@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
52760 goto check_if_dead;
52761
52762 _debug(">>> WT");
52763- fscache_stat(stat_op_waits);
52764+ fscache_stat_unchecked(stat_op_waits);
52765 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
52766 fscache_wait_bit_interruptible,
52767 TASK_INTERRUPTIBLE) != 0) {
52768@@ -344,14 +344,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
52769
52770 check_if_dead:
52771 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
52772- fscache_stat(stat_object_dead);
52773+ fscache_stat_unchecked(stat_object_dead);
52774 _leave(" = -ENOBUFS [cancelled]");
52775 return -ENOBUFS;
52776 }
52777 if (unlikely(fscache_object_is_dead(object))) {
52778 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
52779 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
52780- fscache_stat(stat_object_dead);
52781+ fscache_stat_unchecked(stat_object_dead);
52782 return -ENOBUFS;
52783 }
52784 return 0;
52785@@ -378,7 +378,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
52786
52787 _enter("%p,%p,,,", cookie, page);
52788
52789- fscache_stat(&fscache_n_retrievals);
52790+ fscache_stat_unchecked(&fscache_n_retrievals);
52791
52792 if (hlist_empty(&cookie->backing_objects))
52793 goto nobufs;
52794@@ -417,7 +417,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
52795 goto nobufs_unlock_dec;
52796 spin_unlock(&cookie->lock);
52797
52798- fscache_stat(&fscache_n_retrieval_ops);
52799+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
52800
52801 /* pin the netfs read context in case we need to do the actual netfs
52802 * read because we've encountered a cache read failure */
52803@@ -447,15 +447,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
52804
52805 error:
52806 if (ret == -ENOMEM)
52807- fscache_stat(&fscache_n_retrievals_nomem);
52808+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52809 else if (ret == -ERESTARTSYS)
52810- fscache_stat(&fscache_n_retrievals_intr);
52811+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52812 else if (ret == -ENODATA)
52813- fscache_stat(&fscache_n_retrievals_nodata);
52814+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
52815 else if (ret < 0)
52816- fscache_stat(&fscache_n_retrievals_nobufs);
52817+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52818 else
52819- fscache_stat(&fscache_n_retrievals_ok);
52820+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
52821
52822 fscache_put_retrieval(op);
52823 _leave(" = %d", ret);
52824@@ -467,7 +467,7 @@ nobufs_unlock:
52825 spin_unlock(&cookie->lock);
52826 kfree(op);
52827 nobufs:
52828- fscache_stat(&fscache_n_retrievals_nobufs);
52829+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52830 _leave(" = -ENOBUFS");
52831 return -ENOBUFS;
52832 }
52833@@ -505,7 +505,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52834
52835 _enter("%p,,%d,,,", cookie, *nr_pages);
52836
52837- fscache_stat(&fscache_n_retrievals);
52838+ fscache_stat_unchecked(&fscache_n_retrievals);
52839
52840 if (hlist_empty(&cookie->backing_objects))
52841 goto nobufs;
52842@@ -541,7 +541,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52843 goto nobufs_unlock_dec;
52844 spin_unlock(&cookie->lock);
52845
52846- fscache_stat(&fscache_n_retrieval_ops);
52847+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
52848
52849 /* pin the netfs read context in case we need to do the actual netfs
52850 * read because we've encountered a cache read failure */
52851@@ -571,15 +571,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52852
52853 error:
52854 if (ret == -ENOMEM)
52855- fscache_stat(&fscache_n_retrievals_nomem);
52856+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52857 else if (ret == -ERESTARTSYS)
52858- fscache_stat(&fscache_n_retrievals_intr);
52859+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52860 else if (ret == -ENODATA)
52861- fscache_stat(&fscache_n_retrievals_nodata);
52862+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
52863 else if (ret < 0)
52864- fscache_stat(&fscache_n_retrievals_nobufs);
52865+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52866 else
52867- fscache_stat(&fscache_n_retrievals_ok);
52868+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
52869
52870 fscache_put_retrieval(op);
52871 _leave(" = %d", ret);
52872@@ -591,7 +591,7 @@ nobufs_unlock:
52873 spin_unlock(&cookie->lock);
52874 kfree(op);
52875 nobufs:
52876- fscache_stat(&fscache_n_retrievals_nobufs);
52877+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52878 _leave(" = -ENOBUFS");
52879 return -ENOBUFS;
52880 }
52881@@ -615,7 +615,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52882
52883 _enter("%p,%p,,,", cookie, page);
52884
52885- fscache_stat(&fscache_n_allocs);
52886+ fscache_stat_unchecked(&fscache_n_allocs);
52887
52888 if (hlist_empty(&cookie->backing_objects))
52889 goto nobufs;
52890@@ -647,7 +647,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52891 goto nobufs_unlock;
52892 spin_unlock(&cookie->lock);
52893
52894- fscache_stat(&fscache_n_alloc_ops);
52895+ fscache_stat_unchecked(&fscache_n_alloc_ops);
52896
52897 ret = fscache_wait_for_retrieval_activation(
52898 object, op,
52899@@ -663,11 +663,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52900
52901 error:
52902 if (ret == -ERESTARTSYS)
52903- fscache_stat(&fscache_n_allocs_intr);
52904+ fscache_stat_unchecked(&fscache_n_allocs_intr);
52905 else if (ret < 0)
52906- fscache_stat(&fscache_n_allocs_nobufs);
52907+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
52908 else
52909- fscache_stat(&fscache_n_allocs_ok);
52910+ fscache_stat_unchecked(&fscache_n_allocs_ok);
52911
52912 fscache_put_retrieval(op);
52913 _leave(" = %d", ret);
52914@@ -677,7 +677,7 @@ nobufs_unlock:
52915 spin_unlock(&cookie->lock);
52916 kfree(op);
52917 nobufs:
52918- fscache_stat(&fscache_n_allocs_nobufs);
52919+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
52920 _leave(" = -ENOBUFS");
52921 return -ENOBUFS;
52922 }
52923@@ -736,7 +736,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52924
52925 spin_lock(&cookie->stores_lock);
52926
52927- fscache_stat(&fscache_n_store_calls);
52928+ fscache_stat_unchecked(&fscache_n_store_calls);
52929
52930 /* find a page to store */
52931 page = NULL;
52932@@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52933 page = results[0];
52934 _debug("gang %d [%lx]", n, page->index);
52935 if (page->index > op->store_limit) {
52936- fscache_stat(&fscache_n_store_pages_over_limit);
52937+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
52938 goto superseded;
52939 }
52940
52941@@ -759,7 +759,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52942 spin_unlock(&cookie->stores_lock);
52943 spin_unlock(&object->lock);
52944
52945- fscache_stat(&fscache_n_store_pages);
52946+ fscache_stat_unchecked(&fscache_n_store_pages);
52947 fscache_stat(&fscache_n_cop_write_page);
52948 ret = object->cache->ops->write_page(op, page);
52949 fscache_stat_d(&fscache_n_cop_write_page);
52950@@ -860,7 +860,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52951 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52952 ASSERT(PageFsCache(page));
52953
52954- fscache_stat(&fscache_n_stores);
52955+ fscache_stat_unchecked(&fscache_n_stores);
52956
52957 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
52958 _leave(" = -ENOBUFS [invalidating]");
52959@@ -916,7 +916,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52960 spin_unlock(&cookie->stores_lock);
52961 spin_unlock(&object->lock);
52962
52963- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
52964+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
52965 op->store_limit = object->store_limit;
52966
52967 if (fscache_submit_op(object, &op->op) < 0)
52968@@ -924,8 +924,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52969
52970 spin_unlock(&cookie->lock);
52971 radix_tree_preload_end();
52972- fscache_stat(&fscache_n_store_ops);
52973- fscache_stat(&fscache_n_stores_ok);
52974+ fscache_stat_unchecked(&fscache_n_store_ops);
52975+ fscache_stat_unchecked(&fscache_n_stores_ok);
52976
52977 /* the work queue now carries its own ref on the object */
52978 fscache_put_operation(&op->op);
52979@@ -933,14 +933,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52980 return 0;
52981
52982 already_queued:
52983- fscache_stat(&fscache_n_stores_again);
52984+ fscache_stat_unchecked(&fscache_n_stores_again);
52985 already_pending:
52986 spin_unlock(&cookie->stores_lock);
52987 spin_unlock(&object->lock);
52988 spin_unlock(&cookie->lock);
52989 radix_tree_preload_end();
52990 kfree(op);
52991- fscache_stat(&fscache_n_stores_ok);
52992+ fscache_stat_unchecked(&fscache_n_stores_ok);
52993 _leave(" = 0");
52994 return 0;
52995
52996@@ -959,14 +959,14 @@ nobufs:
52997 spin_unlock(&cookie->lock);
52998 radix_tree_preload_end();
52999 kfree(op);
53000- fscache_stat(&fscache_n_stores_nobufs);
53001+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
53002 _leave(" = -ENOBUFS");
53003 return -ENOBUFS;
53004
53005 nomem_free:
53006 kfree(op);
53007 nomem:
53008- fscache_stat(&fscache_n_stores_oom);
53009+ fscache_stat_unchecked(&fscache_n_stores_oom);
53010 _leave(" = -ENOMEM");
53011 return -ENOMEM;
53012 }
53013@@ -984,7 +984,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
53014 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
53015 ASSERTCMP(page, !=, NULL);
53016
53017- fscache_stat(&fscache_n_uncaches);
53018+ fscache_stat_unchecked(&fscache_n_uncaches);
53019
53020 /* cache withdrawal may beat us to it */
53021 if (!PageFsCache(page))
53022@@ -1035,7 +1035,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
53023 struct fscache_cookie *cookie = op->op.object->cookie;
53024
53025 #ifdef CONFIG_FSCACHE_STATS
53026- atomic_inc(&fscache_n_marks);
53027+ atomic_inc_unchecked(&fscache_n_marks);
53028 #endif
53029
53030 _debug("- mark %p{%lx}", page, page->index);
53031diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
53032index 8179e8b..5072cc7 100644
53033--- a/fs/fscache/stats.c
53034+++ b/fs/fscache/stats.c
53035@@ -18,99 +18,99 @@
53036 /*
53037 * operation counters
53038 */
53039-atomic_t fscache_n_op_pend;
53040-atomic_t fscache_n_op_run;
53041-atomic_t fscache_n_op_enqueue;
53042-atomic_t fscache_n_op_requeue;
53043-atomic_t fscache_n_op_deferred_release;
53044-atomic_t fscache_n_op_release;
53045-atomic_t fscache_n_op_gc;
53046-atomic_t fscache_n_op_cancelled;
53047-atomic_t fscache_n_op_rejected;
53048+atomic_unchecked_t fscache_n_op_pend;
53049+atomic_unchecked_t fscache_n_op_run;
53050+atomic_unchecked_t fscache_n_op_enqueue;
53051+atomic_unchecked_t fscache_n_op_requeue;
53052+atomic_unchecked_t fscache_n_op_deferred_release;
53053+atomic_unchecked_t fscache_n_op_release;
53054+atomic_unchecked_t fscache_n_op_gc;
53055+atomic_unchecked_t fscache_n_op_cancelled;
53056+atomic_unchecked_t fscache_n_op_rejected;
53057
53058-atomic_t fscache_n_attr_changed;
53059-atomic_t fscache_n_attr_changed_ok;
53060-atomic_t fscache_n_attr_changed_nobufs;
53061-atomic_t fscache_n_attr_changed_nomem;
53062-atomic_t fscache_n_attr_changed_calls;
53063+atomic_unchecked_t fscache_n_attr_changed;
53064+atomic_unchecked_t fscache_n_attr_changed_ok;
53065+atomic_unchecked_t fscache_n_attr_changed_nobufs;
53066+atomic_unchecked_t fscache_n_attr_changed_nomem;
53067+atomic_unchecked_t fscache_n_attr_changed_calls;
53068
53069-atomic_t fscache_n_allocs;
53070-atomic_t fscache_n_allocs_ok;
53071-atomic_t fscache_n_allocs_wait;
53072-atomic_t fscache_n_allocs_nobufs;
53073-atomic_t fscache_n_allocs_intr;
53074-atomic_t fscache_n_allocs_object_dead;
53075-atomic_t fscache_n_alloc_ops;
53076-atomic_t fscache_n_alloc_op_waits;
53077+atomic_unchecked_t fscache_n_allocs;
53078+atomic_unchecked_t fscache_n_allocs_ok;
53079+atomic_unchecked_t fscache_n_allocs_wait;
53080+atomic_unchecked_t fscache_n_allocs_nobufs;
53081+atomic_unchecked_t fscache_n_allocs_intr;
53082+atomic_unchecked_t fscache_n_allocs_object_dead;
53083+atomic_unchecked_t fscache_n_alloc_ops;
53084+atomic_unchecked_t fscache_n_alloc_op_waits;
53085
53086-atomic_t fscache_n_retrievals;
53087-atomic_t fscache_n_retrievals_ok;
53088-atomic_t fscache_n_retrievals_wait;
53089-atomic_t fscache_n_retrievals_nodata;
53090-atomic_t fscache_n_retrievals_nobufs;
53091-atomic_t fscache_n_retrievals_intr;
53092-atomic_t fscache_n_retrievals_nomem;
53093-atomic_t fscache_n_retrievals_object_dead;
53094-atomic_t fscache_n_retrieval_ops;
53095-atomic_t fscache_n_retrieval_op_waits;
53096+atomic_unchecked_t fscache_n_retrievals;
53097+atomic_unchecked_t fscache_n_retrievals_ok;
53098+atomic_unchecked_t fscache_n_retrievals_wait;
53099+atomic_unchecked_t fscache_n_retrievals_nodata;
53100+atomic_unchecked_t fscache_n_retrievals_nobufs;
53101+atomic_unchecked_t fscache_n_retrievals_intr;
53102+atomic_unchecked_t fscache_n_retrievals_nomem;
53103+atomic_unchecked_t fscache_n_retrievals_object_dead;
53104+atomic_unchecked_t fscache_n_retrieval_ops;
53105+atomic_unchecked_t fscache_n_retrieval_op_waits;
53106
53107-atomic_t fscache_n_stores;
53108-atomic_t fscache_n_stores_ok;
53109-atomic_t fscache_n_stores_again;
53110-atomic_t fscache_n_stores_nobufs;
53111-atomic_t fscache_n_stores_oom;
53112-atomic_t fscache_n_store_ops;
53113-atomic_t fscache_n_store_calls;
53114-atomic_t fscache_n_store_pages;
53115-atomic_t fscache_n_store_radix_deletes;
53116-atomic_t fscache_n_store_pages_over_limit;
53117+atomic_unchecked_t fscache_n_stores;
53118+atomic_unchecked_t fscache_n_stores_ok;
53119+atomic_unchecked_t fscache_n_stores_again;
53120+atomic_unchecked_t fscache_n_stores_nobufs;
53121+atomic_unchecked_t fscache_n_stores_oom;
53122+atomic_unchecked_t fscache_n_store_ops;
53123+atomic_unchecked_t fscache_n_store_calls;
53124+atomic_unchecked_t fscache_n_store_pages;
53125+atomic_unchecked_t fscache_n_store_radix_deletes;
53126+atomic_unchecked_t fscache_n_store_pages_over_limit;
53127
53128-atomic_t fscache_n_store_vmscan_not_storing;
53129-atomic_t fscache_n_store_vmscan_gone;
53130-atomic_t fscache_n_store_vmscan_busy;
53131-atomic_t fscache_n_store_vmscan_cancelled;
53132-atomic_t fscache_n_store_vmscan_wait;
53133+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
53134+atomic_unchecked_t fscache_n_store_vmscan_gone;
53135+atomic_unchecked_t fscache_n_store_vmscan_busy;
53136+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
53137+atomic_unchecked_t fscache_n_store_vmscan_wait;
53138
53139-atomic_t fscache_n_marks;
53140-atomic_t fscache_n_uncaches;
53141+atomic_unchecked_t fscache_n_marks;
53142+atomic_unchecked_t fscache_n_uncaches;
53143
53144-atomic_t fscache_n_acquires;
53145-atomic_t fscache_n_acquires_null;
53146-atomic_t fscache_n_acquires_no_cache;
53147-atomic_t fscache_n_acquires_ok;
53148-atomic_t fscache_n_acquires_nobufs;
53149-atomic_t fscache_n_acquires_oom;
53150+atomic_unchecked_t fscache_n_acquires;
53151+atomic_unchecked_t fscache_n_acquires_null;
53152+atomic_unchecked_t fscache_n_acquires_no_cache;
53153+atomic_unchecked_t fscache_n_acquires_ok;
53154+atomic_unchecked_t fscache_n_acquires_nobufs;
53155+atomic_unchecked_t fscache_n_acquires_oom;
53156
53157-atomic_t fscache_n_invalidates;
53158-atomic_t fscache_n_invalidates_run;
53159+atomic_unchecked_t fscache_n_invalidates;
53160+atomic_unchecked_t fscache_n_invalidates_run;
53161
53162-atomic_t fscache_n_updates;
53163-atomic_t fscache_n_updates_null;
53164-atomic_t fscache_n_updates_run;
53165+atomic_unchecked_t fscache_n_updates;
53166+atomic_unchecked_t fscache_n_updates_null;
53167+atomic_unchecked_t fscache_n_updates_run;
53168
53169-atomic_t fscache_n_relinquishes;
53170-atomic_t fscache_n_relinquishes_null;
53171-atomic_t fscache_n_relinquishes_waitcrt;
53172-atomic_t fscache_n_relinquishes_retire;
53173+atomic_unchecked_t fscache_n_relinquishes;
53174+atomic_unchecked_t fscache_n_relinquishes_null;
53175+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
53176+atomic_unchecked_t fscache_n_relinquishes_retire;
53177
53178-atomic_t fscache_n_cookie_index;
53179-atomic_t fscache_n_cookie_data;
53180-atomic_t fscache_n_cookie_special;
53181+atomic_unchecked_t fscache_n_cookie_index;
53182+atomic_unchecked_t fscache_n_cookie_data;
53183+atomic_unchecked_t fscache_n_cookie_special;
53184
53185-atomic_t fscache_n_object_alloc;
53186-atomic_t fscache_n_object_no_alloc;
53187-atomic_t fscache_n_object_lookups;
53188-atomic_t fscache_n_object_lookups_negative;
53189-atomic_t fscache_n_object_lookups_positive;
53190-atomic_t fscache_n_object_lookups_timed_out;
53191-atomic_t fscache_n_object_created;
53192-atomic_t fscache_n_object_avail;
53193-atomic_t fscache_n_object_dead;
53194+atomic_unchecked_t fscache_n_object_alloc;
53195+atomic_unchecked_t fscache_n_object_no_alloc;
53196+atomic_unchecked_t fscache_n_object_lookups;
53197+atomic_unchecked_t fscache_n_object_lookups_negative;
53198+atomic_unchecked_t fscache_n_object_lookups_positive;
53199+atomic_unchecked_t fscache_n_object_lookups_timed_out;
53200+atomic_unchecked_t fscache_n_object_created;
53201+atomic_unchecked_t fscache_n_object_avail;
53202+atomic_unchecked_t fscache_n_object_dead;
53203
53204-atomic_t fscache_n_checkaux_none;
53205-atomic_t fscache_n_checkaux_okay;
53206-atomic_t fscache_n_checkaux_update;
53207-atomic_t fscache_n_checkaux_obsolete;
53208+atomic_unchecked_t fscache_n_checkaux_none;
53209+atomic_unchecked_t fscache_n_checkaux_okay;
53210+atomic_unchecked_t fscache_n_checkaux_update;
53211+atomic_unchecked_t fscache_n_checkaux_obsolete;
53212
53213 atomic_t fscache_n_cop_alloc_object;
53214 atomic_t fscache_n_cop_lookup_object;
53215@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
53216 seq_puts(m, "FS-Cache statistics\n");
53217
53218 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
53219- atomic_read(&fscache_n_cookie_index),
53220- atomic_read(&fscache_n_cookie_data),
53221- atomic_read(&fscache_n_cookie_special));
53222+ atomic_read_unchecked(&fscache_n_cookie_index),
53223+ atomic_read_unchecked(&fscache_n_cookie_data),
53224+ atomic_read_unchecked(&fscache_n_cookie_special));
53225
53226 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
53227- atomic_read(&fscache_n_object_alloc),
53228- atomic_read(&fscache_n_object_no_alloc),
53229- atomic_read(&fscache_n_object_avail),
53230- atomic_read(&fscache_n_object_dead));
53231+ atomic_read_unchecked(&fscache_n_object_alloc),
53232+ atomic_read_unchecked(&fscache_n_object_no_alloc),
53233+ atomic_read_unchecked(&fscache_n_object_avail),
53234+ atomic_read_unchecked(&fscache_n_object_dead));
53235 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
53236- atomic_read(&fscache_n_checkaux_none),
53237- atomic_read(&fscache_n_checkaux_okay),
53238- atomic_read(&fscache_n_checkaux_update),
53239- atomic_read(&fscache_n_checkaux_obsolete));
53240+ atomic_read_unchecked(&fscache_n_checkaux_none),
53241+ atomic_read_unchecked(&fscache_n_checkaux_okay),
53242+ atomic_read_unchecked(&fscache_n_checkaux_update),
53243+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
53244
53245 seq_printf(m, "Pages : mrk=%u unc=%u\n",
53246- atomic_read(&fscache_n_marks),
53247- atomic_read(&fscache_n_uncaches));
53248+ atomic_read_unchecked(&fscache_n_marks),
53249+ atomic_read_unchecked(&fscache_n_uncaches));
53250
53251 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
53252 " oom=%u\n",
53253- atomic_read(&fscache_n_acquires),
53254- atomic_read(&fscache_n_acquires_null),
53255- atomic_read(&fscache_n_acquires_no_cache),
53256- atomic_read(&fscache_n_acquires_ok),
53257- atomic_read(&fscache_n_acquires_nobufs),
53258- atomic_read(&fscache_n_acquires_oom));
53259+ atomic_read_unchecked(&fscache_n_acquires),
53260+ atomic_read_unchecked(&fscache_n_acquires_null),
53261+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
53262+ atomic_read_unchecked(&fscache_n_acquires_ok),
53263+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
53264+ atomic_read_unchecked(&fscache_n_acquires_oom));
53265
53266 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
53267- atomic_read(&fscache_n_object_lookups),
53268- atomic_read(&fscache_n_object_lookups_negative),
53269- atomic_read(&fscache_n_object_lookups_positive),
53270- atomic_read(&fscache_n_object_created),
53271- atomic_read(&fscache_n_object_lookups_timed_out));
53272+ atomic_read_unchecked(&fscache_n_object_lookups),
53273+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
53274+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
53275+ atomic_read_unchecked(&fscache_n_object_created),
53276+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
53277
53278 seq_printf(m, "Invals : n=%u run=%u\n",
53279- atomic_read(&fscache_n_invalidates),
53280- atomic_read(&fscache_n_invalidates_run));
53281+ atomic_read_unchecked(&fscache_n_invalidates),
53282+ atomic_read_unchecked(&fscache_n_invalidates_run));
53283
53284 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
53285- atomic_read(&fscache_n_updates),
53286- atomic_read(&fscache_n_updates_null),
53287- atomic_read(&fscache_n_updates_run));
53288+ atomic_read_unchecked(&fscache_n_updates),
53289+ atomic_read_unchecked(&fscache_n_updates_null),
53290+ atomic_read_unchecked(&fscache_n_updates_run));
53291
53292 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
53293- atomic_read(&fscache_n_relinquishes),
53294- atomic_read(&fscache_n_relinquishes_null),
53295- atomic_read(&fscache_n_relinquishes_waitcrt),
53296- atomic_read(&fscache_n_relinquishes_retire));
53297+ atomic_read_unchecked(&fscache_n_relinquishes),
53298+ atomic_read_unchecked(&fscache_n_relinquishes_null),
53299+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
53300+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
53301
53302 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
53303- atomic_read(&fscache_n_attr_changed),
53304- atomic_read(&fscache_n_attr_changed_ok),
53305- atomic_read(&fscache_n_attr_changed_nobufs),
53306- atomic_read(&fscache_n_attr_changed_nomem),
53307- atomic_read(&fscache_n_attr_changed_calls));
53308+ atomic_read_unchecked(&fscache_n_attr_changed),
53309+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
53310+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
53311+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
53312+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
53313
53314 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
53315- atomic_read(&fscache_n_allocs),
53316- atomic_read(&fscache_n_allocs_ok),
53317- atomic_read(&fscache_n_allocs_wait),
53318- atomic_read(&fscache_n_allocs_nobufs),
53319- atomic_read(&fscache_n_allocs_intr));
53320+ atomic_read_unchecked(&fscache_n_allocs),
53321+ atomic_read_unchecked(&fscache_n_allocs_ok),
53322+ atomic_read_unchecked(&fscache_n_allocs_wait),
53323+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
53324+ atomic_read_unchecked(&fscache_n_allocs_intr));
53325 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
53326- atomic_read(&fscache_n_alloc_ops),
53327- atomic_read(&fscache_n_alloc_op_waits),
53328- atomic_read(&fscache_n_allocs_object_dead));
53329+ atomic_read_unchecked(&fscache_n_alloc_ops),
53330+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
53331+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
53332
53333 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
53334 " int=%u oom=%u\n",
53335- atomic_read(&fscache_n_retrievals),
53336- atomic_read(&fscache_n_retrievals_ok),
53337- atomic_read(&fscache_n_retrievals_wait),
53338- atomic_read(&fscache_n_retrievals_nodata),
53339- atomic_read(&fscache_n_retrievals_nobufs),
53340- atomic_read(&fscache_n_retrievals_intr),
53341- atomic_read(&fscache_n_retrievals_nomem));
53342+ atomic_read_unchecked(&fscache_n_retrievals),
53343+ atomic_read_unchecked(&fscache_n_retrievals_ok),
53344+ atomic_read_unchecked(&fscache_n_retrievals_wait),
53345+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
53346+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
53347+ atomic_read_unchecked(&fscache_n_retrievals_intr),
53348+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
53349 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
53350- atomic_read(&fscache_n_retrieval_ops),
53351- atomic_read(&fscache_n_retrieval_op_waits),
53352- atomic_read(&fscache_n_retrievals_object_dead));
53353+ atomic_read_unchecked(&fscache_n_retrieval_ops),
53354+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
53355+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
53356
53357 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
53358- atomic_read(&fscache_n_stores),
53359- atomic_read(&fscache_n_stores_ok),
53360- atomic_read(&fscache_n_stores_again),
53361- atomic_read(&fscache_n_stores_nobufs),
53362- atomic_read(&fscache_n_stores_oom));
53363+ atomic_read_unchecked(&fscache_n_stores),
53364+ atomic_read_unchecked(&fscache_n_stores_ok),
53365+ atomic_read_unchecked(&fscache_n_stores_again),
53366+ atomic_read_unchecked(&fscache_n_stores_nobufs),
53367+ atomic_read_unchecked(&fscache_n_stores_oom));
53368 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
53369- atomic_read(&fscache_n_store_ops),
53370- atomic_read(&fscache_n_store_calls),
53371- atomic_read(&fscache_n_store_pages),
53372- atomic_read(&fscache_n_store_radix_deletes),
53373- atomic_read(&fscache_n_store_pages_over_limit));
53374+ atomic_read_unchecked(&fscache_n_store_ops),
53375+ atomic_read_unchecked(&fscache_n_store_calls),
53376+ atomic_read_unchecked(&fscache_n_store_pages),
53377+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
53378+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
53379
53380 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
53381- atomic_read(&fscache_n_store_vmscan_not_storing),
53382- atomic_read(&fscache_n_store_vmscan_gone),
53383- atomic_read(&fscache_n_store_vmscan_busy),
53384- atomic_read(&fscache_n_store_vmscan_cancelled),
53385- atomic_read(&fscache_n_store_vmscan_wait));
53386+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
53387+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
53388+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
53389+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
53390+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
53391
53392 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
53393- atomic_read(&fscache_n_op_pend),
53394- atomic_read(&fscache_n_op_run),
53395- atomic_read(&fscache_n_op_enqueue),
53396- atomic_read(&fscache_n_op_cancelled),
53397- atomic_read(&fscache_n_op_rejected));
53398+ atomic_read_unchecked(&fscache_n_op_pend),
53399+ atomic_read_unchecked(&fscache_n_op_run),
53400+ atomic_read_unchecked(&fscache_n_op_enqueue),
53401+ atomic_read_unchecked(&fscache_n_op_cancelled),
53402+ atomic_read_unchecked(&fscache_n_op_rejected));
53403 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
53404- atomic_read(&fscache_n_op_deferred_release),
53405- atomic_read(&fscache_n_op_release),
53406- atomic_read(&fscache_n_op_gc));
53407+ atomic_read_unchecked(&fscache_n_op_deferred_release),
53408+ atomic_read_unchecked(&fscache_n_op_release),
53409+ atomic_read_unchecked(&fscache_n_op_gc));
53410
53411 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
53412 atomic_read(&fscache_n_cop_alloc_object),
53413diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
53414index e397b67..b0d8709 100644
53415--- a/fs/fuse/cuse.c
53416+++ b/fs/fuse/cuse.c
53417@@ -593,10 +593,12 @@ static int __init cuse_init(void)
53418 INIT_LIST_HEAD(&cuse_conntbl[i]);
53419
53420 /* inherit and extend fuse_dev_operations */
53421- cuse_channel_fops = fuse_dev_operations;
53422- cuse_channel_fops.owner = THIS_MODULE;
53423- cuse_channel_fops.open = cuse_channel_open;
53424- cuse_channel_fops.release = cuse_channel_release;
53425+ pax_open_kernel();
53426+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
53427+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
53428+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
53429+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
53430+ pax_close_kernel();
53431
53432 cuse_class = class_create(THIS_MODULE, "cuse");
53433 if (IS_ERR(cuse_class))
53434diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
53435index e83351a..41e3c9c 100644
53436--- a/fs/fuse/dev.c
53437+++ b/fs/fuse/dev.c
53438@@ -1236,7 +1236,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
53439 ret = 0;
53440 pipe_lock(pipe);
53441
53442- if (!pipe->readers) {
53443+ if (!atomic_read(&pipe->readers)) {
53444 send_sig(SIGPIPE, current, 0);
53445 if (!ret)
53446 ret = -EPIPE;
53447diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
53448index 315e1f8..91f890c 100644
53449--- a/fs/fuse/dir.c
53450+++ b/fs/fuse/dir.c
53451@@ -1233,7 +1233,7 @@ static char *read_link(struct dentry *dentry)
53452 return link;
53453 }
53454
53455-static void free_link(char *link)
53456+static void free_link(const char *link)
53457 {
53458 if (!IS_ERR(link))
53459 free_page((unsigned long) link);
53460diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
53461index 2b6f569..fcb4d1f 100644
53462--- a/fs/gfs2/inode.c
53463+++ b/fs/gfs2/inode.c
53464@@ -1499,7 +1499,7 @@ out:
53465
53466 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
53467 {
53468- char *s = nd_get_link(nd);
53469+ const char *s = nd_get_link(nd);
53470 if (!IS_ERR(s))
53471 kfree(s);
53472 }
53473diff --git a/fs/hfsplus/extents.c b/fs/hfsplus/extents.c
53474index eba76eab..fc8ddc1 100644
53475--- a/fs/hfsplus/extents.c
53476+++ b/fs/hfsplus/extents.c
53477@@ -533,7 +533,7 @@ void hfsplus_file_truncate(struct inode *inode)
53478 struct address_space *mapping = inode->i_mapping;
53479 struct page *page;
53480 void *fsdata;
53481- u32 size = inode->i_size;
53482+ loff_t size = inode->i_size;
53483
53484 res = pagecache_write_begin(NULL, mapping, size, 0,
53485 AOP_FLAG_UNINTERRUPTIBLE,
53486diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
53487index 78bde32..767e906 100644
53488--- a/fs/hugetlbfs/inode.c
53489+++ b/fs/hugetlbfs/inode.c
53490@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
53491 struct mm_struct *mm = current->mm;
53492 struct vm_area_struct *vma;
53493 struct hstate *h = hstate_file(file);
53494+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
53495 struct vm_unmapped_area_info info;
53496
53497 if (len & ~huge_page_mask(h))
53498@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
53499 return addr;
53500 }
53501
53502+#ifdef CONFIG_PAX_RANDMMAP
53503+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
53504+#endif
53505+
53506 if (addr) {
53507 addr = ALIGN(addr, huge_page_size(h));
53508 vma = find_vma(mm, addr);
53509- if (TASK_SIZE - len >= addr &&
53510- (!vma || addr + len <= vma->vm_start))
53511+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
53512 return addr;
53513 }
53514
53515 info.flags = 0;
53516 info.length = len;
53517 info.low_limit = TASK_UNMAPPED_BASE;
53518+
53519+#ifdef CONFIG_PAX_RANDMMAP
53520+ if (mm->pax_flags & MF_PAX_RANDMMAP)
53521+ info.low_limit += mm->delta_mmap;
53522+#endif
53523+
53524 info.high_limit = TASK_SIZE;
53525 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
53526 info.align_offset = 0;
53527@@ -897,7 +907,7 @@ static struct file_system_type hugetlbfs_fs_type = {
53528 .kill_sb = kill_litter_super,
53529 };
53530
53531-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
53532+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
53533
53534 static int can_do_hugetlb_shm(void)
53535 {
53536diff --git a/fs/inode.c b/fs/inode.c
53537index b98540e..6a439ea 100644
53538--- a/fs/inode.c
53539+++ b/fs/inode.c
53540@@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
53541
53542 #ifdef CONFIG_SMP
53543 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
53544- static atomic_t shared_last_ino;
53545- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
53546+ static atomic_unchecked_t shared_last_ino;
53547+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
53548
53549 res = next - LAST_INO_BATCH;
53550 }
53551diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
53552index 4a6cf28..d3a29d3 100644
53553--- a/fs/jffs2/erase.c
53554+++ b/fs/jffs2/erase.c
53555@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
53556 struct jffs2_unknown_node marker = {
53557 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
53558 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
53559- .totlen = cpu_to_je32(c->cleanmarker_size)
53560+ .totlen = cpu_to_je32(c->cleanmarker_size),
53561+ .hdr_crc = cpu_to_je32(0)
53562 };
53563
53564 jffs2_prealloc_raw_node_refs(c, jeb, 1);
53565diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
53566index a6597d6..41b30ec 100644
53567--- a/fs/jffs2/wbuf.c
53568+++ b/fs/jffs2/wbuf.c
53569@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
53570 {
53571 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
53572 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
53573- .totlen = constant_cpu_to_je32(8)
53574+ .totlen = constant_cpu_to_je32(8),
53575+ .hdr_crc = constant_cpu_to_je32(0)
53576 };
53577
53578 /*
53579diff --git a/fs/jfs/super.c b/fs/jfs/super.c
53580index 1a543be..a4e1363 100644
53581--- a/fs/jfs/super.c
53582+++ b/fs/jfs/super.c
53583@@ -225,7 +225,7 @@ static const match_table_t tokens = {
53584 static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
53585 int *flag)
53586 {
53587- void *nls_map = (void *)-1; /* -1: no change; NULL: none */
53588+ const void *nls_map = (const void *)-1; /* -1: no change; NULL: none */
53589 char *p;
53590 struct jfs_sb_info *sbi = JFS_SBI(sb);
53591
53592@@ -253,7 +253,7 @@ static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
53593 /* Don't do anything ;-) */
53594 break;
53595 case Opt_iocharset:
53596- if (nls_map && nls_map != (void *) -1)
53597+ if (nls_map && nls_map != (const void *) -1)
53598 unload_nls(nls_map);
53599 if (!strcmp(args[0].from, "none"))
53600 nls_map = NULL;
53601@@ -855,7 +855,7 @@ static int __init init_jfs_fs(void)
53602
53603 jfs_inode_cachep =
53604 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
53605- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
53606+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
53607 init_once);
53608 if (jfs_inode_cachep == NULL)
53609 return -ENOMEM;
53610diff --git a/fs/libfs.c b/fs/libfs.c
53611index 916da8c..1588998 100644
53612--- a/fs/libfs.c
53613+++ b/fs/libfs.c
53614@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
53615
53616 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
53617 struct dentry *next;
53618+ char d_name[sizeof(next->d_iname)];
53619+ const unsigned char *name;
53620+
53621 next = list_entry(p, struct dentry, d_u.d_child);
53622 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
53623 if (!simple_positive(next)) {
53624@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
53625
53626 spin_unlock(&next->d_lock);
53627 spin_unlock(&dentry->d_lock);
53628- if (filldir(dirent, next->d_name.name,
53629+ name = next->d_name.name;
53630+ if (name == next->d_iname) {
53631+ memcpy(d_name, name, next->d_name.len);
53632+ name = d_name;
53633+ }
53634+ if (filldir(dirent, name,
53635 next->d_name.len, filp->f_pos,
53636 next->d_inode->i_ino,
53637 dt_type(next->d_inode)) < 0)
53638diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
53639index 52e5120..808936e 100644
53640--- a/fs/lockd/clntproc.c
53641+++ b/fs/lockd/clntproc.c
53642@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
53643 /*
53644 * Cookie counter for NLM requests
53645 */
53646-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
53647+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
53648
53649 void nlmclnt_next_cookie(struct nlm_cookie *c)
53650 {
53651- u32 cookie = atomic_inc_return(&nlm_cookie);
53652+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
53653
53654 memcpy(c->data, &cookie, 4);
53655 c->len=4;
53656diff --git a/fs/locks.c b/fs/locks.c
53657index a94e331..060bce3 100644
53658--- a/fs/locks.c
53659+++ b/fs/locks.c
53660@@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
53661 return;
53662
53663 if (filp->f_op && filp->f_op->flock) {
53664- struct file_lock fl = {
53665+ struct file_lock flock = {
53666 .fl_pid = current->tgid,
53667 .fl_file = filp,
53668 .fl_flags = FL_FLOCK,
53669 .fl_type = F_UNLCK,
53670 .fl_end = OFFSET_MAX,
53671 };
53672- filp->f_op->flock(filp, F_SETLKW, &fl);
53673- if (fl.fl_ops && fl.fl_ops->fl_release_private)
53674- fl.fl_ops->fl_release_private(&fl);
53675+ filp->f_op->flock(filp, F_SETLKW, &flock);
53676+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
53677+ flock.fl_ops->fl_release_private(&flock);
53678 }
53679
53680 lock_flocks();
53681diff --git a/fs/namei.c b/fs/namei.c
53682index ec97aef..e67718d 100644
53683--- a/fs/namei.c
53684+++ b/fs/namei.c
53685@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
53686 if (ret != -EACCES)
53687 return ret;
53688
53689+#ifdef CONFIG_GRKERNSEC
53690+ /* we'll block if we have to log due to a denied capability use */
53691+ if (mask & MAY_NOT_BLOCK)
53692+ return -ECHILD;
53693+#endif
53694+
53695 if (S_ISDIR(inode->i_mode)) {
53696 /* DACs are overridable for directories */
53697- if (inode_capable(inode, CAP_DAC_OVERRIDE))
53698- return 0;
53699 if (!(mask & MAY_WRITE))
53700- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
53701+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
53702+ inode_capable(inode, CAP_DAC_READ_SEARCH))
53703 return 0;
53704+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
53705+ return 0;
53706 return -EACCES;
53707 }
53708 /*
53709+ * Searching includes executable on directories, else just read.
53710+ */
53711+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
53712+ if (mask == MAY_READ)
53713+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
53714+ inode_capable(inode, CAP_DAC_READ_SEARCH))
53715+ return 0;
53716+
53717+ /*
53718 * Read/write DACs are always overridable.
53719 * Executable DACs are overridable when there is
53720 * at least one exec bit set.
53721@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
53722 if (inode_capable(inode, CAP_DAC_OVERRIDE))
53723 return 0;
53724
53725- /*
53726- * Searching includes executable on directories, else just read.
53727- */
53728- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
53729- if (mask == MAY_READ)
53730- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
53731- return 0;
53732-
53733 return -EACCES;
53734 }
53735
53736@@ -824,7 +832,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
53737 {
53738 struct dentry *dentry = link->dentry;
53739 int error;
53740- char *s;
53741+ const char *s;
53742
53743 BUG_ON(nd->flags & LOOKUP_RCU);
53744
53745@@ -845,6 +853,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
53746 if (error)
53747 goto out_put_nd_path;
53748
53749+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
53750+ dentry->d_inode, dentry, nd->path.mnt)) {
53751+ error = -EACCES;
53752+ goto out_put_nd_path;
53753+ }
53754+
53755 nd->last_type = LAST_BIND;
53756 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
53757 error = PTR_ERR(*p);
53758@@ -1594,6 +1608,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
53759 break;
53760 res = walk_component(nd, path, &nd->last,
53761 nd->last_type, LOOKUP_FOLLOW);
53762+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
53763+ res = -EACCES;
53764 put_link(nd, &link, cookie);
53765 } while (res > 0);
53766
53767@@ -1692,7 +1708,7 @@ EXPORT_SYMBOL(full_name_hash);
53768 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
53769 {
53770 unsigned long a, b, adata, bdata, mask, hash, len;
53771- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
53772+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
53773
53774 hash = a = 0;
53775 len = -sizeof(unsigned long);
53776@@ -1977,6 +1993,8 @@ static int path_lookupat(int dfd, const char *name,
53777 if (err)
53778 break;
53779 err = lookup_last(nd, &path);
53780+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
53781+ err = -EACCES;
53782 put_link(nd, &link, cookie);
53783 }
53784 }
53785@@ -1984,6 +2002,13 @@ static int path_lookupat(int dfd, const char *name,
53786 if (!err)
53787 err = complete_walk(nd);
53788
53789+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
53790+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53791+ path_put(&nd->path);
53792+ err = -ENOENT;
53793+ }
53794+ }
53795+
53796 if (!err && nd->flags & LOOKUP_DIRECTORY) {
53797 if (!nd->inode->i_op->lookup) {
53798 path_put(&nd->path);
53799@@ -2011,8 +2036,15 @@ static int filename_lookup(int dfd, struct filename *name,
53800 retval = path_lookupat(dfd, name->name,
53801 flags | LOOKUP_REVAL, nd);
53802
53803- if (likely(!retval))
53804+ if (likely(!retval)) {
53805 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
53806+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
53807+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
53808+ path_put(&nd->path);
53809+ return -ENOENT;
53810+ }
53811+ }
53812+ }
53813 return retval;
53814 }
53815
53816@@ -2390,6 +2422,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
53817 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
53818 return -EPERM;
53819
53820+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
53821+ return -EPERM;
53822+ if (gr_handle_rawio(inode))
53823+ return -EPERM;
53824+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
53825+ return -EACCES;
53826+
53827 return 0;
53828 }
53829
53830@@ -2611,7 +2650,7 @@ looked_up:
53831 * cleared otherwise prior to returning.
53832 */
53833 static int lookup_open(struct nameidata *nd, struct path *path,
53834- struct file *file,
53835+ struct path *link, struct file *file,
53836 const struct open_flags *op,
53837 bool got_write, int *opened)
53838 {
53839@@ -2646,6 +2685,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
53840 /* Negative dentry, just create the file */
53841 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
53842 umode_t mode = op->mode;
53843+
53844+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
53845+ error = -EACCES;
53846+ goto out_dput;
53847+ }
53848+
53849+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
53850+ error = -EACCES;
53851+ goto out_dput;
53852+ }
53853+
53854 if (!IS_POSIXACL(dir->d_inode))
53855 mode &= ~current_umask();
53856 /*
53857@@ -2667,6 +2717,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
53858 nd->flags & LOOKUP_EXCL);
53859 if (error)
53860 goto out_dput;
53861+ else
53862+ gr_handle_create(dentry, nd->path.mnt);
53863 }
53864 out_no_open:
53865 path->dentry = dentry;
53866@@ -2681,7 +2733,7 @@ out_dput:
53867 /*
53868 * Handle the last step of open()
53869 */
53870-static int do_last(struct nameidata *nd, struct path *path,
53871+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
53872 struct file *file, const struct open_flags *op,
53873 int *opened, struct filename *name)
53874 {
53875@@ -2710,16 +2762,32 @@ static int do_last(struct nameidata *nd, struct path *path,
53876 error = complete_walk(nd);
53877 if (error)
53878 return error;
53879+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53880+ error = -ENOENT;
53881+ goto out;
53882+ }
53883 audit_inode(name, nd->path.dentry, 0);
53884 if (open_flag & O_CREAT) {
53885 error = -EISDIR;
53886 goto out;
53887 }
53888+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53889+ error = -EACCES;
53890+ goto out;
53891+ }
53892 goto finish_open;
53893 case LAST_BIND:
53894 error = complete_walk(nd);
53895 if (error)
53896 return error;
53897+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
53898+ error = -ENOENT;
53899+ goto out;
53900+ }
53901+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53902+ error = -EACCES;
53903+ goto out;
53904+ }
53905 audit_inode(name, dir, 0);
53906 goto finish_open;
53907 }
53908@@ -2768,7 +2836,7 @@ retry_lookup:
53909 */
53910 }
53911 mutex_lock(&dir->d_inode->i_mutex);
53912- error = lookup_open(nd, path, file, op, got_write, opened);
53913+ error = lookup_open(nd, path, link, file, op, got_write, opened);
53914 mutex_unlock(&dir->d_inode->i_mutex);
53915
53916 if (error <= 0) {
53917@@ -2792,11 +2860,28 @@ retry_lookup:
53918 goto finish_open_created;
53919 }
53920
53921+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
53922+ error = -ENOENT;
53923+ goto exit_dput;
53924+ }
53925+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
53926+ error = -EACCES;
53927+ goto exit_dput;
53928+ }
53929+
53930 /*
53931 * create/update audit record if it already exists.
53932 */
53933- if (path->dentry->d_inode)
53934+ if (path->dentry->d_inode) {
53935+ /* only check if O_CREAT is specified, all other checks need to go
53936+ into may_open */
53937+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
53938+ error = -EACCES;
53939+ goto exit_dput;
53940+ }
53941+
53942 audit_inode(name, path->dentry, 0);
53943+ }
53944
53945 /*
53946 * If atomic_open() acquired write access it is dropped now due to
53947@@ -2837,6 +2922,11 @@ finish_lookup:
53948 }
53949 }
53950 BUG_ON(inode != path->dentry->d_inode);
53951+ /* if we're resolving a symlink to another symlink */
53952+ if (link && gr_handle_symlink_owner(link, inode)) {
53953+ error = -EACCES;
53954+ goto out;
53955+ }
53956 return 1;
53957 }
53958
53959@@ -2846,7 +2936,6 @@ finish_lookup:
53960 save_parent.dentry = nd->path.dentry;
53961 save_parent.mnt = mntget(path->mnt);
53962 nd->path.dentry = path->dentry;
53963-
53964 }
53965 nd->inode = inode;
53966 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
53967@@ -2855,6 +2944,16 @@ finish_lookup:
53968 path_put(&save_parent);
53969 return error;
53970 }
53971+
53972+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53973+ error = -ENOENT;
53974+ goto out;
53975+ }
53976+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53977+ error = -EACCES;
53978+ goto out;
53979+ }
53980+
53981 error = -EISDIR;
53982 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
53983 goto out;
53984@@ -2953,7 +3052,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
53985 if (unlikely(error))
53986 goto out;
53987
53988- error = do_last(nd, &path, file, op, &opened, pathname);
53989+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
53990 while (unlikely(error > 0)) { /* trailing symlink */
53991 struct path link = path;
53992 void *cookie;
53993@@ -2971,7 +3070,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
53994 error = follow_link(&link, nd, &cookie);
53995 if (unlikely(error))
53996 break;
53997- error = do_last(nd, &path, file, op, &opened, pathname);
53998+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
53999 put_link(nd, &link, cookie);
54000 }
54001 out:
54002@@ -3071,8 +3170,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
54003 goto unlock;
54004
54005 error = -EEXIST;
54006- if (dentry->d_inode)
54007+ if (dentry->d_inode) {
54008+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
54009+ error = -ENOENT;
54010+ }
54011 goto fail;
54012+ }
54013 /*
54014 * Special case - lookup gave negative, but... we had foo/bar/
54015 * From the vfs_mknod() POV we just have a negative dentry -
54016@@ -3124,6 +3227,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
54017 }
54018 EXPORT_SYMBOL(user_path_create);
54019
54020+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
54021+{
54022+ struct filename *tmp = getname(pathname);
54023+ struct dentry *res;
54024+ if (IS_ERR(tmp))
54025+ return ERR_CAST(tmp);
54026+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
54027+ if (IS_ERR(res))
54028+ putname(tmp);
54029+ else
54030+ *to = tmp;
54031+ return res;
54032+}
54033+
54034 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
54035 {
54036 int error = may_create(dir, dentry);
54037@@ -3186,6 +3303,17 @@ retry:
54038
54039 if (!IS_POSIXACL(path.dentry->d_inode))
54040 mode &= ~current_umask();
54041+
54042+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
54043+ error = -EPERM;
54044+ goto out;
54045+ }
54046+
54047+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
54048+ error = -EACCES;
54049+ goto out;
54050+ }
54051+
54052 error = security_path_mknod(&path, dentry, mode, dev);
54053 if (error)
54054 goto out;
54055@@ -3202,6 +3330,8 @@ retry:
54056 break;
54057 }
54058 out:
54059+ if (!error)
54060+ gr_handle_create(dentry, path.mnt);
54061 done_path_create(&path, dentry);
54062 if (retry_estale(error, lookup_flags)) {
54063 lookup_flags |= LOOKUP_REVAL;
54064@@ -3254,9 +3384,16 @@ retry:
54065
54066 if (!IS_POSIXACL(path.dentry->d_inode))
54067 mode &= ~current_umask();
54068+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
54069+ error = -EACCES;
54070+ goto out;
54071+ }
54072 error = security_path_mkdir(&path, dentry, mode);
54073 if (!error)
54074 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
54075+ if (!error)
54076+ gr_handle_create(dentry, path.mnt);
54077+out:
54078 done_path_create(&path, dentry);
54079 if (retry_estale(error, lookup_flags)) {
54080 lookup_flags |= LOOKUP_REVAL;
54081@@ -3337,6 +3474,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
54082 struct filename *name;
54083 struct dentry *dentry;
54084 struct nameidata nd;
54085+ ino_t saved_ino = 0;
54086+ dev_t saved_dev = 0;
54087 unsigned int lookup_flags = 0;
54088 retry:
54089 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
54090@@ -3369,10 +3508,21 @@ retry:
54091 error = -ENOENT;
54092 goto exit3;
54093 }
54094+
54095+ saved_ino = dentry->d_inode->i_ino;
54096+ saved_dev = gr_get_dev_from_dentry(dentry);
54097+
54098+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
54099+ error = -EACCES;
54100+ goto exit3;
54101+ }
54102+
54103 error = security_path_rmdir(&nd.path, dentry);
54104 if (error)
54105 goto exit3;
54106 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
54107+ if (!error && (saved_dev || saved_ino))
54108+ gr_handle_delete(saved_ino, saved_dev);
54109 exit3:
54110 dput(dentry);
54111 exit2:
54112@@ -3438,6 +3588,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
54113 struct dentry *dentry;
54114 struct nameidata nd;
54115 struct inode *inode = NULL;
54116+ ino_t saved_ino = 0;
54117+ dev_t saved_dev = 0;
54118 unsigned int lookup_flags = 0;
54119 retry:
54120 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
54121@@ -3464,10 +3616,22 @@ retry:
54122 if (!inode)
54123 goto slashes;
54124 ihold(inode);
54125+
54126+ if (inode->i_nlink <= 1) {
54127+ saved_ino = inode->i_ino;
54128+ saved_dev = gr_get_dev_from_dentry(dentry);
54129+ }
54130+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
54131+ error = -EACCES;
54132+ goto exit2;
54133+ }
54134+
54135 error = security_path_unlink(&nd.path, dentry);
54136 if (error)
54137 goto exit2;
54138 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
54139+ if (!error && (saved_ino || saved_dev))
54140+ gr_handle_delete(saved_ino, saved_dev);
54141 exit2:
54142 dput(dentry);
54143 }
54144@@ -3545,9 +3709,17 @@ retry:
54145 if (IS_ERR(dentry))
54146 goto out_putname;
54147
54148+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
54149+ error = -EACCES;
54150+ goto out;
54151+ }
54152+
54153 error = security_path_symlink(&path, dentry, from->name);
54154 if (!error)
54155 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
54156+ if (!error)
54157+ gr_handle_create(dentry, path.mnt);
54158+out:
54159 done_path_create(&path, dentry);
54160 if (retry_estale(error, lookup_flags)) {
54161 lookup_flags |= LOOKUP_REVAL;
54162@@ -3621,6 +3793,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
54163 {
54164 struct dentry *new_dentry;
54165 struct path old_path, new_path;
54166+ struct filename *to = NULL;
54167 int how = 0;
54168 int error;
54169
54170@@ -3644,7 +3817,7 @@ retry:
54171 if (error)
54172 return error;
54173
54174- new_dentry = user_path_create(newdfd, newname, &new_path,
54175+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
54176 (how & LOOKUP_REVAL));
54177 error = PTR_ERR(new_dentry);
54178 if (IS_ERR(new_dentry))
54179@@ -3656,11 +3829,28 @@ retry:
54180 error = may_linkat(&old_path);
54181 if (unlikely(error))
54182 goto out_dput;
54183+
54184+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
54185+ old_path.dentry->d_inode,
54186+ old_path.dentry->d_inode->i_mode, to)) {
54187+ error = -EACCES;
54188+ goto out_dput;
54189+ }
54190+
54191+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
54192+ old_path.dentry, old_path.mnt, to)) {
54193+ error = -EACCES;
54194+ goto out_dput;
54195+ }
54196+
54197 error = security_path_link(old_path.dentry, &new_path, new_dentry);
54198 if (error)
54199 goto out_dput;
54200 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
54201+ if (!error)
54202+ gr_handle_create(new_dentry, new_path.mnt);
54203 out_dput:
54204+ putname(to);
54205 done_path_create(&new_path, new_dentry);
54206 if (retry_estale(error, how)) {
54207 how |= LOOKUP_REVAL;
54208@@ -3906,12 +4096,21 @@ retry:
54209 if (new_dentry == trap)
54210 goto exit5;
54211
54212+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
54213+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
54214+ to);
54215+ if (error)
54216+ goto exit5;
54217+
54218 error = security_path_rename(&oldnd.path, old_dentry,
54219 &newnd.path, new_dentry);
54220 if (error)
54221 goto exit5;
54222 error = vfs_rename(old_dir->d_inode, old_dentry,
54223 new_dir->d_inode, new_dentry);
54224+ if (!error)
54225+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
54226+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
54227 exit5:
54228 dput(new_dentry);
54229 exit4:
54230@@ -3943,6 +4142,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
54231
54232 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
54233 {
54234+ char tmpbuf[64];
54235+ const char *newlink;
54236 int len;
54237
54238 len = PTR_ERR(link);
54239@@ -3952,7 +4153,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
54240 len = strlen(link);
54241 if (len > (unsigned) buflen)
54242 len = buflen;
54243- if (copy_to_user(buffer, link, len))
54244+
54245+ if (len < sizeof(tmpbuf)) {
54246+ memcpy(tmpbuf, link, len);
54247+ newlink = tmpbuf;
54248+ } else
54249+ newlink = link;
54250+
54251+ if (copy_to_user(buffer, newlink, len))
54252 len = -EFAULT;
54253 out:
54254 return len;
54255diff --git a/fs/namespace.c b/fs/namespace.c
54256index 5dd7709..6f64e9c 100644
54257--- a/fs/namespace.c
54258+++ b/fs/namespace.c
54259@@ -1219,6 +1219,9 @@ static int do_umount(struct mount *mnt, int flags)
54260 if (!(sb->s_flags & MS_RDONLY))
54261 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
54262 up_write(&sb->s_umount);
54263+
54264+ gr_log_remount(mnt->mnt_devname, retval);
54265+
54266 return retval;
54267 }
54268
54269@@ -1238,6 +1241,9 @@ static int do_umount(struct mount *mnt, int flags)
54270 br_write_unlock(&vfsmount_lock);
54271 up_write(&namespace_sem);
54272 release_mounts(&umount_list);
54273+
54274+ gr_log_unmount(mnt->mnt_devname, retval);
54275+
54276 return retval;
54277 }
54278
54279@@ -1713,7 +1719,7 @@ static int do_loopback(struct path *path, const char *old_name,
54280
54281 if (IS_ERR(mnt)) {
54282 err = PTR_ERR(mnt);
54283- goto out;
54284+ goto out2;
54285 }
54286
54287 err = graft_tree(mnt, path);
54288@@ -2294,6 +2300,16 @@ long do_mount(const char *dev_name, const char *dir_name,
54289 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
54290 MS_STRICTATIME);
54291
54292+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
54293+ retval = -EPERM;
54294+ goto dput_out;
54295+ }
54296+
54297+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
54298+ retval = -EPERM;
54299+ goto dput_out;
54300+ }
54301+
54302 if (flags & MS_REMOUNT)
54303 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
54304 data_page);
54305@@ -2308,6 +2324,9 @@ long do_mount(const char *dev_name, const char *dir_name,
54306 dev_name, data_page);
54307 dput_out:
54308 path_put(&path);
54309+
54310+ gr_log_mount(dev_name, dir_name, retval);
54311+
54312 return retval;
54313 }
54314
54315@@ -2594,6 +2613,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
54316 if (error)
54317 goto out2;
54318
54319+ if (gr_handle_chroot_pivot()) {
54320+ error = -EPERM;
54321+ goto out2;
54322+ }
54323+
54324 get_fs_root(current->fs, &root);
54325 error = lock_mount(&old);
54326 if (error)
54327@@ -2842,7 +2866,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
54328 !nsown_capable(CAP_SYS_ADMIN))
54329 return -EPERM;
54330
54331- if (fs->users != 1)
54332+ if (atomic_read(&fs->users) != 1)
54333 return -EINVAL;
54334
54335 get_mnt_ns(mnt_ns);
54336diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
54337index 59461c9..b17c57e 100644
54338--- a/fs/nfs/callback_xdr.c
54339+++ b/fs/nfs/callback_xdr.c
54340@@ -51,7 +51,7 @@ struct callback_op {
54341 callback_decode_arg_t decode_args;
54342 callback_encode_res_t encode_res;
54343 long res_maxsize;
54344-};
54345+} __do_const;
54346
54347 static struct callback_op callback_ops[];
54348
54349diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
54350index ebeb94c..ff35337 100644
54351--- a/fs/nfs/inode.c
54352+++ b/fs/nfs/inode.c
54353@@ -1042,16 +1042,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
54354 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
54355 }
54356
54357-static atomic_long_t nfs_attr_generation_counter;
54358+static atomic_long_unchecked_t nfs_attr_generation_counter;
54359
54360 static unsigned long nfs_read_attr_generation_counter(void)
54361 {
54362- return atomic_long_read(&nfs_attr_generation_counter);
54363+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
54364 }
54365
54366 unsigned long nfs_inc_attr_generation_counter(void)
54367 {
54368- return atomic_long_inc_return(&nfs_attr_generation_counter);
54369+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
54370 }
54371
54372 void nfs_fattr_init(struct nfs_fattr *fattr)
54373diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
54374index 9d1c5db..1e13db8 100644
54375--- a/fs/nfsd/nfs4proc.c
54376+++ b/fs/nfsd/nfs4proc.c
54377@@ -1097,7 +1097,7 @@ struct nfsd4_operation {
54378 nfsd4op_rsize op_rsize_bop;
54379 stateid_getter op_get_currentstateid;
54380 stateid_setter op_set_currentstateid;
54381-};
54382+} __do_const;
54383
54384 static struct nfsd4_operation nfsd4_ops[];
54385
54386diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
54387index d1dd710..32ac0e8 100644
54388--- a/fs/nfsd/nfs4xdr.c
54389+++ b/fs/nfsd/nfs4xdr.c
54390@@ -1456,7 +1456,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
54391
54392 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
54393
54394-static nfsd4_dec nfsd4_dec_ops[] = {
54395+static const nfsd4_dec nfsd4_dec_ops[] = {
54396 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
54397 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
54398 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
54399@@ -1496,7 +1496,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
54400 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
54401 };
54402
54403-static nfsd4_dec nfsd41_dec_ops[] = {
54404+static const nfsd4_dec nfsd41_dec_ops[] = {
54405 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
54406 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
54407 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
54408@@ -1558,7 +1558,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
54409 };
54410
54411 struct nfsd4_minorversion_ops {
54412- nfsd4_dec *decoders;
54413+ const nfsd4_dec *decoders;
54414 int nops;
54415 };
54416
54417diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
54418index 69c6413..c0408d2 100644
54419--- a/fs/nfsd/vfs.c
54420+++ b/fs/nfsd/vfs.c
54421@@ -939,7 +939,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
54422 } else {
54423 oldfs = get_fs();
54424 set_fs(KERNEL_DS);
54425- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
54426+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
54427 set_fs(oldfs);
54428 }
54429
54430@@ -1026,7 +1026,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
54431
54432 /* Write the data. */
54433 oldfs = get_fs(); set_fs(KERNEL_DS);
54434- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
54435+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
54436 set_fs(oldfs);
54437 if (host_err < 0)
54438 goto out_nfserr;
54439@@ -1572,7 +1572,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
54440 */
54441
54442 oldfs = get_fs(); set_fs(KERNEL_DS);
54443- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
54444+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
54445 set_fs(oldfs);
54446
54447 if (host_err < 0)
54448diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
54449index fea6bd5..8ee9d81 100644
54450--- a/fs/nls/nls_base.c
54451+++ b/fs/nls/nls_base.c
54452@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
54453
54454 int register_nls(struct nls_table * nls)
54455 {
54456- struct nls_table ** tmp = &tables;
54457+ struct nls_table *tmp = tables;
54458
54459 if (nls->next)
54460 return -EBUSY;
54461
54462 spin_lock(&nls_lock);
54463- while (*tmp) {
54464- if (nls == *tmp) {
54465+ while (tmp) {
54466+ if (nls == tmp) {
54467 spin_unlock(&nls_lock);
54468 return -EBUSY;
54469 }
54470- tmp = &(*tmp)->next;
54471+ tmp = tmp->next;
54472 }
54473- nls->next = tables;
54474+ pax_open_kernel();
54475+ *(struct nls_table **)&nls->next = tables;
54476+ pax_close_kernel();
54477 tables = nls;
54478 spin_unlock(&nls_lock);
54479 return 0;
54480@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
54481
54482 int unregister_nls(struct nls_table * nls)
54483 {
54484- struct nls_table ** tmp = &tables;
54485+ struct nls_table * const * tmp = &tables;
54486
54487 spin_lock(&nls_lock);
54488 while (*tmp) {
54489 if (nls == *tmp) {
54490- *tmp = nls->next;
54491+ pax_open_kernel();
54492+ *(struct nls_table **)tmp = nls->next;
54493+ pax_close_kernel();
54494 spin_unlock(&nls_lock);
54495 return 0;
54496 }
54497diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
54498index 7424929..35f6be5 100644
54499--- a/fs/nls/nls_euc-jp.c
54500+++ b/fs/nls/nls_euc-jp.c
54501@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
54502 p_nls = load_nls("cp932");
54503
54504 if (p_nls) {
54505- table.charset2upper = p_nls->charset2upper;
54506- table.charset2lower = p_nls->charset2lower;
54507+ pax_open_kernel();
54508+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
54509+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
54510+ pax_close_kernel();
54511 return register_nls(&table);
54512 }
54513
54514diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
54515index e7bc1d7..06bd4bb 100644
54516--- a/fs/nls/nls_koi8-ru.c
54517+++ b/fs/nls/nls_koi8-ru.c
54518@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
54519 p_nls = load_nls("koi8-u");
54520
54521 if (p_nls) {
54522- table.charset2upper = p_nls->charset2upper;
54523- table.charset2lower = p_nls->charset2lower;
54524+ pax_open_kernel();
54525+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
54526+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
54527+ pax_close_kernel();
54528 return register_nls(&table);
54529 }
54530
54531diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
54532index 9ff4a5e..deb1f0f 100644
54533--- a/fs/notify/fanotify/fanotify_user.c
54534+++ b/fs/notify/fanotify/fanotify_user.c
54535@@ -251,8 +251,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
54536
54537 fd = fanotify_event_metadata.fd;
54538 ret = -EFAULT;
54539- if (copy_to_user(buf, &fanotify_event_metadata,
54540- fanotify_event_metadata.event_len))
54541+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
54542+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
54543 goto out_close_fd;
54544
54545 ret = prepare_for_access_response(group, event, fd);
54546diff --git a/fs/notify/notification.c b/fs/notify/notification.c
54547index 7b51b05..5ea5ef6 100644
54548--- a/fs/notify/notification.c
54549+++ b/fs/notify/notification.c
54550@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
54551 * get set to 0 so it will never get 'freed'
54552 */
54553 static struct fsnotify_event *q_overflow_event;
54554-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
54555+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
54556
54557 /**
54558 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
54559@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
54560 */
54561 u32 fsnotify_get_cookie(void)
54562 {
54563- return atomic_inc_return(&fsnotify_sync_cookie);
54564+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
54565 }
54566 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
54567
54568diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
54569index 99e3610..02c1068 100644
54570--- a/fs/ntfs/dir.c
54571+++ b/fs/ntfs/dir.c
54572@@ -1329,7 +1329,7 @@ find_next_index_buffer:
54573 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
54574 ~(s64)(ndir->itype.index.block_size - 1)));
54575 /* Bounds checks. */
54576- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
54577+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
54578 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
54579 "inode 0x%lx or driver bug.", vdir->i_ino);
54580 goto err_out;
54581diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
54582index 5b2d4f0..c6de396 100644
54583--- a/fs/ntfs/file.c
54584+++ b/fs/ntfs/file.c
54585@@ -2242,6 +2242,6 @@ const struct inode_operations ntfs_file_inode_ops = {
54586 #endif /* NTFS_RW */
54587 };
54588
54589-const struct file_operations ntfs_empty_file_ops = {};
54590+const struct file_operations ntfs_empty_file_ops __read_only;
54591
54592-const struct inode_operations ntfs_empty_inode_ops = {};
54593+const struct inode_operations ntfs_empty_inode_ops __read_only;
54594diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
54595index a9f78c7..ed8a381 100644
54596--- a/fs/ocfs2/localalloc.c
54597+++ b/fs/ocfs2/localalloc.c
54598@@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
54599 goto bail;
54600 }
54601
54602- atomic_inc(&osb->alloc_stats.moves);
54603+ atomic_inc_unchecked(&osb->alloc_stats.moves);
54604
54605 bail:
54606 if (handle)
54607diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
54608index d355e6e..578d905 100644
54609--- a/fs/ocfs2/ocfs2.h
54610+++ b/fs/ocfs2/ocfs2.h
54611@@ -235,11 +235,11 @@ enum ocfs2_vol_state
54612
54613 struct ocfs2_alloc_stats
54614 {
54615- atomic_t moves;
54616- atomic_t local_data;
54617- atomic_t bitmap_data;
54618- atomic_t bg_allocs;
54619- atomic_t bg_extends;
54620+ atomic_unchecked_t moves;
54621+ atomic_unchecked_t local_data;
54622+ atomic_unchecked_t bitmap_data;
54623+ atomic_unchecked_t bg_allocs;
54624+ atomic_unchecked_t bg_extends;
54625 };
54626
54627 enum ocfs2_local_alloc_state
54628diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
54629index b7e74b5..19c6536 100644
54630--- a/fs/ocfs2/suballoc.c
54631+++ b/fs/ocfs2/suballoc.c
54632@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
54633 mlog_errno(status);
54634 goto bail;
54635 }
54636- atomic_inc(&osb->alloc_stats.bg_extends);
54637+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
54638
54639 /* You should never ask for this much metadata */
54640 BUG_ON(bits_wanted >
54641@@ -2007,7 +2007,7 @@ int ocfs2_claim_metadata(handle_t *handle,
54642 mlog_errno(status);
54643 goto bail;
54644 }
54645- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54646+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54647
54648 *suballoc_loc = res.sr_bg_blkno;
54649 *suballoc_bit_start = res.sr_bit_offset;
54650@@ -2171,7 +2171,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
54651 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
54652 res->sr_bits);
54653
54654- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54655+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54656
54657 BUG_ON(res->sr_bits != 1);
54658
54659@@ -2213,7 +2213,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
54660 mlog_errno(status);
54661 goto bail;
54662 }
54663- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54664+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54665
54666 BUG_ON(res.sr_bits != 1);
54667
54668@@ -2317,7 +2317,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
54669 cluster_start,
54670 num_clusters);
54671 if (!status)
54672- atomic_inc(&osb->alloc_stats.local_data);
54673+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
54674 } else {
54675 if (min_clusters > (osb->bitmap_cpg - 1)) {
54676 /* The only paths asking for contiguousness
54677@@ -2343,7 +2343,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
54678 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
54679 res.sr_bg_blkno,
54680 res.sr_bit_offset);
54681- atomic_inc(&osb->alloc_stats.bitmap_data);
54682+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
54683 *num_clusters = res.sr_bits;
54684 }
54685 }
54686diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
54687index 0e91ec2..f4b3fc6 100644
54688--- a/fs/ocfs2/super.c
54689+++ b/fs/ocfs2/super.c
54690@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
54691 "%10s => GlobalAllocs: %d LocalAllocs: %d "
54692 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
54693 "Stats",
54694- atomic_read(&osb->alloc_stats.bitmap_data),
54695- atomic_read(&osb->alloc_stats.local_data),
54696- atomic_read(&osb->alloc_stats.bg_allocs),
54697- atomic_read(&osb->alloc_stats.moves),
54698- atomic_read(&osb->alloc_stats.bg_extends));
54699+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
54700+ atomic_read_unchecked(&osb->alloc_stats.local_data),
54701+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
54702+ atomic_read_unchecked(&osb->alloc_stats.moves),
54703+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
54704
54705 out += snprintf(buf + out, len - out,
54706 "%10s => State: %u Descriptor: %llu Size: %u bits "
54707@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
54708 spin_lock_init(&osb->osb_xattr_lock);
54709 ocfs2_init_steal_slots(osb);
54710
54711- atomic_set(&osb->alloc_stats.moves, 0);
54712- atomic_set(&osb->alloc_stats.local_data, 0);
54713- atomic_set(&osb->alloc_stats.bitmap_data, 0);
54714- atomic_set(&osb->alloc_stats.bg_allocs, 0);
54715- atomic_set(&osb->alloc_stats.bg_extends, 0);
54716+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
54717+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
54718+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
54719+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
54720+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
54721
54722 /* Copy the blockcheck stats from the superblock probe */
54723 osb->osb_ecc_stats = *stats;
54724diff --git a/fs/open.c b/fs/open.c
54725index 9b33c0c..2ffcca2 100644
54726--- a/fs/open.c
54727+++ b/fs/open.c
54728@@ -31,6 +31,8 @@
54729 #include <linux/ima.h>
54730 #include <linux/dnotify.h>
54731
54732+#define CREATE_TRACE_POINTS
54733+#include <trace/events/fs.h>
54734 #include "internal.h"
54735
54736 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
54737@@ -101,6 +103,8 @@ long vfs_truncate(struct path *path, loff_t length)
54738 error = locks_verify_truncate(inode, NULL, length);
54739 if (!error)
54740 error = security_path_truncate(path);
54741+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
54742+ error = -EACCES;
54743 if (!error)
54744 error = do_truncate(path->dentry, length, 0, NULL);
54745
54746@@ -178,6 +182,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
54747 error = locks_verify_truncate(inode, f.file, length);
54748 if (!error)
54749 error = security_path_truncate(&f.file->f_path);
54750+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
54751+ error = -EACCES;
54752 if (!error)
54753 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
54754 sb_end_write(inode->i_sb);
54755@@ -373,6 +379,9 @@ retry:
54756 if (__mnt_is_readonly(path.mnt))
54757 res = -EROFS;
54758
54759+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
54760+ res = -EACCES;
54761+
54762 out_path_release:
54763 path_put(&path);
54764 if (retry_estale(res, lookup_flags)) {
54765@@ -404,6 +413,8 @@ retry:
54766 if (error)
54767 goto dput_and_out;
54768
54769+ gr_log_chdir(path.dentry, path.mnt);
54770+
54771 set_fs_pwd(current->fs, &path);
54772
54773 dput_and_out:
54774@@ -433,6 +444,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
54775 goto out_putf;
54776
54777 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
54778+
54779+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
54780+ error = -EPERM;
54781+
54782+ if (!error)
54783+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
54784+
54785 if (!error)
54786 set_fs_pwd(current->fs, &f.file->f_path);
54787 out_putf:
54788@@ -462,7 +480,13 @@ retry:
54789 if (error)
54790 goto dput_and_out;
54791
54792+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
54793+ goto dput_and_out;
54794+
54795 set_fs_root(current->fs, &path);
54796+
54797+ gr_handle_chroot_chdir(&path);
54798+
54799 error = 0;
54800 dput_and_out:
54801 path_put(&path);
54802@@ -484,6 +508,16 @@ static int chmod_common(struct path *path, umode_t mode)
54803 if (error)
54804 return error;
54805 mutex_lock(&inode->i_mutex);
54806+
54807+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
54808+ error = -EACCES;
54809+ goto out_unlock;
54810+ }
54811+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
54812+ error = -EACCES;
54813+ goto out_unlock;
54814+ }
54815+
54816 error = security_path_chmod(path, mode);
54817 if (error)
54818 goto out_unlock;
54819@@ -544,6 +578,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
54820 uid = make_kuid(current_user_ns(), user);
54821 gid = make_kgid(current_user_ns(), group);
54822
54823+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
54824+ return -EACCES;
54825+
54826 newattrs.ia_valid = ATTR_CTIME;
54827 if (user != (uid_t) -1) {
54828 if (!uid_valid(uid))
54829@@ -960,6 +997,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
54830 } else {
54831 fsnotify_open(f);
54832 fd_install(fd, f);
54833+ trace_do_sys_open(tmp->name, flags, mode);
54834 }
54835 }
54836 putname(tmp);
54837diff --git a/fs/pipe.c b/fs/pipe.c
54838index 8e2e73f..1ef1048 100644
54839--- a/fs/pipe.c
54840+++ b/fs/pipe.c
54841@@ -438,9 +438,9 @@ redo:
54842 }
54843 if (bufs) /* More to do? */
54844 continue;
54845- if (!pipe->writers)
54846+ if (!atomic_read(&pipe->writers))
54847 break;
54848- if (!pipe->waiting_writers) {
54849+ if (!atomic_read(&pipe->waiting_writers)) {
54850 /* syscall merging: Usually we must not sleep
54851 * if O_NONBLOCK is set, or if we got some data.
54852 * But if a writer sleeps in kernel space, then
54853@@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
54854 mutex_lock(&inode->i_mutex);
54855 pipe = inode->i_pipe;
54856
54857- if (!pipe->readers) {
54858+ if (!atomic_read(&pipe->readers)) {
54859 send_sig(SIGPIPE, current, 0);
54860 ret = -EPIPE;
54861 goto out;
54862@@ -553,7 +553,7 @@ redo1:
54863 for (;;) {
54864 int bufs;
54865
54866- if (!pipe->readers) {
54867+ if (!atomic_read(&pipe->readers)) {
54868 send_sig(SIGPIPE, current, 0);
54869 if (!ret)
54870 ret = -EPIPE;
54871@@ -644,9 +644,9 @@ redo2:
54872 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
54873 do_wakeup = 0;
54874 }
54875- pipe->waiting_writers++;
54876+ atomic_inc(&pipe->waiting_writers);
54877 pipe_wait(pipe);
54878- pipe->waiting_writers--;
54879+ atomic_dec(&pipe->waiting_writers);
54880 }
54881 out:
54882 mutex_unlock(&inode->i_mutex);
54883@@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
54884 mask = 0;
54885 if (filp->f_mode & FMODE_READ) {
54886 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
54887- if (!pipe->writers && filp->f_version != pipe->w_counter)
54888+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
54889 mask |= POLLHUP;
54890 }
54891
54892@@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
54893 * Most Unices do not set POLLERR for FIFOs but on Linux they
54894 * behave exactly like pipes for poll().
54895 */
54896- if (!pipe->readers)
54897+ if (!atomic_read(&pipe->readers))
54898 mask |= POLLERR;
54899 }
54900
54901@@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
54902
54903 mutex_lock(&inode->i_mutex);
54904 pipe = inode->i_pipe;
54905- pipe->readers -= decr;
54906- pipe->writers -= decw;
54907+ atomic_sub(decr, &pipe->readers);
54908+ atomic_sub(decw, &pipe->writers);
54909
54910- if (!pipe->readers && !pipe->writers) {
54911+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
54912 free_pipe_info(inode);
54913 } else {
54914 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
54915@@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
54916
54917 if (inode->i_pipe) {
54918 ret = 0;
54919- inode->i_pipe->readers++;
54920+ atomic_inc(&inode->i_pipe->readers);
54921 }
54922
54923 mutex_unlock(&inode->i_mutex);
54924@@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
54925
54926 if (inode->i_pipe) {
54927 ret = 0;
54928- inode->i_pipe->writers++;
54929+ atomic_inc(&inode->i_pipe->writers);
54930 }
54931
54932 mutex_unlock(&inode->i_mutex);
54933@@ -871,9 +871,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
54934 if (inode->i_pipe) {
54935 ret = 0;
54936 if (filp->f_mode & FMODE_READ)
54937- inode->i_pipe->readers++;
54938+ atomic_inc(&inode->i_pipe->readers);
54939 if (filp->f_mode & FMODE_WRITE)
54940- inode->i_pipe->writers++;
54941+ atomic_inc(&inode->i_pipe->writers);
54942 }
54943
54944 mutex_unlock(&inode->i_mutex);
54945@@ -965,7 +965,7 @@ void free_pipe_info(struct inode *inode)
54946 inode->i_pipe = NULL;
54947 }
54948
54949-static struct vfsmount *pipe_mnt __read_mostly;
54950+struct vfsmount *pipe_mnt __read_mostly;
54951
54952 /*
54953 * pipefs_dname() is called from d_path().
54954@@ -995,7 +995,8 @@ static struct inode * get_pipe_inode(void)
54955 goto fail_iput;
54956 inode->i_pipe = pipe;
54957
54958- pipe->readers = pipe->writers = 1;
54959+ atomic_set(&pipe->readers, 1);
54960+ atomic_set(&pipe->writers, 1);
54961 inode->i_fop = &rdwr_pipefifo_fops;
54962
54963 /*
54964diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
54965index 15af622..0e9f4467 100644
54966--- a/fs/proc/Kconfig
54967+++ b/fs/proc/Kconfig
54968@@ -30,12 +30,12 @@ config PROC_FS
54969
54970 config PROC_KCORE
54971 bool "/proc/kcore support" if !ARM
54972- depends on PROC_FS && MMU
54973+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
54974
54975 config PROC_VMCORE
54976 bool "/proc/vmcore support"
54977- depends on PROC_FS && CRASH_DUMP
54978- default y
54979+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
54980+ default n
54981 help
54982 Exports the dump image of crashed kernel in ELF format.
54983
54984@@ -59,8 +59,8 @@ config PROC_SYSCTL
54985 limited in memory.
54986
54987 config PROC_PAGE_MONITOR
54988- default y
54989- depends on PROC_FS && MMU
54990+ default n
54991+ depends on PROC_FS && MMU && !GRKERNSEC
54992 bool "Enable /proc page monitoring" if EXPERT
54993 help
54994 Various /proc files exist to monitor process memory utilization:
54995diff --git a/fs/proc/array.c b/fs/proc/array.c
54996index 6a91e6f..e54dbc14 100644
54997--- a/fs/proc/array.c
54998+++ b/fs/proc/array.c
54999@@ -60,6 +60,7 @@
55000 #include <linux/tty.h>
55001 #include <linux/string.h>
55002 #include <linux/mman.h>
55003+#include <linux/grsecurity.h>
55004 #include <linux/proc_fs.h>
55005 #include <linux/ioport.h>
55006 #include <linux/uaccess.h>
55007@@ -362,6 +363,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
55008 seq_putc(m, '\n');
55009 }
55010
55011+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55012+static inline void task_pax(struct seq_file *m, struct task_struct *p)
55013+{
55014+ if (p->mm)
55015+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
55016+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
55017+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
55018+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
55019+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
55020+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
55021+ else
55022+ seq_printf(m, "PaX:\t-----\n");
55023+}
55024+#endif
55025+
55026 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
55027 struct pid *pid, struct task_struct *task)
55028 {
55029@@ -380,9 +396,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
55030 task_cpus_allowed(m, task);
55031 cpuset_task_status_allowed(m, task);
55032 task_context_switch_counts(m, task);
55033+
55034+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55035+ task_pax(m, task);
55036+#endif
55037+
55038+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
55039+ task_grsec_rbac(m, task);
55040+#endif
55041+
55042 return 0;
55043 }
55044
55045+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55046+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
55047+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
55048+ _mm->pax_flags & MF_PAX_SEGMEXEC))
55049+#endif
55050+
55051 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55052 struct pid *pid, struct task_struct *task, int whole)
55053 {
55054@@ -404,6 +435,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55055 char tcomm[sizeof(task->comm)];
55056 unsigned long flags;
55057
55058+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55059+ if (current->exec_id != m->exec_id) {
55060+ gr_log_badprocpid("stat");
55061+ return 0;
55062+ }
55063+#endif
55064+
55065 state = *get_task_state(task);
55066 vsize = eip = esp = 0;
55067 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
55068@@ -475,6 +513,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55069 gtime = task->gtime;
55070 }
55071
55072+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55073+ if (PAX_RAND_FLAGS(mm)) {
55074+ eip = 0;
55075+ esp = 0;
55076+ wchan = 0;
55077+ }
55078+#endif
55079+#ifdef CONFIG_GRKERNSEC_HIDESYM
55080+ wchan = 0;
55081+ eip =0;
55082+ esp =0;
55083+#endif
55084+
55085 /* scale priority and nice values from timeslices to -20..20 */
55086 /* to make it look like a "normal" Unix priority/nice value */
55087 priority = task_prio(task);
55088@@ -511,9 +562,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55089 seq_put_decimal_ull(m, ' ', vsize);
55090 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
55091 seq_put_decimal_ull(m, ' ', rsslim);
55092+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55093+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
55094+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
55095+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
55096+#else
55097 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
55098 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
55099 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
55100+#endif
55101 seq_put_decimal_ull(m, ' ', esp);
55102 seq_put_decimal_ull(m, ' ', eip);
55103 /* The signal information here is obsolete.
55104@@ -535,7 +592,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55105 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
55106 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
55107
55108- if (mm && permitted) {
55109+ if (mm && permitted
55110+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55111+ && !PAX_RAND_FLAGS(mm)
55112+#endif
55113+ ) {
55114 seq_put_decimal_ull(m, ' ', mm->start_data);
55115 seq_put_decimal_ull(m, ' ', mm->end_data);
55116 seq_put_decimal_ull(m, ' ', mm->start_brk);
55117@@ -573,8 +634,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
55118 struct pid *pid, struct task_struct *task)
55119 {
55120 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
55121- struct mm_struct *mm = get_task_mm(task);
55122+ struct mm_struct *mm;
55123
55124+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55125+ if (current->exec_id != m->exec_id) {
55126+ gr_log_badprocpid("statm");
55127+ return 0;
55128+ }
55129+#endif
55130+ mm = get_task_mm(task);
55131 if (mm) {
55132 size = task_statm(mm, &shared, &text, &data, &resident);
55133 mmput(mm);
55134@@ -597,6 +665,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
55135 return 0;
55136 }
55137
55138+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
55139+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
55140+{
55141+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
55142+}
55143+#endif
55144+
55145 #ifdef CONFIG_CHECKPOINT_RESTORE
55146 static struct pid *
55147 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
55148diff --git a/fs/proc/base.c b/fs/proc/base.c
55149index 9b43ff77..0fa9564 100644
55150--- a/fs/proc/base.c
55151+++ b/fs/proc/base.c
55152@@ -111,6 +111,14 @@ struct pid_entry {
55153 union proc_op op;
55154 };
55155
55156+struct getdents_callback {
55157+ struct linux_dirent __user * current_dir;
55158+ struct linux_dirent __user * previous;
55159+ struct file * file;
55160+ int count;
55161+ int error;
55162+};
55163+
55164 #define NOD(NAME, MODE, IOP, FOP, OP) { \
55165 .name = (NAME), \
55166 .len = sizeof(NAME) - 1, \
55167@@ -208,6 +216,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
55168 if (!mm->arg_end)
55169 goto out_mm; /* Shh! No looking before we're done */
55170
55171+ if (gr_acl_handle_procpidmem(task))
55172+ goto out_mm;
55173+
55174 len = mm->arg_end - mm->arg_start;
55175
55176 if (len > PAGE_SIZE)
55177@@ -235,12 +246,28 @@ out:
55178 return res;
55179 }
55180
55181+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55182+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
55183+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
55184+ _mm->pax_flags & MF_PAX_SEGMEXEC))
55185+#endif
55186+
55187 static int proc_pid_auxv(struct task_struct *task, char *buffer)
55188 {
55189 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
55190 int res = PTR_ERR(mm);
55191 if (mm && !IS_ERR(mm)) {
55192 unsigned int nwords = 0;
55193+
55194+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55195+ /* allow if we're currently ptracing this task */
55196+ if (PAX_RAND_FLAGS(mm) &&
55197+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
55198+ mmput(mm);
55199+ return 0;
55200+ }
55201+#endif
55202+
55203 do {
55204 nwords += 2;
55205 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
55206@@ -254,7 +281,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
55207 }
55208
55209
55210-#ifdef CONFIG_KALLSYMS
55211+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55212 /*
55213 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
55214 * Returns the resolved symbol. If that fails, simply return the address.
55215@@ -293,7 +320,7 @@ static void unlock_trace(struct task_struct *task)
55216 mutex_unlock(&task->signal->cred_guard_mutex);
55217 }
55218
55219-#ifdef CONFIG_STACKTRACE
55220+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55221
55222 #define MAX_STACK_TRACE_DEPTH 64
55223
55224@@ -485,7 +512,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
55225 return count;
55226 }
55227
55228-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
55229+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
55230 static int proc_pid_syscall(struct task_struct *task, char *buffer)
55231 {
55232 long nr;
55233@@ -514,7 +541,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
55234 /************************************************************************/
55235
55236 /* permission checks */
55237-static int proc_fd_access_allowed(struct inode *inode)
55238+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
55239 {
55240 struct task_struct *task;
55241 int allowed = 0;
55242@@ -524,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
55243 */
55244 task = get_proc_task(inode);
55245 if (task) {
55246- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
55247+ if (log)
55248+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
55249+ else
55250+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
55251 put_task_struct(task);
55252 }
55253 return allowed;
55254@@ -555,10 +585,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
55255 struct task_struct *task,
55256 int hide_pid_min)
55257 {
55258+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55259+ return false;
55260+
55261+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55262+ rcu_read_lock();
55263+ {
55264+ const struct cred *tmpcred = current_cred();
55265+ const struct cred *cred = __task_cred(task);
55266+
55267+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
55268+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55269+ || in_group_p(grsec_proc_gid)
55270+#endif
55271+ ) {
55272+ rcu_read_unlock();
55273+ return true;
55274+ }
55275+ }
55276+ rcu_read_unlock();
55277+
55278+ if (!pid->hide_pid)
55279+ return false;
55280+#endif
55281+
55282 if (pid->hide_pid < hide_pid_min)
55283 return true;
55284 if (in_group_p(pid->pid_gid))
55285 return true;
55286+
55287 return ptrace_may_access(task, PTRACE_MODE_READ);
55288 }
55289
55290@@ -576,7 +631,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
55291 put_task_struct(task);
55292
55293 if (!has_perms) {
55294+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55295+ {
55296+#else
55297 if (pid->hide_pid == 2) {
55298+#endif
55299 /*
55300 * Let's make getdents(), stat(), and open()
55301 * consistent with each other. If a process
55302@@ -674,6 +733,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
55303 if (!task)
55304 return -ESRCH;
55305
55306+ if (gr_acl_handle_procpidmem(task)) {
55307+ put_task_struct(task);
55308+ return -EPERM;
55309+ }
55310+
55311 mm = mm_access(task, mode);
55312 put_task_struct(task);
55313
55314@@ -689,6 +753,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
55315
55316 file->private_data = mm;
55317
55318+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55319+ file->f_version = current->exec_id;
55320+#endif
55321+
55322 return 0;
55323 }
55324
55325@@ -710,6 +778,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
55326 ssize_t copied;
55327 char *page;
55328
55329+#ifdef CONFIG_GRKERNSEC
55330+ if (write)
55331+ return -EPERM;
55332+#endif
55333+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55334+ if (file->f_version != current->exec_id) {
55335+ gr_log_badprocpid("mem");
55336+ return 0;
55337+ }
55338+#endif
55339+
55340 if (!mm)
55341 return 0;
55342
55343@@ -722,7 +801,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
55344 goto free;
55345
55346 while (count > 0) {
55347- int this_len = min_t(int, count, PAGE_SIZE);
55348+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
55349
55350 if (write && copy_from_user(page, buf, this_len)) {
55351 copied = -EFAULT;
55352@@ -814,6 +893,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
55353 if (!mm)
55354 return 0;
55355
55356+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55357+ if (file->f_version != current->exec_id) {
55358+ gr_log_badprocpid("environ");
55359+ return 0;
55360+ }
55361+#endif
55362+
55363 page = (char *)__get_free_page(GFP_TEMPORARY);
55364 if (!page)
55365 return -ENOMEM;
55366@@ -823,7 +909,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
55367 goto free;
55368 while (count > 0) {
55369 size_t this_len, max_len;
55370- int retval;
55371+ ssize_t retval;
55372
55373 if (src >= (mm->env_end - mm->env_start))
55374 break;
55375@@ -1429,7 +1515,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
55376 int error = -EACCES;
55377
55378 /* Are we allowed to snoop on the tasks file descriptors? */
55379- if (!proc_fd_access_allowed(inode))
55380+ if (!proc_fd_access_allowed(inode, 0))
55381 goto out;
55382
55383 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
55384@@ -1473,8 +1559,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
55385 struct path path;
55386
55387 /* Are we allowed to snoop on the tasks file descriptors? */
55388- if (!proc_fd_access_allowed(inode))
55389- goto out;
55390+ /* logging this is needed for learning on chromium to work properly,
55391+ but we don't want to flood the logs from 'ps' which does a readlink
55392+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
55393+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
55394+ */
55395+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
55396+ if (!proc_fd_access_allowed(inode,0))
55397+ goto out;
55398+ } else {
55399+ if (!proc_fd_access_allowed(inode,1))
55400+ goto out;
55401+ }
55402
55403 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
55404 if (error)
55405@@ -1524,7 +1620,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
55406 rcu_read_lock();
55407 cred = __task_cred(task);
55408 inode->i_uid = cred->euid;
55409+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55410+ inode->i_gid = grsec_proc_gid;
55411+#else
55412 inode->i_gid = cred->egid;
55413+#endif
55414 rcu_read_unlock();
55415 }
55416 security_task_to_inode(task, inode);
55417@@ -1560,10 +1660,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
55418 return -ENOENT;
55419 }
55420 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
55421+#ifdef CONFIG_GRKERNSEC_PROC_USER
55422+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
55423+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55424+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
55425+#endif
55426 task_dumpable(task)) {
55427 cred = __task_cred(task);
55428 stat->uid = cred->euid;
55429+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55430+ stat->gid = grsec_proc_gid;
55431+#else
55432 stat->gid = cred->egid;
55433+#endif
55434 }
55435 }
55436 rcu_read_unlock();
55437@@ -1601,11 +1710,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
55438
55439 if (task) {
55440 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
55441+#ifdef CONFIG_GRKERNSEC_PROC_USER
55442+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
55443+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55444+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
55445+#endif
55446 task_dumpable(task)) {
55447 rcu_read_lock();
55448 cred = __task_cred(task);
55449 inode->i_uid = cred->euid;
55450+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55451+ inode->i_gid = grsec_proc_gid;
55452+#else
55453 inode->i_gid = cred->egid;
55454+#endif
55455 rcu_read_unlock();
55456 } else {
55457 inode->i_uid = GLOBAL_ROOT_UID;
55458@@ -2058,6 +2176,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
55459 if (!task)
55460 goto out_no_task;
55461
55462+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55463+ goto out;
55464+
55465 /*
55466 * Yes, it does not scale. And it should not. Don't add
55467 * new entries into /proc/<tgid>/ without very good reasons.
55468@@ -2102,6 +2223,9 @@ static int proc_pident_readdir(struct file *filp,
55469 if (!task)
55470 goto out_no_task;
55471
55472+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55473+ goto out;
55474+
55475 ret = 0;
55476 i = filp->f_pos;
55477 switch (i) {
55478@@ -2515,7 +2639,7 @@ static const struct pid_entry tgid_base_stuff[] = {
55479 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
55480 #endif
55481 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
55482-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
55483+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
55484 INF("syscall", S_IRUGO, proc_pid_syscall),
55485 #endif
55486 INF("cmdline", S_IRUGO, proc_pid_cmdline),
55487@@ -2540,10 +2664,10 @@ static const struct pid_entry tgid_base_stuff[] = {
55488 #ifdef CONFIG_SECURITY
55489 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
55490 #endif
55491-#ifdef CONFIG_KALLSYMS
55492+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55493 INF("wchan", S_IRUGO, proc_pid_wchan),
55494 #endif
55495-#ifdef CONFIG_STACKTRACE
55496+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55497 ONE("stack", S_IRUGO, proc_pid_stack),
55498 #endif
55499 #ifdef CONFIG_SCHEDSTATS
55500@@ -2577,6 +2701,9 @@ static const struct pid_entry tgid_base_stuff[] = {
55501 #ifdef CONFIG_HARDWALL
55502 INF("hardwall", S_IRUGO, proc_pid_hardwall),
55503 #endif
55504+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
55505+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
55506+#endif
55507 #ifdef CONFIG_USER_NS
55508 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
55509 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
55510@@ -2705,7 +2832,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
55511 if (!inode)
55512 goto out;
55513
55514+#ifdef CONFIG_GRKERNSEC_PROC_USER
55515+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
55516+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55517+ inode->i_gid = grsec_proc_gid;
55518+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
55519+#else
55520 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
55521+#endif
55522 inode->i_op = &proc_tgid_base_inode_operations;
55523 inode->i_fop = &proc_tgid_base_operations;
55524 inode->i_flags|=S_IMMUTABLE;
55525@@ -2743,7 +2877,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
55526 if (!task)
55527 goto out;
55528
55529+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55530+ goto out_put_task;
55531+
55532 result = proc_pid_instantiate(dir, dentry, task, NULL);
55533+out_put_task:
55534 put_task_struct(task);
55535 out:
55536 return result;
55537@@ -2806,6 +2944,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
55538 static int fake_filldir(void *buf, const char *name, int namelen,
55539 loff_t offset, u64 ino, unsigned d_type)
55540 {
55541+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
55542+ __buf->error = -EINVAL;
55543 return 0;
55544 }
55545
55546@@ -2857,7 +2997,7 @@ static const struct pid_entry tid_base_stuff[] = {
55547 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
55548 #endif
55549 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
55550-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
55551+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
55552 INF("syscall", S_IRUGO, proc_pid_syscall),
55553 #endif
55554 INF("cmdline", S_IRUGO, proc_pid_cmdline),
55555@@ -2884,10 +3024,10 @@ static const struct pid_entry tid_base_stuff[] = {
55556 #ifdef CONFIG_SECURITY
55557 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
55558 #endif
55559-#ifdef CONFIG_KALLSYMS
55560+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55561 INF("wchan", S_IRUGO, proc_pid_wchan),
55562 #endif
55563-#ifdef CONFIG_STACKTRACE
55564+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55565 ONE("stack", S_IRUGO, proc_pid_stack),
55566 #endif
55567 #ifdef CONFIG_SCHEDSTATS
55568diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
55569index 82676e3..5f8518a 100644
55570--- a/fs/proc/cmdline.c
55571+++ b/fs/proc/cmdline.c
55572@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
55573
55574 static int __init proc_cmdline_init(void)
55575 {
55576+#ifdef CONFIG_GRKERNSEC_PROC_ADD
55577+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
55578+#else
55579 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
55580+#endif
55581 return 0;
55582 }
55583 module_init(proc_cmdline_init);
55584diff --git a/fs/proc/devices.c b/fs/proc/devices.c
55585index b143471..bb105e5 100644
55586--- a/fs/proc/devices.c
55587+++ b/fs/proc/devices.c
55588@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
55589
55590 static int __init proc_devices_init(void)
55591 {
55592+#ifdef CONFIG_GRKERNSEC_PROC_ADD
55593+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
55594+#else
55595 proc_create("devices", 0, NULL, &proc_devinfo_operations);
55596+#endif
55597 return 0;
55598 }
55599 module_init(proc_devices_init);
55600diff --git a/fs/proc/fd.c b/fs/proc/fd.c
55601index d7a4a28..0201742 100644
55602--- a/fs/proc/fd.c
55603+++ b/fs/proc/fd.c
55604@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
55605 if (!task)
55606 return -ENOENT;
55607
55608- files = get_files_struct(task);
55609+ if (!gr_acl_handle_procpidmem(task))
55610+ files = get_files_struct(task);
55611 put_task_struct(task);
55612
55613 if (files) {
55614@@ -302,11 +303,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
55615 */
55616 int proc_fd_permission(struct inode *inode, int mask)
55617 {
55618+ struct task_struct *task;
55619 int rv = generic_permission(inode, mask);
55620- if (rv == 0)
55621- return 0;
55622+
55623 if (task_pid(current) == proc_pid(inode))
55624 rv = 0;
55625+
55626+ task = get_proc_task(inode);
55627+ if (task == NULL)
55628+ return rv;
55629+
55630+ if (gr_acl_handle_procpidmem(task))
55631+ rv = -EACCES;
55632+
55633+ put_task_struct(task);
55634+
55635 return rv;
55636 }
55637
55638diff --git a/fs/proc/inode.c b/fs/proc/inode.c
55639index 0ac1e1b..0497e58 100644
55640--- a/fs/proc/inode.c
55641+++ b/fs/proc/inode.c
55642@@ -21,11 +21,17 @@
55643 #include <linux/seq_file.h>
55644 #include <linux/slab.h>
55645 #include <linux/mount.h>
55646+#include <linux/grsecurity.h>
55647
55648 #include <asm/uaccess.h>
55649
55650 #include "internal.h"
55651
55652+#ifdef CONFIG_PROC_SYSCTL
55653+extern const struct inode_operations proc_sys_inode_operations;
55654+extern const struct inode_operations proc_sys_dir_operations;
55655+#endif
55656+
55657 static void proc_evict_inode(struct inode *inode)
55658 {
55659 struct proc_dir_entry *de;
55660@@ -53,6 +59,13 @@ static void proc_evict_inode(struct inode *inode)
55661 ns = PROC_I(inode)->ns;
55662 if (ns_ops && ns)
55663 ns_ops->put(ns);
55664+
55665+#ifdef CONFIG_PROC_SYSCTL
55666+ if (inode->i_op == &proc_sys_inode_operations ||
55667+ inode->i_op == &proc_sys_dir_operations)
55668+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
55669+#endif
55670+
55671 }
55672
55673 static struct kmem_cache * proc_inode_cachep;
55674@@ -455,7 +468,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
55675 if (de->mode) {
55676 inode->i_mode = de->mode;
55677 inode->i_uid = de->uid;
55678+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55679+ inode->i_gid = grsec_proc_gid;
55680+#else
55681 inode->i_gid = de->gid;
55682+#endif
55683 }
55684 if (de->size)
55685 inode->i_size = de->size;
55686diff --git a/fs/proc/internal.h b/fs/proc/internal.h
55687index 252544c..04395b9 100644
55688--- a/fs/proc/internal.h
55689+++ b/fs/proc/internal.h
55690@@ -55,6 +55,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
55691 struct pid *pid, struct task_struct *task);
55692 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
55693 struct pid *pid, struct task_struct *task);
55694+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
55695+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
55696+#endif
55697 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
55698
55699 extern const struct file_operations proc_tid_children_operations;
55700diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
55701index e96d4f1..8b116ed 100644
55702--- a/fs/proc/kcore.c
55703+++ b/fs/proc/kcore.c
55704@@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
55705 * the addresses in the elf_phdr on our list.
55706 */
55707 start = kc_offset_to_vaddr(*fpos - elf_buflen);
55708- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
55709+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
55710+ if (tsz > buflen)
55711 tsz = buflen;
55712-
55713+
55714 while (buflen) {
55715 struct kcore_list *m;
55716
55717@@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
55718 kfree(elf_buf);
55719 } else {
55720 if (kern_addr_valid(start)) {
55721- unsigned long n;
55722+ char *elf_buf;
55723+ mm_segment_t oldfs;
55724
55725- n = copy_to_user(buffer, (char *)start, tsz);
55726- /*
55727- * We cannot distinguish between fault on source
55728- * and fault on destination. When this happens
55729- * we clear too and hope it will trigger the
55730- * EFAULT again.
55731- */
55732- if (n) {
55733- if (clear_user(buffer + tsz - n,
55734- n))
55735+ elf_buf = kmalloc(tsz, GFP_KERNEL);
55736+ if (!elf_buf)
55737+ return -ENOMEM;
55738+ oldfs = get_fs();
55739+ set_fs(KERNEL_DS);
55740+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
55741+ set_fs(oldfs);
55742+ if (copy_to_user(buffer, elf_buf, tsz)) {
55743+ kfree(elf_buf);
55744 return -EFAULT;
55745+ }
55746 }
55747+ set_fs(oldfs);
55748+ kfree(elf_buf);
55749 } else {
55750 if (clear_user(buffer, tsz))
55751 return -EFAULT;
55752@@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
55753
55754 static int open_kcore(struct inode *inode, struct file *filp)
55755 {
55756+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
55757+ return -EPERM;
55758+#endif
55759 if (!capable(CAP_SYS_RAWIO))
55760 return -EPERM;
55761 if (kcore_need_update)
55762diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
55763index 80e4645..53e5fcf 100644
55764--- a/fs/proc/meminfo.c
55765+++ b/fs/proc/meminfo.c
55766@@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
55767 vmi.used >> 10,
55768 vmi.largest_chunk >> 10
55769 #ifdef CONFIG_MEMORY_FAILURE
55770- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
55771+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
55772 #endif
55773 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
55774 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
55775diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
55776index b1822dd..df622cb 100644
55777--- a/fs/proc/nommu.c
55778+++ b/fs/proc/nommu.c
55779@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
55780 if (len < 1)
55781 len = 1;
55782 seq_printf(m, "%*c", len, ' ');
55783- seq_path(m, &file->f_path, "");
55784+ seq_path(m, &file->f_path, "\n\\");
55785 }
55786
55787 seq_putc(m, '\n');
55788diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
55789index fe72cd0..21b52ff 100644
55790--- a/fs/proc/proc_net.c
55791+++ b/fs/proc/proc_net.c
55792@@ -23,6 +23,7 @@
55793 #include <linux/nsproxy.h>
55794 #include <net/net_namespace.h>
55795 #include <linux/seq_file.h>
55796+#include <linux/grsecurity.h>
55797
55798 #include "internal.h"
55799
55800@@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
55801 struct task_struct *task;
55802 struct nsproxy *ns;
55803 struct net *net = NULL;
55804+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55805+ const struct cred *cred = current_cred();
55806+#endif
55807+
55808+#ifdef CONFIG_GRKERNSEC_PROC_USER
55809+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
55810+ return net;
55811+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55812+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
55813+ return net;
55814+#endif
55815
55816 rcu_read_lock();
55817 task = pid_task(proc_pid(dir), PIDTYPE_PID);
55818diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
55819index 1827d88..43b0279 100644
55820--- a/fs/proc/proc_sysctl.c
55821+++ b/fs/proc/proc_sysctl.c
55822@@ -12,11 +12,15 @@
55823 #include <linux/module.h>
55824 #include "internal.h"
55825
55826+extern int gr_handle_chroot_sysctl(const int op);
55827+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
55828+ const int op);
55829+
55830 static const struct dentry_operations proc_sys_dentry_operations;
55831 static const struct file_operations proc_sys_file_operations;
55832-static const struct inode_operations proc_sys_inode_operations;
55833+const struct inode_operations proc_sys_inode_operations;
55834 static const struct file_operations proc_sys_dir_file_operations;
55835-static const struct inode_operations proc_sys_dir_operations;
55836+const struct inode_operations proc_sys_dir_operations;
55837
55838 void proc_sys_poll_notify(struct ctl_table_poll *poll)
55839 {
55840@@ -466,6 +470,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
55841
55842 err = NULL;
55843 d_set_d_op(dentry, &proc_sys_dentry_operations);
55844+
55845+ gr_handle_proc_create(dentry, inode);
55846+
55847 d_add(dentry, inode);
55848
55849 out:
55850@@ -481,6 +488,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
55851 struct inode *inode = filp->f_path.dentry->d_inode;
55852 struct ctl_table_header *head = grab_header(inode);
55853 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
55854+ int op = write ? MAY_WRITE : MAY_READ;
55855 ssize_t error;
55856 size_t res;
55857
55858@@ -492,7 +500,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
55859 * and won't be until we finish.
55860 */
55861 error = -EPERM;
55862- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
55863+ if (sysctl_perm(head, table, op))
55864 goto out;
55865
55866 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
55867@@ -500,6 +508,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
55868 if (!table->proc_handler)
55869 goto out;
55870
55871+#ifdef CONFIG_GRKERNSEC
55872+ error = -EPERM;
55873+ if (gr_handle_chroot_sysctl(op))
55874+ goto out;
55875+ dget(filp->f_path.dentry);
55876+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
55877+ dput(filp->f_path.dentry);
55878+ goto out;
55879+ }
55880+ dput(filp->f_path.dentry);
55881+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
55882+ goto out;
55883+ if (write && !capable(CAP_SYS_ADMIN))
55884+ goto out;
55885+#endif
55886+
55887 /* careful: calling conventions are nasty here */
55888 res = count;
55889 error = table->proc_handler(table, write, buf, &res, ppos);
55890@@ -597,6 +621,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
55891 return -ENOMEM;
55892 } else {
55893 d_set_d_op(child, &proc_sys_dentry_operations);
55894+
55895+ gr_handle_proc_create(child, inode);
55896+
55897 d_add(child, inode);
55898 }
55899 } else {
55900@@ -640,6 +667,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
55901 if ((*pos)++ < file->f_pos)
55902 return 0;
55903
55904+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
55905+ return 0;
55906+
55907 if (unlikely(S_ISLNK(table->mode)))
55908 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
55909 else
55910@@ -750,6 +780,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
55911 if (IS_ERR(head))
55912 return PTR_ERR(head);
55913
55914+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
55915+ return -ENOENT;
55916+
55917 generic_fillattr(inode, stat);
55918 if (table)
55919 stat->mode = (stat->mode & S_IFMT) | table->mode;
55920@@ -772,13 +805,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
55921 .llseek = generic_file_llseek,
55922 };
55923
55924-static const struct inode_operations proc_sys_inode_operations = {
55925+const struct inode_operations proc_sys_inode_operations = {
55926 .permission = proc_sys_permission,
55927 .setattr = proc_sys_setattr,
55928 .getattr = proc_sys_getattr,
55929 };
55930
55931-static const struct inode_operations proc_sys_dir_operations = {
55932+const struct inode_operations proc_sys_dir_operations = {
55933 .lookup = proc_sys_lookup,
55934 .permission = proc_sys_permission,
55935 .setattr = proc_sys_setattr,
55936@@ -854,7 +887,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
55937 static struct ctl_dir *new_dir(struct ctl_table_set *set,
55938 const char *name, int namelen)
55939 {
55940- struct ctl_table *table;
55941+ ctl_table_no_const *table;
55942 struct ctl_dir *new;
55943 struct ctl_node *node;
55944 char *new_name;
55945@@ -866,7 +899,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
55946 return NULL;
55947
55948 node = (struct ctl_node *)(new + 1);
55949- table = (struct ctl_table *)(node + 1);
55950+ table = (ctl_table_no_const *)(node + 1);
55951 new_name = (char *)(table + 2);
55952 memcpy(new_name, name, namelen);
55953 new_name[namelen] = '\0';
55954@@ -1035,7 +1068,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
55955 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
55956 struct ctl_table_root *link_root)
55957 {
55958- struct ctl_table *link_table, *entry, *link;
55959+ ctl_table_no_const *link_table, *link;
55960+ struct ctl_table *entry;
55961 struct ctl_table_header *links;
55962 struct ctl_node *node;
55963 char *link_name;
55964@@ -1058,7 +1092,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
55965 return NULL;
55966
55967 node = (struct ctl_node *)(links + 1);
55968- link_table = (struct ctl_table *)(node + nr_entries);
55969+ link_table = (ctl_table_no_const *)(node + nr_entries);
55970 link_name = (char *)&link_table[nr_entries + 1];
55971
55972 for (link = link_table, entry = table; entry->procname; link++, entry++) {
55973@@ -1306,8 +1340,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
55974 struct ctl_table_header ***subheader, struct ctl_table_set *set,
55975 struct ctl_table *table)
55976 {
55977- struct ctl_table *ctl_table_arg = NULL;
55978- struct ctl_table *entry, *files;
55979+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
55980+ struct ctl_table *entry;
55981 int nr_files = 0;
55982 int nr_dirs = 0;
55983 int err = -ENOMEM;
55984@@ -1319,10 +1353,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
55985 nr_files++;
55986 }
55987
55988- files = table;
55989 /* If there are mixed files and directories we need a new table */
55990 if (nr_dirs && nr_files) {
55991- struct ctl_table *new;
55992+ ctl_table_no_const *new;
55993 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
55994 GFP_KERNEL);
55995 if (!files)
55996@@ -1340,7 +1373,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
55997 /* Register everything except a directory full of subdirectories */
55998 if (nr_files || !nr_dirs) {
55999 struct ctl_table_header *header;
56000- header = __register_sysctl_table(set, path, files);
56001+ header = __register_sysctl_table(set, path, files ? files : table);
56002 if (!header) {
56003 kfree(ctl_table_arg);
56004 goto out;
56005diff --git a/fs/proc/root.c b/fs/proc/root.c
56006index 9c7fab1..ed1c8e0 100644
56007--- a/fs/proc/root.c
56008+++ b/fs/proc/root.c
56009@@ -180,7 +180,15 @@ void __init proc_root_init(void)
56010 #ifdef CONFIG_PROC_DEVICETREE
56011 proc_device_tree_init();
56012 #endif
56013+#ifdef CONFIG_GRKERNSEC_PROC_ADD
56014+#ifdef CONFIG_GRKERNSEC_PROC_USER
56015+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
56016+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
56017+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
56018+#endif
56019+#else
56020 proc_mkdir("bus", NULL);
56021+#endif
56022 proc_sys_init();
56023 }
56024
56025diff --git a/fs/proc/self.c b/fs/proc/self.c
56026index aa5cc3b..c91a5d0 100644
56027--- a/fs/proc/self.c
56028+++ b/fs/proc/self.c
56029@@ -37,7 +37,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
56030 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
56031 void *cookie)
56032 {
56033- char *s = nd_get_link(nd);
56034+ const char *s = nd_get_link(nd);
56035 if (!IS_ERR(s))
56036 kfree(s);
56037 }
56038diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
56039index ca5ce7f..02c1cf0 100644
56040--- a/fs/proc/task_mmu.c
56041+++ b/fs/proc/task_mmu.c
56042@@ -11,12 +11,19 @@
56043 #include <linux/rmap.h>
56044 #include <linux/swap.h>
56045 #include <linux/swapops.h>
56046+#include <linux/grsecurity.h>
56047
56048 #include <asm/elf.h>
56049 #include <asm/uaccess.h>
56050 #include <asm/tlbflush.h>
56051 #include "internal.h"
56052
56053+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56054+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
56055+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
56056+ _mm->pax_flags & MF_PAX_SEGMEXEC))
56057+#endif
56058+
56059 void task_mem(struct seq_file *m, struct mm_struct *mm)
56060 {
56061 unsigned long data, text, lib, swap;
56062@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
56063 "VmExe:\t%8lu kB\n"
56064 "VmLib:\t%8lu kB\n"
56065 "VmPTE:\t%8lu kB\n"
56066- "VmSwap:\t%8lu kB\n",
56067- hiwater_vm << (PAGE_SHIFT-10),
56068+ "VmSwap:\t%8lu kB\n"
56069+
56070+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56071+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
56072+#endif
56073+
56074+ ,hiwater_vm << (PAGE_SHIFT-10),
56075 total_vm << (PAGE_SHIFT-10),
56076 mm->locked_vm << (PAGE_SHIFT-10),
56077 mm->pinned_vm << (PAGE_SHIFT-10),
56078@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
56079 data << (PAGE_SHIFT-10),
56080 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
56081 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
56082- swap << (PAGE_SHIFT-10));
56083+ swap << (PAGE_SHIFT-10)
56084+
56085+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56086+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56087+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
56088+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
56089+#else
56090+ , mm->context.user_cs_base
56091+ , mm->context.user_cs_limit
56092+#endif
56093+#endif
56094+
56095+ );
56096 }
56097
56098 unsigned long task_vsize(struct mm_struct *mm)
56099@@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56100 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
56101 }
56102
56103- /* We don't show the stack guard page in /proc/maps */
56104+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56105+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
56106+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
56107+#else
56108 start = vma->vm_start;
56109- if (stack_guard_page_start(vma, start))
56110- start += PAGE_SIZE;
56111 end = vma->vm_end;
56112- if (stack_guard_page_end(vma, end))
56113- end -= PAGE_SIZE;
56114+#endif
56115
56116 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
56117 start,
56118@@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56119 flags & VM_WRITE ? 'w' : '-',
56120 flags & VM_EXEC ? 'x' : '-',
56121 flags & VM_MAYSHARE ? 's' : 'p',
56122+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56123+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
56124+#else
56125 pgoff,
56126+#endif
56127 MAJOR(dev), MINOR(dev), ino, &len);
56128
56129 /*
56130@@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56131 */
56132 if (file) {
56133 pad_len_spaces(m, len);
56134- seq_path(m, &file->f_path, "\n");
56135+ seq_path(m, &file->f_path, "\n\\");
56136 goto done;
56137 }
56138
56139@@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56140 * Thread stack in /proc/PID/task/TID/maps or
56141 * the main process stack.
56142 */
56143- if (!is_pid || (vma->vm_start <= mm->start_stack &&
56144- vma->vm_end >= mm->start_stack)) {
56145+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
56146+ (vma->vm_start <= mm->start_stack &&
56147+ vma->vm_end >= mm->start_stack)) {
56148 name = "[stack]";
56149 } else {
56150 /* Thread stack in /proc/PID/maps */
56151@@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
56152 struct proc_maps_private *priv = m->private;
56153 struct task_struct *task = priv->task;
56154
56155+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56156+ if (current->exec_id != m->exec_id) {
56157+ gr_log_badprocpid("maps");
56158+ return 0;
56159+ }
56160+#endif
56161+
56162 show_map_vma(m, vma, is_pid);
56163
56164 if (m->count < m->size) /* vma is copied successfully */
56165@@ -589,12 +625,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
56166 .private = &mss,
56167 };
56168
56169+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56170+ if (current->exec_id != m->exec_id) {
56171+ gr_log_badprocpid("smaps");
56172+ return 0;
56173+ }
56174+#endif
56175 memset(&mss, 0, sizeof mss);
56176- mss.vma = vma;
56177- /* mmap_sem is held in m_start */
56178- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
56179- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
56180-
56181+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56182+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
56183+#endif
56184+ mss.vma = vma;
56185+ /* mmap_sem is held in m_start */
56186+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
56187+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
56188+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56189+ }
56190+#endif
56191 show_map_vma(m, vma, is_pid);
56192
56193 seq_printf(m,
56194@@ -612,7 +659,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
56195 "KernelPageSize: %8lu kB\n"
56196 "MMUPageSize: %8lu kB\n"
56197 "Locked: %8lu kB\n",
56198+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56199+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
56200+#else
56201 (vma->vm_end - vma->vm_start) >> 10,
56202+#endif
56203 mss.resident >> 10,
56204 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
56205 mss.shared_clean >> 10,
56206@@ -1264,6 +1315,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
56207 int n;
56208 char buffer[50];
56209
56210+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56211+ if (current->exec_id != m->exec_id) {
56212+ gr_log_badprocpid("numa_maps");
56213+ return 0;
56214+ }
56215+#endif
56216+
56217 if (!mm)
56218 return 0;
56219
56220@@ -1281,11 +1339,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
56221 mpol_to_str(buffer, sizeof(buffer), pol);
56222 mpol_cond_put(pol);
56223
56224+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56225+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
56226+#else
56227 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
56228+#endif
56229
56230 if (file) {
56231 seq_printf(m, " file=");
56232- seq_path(m, &file->f_path, "\n\t= ");
56233+ seq_path(m, &file->f_path, "\n\t\\= ");
56234 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
56235 seq_printf(m, " heap");
56236 } else {
56237diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
56238index 1ccfa53..0848f95 100644
56239--- a/fs/proc/task_nommu.c
56240+++ b/fs/proc/task_nommu.c
56241@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
56242 else
56243 bytes += kobjsize(mm);
56244
56245- if (current->fs && current->fs->users > 1)
56246+ if (current->fs && atomic_read(&current->fs->users) > 1)
56247 sbytes += kobjsize(current->fs);
56248 else
56249 bytes += kobjsize(current->fs);
56250@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
56251
56252 if (file) {
56253 pad_len_spaces(m, len);
56254- seq_path(m, &file->f_path, "");
56255+ seq_path(m, &file->f_path, "\n\\");
56256 } else if (mm) {
56257 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
56258
56259diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
56260index b00fcc9..e0c6381 100644
56261--- a/fs/qnx6/qnx6.h
56262+++ b/fs/qnx6/qnx6.h
56263@@ -74,7 +74,7 @@ enum {
56264 BYTESEX_BE,
56265 };
56266
56267-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
56268+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
56269 {
56270 if (sbi->s_bytesex == BYTESEX_LE)
56271 return le64_to_cpu((__force __le64)n);
56272@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
56273 return (__force __fs64)cpu_to_be64(n);
56274 }
56275
56276-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
56277+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
56278 {
56279 if (sbi->s_bytesex == BYTESEX_LE)
56280 return le32_to_cpu((__force __le32)n);
56281diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
56282index 16e8abb..2dcf914 100644
56283--- a/fs/quota/netlink.c
56284+++ b/fs/quota/netlink.c
56285@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
56286 void quota_send_warning(struct kqid qid, dev_t dev,
56287 const char warntype)
56288 {
56289- static atomic_t seq;
56290+ static atomic_unchecked_t seq;
56291 struct sk_buff *skb;
56292 void *msg_head;
56293 int ret;
56294@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
56295 "VFS: Not enough memory to send quota warning.\n");
56296 return;
56297 }
56298- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
56299+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
56300 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
56301 if (!msg_head) {
56302 printk(KERN_ERR
56303diff --git a/fs/readdir.c b/fs/readdir.c
56304index 5e69ef5..e5d9099 100644
56305--- a/fs/readdir.c
56306+++ b/fs/readdir.c
56307@@ -17,6 +17,7 @@
56308 #include <linux/security.h>
56309 #include <linux/syscalls.h>
56310 #include <linux/unistd.h>
56311+#include <linux/namei.h>
56312
56313 #include <asm/uaccess.h>
56314
56315@@ -67,6 +68,7 @@ struct old_linux_dirent {
56316
56317 struct readdir_callback {
56318 struct old_linux_dirent __user * dirent;
56319+ struct file * file;
56320 int result;
56321 };
56322
56323@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
56324 buf->result = -EOVERFLOW;
56325 return -EOVERFLOW;
56326 }
56327+
56328+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56329+ return 0;
56330+
56331 buf->result++;
56332 dirent = buf->dirent;
56333 if (!access_ok(VERIFY_WRITE, dirent,
56334@@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
56335
56336 buf.result = 0;
56337 buf.dirent = dirent;
56338+ buf.file = f.file;
56339
56340 error = vfs_readdir(f.file, fillonedir, &buf);
56341 if (buf.result)
56342@@ -139,6 +146,7 @@ struct linux_dirent {
56343 struct getdents_callback {
56344 struct linux_dirent __user * current_dir;
56345 struct linux_dirent __user * previous;
56346+ struct file * file;
56347 int count;
56348 int error;
56349 };
56350@@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
56351 buf->error = -EOVERFLOW;
56352 return -EOVERFLOW;
56353 }
56354+
56355+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56356+ return 0;
56357+
56358 dirent = buf->previous;
56359 if (dirent) {
56360 if (__put_user(offset, &dirent->d_off))
56361@@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
56362 buf.previous = NULL;
56363 buf.count = count;
56364 buf.error = 0;
56365+ buf.file = f.file;
56366
56367 error = vfs_readdir(f.file, filldir, &buf);
56368 if (error >= 0)
56369@@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
56370 struct getdents_callback64 {
56371 struct linux_dirent64 __user * current_dir;
56372 struct linux_dirent64 __user * previous;
56373+ struct file *file;
56374 int count;
56375 int error;
56376 };
56377@@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
56378 buf->error = -EINVAL; /* only used if we fail.. */
56379 if (reclen > buf->count)
56380 return -EINVAL;
56381+
56382+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56383+ return 0;
56384+
56385 dirent = buf->previous;
56386 if (dirent) {
56387 if (__put_user(offset, &dirent->d_off))
56388@@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
56389
56390 buf.current_dir = dirent;
56391 buf.previous = NULL;
56392+ buf.file = f.file;
56393 buf.count = count;
56394 buf.error = 0;
56395
56396@@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
56397 error = buf.error;
56398 lastdirent = buf.previous;
56399 if (lastdirent) {
56400- typeof(lastdirent->d_off) d_off = f.file->f_pos;
56401+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
56402 if (__put_user(d_off, &lastdirent->d_off))
56403 error = -EFAULT;
56404 else
56405diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
56406index 2b7882b..1c5ef48 100644
56407--- a/fs/reiserfs/do_balan.c
56408+++ b/fs/reiserfs/do_balan.c
56409@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
56410 return;
56411 }
56412
56413- atomic_inc(&(fs_generation(tb->tb_sb)));
56414+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
56415 do_balance_starts(tb);
56416
56417 /* balance leaf returns 0 except if combining L R and S into
56418diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
56419index e60e870..f40ac16 100644
56420--- a/fs/reiserfs/procfs.c
56421+++ b/fs/reiserfs/procfs.c
56422@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
56423 "SMALL_TAILS " : "NO_TAILS ",
56424 replay_only(sb) ? "REPLAY_ONLY " : "",
56425 convert_reiserfs(sb) ? "CONV " : "",
56426- atomic_read(&r->s_generation_counter),
56427+ atomic_read_unchecked(&r->s_generation_counter),
56428 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
56429 SF(s_do_balance), SF(s_unneeded_left_neighbor),
56430 SF(s_good_search_by_key_reada), SF(s_bmaps),
56431diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
56432index 157e474..65a6114 100644
56433--- a/fs/reiserfs/reiserfs.h
56434+++ b/fs/reiserfs/reiserfs.h
56435@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
56436 /* Comment? -Hans */
56437 wait_queue_head_t s_wait;
56438 /* To be obsoleted soon by per buffer seals.. -Hans */
56439- atomic_t s_generation_counter; // increased by one every time the
56440+ atomic_unchecked_t s_generation_counter; // increased by one every time the
56441 // tree gets re-balanced
56442 unsigned long s_properties; /* File system properties. Currently holds
56443 on-disk FS format */
56444@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
56445 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
56446
56447 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
56448-#define get_generation(s) atomic_read (&fs_generation(s))
56449+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
56450 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
56451 #define __fs_changed(gen,s) (gen != get_generation (s))
56452 #define fs_changed(gen,s) \
56453diff --git a/fs/select.c b/fs/select.c
56454index 2ef72d9..f213b17 100644
56455--- a/fs/select.c
56456+++ b/fs/select.c
56457@@ -20,6 +20,7 @@
56458 #include <linux/export.h>
56459 #include <linux/slab.h>
56460 #include <linux/poll.h>
56461+#include <linux/security.h>
56462 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
56463 #include <linux/file.h>
56464 #include <linux/fdtable.h>
56465@@ -826,6 +827,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
56466 struct poll_list *walk = head;
56467 unsigned long todo = nfds;
56468
56469+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
56470 if (nfds > rlimit(RLIMIT_NOFILE))
56471 return -EINVAL;
56472
56473diff --git a/fs/seq_file.c b/fs/seq_file.c
56474index f2bc3df..239d4f6 100644
56475--- a/fs/seq_file.c
56476+++ b/fs/seq_file.c
56477@@ -10,6 +10,7 @@
56478 #include <linux/seq_file.h>
56479 #include <linux/slab.h>
56480 #include <linux/cred.h>
56481+#include <linux/sched.h>
56482
56483 #include <asm/uaccess.h>
56484 #include <asm/page.h>
56485@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
56486 #ifdef CONFIG_USER_NS
56487 p->user_ns = file->f_cred->user_ns;
56488 #endif
56489+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56490+ p->exec_id = current->exec_id;
56491+#endif
56492
56493 /*
56494 * Wrappers around seq_open(e.g. swaps_open) need to be
56495@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
56496 return 0;
56497 }
56498 if (!m->buf) {
56499- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
56500+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
56501 if (!m->buf)
56502 return -ENOMEM;
56503 }
56504@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
56505 Eoverflow:
56506 m->op->stop(m, p);
56507 kfree(m->buf);
56508- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
56509+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
56510 return !m->buf ? -ENOMEM : -EAGAIN;
56511 }
56512
56513@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
56514
56515 /* grab buffer if we didn't have one */
56516 if (!m->buf) {
56517- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
56518+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
56519 if (!m->buf)
56520 goto Enomem;
56521 }
56522@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
56523 goto Fill;
56524 m->op->stop(m, p);
56525 kfree(m->buf);
56526- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
56527+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
56528 if (!m->buf)
56529 goto Enomem;
56530 m->count = 0;
56531@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
56532 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
56533 void *data)
56534 {
56535- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
56536+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
56537 int res = -ENOMEM;
56538
56539 if (op) {
56540diff --git a/fs/splice.c b/fs/splice.c
56541index 6909d89..5b2e8f9 100644
56542--- a/fs/splice.c
56543+++ b/fs/splice.c
56544@@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
56545 pipe_lock(pipe);
56546
56547 for (;;) {
56548- if (!pipe->readers) {
56549+ if (!atomic_read(&pipe->readers)) {
56550 send_sig(SIGPIPE, current, 0);
56551 if (!ret)
56552 ret = -EPIPE;
56553@@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
56554 do_wakeup = 0;
56555 }
56556
56557- pipe->waiting_writers++;
56558+ atomic_inc(&pipe->waiting_writers);
56559 pipe_wait(pipe);
56560- pipe->waiting_writers--;
56561+ atomic_dec(&pipe->waiting_writers);
56562 }
56563
56564 pipe_unlock(pipe);
56565@@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
56566 old_fs = get_fs();
56567 set_fs(get_ds());
56568 /* The cast to a user pointer is valid due to the set_fs() */
56569- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
56570+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
56571 set_fs(old_fs);
56572
56573 return res;
56574@@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
56575 old_fs = get_fs();
56576 set_fs(get_ds());
56577 /* The cast to a user pointer is valid due to the set_fs() */
56578- res = vfs_write(file, (const char __user *)buf, count, &pos);
56579+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
56580 set_fs(old_fs);
56581
56582 return res;
56583@@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
56584 goto err;
56585
56586 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
56587- vec[i].iov_base = (void __user *) page_address(page);
56588+ vec[i].iov_base = (void __force_user *) page_address(page);
56589 vec[i].iov_len = this_len;
56590 spd.pages[i] = page;
56591 spd.nr_pages++;
56592@@ -851,10 +851,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
56593 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
56594 {
56595 while (!pipe->nrbufs) {
56596- if (!pipe->writers)
56597+ if (!atomic_read(&pipe->writers))
56598 return 0;
56599
56600- if (!pipe->waiting_writers && sd->num_spliced)
56601+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
56602 return 0;
56603
56604 if (sd->flags & SPLICE_F_NONBLOCK)
56605@@ -1189,7 +1189,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
56606 * out of the pipe right after the splice_to_pipe(). So set
56607 * PIPE_READERS appropriately.
56608 */
56609- pipe->readers = 1;
56610+ atomic_set(&pipe->readers, 1);
56611
56612 current->splice_pipe = pipe;
56613 }
56614@@ -1738,9 +1738,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
56615 ret = -ERESTARTSYS;
56616 break;
56617 }
56618- if (!pipe->writers)
56619+ if (!atomic_read(&pipe->writers))
56620 break;
56621- if (!pipe->waiting_writers) {
56622+ if (!atomic_read(&pipe->waiting_writers)) {
56623 if (flags & SPLICE_F_NONBLOCK) {
56624 ret = -EAGAIN;
56625 break;
56626@@ -1772,7 +1772,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
56627 pipe_lock(pipe);
56628
56629 while (pipe->nrbufs >= pipe->buffers) {
56630- if (!pipe->readers) {
56631+ if (!atomic_read(&pipe->readers)) {
56632 send_sig(SIGPIPE, current, 0);
56633 ret = -EPIPE;
56634 break;
56635@@ -1785,9 +1785,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
56636 ret = -ERESTARTSYS;
56637 break;
56638 }
56639- pipe->waiting_writers++;
56640+ atomic_inc(&pipe->waiting_writers);
56641 pipe_wait(pipe);
56642- pipe->waiting_writers--;
56643+ atomic_dec(&pipe->waiting_writers);
56644 }
56645
56646 pipe_unlock(pipe);
56647@@ -1823,14 +1823,14 @@ retry:
56648 pipe_double_lock(ipipe, opipe);
56649
56650 do {
56651- if (!opipe->readers) {
56652+ if (!atomic_read(&opipe->readers)) {
56653 send_sig(SIGPIPE, current, 0);
56654 if (!ret)
56655 ret = -EPIPE;
56656 break;
56657 }
56658
56659- if (!ipipe->nrbufs && !ipipe->writers)
56660+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
56661 break;
56662
56663 /*
56664@@ -1927,7 +1927,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
56665 pipe_double_lock(ipipe, opipe);
56666
56667 do {
56668- if (!opipe->readers) {
56669+ if (!atomic_read(&opipe->readers)) {
56670 send_sig(SIGPIPE, current, 0);
56671 if (!ret)
56672 ret = -EPIPE;
56673@@ -1972,7 +1972,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
56674 * return EAGAIN if we have the potential of some data in the
56675 * future, otherwise just return 0
56676 */
56677- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
56678+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
56679 ret = -EAGAIN;
56680
56681 pipe_unlock(ipipe);
56682diff --git a/fs/stat.c b/fs/stat.c
56683index 14f4545..9b7f55b 100644
56684--- a/fs/stat.c
56685+++ b/fs/stat.c
56686@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
56687 stat->gid = inode->i_gid;
56688 stat->rdev = inode->i_rdev;
56689 stat->size = i_size_read(inode);
56690- stat->atime = inode->i_atime;
56691- stat->mtime = inode->i_mtime;
56692+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
56693+ stat->atime = inode->i_ctime;
56694+ stat->mtime = inode->i_ctime;
56695+ } else {
56696+ stat->atime = inode->i_atime;
56697+ stat->mtime = inode->i_mtime;
56698+ }
56699 stat->ctime = inode->i_ctime;
56700 stat->blksize = (1 << inode->i_blkbits);
56701 stat->blocks = inode->i_blocks;
56702@@ -46,8 +51,14 @@ int vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
56703 if (retval)
56704 return retval;
56705
56706- if (inode->i_op->getattr)
56707- return inode->i_op->getattr(mnt, dentry, stat);
56708+ if (inode->i_op->getattr) {
56709+ retval = inode->i_op->getattr(mnt, dentry, stat);
56710+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
56711+ stat->atime = stat->ctime;
56712+ stat->mtime = stat->ctime;
56713+ }
56714+ return retval;
56715+ }
56716
56717 generic_fillattr(inode, stat);
56718 return 0;
56719diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
56720index 614b2b5..4d321e6 100644
56721--- a/fs/sysfs/bin.c
56722+++ b/fs/sysfs/bin.c
56723@@ -235,13 +235,13 @@ static int bin_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
56724 return ret;
56725 }
56726
56727-static int bin_access(struct vm_area_struct *vma, unsigned long addr,
56728- void *buf, int len, int write)
56729+static ssize_t bin_access(struct vm_area_struct *vma, unsigned long addr,
56730+ void *buf, size_t len, int write)
56731 {
56732 struct file *file = vma->vm_file;
56733 struct bin_buffer *bb = file->private_data;
56734 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
56735- int ret;
56736+ ssize_t ret;
56737
56738 if (!bb->vm_ops)
56739 return -EINVAL;
56740diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
56741index 1f8c823..ed57cfe 100644
56742--- a/fs/sysfs/dir.c
56743+++ b/fs/sysfs/dir.c
56744@@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
56745 *
56746 * Returns 31 bit hash of ns + name (so it fits in an off_t )
56747 */
56748-static unsigned int sysfs_name_hash(const void *ns, const char *name)
56749+static unsigned int sysfs_name_hash(const void *ns, const unsigned char *name)
56750 {
56751 unsigned long hash = init_name_hash();
56752 unsigned int len = strlen(name);
56753@@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
56754 struct sysfs_dirent *sd;
56755 int rc;
56756
56757+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
56758+ const char *parent_name = parent_sd->s_name;
56759+
56760+ mode = S_IFDIR | S_IRWXU;
56761+
56762+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
56763+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
56764+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
56765+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
56766+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
56767+#endif
56768+
56769 /* allocate */
56770 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
56771 if (!sd)
56772diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
56773index 602f56d..6853db8 100644
56774--- a/fs/sysfs/file.c
56775+++ b/fs/sysfs/file.c
56776@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
56777
56778 struct sysfs_open_dirent {
56779 atomic_t refcnt;
56780- atomic_t event;
56781+ atomic_unchecked_t event;
56782 wait_queue_head_t poll;
56783 struct list_head buffers; /* goes through sysfs_buffer.list */
56784 };
56785@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
56786 if (!sysfs_get_active(attr_sd))
56787 return -ENODEV;
56788
56789- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
56790+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
56791 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
56792
56793 sysfs_put_active(attr_sd);
56794@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
56795 return -ENOMEM;
56796
56797 atomic_set(&new_od->refcnt, 0);
56798- atomic_set(&new_od->event, 1);
56799+ atomic_set_unchecked(&new_od->event, 1);
56800 init_waitqueue_head(&new_od->poll);
56801 INIT_LIST_HEAD(&new_od->buffers);
56802 goto retry;
56803@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
56804
56805 sysfs_put_active(attr_sd);
56806
56807- if (buffer->event != atomic_read(&od->event))
56808+ if (buffer->event != atomic_read_unchecked(&od->event))
56809 goto trigger;
56810
56811 return DEFAULT_POLLMASK;
56812@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
56813
56814 od = sd->s_attr.open;
56815 if (od) {
56816- atomic_inc(&od->event);
56817+ atomic_inc_unchecked(&od->event);
56818 wake_up_interruptible(&od->poll);
56819 }
56820
56821diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
56822index 3c9eb56..9dea5be 100644
56823--- a/fs/sysfs/symlink.c
56824+++ b/fs/sysfs/symlink.c
56825@@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
56826
56827 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
56828 {
56829- char *page = nd_get_link(nd);
56830+ const char *page = nd_get_link(nd);
56831 if (!IS_ERR(page))
56832 free_page((unsigned long)page);
56833 }
56834diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
56835index 69d4889..a810bd4 100644
56836--- a/fs/sysv/sysv.h
56837+++ b/fs/sysv/sysv.h
56838@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
56839 #endif
56840 }
56841
56842-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
56843+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
56844 {
56845 if (sbi->s_bytesex == BYTESEX_PDP)
56846 return PDP_swab((__force __u32)n);
56847diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
56848index e18b988..f1d4ad0f 100644
56849--- a/fs/ubifs/io.c
56850+++ b/fs/ubifs/io.c
56851@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
56852 return err;
56853 }
56854
56855-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
56856+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
56857 {
56858 int err;
56859
56860diff --git a/fs/udf/misc.c b/fs/udf/misc.c
56861index c175b4d..8f36a16 100644
56862--- a/fs/udf/misc.c
56863+++ b/fs/udf/misc.c
56864@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
56865
56866 u8 udf_tag_checksum(const struct tag *t)
56867 {
56868- u8 *data = (u8 *)t;
56869+ const u8 *data = (const u8 *)t;
56870 u8 checksum = 0;
56871 int i;
56872 for (i = 0; i < sizeof(struct tag); ++i)
56873diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
56874index 8d974c4..b82f6ec 100644
56875--- a/fs/ufs/swab.h
56876+++ b/fs/ufs/swab.h
56877@@ -22,7 +22,7 @@ enum {
56878 BYTESEX_BE
56879 };
56880
56881-static inline u64
56882+static inline u64 __intentional_overflow(-1)
56883 fs64_to_cpu(struct super_block *sbp, __fs64 n)
56884 {
56885 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
56886@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
56887 return (__force __fs64)cpu_to_be64(n);
56888 }
56889
56890-static inline u32
56891+static inline u32 __intentional_overflow(-1)
56892 fs32_to_cpu(struct super_block *sbp, __fs32 n)
56893 {
56894 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
56895diff --git a/fs/utimes.c b/fs/utimes.c
56896index f4fb7ec..3fe03c0 100644
56897--- a/fs/utimes.c
56898+++ b/fs/utimes.c
56899@@ -1,6 +1,7 @@
56900 #include <linux/compiler.h>
56901 #include <linux/file.h>
56902 #include <linux/fs.h>
56903+#include <linux/security.h>
56904 #include <linux/linkage.h>
56905 #include <linux/mount.h>
56906 #include <linux/namei.h>
56907@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
56908 goto mnt_drop_write_and_out;
56909 }
56910 }
56911+
56912+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
56913+ error = -EACCES;
56914+ goto mnt_drop_write_and_out;
56915+ }
56916+
56917 mutex_lock(&inode->i_mutex);
56918 error = notify_change(path->dentry, &newattrs);
56919 mutex_unlock(&inode->i_mutex);
56920diff --git a/fs/xattr.c b/fs/xattr.c
56921index 3377dff..4feded6 100644
56922--- a/fs/xattr.c
56923+++ b/fs/xattr.c
56924@@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
56925 * Extended attribute SET operations
56926 */
56927 static long
56928-setxattr(struct dentry *d, const char __user *name, const void __user *value,
56929+setxattr(struct path *path, const char __user *name, const void __user *value,
56930 size_t size, int flags)
56931 {
56932 int error;
56933@@ -355,7 +355,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
56934 posix_acl_fix_xattr_from_user(kvalue, size);
56935 }
56936
56937- error = vfs_setxattr(d, kname, kvalue, size, flags);
56938+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
56939+ error = -EACCES;
56940+ goto out;
56941+ }
56942+
56943+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
56944 out:
56945 if (vvalue)
56946 vfree(vvalue);
56947@@ -377,7 +382,7 @@ retry:
56948 return error;
56949 error = mnt_want_write(path.mnt);
56950 if (!error) {
56951- error = setxattr(path.dentry, name, value, size, flags);
56952+ error = setxattr(&path, name, value, size, flags);
56953 mnt_drop_write(path.mnt);
56954 }
56955 path_put(&path);
56956@@ -401,7 +406,7 @@ retry:
56957 return error;
56958 error = mnt_want_write(path.mnt);
56959 if (!error) {
56960- error = setxattr(path.dentry, name, value, size, flags);
56961+ error = setxattr(&path, name, value, size, flags);
56962 mnt_drop_write(path.mnt);
56963 }
56964 path_put(&path);
56965@@ -416,16 +421,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
56966 const void __user *,value, size_t, size, int, flags)
56967 {
56968 struct fd f = fdget(fd);
56969- struct dentry *dentry;
56970 int error = -EBADF;
56971
56972 if (!f.file)
56973 return error;
56974- dentry = f.file->f_path.dentry;
56975- audit_inode(NULL, dentry, 0);
56976+ audit_inode(NULL, f.file->f_path.dentry, 0);
56977 error = mnt_want_write_file(f.file);
56978 if (!error) {
56979- error = setxattr(dentry, name, value, size, flags);
56980+ error = setxattr(&f.file->f_path, name, value, size, flags);
56981 mnt_drop_write_file(f.file);
56982 }
56983 fdput(f);
56984diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
56985index 9fbea87..6b19972 100644
56986--- a/fs/xattr_acl.c
56987+++ b/fs/xattr_acl.c
56988@@ -76,8 +76,8 @@ struct posix_acl *
56989 posix_acl_from_xattr(struct user_namespace *user_ns,
56990 const void *value, size_t size)
56991 {
56992- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
56993- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
56994+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
56995+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
56996 int count;
56997 struct posix_acl *acl;
56998 struct posix_acl_entry *acl_e;
56999diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
57000index 572a858..12a9b0d 100644
57001--- a/fs/xfs/xfs_bmap.c
57002+++ b/fs/xfs/xfs_bmap.c
57003@@ -192,7 +192,7 @@ xfs_bmap_validate_ret(
57004 int nmap,
57005 int ret_nmap);
57006 #else
57007-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
57008+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
57009 #endif /* DEBUG */
57010
57011 STATIC int
57012diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
57013index 1b9fc3e..e1bdde0 100644
57014--- a/fs/xfs/xfs_dir2_sf.c
57015+++ b/fs/xfs/xfs_dir2_sf.c
57016@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
57017 }
57018
57019 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
57020- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
57021+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
57022+ char name[sfep->namelen];
57023+ memcpy(name, sfep->name, sfep->namelen);
57024+ if (filldir(dirent, name, sfep->namelen,
57025+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
57026+ *offset = off & 0x7fffffff;
57027+ return 0;
57028+ }
57029+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
57030 off & 0x7fffffff, ino, DT_UNKNOWN)) {
57031 *offset = off & 0x7fffffff;
57032 return 0;
57033diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
57034index c1c3ef8..0952438 100644
57035--- a/fs/xfs/xfs_ioctl.c
57036+++ b/fs/xfs/xfs_ioctl.c
57037@@ -127,7 +127,7 @@ xfs_find_handle(
57038 }
57039
57040 error = -EFAULT;
57041- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
57042+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
57043 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
57044 goto out_put;
57045
57046diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
57047index d82efaa..0904a8e 100644
57048--- a/fs/xfs/xfs_iops.c
57049+++ b/fs/xfs/xfs_iops.c
57050@@ -395,7 +395,7 @@ xfs_vn_put_link(
57051 struct nameidata *nd,
57052 void *p)
57053 {
57054- char *s = nd_get_link(nd);
57055+ const char *s = nd_get_link(nd);
57056
57057 if (!IS_ERR(s))
57058 kfree(s);
57059diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
57060new file mode 100644
57061index 0000000..92247e4
57062--- /dev/null
57063+++ b/grsecurity/Kconfig
57064@@ -0,0 +1,1021 @@
57065+#
57066+# grecurity configuration
57067+#
57068+menu "Memory Protections"
57069+depends on GRKERNSEC
57070+
57071+config GRKERNSEC_KMEM
57072+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
57073+ default y if GRKERNSEC_CONFIG_AUTO
57074+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
57075+ help
57076+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
57077+ be written to or read from to modify or leak the contents of the running
57078+ kernel. /dev/port will also not be allowed to be opened and support
57079+ for /dev/cpu/*/msr will be removed. If you have module
57080+ support disabled, enabling this will close up five ways that are
57081+ currently used to insert malicious code into the running kernel.
57082+
57083+ Even with all these features enabled, we still highly recommend that
57084+ you use the RBAC system, as it is still possible for an attacker to
57085+ modify the running kernel through privileged I/O granted by ioperm/iopl.
57086+
57087+ If you are not using XFree86, you may be able to stop this additional
57088+ case by enabling the 'Disable privileged I/O' option. Though nothing
57089+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
57090+ but only to video memory, which is the only writing we allow in this
57091+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
57092+ not be allowed to mprotect it with PROT_WRITE later.
57093+ Enabling this feature will prevent the "cpupower" and "powertop" tools
57094+ from working.
57095+
57096+ It is highly recommended that you say Y here if you meet all the
57097+ conditions above.
57098+
57099+config GRKERNSEC_VM86
57100+ bool "Restrict VM86 mode"
57101+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
57102+ depends on X86_32
57103+
57104+ help
57105+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
57106+ make use of a special execution mode on 32bit x86 processors called
57107+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
57108+ video cards and will still work with this option enabled. The purpose
57109+ of the option is to prevent exploitation of emulation errors in
57110+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
57111+ Nearly all users should be able to enable this option.
57112+
57113+config GRKERNSEC_IO
57114+ bool "Disable privileged I/O"
57115+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
57116+ depends on X86
57117+ select RTC_CLASS
57118+ select RTC_INTF_DEV
57119+ select RTC_DRV_CMOS
57120+
57121+ help
57122+ If you say Y here, all ioperm and iopl calls will return an error.
57123+ Ioperm and iopl can be used to modify the running kernel.
57124+ Unfortunately, some programs need this access to operate properly,
57125+ the most notable of which are XFree86 and hwclock. hwclock can be
57126+ remedied by having RTC support in the kernel, so real-time
57127+ clock support is enabled if this option is enabled, to ensure
57128+ that hwclock operates correctly. XFree86 still will not
57129+ operate correctly with this option enabled, so DO NOT CHOOSE Y
57130+ IF YOU USE XFree86. If you use XFree86 and you still want to
57131+ protect your kernel against modification, use the RBAC system.
57132+
57133+config GRKERNSEC_JIT_HARDEN
57134+ bool "Harden BPF JIT against spray attacks"
57135+ default y if GRKERNSEC_CONFIG_AUTO
57136+ depends on BPF_JIT
57137+ help
57138+ If you say Y here, the native code generated by the kernel's Berkeley
57139+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
57140+ attacks that attempt to fit attacker-beneficial instructions in
57141+ 32bit immediate fields of JIT-generated native instructions. The
57142+ attacker will generally aim to cause an unintended instruction sequence
57143+ of JIT-generated native code to execute by jumping into the middle of
57144+ a generated instruction. This feature effectively randomizes the 32bit
57145+ immediate constants present in the generated code to thwart such attacks.
57146+
57147+ If you're using KERNEXEC, it's recommended that you enable this option
57148+ to supplement the hardening of the kernel.
57149+
57150+config GRKERNSEC_RAND_THREADSTACK
57151+ bool "Insert random gaps between thread stacks"
57152+ default y if GRKERNSEC_CONFIG_AUTO
57153+ depends on PAX_RANDMMAP && !PPC
57154+ help
57155+ If you say Y here, a random-sized gap will be enforced between allocated
57156+ thread stacks. Glibc's NPTL and other threading libraries that
57157+ pass MAP_STACK to the kernel for thread stack allocation are supported.
57158+ The implementation currently provides 8 bits of entropy for the gap.
57159+
57160+ Many distributions do not compile threaded remote services with the
57161+ -fstack-check argument to GCC, causing the variable-sized stack-based
57162+ allocator, alloca(), to not probe the stack on allocation. This
57163+ permits an unbounded alloca() to skip over any guard page and potentially
57164+ modify another thread's stack reliably. An enforced random gap
57165+ reduces the reliability of such an attack and increases the chance
57166+ that such a read/write to another thread's stack instead lands in
57167+ an unmapped area, causing a crash and triggering grsecurity's
57168+ anti-bruteforcing logic.
57169+
57170+config GRKERNSEC_PROC_MEMMAP
57171+ bool "Harden ASLR against information leaks and entropy reduction"
57172+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
57173+ depends on PAX_NOEXEC || PAX_ASLR
57174+ help
57175+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
57176+ give no information about the addresses of its mappings if
57177+ PaX features that rely on random addresses are enabled on the task.
57178+ In addition to sanitizing this information and disabling other
57179+ dangerous sources of information, this option causes reads of sensitive
57180+ /proc/<pid> entries where the file descriptor was opened in a different
57181+ task than the one performing the read. Such attempts are logged.
57182+ This option also limits argv/env strings for suid/sgid binaries
57183+ to 512KB to prevent a complete exhaustion of the stack entropy provided
57184+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
57185+ binaries to prevent alternative mmap layouts from being abused.
57186+
57187+ If you use PaX it is essential that you say Y here as it closes up
57188+ several holes that make full ASLR useless locally.
57189+
57190+config GRKERNSEC_BRUTE
57191+ bool "Deter exploit bruteforcing"
57192+ default y if GRKERNSEC_CONFIG_AUTO
57193+ help
57194+ If you say Y here, attempts to bruteforce exploits against forking
57195+ daemons such as apache or sshd, as well as against suid/sgid binaries
57196+ will be deterred. When a child of a forking daemon is killed by PaX
57197+ or crashes due to an illegal instruction or other suspicious signal,
57198+ the parent process will be delayed 30 seconds upon every subsequent
57199+ fork until the administrator is able to assess the situation and
57200+ restart the daemon.
57201+ In the suid/sgid case, the attempt is logged, the user has all their
57202+ processes terminated, and they are prevented from executing any further
57203+ processes for 15 minutes.
57204+ It is recommended that you also enable signal logging in the auditing
57205+ section so that logs are generated when a process triggers a suspicious
57206+ signal.
57207+ If the sysctl option is enabled, a sysctl option with name
57208+ "deter_bruteforce" is created.
57209+
57210+
57211+config GRKERNSEC_MODHARDEN
57212+ bool "Harden module auto-loading"
57213+ default y if GRKERNSEC_CONFIG_AUTO
57214+ depends on MODULES
57215+ help
57216+ If you say Y here, module auto-loading in response to use of some
57217+ feature implemented by an unloaded module will be restricted to
57218+ root users. Enabling this option helps defend against attacks
57219+ by unprivileged users who abuse the auto-loading behavior to
57220+ cause a vulnerable module to load that is then exploited.
57221+
57222+ If this option prevents a legitimate use of auto-loading for a
57223+ non-root user, the administrator can execute modprobe manually
57224+ with the exact name of the module mentioned in the alert log.
57225+ Alternatively, the administrator can add the module to the list
57226+ of modules loaded at boot by modifying init scripts.
57227+
57228+ Modification of init scripts will most likely be needed on
57229+ Ubuntu servers with encrypted home directory support enabled,
57230+ as the first non-root user logging in will cause the ecb(aes),
57231+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
57232+
57233+config GRKERNSEC_HIDESYM
57234+ bool "Hide kernel symbols"
57235+ default y if GRKERNSEC_CONFIG_AUTO
57236+ select PAX_USERCOPY_SLABS
57237+ help
57238+ If you say Y here, getting information on loaded modules, and
57239+ displaying all kernel symbols through a syscall will be restricted
57240+ to users with CAP_SYS_MODULE. For software compatibility reasons,
57241+ /proc/kallsyms will be restricted to the root user. The RBAC
57242+ system can hide that entry even from root.
57243+
57244+ This option also prevents leaking of kernel addresses through
57245+ several /proc entries.
57246+
57247+ Note that this option is only effective provided the following
57248+ conditions are met:
57249+ 1) The kernel using grsecurity is not precompiled by some distribution
57250+ 2) You have also enabled GRKERNSEC_DMESG
57251+ 3) You are using the RBAC system and hiding other files such as your
57252+ kernel image and System.map. Alternatively, enabling this option
57253+ causes the permissions on /boot, /lib/modules, and the kernel
57254+ source directory to change at compile time to prevent
57255+ reading by non-root users.
57256+ If the above conditions are met, this option will aid in providing a
57257+ useful protection against local kernel exploitation of overflows
57258+ and arbitrary read/write vulnerabilities.
57259+
57260+config GRKERNSEC_KERN_LOCKOUT
57261+ bool "Active kernel exploit response"
57262+ default y if GRKERNSEC_CONFIG_AUTO
57263+ depends on X86 || ARM || PPC || SPARC
57264+ help
57265+ If you say Y here, when a PaX alert is triggered due to suspicious
57266+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
57267+ or an OOPS occurs due to bad memory accesses, instead of just
57268+ terminating the offending process (and potentially allowing
57269+ a subsequent exploit from the same user), we will take one of two
57270+ actions:
57271+ If the user was root, we will panic the system
57272+ If the user was non-root, we will log the attempt, terminate
57273+ all processes owned by the user, then prevent them from creating
57274+ any new processes until the system is restarted
57275+ This deters repeated kernel exploitation/bruteforcing attempts
57276+ and is useful for later forensics.
57277+
57278+endmenu
57279+menu "Role Based Access Control Options"
57280+depends on GRKERNSEC
57281+
57282+config GRKERNSEC_RBAC_DEBUG
57283+ bool
57284+
57285+config GRKERNSEC_NO_RBAC
57286+ bool "Disable RBAC system"
57287+ help
57288+ If you say Y here, the /dev/grsec device will be removed from the kernel,
57289+ preventing the RBAC system from being enabled. You should only say Y
57290+ here if you have no intention of using the RBAC system, so as to prevent
57291+ an attacker with root access from misusing the RBAC system to hide files
57292+ and processes when loadable module support and /dev/[k]mem have been
57293+ locked down.
57294+
57295+config GRKERNSEC_ACL_HIDEKERN
57296+ bool "Hide kernel processes"
57297+ help
57298+ If you say Y here, all kernel threads will be hidden to all
57299+ processes but those whose subject has the "view hidden processes"
57300+ flag.
57301+
57302+config GRKERNSEC_ACL_MAXTRIES
57303+ int "Maximum tries before password lockout"
57304+ default 3
57305+ help
57306+ This option enforces the maximum number of times a user can attempt
57307+ to authorize themselves with the grsecurity RBAC system before being
57308+ denied the ability to attempt authorization again for a specified time.
57309+ The lower the number, the harder it will be to brute-force a password.
57310+
57311+config GRKERNSEC_ACL_TIMEOUT
57312+ int "Time to wait after max password tries, in seconds"
57313+ default 30
57314+ help
57315+ This option specifies the time the user must wait after attempting to
57316+ authorize to the RBAC system with the maximum number of invalid
57317+ passwords. The higher the number, the harder it will be to brute-force
57318+ a password.
57319+
57320+endmenu
57321+menu "Filesystem Protections"
57322+depends on GRKERNSEC
57323+
57324+config GRKERNSEC_PROC
57325+ bool "Proc restrictions"
57326+ default y if GRKERNSEC_CONFIG_AUTO
57327+ help
57328+ If you say Y here, the permissions of the /proc filesystem
57329+ will be altered to enhance system security and privacy. You MUST
57330+ choose either a user only restriction or a user and group restriction.
57331+ Depending upon the option you choose, you can either restrict users to
57332+ see only the processes they themselves run, or choose a group that can
57333+ view all processes and files normally restricted to root if you choose
57334+ the "restrict to user only" option. NOTE: If you're running identd or
57335+ ntpd as a non-root user, you will have to run it as the group you
57336+ specify here.
57337+
57338+config GRKERNSEC_PROC_USER
57339+ bool "Restrict /proc to user only"
57340+ depends on GRKERNSEC_PROC
57341+ help
57342+ If you say Y here, non-root users will only be able to view their own
57343+ processes, and restricts them from viewing network-related information,
57344+ and viewing kernel symbol and module information.
57345+
57346+config GRKERNSEC_PROC_USERGROUP
57347+ bool "Allow special group"
57348+ default y if GRKERNSEC_CONFIG_AUTO
57349+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
57350+ help
57351+ If you say Y here, you will be able to select a group that will be
57352+ able to view all processes and network-related information. If you've
57353+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
57354+ remain hidden. This option is useful if you want to run identd as
57355+ a non-root user. The group you select may also be chosen at boot time
57356+ via "grsec_proc_gid=" on the kernel commandline.
57357+
57358+config GRKERNSEC_PROC_GID
57359+ int "GID for special group"
57360+ depends on GRKERNSEC_PROC_USERGROUP
57361+ default 1001
57362+
57363+config GRKERNSEC_PROC_ADD
57364+ bool "Additional restrictions"
57365+ default y if GRKERNSEC_CONFIG_AUTO
57366+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
57367+ help
57368+ If you say Y here, additional restrictions will be placed on
57369+ /proc that keep normal users from viewing device information and
57370+ slabinfo information that could be useful for exploits.
57371+
57372+config GRKERNSEC_LINK
57373+ bool "Linking restrictions"
57374+ default y if GRKERNSEC_CONFIG_AUTO
57375+ help
57376+ If you say Y here, /tmp race exploits will be prevented, since users
57377+ will no longer be able to follow symlinks owned by other users in
57378+ world-writable +t directories (e.g. /tmp), unless the owner of the
57379+ symlink is the owner of the directory. users will also not be
57380+ able to hardlink to files they do not own. If the sysctl option is
57381+ enabled, a sysctl option with name "linking_restrictions" is created.
57382+
57383+config GRKERNSEC_SYMLINKOWN
57384+ bool "Kernel-enforced SymlinksIfOwnerMatch"
57385+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
57386+ help
57387+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
57388+ that prevents it from being used as a security feature. As Apache
57389+ verifies the symlink by performing a stat() against the target of
57390+ the symlink before it is followed, an attacker can setup a symlink
57391+ to point to a same-owned file, then replace the symlink with one
57392+ that targets another user's file just after Apache "validates" the
57393+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
57394+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
57395+ will be in place for the group you specify. If the sysctl option
57396+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
57397+ created.
57398+
57399+config GRKERNSEC_SYMLINKOWN_GID
57400+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
57401+ depends on GRKERNSEC_SYMLINKOWN
57402+ default 1006
57403+ help
57404+ Setting this GID determines what group kernel-enforced
57405+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
57406+ is enabled, a sysctl option with name "symlinkown_gid" is created.
57407+
57408+config GRKERNSEC_FIFO
57409+ bool "FIFO restrictions"
57410+ default y if GRKERNSEC_CONFIG_AUTO
57411+ help
57412+ If you say Y here, users will not be able to write to FIFOs they don't
57413+ own in world-writable +t directories (e.g. /tmp), unless the owner of
57414+ the FIFO is the same owner of the directory it's held in. If the sysctl
57415+ option is enabled, a sysctl option with name "fifo_restrictions" is
57416+ created.
57417+
57418+config GRKERNSEC_SYSFS_RESTRICT
57419+ bool "Sysfs/debugfs restriction"
57420+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
57421+ depends on SYSFS
57422+ help
57423+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
57424+ any filesystem normally mounted under it (e.g. debugfs) will be
57425+ mostly accessible only by root. These filesystems generally provide access
57426+ to hardware and debug information that isn't appropriate for unprivileged
57427+ users of the system. Sysfs and debugfs have also become a large source
57428+ of new vulnerabilities, ranging from infoleaks to local compromise.
57429+ There has been very little oversight with an eye toward security involved
57430+ in adding new exporters of information to these filesystems, so their
57431+ use is discouraged.
57432+ For reasons of compatibility, a few directories have been whitelisted
57433+ for access by non-root users:
57434+ /sys/fs/selinux
57435+ /sys/fs/fuse
57436+ /sys/devices/system/cpu
57437+
57438+config GRKERNSEC_ROFS
57439+ bool "Runtime read-only mount protection"
57440+ help
57441+ If you say Y here, a sysctl option with name "romount_protect" will
57442+ be created. By setting this option to 1 at runtime, filesystems
57443+ will be protected in the following ways:
57444+ * No new writable mounts will be allowed
57445+ * Existing read-only mounts won't be able to be remounted read/write
57446+ * Write operations will be denied on all block devices
57447+ This option acts independently of grsec_lock: once it is set to 1,
57448+ it cannot be turned off. Therefore, please be mindful of the resulting
57449+ behavior if this option is enabled in an init script on a read-only
57450+ filesystem. This feature is mainly intended for secure embedded systems.
57451+
57452+config GRKERNSEC_DEVICE_SIDECHANNEL
57453+ bool "Eliminate stat/notify-based device sidechannels"
57454+ default y if GRKERNSEC_CONFIG_AUTO
57455+ help
57456+ If you say Y here, timing analyses on block or character
57457+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
57458+ will be thwarted for unprivileged users. If a process without
57459+ CAP_MKNOD stats such a device, the last access and last modify times
57460+ will match the device's create time. No access or modify events
57461+ will be triggered through inotify/dnotify/fanotify for such devices.
57462+ This feature will prevent attacks that may at a minimum
57463+ allow an attacker to determine the administrator's password length.
57464+
57465+config GRKERNSEC_CHROOT
57466+ bool "Chroot jail restrictions"
57467+ default y if GRKERNSEC_CONFIG_AUTO
57468+ help
57469+ If you say Y here, you will be able to choose several options that will
57470+ make breaking out of a chrooted jail much more difficult. If you
57471+ encounter no software incompatibilities with the following options, it
57472+ is recommended that you enable each one.
57473+
57474+config GRKERNSEC_CHROOT_MOUNT
57475+ bool "Deny mounts"
57476+ default y if GRKERNSEC_CONFIG_AUTO
57477+ depends on GRKERNSEC_CHROOT
57478+ help
57479+ If you say Y here, processes inside a chroot will not be able to
57480+ mount or remount filesystems. If the sysctl option is enabled, a
57481+ sysctl option with name "chroot_deny_mount" is created.
57482+
57483+config GRKERNSEC_CHROOT_DOUBLE
57484+ bool "Deny double-chroots"
57485+ default y if GRKERNSEC_CONFIG_AUTO
57486+ depends on GRKERNSEC_CHROOT
57487+ help
57488+ If you say Y here, processes inside a chroot will not be able to chroot
57489+ again outside the chroot. This is a widely used method of breaking
57490+ out of a chroot jail and should not be allowed. If the sysctl
57491+ option is enabled, a sysctl option with name
57492+ "chroot_deny_chroot" is created.
57493+
57494+config GRKERNSEC_CHROOT_PIVOT
57495+ bool "Deny pivot_root in chroot"
57496+ default y if GRKERNSEC_CONFIG_AUTO
57497+ depends on GRKERNSEC_CHROOT
57498+ help
57499+ If you say Y here, processes inside a chroot will not be able to use
57500+ a function called pivot_root() that was introduced in Linux 2.3.41. It
57501+ works similar to chroot in that it changes the root filesystem. This
57502+ function could be misused in a chrooted process to attempt to break out
57503+ of the chroot, and therefore should not be allowed. If the sysctl
57504+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
57505+ created.
57506+
57507+config GRKERNSEC_CHROOT_CHDIR
57508+ bool "Enforce chdir(\"/\") on all chroots"
57509+ default y if GRKERNSEC_CONFIG_AUTO
57510+ depends on GRKERNSEC_CHROOT
57511+ help
57512+ If you say Y here, the current working directory of all newly-chrooted
57513+ applications will be set to the the root directory of the chroot.
57514+ The man page on chroot(2) states:
57515+ Note that this call does not change the current working
57516+ directory, so that `.' can be outside the tree rooted at
57517+ `/'. In particular, the super-user can escape from a
57518+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
57519+
57520+ It is recommended that you say Y here, since it's not known to break
57521+ any software. If the sysctl option is enabled, a sysctl option with
57522+ name "chroot_enforce_chdir" is created.
57523+
57524+config GRKERNSEC_CHROOT_CHMOD
57525+ bool "Deny (f)chmod +s"
57526+ default y if GRKERNSEC_CONFIG_AUTO
57527+ depends on GRKERNSEC_CHROOT
57528+ help
57529+ If you say Y here, processes inside a chroot will not be able to chmod
57530+ or fchmod files to make them have suid or sgid bits. This protects
57531+ against another published method of breaking a chroot. If the sysctl
57532+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
57533+ created.
57534+
57535+config GRKERNSEC_CHROOT_FCHDIR
57536+ bool "Deny fchdir out of chroot"
57537+ default y if GRKERNSEC_CONFIG_AUTO
57538+ depends on GRKERNSEC_CHROOT
57539+ help
57540+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
57541+ to a file descriptor of the chrooting process that points to a directory
57542+ outside the filesystem will be stopped. If the sysctl option
57543+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
57544+
57545+config GRKERNSEC_CHROOT_MKNOD
57546+ bool "Deny mknod"
57547+ default y if GRKERNSEC_CONFIG_AUTO
57548+ depends on GRKERNSEC_CHROOT
57549+ help
57550+ If you say Y here, processes inside a chroot will not be allowed to
57551+ mknod. The problem with using mknod inside a chroot is that it
57552+ would allow an attacker to create a device entry that is the same
57553+ as one on the physical root of your system, which could range from
57554+ anything from the console device to a device for your harddrive (which
57555+ they could then use to wipe the drive or steal data). It is recommended
57556+ that you say Y here, unless you run into software incompatibilities.
57557+ If the sysctl option is enabled, a sysctl option with name
57558+ "chroot_deny_mknod" is created.
57559+
57560+config GRKERNSEC_CHROOT_SHMAT
57561+ bool "Deny shmat() out of chroot"
57562+ default y if GRKERNSEC_CONFIG_AUTO
57563+ depends on GRKERNSEC_CHROOT
57564+ help
57565+ If you say Y here, processes inside a chroot will not be able to attach
57566+ to shared memory segments that were created outside of the chroot jail.
57567+ It is recommended that you say Y here. If the sysctl option is enabled,
57568+ a sysctl option with name "chroot_deny_shmat" is created.
57569+
57570+config GRKERNSEC_CHROOT_UNIX
57571+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
57572+ default y if GRKERNSEC_CONFIG_AUTO
57573+ depends on GRKERNSEC_CHROOT
57574+ help
57575+ If you say Y here, processes inside a chroot will not be able to
57576+ connect to abstract (meaning not belonging to a filesystem) Unix
57577+ domain sockets that were bound outside of a chroot. It is recommended
57578+ that you say Y here. If the sysctl option is enabled, a sysctl option
57579+ with name "chroot_deny_unix" is created.
57580+
57581+config GRKERNSEC_CHROOT_FINDTASK
57582+ bool "Protect outside processes"
57583+ default y if GRKERNSEC_CONFIG_AUTO
57584+ depends on GRKERNSEC_CHROOT
57585+ help
57586+ If you say Y here, processes inside a chroot will not be able to
57587+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
57588+ getsid, or view any process outside of the chroot. If the sysctl
57589+ option is enabled, a sysctl option with name "chroot_findtask" is
57590+ created.
57591+
57592+config GRKERNSEC_CHROOT_NICE
57593+ bool "Restrict priority changes"
57594+ default y if GRKERNSEC_CONFIG_AUTO
57595+ depends on GRKERNSEC_CHROOT
57596+ help
57597+ If you say Y here, processes inside a chroot will not be able to raise
57598+ the priority of processes in the chroot, or alter the priority of
57599+ processes outside the chroot. This provides more security than simply
57600+ removing CAP_SYS_NICE from the process' capability set. If the
57601+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
57602+ is created.
57603+
57604+config GRKERNSEC_CHROOT_SYSCTL
57605+ bool "Deny sysctl writes"
57606+ default y if GRKERNSEC_CONFIG_AUTO
57607+ depends on GRKERNSEC_CHROOT
57608+ help
57609+ If you say Y here, an attacker in a chroot will not be able to
57610+ write to sysctl entries, either by sysctl(2) or through a /proc
57611+ interface. It is strongly recommended that you say Y here. If the
57612+ sysctl option is enabled, a sysctl option with name
57613+ "chroot_deny_sysctl" is created.
57614+
57615+config GRKERNSEC_CHROOT_CAPS
57616+ bool "Capability restrictions"
57617+ default y if GRKERNSEC_CONFIG_AUTO
57618+ depends on GRKERNSEC_CHROOT
57619+ help
57620+ If you say Y here, the capabilities on all processes within a
57621+ chroot jail will be lowered to stop module insertion, raw i/o,
57622+ system and net admin tasks, rebooting the system, modifying immutable
57623+ files, modifying IPC owned by another, and changing the system time.
57624+ This is left an option because it can break some apps. Disable this
57625+ if your chrooted apps are having problems performing those kinds of
57626+ tasks. If the sysctl option is enabled, a sysctl option with
57627+ name "chroot_caps" is created.
57628+
57629+endmenu
57630+menu "Kernel Auditing"
57631+depends on GRKERNSEC
57632+
57633+config GRKERNSEC_AUDIT_GROUP
57634+ bool "Single group for auditing"
57635+ help
57636+ If you say Y here, the exec and chdir logging features will only operate
57637+ on a group you specify. This option is recommended if you only want to
57638+ watch certain users instead of having a large amount of logs from the
57639+ entire system. If the sysctl option is enabled, a sysctl option with
57640+ name "audit_group" is created.
57641+
57642+config GRKERNSEC_AUDIT_GID
57643+ int "GID for auditing"
57644+ depends on GRKERNSEC_AUDIT_GROUP
57645+ default 1007
57646+
57647+config GRKERNSEC_EXECLOG
57648+ bool "Exec logging"
57649+ help
57650+ If you say Y here, all execve() calls will be logged (since the
57651+ other exec*() calls are frontends to execve(), all execution
57652+ will be logged). Useful for shell-servers that like to keep track
57653+ of their users. If the sysctl option is enabled, a sysctl option with
57654+ name "exec_logging" is created.
57655+ WARNING: This option when enabled will produce a LOT of logs, especially
57656+ on an active system.
57657+
57658+config GRKERNSEC_RESLOG
57659+ bool "Resource logging"
57660+ default y if GRKERNSEC_CONFIG_AUTO
57661+ help
57662+ If you say Y here, all attempts to overstep resource limits will
57663+ be logged with the resource name, the requested size, and the current
57664+ limit. It is highly recommended that you say Y here. If the sysctl
57665+ option is enabled, a sysctl option with name "resource_logging" is
57666+ created. If the RBAC system is enabled, the sysctl value is ignored.
57667+
57668+config GRKERNSEC_CHROOT_EXECLOG
57669+ bool "Log execs within chroot"
57670+ help
57671+ If you say Y here, all executions inside a chroot jail will be logged
57672+ to syslog. This can cause a large amount of logs if certain
57673+ applications (eg. djb's daemontools) are installed on the system, and
57674+ is therefore left as an option. If the sysctl option is enabled, a
57675+ sysctl option with name "chroot_execlog" is created.
57676+
57677+config GRKERNSEC_AUDIT_PTRACE
57678+ bool "Ptrace logging"
57679+ help
57680+ If you say Y here, all attempts to attach to a process via ptrace
57681+ will be logged. If the sysctl option is enabled, a sysctl option
57682+ with name "audit_ptrace" is created.
57683+
57684+config GRKERNSEC_AUDIT_CHDIR
57685+ bool "Chdir logging"
57686+ help
57687+ If you say Y here, all chdir() calls will be logged. If the sysctl
57688+ option is enabled, a sysctl option with name "audit_chdir" is created.
57689+
57690+config GRKERNSEC_AUDIT_MOUNT
57691+ bool "(Un)Mount logging"
57692+ help
57693+ If you say Y here, all mounts and unmounts will be logged. If the
57694+ sysctl option is enabled, a sysctl option with name "audit_mount" is
57695+ created.
57696+
57697+config GRKERNSEC_SIGNAL
57698+ bool "Signal logging"
57699+ default y if GRKERNSEC_CONFIG_AUTO
57700+ help
57701+ If you say Y here, certain important signals will be logged, such as
57702+ SIGSEGV, which will as a result inform you of when a error in a program
57703+ occurred, which in some cases could mean a possible exploit attempt.
57704+ If the sysctl option is enabled, a sysctl option with name
57705+ "signal_logging" is created.
57706+
57707+config GRKERNSEC_FORKFAIL
57708+ bool "Fork failure logging"
57709+ help
57710+ If you say Y here, all failed fork() attempts will be logged.
57711+ This could suggest a fork bomb, or someone attempting to overstep
57712+ their process limit. If the sysctl option is enabled, a sysctl option
57713+ with name "forkfail_logging" is created.
57714+
57715+config GRKERNSEC_TIME
57716+ bool "Time change logging"
57717+ default y if GRKERNSEC_CONFIG_AUTO
57718+ help
57719+ If you say Y here, any changes of the system clock will be logged.
57720+ If the sysctl option is enabled, a sysctl option with name
57721+ "timechange_logging" is created.
57722+
57723+config GRKERNSEC_PROC_IPADDR
57724+ bool "/proc/<pid>/ipaddr support"
57725+ default y if GRKERNSEC_CONFIG_AUTO
57726+ help
57727+ If you say Y here, a new entry will be added to each /proc/<pid>
57728+ directory that contains the IP address of the person using the task.
57729+ The IP is carried across local TCP and AF_UNIX stream sockets.
57730+ This information can be useful for IDS/IPSes to perform remote response
57731+ to a local attack. The entry is readable by only the owner of the
57732+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
57733+ the RBAC system), and thus does not create privacy concerns.
57734+
57735+config GRKERNSEC_RWXMAP_LOG
57736+ bool 'Denied RWX mmap/mprotect logging'
57737+ default y if GRKERNSEC_CONFIG_AUTO
57738+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
57739+ help
57740+ If you say Y here, calls to mmap() and mprotect() with explicit
57741+ usage of PROT_WRITE and PROT_EXEC together will be logged when
57742+ denied by the PAX_MPROTECT feature. If the sysctl option is
57743+ enabled, a sysctl option with name "rwxmap_logging" is created.
57744+
57745+config GRKERNSEC_AUDIT_TEXTREL
57746+ bool 'ELF text relocations logging (READ HELP)'
57747+ depends on PAX_MPROTECT
57748+ help
57749+ If you say Y here, text relocations will be logged with the filename
57750+ of the offending library or binary. The purpose of the feature is
57751+ to help Linux distribution developers get rid of libraries and
57752+ binaries that need text relocations which hinder the future progress
57753+ of PaX. Only Linux distribution developers should say Y here, and
57754+ never on a production machine, as this option creates an information
57755+ leak that could aid an attacker in defeating the randomization of
57756+ a single memory region. If the sysctl option is enabled, a sysctl
57757+ option with name "audit_textrel" is created.
57758+
57759+endmenu
57760+
57761+menu "Executable Protections"
57762+depends on GRKERNSEC
57763+
57764+config GRKERNSEC_DMESG
57765+ bool "Dmesg(8) restriction"
57766+ default y if GRKERNSEC_CONFIG_AUTO
57767+ help
57768+ If you say Y here, non-root users will not be able to use dmesg(8)
57769+ to view the contents of the kernel's circular log buffer.
57770+ The kernel's log buffer often contains kernel addresses and other
57771+ identifying information useful to an attacker in fingerprinting a
57772+ system for a targeted exploit.
57773+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
57774+ created.
57775+
57776+config GRKERNSEC_HARDEN_PTRACE
57777+ bool "Deter ptrace-based process snooping"
57778+ default y if GRKERNSEC_CONFIG_AUTO
57779+ help
57780+ If you say Y here, TTY sniffers and other malicious monitoring
57781+ programs implemented through ptrace will be defeated. If you
57782+ have been using the RBAC system, this option has already been
57783+ enabled for several years for all users, with the ability to make
57784+ fine-grained exceptions.
57785+
57786+ This option only affects the ability of non-root users to ptrace
57787+ processes that are not a descendent of the ptracing process.
57788+ This means that strace ./binary and gdb ./binary will still work,
57789+ but attaching to arbitrary processes will not. If the sysctl
57790+ option is enabled, a sysctl option with name "harden_ptrace" is
57791+ created.
57792+
57793+config GRKERNSEC_PTRACE_READEXEC
57794+ bool "Require read access to ptrace sensitive binaries"
57795+ default y if GRKERNSEC_CONFIG_AUTO
57796+ help
57797+ If you say Y here, unprivileged users will not be able to ptrace unreadable
57798+ binaries. This option is useful in environments that
57799+ remove the read bits (e.g. file mode 4711) from suid binaries to
57800+ prevent infoleaking of their contents. This option adds
57801+ consistency to the use of that file mode, as the binary could normally
57802+ be read out when run without privileges while ptracing.
57803+
57804+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
57805+ is created.
57806+
57807+config GRKERNSEC_SETXID
57808+ bool "Enforce consistent multithreaded privileges"
57809+ default y if GRKERNSEC_CONFIG_AUTO
57810+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
57811+ help
57812+ If you say Y here, a change from a root uid to a non-root uid
57813+ in a multithreaded application will cause the resulting uids,
57814+ gids, supplementary groups, and capabilities in that thread
57815+ to be propagated to the other threads of the process. In most
57816+ cases this is unnecessary, as glibc will emulate this behavior
57817+ on behalf of the application. Other libcs do not act in the
57818+ same way, allowing the other threads of the process to continue
57819+ running with root privileges. If the sysctl option is enabled,
57820+ a sysctl option with name "consistent_setxid" is created.
57821+
57822+config GRKERNSEC_TPE
57823+ bool "Trusted Path Execution (TPE)"
57824+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
57825+ help
57826+ If you say Y here, you will be able to choose a gid to add to the
57827+ supplementary groups of users you want to mark as "untrusted."
57828+ These users will not be able to execute any files that are not in
57829+ root-owned directories writable only by root. If the sysctl option
57830+ is enabled, a sysctl option with name "tpe" is created.
57831+
57832+config GRKERNSEC_TPE_ALL
57833+ bool "Partially restrict all non-root users"
57834+ depends on GRKERNSEC_TPE
57835+ help
57836+ If you say Y here, all non-root users will be covered under
57837+ a weaker TPE restriction. This is separate from, and in addition to,
57838+ the main TPE options that you have selected elsewhere. Thus, if a
57839+ "trusted" GID is chosen, this restriction applies to even that GID.
57840+ Under this restriction, all non-root users will only be allowed to
57841+ execute files in directories they own that are not group or
57842+ world-writable, or in directories owned by root and writable only by
57843+ root. If the sysctl option is enabled, a sysctl option with name
57844+ "tpe_restrict_all" is created.
57845+
57846+config GRKERNSEC_TPE_INVERT
57847+ bool "Invert GID option"
57848+ depends on GRKERNSEC_TPE
57849+ help
57850+ If you say Y here, the group you specify in the TPE configuration will
57851+ decide what group TPE restrictions will be *disabled* for. This
57852+ option is useful if you want TPE restrictions to be applied to most
57853+ users on the system. If the sysctl option is enabled, a sysctl option
57854+ with name "tpe_invert" is created. Unlike other sysctl options, this
57855+ entry will default to on for backward-compatibility.
57856+
57857+config GRKERNSEC_TPE_GID
57858+ int
57859+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
57860+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
57861+
57862+config GRKERNSEC_TPE_UNTRUSTED_GID
57863+ int "GID for TPE-untrusted users"
57864+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
57865+ default 1005
57866+ help
57867+ Setting this GID determines what group TPE restrictions will be
57868+ *enabled* for. If the sysctl option is enabled, a sysctl option
57869+ with name "tpe_gid" is created.
57870+
57871+config GRKERNSEC_TPE_TRUSTED_GID
57872+ int "GID for TPE-trusted users"
57873+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
57874+ default 1005
57875+ help
57876+ Setting this GID determines what group TPE restrictions will be
57877+ *disabled* for. If the sysctl option is enabled, a sysctl option
57878+ with name "tpe_gid" is created.
57879+
57880+endmenu
57881+menu "Network Protections"
57882+depends on GRKERNSEC
57883+
57884+config GRKERNSEC_RANDNET
57885+ bool "Larger entropy pools"
57886+ default y if GRKERNSEC_CONFIG_AUTO
57887+ help
57888+ If you say Y here, the entropy pools used for many features of Linux
57889+ and grsecurity will be doubled in size. Since several grsecurity
57890+ features use additional randomness, it is recommended that you say Y
57891+ here. Saying Y here has a similar effect as modifying
57892+ /proc/sys/kernel/random/poolsize.
57893+
57894+config GRKERNSEC_BLACKHOLE
57895+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
57896+ default y if GRKERNSEC_CONFIG_AUTO
57897+ depends on NET
57898+ help
57899+ If you say Y here, neither TCP resets nor ICMP
57900+ destination-unreachable packets will be sent in response to packets
57901+ sent to ports for which no associated listening process exists.
57902+ This feature supports both IPV4 and IPV6 and exempts the
57903+ loopback interface from blackholing. Enabling this feature
57904+ makes a host more resilient to DoS attacks and reduces network
57905+ visibility against scanners.
57906+
57907+ The blackhole feature as-implemented is equivalent to the FreeBSD
57908+ blackhole feature, as it prevents RST responses to all packets, not
57909+ just SYNs. Under most application behavior this causes no
57910+ problems, but applications (like haproxy) may not close certain
57911+ connections in a way that cleanly terminates them on the remote
57912+ end, leaving the remote host in LAST_ACK state. Because of this
57913+ side-effect and to prevent intentional LAST_ACK DoSes, this
57914+ feature also adds automatic mitigation against such attacks.
57915+ The mitigation drastically reduces the amount of time a socket
57916+ can spend in LAST_ACK state. If you're using haproxy and not
57917+ all servers it connects to have this option enabled, consider
57918+ disabling this feature on the haproxy host.
57919+
57920+ If the sysctl option is enabled, two sysctl options with names
57921+ "ip_blackhole" and "lastack_retries" will be created.
57922+ While "ip_blackhole" takes the standard zero/non-zero on/off
57923+ toggle, "lastack_retries" uses the same kinds of values as
57924+ "tcp_retries1" and "tcp_retries2". The default value of 4
57925+ prevents a socket from lasting more than 45 seconds in LAST_ACK
57926+ state.
57927+
57928+config GRKERNSEC_NO_SIMULT_CONNECT
57929+ bool "Disable TCP Simultaneous Connect"
57930+ default y if GRKERNSEC_CONFIG_AUTO
57931+ depends on NET
57932+ help
57933+ If you say Y here, a feature by Willy Tarreau will be enabled that
57934+ removes a weakness in Linux's strict implementation of TCP that
57935+ allows two clients to connect to each other without either entering
57936+ a listening state. The weakness allows an attacker to easily prevent
57937+ a client from connecting to a known server provided the source port
57938+ for the connection is guessed correctly.
57939+
57940+ As the weakness could be used to prevent an antivirus or IPS from
57941+ fetching updates, or prevent an SSL gateway from fetching a CRL,
57942+ it should be eliminated by enabling this option. Though Linux is
57943+ one of few operating systems supporting simultaneous connect, it
57944+ has no legitimate use in practice and is rarely supported by firewalls.
57945+
57946+config GRKERNSEC_SOCKET
57947+ bool "Socket restrictions"
57948+ depends on NET
57949+ help
57950+ If you say Y here, you will be able to choose from several options.
57951+ If you assign a GID on your system and add it to the supplementary
57952+ groups of users you want to restrict socket access to, this patch
57953+ will perform up to three things, based on the option(s) you choose.
57954+
57955+config GRKERNSEC_SOCKET_ALL
57956+ bool "Deny any sockets to group"
57957+ depends on GRKERNSEC_SOCKET
57958+ help
57959+ If you say Y here, you will be able to choose a GID of whose users will
57960+ be unable to connect to other hosts from your machine or run server
57961+ applications from your machine. If the sysctl option is enabled, a
57962+ sysctl option with name "socket_all" is created.
57963+
57964+config GRKERNSEC_SOCKET_ALL_GID
57965+ int "GID to deny all sockets for"
57966+ depends on GRKERNSEC_SOCKET_ALL
57967+ default 1004
57968+ help
57969+ Here you can choose the GID to disable socket access for. Remember to
57970+ add the users you want socket access disabled for to the GID
57971+ specified here. If the sysctl option is enabled, a sysctl option
57972+ with name "socket_all_gid" is created.
57973+
57974+config GRKERNSEC_SOCKET_CLIENT
57975+ bool "Deny client sockets to group"
57976+ depends on GRKERNSEC_SOCKET
57977+ help
57978+ If you say Y here, you will be able to choose a GID of whose users will
57979+ be unable to connect to other hosts from your machine, but will be
57980+ able to run servers. If this option is enabled, all users in the group
57981+ you specify will have to use passive mode when initiating ftp transfers
57982+ from the shell on your machine. If the sysctl option is enabled, a
57983+ sysctl option with name "socket_client" is created.
57984+
57985+config GRKERNSEC_SOCKET_CLIENT_GID
57986+ int "GID to deny client sockets for"
57987+ depends on GRKERNSEC_SOCKET_CLIENT
57988+ default 1003
57989+ help
57990+ Here you can choose the GID to disable client socket access for.
57991+ Remember to add the users you want client socket access disabled for to
57992+ the GID specified here. If the sysctl option is enabled, a sysctl
57993+ option with name "socket_client_gid" is created.
57994+
57995+config GRKERNSEC_SOCKET_SERVER
57996+ bool "Deny server sockets to group"
57997+ depends on GRKERNSEC_SOCKET
57998+ help
57999+ If you say Y here, you will be able to choose a GID of whose users will
58000+ be unable to run server applications from your machine. If the sysctl
58001+ option is enabled, a sysctl option with name "socket_server" is created.
58002+
58003+config GRKERNSEC_SOCKET_SERVER_GID
58004+ int "GID to deny server sockets for"
58005+ depends on GRKERNSEC_SOCKET_SERVER
58006+ default 1002
58007+ help
58008+ Here you can choose the GID to disable server socket access for.
58009+ Remember to add the users you want server socket access disabled for to
58010+ the GID specified here. If the sysctl option is enabled, a sysctl
58011+ option with name "socket_server_gid" is created.
58012+
58013+endmenu
58014+menu "Sysctl Support"
58015+depends on GRKERNSEC && SYSCTL
58016+
58017+config GRKERNSEC_SYSCTL
58018+ bool "Sysctl support"
58019+ default y if GRKERNSEC_CONFIG_AUTO
58020+ help
58021+ If you say Y here, you will be able to change the options that
58022+ grsecurity runs with at bootup, without having to recompile your
58023+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
58024+ to enable (1) or disable (0) various features. All the sysctl entries
58025+ are mutable until the "grsec_lock" entry is set to a non-zero value.
58026+ All features enabled in the kernel configuration are disabled at boot
58027+ if you do not say Y to the "Turn on features by default" option.
58028+ All options should be set at startup, and the grsec_lock entry should
58029+ be set to a non-zero value after all the options are set.
58030+ *THIS IS EXTREMELY IMPORTANT*
58031+
58032+config GRKERNSEC_SYSCTL_DISTRO
58033+ bool "Extra sysctl support for distro makers (READ HELP)"
58034+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
58035+ help
58036+ If you say Y here, additional sysctl options will be created
58037+ for features that affect processes running as root. Therefore,
58038+ it is critical when using this option that the grsec_lock entry be
58039+ enabled after boot. Only distros with prebuilt kernel packages
58040+ with this option enabled that can ensure grsec_lock is enabled
58041+ after boot should use this option.
58042+ *Failure to set grsec_lock after boot makes all grsec features
58043+ this option covers useless*
58044+
58045+ Currently this option creates the following sysctl entries:
58046+ "Disable Privileged I/O": "disable_priv_io"
58047+
58048+config GRKERNSEC_SYSCTL_ON
58049+ bool "Turn on features by default"
58050+ default y if GRKERNSEC_CONFIG_AUTO
58051+ depends on GRKERNSEC_SYSCTL
58052+ help
58053+ If you say Y here, instead of having all features enabled in the
58054+ kernel configuration disabled at boot time, the features will be
58055+ enabled at boot time. It is recommended you say Y here unless
58056+ there is some reason you would want all sysctl-tunable features to
58057+ be disabled by default. As mentioned elsewhere, it is important
58058+ to enable the grsec_lock entry once you have finished modifying
58059+ the sysctl entries.
58060+
58061+endmenu
58062+menu "Logging Options"
58063+depends on GRKERNSEC
58064+
58065+config GRKERNSEC_FLOODTIME
58066+ int "Seconds in between log messages (minimum)"
58067+ default 10
58068+ help
58069+ This option allows you to enforce the number of seconds between
58070+ grsecurity log messages. The default should be suitable for most
58071+ people, however, if you choose to change it, choose a value small enough
58072+ to allow informative logs to be produced, but large enough to
58073+ prevent flooding.
58074+
58075+config GRKERNSEC_FLOODBURST
58076+ int "Number of messages in a burst (maximum)"
58077+ default 6
58078+ help
58079+ This option allows you to choose the maximum number of messages allowed
58080+ within the flood time interval you chose in a separate option. The
58081+ default should be suitable for most people, however if you find that
58082+ many of your logs are being interpreted as flooding, you may want to
58083+ raise this value.
58084+
58085+endmenu
58086diff --git a/grsecurity/Makefile b/grsecurity/Makefile
58087new file mode 100644
58088index 0000000..1b9afa9
58089--- /dev/null
58090+++ b/grsecurity/Makefile
58091@@ -0,0 +1,38 @@
58092+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
58093+# during 2001-2009 it has been completely redesigned by Brad Spengler
58094+# into an RBAC system
58095+#
58096+# All code in this directory and various hooks inserted throughout the kernel
58097+# are copyright Brad Spengler - Open Source Security, Inc., and released
58098+# under the GPL v2 or higher
58099+
58100+KBUILD_CFLAGS += -Werror
58101+
58102+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
58103+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
58104+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
58105+
58106+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
58107+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
58108+ gracl_learn.o grsec_log.o
58109+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
58110+
58111+ifdef CONFIG_NET
58112+obj-y += grsec_sock.o
58113+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
58114+endif
58115+
58116+ifndef CONFIG_GRKERNSEC
58117+obj-y += grsec_disabled.o
58118+endif
58119+
58120+ifdef CONFIG_GRKERNSEC_HIDESYM
58121+extra-y := grsec_hidesym.o
58122+$(obj)/grsec_hidesym.o:
58123+ @-chmod -f 500 /boot
58124+ @-chmod -f 500 /lib/modules
58125+ @-chmod -f 500 /lib64/modules
58126+ @-chmod -f 500 /lib32/modules
58127+ @-chmod -f 700 .
58128+ @echo ' grsec: protected kernel image paths'
58129+endif
58130diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
58131new file mode 100644
58132index 0000000..b306b36
58133--- /dev/null
58134+++ b/grsecurity/gracl.c
58135@@ -0,0 +1,4071 @@
58136+#include <linux/kernel.h>
58137+#include <linux/module.h>
58138+#include <linux/sched.h>
58139+#include <linux/mm.h>
58140+#include <linux/file.h>
58141+#include <linux/fs.h>
58142+#include <linux/namei.h>
58143+#include <linux/mount.h>
58144+#include <linux/tty.h>
58145+#include <linux/proc_fs.h>
58146+#include <linux/lglock.h>
58147+#include <linux/slab.h>
58148+#include <linux/vmalloc.h>
58149+#include <linux/types.h>
58150+#include <linux/sysctl.h>
58151+#include <linux/netdevice.h>
58152+#include <linux/ptrace.h>
58153+#include <linux/gracl.h>
58154+#include <linux/gralloc.h>
58155+#include <linux/security.h>
58156+#include <linux/grinternal.h>
58157+#include <linux/pid_namespace.h>
58158+#include <linux/stop_machine.h>
58159+#include <linux/fdtable.h>
58160+#include <linux/percpu.h>
58161+#include <linux/lglock.h>
58162+#include <linux/hugetlb.h>
58163+#include <linux/posix-timers.h>
58164+#include "../fs/mount.h"
58165+
58166+#include <asm/uaccess.h>
58167+#include <asm/errno.h>
58168+#include <asm/mman.h>
58169+
58170+extern struct lglock vfsmount_lock;
58171+
58172+static struct acl_role_db acl_role_set;
58173+static struct name_db name_set;
58174+static struct inodev_db inodev_set;
58175+
58176+/* for keeping track of userspace pointers used for subjects, so we
58177+ can share references in the kernel as well
58178+*/
58179+
58180+static struct path real_root;
58181+
58182+static struct acl_subj_map_db subj_map_set;
58183+
58184+static struct acl_role_label *default_role;
58185+
58186+static struct acl_role_label *role_list;
58187+
58188+static u16 acl_sp_role_value;
58189+
58190+extern char *gr_shared_page[4];
58191+static DEFINE_MUTEX(gr_dev_mutex);
58192+DEFINE_RWLOCK(gr_inode_lock);
58193+
58194+struct gr_arg *gr_usermode;
58195+
58196+static unsigned int gr_status __read_only = GR_STATUS_INIT;
58197+
58198+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
58199+extern void gr_clear_learn_entries(void);
58200+
58201+unsigned char *gr_system_salt;
58202+unsigned char *gr_system_sum;
58203+
58204+static struct sprole_pw **acl_special_roles = NULL;
58205+static __u16 num_sprole_pws = 0;
58206+
58207+static struct acl_role_label *kernel_role = NULL;
58208+
58209+static unsigned int gr_auth_attempts = 0;
58210+static unsigned long gr_auth_expires = 0UL;
58211+
58212+#ifdef CONFIG_NET
58213+extern struct vfsmount *sock_mnt;
58214+#endif
58215+
58216+extern struct vfsmount *pipe_mnt;
58217+extern struct vfsmount *shm_mnt;
58218+
58219+#ifdef CONFIG_HUGETLBFS
58220+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
58221+#endif
58222+
58223+static struct acl_object_label *fakefs_obj_rw;
58224+static struct acl_object_label *fakefs_obj_rwx;
58225+
58226+extern int gr_init_uidset(void);
58227+extern void gr_free_uidset(void);
58228+extern void gr_remove_uid(uid_t uid);
58229+extern int gr_find_uid(uid_t uid);
58230+
58231+__inline__ int
58232+gr_acl_is_enabled(void)
58233+{
58234+ return (gr_status & GR_READY);
58235+}
58236+
58237+#ifdef CONFIG_BTRFS_FS
58238+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
58239+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
58240+#endif
58241+
58242+static inline dev_t __get_dev(const struct dentry *dentry)
58243+{
58244+#ifdef CONFIG_BTRFS_FS
58245+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
58246+ return get_btrfs_dev_from_inode(dentry->d_inode);
58247+ else
58248+#endif
58249+ return dentry->d_inode->i_sb->s_dev;
58250+}
58251+
58252+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
58253+{
58254+ return __get_dev(dentry);
58255+}
58256+
58257+static char gr_task_roletype_to_char(struct task_struct *task)
58258+{
58259+ switch (task->role->roletype &
58260+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
58261+ GR_ROLE_SPECIAL)) {
58262+ case GR_ROLE_DEFAULT:
58263+ return 'D';
58264+ case GR_ROLE_USER:
58265+ return 'U';
58266+ case GR_ROLE_GROUP:
58267+ return 'G';
58268+ case GR_ROLE_SPECIAL:
58269+ return 'S';
58270+ }
58271+
58272+ return 'X';
58273+}
58274+
58275+char gr_roletype_to_char(void)
58276+{
58277+ return gr_task_roletype_to_char(current);
58278+}
58279+
58280+__inline__ int
58281+gr_acl_tpe_check(void)
58282+{
58283+ if (unlikely(!(gr_status & GR_READY)))
58284+ return 0;
58285+ if (current->role->roletype & GR_ROLE_TPE)
58286+ return 1;
58287+ else
58288+ return 0;
58289+}
58290+
58291+int
58292+gr_handle_rawio(const struct inode *inode)
58293+{
58294+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58295+ if (inode && S_ISBLK(inode->i_mode) &&
58296+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
58297+ !capable(CAP_SYS_RAWIO))
58298+ return 1;
58299+#endif
58300+ return 0;
58301+}
58302+
58303+static int
58304+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
58305+{
58306+ if (likely(lena != lenb))
58307+ return 0;
58308+
58309+ return !memcmp(a, b, lena);
58310+}
58311+
58312+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
58313+{
58314+ *buflen -= namelen;
58315+ if (*buflen < 0)
58316+ return -ENAMETOOLONG;
58317+ *buffer -= namelen;
58318+ memcpy(*buffer, str, namelen);
58319+ return 0;
58320+}
58321+
58322+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
58323+{
58324+ return prepend(buffer, buflen, name->name, name->len);
58325+}
58326+
58327+static int prepend_path(const struct path *path, struct path *root,
58328+ char **buffer, int *buflen)
58329+{
58330+ struct dentry *dentry = path->dentry;
58331+ struct vfsmount *vfsmnt = path->mnt;
58332+ struct mount *mnt = real_mount(vfsmnt);
58333+ bool slash = false;
58334+ int error = 0;
58335+
58336+ while (dentry != root->dentry || vfsmnt != root->mnt) {
58337+ struct dentry * parent;
58338+
58339+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
58340+ /* Global root? */
58341+ if (!mnt_has_parent(mnt)) {
58342+ goto out;
58343+ }
58344+ dentry = mnt->mnt_mountpoint;
58345+ mnt = mnt->mnt_parent;
58346+ vfsmnt = &mnt->mnt;
58347+ continue;
58348+ }
58349+ parent = dentry->d_parent;
58350+ prefetch(parent);
58351+ spin_lock(&dentry->d_lock);
58352+ error = prepend_name(buffer, buflen, &dentry->d_name);
58353+ spin_unlock(&dentry->d_lock);
58354+ if (!error)
58355+ error = prepend(buffer, buflen, "/", 1);
58356+ if (error)
58357+ break;
58358+
58359+ slash = true;
58360+ dentry = parent;
58361+ }
58362+
58363+out:
58364+ if (!error && !slash)
58365+ error = prepend(buffer, buflen, "/", 1);
58366+
58367+ return error;
58368+}
58369+
58370+/* this must be called with vfsmount_lock and rename_lock held */
58371+
58372+static char *__our_d_path(const struct path *path, struct path *root,
58373+ char *buf, int buflen)
58374+{
58375+ char *res = buf + buflen;
58376+ int error;
58377+
58378+ prepend(&res, &buflen, "\0", 1);
58379+ error = prepend_path(path, root, &res, &buflen);
58380+ if (error)
58381+ return ERR_PTR(error);
58382+
58383+ return res;
58384+}
58385+
58386+static char *
58387+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
58388+{
58389+ char *retval;
58390+
58391+ retval = __our_d_path(path, root, buf, buflen);
58392+ if (unlikely(IS_ERR(retval)))
58393+ retval = strcpy(buf, "<path too long>");
58394+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
58395+ retval[1] = '\0';
58396+
58397+ return retval;
58398+}
58399+
58400+static char *
58401+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
58402+ char *buf, int buflen)
58403+{
58404+ struct path path;
58405+ char *res;
58406+
58407+ path.dentry = (struct dentry *)dentry;
58408+ path.mnt = (struct vfsmount *)vfsmnt;
58409+
58410+ /* we can use real_root.dentry, real_root.mnt, because this is only called
58411+ by the RBAC system */
58412+ res = gen_full_path(&path, &real_root, buf, buflen);
58413+
58414+ return res;
58415+}
58416+
58417+static char *
58418+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
58419+ char *buf, int buflen)
58420+{
58421+ char *res;
58422+ struct path path;
58423+ struct path root;
58424+ struct task_struct *reaper = init_pid_ns.child_reaper;
58425+
58426+ path.dentry = (struct dentry *)dentry;
58427+ path.mnt = (struct vfsmount *)vfsmnt;
58428+
58429+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
58430+ get_fs_root(reaper->fs, &root);
58431+
58432+ br_read_lock(&vfsmount_lock);
58433+ write_seqlock(&rename_lock);
58434+ res = gen_full_path(&path, &root, buf, buflen);
58435+ write_sequnlock(&rename_lock);
58436+ br_read_unlock(&vfsmount_lock);
58437+
58438+ path_put(&root);
58439+ return res;
58440+}
58441+
58442+static char *
58443+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
58444+{
58445+ char *ret;
58446+ br_read_lock(&vfsmount_lock);
58447+ write_seqlock(&rename_lock);
58448+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
58449+ PAGE_SIZE);
58450+ write_sequnlock(&rename_lock);
58451+ br_read_unlock(&vfsmount_lock);
58452+ return ret;
58453+}
58454+
58455+static char *
58456+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
58457+{
58458+ char *ret;
58459+ char *buf;
58460+ int buflen;
58461+
58462+ br_read_lock(&vfsmount_lock);
58463+ write_seqlock(&rename_lock);
58464+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
58465+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
58466+ buflen = (int)(ret - buf);
58467+ if (buflen >= 5)
58468+ prepend(&ret, &buflen, "/proc", 5);
58469+ else
58470+ ret = strcpy(buf, "<path too long>");
58471+ write_sequnlock(&rename_lock);
58472+ br_read_unlock(&vfsmount_lock);
58473+ return ret;
58474+}
58475+
58476+char *
58477+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
58478+{
58479+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
58480+ PAGE_SIZE);
58481+}
58482+
58483+char *
58484+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
58485+{
58486+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
58487+ PAGE_SIZE);
58488+}
58489+
58490+char *
58491+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
58492+{
58493+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
58494+ PAGE_SIZE);
58495+}
58496+
58497+char *
58498+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
58499+{
58500+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
58501+ PAGE_SIZE);
58502+}
58503+
58504+char *
58505+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
58506+{
58507+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
58508+ PAGE_SIZE);
58509+}
58510+
58511+__inline__ __u32
58512+to_gr_audit(const __u32 reqmode)
58513+{
58514+ /* masks off auditable permission flags, then shifts them to create
58515+ auditing flags, and adds the special case of append auditing if
58516+ we're requesting write */
58517+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
58518+}
58519+
58520+struct acl_subject_label *
58521+lookup_subject_map(const struct acl_subject_label *userp)
58522+{
58523+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
58524+ struct subject_map *match;
58525+
58526+ match = subj_map_set.s_hash[index];
58527+
58528+ while (match && match->user != userp)
58529+ match = match->next;
58530+
58531+ if (match != NULL)
58532+ return match->kernel;
58533+ else
58534+ return NULL;
58535+}
58536+
58537+static void
58538+insert_subj_map_entry(struct subject_map *subjmap)
58539+{
58540+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
58541+ struct subject_map **curr;
58542+
58543+ subjmap->prev = NULL;
58544+
58545+ curr = &subj_map_set.s_hash[index];
58546+ if (*curr != NULL)
58547+ (*curr)->prev = subjmap;
58548+
58549+ subjmap->next = *curr;
58550+ *curr = subjmap;
58551+
58552+ return;
58553+}
58554+
58555+static struct acl_role_label *
58556+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
58557+ const gid_t gid)
58558+{
58559+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
58560+ struct acl_role_label *match;
58561+ struct role_allowed_ip *ipp;
58562+ unsigned int x;
58563+ u32 curr_ip = task->signal->curr_ip;
58564+
58565+ task->signal->saved_ip = curr_ip;
58566+
58567+ match = acl_role_set.r_hash[index];
58568+
58569+ while (match) {
58570+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
58571+ for (x = 0; x < match->domain_child_num; x++) {
58572+ if (match->domain_children[x] == uid)
58573+ goto found;
58574+ }
58575+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
58576+ break;
58577+ match = match->next;
58578+ }
58579+found:
58580+ if (match == NULL) {
58581+ try_group:
58582+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
58583+ match = acl_role_set.r_hash[index];
58584+
58585+ while (match) {
58586+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
58587+ for (x = 0; x < match->domain_child_num; x++) {
58588+ if (match->domain_children[x] == gid)
58589+ goto found2;
58590+ }
58591+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
58592+ break;
58593+ match = match->next;
58594+ }
58595+found2:
58596+ if (match == NULL)
58597+ match = default_role;
58598+ if (match->allowed_ips == NULL)
58599+ return match;
58600+ else {
58601+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
58602+ if (likely
58603+ ((ntohl(curr_ip) & ipp->netmask) ==
58604+ (ntohl(ipp->addr) & ipp->netmask)))
58605+ return match;
58606+ }
58607+ match = default_role;
58608+ }
58609+ } else if (match->allowed_ips == NULL) {
58610+ return match;
58611+ } else {
58612+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
58613+ if (likely
58614+ ((ntohl(curr_ip) & ipp->netmask) ==
58615+ (ntohl(ipp->addr) & ipp->netmask)))
58616+ return match;
58617+ }
58618+ goto try_group;
58619+ }
58620+
58621+ return match;
58622+}
58623+
58624+struct acl_subject_label *
58625+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
58626+ const struct acl_role_label *role)
58627+{
58628+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
58629+ struct acl_subject_label *match;
58630+
58631+ match = role->subj_hash[index];
58632+
58633+ while (match && (match->inode != ino || match->device != dev ||
58634+ (match->mode & GR_DELETED))) {
58635+ match = match->next;
58636+ }
58637+
58638+ if (match && !(match->mode & GR_DELETED))
58639+ return match;
58640+ else
58641+ return NULL;
58642+}
58643+
58644+struct acl_subject_label *
58645+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
58646+ const struct acl_role_label *role)
58647+{
58648+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
58649+ struct acl_subject_label *match;
58650+
58651+ match = role->subj_hash[index];
58652+
58653+ while (match && (match->inode != ino || match->device != dev ||
58654+ !(match->mode & GR_DELETED))) {
58655+ match = match->next;
58656+ }
58657+
58658+ if (match && (match->mode & GR_DELETED))
58659+ return match;
58660+ else
58661+ return NULL;
58662+}
58663+
58664+static struct acl_object_label *
58665+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
58666+ const struct acl_subject_label *subj)
58667+{
58668+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
58669+ struct acl_object_label *match;
58670+
58671+ match = subj->obj_hash[index];
58672+
58673+ while (match && (match->inode != ino || match->device != dev ||
58674+ (match->mode & GR_DELETED))) {
58675+ match = match->next;
58676+ }
58677+
58678+ if (match && !(match->mode & GR_DELETED))
58679+ return match;
58680+ else
58681+ return NULL;
58682+}
58683+
58684+static struct acl_object_label *
58685+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
58686+ const struct acl_subject_label *subj)
58687+{
58688+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
58689+ struct acl_object_label *match;
58690+
58691+ match = subj->obj_hash[index];
58692+
58693+ while (match && (match->inode != ino || match->device != dev ||
58694+ !(match->mode & GR_DELETED))) {
58695+ match = match->next;
58696+ }
58697+
58698+ if (match && (match->mode & GR_DELETED))
58699+ return match;
58700+
58701+ match = subj->obj_hash[index];
58702+
58703+ while (match && (match->inode != ino || match->device != dev ||
58704+ (match->mode & GR_DELETED))) {
58705+ match = match->next;
58706+ }
58707+
58708+ if (match && !(match->mode & GR_DELETED))
58709+ return match;
58710+ else
58711+ return NULL;
58712+}
58713+
58714+static struct name_entry *
58715+lookup_name_entry(const char *name)
58716+{
58717+ unsigned int len = strlen(name);
58718+ unsigned int key = full_name_hash(name, len);
58719+ unsigned int index = key % name_set.n_size;
58720+ struct name_entry *match;
58721+
58722+ match = name_set.n_hash[index];
58723+
58724+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
58725+ match = match->next;
58726+
58727+ return match;
58728+}
58729+
58730+static struct name_entry *
58731+lookup_name_entry_create(const char *name)
58732+{
58733+ unsigned int len = strlen(name);
58734+ unsigned int key = full_name_hash(name, len);
58735+ unsigned int index = key % name_set.n_size;
58736+ struct name_entry *match;
58737+
58738+ match = name_set.n_hash[index];
58739+
58740+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
58741+ !match->deleted))
58742+ match = match->next;
58743+
58744+ if (match && match->deleted)
58745+ return match;
58746+
58747+ match = name_set.n_hash[index];
58748+
58749+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
58750+ match->deleted))
58751+ match = match->next;
58752+
58753+ if (match && !match->deleted)
58754+ return match;
58755+ else
58756+ return NULL;
58757+}
58758+
58759+static struct inodev_entry *
58760+lookup_inodev_entry(const ino_t ino, const dev_t dev)
58761+{
58762+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
58763+ struct inodev_entry *match;
58764+
58765+ match = inodev_set.i_hash[index];
58766+
58767+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
58768+ match = match->next;
58769+
58770+ return match;
58771+}
58772+
58773+static void
58774+insert_inodev_entry(struct inodev_entry *entry)
58775+{
58776+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
58777+ inodev_set.i_size);
58778+ struct inodev_entry **curr;
58779+
58780+ entry->prev = NULL;
58781+
58782+ curr = &inodev_set.i_hash[index];
58783+ if (*curr != NULL)
58784+ (*curr)->prev = entry;
58785+
58786+ entry->next = *curr;
58787+ *curr = entry;
58788+
58789+ return;
58790+}
58791+
58792+static void
58793+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
58794+{
58795+ unsigned int index =
58796+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
58797+ struct acl_role_label **curr;
58798+ struct acl_role_label *tmp, *tmp2;
58799+
58800+ curr = &acl_role_set.r_hash[index];
58801+
58802+ /* simple case, slot is empty, just set it to our role */
58803+ if (*curr == NULL) {
58804+ *curr = role;
58805+ } else {
58806+ /* example:
58807+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
58808+ 2 -> 3
58809+ */
58810+ /* first check to see if we can already be reached via this slot */
58811+ tmp = *curr;
58812+ while (tmp && tmp != role)
58813+ tmp = tmp->next;
58814+ if (tmp == role) {
58815+ /* we don't need to add ourselves to this slot's chain */
58816+ return;
58817+ }
58818+ /* we need to add ourselves to this chain, two cases */
58819+ if (role->next == NULL) {
58820+ /* simple case, append the current chain to our role */
58821+ role->next = *curr;
58822+ *curr = role;
58823+ } else {
58824+ /* 1 -> 2 -> 3 -> 4
58825+ 2 -> 3 -> 4
58826+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
58827+ */
58828+ /* trickier case: walk our role's chain until we find
58829+ the role for the start of the current slot's chain */
58830+ tmp = role;
58831+ tmp2 = *curr;
58832+ while (tmp->next && tmp->next != tmp2)
58833+ tmp = tmp->next;
58834+ if (tmp->next == tmp2) {
58835+ /* from example above, we found 3, so just
58836+ replace this slot's chain with ours */
58837+ *curr = role;
58838+ } else {
58839+ /* we didn't find a subset of our role's chain
58840+ in the current slot's chain, so append their
58841+ chain to ours, and set us as the first role in
58842+ the slot's chain
58843+
58844+ we could fold this case with the case above,
58845+ but making it explicit for clarity
58846+ */
58847+ tmp->next = tmp2;
58848+ *curr = role;
58849+ }
58850+ }
58851+ }
58852+
58853+ return;
58854+}
58855+
58856+static void
58857+insert_acl_role_label(struct acl_role_label *role)
58858+{
58859+ int i;
58860+
58861+ if (role_list == NULL) {
58862+ role_list = role;
58863+ role->prev = NULL;
58864+ } else {
58865+ role->prev = role_list;
58866+ role_list = role;
58867+ }
58868+
58869+ /* used for hash chains */
58870+ role->next = NULL;
58871+
58872+ if (role->roletype & GR_ROLE_DOMAIN) {
58873+ for (i = 0; i < role->domain_child_num; i++)
58874+ __insert_acl_role_label(role, role->domain_children[i]);
58875+ } else
58876+ __insert_acl_role_label(role, role->uidgid);
58877+}
58878+
58879+static int
58880+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
58881+{
58882+ struct name_entry **curr, *nentry;
58883+ struct inodev_entry *ientry;
58884+ unsigned int len = strlen(name);
58885+ unsigned int key = full_name_hash(name, len);
58886+ unsigned int index = key % name_set.n_size;
58887+
58888+ curr = &name_set.n_hash[index];
58889+
58890+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
58891+ curr = &((*curr)->next);
58892+
58893+ if (*curr != NULL)
58894+ return 1;
58895+
58896+ nentry = acl_alloc(sizeof (struct name_entry));
58897+ if (nentry == NULL)
58898+ return 0;
58899+ ientry = acl_alloc(sizeof (struct inodev_entry));
58900+ if (ientry == NULL)
58901+ return 0;
58902+ ientry->nentry = nentry;
58903+
58904+ nentry->key = key;
58905+ nentry->name = name;
58906+ nentry->inode = inode;
58907+ nentry->device = device;
58908+ nentry->len = len;
58909+ nentry->deleted = deleted;
58910+
58911+ nentry->prev = NULL;
58912+ curr = &name_set.n_hash[index];
58913+ if (*curr != NULL)
58914+ (*curr)->prev = nentry;
58915+ nentry->next = *curr;
58916+ *curr = nentry;
58917+
58918+ /* insert us into the table searchable by inode/dev */
58919+ insert_inodev_entry(ientry);
58920+
58921+ return 1;
58922+}
58923+
58924+static void
58925+insert_acl_obj_label(struct acl_object_label *obj,
58926+ struct acl_subject_label *subj)
58927+{
58928+ unsigned int index =
58929+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
58930+ struct acl_object_label **curr;
58931+
58932+
58933+ obj->prev = NULL;
58934+
58935+ curr = &subj->obj_hash[index];
58936+ if (*curr != NULL)
58937+ (*curr)->prev = obj;
58938+
58939+ obj->next = *curr;
58940+ *curr = obj;
58941+
58942+ return;
58943+}
58944+
58945+static void
58946+insert_acl_subj_label(struct acl_subject_label *obj,
58947+ struct acl_role_label *role)
58948+{
58949+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
58950+ struct acl_subject_label **curr;
58951+
58952+ obj->prev = NULL;
58953+
58954+ curr = &role->subj_hash[index];
58955+ if (*curr != NULL)
58956+ (*curr)->prev = obj;
58957+
58958+ obj->next = *curr;
58959+ *curr = obj;
58960+
58961+ return;
58962+}
58963+
58964+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
58965+
58966+static void *
58967+create_table(__u32 * len, int elementsize)
58968+{
58969+ unsigned int table_sizes[] = {
58970+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
58971+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
58972+ 4194301, 8388593, 16777213, 33554393, 67108859
58973+ };
58974+ void *newtable = NULL;
58975+ unsigned int pwr = 0;
58976+
58977+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
58978+ table_sizes[pwr] <= *len)
58979+ pwr++;
58980+
58981+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
58982+ return newtable;
58983+
58984+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
58985+ newtable =
58986+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
58987+ else
58988+ newtable = vmalloc(table_sizes[pwr] * elementsize);
58989+
58990+ *len = table_sizes[pwr];
58991+
58992+ return newtable;
58993+}
58994+
58995+static int
58996+init_variables(const struct gr_arg *arg)
58997+{
58998+ struct task_struct *reaper = init_pid_ns.child_reaper;
58999+ unsigned int stacksize;
59000+
59001+ subj_map_set.s_size = arg->role_db.num_subjects;
59002+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
59003+ name_set.n_size = arg->role_db.num_objects;
59004+ inodev_set.i_size = arg->role_db.num_objects;
59005+
59006+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
59007+ !name_set.n_size || !inodev_set.i_size)
59008+ return 1;
59009+
59010+ if (!gr_init_uidset())
59011+ return 1;
59012+
59013+ /* set up the stack that holds allocation info */
59014+
59015+ stacksize = arg->role_db.num_pointers + 5;
59016+
59017+ if (!acl_alloc_stack_init(stacksize))
59018+ return 1;
59019+
59020+ /* grab reference for the real root dentry and vfsmount */
59021+ get_fs_root(reaper->fs, &real_root);
59022+
59023+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59024+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
59025+#endif
59026+
59027+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
59028+ if (fakefs_obj_rw == NULL)
59029+ return 1;
59030+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
59031+
59032+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
59033+ if (fakefs_obj_rwx == NULL)
59034+ return 1;
59035+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
59036+
59037+ subj_map_set.s_hash =
59038+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
59039+ acl_role_set.r_hash =
59040+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
59041+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
59042+ inodev_set.i_hash =
59043+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
59044+
59045+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
59046+ !name_set.n_hash || !inodev_set.i_hash)
59047+ return 1;
59048+
59049+ memset(subj_map_set.s_hash, 0,
59050+ sizeof(struct subject_map *) * subj_map_set.s_size);
59051+ memset(acl_role_set.r_hash, 0,
59052+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
59053+ memset(name_set.n_hash, 0,
59054+ sizeof (struct name_entry *) * name_set.n_size);
59055+ memset(inodev_set.i_hash, 0,
59056+ sizeof (struct inodev_entry *) * inodev_set.i_size);
59057+
59058+ return 0;
59059+}
59060+
59061+/* free information not needed after startup
59062+ currently contains user->kernel pointer mappings for subjects
59063+*/
59064+
59065+static void
59066+free_init_variables(void)
59067+{
59068+ __u32 i;
59069+
59070+ if (subj_map_set.s_hash) {
59071+ for (i = 0; i < subj_map_set.s_size; i++) {
59072+ if (subj_map_set.s_hash[i]) {
59073+ kfree(subj_map_set.s_hash[i]);
59074+ subj_map_set.s_hash[i] = NULL;
59075+ }
59076+ }
59077+
59078+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
59079+ PAGE_SIZE)
59080+ kfree(subj_map_set.s_hash);
59081+ else
59082+ vfree(subj_map_set.s_hash);
59083+ }
59084+
59085+ return;
59086+}
59087+
59088+static void
59089+free_variables(void)
59090+{
59091+ struct acl_subject_label *s;
59092+ struct acl_role_label *r;
59093+ struct task_struct *task, *task2;
59094+ unsigned int x;
59095+
59096+ gr_clear_learn_entries();
59097+
59098+ read_lock(&tasklist_lock);
59099+ do_each_thread(task2, task) {
59100+ task->acl_sp_role = 0;
59101+ task->acl_role_id = 0;
59102+ task->acl = NULL;
59103+ task->role = NULL;
59104+ } while_each_thread(task2, task);
59105+ read_unlock(&tasklist_lock);
59106+
59107+ /* release the reference to the real root dentry and vfsmount */
59108+ path_put(&real_root);
59109+ memset(&real_root, 0, sizeof(real_root));
59110+
59111+ /* free all object hash tables */
59112+
59113+ FOR_EACH_ROLE_START(r)
59114+ if (r->subj_hash == NULL)
59115+ goto next_role;
59116+ FOR_EACH_SUBJECT_START(r, s, x)
59117+ if (s->obj_hash == NULL)
59118+ break;
59119+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
59120+ kfree(s->obj_hash);
59121+ else
59122+ vfree(s->obj_hash);
59123+ FOR_EACH_SUBJECT_END(s, x)
59124+ FOR_EACH_NESTED_SUBJECT_START(r, s)
59125+ if (s->obj_hash == NULL)
59126+ break;
59127+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
59128+ kfree(s->obj_hash);
59129+ else
59130+ vfree(s->obj_hash);
59131+ FOR_EACH_NESTED_SUBJECT_END(s)
59132+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
59133+ kfree(r->subj_hash);
59134+ else
59135+ vfree(r->subj_hash);
59136+ r->subj_hash = NULL;
59137+next_role:
59138+ FOR_EACH_ROLE_END(r)
59139+
59140+ acl_free_all();
59141+
59142+ if (acl_role_set.r_hash) {
59143+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
59144+ PAGE_SIZE)
59145+ kfree(acl_role_set.r_hash);
59146+ else
59147+ vfree(acl_role_set.r_hash);
59148+ }
59149+ if (name_set.n_hash) {
59150+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
59151+ PAGE_SIZE)
59152+ kfree(name_set.n_hash);
59153+ else
59154+ vfree(name_set.n_hash);
59155+ }
59156+
59157+ if (inodev_set.i_hash) {
59158+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
59159+ PAGE_SIZE)
59160+ kfree(inodev_set.i_hash);
59161+ else
59162+ vfree(inodev_set.i_hash);
59163+ }
59164+
59165+ gr_free_uidset();
59166+
59167+ memset(&name_set, 0, sizeof (struct name_db));
59168+ memset(&inodev_set, 0, sizeof (struct inodev_db));
59169+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
59170+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
59171+
59172+ default_role = NULL;
59173+ kernel_role = NULL;
59174+ role_list = NULL;
59175+
59176+ return;
59177+}
59178+
59179+static __u32
59180+count_user_objs(struct acl_object_label *userp)
59181+{
59182+ struct acl_object_label o_tmp;
59183+ __u32 num = 0;
59184+
59185+ while (userp) {
59186+ if (copy_from_user(&o_tmp, userp,
59187+ sizeof (struct acl_object_label)))
59188+ break;
59189+
59190+ userp = o_tmp.prev;
59191+ num++;
59192+ }
59193+
59194+ return num;
59195+}
59196+
59197+static struct acl_subject_label *
59198+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
59199+
59200+static int
59201+copy_user_glob(struct acl_object_label *obj)
59202+{
59203+ struct acl_object_label *g_tmp, **guser;
59204+ unsigned int len;
59205+ char *tmp;
59206+
59207+ if (obj->globbed == NULL)
59208+ return 0;
59209+
59210+ guser = &obj->globbed;
59211+ while (*guser) {
59212+ g_tmp = (struct acl_object_label *)
59213+ acl_alloc(sizeof (struct acl_object_label));
59214+ if (g_tmp == NULL)
59215+ return -ENOMEM;
59216+
59217+ if (copy_from_user(g_tmp, *guser,
59218+ sizeof (struct acl_object_label)))
59219+ return -EFAULT;
59220+
59221+ len = strnlen_user(g_tmp->filename, PATH_MAX);
59222+
59223+ if (!len || len >= PATH_MAX)
59224+ return -EINVAL;
59225+
59226+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59227+ return -ENOMEM;
59228+
59229+ if (copy_from_user(tmp, g_tmp->filename, len))
59230+ return -EFAULT;
59231+ tmp[len-1] = '\0';
59232+ g_tmp->filename = tmp;
59233+
59234+ *guser = g_tmp;
59235+ guser = &(g_tmp->next);
59236+ }
59237+
59238+ return 0;
59239+}
59240+
59241+static int
59242+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
59243+ struct acl_role_label *role)
59244+{
59245+ struct acl_object_label *o_tmp;
59246+ unsigned int len;
59247+ int ret;
59248+ char *tmp;
59249+
59250+ while (userp) {
59251+ if ((o_tmp = (struct acl_object_label *)
59252+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
59253+ return -ENOMEM;
59254+
59255+ if (copy_from_user(o_tmp, userp,
59256+ sizeof (struct acl_object_label)))
59257+ return -EFAULT;
59258+
59259+ userp = o_tmp->prev;
59260+
59261+ len = strnlen_user(o_tmp->filename, PATH_MAX);
59262+
59263+ if (!len || len >= PATH_MAX)
59264+ return -EINVAL;
59265+
59266+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59267+ return -ENOMEM;
59268+
59269+ if (copy_from_user(tmp, o_tmp->filename, len))
59270+ return -EFAULT;
59271+ tmp[len-1] = '\0';
59272+ o_tmp->filename = tmp;
59273+
59274+ insert_acl_obj_label(o_tmp, subj);
59275+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
59276+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
59277+ return -ENOMEM;
59278+
59279+ ret = copy_user_glob(o_tmp);
59280+ if (ret)
59281+ return ret;
59282+
59283+ if (o_tmp->nested) {
59284+ int already_copied;
59285+
59286+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
59287+ if (IS_ERR(o_tmp->nested))
59288+ return PTR_ERR(o_tmp->nested);
59289+
59290+ /* insert into nested subject list if we haven't copied this one yet
59291+ to prevent duplicate entries */
59292+ if (!already_copied) {
59293+ o_tmp->nested->next = role->hash->first;
59294+ role->hash->first = o_tmp->nested;
59295+ }
59296+ }
59297+ }
59298+
59299+ return 0;
59300+}
59301+
59302+static __u32
59303+count_user_subjs(struct acl_subject_label *userp)
59304+{
59305+ struct acl_subject_label s_tmp;
59306+ __u32 num = 0;
59307+
59308+ while (userp) {
59309+ if (copy_from_user(&s_tmp, userp,
59310+ sizeof (struct acl_subject_label)))
59311+ break;
59312+
59313+ userp = s_tmp.prev;
59314+ }
59315+
59316+ return num;
59317+}
59318+
59319+static int
59320+copy_user_allowedips(struct acl_role_label *rolep)
59321+{
59322+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
59323+
59324+ ruserip = rolep->allowed_ips;
59325+
59326+ while (ruserip) {
59327+ rlast = rtmp;
59328+
59329+ if ((rtmp = (struct role_allowed_ip *)
59330+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
59331+ return -ENOMEM;
59332+
59333+ if (copy_from_user(rtmp, ruserip,
59334+ sizeof (struct role_allowed_ip)))
59335+ return -EFAULT;
59336+
59337+ ruserip = rtmp->prev;
59338+
59339+ if (!rlast) {
59340+ rtmp->prev = NULL;
59341+ rolep->allowed_ips = rtmp;
59342+ } else {
59343+ rlast->next = rtmp;
59344+ rtmp->prev = rlast;
59345+ }
59346+
59347+ if (!ruserip)
59348+ rtmp->next = NULL;
59349+ }
59350+
59351+ return 0;
59352+}
59353+
59354+static int
59355+copy_user_transitions(struct acl_role_label *rolep)
59356+{
59357+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
59358+
59359+ unsigned int len;
59360+ char *tmp;
59361+
59362+ rusertp = rolep->transitions;
59363+
59364+ while (rusertp) {
59365+ rlast = rtmp;
59366+
59367+ if ((rtmp = (struct role_transition *)
59368+ acl_alloc(sizeof (struct role_transition))) == NULL)
59369+ return -ENOMEM;
59370+
59371+ if (copy_from_user(rtmp, rusertp,
59372+ sizeof (struct role_transition)))
59373+ return -EFAULT;
59374+
59375+ rusertp = rtmp->prev;
59376+
59377+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
59378+
59379+ if (!len || len >= GR_SPROLE_LEN)
59380+ return -EINVAL;
59381+
59382+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59383+ return -ENOMEM;
59384+
59385+ if (copy_from_user(tmp, rtmp->rolename, len))
59386+ return -EFAULT;
59387+ tmp[len-1] = '\0';
59388+ rtmp->rolename = tmp;
59389+
59390+ if (!rlast) {
59391+ rtmp->prev = NULL;
59392+ rolep->transitions = rtmp;
59393+ } else {
59394+ rlast->next = rtmp;
59395+ rtmp->prev = rlast;
59396+ }
59397+
59398+ if (!rusertp)
59399+ rtmp->next = NULL;
59400+ }
59401+
59402+ return 0;
59403+}
59404+
59405+static struct acl_subject_label *
59406+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
59407+{
59408+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
59409+ unsigned int len;
59410+ char *tmp;
59411+ __u32 num_objs;
59412+ struct acl_ip_label **i_tmp, *i_utmp2;
59413+ struct gr_hash_struct ghash;
59414+ struct subject_map *subjmap;
59415+ unsigned int i_num;
59416+ int err;
59417+
59418+ if (already_copied != NULL)
59419+ *already_copied = 0;
59420+
59421+ s_tmp = lookup_subject_map(userp);
59422+
59423+ /* we've already copied this subject into the kernel, just return
59424+ the reference to it, and don't copy it over again
59425+ */
59426+ if (s_tmp) {
59427+ if (already_copied != NULL)
59428+ *already_copied = 1;
59429+ return(s_tmp);
59430+ }
59431+
59432+ if ((s_tmp = (struct acl_subject_label *)
59433+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
59434+ return ERR_PTR(-ENOMEM);
59435+
59436+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
59437+ if (subjmap == NULL)
59438+ return ERR_PTR(-ENOMEM);
59439+
59440+ subjmap->user = userp;
59441+ subjmap->kernel = s_tmp;
59442+ insert_subj_map_entry(subjmap);
59443+
59444+ if (copy_from_user(s_tmp, userp,
59445+ sizeof (struct acl_subject_label)))
59446+ return ERR_PTR(-EFAULT);
59447+
59448+ len = strnlen_user(s_tmp->filename, PATH_MAX);
59449+
59450+ if (!len || len >= PATH_MAX)
59451+ return ERR_PTR(-EINVAL);
59452+
59453+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59454+ return ERR_PTR(-ENOMEM);
59455+
59456+ if (copy_from_user(tmp, s_tmp->filename, len))
59457+ return ERR_PTR(-EFAULT);
59458+ tmp[len-1] = '\0';
59459+ s_tmp->filename = tmp;
59460+
59461+ if (!strcmp(s_tmp->filename, "/"))
59462+ role->root_label = s_tmp;
59463+
59464+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
59465+ return ERR_PTR(-EFAULT);
59466+
59467+ /* copy user and group transition tables */
59468+
59469+ if (s_tmp->user_trans_num) {
59470+ uid_t *uidlist;
59471+
59472+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
59473+ if (uidlist == NULL)
59474+ return ERR_PTR(-ENOMEM);
59475+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
59476+ return ERR_PTR(-EFAULT);
59477+
59478+ s_tmp->user_transitions = uidlist;
59479+ }
59480+
59481+ if (s_tmp->group_trans_num) {
59482+ gid_t *gidlist;
59483+
59484+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
59485+ if (gidlist == NULL)
59486+ return ERR_PTR(-ENOMEM);
59487+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
59488+ return ERR_PTR(-EFAULT);
59489+
59490+ s_tmp->group_transitions = gidlist;
59491+ }
59492+
59493+ /* set up object hash table */
59494+ num_objs = count_user_objs(ghash.first);
59495+
59496+ s_tmp->obj_hash_size = num_objs;
59497+ s_tmp->obj_hash =
59498+ (struct acl_object_label **)
59499+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
59500+
59501+ if (!s_tmp->obj_hash)
59502+ return ERR_PTR(-ENOMEM);
59503+
59504+ memset(s_tmp->obj_hash, 0,
59505+ s_tmp->obj_hash_size *
59506+ sizeof (struct acl_object_label *));
59507+
59508+ /* add in objects */
59509+ err = copy_user_objs(ghash.first, s_tmp, role);
59510+
59511+ if (err)
59512+ return ERR_PTR(err);
59513+
59514+ /* set pointer for parent subject */
59515+ if (s_tmp->parent_subject) {
59516+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
59517+
59518+ if (IS_ERR(s_tmp2))
59519+ return s_tmp2;
59520+
59521+ s_tmp->parent_subject = s_tmp2;
59522+ }
59523+
59524+ /* add in ip acls */
59525+
59526+ if (!s_tmp->ip_num) {
59527+ s_tmp->ips = NULL;
59528+ goto insert;
59529+ }
59530+
59531+ i_tmp =
59532+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
59533+ sizeof (struct acl_ip_label *));
59534+
59535+ if (!i_tmp)
59536+ return ERR_PTR(-ENOMEM);
59537+
59538+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
59539+ *(i_tmp + i_num) =
59540+ (struct acl_ip_label *)
59541+ acl_alloc(sizeof (struct acl_ip_label));
59542+ if (!*(i_tmp + i_num))
59543+ return ERR_PTR(-ENOMEM);
59544+
59545+ if (copy_from_user
59546+ (&i_utmp2, s_tmp->ips + i_num,
59547+ sizeof (struct acl_ip_label *)))
59548+ return ERR_PTR(-EFAULT);
59549+
59550+ if (copy_from_user
59551+ (*(i_tmp + i_num), i_utmp2,
59552+ sizeof (struct acl_ip_label)))
59553+ return ERR_PTR(-EFAULT);
59554+
59555+ if ((*(i_tmp + i_num))->iface == NULL)
59556+ continue;
59557+
59558+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
59559+ if (!len || len >= IFNAMSIZ)
59560+ return ERR_PTR(-EINVAL);
59561+ tmp = acl_alloc(len);
59562+ if (tmp == NULL)
59563+ return ERR_PTR(-ENOMEM);
59564+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
59565+ return ERR_PTR(-EFAULT);
59566+ (*(i_tmp + i_num))->iface = tmp;
59567+ }
59568+
59569+ s_tmp->ips = i_tmp;
59570+
59571+insert:
59572+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
59573+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
59574+ return ERR_PTR(-ENOMEM);
59575+
59576+ return s_tmp;
59577+}
59578+
59579+static int
59580+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
59581+{
59582+ struct acl_subject_label s_pre;
59583+ struct acl_subject_label * ret;
59584+ int err;
59585+
59586+ while (userp) {
59587+ if (copy_from_user(&s_pre, userp,
59588+ sizeof (struct acl_subject_label)))
59589+ return -EFAULT;
59590+
59591+ ret = do_copy_user_subj(userp, role, NULL);
59592+
59593+ err = PTR_ERR(ret);
59594+ if (IS_ERR(ret))
59595+ return err;
59596+
59597+ insert_acl_subj_label(ret, role);
59598+
59599+ userp = s_pre.prev;
59600+ }
59601+
59602+ return 0;
59603+}
59604+
59605+static int
59606+copy_user_acl(struct gr_arg *arg)
59607+{
59608+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
59609+ struct acl_subject_label *subj_list;
59610+ struct sprole_pw *sptmp;
59611+ struct gr_hash_struct *ghash;
59612+ uid_t *domainlist;
59613+ unsigned int r_num;
59614+ unsigned int len;
59615+ char *tmp;
59616+ int err = 0;
59617+ __u16 i;
59618+ __u32 num_subjs;
59619+
59620+ /* we need a default and kernel role */
59621+ if (arg->role_db.num_roles < 2)
59622+ return -EINVAL;
59623+
59624+ /* copy special role authentication info from userspace */
59625+
59626+ num_sprole_pws = arg->num_sprole_pws;
59627+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
59628+
59629+ if (!acl_special_roles && num_sprole_pws)
59630+ return -ENOMEM;
59631+
59632+ for (i = 0; i < num_sprole_pws; i++) {
59633+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
59634+ if (!sptmp)
59635+ return -ENOMEM;
59636+ if (copy_from_user(sptmp, arg->sprole_pws + i,
59637+ sizeof (struct sprole_pw)))
59638+ return -EFAULT;
59639+
59640+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
59641+
59642+ if (!len || len >= GR_SPROLE_LEN)
59643+ return -EINVAL;
59644+
59645+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59646+ return -ENOMEM;
59647+
59648+ if (copy_from_user(tmp, sptmp->rolename, len))
59649+ return -EFAULT;
59650+
59651+ tmp[len-1] = '\0';
59652+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59653+ printk(KERN_ALERT "Copying special role %s\n", tmp);
59654+#endif
59655+ sptmp->rolename = tmp;
59656+ acl_special_roles[i] = sptmp;
59657+ }
59658+
59659+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
59660+
59661+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
59662+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
59663+
59664+ if (!r_tmp)
59665+ return -ENOMEM;
59666+
59667+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
59668+ sizeof (struct acl_role_label *)))
59669+ return -EFAULT;
59670+
59671+ if (copy_from_user(r_tmp, r_utmp2,
59672+ sizeof (struct acl_role_label)))
59673+ return -EFAULT;
59674+
59675+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
59676+
59677+ if (!len || len >= PATH_MAX)
59678+ return -EINVAL;
59679+
59680+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59681+ return -ENOMEM;
59682+
59683+ if (copy_from_user(tmp, r_tmp->rolename, len))
59684+ return -EFAULT;
59685+
59686+ tmp[len-1] = '\0';
59687+ r_tmp->rolename = tmp;
59688+
59689+ if (!strcmp(r_tmp->rolename, "default")
59690+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
59691+ default_role = r_tmp;
59692+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
59693+ kernel_role = r_tmp;
59694+ }
59695+
59696+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
59697+ return -ENOMEM;
59698+
59699+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
59700+ return -EFAULT;
59701+
59702+ r_tmp->hash = ghash;
59703+
59704+ num_subjs = count_user_subjs(r_tmp->hash->first);
59705+
59706+ r_tmp->subj_hash_size = num_subjs;
59707+ r_tmp->subj_hash =
59708+ (struct acl_subject_label **)
59709+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
59710+
59711+ if (!r_tmp->subj_hash)
59712+ return -ENOMEM;
59713+
59714+ err = copy_user_allowedips(r_tmp);
59715+ if (err)
59716+ return err;
59717+
59718+ /* copy domain info */
59719+ if (r_tmp->domain_children != NULL) {
59720+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
59721+ if (domainlist == NULL)
59722+ return -ENOMEM;
59723+
59724+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
59725+ return -EFAULT;
59726+
59727+ r_tmp->domain_children = domainlist;
59728+ }
59729+
59730+ err = copy_user_transitions(r_tmp);
59731+ if (err)
59732+ return err;
59733+
59734+ memset(r_tmp->subj_hash, 0,
59735+ r_tmp->subj_hash_size *
59736+ sizeof (struct acl_subject_label *));
59737+
59738+ /* acquire the list of subjects, then NULL out
59739+ the list prior to parsing the subjects for this role,
59740+ as during this parsing the list is replaced with a list
59741+ of *nested* subjects for the role
59742+ */
59743+ subj_list = r_tmp->hash->first;
59744+
59745+ /* set nested subject list to null */
59746+ r_tmp->hash->first = NULL;
59747+
59748+ err = copy_user_subjs(subj_list, r_tmp);
59749+
59750+ if (err)
59751+ return err;
59752+
59753+ insert_acl_role_label(r_tmp);
59754+ }
59755+
59756+ if (default_role == NULL || kernel_role == NULL)
59757+ return -EINVAL;
59758+
59759+ return err;
59760+}
59761+
59762+static int
59763+gracl_init(struct gr_arg *args)
59764+{
59765+ int error = 0;
59766+
59767+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
59768+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
59769+
59770+ if (init_variables(args)) {
59771+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
59772+ error = -ENOMEM;
59773+ free_variables();
59774+ goto out;
59775+ }
59776+
59777+ error = copy_user_acl(args);
59778+ free_init_variables();
59779+ if (error) {
59780+ free_variables();
59781+ goto out;
59782+ }
59783+
59784+ if ((error = gr_set_acls(0))) {
59785+ free_variables();
59786+ goto out;
59787+ }
59788+
59789+ pax_open_kernel();
59790+ gr_status |= GR_READY;
59791+ pax_close_kernel();
59792+
59793+ out:
59794+ return error;
59795+}
59796+
59797+/* derived from glibc fnmatch() 0: match, 1: no match*/
59798+
59799+static int
59800+glob_match(const char *p, const char *n)
59801+{
59802+ char c;
59803+
59804+ while ((c = *p++) != '\0') {
59805+ switch (c) {
59806+ case '?':
59807+ if (*n == '\0')
59808+ return 1;
59809+ else if (*n == '/')
59810+ return 1;
59811+ break;
59812+ case '\\':
59813+ if (*n != c)
59814+ return 1;
59815+ break;
59816+ case '*':
59817+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
59818+ if (*n == '/')
59819+ return 1;
59820+ else if (c == '?') {
59821+ if (*n == '\0')
59822+ return 1;
59823+ else
59824+ ++n;
59825+ }
59826+ }
59827+ if (c == '\0') {
59828+ return 0;
59829+ } else {
59830+ const char *endp;
59831+
59832+ if ((endp = strchr(n, '/')) == NULL)
59833+ endp = n + strlen(n);
59834+
59835+ if (c == '[') {
59836+ for (--p; n < endp; ++n)
59837+ if (!glob_match(p, n))
59838+ return 0;
59839+ } else if (c == '/') {
59840+ while (*n != '\0' && *n != '/')
59841+ ++n;
59842+ if (*n == '/' && !glob_match(p, n + 1))
59843+ return 0;
59844+ } else {
59845+ for (--p; n < endp; ++n)
59846+ if (*n == c && !glob_match(p, n))
59847+ return 0;
59848+ }
59849+
59850+ return 1;
59851+ }
59852+ case '[':
59853+ {
59854+ int not;
59855+ char cold;
59856+
59857+ if (*n == '\0' || *n == '/')
59858+ return 1;
59859+
59860+ not = (*p == '!' || *p == '^');
59861+ if (not)
59862+ ++p;
59863+
59864+ c = *p++;
59865+ for (;;) {
59866+ unsigned char fn = (unsigned char)*n;
59867+
59868+ if (c == '\0')
59869+ return 1;
59870+ else {
59871+ if (c == fn)
59872+ goto matched;
59873+ cold = c;
59874+ c = *p++;
59875+
59876+ if (c == '-' && *p != ']') {
59877+ unsigned char cend = *p++;
59878+
59879+ if (cend == '\0')
59880+ return 1;
59881+
59882+ if (cold <= fn && fn <= cend)
59883+ goto matched;
59884+
59885+ c = *p++;
59886+ }
59887+ }
59888+
59889+ if (c == ']')
59890+ break;
59891+ }
59892+ if (!not)
59893+ return 1;
59894+ break;
59895+ matched:
59896+ while (c != ']') {
59897+ if (c == '\0')
59898+ return 1;
59899+
59900+ c = *p++;
59901+ }
59902+ if (not)
59903+ return 1;
59904+ }
59905+ break;
59906+ default:
59907+ if (c != *n)
59908+ return 1;
59909+ }
59910+
59911+ ++n;
59912+ }
59913+
59914+ if (*n == '\0')
59915+ return 0;
59916+
59917+ if (*n == '/')
59918+ return 0;
59919+
59920+ return 1;
59921+}
59922+
59923+static struct acl_object_label *
59924+chk_glob_label(struct acl_object_label *globbed,
59925+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
59926+{
59927+ struct acl_object_label *tmp;
59928+
59929+ if (*path == NULL)
59930+ *path = gr_to_filename_nolock(dentry, mnt);
59931+
59932+ tmp = globbed;
59933+
59934+ while (tmp) {
59935+ if (!glob_match(tmp->filename, *path))
59936+ return tmp;
59937+ tmp = tmp->next;
59938+ }
59939+
59940+ return NULL;
59941+}
59942+
59943+static struct acl_object_label *
59944+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
59945+ const ino_t curr_ino, const dev_t curr_dev,
59946+ const struct acl_subject_label *subj, char **path, const int checkglob)
59947+{
59948+ struct acl_subject_label *tmpsubj;
59949+ struct acl_object_label *retval;
59950+ struct acl_object_label *retval2;
59951+
59952+ tmpsubj = (struct acl_subject_label *) subj;
59953+ read_lock(&gr_inode_lock);
59954+ do {
59955+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
59956+ if (retval) {
59957+ if (checkglob && retval->globbed) {
59958+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
59959+ if (retval2)
59960+ retval = retval2;
59961+ }
59962+ break;
59963+ }
59964+ } while ((tmpsubj = tmpsubj->parent_subject));
59965+ read_unlock(&gr_inode_lock);
59966+
59967+ return retval;
59968+}
59969+
59970+static __inline__ struct acl_object_label *
59971+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
59972+ struct dentry *curr_dentry,
59973+ const struct acl_subject_label *subj, char **path, const int checkglob)
59974+{
59975+ int newglob = checkglob;
59976+ ino_t inode;
59977+ dev_t device;
59978+
59979+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
59980+ as we don't want a / * rule to match instead of the / object
59981+ don't do this for create lookups that call this function though, since they're looking up
59982+ on the parent and thus need globbing checks on all paths
59983+ */
59984+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
59985+ newglob = GR_NO_GLOB;
59986+
59987+ spin_lock(&curr_dentry->d_lock);
59988+ inode = curr_dentry->d_inode->i_ino;
59989+ device = __get_dev(curr_dentry);
59990+ spin_unlock(&curr_dentry->d_lock);
59991+
59992+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
59993+}
59994+
59995+#ifdef CONFIG_HUGETLBFS
59996+static inline bool
59997+is_hugetlbfs_mnt(const struct vfsmount *mnt)
59998+{
59999+ int i;
60000+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
60001+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
60002+ return true;
60003+ }
60004+
60005+ return false;
60006+}
60007+#endif
60008+
60009+static struct acl_object_label *
60010+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60011+ const struct acl_subject_label *subj, char *path, const int checkglob)
60012+{
60013+ struct dentry *dentry = (struct dentry *) l_dentry;
60014+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
60015+ struct mount *real_mnt = real_mount(mnt);
60016+ struct acl_object_label *retval;
60017+ struct dentry *parent;
60018+
60019+ br_read_lock(&vfsmount_lock);
60020+ write_seqlock(&rename_lock);
60021+
60022+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
60023+#ifdef CONFIG_NET
60024+ mnt == sock_mnt ||
60025+#endif
60026+#ifdef CONFIG_HUGETLBFS
60027+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
60028+#endif
60029+ /* ignore Eric Biederman */
60030+ IS_PRIVATE(l_dentry->d_inode))) {
60031+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
60032+ goto out;
60033+ }
60034+
60035+ for (;;) {
60036+ if (dentry == real_root.dentry && mnt == real_root.mnt)
60037+ break;
60038+
60039+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
60040+ if (!mnt_has_parent(real_mnt))
60041+ break;
60042+
60043+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
60044+ if (retval != NULL)
60045+ goto out;
60046+
60047+ dentry = real_mnt->mnt_mountpoint;
60048+ real_mnt = real_mnt->mnt_parent;
60049+ mnt = &real_mnt->mnt;
60050+ continue;
60051+ }
60052+
60053+ parent = dentry->d_parent;
60054+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
60055+ if (retval != NULL)
60056+ goto out;
60057+
60058+ dentry = parent;
60059+ }
60060+
60061+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
60062+
60063+ /* real_root is pinned so we don't have to hold a reference */
60064+ if (retval == NULL)
60065+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
60066+out:
60067+ write_sequnlock(&rename_lock);
60068+ br_read_unlock(&vfsmount_lock);
60069+
60070+ BUG_ON(retval == NULL);
60071+
60072+ return retval;
60073+}
60074+
60075+static __inline__ struct acl_object_label *
60076+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60077+ const struct acl_subject_label *subj)
60078+{
60079+ char *path = NULL;
60080+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
60081+}
60082+
60083+static __inline__ struct acl_object_label *
60084+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60085+ const struct acl_subject_label *subj)
60086+{
60087+ char *path = NULL;
60088+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
60089+}
60090+
60091+static __inline__ struct acl_object_label *
60092+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60093+ const struct acl_subject_label *subj, char *path)
60094+{
60095+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
60096+}
60097+
60098+static struct acl_subject_label *
60099+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60100+ const struct acl_role_label *role)
60101+{
60102+ struct dentry *dentry = (struct dentry *) l_dentry;
60103+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
60104+ struct mount *real_mnt = real_mount(mnt);
60105+ struct acl_subject_label *retval;
60106+ struct dentry *parent;
60107+
60108+ br_read_lock(&vfsmount_lock);
60109+ write_seqlock(&rename_lock);
60110+
60111+ for (;;) {
60112+ if (dentry == real_root.dentry && mnt == real_root.mnt)
60113+ break;
60114+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
60115+ if (!mnt_has_parent(real_mnt))
60116+ break;
60117+
60118+ spin_lock(&dentry->d_lock);
60119+ read_lock(&gr_inode_lock);
60120+ retval =
60121+ lookup_acl_subj_label(dentry->d_inode->i_ino,
60122+ __get_dev(dentry), role);
60123+ read_unlock(&gr_inode_lock);
60124+ spin_unlock(&dentry->d_lock);
60125+ if (retval != NULL)
60126+ goto out;
60127+
60128+ dentry = real_mnt->mnt_mountpoint;
60129+ real_mnt = real_mnt->mnt_parent;
60130+ mnt = &real_mnt->mnt;
60131+ continue;
60132+ }
60133+
60134+ spin_lock(&dentry->d_lock);
60135+ read_lock(&gr_inode_lock);
60136+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
60137+ __get_dev(dentry), role);
60138+ read_unlock(&gr_inode_lock);
60139+ parent = dentry->d_parent;
60140+ spin_unlock(&dentry->d_lock);
60141+
60142+ if (retval != NULL)
60143+ goto out;
60144+
60145+ dentry = parent;
60146+ }
60147+
60148+ spin_lock(&dentry->d_lock);
60149+ read_lock(&gr_inode_lock);
60150+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
60151+ __get_dev(dentry), role);
60152+ read_unlock(&gr_inode_lock);
60153+ spin_unlock(&dentry->d_lock);
60154+
60155+ if (unlikely(retval == NULL)) {
60156+ /* real_root is pinned, we don't need to hold a reference */
60157+ read_lock(&gr_inode_lock);
60158+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
60159+ __get_dev(real_root.dentry), role);
60160+ read_unlock(&gr_inode_lock);
60161+ }
60162+out:
60163+ write_sequnlock(&rename_lock);
60164+ br_read_unlock(&vfsmount_lock);
60165+
60166+ BUG_ON(retval == NULL);
60167+
60168+ return retval;
60169+}
60170+
60171+static void
60172+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
60173+{
60174+ struct task_struct *task = current;
60175+ const struct cred *cred = current_cred();
60176+
60177+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
60178+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
60179+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
60180+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
60181+
60182+ return;
60183+}
60184+
60185+static void
60186+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
60187+{
60188+ struct task_struct *task = current;
60189+ const struct cred *cred = current_cred();
60190+
60191+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
60192+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
60193+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
60194+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
60195+
60196+ return;
60197+}
60198+
60199+static void
60200+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
60201+{
60202+ struct task_struct *task = current;
60203+ const struct cred *cred = current_cred();
60204+
60205+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
60206+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
60207+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
60208+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
60209+
60210+ return;
60211+}
60212+
60213+__u32
60214+gr_search_file(const struct dentry * dentry, const __u32 mode,
60215+ const struct vfsmount * mnt)
60216+{
60217+ __u32 retval = mode;
60218+ struct acl_subject_label *curracl;
60219+ struct acl_object_label *currobj;
60220+
60221+ if (unlikely(!(gr_status & GR_READY)))
60222+ return (mode & ~GR_AUDITS);
60223+
60224+ curracl = current->acl;
60225+
60226+ currobj = chk_obj_label(dentry, mnt, curracl);
60227+ retval = currobj->mode & mode;
60228+
60229+ /* if we're opening a specified transfer file for writing
60230+ (e.g. /dev/initctl), then transfer our role to init
60231+ */
60232+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
60233+ current->role->roletype & GR_ROLE_PERSIST)) {
60234+ struct task_struct *task = init_pid_ns.child_reaper;
60235+
60236+ if (task->role != current->role) {
60237+ task->acl_sp_role = 0;
60238+ task->acl_role_id = current->acl_role_id;
60239+ task->role = current->role;
60240+ rcu_read_lock();
60241+ read_lock(&grsec_exec_file_lock);
60242+ gr_apply_subject_to_task(task);
60243+ read_unlock(&grsec_exec_file_lock);
60244+ rcu_read_unlock();
60245+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
60246+ }
60247+ }
60248+
60249+ if (unlikely
60250+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
60251+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
60252+ __u32 new_mode = mode;
60253+
60254+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
60255+
60256+ retval = new_mode;
60257+
60258+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
60259+ new_mode |= GR_INHERIT;
60260+
60261+ if (!(mode & GR_NOLEARN))
60262+ gr_log_learn(dentry, mnt, new_mode);
60263+ }
60264+
60265+ return retval;
60266+}
60267+
60268+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
60269+ const struct dentry *parent,
60270+ const struct vfsmount *mnt)
60271+{
60272+ struct name_entry *match;
60273+ struct acl_object_label *matchpo;
60274+ struct acl_subject_label *curracl;
60275+ char *path;
60276+
60277+ if (unlikely(!(gr_status & GR_READY)))
60278+ return NULL;
60279+
60280+ preempt_disable();
60281+ path = gr_to_filename_rbac(new_dentry, mnt);
60282+ match = lookup_name_entry_create(path);
60283+
60284+ curracl = current->acl;
60285+
60286+ if (match) {
60287+ read_lock(&gr_inode_lock);
60288+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
60289+ read_unlock(&gr_inode_lock);
60290+
60291+ if (matchpo) {
60292+ preempt_enable();
60293+ return matchpo;
60294+ }
60295+ }
60296+
60297+ // lookup parent
60298+
60299+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
60300+
60301+ preempt_enable();
60302+ return matchpo;
60303+}
60304+
60305+__u32
60306+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
60307+ const struct vfsmount * mnt, const __u32 mode)
60308+{
60309+ struct acl_object_label *matchpo;
60310+ __u32 retval;
60311+
60312+ if (unlikely(!(gr_status & GR_READY)))
60313+ return (mode & ~GR_AUDITS);
60314+
60315+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
60316+
60317+ retval = matchpo->mode & mode;
60318+
60319+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
60320+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
60321+ __u32 new_mode = mode;
60322+
60323+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
60324+
60325+ gr_log_learn(new_dentry, mnt, new_mode);
60326+ return new_mode;
60327+ }
60328+
60329+ return retval;
60330+}
60331+
60332+__u32
60333+gr_check_link(const struct dentry * new_dentry,
60334+ const struct dentry * parent_dentry,
60335+ const struct vfsmount * parent_mnt,
60336+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
60337+{
60338+ struct acl_object_label *obj;
60339+ __u32 oldmode, newmode;
60340+ __u32 needmode;
60341+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
60342+ GR_DELETE | GR_INHERIT;
60343+
60344+ if (unlikely(!(gr_status & GR_READY)))
60345+ return (GR_CREATE | GR_LINK);
60346+
60347+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
60348+ oldmode = obj->mode;
60349+
60350+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
60351+ newmode = obj->mode;
60352+
60353+ needmode = newmode & checkmodes;
60354+
60355+ // old name for hardlink must have at least the permissions of the new name
60356+ if ((oldmode & needmode) != needmode)
60357+ goto bad;
60358+
60359+ // if old name had restrictions/auditing, make sure the new name does as well
60360+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
60361+
60362+ // don't allow hardlinking of suid/sgid/fcapped files without permission
60363+ if (is_privileged_binary(old_dentry))
60364+ needmode |= GR_SETID;
60365+
60366+ if ((newmode & needmode) != needmode)
60367+ goto bad;
60368+
60369+ // enforce minimum permissions
60370+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
60371+ return newmode;
60372+bad:
60373+ needmode = oldmode;
60374+ if (is_privileged_binary(old_dentry))
60375+ needmode |= GR_SETID;
60376+
60377+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
60378+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
60379+ return (GR_CREATE | GR_LINK);
60380+ } else if (newmode & GR_SUPPRESS)
60381+ return GR_SUPPRESS;
60382+ else
60383+ return 0;
60384+}
60385+
60386+int
60387+gr_check_hidden_task(const struct task_struct *task)
60388+{
60389+ if (unlikely(!(gr_status & GR_READY)))
60390+ return 0;
60391+
60392+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
60393+ return 1;
60394+
60395+ return 0;
60396+}
60397+
60398+int
60399+gr_check_protected_task(const struct task_struct *task)
60400+{
60401+ if (unlikely(!(gr_status & GR_READY) || !task))
60402+ return 0;
60403+
60404+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
60405+ task->acl != current->acl)
60406+ return 1;
60407+
60408+ return 0;
60409+}
60410+
60411+int
60412+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
60413+{
60414+ struct task_struct *p;
60415+ int ret = 0;
60416+
60417+ if (unlikely(!(gr_status & GR_READY) || !pid))
60418+ return ret;
60419+
60420+ read_lock(&tasklist_lock);
60421+ do_each_pid_task(pid, type, p) {
60422+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
60423+ p->acl != current->acl) {
60424+ ret = 1;
60425+ goto out;
60426+ }
60427+ } while_each_pid_task(pid, type, p);
60428+out:
60429+ read_unlock(&tasklist_lock);
60430+
60431+ return ret;
60432+}
60433+
60434+void
60435+gr_copy_label(struct task_struct *tsk)
60436+{
60437+ tsk->signal->used_accept = 0;
60438+ tsk->acl_sp_role = 0;
60439+ tsk->acl_role_id = current->acl_role_id;
60440+ tsk->acl = current->acl;
60441+ tsk->role = current->role;
60442+ tsk->signal->curr_ip = current->signal->curr_ip;
60443+ tsk->signal->saved_ip = current->signal->saved_ip;
60444+ if (current->exec_file)
60445+ get_file(current->exec_file);
60446+ tsk->exec_file = current->exec_file;
60447+ tsk->is_writable = current->is_writable;
60448+ if (unlikely(current->signal->used_accept)) {
60449+ current->signal->curr_ip = 0;
60450+ current->signal->saved_ip = 0;
60451+ }
60452+
60453+ return;
60454+}
60455+
60456+static void
60457+gr_set_proc_res(struct task_struct *task)
60458+{
60459+ struct acl_subject_label *proc;
60460+ unsigned short i;
60461+
60462+ proc = task->acl;
60463+
60464+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
60465+ return;
60466+
60467+ for (i = 0; i < RLIM_NLIMITS; i++) {
60468+ if (!(proc->resmask & (1U << i)))
60469+ continue;
60470+
60471+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
60472+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
60473+
60474+ if (i == RLIMIT_CPU)
60475+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
60476+ }
60477+
60478+ return;
60479+}
60480+
60481+extern int __gr_process_user_ban(struct user_struct *user);
60482+
60483+int
60484+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
60485+{
60486+ unsigned int i;
60487+ __u16 num;
60488+ uid_t *uidlist;
60489+ uid_t curuid;
60490+ int realok = 0;
60491+ int effectiveok = 0;
60492+ int fsok = 0;
60493+ uid_t globalreal, globaleffective, globalfs;
60494+
60495+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
60496+ struct user_struct *user;
60497+
60498+ if (!uid_valid(real))
60499+ goto skipit;
60500+
60501+ /* find user based on global namespace */
60502+
60503+ globalreal = GR_GLOBAL_UID(real);
60504+
60505+ user = find_user(make_kuid(&init_user_ns, globalreal));
60506+ if (user == NULL)
60507+ goto skipit;
60508+
60509+ if (__gr_process_user_ban(user)) {
60510+ /* for find_user */
60511+ free_uid(user);
60512+ return 1;
60513+ }
60514+
60515+ /* for find_user */
60516+ free_uid(user);
60517+
60518+skipit:
60519+#endif
60520+
60521+ if (unlikely(!(gr_status & GR_READY)))
60522+ return 0;
60523+
60524+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
60525+ gr_log_learn_uid_change(real, effective, fs);
60526+
60527+ num = current->acl->user_trans_num;
60528+ uidlist = current->acl->user_transitions;
60529+
60530+ if (uidlist == NULL)
60531+ return 0;
60532+
60533+ if (!uid_valid(real)) {
60534+ realok = 1;
60535+ globalreal = (uid_t)-1;
60536+ } else {
60537+ globalreal = GR_GLOBAL_UID(real);
60538+ }
60539+ if (!uid_valid(effective)) {
60540+ effectiveok = 1;
60541+ globaleffective = (uid_t)-1;
60542+ } else {
60543+ globaleffective = GR_GLOBAL_UID(effective);
60544+ }
60545+ if (!uid_valid(fs)) {
60546+ fsok = 1;
60547+ globalfs = (uid_t)-1;
60548+ } else {
60549+ globalfs = GR_GLOBAL_UID(fs);
60550+ }
60551+
60552+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
60553+ for (i = 0; i < num; i++) {
60554+ curuid = uidlist[i];
60555+ if (globalreal == curuid)
60556+ realok = 1;
60557+ if (globaleffective == curuid)
60558+ effectiveok = 1;
60559+ if (globalfs == curuid)
60560+ fsok = 1;
60561+ }
60562+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
60563+ for (i = 0; i < num; i++) {
60564+ curuid = uidlist[i];
60565+ if (globalreal == curuid)
60566+ break;
60567+ if (globaleffective == curuid)
60568+ break;
60569+ if (globalfs == curuid)
60570+ break;
60571+ }
60572+ /* not in deny list */
60573+ if (i == num) {
60574+ realok = 1;
60575+ effectiveok = 1;
60576+ fsok = 1;
60577+ }
60578+ }
60579+
60580+ if (realok && effectiveok && fsok)
60581+ return 0;
60582+ else {
60583+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
60584+ return 1;
60585+ }
60586+}
60587+
60588+int
60589+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
60590+{
60591+ unsigned int i;
60592+ __u16 num;
60593+ gid_t *gidlist;
60594+ gid_t curgid;
60595+ int realok = 0;
60596+ int effectiveok = 0;
60597+ int fsok = 0;
60598+ gid_t globalreal, globaleffective, globalfs;
60599+
60600+ if (unlikely(!(gr_status & GR_READY)))
60601+ return 0;
60602+
60603+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
60604+ gr_log_learn_gid_change(real, effective, fs);
60605+
60606+ num = current->acl->group_trans_num;
60607+ gidlist = current->acl->group_transitions;
60608+
60609+ if (gidlist == NULL)
60610+ return 0;
60611+
60612+ if (!gid_valid(real)) {
60613+ realok = 1;
60614+ globalreal = (gid_t)-1;
60615+ } else {
60616+ globalreal = GR_GLOBAL_GID(real);
60617+ }
60618+ if (!gid_valid(effective)) {
60619+ effectiveok = 1;
60620+ globaleffective = (gid_t)-1;
60621+ } else {
60622+ globaleffective = GR_GLOBAL_GID(effective);
60623+ }
60624+ if (!gid_valid(fs)) {
60625+ fsok = 1;
60626+ globalfs = (gid_t)-1;
60627+ } else {
60628+ globalfs = GR_GLOBAL_GID(fs);
60629+ }
60630+
60631+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
60632+ for (i = 0; i < num; i++) {
60633+ curgid = gidlist[i];
60634+ if (globalreal == curgid)
60635+ realok = 1;
60636+ if (globaleffective == curgid)
60637+ effectiveok = 1;
60638+ if (globalfs == curgid)
60639+ fsok = 1;
60640+ }
60641+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
60642+ for (i = 0; i < num; i++) {
60643+ curgid = gidlist[i];
60644+ if (globalreal == curgid)
60645+ break;
60646+ if (globaleffective == curgid)
60647+ break;
60648+ if (globalfs == curgid)
60649+ break;
60650+ }
60651+ /* not in deny list */
60652+ if (i == num) {
60653+ realok = 1;
60654+ effectiveok = 1;
60655+ fsok = 1;
60656+ }
60657+ }
60658+
60659+ if (realok && effectiveok && fsok)
60660+ return 0;
60661+ else {
60662+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
60663+ return 1;
60664+ }
60665+}
60666+
60667+extern int gr_acl_is_capable(const int cap);
60668+
60669+void
60670+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
60671+{
60672+ struct acl_role_label *role = task->role;
60673+ struct acl_subject_label *subj = NULL;
60674+ struct acl_object_label *obj;
60675+ struct file *filp;
60676+ uid_t uid;
60677+ gid_t gid;
60678+
60679+ if (unlikely(!(gr_status & GR_READY)))
60680+ return;
60681+
60682+ uid = GR_GLOBAL_UID(kuid);
60683+ gid = GR_GLOBAL_GID(kgid);
60684+
60685+ filp = task->exec_file;
60686+
60687+ /* kernel process, we'll give them the kernel role */
60688+ if (unlikely(!filp)) {
60689+ task->role = kernel_role;
60690+ task->acl = kernel_role->root_label;
60691+ return;
60692+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
60693+ role = lookup_acl_role_label(task, uid, gid);
60694+
60695+ /* don't change the role if we're not a privileged process */
60696+ if (role && task->role != role &&
60697+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
60698+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
60699+ return;
60700+
60701+ /* perform subject lookup in possibly new role
60702+ we can use this result below in the case where role == task->role
60703+ */
60704+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
60705+
60706+ /* if we changed uid/gid, but result in the same role
60707+ and are using inheritance, don't lose the inherited subject
60708+ if current subject is other than what normal lookup
60709+ would result in, we arrived via inheritance, don't
60710+ lose subject
60711+ */
60712+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
60713+ (subj == task->acl)))
60714+ task->acl = subj;
60715+
60716+ task->role = role;
60717+
60718+ task->is_writable = 0;
60719+
60720+ /* ignore additional mmap checks for processes that are writable
60721+ by the default ACL */
60722+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
60723+ if (unlikely(obj->mode & GR_WRITE))
60724+ task->is_writable = 1;
60725+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
60726+ if (unlikely(obj->mode & GR_WRITE))
60727+ task->is_writable = 1;
60728+
60729+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60730+ 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);
60731+#endif
60732+
60733+ gr_set_proc_res(task);
60734+
60735+ return;
60736+}
60737+
60738+int
60739+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
60740+ const int unsafe_flags)
60741+{
60742+ struct task_struct *task = current;
60743+ struct acl_subject_label *newacl;
60744+ struct acl_object_label *obj;
60745+ __u32 retmode;
60746+
60747+ if (unlikely(!(gr_status & GR_READY)))
60748+ return 0;
60749+
60750+ newacl = chk_subj_label(dentry, mnt, task->role);
60751+
60752+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
60753+ did an exec
60754+ */
60755+ rcu_read_lock();
60756+ read_lock(&tasklist_lock);
60757+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
60758+ (task->parent->acl->mode & GR_POVERRIDE))) {
60759+ read_unlock(&tasklist_lock);
60760+ rcu_read_unlock();
60761+ goto skip_check;
60762+ }
60763+ read_unlock(&tasklist_lock);
60764+ rcu_read_unlock();
60765+
60766+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
60767+ !(task->role->roletype & GR_ROLE_GOD) &&
60768+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
60769+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
60770+ if (unsafe_flags & LSM_UNSAFE_SHARE)
60771+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
60772+ else
60773+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
60774+ return -EACCES;
60775+ }
60776+
60777+skip_check:
60778+
60779+ obj = chk_obj_label(dentry, mnt, task->acl);
60780+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
60781+
60782+ if (!(task->acl->mode & GR_INHERITLEARN) &&
60783+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
60784+ if (obj->nested)
60785+ task->acl = obj->nested;
60786+ else
60787+ task->acl = newacl;
60788+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
60789+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
60790+
60791+ task->is_writable = 0;
60792+
60793+ /* ignore additional mmap checks for processes that are writable
60794+ by the default ACL */
60795+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
60796+ if (unlikely(obj->mode & GR_WRITE))
60797+ task->is_writable = 1;
60798+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
60799+ if (unlikely(obj->mode & GR_WRITE))
60800+ task->is_writable = 1;
60801+
60802+ gr_set_proc_res(task);
60803+
60804+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60805+ 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);
60806+#endif
60807+ return 0;
60808+}
60809+
60810+/* always called with valid inodev ptr */
60811+static void
60812+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
60813+{
60814+ struct acl_object_label *matchpo;
60815+ struct acl_subject_label *matchps;
60816+ struct acl_subject_label *subj;
60817+ struct acl_role_label *role;
60818+ unsigned int x;
60819+
60820+ FOR_EACH_ROLE_START(role)
60821+ FOR_EACH_SUBJECT_START(role, subj, x)
60822+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
60823+ matchpo->mode |= GR_DELETED;
60824+ FOR_EACH_SUBJECT_END(subj,x)
60825+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
60826+ /* nested subjects aren't in the role's subj_hash table */
60827+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
60828+ matchpo->mode |= GR_DELETED;
60829+ FOR_EACH_NESTED_SUBJECT_END(subj)
60830+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
60831+ matchps->mode |= GR_DELETED;
60832+ FOR_EACH_ROLE_END(role)
60833+
60834+ inodev->nentry->deleted = 1;
60835+
60836+ return;
60837+}
60838+
60839+void
60840+gr_handle_delete(const ino_t ino, const dev_t dev)
60841+{
60842+ struct inodev_entry *inodev;
60843+
60844+ if (unlikely(!(gr_status & GR_READY)))
60845+ return;
60846+
60847+ write_lock(&gr_inode_lock);
60848+ inodev = lookup_inodev_entry(ino, dev);
60849+ if (inodev != NULL)
60850+ do_handle_delete(inodev, ino, dev);
60851+ write_unlock(&gr_inode_lock);
60852+
60853+ return;
60854+}
60855+
60856+static void
60857+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
60858+ const ino_t newinode, const dev_t newdevice,
60859+ struct acl_subject_label *subj)
60860+{
60861+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
60862+ struct acl_object_label *match;
60863+
60864+ match = subj->obj_hash[index];
60865+
60866+ while (match && (match->inode != oldinode ||
60867+ match->device != olddevice ||
60868+ !(match->mode & GR_DELETED)))
60869+ match = match->next;
60870+
60871+ if (match && (match->inode == oldinode)
60872+ && (match->device == olddevice)
60873+ && (match->mode & GR_DELETED)) {
60874+ if (match->prev == NULL) {
60875+ subj->obj_hash[index] = match->next;
60876+ if (match->next != NULL)
60877+ match->next->prev = NULL;
60878+ } else {
60879+ match->prev->next = match->next;
60880+ if (match->next != NULL)
60881+ match->next->prev = match->prev;
60882+ }
60883+ match->prev = NULL;
60884+ match->next = NULL;
60885+ match->inode = newinode;
60886+ match->device = newdevice;
60887+ match->mode &= ~GR_DELETED;
60888+
60889+ insert_acl_obj_label(match, subj);
60890+ }
60891+
60892+ return;
60893+}
60894+
60895+static void
60896+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
60897+ const ino_t newinode, const dev_t newdevice,
60898+ struct acl_role_label *role)
60899+{
60900+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
60901+ struct acl_subject_label *match;
60902+
60903+ match = role->subj_hash[index];
60904+
60905+ while (match && (match->inode != oldinode ||
60906+ match->device != olddevice ||
60907+ !(match->mode & GR_DELETED)))
60908+ match = match->next;
60909+
60910+ if (match && (match->inode == oldinode)
60911+ && (match->device == olddevice)
60912+ && (match->mode & GR_DELETED)) {
60913+ if (match->prev == NULL) {
60914+ role->subj_hash[index] = match->next;
60915+ if (match->next != NULL)
60916+ match->next->prev = NULL;
60917+ } else {
60918+ match->prev->next = match->next;
60919+ if (match->next != NULL)
60920+ match->next->prev = match->prev;
60921+ }
60922+ match->prev = NULL;
60923+ match->next = NULL;
60924+ match->inode = newinode;
60925+ match->device = newdevice;
60926+ match->mode &= ~GR_DELETED;
60927+
60928+ insert_acl_subj_label(match, role);
60929+ }
60930+
60931+ return;
60932+}
60933+
60934+static void
60935+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
60936+ const ino_t newinode, const dev_t newdevice)
60937+{
60938+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
60939+ struct inodev_entry *match;
60940+
60941+ match = inodev_set.i_hash[index];
60942+
60943+ while (match && (match->nentry->inode != oldinode ||
60944+ match->nentry->device != olddevice || !match->nentry->deleted))
60945+ match = match->next;
60946+
60947+ if (match && (match->nentry->inode == oldinode)
60948+ && (match->nentry->device == olddevice) &&
60949+ match->nentry->deleted) {
60950+ if (match->prev == NULL) {
60951+ inodev_set.i_hash[index] = match->next;
60952+ if (match->next != NULL)
60953+ match->next->prev = NULL;
60954+ } else {
60955+ match->prev->next = match->next;
60956+ if (match->next != NULL)
60957+ match->next->prev = match->prev;
60958+ }
60959+ match->prev = NULL;
60960+ match->next = NULL;
60961+ match->nentry->inode = newinode;
60962+ match->nentry->device = newdevice;
60963+ match->nentry->deleted = 0;
60964+
60965+ insert_inodev_entry(match);
60966+ }
60967+
60968+ return;
60969+}
60970+
60971+static void
60972+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
60973+{
60974+ struct acl_subject_label *subj;
60975+ struct acl_role_label *role;
60976+ unsigned int x;
60977+
60978+ FOR_EACH_ROLE_START(role)
60979+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
60980+
60981+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
60982+ if ((subj->inode == ino) && (subj->device == dev)) {
60983+ subj->inode = ino;
60984+ subj->device = dev;
60985+ }
60986+ /* nested subjects aren't in the role's subj_hash table */
60987+ update_acl_obj_label(matchn->inode, matchn->device,
60988+ ino, dev, subj);
60989+ FOR_EACH_NESTED_SUBJECT_END(subj)
60990+ FOR_EACH_SUBJECT_START(role, subj, x)
60991+ update_acl_obj_label(matchn->inode, matchn->device,
60992+ ino, dev, subj);
60993+ FOR_EACH_SUBJECT_END(subj,x)
60994+ FOR_EACH_ROLE_END(role)
60995+
60996+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
60997+
60998+ return;
60999+}
61000+
61001+static void
61002+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
61003+ const struct vfsmount *mnt)
61004+{
61005+ ino_t ino = dentry->d_inode->i_ino;
61006+ dev_t dev = __get_dev(dentry);
61007+
61008+ __do_handle_create(matchn, ino, dev);
61009+
61010+ return;
61011+}
61012+
61013+void
61014+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
61015+{
61016+ struct name_entry *matchn;
61017+
61018+ if (unlikely(!(gr_status & GR_READY)))
61019+ return;
61020+
61021+ preempt_disable();
61022+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
61023+
61024+ if (unlikely((unsigned long)matchn)) {
61025+ write_lock(&gr_inode_lock);
61026+ do_handle_create(matchn, dentry, mnt);
61027+ write_unlock(&gr_inode_lock);
61028+ }
61029+ preempt_enable();
61030+
61031+ return;
61032+}
61033+
61034+void
61035+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
61036+{
61037+ struct name_entry *matchn;
61038+
61039+ if (unlikely(!(gr_status & GR_READY)))
61040+ return;
61041+
61042+ preempt_disable();
61043+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
61044+
61045+ if (unlikely((unsigned long)matchn)) {
61046+ write_lock(&gr_inode_lock);
61047+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
61048+ write_unlock(&gr_inode_lock);
61049+ }
61050+ preempt_enable();
61051+
61052+ return;
61053+}
61054+
61055+void
61056+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
61057+ struct dentry *old_dentry,
61058+ struct dentry *new_dentry,
61059+ struct vfsmount *mnt, const __u8 replace)
61060+{
61061+ struct name_entry *matchn;
61062+ struct inodev_entry *inodev;
61063+ struct inode *inode = new_dentry->d_inode;
61064+ ino_t old_ino = old_dentry->d_inode->i_ino;
61065+ dev_t old_dev = __get_dev(old_dentry);
61066+
61067+ /* vfs_rename swaps the name and parent link for old_dentry and
61068+ new_dentry
61069+ at this point, old_dentry has the new name, parent link, and inode
61070+ for the renamed file
61071+ if a file is being replaced by a rename, new_dentry has the inode
61072+ and name for the replaced file
61073+ */
61074+
61075+ if (unlikely(!(gr_status & GR_READY)))
61076+ return;
61077+
61078+ preempt_disable();
61079+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
61080+
61081+ /* we wouldn't have to check d_inode if it weren't for
61082+ NFS silly-renaming
61083+ */
61084+
61085+ write_lock(&gr_inode_lock);
61086+ if (unlikely(replace && inode)) {
61087+ ino_t new_ino = inode->i_ino;
61088+ dev_t new_dev = __get_dev(new_dentry);
61089+
61090+ inodev = lookup_inodev_entry(new_ino, new_dev);
61091+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
61092+ do_handle_delete(inodev, new_ino, new_dev);
61093+ }
61094+
61095+ inodev = lookup_inodev_entry(old_ino, old_dev);
61096+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
61097+ do_handle_delete(inodev, old_ino, old_dev);
61098+
61099+ if (unlikely((unsigned long)matchn))
61100+ do_handle_create(matchn, old_dentry, mnt);
61101+
61102+ write_unlock(&gr_inode_lock);
61103+ preempt_enable();
61104+
61105+ return;
61106+}
61107+
61108+static int
61109+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
61110+ unsigned char **sum)
61111+{
61112+ struct acl_role_label *r;
61113+ struct role_allowed_ip *ipp;
61114+ struct role_transition *trans;
61115+ unsigned int i;
61116+ int found = 0;
61117+ u32 curr_ip = current->signal->curr_ip;
61118+
61119+ current->signal->saved_ip = curr_ip;
61120+
61121+ /* check transition table */
61122+
61123+ for (trans = current->role->transitions; trans; trans = trans->next) {
61124+ if (!strcmp(rolename, trans->rolename)) {
61125+ found = 1;
61126+ break;
61127+ }
61128+ }
61129+
61130+ if (!found)
61131+ return 0;
61132+
61133+ /* handle special roles that do not require authentication
61134+ and check ip */
61135+
61136+ FOR_EACH_ROLE_START(r)
61137+ if (!strcmp(rolename, r->rolename) &&
61138+ (r->roletype & GR_ROLE_SPECIAL)) {
61139+ found = 0;
61140+ if (r->allowed_ips != NULL) {
61141+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
61142+ if ((ntohl(curr_ip) & ipp->netmask) ==
61143+ (ntohl(ipp->addr) & ipp->netmask))
61144+ found = 1;
61145+ }
61146+ } else
61147+ found = 2;
61148+ if (!found)
61149+ return 0;
61150+
61151+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
61152+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
61153+ *salt = NULL;
61154+ *sum = NULL;
61155+ return 1;
61156+ }
61157+ }
61158+ FOR_EACH_ROLE_END(r)
61159+
61160+ for (i = 0; i < num_sprole_pws; i++) {
61161+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
61162+ *salt = acl_special_roles[i]->salt;
61163+ *sum = acl_special_roles[i]->sum;
61164+ return 1;
61165+ }
61166+ }
61167+
61168+ return 0;
61169+}
61170+
61171+static void
61172+assign_special_role(char *rolename)
61173+{
61174+ struct acl_object_label *obj;
61175+ struct acl_role_label *r;
61176+ struct acl_role_label *assigned = NULL;
61177+ struct task_struct *tsk;
61178+ struct file *filp;
61179+
61180+ FOR_EACH_ROLE_START(r)
61181+ if (!strcmp(rolename, r->rolename) &&
61182+ (r->roletype & GR_ROLE_SPECIAL)) {
61183+ assigned = r;
61184+ break;
61185+ }
61186+ FOR_EACH_ROLE_END(r)
61187+
61188+ if (!assigned)
61189+ return;
61190+
61191+ read_lock(&tasklist_lock);
61192+ read_lock(&grsec_exec_file_lock);
61193+
61194+ tsk = current->real_parent;
61195+ if (tsk == NULL)
61196+ goto out_unlock;
61197+
61198+ filp = tsk->exec_file;
61199+ if (filp == NULL)
61200+ goto out_unlock;
61201+
61202+ tsk->is_writable = 0;
61203+
61204+ tsk->acl_sp_role = 1;
61205+ tsk->acl_role_id = ++acl_sp_role_value;
61206+ tsk->role = assigned;
61207+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
61208+
61209+ /* ignore additional mmap checks for processes that are writable
61210+ by the default ACL */
61211+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
61212+ if (unlikely(obj->mode & GR_WRITE))
61213+ tsk->is_writable = 1;
61214+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
61215+ if (unlikely(obj->mode & GR_WRITE))
61216+ tsk->is_writable = 1;
61217+
61218+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
61219+ 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));
61220+#endif
61221+
61222+out_unlock:
61223+ read_unlock(&grsec_exec_file_lock);
61224+ read_unlock(&tasklist_lock);
61225+ return;
61226+}
61227+
61228+int gr_check_secure_terminal(struct task_struct *task)
61229+{
61230+ struct task_struct *p, *p2, *p3;
61231+ struct files_struct *files;
61232+ struct fdtable *fdt;
61233+ struct file *our_file = NULL, *file;
61234+ int i;
61235+
61236+ if (task->signal->tty == NULL)
61237+ return 1;
61238+
61239+ files = get_files_struct(task);
61240+ if (files != NULL) {
61241+ rcu_read_lock();
61242+ fdt = files_fdtable(files);
61243+ for (i=0; i < fdt->max_fds; i++) {
61244+ file = fcheck_files(files, i);
61245+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
61246+ get_file(file);
61247+ our_file = file;
61248+ }
61249+ }
61250+ rcu_read_unlock();
61251+ put_files_struct(files);
61252+ }
61253+
61254+ if (our_file == NULL)
61255+ return 1;
61256+
61257+ read_lock(&tasklist_lock);
61258+ do_each_thread(p2, p) {
61259+ files = get_files_struct(p);
61260+ if (files == NULL ||
61261+ (p->signal && p->signal->tty == task->signal->tty)) {
61262+ if (files != NULL)
61263+ put_files_struct(files);
61264+ continue;
61265+ }
61266+ rcu_read_lock();
61267+ fdt = files_fdtable(files);
61268+ for (i=0; i < fdt->max_fds; i++) {
61269+ file = fcheck_files(files, i);
61270+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
61271+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
61272+ p3 = task;
61273+ while (task_pid_nr(p3) > 0) {
61274+ if (p3 == p)
61275+ break;
61276+ p3 = p3->real_parent;
61277+ }
61278+ if (p3 == p)
61279+ break;
61280+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
61281+ gr_handle_alertkill(p);
61282+ rcu_read_unlock();
61283+ put_files_struct(files);
61284+ read_unlock(&tasklist_lock);
61285+ fput(our_file);
61286+ return 0;
61287+ }
61288+ }
61289+ rcu_read_unlock();
61290+ put_files_struct(files);
61291+ } while_each_thread(p2, p);
61292+ read_unlock(&tasklist_lock);
61293+
61294+ fput(our_file);
61295+ return 1;
61296+}
61297+
61298+static int gr_rbac_disable(void *unused)
61299+{
61300+ pax_open_kernel();
61301+ gr_status &= ~GR_READY;
61302+ pax_close_kernel();
61303+
61304+ return 0;
61305+}
61306+
61307+ssize_t
61308+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
61309+{
61310+ struct gr_arg_wrapper uwrap;
61311+ unsigned char *sprole_salt = NULL;
61312+ unsigned char *sprole_sum = NULL;
61313+ int error = sizeof (struct gr_arg_wrapper);
61314+ int error2 = 0;
61315+
61316+ mutex_lock(&gr_dev_mutex);
61317+
61318+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
61319+ error = -EPERM;
61320+ goto out;
61321+ }
61322+
61323+ if (count != sizeof (struct gr_arg_wrapper)) {
61324+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
61325+ error = -EINVAL;
61326+ goto out;
61327+ }
61328+
61329+
61330+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
61331+ gr_auth_expires = 0;
61332+ gr_auth_attempts = 0;
61333+ }
61334+
61335+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
61336+ error = -EFAULT;
61337+ goto out;
61338+ }
61339+
61340+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
61341+ error = -EINVAL;
61342+ goto out;
61343+ }
61344+
61345+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
61346+ error = -EFAULT;
61347+ goto out;
61348+ }
61349+
61350+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
61351+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
61352+ time_after(gr_auth_expires, get_seconds())) {
61353+ error = -EBUSY;
61354+ goto out;
61355+ }
61356+
61357+ /* if non-root trying to do anything other than use a special role,
61358+ do not attempt authentication, do not count towards authentication
61359+ locking
61360+ */
61361+
61362+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
61363+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
61364+ gr_is_global_nonroot(current_uid())) {
61365+ error = -EPERM;
61366+ goto out;
61367+ }
61368+
61369+ /* ensure pw and special role name are null terminated */
61370+
61371+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
61372+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
61373+
61374+ /* Okay.
61375+ * We have our enough of the argument structure..(we have yet
61376+ * to copy_from_user the tables themselves) . Copy the tables
61377+ * only if we need them, i.e. for loading operations. */
61378+
61379+ switch (gr_usermode->mode) {
61380+ case GR_STATUS:
61381+ if (gr_status & GR_READY) {
61382+ error = 1;
61383+ if (!gr_check_secure_terminal(current))
61384+ error = 3;
61385+ } else
61386+ error = 2;
61387+ goto out;
61388+ case GR_SHUTDOWN:
61389+ if ((gr_status & GR_READY)
61390+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
61391+ stop_machine(gr_rbac_disable, NULL, NULL);
61392+ free_variables();
61393+ memset(gr_usermode, 0, sizeof (struct gr_arg));
61394+ memset(gr_system_salt, 0, GR_SALT_LEN);
61395+ memset(gr_system_sum, 0, GR_SHA_LEN);
61396+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
61397+ } else if (gr_status & GR_READY) {
61398+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
61399+ error = -EPERM;
61400+ } else {
61401+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
61402+ error = -EAGAIN;
61403+ }
61404+ break;
61405+ case GR_ENABLE:
61406+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
61407+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
61408+ else {
61409+ if (gr_status & GR_READY)
61410+ error = -EAGAIN;
61411+ else
61412+ error = error2;
61413+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
61414+ }
61415+ break;
61416+ case GR_RELOAD:
61417+ if (!(gr_status & GR_READY)) {
61418+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
61419+ error = -EAGAIN;
61420+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
61421+ stop_machine(gr_rbac_disable, NULL, NULL);
61422+ free_variables();
61423+ error2 = gracl_init(gr_usermode);
61424+ if (!error2)
61425+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
61426+ else {
61427+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
61428+ error = error2;
61429+ }
61430+ } else {
61431+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
61432+ error = -EPERM;
61433+ }
61434+ break;
61435+ case GR_SEGVMOD:
61436+ if (unlikely(!(gr_status & GR_READY))) {
61437+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
61438+ error = -EAGAIN;
61439+ break;
61440+ }
61441+
61442+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
61443+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
61444+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
61445+ struct acl_subject_label *segvacl;
61446+ segvacl =
61447+ lookup_acl_subj_label(gr_usermode->segv_inode,
61448+ gr_usermode->segv_device,
61449+ current->role);
61450+ if (segvacl) {
61451+ segvacl->crashes = 0;
61452+ segvacl->expires = 0;
61453+ }
61454+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
61455+ gr_remove_uid(gr_usermode->segv_uid);
61456+ }
61457+ } else {
61458+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
61459+ error = -EPERM;
61460+ }
61461+ break;
61462+ case GR_SPROLE:
61463+ case GR_SPROLEPAM:
61464+ if (unlikely(!(gr_status & GR_READY))) {
61465+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
61466+ error = -EAGAIN;
61467+ break;
61468+ }
61469+
61470+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
61471+ current->role->expires = 0;
61472+ current->role->auth_attempts = 0;
61473+ }
61474+
61475+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
61476+ time_after(current->role->expires, get_seconds())) {
61477+ error = -EBUSY;
61478+ goto out;
61479+ }
61480+
61481+ if (lookup_special_role_auth
61482+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
61483+ && ((!sprole_salt && !sprole_sum)
61484+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
61485+ char *p = "";
61486+ assign_special_role(gr_usermode->sp_role);
61487+ read_lock(&tasklist_lock);
61488+ if (current->real_parent)
61489+ p = current->real_parent->role->rolename;
61490+ read_unlock(&tasklist_lock);
61491+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
61492+ p, acl_sp_role_value);
61493+ } else {
61494+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
61495+ error = -EPERM;
61496+ if(!(current->role->auth_attempts++))
61497+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
61498+
61499+ goto out;
61500+ }
61501+ break;
61502+ case GR_UNSPROLE:
61503+ if (unlikely(!(gr_status & GR_READY))) {
61504+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
61505+ error = -EAGAIN;
61506+ break;
61507+ }
61508+
61509+ if (current->role->roletype & GR_ROLE_SPECIAL) {
61510+ char *p = "";
61511+ int i = 0;
61512+
61513+ read_lock(&tasklist_lock);
61514+ if (current->real_parent) {
61515+ p = current->real_parent->role->rolename;
61516+ i = current->real_parent->acl_role_id;
61517+ }
61518+ read_unlock(&tasklist_lock);
61519+
61520+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
61521+ gr_set_acls(1);
61522+ } else {
61523+ error = -EPERM;
61524+ goto out;
61525+ }
61526+ break;
61527+ default:
61528+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
61529+ error = -EINVAL;
61530+ break;
61531+ }
61532+
61533+ if (error != -EPERM)
61534+ goto out;
61535+
61536+ if(!(gr_auth_attempts++))
61537+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
61538+
61539+ out:
61540+ mutex_unlock(&gr_dev_mutex);
61541+ return error;
61542+}
61543+
61544+/* must be called with
61545+ rcu_read_lock();
61546+ read_lock(&tasklist_lock);
61547+ read_lock(&grsec_exec_file_lock);
61548+*/
61549+int gr_apply_subject_to_task(struct task_struct *task)
61550+{
61551+ struct acl_object_label *obj;
61552+ char *tmpname;
61553+ struct acl_subject_label *tmpsubj;
61554+ struct file *filp;
61555+ struct name_entry *nmatch;
61556+
61557+ filp = task->exec_file;
61558+ if (filp == NULL)
61559+ return 0;
61560+
61561+ /* the following is to apply the correct subject
61562+ on binaries running when the RBAC system
61563+ is enabled, when the binaries have been
61564+ replaced or deleted since their execution
61565+ -----
61566+ when the RBAC system starts, the inode/dev
61567+ from exec_file will be one the RBAC system
61568+ is unaware of. It only knows the inode/dev
61569+ of the present file on disk, or the absence
61570+ of it.
61571+ */
61572+ preempt_disable();
61573+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
61574+
61575+ nmatch = lookup_name_entry(tmpname);
61576+ preempt_enable();
61577+ tmpsubj = NULL;
61578+ if (nmatch) {
61579+ if (nmatch->deleted)
61580+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
61581+ else
61582+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
61583+ if (tmpsubj != NULL)
61584+ task->acl = tmpsubj;
61585+ }
61586+ if (tmpsubj == NULL)
61587+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
61588+ task->role);
61589+ if (task->acl) {
61590+ task->is_writable = 0;
61591+ /* ignore additional mmap checks for processes that are writable
61592+ by the default ACL */
61593+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
61594+ if (unlikely(obj->mode & GR_WRITE))
61595+ task->is_writable = 1;
61596+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
61597+ if (unlikely(obj->mode & GR_WRITE))
61598+ task->is_writable = 1;
61599+
61600+ gr_set_proc_res(task);
61601+
61602+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
61603+ 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);
61604+#endif
61605+ } else {
61606+ return 1;
61607+ }
61608+
61609+ return 0;
61610+}
61611+
61612+int
61613+gr_set_acls(const int type)
61614+{
61615+ struct task_struct *task, *task2;
61616+ struct acl_role_label *role = current->role;
61617+ __u16 acl_role_id = current->acl_role_id;
61618+ const struct cred *cred;
61619+ int ret;
61620+
61621+ rcu_read_lock();
61622+ read_lock(&tasklist_lock);
61623+ read_lock(&grsec_exec_file_lock);
61624+ do_each_thread(task2, task) {
61625+ /* check to see if we're called from the exit handler,
61626+ if so, only replace ACLs that have inherited the admin
61627+ ACL */
61628+
61629+ if (type && (task->role != role ||
61630+ task->acl_role_id != acl_role_id))
61631+ continue;
61632+
61633+ task->acl_role_id = 0;
61634+ task->acl_sp_role = 0;
61635+
61636+ if (task->exec_file) {
61637+ cred = __task_cred(task);
61638+ task->role = lookup_acl_role_label(task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
61639+ ret = gr_apply_subject_to_task(task);
61640+ if (ret) {
61641+ read_unlock(&grsec_exec_file_lock);
61642+ read_unlock(&tasklist_lock);
61643+ rcu_read_unlock();
61644+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
61645+ return ret;
61646+ }
61647+ } else {
61648+ // it's a kernel process
61649+ task->role = kernel_role;
61650+ task->acl = kernel_role->root_label;
61651+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
61652+ task->acl->mode &= ~GR_PROCFIND;
61653+#endif
61654+ }
61655+ } while_each_thread(task2, task);
61656+ read_unlock(&grsec_exec_file_lock);
61657+ read_unlock(&tasklist_lock);
61658+ rcu_read_unlock();
61659+
61660+ return 0;
61661+}
61662+
61663+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
61664+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
61665+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
61666+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
61667+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
61668+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
61669+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
61670+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
61671+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
61672+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
61673+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
61674+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
61675+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
61676+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
61677+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
61678+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
61679+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
61680+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
61681+};
61682+
61683+void
61684+gr_learn_resource(const struct task_struct *task,
61685+ const int res, const unsigned long wanted, const int gt)
61686+{
61687+ struct acl_subject_label *acl;
61688+ const struct cred *cred;
61689+
61690+ if (unlikely((gr_status & GR_READY) &&
61691+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
61692+ goto skip_reslog;
61693+
61694+ gr_log_resource(task, res, wanted, gt);
61695+skip_reslog:
61696+
61697+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
61698+ return;
61699+
61700+ acl = task->acl;
61701+
61702+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
61703+ !(acl->resmask & (1U << (unsigned short) res))))
61704+ return;
61705+
61706+ if (wanted >= acl->res[res].rlim_cur) {
61707+ unsigned long res_add;
61708+
61709+ res_add = wanted + res_learn_bumps[res];
61710+
61711+ acl->res[res].rlim_cur = res_add;
61712+
61713+ if (wanted > acl->res[res].rlim_max)
61714+ acl->res[res].rlim_max = res_add;
61715+
61716+ /* only log the subject filename, since resource logging is supported for
61717+ single-subject learning only */
61718+ rcu_read_lock();
61719+ cred = __task_cred(task);
61720+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
61721+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
61722+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
61723+ "", (unsigned long) res, &task->signal->saved_ip);
61724+ rcu_read_unlock();
61725+ }
61726+
61727+ return;
61728+}
61729+EXPORT_SYMBOL(gr_learn_resource);
61730+#endif
61731+
61732+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
61733+void
61734+pax_set_initial_flags(struct linux_binprm *bprm)
61735+{
61736+ struct task_struct *task = current;
61737+ struct acl_subject_label *proc;
61738+ unsigned long flags;
61739+
61740+ if (unlikely(!(gr_status & GR_READY)))
61741+ return;
61742+
61743+ flags = pax_get_flags(task);
61744+
61745+ proc = task->acl;
61746+
61747+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
61748+ flags &= ~MF_PAX_PAGEEXEC;
61749+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
61750+ flags &= ~MF_PAX_SEGMEXEC;
61751+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
61752+ flags &= ~MF_PAX_RANDMMAP;
61753+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
61754+ flags &= ~MF_PAX_EMUTRAMP;
61755+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
61756+ flags &= ~MF_PAX_MPROTECT;
61757+
61758+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
61759+ flags |= MF_PAX_PAGEEXEC;
61760+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
61761+ flags |= MF_PAX_SEGMEXEC;
61762+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
61763+ flags |= MF_PAX_RANDMMAP;
61764+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
61765+ flags |= MF_PAX_EMUTRAMP;
61766+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
61767+ flags |= MF_PAX_MPROTECT;
61768+
61769+ pax_set_flags(task, flags);
61770+
61771+ return;
61772+}
61773+#endif
61774+
61775+int
61776+gr_handle_proc_ptrace(struct task_struct *task)
61777+{
61778+ struct file *filp;
61779+ struct task_struct *tmp = task;
61780+ struct task_struct *curtemp = current;
61781+ __u32 retmode;
61782+
61783+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
61784+ if (unlikely(!(gr_status & GR_READY)))
61785+ return 0;
61786+#endif
61787+
61788+ read_lock(&tasklist_lock);
61789+ read_lock(&grsec_exec_file_lock);
61790+ filp = task->exec_file;
61791+
61792+ while (task_pid_nr(tmp) > 0) {
61793+ if (tmp == curtemp)
61794+ break;
61795+ tmp = tmp->real_parent;
61796+ }
61797+
61798+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
61799+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
61800+ read_unlock(&grsec_exec_file_lock);
61801+ read_unlock(&tasklist_lock);
61802+ return 1;
61803+ }
61804+
61805+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
61806+ if (!(gr_status & GR_READY)) {
61807+ read_unlock(&grsec_exec_file_lock);
61808+ read_unlock(&tasklist_lock);
61809+ return 0;
61810+ }
61811+#endif
61812+
61813+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
61814+ read_unlock(&grsec_exec_file_lock);
61815+ read_unlock(&tasklist_lock);
61816+
61817+ if (retmode & GR_NOPTRACE)
61818+ return 1;
61819+
61820+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
61821+ && (current->acl != task->acl || (current->acl != current->role->root_label
61822+ && task_pid_nr(current) != task_pid_nr(task))))
61823+ return 1;
61824+
61825+ return 0;
61826+}
61827+
61828+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
61829+{
61830+ if (unlikely(!(gr_status & GR_READY)))
61831+ return;
61832+
61833+ if (!(current->role->roletype & GR_ROLE_GOD))
61834+ return;
61835+
61836+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
61837+ p->role->rolename, gr_task_roletype_to_char(p),
61838+ p->acl->filename);
61839+}
61840+
61841+int
61842+gr_handle_ptrace(struct task_struct *task, const long request)
61843+{
61844+ struct task_struct *tmp = task;
61845+ struct task_struct *curtemp = current;
61846+ __u32 retmode;
61847+
61848+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
61849+ if (unlikely(!(gr_status & GR_READY)))
61850+ return 0;
61851+#endif
61852+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
61853+ read_lock(&tasklist_lock);
61854+ while (task_pid_nr(tmp) > 0) {
61855+ if (tmp == curtemp)
61856+ break;
61857+ tmp = tmp->real_parent;
61858+ }
61859+
61860+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
61861+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
61862+ read_unlock(&tasklist_lock);
61863+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
61864+ return 1;
61865+ }
61866+ read_unlock(&tasklist_lock);
61867+ }
61868+
61869+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
61870+ if (!(gr_status & GR_READY))
61871+ return 0;
61872+#endif
61873+
61874+ read_lock(&grsec_exec_file_lock);
61875+ if (unlikely(!task->exec_file)) {
61876+ read_unlock(&grsec_exec_file_lock);
61877+ return 0;
61878+ }
61879+
61880+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
61881+ read_unlock(&grsec_exec_file_lock);
61882+
61883+ if (retmode & GR_NOPTRACE) {
61884+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
61885+ return 1;
61886+ }
61887+
61888+ if (retmode & GR_PTRACERD) {
61889+ switch (request) {
61890+ case PTRACE_SEIZE:
61891+ case PTRACE_POKETEXT:
61892+ case PTRACE_POKEDATA:
61893+ case PTRACE_POKEUSR:
61894+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
61895+ case PTRACE_SETREGS:
61896+ case PTRACE_SETFPREGS:
61897+#endif
61898+#ifdef CONFIG_X86
61899+ case PTRACE_SETFPXREGS:
61900+#endif
61901+#ifdef CONFIG_ALTIVEC
61902+ case PTRACE_SETVRREGS:
61903+#endif
61904+ return 1;
61905+ default:
61906+ return 0;
61907+ }
61908+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
61909+ !(current->role->roletype & GR_ROLE_GOD) &&
61910+ (current->acl != task->acl)) {
61911+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
61912+ return 1;
61913+ }
61914+
61915+ return 0;
61916+}
61917+
61918+static int is_writable_mmap(const struct file *filp)
61919+{
61920+ struct task_struct *task = current;
61921+ struct acl_object_label *obj, *obj2;
61922+
61923+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
61924+ !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))) {
61925+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
61926+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
61927+ task->role->root_label);
61928+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
61929+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
61930+ return 1;
61931+ }
61932+ }
61933+ return 0;
61934+}
61935+
61936+int
61937+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
61938+{
61939+ __u32 mode;
61940+
61941+ if (unlikely(!file || !(prot & PROT_EXEC)))
61942+ return 1;
61943+
61944+ if (is_writable_mmap(file))
61945+ return 0;
61946+
61947+ mode =
61948+ gr_search_file(file->f_path.dentry,
61949+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
61950+ file->f_path.mnt);
61951+
61952+ if (!gr_tpe_allow(file))
61953+ return 0;
61954+
61955+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
61956+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
61957+ return 0;
61958+ } else if (unlikely(!(mode & GR_EXEC))) {
61959+ return 0;
61960+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
61961+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
61962+ return 1;
61963+ }
61964+
61965+ return 1;
61966+}
61967+
61968+int
61969+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
61970+{
61971+ __u32 mode;
61972+
61973+ if (unlikely(!file || !(prot & PROT_EXEC)))
61974+ return 1;
61975+
61976+ if (is_writable_mmap(file))
61977+ return 0;
61978+
61979+ mode =
61980+ gr_search_file(file->f_path.dentry,
61981+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
61982+ file->f_path.mnt);
61983+
61984+ if (!gr_tpe_allow(file))
61985+ return 0;
61986+
61987+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
61988+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
61989+ return 0;
61990+ } else if (unlikely(!(mode & GR_EXEC))) {
61991+ return 0;
61992+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
61993+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
61994+ return 1;
61995+ }
61996+
61997+ return 1;
61998+}
61999+
62000+void
62001+gr_acl_handle_psacct(struct task_struct *task, const long code)
62002+{
62003+ unsigned long runtime;
62004+ unsigned long cputime;
62005+ unsigned int wday, cday;
62006+ __u8 whr, chr;
62007+ __u8 wmin, cmin;
62008+ __u8 wsec, csec;
62009+ struct timespec timeval;
62010+
62011+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
62012+ !(task->acl->mode & GR_PROCACCT)))
62013+ return;
62014+
62015+ do_posix_clock_monotonic_gettime(&timeval);
62016+ runtime = timeval.tv_sec - task->start_time.tv_sec;
62017+ wday = runtime / (3600 * 24);
62018+ runtime -= wday * (3600 * 24);
62019+ whr = runtime / 3600;
62020+ runtime -= whr * 3600;
62021+ wmin = runtime / 60;
62022+ runtime -= wmin * 60;
62023+ wsec = runtime;
62024+
62025+ cputime = (task->utime + task->stime) / HZ;
62026+ cday = cputime / (3600 * 24);
62027+ cputime -= cday * (3600 * 24);
62028+ chr = cputime / 3600;
62029+ cputime -= chr * 3600;
62030+ cmin = cputime / 60;
62031+ cputime -= cmin * 60;
62032+ csec = cputime;
62033+
62034+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
62035+
62036+ return;
62037+}
62038+
62039+void gr_set_kernel_label(struct task_struct *task)
62040+{
62041+ if (gr_status & GR_READY) {
62042+ task->role = kernel_role;
62043+ task->acl = kernel_role->root_label;
62044+ }
62045+ return;
62046+}
62047+
62048+#ifdef CONFIG_TASKSTATS
62049+int gr_is_taskstats_denied(int pid)
62050+{
62051+ struct task_struct *task;
62052+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62053+ const struct cred *cred;
62054+#endif
62055+ int ret = 0;
62056+
62057+ /* restrict taskstats viewing to un-chrooted root users
62058+ who have the 'view' subject flag if the RBAC system is enabled
62059+ */
62060+
62061+ rcu_read_lock();
62062+ read_lock(&tasklist_lock);
62063+ task = find_task_by_vpid(pid);
62064+ if (task) {
62065+#ifdef CONFIG_GRKERNSEC_CHROOT
62066+ if (proc_is_chrooted(task))
62067+ ret = -EACCES;
62068+#endif
62069+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62070+ cred = __task_cred(task);
62071+#ifdef CONFIG_GRKERNSEC_PROC_USER
62072+ if (gr_is_global_nonroot(cred->uid))
62073+ ret = -EACCES;
62074+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62075+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
62076+ ret = -EACCES;
62077+#endif
62078+#endif
62079+ if (gr_status & GR_READY) {
62080+ if (!(task->acl->mode & GR_VIEW))
62081+ ret = -EACCES;
62082+ }
62083+ } else
62084+ ret = -ENOENT;
62085+
62086+ read_unlock(&tasklist_lock);
62087+ rcu_read_unlock();
62088+
62089+ return ret;
62090+}
62091+#endif
62092+
62093+/* AUXV entries are filled via a descendant of search_binary_handler
62094+ after we've already applied the subject for the target
62095+*/
62096+int gr_acl_enable_at_secure(void)
62097+{
62098+ if (unlikely(!(gr_status & GR_READY)))
62099+ return 0;
62100+
62101+ if (current->acl->mode & GR_ATSECURE)
62102+ return 1;
62103+
62104+ return 0;
62105+}
62106+
62107+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
62108+{
62109+ struct task_struct *task = current;
62110+ struct dentry *dentry = file->f_path.dentry;
62111+ struct vfsmount *mnt = file->f_path.mnt;
62112+ struct acl_object_label *obj, *tmp;
62113+ struct acl_subject_label *subj;
62114+ unsigned int bufsize;
62115+ int is_not_root;
62116+ char *path;
62117+ dev_t dev = __get_dev(dentry);
62118+
62119+ if (unlikely(!(gr_status & GR_READY)))
62120+ return 1;
62121+
62122+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
62123+ return 1;
62124+
62125+ /* ignore Eric Biederman */
62126+ if (IS_PRIVATE(dentry->d_inode))
62127+ return 1;
62128+
62129+ subj = task->acl;
62130+ read_lock(&gr_inode_lock);
62131+ do {
62132+ obj = lookup_acl_obj_label(ino, dev, subj);
62133+ if (obj != NULL) {
62134+ read_unlock(&gr_inode_lock);
62135+ return (obj->mode & GR_FIND) ? 1 : 0;
62136+ }
62137+ } while ((subj = subj->parent_subject));
62138+ read_unlock(&gr_inode_lock);
62139+
62140+ /* this is purely an optimization since we're looking for an object
62141+ for the directory we're doing a readdir on
62142+ if it's possible for any globbed object to match the entry we're
62143+ filling into the directory, then the object we find here will be
62144+ an anchor point with attached globbed objects
62145+ */
62146+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
62147+ if (obj->globbed == NULL)
62148+ return (obj->mode & GR_FIND) ? 1 : 0;
62149+
62150+ is_not_root = ((obj->filename[0] == '/') &&
62151+ (obj->filename[1] == '\0')) ? 0 : 1;
62152+ bufsize = PAGE_SIZE - namelen - is_not_root;
62153+
62154+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
62155+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
62156+ return 1;
62157+
62158+ preempt_disable();
62159+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
62160+ bufsize);
62161+
62162+ bufsize = strlen(path);
62163+
62164+ /* if base is "/", don't append an additional slash */
62165+ if (is_not_root)
62166+ *(path + bufsize) = '/';
62167+ memcpy(path + bufsize + is_not_root, name, namelen);
62168+ *(path + bufsize + namelen + is_not_root) = '\0';
62169+
62170+ tmp = obj->globbed;
62171+ while (tmp) {
62172+ if (!glob_match(tmp->filename, path)) {
62173+ preempt_enable();
62174+ return (tmp->mode & GR_FIND) ? 1 : 0;
62175+ }
62176+ tmp = tmp->next;
62177+ }
62178+ preempt_enable();
62179+ return (obj->mode & GR_FIND) ? 1 : 0;
62180+}
62181+
62182+void gr_put_exec_file(struct task_struct *task)
62183+{
62184+ struct file *filp;
62185+
62186+ write_lock(&grsec_exec_file_lock);
62187+ filp = task->exec_file;
62188+ task->exec_file = NULL;
62189+ write_unlock(&grsec_exec_file_lock);
62190+
62191+ if (filp)
62192+ fput(filp);
62193+
62194+ return;
62195+}
62196+
62197+
62198+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
62199+EXPORT_SYMBOL(gr_acl_is_enabled);
62200+#endif
62201+EXPORT_SYMBOL(gr_set_kernel_label);
62202+#ifdef CONFIG_SECURITY
62203+EXPORT_SYMBOL(gr_check_user_change);
62204+EXPORT_SYMBOL(gr_check_group_change);
62205+#endif
62206+
62207diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
62208new file mode 100644
62209index 0000000..34fefda
62210--- /dev/null
62211+++ b/grsecurity/gracl_alloc.c
62212@@ -0,0 +1,105 @@
62213+#include <linux/kernel.h>
62214+#include <linux/mm.h>
62215+#include <linux/slab.h>
62216+#include <linux/vmalloc.h>
62217+#include <linux/gracl.h>
62218+#include <linux/grsecurity.h>
62219+
62220+static unsigned long alloc_stack_next = 1;
62221+static unsigned long alloc_stack_size = 1;
62222+static void **alloc_stack;
62223+
62224+static __inline__ int
62225+alloc_pop(void)
62226+{
62227+ if (alloc_stack_next == 1)
62228+ return 0;
62229+
62230+ kfree(alloc_stack[alloc_stack_next - 2]);
62231+
62232+ alloc_stack_next--;
62233+
62234+ return 1;
62235+}
62236+
62237+static __inline__ int
62238+alloc_push(void *buf)
62239+{
62240+ if (alloc_stack_next >= alloc_stack_size)
62241+ return 1;
62242+
62243+ alloc_stack[alloc_stack_next - 1] = buf;
62244+
62245+ alloc_stack_next++;
62246+
62247+ return 0;
62248+}
62249+
62250+void *
62251+acl_alloc(unsigned long len)
62252+{
62253+ void *ret = NULL;
62254+
62255+ if (!len || len > PAGE_SIZE)
62256+ goto out;
62257+
62258+ ret = kmalloc(len, GFP_KERNEL);
62259+
62260+ if (ret) {
62261+ if (alloc_push(ret)) {
62262+ kfree(ret);
62263+ ret = NULL;
62264+ }
62265+ }
62266+
62267+out:
62268+ return ret;
62269+}
62270+
62271+void *
62272+acl_alloc_num(unsigned long num, unsigned long len)
62273+{
62274+ if (!len || (num > (PAGE_SIZE / len)))
62275+ return NULL;
62276+
62277+ return acl_alloc(num * len);
62278+}
62279+
62280+void
62281+acl_free_all(void)
62282+{
62283+ if (gr_acl_is_enabled() || !alloc_stack)
62284+ return;
62285+
62286+ while (alloc_pop()) ;
62287+
62288+ if (alloc_stack) {
62289+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
62290+ kfree(alloc_stack);
62291+ else
62292+ vfree(alloc_stack);
62293+ }
62294+
62295+ alloc_stack = NULL;
62296+ alloc_stack_size = 1;
62297+ alloc_stack_next = 1;
62298+
62299+ return;
62300+}
62301+
62302+int
62303+acl_alloc_stack_init(unsigned long size)
62304+{
62305+ if ((size * sizeof (void *)) <= PAGE_SIZE)
62306+ alloc_stack =
62307+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
62308+ else
62309+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
62310+
62311+ alloc_stack_size = size;
62312+
62313+ if (!alloc_stack)
62314+ return 0;
62315+ else
62316+ return 1;
62317+}
62318diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
62319new file mode 100644
62320index 0000000..bdd51ea
62321--- /dev/null
62322+++ b/grsecurity/gracl_cap.c
62323@@ -0,0 +1,110 @@
62324+#include <linux/kernel.h>
62325+#include <linux/module.h>
62326+#include <linux/sched.h>
62327+#include <linux/gracl.h>
62328+#include <linux/grsecurity.h>
62329+#include <linux/grinternal.h>
62330+
62331+extern const char *captab_log[];
62332+extern int captab_log_entries;
62333+
62334+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
62335+{
62336+ struct acl_subject_label *curracl;
62337+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
62338+ kernel_cap_t cap_audit = __cap_empty_set;
62339+
62340+ if (!gr_acl_is_enabled())
62341+ return 1;
62342+
62343+ curracl = task->acl;
62344+
62345+ cap_drop = curracl->cap_lower;
62346+ cap_mask = curracl->cap_mask;
62347+ cap_audit = curracl->cap_invert_audit;
62348+
62349+ while ((curracl = curracl->parent_subject)) {
62350+ /* if the cap isn't specified in the current computed mask but is specified in the
62351+ current level subject, and is lowered in the current level subject, then add
62352+ it to the set of dropped capabilities
62353+ otherwise, add the current level subject's mask to the current computed mask
62354+ */
62355+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
62356+ cap_raise(cap_mask, cap);
62357+ if (cap_raised(curracl->cap_lower, cap))
62358+ cap_raise(cap_drop, cap);
62359+ if (cap_raised(curracl->cap_invert_audit, cap))
62360+ cap_raise(cap_audit, cap);
62361+ }
62362+ }
62363+
62364+ if (!cap_raised(cap_drop, cap)) {
62365+ if (cap_raised(cap_audit, cap))
62366+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
62367+ return 1;
62368+ }
62369+
62370+ curracl = task->acl;
62371+
62372+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
62373+ && cap_raised(cred->cap_effective, cap)) {
62374+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
62375+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
62376+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
62377+ gr_to_filename(task->exec_file->f_path.dentry,
62378+ task->exec_file->f_path.mnt) : curracl->filename,
62379+ curracl->filename, 0UL,
62380+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
62381+ return 1;
62382+ }
62383+
62384+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
62385+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
62386+
62387+ return 0;
62388+}
62389+
62390+int
62391+gr_acl_is_capable(const int cap)
62392+{
62393+ return gr_task_acl_is_capable(current, current_cred(), cap);
62394+}
62395+
62396+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
62397+{
62398+ struct acl_subject_label *curracl;
62399+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
62400+
62401+ if (!gr_acl_is_enabled())
62402+ return 1;
62403+
62404+ curracl = task->acl;
62405+
62406+ cap_drop = curracl->cap_lower;
62407+ cap_mask = curracl->cap_mask;
62408+
62409+ while ((curracl = curracl->parent_subject)) {
62410+ /* if the cap isn't specified in the current computed mask but is specified in the
62411+ current level subject, and is lowered in the current level subject, then add
62412+ it to the set of dropped capabilities
62413+ otherwise, add the current level subject's mask to the current computed mask
62414+ */
62415+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
62416+ cap_raise(cap_mask, cap);
62417+ if (cap_raised(curracl->cap_lower, cap))
62418+ cap_raise(cap_drop, cap);
62419+ }
62420+ }
62421+
62422+ if (!cap_raised(cap_drop, cap))
62423+ return 1;
62424+
62425+ return 0;
62426+}
62427+
62428+int
62429+gr_acl_is_capable_nolog(const int cap)
62430+{
62431+ return gr_task_acl_is_capable_nolog(current, cap);
62432+}
62433+
62434diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
62435new file mode 100644
62436index 0000000..a340c17
62437--- /dev/null
62438+++ b/grsecurity/gracl_fs.c
62439@@ -0,0 +1,431 @@
62440+#include <linux/kernel.h>
62441+#include <linux/sched.h>
62442+#include <linux/types.h>
62443+#include <linux/fs.h>
62444+#include <linux/file.h>
62445+#include <linux/stat.h>
62446+#include <linux/grsecurity.h>
62447+#include <linux/grinternal.h>
62448+#include <linux/gracl.h>
62449+
62450+umode_t
62451+gr_acl_umask(void)
62452+{
62453+ if (unlikely(!gr_acl_is_enabled()))
62454+ return 0;
62455+
62456+ return current->role->umask;
62457+}
62458+
62459+__u32
62460+gr_acl_handle_hidden_file(const struct dentry * dentry,
62461+ const struct vfsmount * mnt)
62462+{
62463+ __u32 mode;
62464+
62465+ if (unlikely(!dentry->d_inode))
62466+ return GR_FIND;
62467+
62468+ mode =
62469+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
62470+
62471+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
62472+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
62473+ return mode;
62474+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
62475+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
62476+ return 0;
62477+ } else if (unlikely(!(mode & GR_FIND)))
62478+ return 0;
62479+
62480+ return GR_FIND;
62481+}
62482+
62483+__u32
62484+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
62485+ int acc_mode)
62486+{
62487+ __u32 reqmode = GR_FIND;
62488+ __u32 mode;
62489+
62490+ if (unlikely(!dentry->d_inode))
62491+ return reqmode;
62492+
62493+ if (acc_mode & MAY_APPEND)
62494+ reqmode |= GR_APPEND;
62495+ else if (acc_mode & MAY_WRITE)
62496+ reqmode |= GR_WRITE;
62497+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
62498+ reqmode |= GR_READ;
62499+
62500+ mode =
62501+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
62502+ mnt);
62503+
62504+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
62505+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
62506+ reqmode & GR_READ ? " reading" : "",
62507+ reqmode & GR_WRITE ? " writing" : reqmode &
62508+ GR_APPEND ? " appending" : "");
62509+ return reqmode;
62510+ } else
62511+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
62512+ {
62513+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
62514+ reqmode & GR_READ ? " reading" : "",
62515+ reqmode & GR_WRITE ? " writing" : reqmode &
62516+ GR_APPEND ? " appending" : "");
62517+ return 0;
62518+ } else if (unlikely((mode & reqmode) != reqmode))
62519+ return 0;
62520+
62521+ return reqmode;
62522+}
62523+
62524+__u32
62525+gr_acl_handle_creat(const struct dentry * dentry,
62526+ const struct dentry * p_dentry,
62527+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
62528+ const int imode)
62529+{
62530+ __u32 reqmode = GR_WRITE | GR_CREATE;
62531+ __u32 mode;
62532+
62533+ if (acc_mode & MAY_APPEND)
62534+ reqmode |= GR_APPEND;
62535+ // if a directory was required or the directory already exists, then
62536+ // don't count this open as a read
62537+ if ((acc_mode & MAY_READ) &&
62538+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
62539+ reqmode |= GR_READ;
62540+ if ((open_flags & O_CREAT) &&
62541+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
62542+ reqmode |= GR_SETID;
62543+
62544+ mode =
62545+ gr_check_create(dentry, p_dentry, p_mnt,
62546+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
62547+
62548+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
62549+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
62550+ reqmode & GR_READ ? " reading" : "",
62551+ reqmode & GR_WRITE ? " writing" : reqmode &
62552+ GR_APPEND ? " appending" : "");
62553+ return reqmode;
62554+ } else
62555+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
62556+ {
62557+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
62558+ reqmode & GR_READ ? " reading" : "",
62559+ reqmode & GR_WRITE ? " writing" : reqmode &
62560+ GR_APPEND ? " appending" : "");
62561+ return 0;
62562+ } else if (unlikely((mode & reqmode) != reqmode))
62563+ return 0;
62564+
62565+ return reqmode;
62566+}
62567+
62568+__u32
62569+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
62570+ const int fmode)
62571+{
62572+ __u32 mode, reqmode = GR_FIND;
62573+
62574+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
62575+ reqmode |= GR_EXEC;
62576+ if (fmode & S_IWOTH)
62577+ reqmode |= GR_WRITE;
62578+ if (fmode & S_IROTH)
62579+ reqmode |= GR_READ;
62580+
62581+ mode =
62582+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
62583+ mnt);
62584+
62585+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
62586+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
62587+ reqmode & GR_READ ? " reading" : "",
62588+ reqmode & GR_WRITE ? " writing" : "",
62589+ reqmode & GR_EXEC ? " executing" : "");
62590+ return reqmode;
62591+ } else
62592+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
62593+ {
62594+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
62595+ reqmode & GR_READ ? " reading" : "",
62596+ reqmode & GR_WRITE ? " writing" : "",
62597+ reqmode & GR_EXEC ? " executing" : "");
62598+ return 0;
62599+ } else if (unlikely((mode & reqmode) != reqmode))
62600+ return 0;
62601+
62602+ return reqmode;
62603+}
62604+
62605+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
62606+{
62607+ __u32 mode;
62608+
62609+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
62610+
62611+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
62612+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
62613+ return mode;
62614+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
62615+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
62616+ return 0;
62617+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
62618+ return 0;
62619+
62620+ return (reqmode);
62621+}
62622+
62623+__u32
62624+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
62625+{
62626+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
62627+}
62628+
62629+__u32
62630+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
62631+{
62632+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
62633+}
62634+
62635+__u32
62636+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
62637+{
62638+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
62639+}
62640+
62641+__u32
62642+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
62643+{
62644+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
62645+}
62646+
62647+__u32
62648+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
62649+ umode_t *modeptr)
62650+{
62651+ umode_t mode;
62652+
62653+ *modeptr &= ~gr_acl_umask();
62654+ mode = *modeptr;
62655+
62656+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
62657+ return 1;
62658+
62659+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
62660+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
62661+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
62662+ GR_CHMOD_ACL_MSG);
62663+ } else {
62664+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
62665+ }
62666+}
62667+
62668+__u32
62669+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
62670+{
62671+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
62672+}
62673+
62674+__u32
62675+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
62676+{
62677+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
62678+}
62679+
62680+__u32
62681+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
62682+{
62683+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
62684+}
62685+
62686+__u32
62687+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
62688+{
62689+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
62690+ GR_UNIXCONNECT_ACL_MSG);
62691+}
62692+
62693+/* hardlinks require at minimum create and link permission,
62694+ any additional privilege required is based on the
62695+ privilege of the file being linked to
62696+*/
62697+__u32
62698+gr_acl_handle_link(const struct dentry * new_dentry,
62699+ const struct dentry * parent_dentry,
62700+ const struct vfsmount * parent_mnt,
62701+ const struct dentry * old_dentry,
62702+ const struct vfsmount * old_mnt, const struct filename *to)
62703+{
62704+ __u32 mode;
62705+ __u32 needmode = GR_CREATE | GR_LINK;
62706+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
62707+
62708+ mode =
62709+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
62710+ old_mnt);
62711+
62712+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
62713+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
62714+ return mode;
62715+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
62716+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
62717+ return 0;
62718+ } else if (unlikely((mode & needmode) != needmode))
62719+ return 0;
62720+
62721+ return 1;
62722+}
62723+
62724+__u32
62725+gr_acl_handle_symlink(const struct dentry * new_dentry,
62726+ const struct dentry * parent_dentry,
62727+ const struct vfsmount * parent_mnt, const struct filename *from)
62728+{
62729+ __u32 needmode = GR_WRITE | GR_CREATE;
62730+ __u32 mode;
62731+
62732+ mode =
62733+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
62734+ GR_CREATE | GR_AUDIT_CREATE |
62735+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
62736+
62737+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
62738+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
62739+ return mode;
62740+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
62741+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
62742+ return 0;
62743+ } else if (unlikely((mode & needmode) != needmode))
62744+ return 0;
62745+
62746+ return (GR_WRITE | GR_CREATE);
62747+}
62748+
62749+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)
62750+{
62751+ __u32 mode;
62752+
62753+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
62754+
62755+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
62756+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
62757+ return mode;
62758+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
62759+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
62760+ return 0;
62761+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
62762+ return 0;
62763+
62764+ return (reqmode);
62765+}
62766+
62767+__u32
62768+gr_acl_handle_mknod(const struct dentry * new_dentry,
62769+ const struct dentry * parent_dentry,
62770+ const struct vfsmount * parent_mnt,
62771+ const int mode)
62772+{
62773+ __u32 reqmode = GR_WRITE | GR_CREATE;
62774+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
62775+ reqmode |= GR_SETID;
62776+
62777+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
62778+ reqmode, GR_MKNOD_ACL_MSG);
62779+}
62780+
62781+__u32
62782+gr_acl_handle_mkdir(const struct dentry *new_dentry,
62783+ const struct dentry *parent_dentry,
62784+ const struct vfsmount *parent_mnt)
62785+{
62786+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
62787+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
62788+}
62789+
62790+#define RENAME_CHECK_SUCCESS(old, new) \
62791+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
62792+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
62793+
62794+int
62795+gr_acl_handle_rename(struct dentry *new_dentry,
62796+ struct dentry *parent_dentry,
62797+ const struct vfsmount *parent_mnt,
62798+ struct dentry *old_dentry,
62799+ struct inode *old_parent_inode,
62800+ struct vfsmount *old_mnt, const struct filename *newname)
62801+{
62802+ __u32 comp1, comp2;
62803+ int error = 0;
62804+
62805+ if (unlikely(!gr_acl_is_enabled()))
62806+ return 0;
62807+
62808+ if (!new_dentry->d_inode) {
62809+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
62810+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
62811+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
62812+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
62813+ GR_DELETE | GR_AUDIT_DELETE |
62814+ GR_AUDIT_READ | GR_AUDIT_WRITE |
62815+ GR_SUPPRESS, old_mnt);
62816+ } else {
62817+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
62818+ GR_CREATE | GR_DELETE |
62819+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
62820+ GR_AUDIT_READ | GR_AUDIT_WRITE |
62821+ GR_SUPPRESS, parent_mnt);
62822+ comp2 =
62823+ gr_search_file(old_dentry,
62824+ GR_READ | GR_WRITE | GR_AUDIT_READ |
62825+ GR_DELETE | GR_AUDIT_DELETE |
62826+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
62827+ }
62828+
62829+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
62830+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
62831+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
62832+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
62833+ && !(comp2 & GR_SUPPRESS)) {
62834+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
62835+ error = -EACCES;
62836+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
62837+ error = -EACCES;
62838+
62839+ return error;
62840+}
62841+
62842+void
62843+gr_acl_handle_exit(void)
62844+{
62845+ u16 id;
62846+ char *rolename;
62847+
62848+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
62849+ !(current->role->roletype & GR_ROLE_PERSIST))) {
62850+ id = current->acl_role_id;
62851+ rolename = current->role->rolename;
62852+ gr_set_acls(1);
62853+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
62854+ }
62855+
62856+ gr_put_exec_file(current);
62857+ return;
62858+}
62859+
62860+int
62861+gr_acl_handle_procpidmem(const struct task_struct *task)
62862+{
62863+ if (unlikely(!gr_acl_is_enabled()))
62864+ return 0;
62865+
62866+ if (task != current && task->acl->mode & GR_PROTPROCFD)
62867+ return -EACCES;
62868+
62869+ return 0;
62870+}
62871diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
62872new file mode 100644
62873index 0000000..8132048
62874--- /dev/null
62875+++ b/grsecurity/gracl_ip.c
62876@@ -0,0 +1,387 @@
62877+#include <linux/kernel.h>
62878+#include <asm/uaccess.h>
62879+#include <asm/errno.h>
62880+#include <net/sock.h>
62881+#include <linux/file.h>
62882+#include <linux/fs.h>
62883+#include <linux/net.h>
62884+#include <linux/in.h>
62885+#include <linux/skbuff.h>
62886+#include <linux/ip.h>
62887+#include <linux/udp.h>
62888+#include <linux/types.h>
62889+#include <linux/sched.h>
62890+#include <linux/netdevice.h>
62891+#include <linux/inetdevice.h>
62892+#include <linux/gracl.h>
62893+#include <linux/grsecurity.h>
62894+#include <linux/grinternal.h>
62895+
62896+#define GR_BIND 0x01
62897+#define GR_CONNECT 0x02
62898+#define GR_INVERT 0x04
62899+#define GR_BINDOVERRIDE 0x08
62900+#define GR_CONNECTOVERRIDE 0x10
62901+#define GR_SOCK_FAMILY 0x20
62902+
62903+static const char * gr_protocols[IPPROTO_MAX] = {
62904+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
62905+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
62906+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
62907+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
62908+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
62909+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
62910+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
62911+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
62912+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
62913+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
62914+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
62915+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
62916+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
62917+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
62918+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
62919+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
62920+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
62921+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
62922+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
62923+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
62924+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
62925+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
62926+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
62927+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
62928+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
62929+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
62930+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
62931+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
62932+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
62933+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
62934+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
62935+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
62936+ };
62937+
62938+static const char * gr_socktypes[SOCK_MAX] = {
62939+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
62940+ "unknown:7", "unknown:8", "unknown:9", "packet"
62941+ };
62942+
62943+static const char * gr_sockfamilies[AF_MAX+1] = {
62944+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
62945+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
62946+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
62947+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
62948+ };
62949+
62950+const char *
62951+gr_proto_to_name(unsigned char proto)
62952+{
62953+ return gr_protocols[proto];
62954+}
62955+
62956+const char *
62957+gr_socktype_to_name(unsigned char type)
62958+{
62959+ return gr_socktypes[type];
62960+}
62961+
62962+const char *
62963+gr_sockfamily_to_name(unsigned char family)
62964+{
62965+ return gr_sockfamilies[family];
62966+}
62967+
62968+int
62969+gr_search_socket(const int domain, const int type, const int protocol)
62970+{
62971+ struct acl_subject_label *curr;
62972+ const struct cred *cred = current_cred();
62973+
62974+ if (unlikely(!gr_acl_is_enabled()))
62975+ goto exit;
62976+
62977+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
62978+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
62979+ goto exit; // let the kernel handle it
62980+
62981+ curr = current->acl;
62982+
62983+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
62984+ /* the family is allowed, if this is PF_INET allow it only if
62985+ the extra sock type/protocol checks pass */
62986+ if (domain == PF_INET)
62987+ goto inet_check;
62988+ goto exit;
62989+ } else {
62990+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
62991+ __u32 fakeip = 0;
62992+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
62993+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
62994+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
62995+ gr_to_filename(current->exec_file->f_path.dentry,
62996+ current->exec_file->f_path.mnt) :
62997+ curr->filename, curr->filename,
62998+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
62999+ &current->signal->saved_ip);
63000+ goto exit;
63001+ }
63002+ goto exit_fail;
63003+ }
63004+
63005+inet_check:
63006+ /* the rest of this checking is for IPv4 only */
63007+ if (!curr->ips)
63008+ goto exit;
63009+
63010+ if ((curr->ip_type & (1U << type)) &&
63011+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
63012+ goto exit;
63013+
63014+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
63015+ /* we don't place acls on raw sockets , and sometimes
63016+ dgram/ip sockets are opened for ioctl and not
63017+ bind/connect, so we'll fake a bind learn log */
63018+ if (type == SOCK_RAW || type == SOCK_PACKET) {
63019+ __u32 fakeip = 0;
63020+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63021+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63022+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63023+ gr_to_filename(current->exec_file->f_path.dentry,
63024+ current->exec_file->f_path.mnt) :
63025+ curr->filename, curr->filename,
63026+ &fakeip, 0, type,
63027+ protocol, GR_CONNECT, &current->signal->saved_ip);
63028+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
63029+ __u32 fakeip = 0;
63030+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63031+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63032+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63033+ gr_to_filename(current->exec_file->f_path.dentry,
63034+ current->exec_file->f_path.mnt) :
63035+ curr->filename, curr->filename,
63036+ &fakeip, 0, type,
63037+ protocol, GR_BIND, &current->signal->saved_ip);
63038+ }
63039+ /* we'll log when they use connect or bind */
63040+ goto exit;
63041+ }
63042+
63043+exit_fail:
63044+ if (domain == PF_INET)
63045+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
63046+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
63047+ else
63048+#ifndef CONFIG_IPV6
63049+ if (domain != PF_INET6)
63050+#endif
63051+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
63052+ gr_socktype_to_name(type), protocol);
63053+
63054+ return 0;
63055+exit:
63056+ return 1;
63057+}
63058+
63059+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)
63060+{
63061+ if ((ip->mode & mode) &&
63062+ (ip_port >= ip->low) &&
63063+ (ip_port <= ip->high) &&
63064+ ((ntohl(ip_addr) & our_netmask) ==
63065+ (ntohl(our_addr) & our_netmask))
63066+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
63067+ && (ip->type & (1U << type))) {
63068+ if (ip->mode & GR_INVERT)
63069+ return 2; // specifically denied
63070+ else
63071+ return 1; // allowed
63072+ }
63073+
63074+ return 0; // not specifically allowed, may continue parsing
63075+}
63076+
63077+static int
63078+gr_search_connectbind(const int full_mode, struct sock *sk,
63079+ struct sockaddr_in *addr, const int type)
63080+{
63081+ char iface[IFNAMSIZ] = {0};
63082+ struct acl_subject_label *curr;
63083+ struct acl_ip_label *ip;
63084+ struct inet_sock *isk;
63085+ struct net_device *dev;
63086+ struct in_device *idev;
63087+ unsigned long i;
63088+ int ret;
63089+ int mode = full_mode & (GR_BIND | GR_CONNECT);
63090+ __u32 ip_addr = 0;
63091+ __u32 our_addr;
63092+ __u32 our_netmask;
63093+ char *p;
63094+ __u16 ip_port = 0;
63095+ const struct cred *cred = current_cred();
63096+
63097+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
63098+ return 0;
63099+
63100+ curr = current->acl;
63101+ isk = inet_sk(sk);
63102+
63103+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
63104+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
63105+ addr->sin_addr.s_addr = curr->inaddr_any_override;
63106+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
63107+ struct sockaddr_in saddr;
63108+ int err;
63109+
63110+ saddr.sin_family = AF_INET;
63111+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
63112+ saddr.sin_port = isk->inet_sport;
63113+
63114+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
63115+ if (err)
63116+ return err;
63117+
63118+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
63119+ if (err)
63120+ return err;
63121+ }
63122+
63123+ if (!curr->ips)
63124+ return 0;
63125+
63126+ ip_addr = addr->sin_addr.s_addr;
63127+ ip_port = ntohs(addr->sin_port);
63128+
63129+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
63130+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63131+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63132+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63133+ gr_to_filename(current->exec_file->f_path.dentry,
63134+ current->exec_file->f_path.mnt) :
63135+ curr->filename, curr->filename,
63136+ &ip_addr, ip_port, type,
63137+ sk->sk_protocol, mode, &current->signal->saved_ip);
63138+ return 0;
63139+ }
63140+
63141+ for (i = 0; i < curr->ip_num; i++) {
63142+ ip = *(curr->ips + i);
63143+ if (ip->iface != NULL) {
63144+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
63145+ p = strchr(iface, ':');
63146+ if (p != NULL)
63147+ *p = '\0';
63148+ dev = dev_get_by_name(sock_net(sk), iface);
63149+ if (dev == NULL)
63150+ continue;
63151+ idev = in_dev_get(dev);
63152+ if (idev == NULL) {
63153+ dev_put(dev);
63154+ continue;
63155+ }
63156+ rcu_read_lock();
63157+ for_ifa(idev) {
63158+ if (!strcmp(ip->iface, ifa->ifa_label)) {
63159+ our_addr = ifa->ifa_address;
63160+ our_netmask = 0xffffffff;
63161+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
63162+ if (ret == 1) {
63163+ rcu_read_unlock();
63164+ in_dev_put(idev);
63165+ dev_put(dev);
63166+ return 0;
63167+ } else if (ret == 2) {
63168+ rcu_read_unlock();
63169+ in_dev_put(idev);
63170+ dev_put(dev);
63171+ goto denied;
63172+ }
63173+ }
63174+ } endfor_ifa(idev);
63175+ rcu_read_unlock();
63176+ in_dev_put(idev);
63177+ dev_put(dev);
63178+ } else {
63179+ our_addr = ip->addr;
63180+ our_netmask = ip->netmask;
63181+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
63182+ if (ret == 1)
63183+ return 0;
63184+ else if (ret == 2)
63185+ goto denied;
63186+ }
63187+ }
63188+
63189+denied:
63190+ if (mode == GR_BIND)
63191+ 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));
63192+ else if (mode == GR_CONNECT)
63193+ 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));
63194+
63195+ return -EACCES;
63196+}
63197+
63198+int
63199+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
63200+{
63201+ /* always allow disconnection of dgram sockets with connect */
63202+ if (addr->sin_family == AF_UNSPEC)
63203+ return 0;
63204+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
63205+}
63206+
63207+int
63208+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
63209+{
63210+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
63211+}
63212+
63213+int gr_search_listen(struct socket *sock)
63214+{
63215+ struct sock *sk = sock->sk;
63216+ struct sockaddr_in addr;
63217+
63218+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
63219+ addr.sin_port = inet_sk(sk)->inet_sport;
63220+
63221+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
63222+}
63223+
63224+int gr_search_accept(struct socket *sock)
63225+{
63226+ struct sock *sk = sock->sk;
63227+ struct sockaddr_in addr;
63228+
63229+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
63230+ addr.sin_port = inet_sk(sk)->inet_sport;
63231+
63232+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
63233+}
63234+
63235+int
63236+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
63237+{
63238+ if (addr)
63239+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
63240+ else {
63241+ struct sockaddr_in sin;
63242+ const struct inet_sock *inet = inet_sk(sk);
63243+
63244+ sin.sin_addr.s_addr = inet->inet_daddr;
63245+ sin.sin_port = inet->inet_dport;
63246+
63247+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
63248+ }
63249+}
63250+
63251+int
63252+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
63253+{
63254+ struct sockaddr_in sin;
63255+
63256+ if (unlikely(skb->len < sizeof (struct udphdr)))
63257+ return 0; // skip this packet
63258+
63259+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
63260+ sin.sin_port = udp_hdr(skb)->source;
63261+
63262+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
63263+}
63264diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
63265new file mode 100644
63266index 0000000..25f54ef
63267--- /dev/null
63268+++ b/grsecurity/gracl_learn.c
63269@@ -0,0 +1,207 @@
63270+#include <linux/kernel.h>
63271+#include <linux/mm.h>
63272+#include <linux/sched.h>
63273+#include <linux/poll.h>
63274+#include <linux/string.h>
63275+#include <linux/file.h>
63276+#include <linux/types.h>
63277+#include <linux/vmalloc.h>
63278+#include <linux/grinternal.h>
63279+
63280+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
63281+ size_t count, loff_t *ppos);
63282+extern int gr_acl_is_enabled(void);
63283+
63284+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
63285+static int gr_learn_attached;
63286+
63287+/* use a 512k buffer */
63288+#define LEARN_BUFFER_SIZE (512 * 1024)
63289+
63290+static DEFINE_SPINLOCK(gr_learn_lock);
63291+static DEFINE_MUTEX(gr_learn_user_mutex);
63292+
63293+/* we need to maintain two buffers, so that the kernel context of grlearn
63294+ uses a semaphore around the userspace copying, and the other kernel contexts
63295+ use a spinlock when copying into the buffer, since they cannot sleep
63296+*/
63297+static char *learn_buffer;
63298+static char *learn_buffer_user;
63299+static int learn_buffer_len;
63300+static int learn_buffer_user_len;
63301+
63302+static ssize_t
63303+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
63304+{
63305+ DECLARE_WAITQUEUE(wait, current);
63306+ ssize_t retval = 0;
63307+
63308+ add_wait_queue(&learn_wait, &wait);
63309+ set_current_state(TASK_INTERRUPTIBLE);
63310+ do {
63311+ mutex_lock(&gr_learn_user_mutex);
63312+ spin_lock(&gr_learn_lock);
63313+ if (learn_buffer_len)
63314+ break;
63315+ spin_unlock(&gr_learn_lock);
63316+ mutex_unlock(&gr_learn_user_mutex);
63317+ if (file->f_flags & O_NONBLOCK) {
63318+ retval = -EAGAIN;
63319+ goto out;
63320+ }
63321+ if (signal_pending(current)) {
63322+ retval = -ERESTARTSYS;
63323+ goto out;
63324+ }
63325+
63326+ schedule();
63327+ } while (1);
63328+
63329+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
63330+ learn_buffer_user_len = learn_buffer_len;
63331+ retval = learn_buffer_len;
63332+ learn_buffer_len = 0;
63333+
63334+ spin_unlock(&gr_learn_lock);
63335+
63336+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
63337+ retval = -EFAULT;
63338+
63339+ mutex_unlock(&gr_learn_user_mutex);
63340+out:
63341+ set_current_state(TASK_RUNNING);
63342+ remove_wait_queue(&learn_wait, &wait);
63343+ return retval;
63344+}
63345+
63346+static unsigned int
63347+poll_learn(struct file * file, poll_table * wait)
63348+{
63349+ poll_wait(file, &learn_wait, wait);
63350+
63351+ if (learn_buffer_len)
63352+ return (POLLIN | POLLRDNORM);
63353+
63354+ return 0;
63355+}
63356+
63357+void
63358+gr_clear_learn_entries(void)
63359+{
63360+ char *tmp;
63361+
63362+ mutex_lock(&gr_learn_user_mutex);
63363+ spin_lock(&gr_learn_lock);
63364+ tmp = learn_buffer;
63365+ learn_buffer = NULL;
63366+ spin_unlock(&gr_learn_lock);
63367+ if (tmp)
63368+ vfree(tmp);
63369+ if (learn_buffer_user != NULL) {
63370+ vfree(learn_buffer_user);
63371+ learn_buffer_user = NULL;
63372+ }
63373+ learn_buffer_len = 0;
63374+ mutex_unlock(&gr_learn_user_mutex);
63375+
63376+ return;
63377+}
63378+
63379+void
63380+gr_add_learn_entry(const char *fmt, ...)
63381+{
63382+ va_list args;
63383+ unsigned int len;
63384+
63385+ if (!gr_learn_attached)
63386+ return;
63387+
63388+ spin_lock(&gr_learn_lock);
63389+
63390+ /* leave a gap at the end so we know when it's "full" but don't have to
63391+ compute the exact length of the string we're trying to append
63392+ */
63393+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
63394+ spin_unlock(&gr_learn_lock);
63395+ wake_up_interruptible(&learn_wait);
63396+ return;
63397+ }
63398+ if (learn_buffer == NULL) {
63399+ spin_unlock(&gr_learn_lock);
63400+ return;
63401+ }
63402+
63403+ va_start(args, fmt);
63404+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
63405+ va_end(args);
63406+
63407+ learn_buffer_len += len + 1;
63408+
63409+ spin_unlock(&gr_learn_lock);
63410+ wake_up_interruptible(&learn_wait);
63411+
63412+ return;
63413+}
63414+
63415+static int
63416+open_learn(struct inode *inode, struct file *file)
63417+{
63418+ if (file->f_mode & FMODE_READ && gr_learn_attached)
63419+ return -EBUSY;
63420+ if (file->f_mode & FMODE_READ) {
63421+ int retval = 0;
63422+ mutex_lock(&gr_learn_user_mutex);
63423+ if (learn_buffer == NULL)
63424+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
63425+ if (learn_buffer_user == NULL)
63426+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
63427+ if (learn_buffer == NULL) {
63428+ retval = -ENOMEM;
63429+ goto out_error;
63430+ }
63431+ if (learn_buffer_user == NULL) {
63432+ retval = -ENOMEM;
63433+ goto out_error;
63434+ }
63435+ learn_buffer_len = 0;
63436+ learn_buffer_user_len = 0;
63437+ gr_learn_attached = 1;
63438+out_error:
63439+ mutex_unlock(&gr_learn_user_mutex);
63440+ return retval;
63441+ }
63442+ return 0;
63443+}
63444+
63445+static int
63446+close_learn(struct inode *inode, struct file *file)
63447+{
63448+ if (file->f_mode & FMODE_READ) {
63449+ char *tmp = NULL;
63450+ mutex_lock(&gr_learn_user_mutex);
63451+ spin_lock(&gr_learn_lock);
63452+ tmp = learn_buffer;
63453+ learn_buffer = NULL;
63454+ spin_unlock(&gr_learn_lock);
63455+ if (tmp)
63456+ vfree(tmp);
63457+ if (learn_buffer_user != NULL) {
63458+ vfree(learn_buffer_user);
63459+ learn_buffer_user = NULL;
63460+ }
63461+ learn_buffer_len = 0;
63462+ learn_buffer_user_len = 0;
63463+ gr_learn_attached = 0;
63464+ mutex_unlock(&gr_learn_user_mutex);
63465+ }
63466+
63467+ return 0;
63468+}
63469+
63470+const struct file_operations grsec_fops = {
63471+ .read = read_learn,
63472+ .write = write_grsec_handler,
63473+ .open = open_learn,
63474+ .release = close_learn,
63475+ .poll = poll_learn,
63476+};
63477diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
63478new file mode 100644
63479index 0000000..39645c9
63480--- /dev/null
63481+++ b/grsecurity/gracl_res.c
63482@@ -0,0 +1,68 @@
63483+#include <linux/kernel.h>
63484+#include <linux/sched.h>
63485+#include <linux/gracl.h>
63486+#include <linux/grinternal.h>
63487+
63488+static const char *restab_log[] = {
63489+ [RLIMIT_CPU] = "RLIMIT_CPU",
63490+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
63491+ [RLIMIT_DATA] = "RLIMIT_DATA",
63492+ [RLIMIT_STACK] = "RLIMIT_STACK",
63493+ [RLIMIT_CORE] = "RLIMIT_CORE",
63494+ [RLIMIT_RSS] = "RLIMIT_RSS",
63495+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
63496+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
63497+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
63498+ [RLIMIT_AS] = "RLIMIT_AS",
63499+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
63500+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
63501+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
63502+ [RLIMIT_NICE] = "RLIMIT_NICE",
63503+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
63504+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
63505+ [GR_CRASH_RES] = "RLIMIT_CRASH"
63506+};
63507+
63508+void
63509+gr_log_resource(const struct task_struct *task,
63510+ const int res, const unsigned long wanted, const int gt)
63511+{
63512+ const struct cred *cred;
63513+ unsigned long rlim;
63514+
63515+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
63516+ return;
63517+
63518+ // not yet supported resource
63519+ if (unlikely(!restab_log[res]))
63520+ return;
63521+
63522+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
63523+ rlim = task_rlimit_max(task, res);
63524+ else
63525+ rlim = task_rlimit(task, res);
63526+
63527+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
63528+ return;
63529+
63530+ rcu_read_lock();
63531+ cred = __task_cred(task);
63532+
63533+ if (res == RLIMIT_NPROC &&
63534+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
63535+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
63536+ goto out_rcu_unlock;
63537+ else if (res == RLIMIT_MEMLOCK &&
63538+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
63539+ goto out_rcu_unlock;
63540+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
63541+ goto out_rcu_unlock;
63542+ rcu_read_unlock();
63543+
63544+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
63545+
63546+ return;
63547+out_rcu_unlock:
63548+ rcu_read_unlock();
63549+ return;
63550+}
63551diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
63552new file mode 100644
63553index 0000000..cb1e5ab
63554--- /dev/null
63555+++ b/grsecurity/gracl_segv.c
63556@@ -0,0 +1,303 @@
63557+#include <linux/kernel.h>
63558+#include <linux/mm.h>
63559+#include <asm/uaccess.h>
63560+#include <asm/errno.h>
63561+#include <asm/mman.h>
63562+#include <net/sock.h>
63563+#include <linux/file.h>
63564+#include <linux/fs.h>
63565+#include <linux/net.h>
63566+#include <linux/in.h>
63567+#include <linux/slab.h>
63568+#include <linux/types.h>
63569+#include <linux/sched.h>
63570+#include <linux/timer.h>
63571+#include <linux/gracl.h>
63572+#include <linux/grsecurity.h>
63573+#include <linux/grinternal.h>
63574+
63575+static struct crash_uid *uid_set;
63576+static unsigned short uid_used;
63577+static DEFINE_SPINLOCK(gr_uid_lock);
63578+extern rwlock_t gr_inode_lock;
63579+extern struct acl_subject_label *
63580+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
63581+ struct acl_role_label *role);
63582+
63583+#ifdef CONFIG_BTRFS_FS
63584+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
63585+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
63586+#endif
63587+
63588+static inline dev_t __get_dev(const struct dentry *dentry)
63589+{
63590+#ifdef CONFIG_BTRFS_FS
63591+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
63592+ return get_btrfs_dev_from_inode(dentry->d_inode);
63593+ else
63594+#endif
63595+ return dentry->d_inode->i_sb->s_dev;
63596+}
63597+
63598+int
63599+gr_init_uidset(void)
63600+{
63601+ uid_set =
63602+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
63603+ uid_used = 0;
63604+
63605+ return uid_set ? 1 : 0;
63606+}
63607+
63608+void
63609+gr_free_uidset(void)
63610+{
63611+ if (uid_set)
63612+ kfree(uid_set);
63613+
63614+ return;
63615+}
63616+
63617+int
63618+gr_find_uid(const uid_t uid)
63619+{
63620+ struct crash_uid *tmp = uid_set;
63621+ uid_t buid;
63622+ int low = 0, high = uid_used - 1, mid;
63623+
63624+ while (high >= low) {
63625+ mid = (low + high) >> 1;
63626+ buid = tmp[mid].uid;
63627+ if (buid == uid)
63628+ return mid;
63629+ if (buid > uid)
63630+ high = mid - 1;
63631+ if (buid < uid)
63632+ low = mid + 1;
63633+ }
63634+
63635+ return -1;
63636+}
63637+
63638+static __inline__ void
63639+gr_insertsort(void)
63640+{
63641+ unsigned short i, j;
63642+ struct crash_uid index;
63643+
63644+ for (i = 1; i < uid_used; i++) {
63645+ index = uid_set[i];
63646+ j = i;
63647+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
63648+ uid_set[j] = uid_set[j - 1];
63649+ j--;
63650+ }
63651+ uid_set[j] = index;
63652+ }
63653+
63654+ return;
63655+}
63656+
63657+static __inline__ void
63658+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
63659+{
63660+ int loc;
63661+ uid_t uid = GR_GLOBAL_UID(kuid);
63662+
63663+ if (uid_used == GR_UIDTABLE_MAX)
63664+ return;
63665+
63666+ loc = gr_find_uid(uid);
63667+
63668+ if (loc >= 0) {
63669+ uid_set[loc].expires = expires;
63670+ return;
63671+ }
63672+
63673+ uid_set[uid_used].uid = uid;
63674+ uid_set[uid_used].expires = expires;
63675+ uid_used++;
63676+
63677+ gr_insertsort();
63678+
63679+ return;
63680+}
63681+
63682+void
63683+gr_remove_uid(const unsigned short loc)
63684+{
63685+ unsigned short i;
63686+
63687+ for (i = loc + 1; i < uid_used; i++)
63688+ uid_set[i - 1] = uid_set[i];
63689+
63690+ uid_used--;
63691+
63692+ return;
63693+}
63694+
63695+int
63696+gr_check_crash_uid(const kuid_t kuid)
63697+{
63698+ int loc;
63699+ int ret = 0;
63700+ uid_t uid;
63701+
63702+ if (unlikely(!gr_acl_is_enabled()))
63703+ return 0;
63704+
63705+ uid = GR_GLOBAL_UID(kuid);
63706+
63707+ spin_lock(&gr_uid_lock);
63708+ loc = gr_find_uid(uid);
63709+
63710+ if (loc < 0)
63711+ goto out_unlock;
63712+
63713+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
63714+ gr_remove_uid(loc);
63715+ else
63716+ ret = 1;
63717+
63718+out_unlock:
63719+ spin_unlock(&gr_uid_lock);
63720+ return ret;
63721+}
63722+
63723+static __inline__ int
63724+proc_is_setxid(const struct cred *cred)
63725+{
63726+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
63727+ !uid_eq(cred->uid, cred->fsuid))
63728+ return 1;
63729+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
63730+ !gid_eq(cred->gid, cred->fsgid))
63731+ return 1;
63732+
63733+ return 0;
63734+}
63735+
63736+extern int gr_fake_force_sig(int sig, struct task_struct *t);
63737+
63738+void
63739+gr_handle_crash(struct task_struct *task, const int sig)
63740+{
63741+ struct acl_subject_label *curr;
63742+ struct task_struct *tsk, *tsk2;
63743+ const struct cred *cred;
63744+ const struct cred *cred2;
63745+
63746+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
63747+ return;
63748+
63749+ if (unlikely(!gr_acl_is_enabled()))
63750+ return;
63751+
63752+ curr = task->acl;
63753+
63754+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
63755+ return;
63756+
63757+ if (time_before_eq(curr->expires, get_seconds())) {
63758+ curr->expires = 0;
63759+ curr->crashes = 0;
63760+ }
63761+
63762+ curr->crashes++;
63763+
63764+ if (!curr->expires)
63765+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
63766+
63767+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
63768+ time_after(curr->expires, get_seconds())) {
63769+ rcu_read_lock();
63770+ cred = __task_cred(task);
63771+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
63772+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
63773+ spin_lock(&gr_uid_lock);
63774+ gr_insert_uid(cred->uid, curr->expires);
63775+ spin_unlock(&gr_uid_lock);
63776+ curr->expires = 0;
63777+ curr->crashes = 0;
63778+ read_lock(&tasklist_lock);
63779+ do_each_thread(tsk2, tsk) {
63780+ cred2 = __task_cred(tsk);
63781+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
63782+ gr_fake_force_sig(SIGKILL, tsk);
63783+ } while_each_thread(tsk2, tsk);
63784+ read_unlock(&tasklist_lock);
63785+ } else {
63786+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
63787+ read_lock(&tasklist_lock);
63788+ read_lock(&grsec_exec_file_lock);
63789+ do_each_thread(tsk2, tsk) {
63790+ if (likely(tsk != task)) {
63791+ // if this thread has the same subject as the one that triggered
63792+ // RES_CRASH and it's the same binary, kill it
63793+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
63794+ gr_fake_force_sig(SIGKILL, tsk);
63795+ }
63796+ } while_each_thread(tsk2, tsk);
63797+ read_unlock(&grsec_exec_file_lock);
63798+ read_unlock(&tasklist_lock);
63799+ }
63800+ rcu_read_unlock();
63801+ }
63802+
63803+ return;
63804+}
63805+
63806+int
63807+gr_check_crash_exec(const struct file *filp)
63808+{
63809+ struct acl_subject_label *curr;
63810+
63811+ if (unlikely(!gr_acl_is_enabled()))
63812+ return 0;
63813+
63814+ read_lock(&gr_inode_lock);
63815+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
63816+ __get_dev(filp->f_path.dentry),
63817+ current->role);
63818+ read_unlock(&gr_inode_lock);
63819+
63820+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
63821+ (!curr->crashes && !curr->expires))
63822+ return 0;
63823+
63824+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
63825+ time_after(curr->expires, get_seconds()))
63826+ return 1;
63827+ else if (time_before_eq(curr->expires, get_seconds())) {
63828+ curr->crashes = 0;
63829+ curr->expires = 0;
63830+ }
63831+
63832+ return 0;
63833+}
63834+
63835+void
63836+gr_handle_alertkill(struct task_struct *task)
63837+{
63838+ struct acl_subject_label *curracl;
63839+ __u32 curr_ip;
63840+ struct task_struct *p, *p2;
63841+
63842+ if (unlikely(!gr_acl_is_enabled()))
63843+ return;
63844+
63845+ curracl = task->acl;
63846+ curr_ip = task->signal->curr_ip;
63847+
63848+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
63849+ read_lock(&tasklist_lock);
63850+ do_each_thread(p2, p) {
63851+ if (p->signal->curr_ip == curr_ip)
63852+ gr_fake_force_sig(SIGKILL, p);
63853+ } while_each_thread(p2, p);
63854+ read_unlock(&tasklist_lock);
63855+ } else if (curracl->mode & GR_KILLPROC)
63856+ gr_fake_force_sig(SIGKILL, task);
63857+
63858+ return;
63859+}
63860diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
63861new file mode 100644
63862index 0000000..98011b0
63863--- /dev/null
63864+++ b/grsecurity/gracl_shm.c
63865@@ -0,0 +1,40 @@
63866+#include <linux/kernel.h>
63867+#include <linux/mm.h>
63868+#include <linux/sched.h>
63869+#include <linux/file.h>
63870+#include <linux/ipc.h>
63871+#include <linux/gracl.h>
63872+#include <linux/grsecurity.h>
63873+#include <linux/grinternal.h>
63874+
63875+int
63876+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
63877+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
63878+{
63879+ struct task_struct *task;
63880+
63881+ if (!gr_acl_is_enabled())
63882+ return 1;
63883+
63884+ rcu_read_lock();
63885+ read_lock(&tasklist_lock);
63886+
63887+ task = find_task_by_vpid(shm_cprid);
63888+
63889+ if (unlikely(!task))
63890+ task = find_task_by_vpid(shm_lapid);
63891+
63892+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
63893+ (task_pid_nr(task) == shm_lapid)) &&
63894+ (task->acl->mode & GR_PROTSHM) &&
63895+ (task->acl != current->acl))) {
63896+ read_unlock(&tasklist_lock);
63897+ rcu_read_unlock();
63898+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
63899+ return 0;
63900+ }
63901+ read_unlock(&tasklist_lock);
63902+ rcu_read_unlock();
63903+
63904+ return 1;
63905+}
63906diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
63907new file mode 100644
63908index 0000000..bc0be01
63909--- /dev/null
63910+++ b/grsecurity/grsec_chdir.c
63911@@ -0,0 +1,19 @@
63912+#include <linux/kernel.h>
63913+#include <linux/sched.h>
63914+#include <linux/fs.h>
63915+#include <linux/file.h>
63916+#include <linux/grsecurity.h>
63917+#include <linux/grinternal.h>
63918+
63919+void
63920+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
63921+{
63922+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
63923+ if ((grsec_enable_chdir && grsec_enable_group &&
63924+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
63925+ !grsec_enable_group)) {
63926+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
63927+ }
63928+#endif
63929+ return;
63930+}
63931diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
63932new file mode 100644
63933index 0000000..6d2de57
63934--- /dev/null
63935+++ b/grsecurity/grsec_chroot.c
63936@@ -0,0 +1,357 @@
63937+#include <linux/kernel.h>
63938+#include <linux/module.h>
63939+#include <linux/sched.h>
63940+#include <linux/file.h>
63941+#include <linux/fs.h>
63942+#include <linux/mount.h>
63943+#include <linux/types.h>
63944+#include "../fs/mount.h"
63945+#include <linux/grsecurity.h>
63946+#include <linux/grinternal.h>
63947+
63948+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
63949+{
63950+#ifdef CONFIG_GRKERNSEC
63951+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
63952+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
63953+ task->gr_is_chrooted = 1;
63954+ else
63955+ task->gr_is_chrooted = 0;
63956+
63957+ task->gr_chroot_dentry = path->dentry;
63958+#endif
63959+ return;
63960+}
63961+
63962+void gr_clear_chroot_entries(struct task_struct *task)
63963+{
63964+#ifdef CONFIG_GRKERNSEC
63965+ task->gr_is_chrooted = 0;
63966+ task->gr_chroot_dentry = NULL;
63967+#endif
63968+ return;
63969+}
63970+
63971+int
63972+gr_handle_chroot_unix(const pid_t pid)
63973+{
63974+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
63975+ struct task_struct *p;
63976+
63977+ if (unlikely(!grsec_enable_chroot_unix))
63978+ return 1;
63979+
63980+ if (likely(!proc_is_chrooted(current)))
63981+ return 1;
63982+
63983+ rcu_read_lock();
63984+ read_lock(&tasklist_lock);
63985+ p = find_task_by_vpid_unrestricted(pid);
63986+ if (unlikely(p && !have_same_root(current, p))) {
63987+ read_unlock(&tasklist_lock);
63988+ rcu_read_unlock();
63989+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
63990+ return 0;
63991+ }
63992+ read_unlock(&tasklist_lock);
63993+ rcu_read_unlock();
63994+#endif
63995+ return 1;
63996+}
63997+
63998+int
63999+gr_handle_chroot_nice(void)
64000+{
64001+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
64002+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
64003+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
64004+ return -EPERM;
64005+ }
64006+#endif
64007+ return 0;
64008+}
64009+
64010+int
64011+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
64012+{
64013+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
64014+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
64015+ && proc_is_chrooted(current)) {
64016+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
64017+ return -EACCES;
64018+ }
64019+#endif
64020+ return 0;
64021+}
64022+
64023+int
64024+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
64025+{
64026+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64027+ struct task_struct *p;
64028+ int ret = 0;
64029+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
64030+ return ret;
64031+
64032+ read_lock(&tasklist_lock);
64033+ do_each_pid_task(pid, type, p) {
64034+ if (!have_same_root(current, p)) {
64035+ ret = 1;
64036+ goto out;
64037+ }
64038+ } while_each_pid_task(pid, type, p);
64039+out:
64040+ read_unlock(&tasklist_lock);
64041+ return ret;
64042+#endif
64043+ return 0;
64044+}
64045+
64046+int
64047+gr_pid_is_chrooted(struct task_struct *p)
64048+{
64049+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64050+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
64051+ return 0;
64052+
64053+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
64054+ !have_same_root(current, p)) {
64055+ return 1;
64056+ }
64057+#endif
64058+ return 0;
64059+}
64060+
64061+EXPORT_SYMBOL(gr_pid_is_chrooted);
64062+
64063+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
64064+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
64065+{
64066+ struct path path, currentroot;
64067+ int ret = 0;
64068+
64069+ path.dentry = (struct dentry *)u_dentry;
64070+ path.mnt = (struct vfsmount *)u_mnt;
64071+ get_fs_root(current->fs, &currentroot);
64072+ if (path_is_under(&path, &currentroot))
64073+ ret = 1;
64074+ path_put(&currentroot);
64075+
64076+ return ret;
64077+}
64078+#endif
64079+
64080+int
64081+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
64082+{
64083+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
64084+ if (!grsec_enable_chroot_fchdir)
64085+ return 1;
64086+
64087+ if (!proc_is_chrooted(current))
64088+ return 1;
64089+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
64090+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
64091+ return 0;
64092+ }
64093+#endif
64094+ return 1;
64095+}
64096+
64097+int
64098+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64099+ const time_t shm_createtime)
64100+{
64101+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
64102+ struct task_struct *p;
64103+ time_t starttime;
64104+
64105+ if (unlikely(!grsec_enable_chroot_shmat))
64106+ return 1;
64107+
64108+ if (likely(!proc_is_chrooted(current)))
64109+ return 1;
64110+
64111+ rcu_read_lock();
64112+ read_lock(&tasklist_lock);
64113+
64114+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
64115+ starttime = p->start_time.tv_sec;
64116+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
64117+ if (have_same_root(current, p)) {
64118+ goto allow;
64119+ } else {
64120+ read_unlock(&tasklist_lock);
64121+ rcu_read_unlock();
64122+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
64123+ return 0;
64124+ }
64125+ }
64126+ /* creator exited, pid reuse, fall through to next check */
64127+ }
64128+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
64129+ if (unlikely(!have_same_root(current, p))) {
64130+ read_unlock(&tasklist_lock);
64131+ rcu_read_unlock();
64132+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
64133+ return 0;
64134+ }
64135+ }
64136+
64137+allow:
64138+ read_unlock(&tasklist_lock);
64139+ rcu_read_unlock();
64140+#endif
64141+ return 1;
64142+}
64143+
64144+void
64145+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
64146+{
64147+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
64148+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
64149+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
64150+#endif
64151+ return;
64152+}
64153+
64154+int
64155+gr_handle_chroot_mknod(const struct dentry *dentry,
64156+ const struct vfsmount *mnt, const int mode)
64157+{
64158+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
64159+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
64160+ proc_is_chrooted(current)) {
64161+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
64162+ return -EPERM;
64163+ }
64164+#endif
64165+ return 0;
64166+}
64167+
64168+int
64169+gr_handle_chroot_mount(const struct dentry *dentry,
64170+ const struct vfsmount *mnt, const char *dev_name)
64171+{
64172+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
64173+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
64174+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
64175+ return -EPERM;
64176+ }
64177+#endif
64178+ return 0;
64179+}
64180+
64181+int
64182+gr_handle_chroot_pivot(void)
64183+{
64184+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
64185+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
64186+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
64187+ return -EPERM;
64188+ }
64189+#endif
64190+ return 0;
64191+}
64192+
64193+int
64194+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
64195+{
64196+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
64197+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
64198+ !gr_is_outside_chroot(dentry, mnt)) {
64199+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
64200+ return -EPERM;
64201+ }
64202+#endif
64203+ return 0;
64204+}
64205+
64206+extern const char *captab_log[];
64207+extern int captab_log_entries;
64208+
64209+int
64210+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
64211+{
64212+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64213+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
64214+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
64215+ if (cap_raised(chroot_caps, cap)) {
64216+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
64217+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
64218+ }
64219+ return 0;
64220+ }
64221+ }
64222+#endif
64223+ return 1;
64224+}
64225+
64226+int
64227+gr_chroot_is_capable(const int cap)
64228+{
64229+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64230+ return gr_task_chroot_is_capable(current, current_cred(), cap);
64231+#endif
64232+ return 1;
64233+}
64234+
64235+int
64236+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
64237+{
64238+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64239+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
64240+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
64241+ if (cap_raised(chroot_caps, cap)) {
64242+ return 0;
64243+ }
64244+ }
64245+#endif
64246+ return 1;
64247+}
64248+
64249+int
64250+gr_chroot_is_capable_nolog(const int cap)
64251+{
64252+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64253+ return gr_task_chroot_is_capable_nolog(current, cap);
64254+#endif
64255+ return 1;
64256+}
64257+
64258+int
64259+gr_handle_chroot_sysctl(const int op)
64260+{
64261+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
64262+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
64263+ proc_is_chrooted(current))
64264+ return -EACCES;
64265+#endif
64266+ return 0;
64267+}
64268+
64269+void
64270+gr_handle_chroot_chdir(struct path *path)
64271+{
64272+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
64273+ if (grsec_enable_chroot_chdir)
64274+ set_fs_pwd(current->fs, path);
64275+#endif
64276+ return;
64277+}
64278+
64279+int
64280+gr_handle_chroot_chmod(const struct dentry *dentry,
64281+ const struct vfsmount *mnt, const int mode)
64282+{
64283+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
64284+ /* allow chmod +s on directories, but not files */
64285+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
64286+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
64287+ proc_is_chrooted(current)) {
64288+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
64289+ return -EPERM;
64290+ }
64291+#endif
64292+ return 0;
64293+}
64294diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
64295new file mode 100644
64296index 0000000..207d409
64297--- /dev/null
64298+++ b/grsecurity/grsec_disabled.c
64299@@ -0,0 +1,434 @@
64300+#include <linux/kernel.h>
64301+#include <linux/module.h>
64302+#include <linux/sched.h>
64303+#include <linux/file.h>
64304+#include <linux/fs.h>
64305+#include <linux/kdev_t.h>
64306+#include <linux/net.h>
64307+#include <linux/in.h>
64308+#include <linux/ip.h>
64309+#include <linux/skbuff.h>
64310+#include <linux/sysctl.h>
64311+
64312+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
64313+void
64314+pax_set_initial_flags(struct linux_binprm *bprm)
64315+{
64316+ return;
64317+}
64318+#endif
64319+
64320+#ifdef CONFIG_SYSCTL
64321+__u32
64322+gr_handle_sysctl(const struct ctl_table * table, const int op)
64323+{
64324+ return 0;
64325+}
64326+#endif
64327+
64328+#ifdef CONFIG_TASKSTATS
64329+int gr_is_taskstats_denied(int pid)
64330+{
64331+ return 0;
64332+}
64333+#endif
64334+
64335+int
64336+gr_acl_is_enabled(void)
64337+{
64338+ return 0;
64339+}
64340+
64341+void
64342+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
64343+{
64344+ return;
64345+}
64346+
64347+int
64348+gr_handle_rawio(const struct inode *inode)
64349+{
64350+ return 0;
64351+}
64352+
64353+void
64354+gr_acl_handle_psacct(struct task_struct *task, const long code)
64355+{
64356+ return;
64357+}
64358+
64359+int
64360+gr_handle_ptrace(struct task_struct *task, const long request)
64361+{
64362+ return 0;
64363+}
64364+
64365+int
64366+gr_handle_proc_ptrace(struct task_struct *task)
64367+{
64368+ return 0;
64369+}
64370+
64371+int
64372+gr_set_acls(const int type)
64373+{
64374+ return 0;
64375+}
64376+
64377+int
64378+gr_check_hidden_task(const struct task_struct *tsk)
64379+{
64380+ return 0;
64381+}
64382+
64383+int
64384+gr_check_protected_task(const struct task_struct *task)
64385+{
64386+ return 0;
64387+}
64388+
64389+int
64390+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
64391+{
64392+ return 0;
64393+}
64394+
64395+void
64396+gr_copy_label(struct task_struct *tsk)
64397+{
64398+ return;
64399+}
64400+
64401+void
64402+gr_set_pax_flags(struct task_struct *task)
64403+{
64404+ return;
64405+}
64406+
64407+int
64408+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
64409+ const int unsafe_share)
64410+{
64411+ return 0;
64412+}
64413+
64414+void
64415+gr_handle_delete(const ino_t ino, const dev_t dev)
64416+{
64417+ return;
64418+}
64419+
64420+void
64421+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
64422+{
64423+ return;
64424+}
64425+
64426+void
64427+gr_handle_crash(struct task_struct *task, const int sig)
64428+{
64429+ return;
64430+}
64431+
64432+int
64433+gr_check_crash_exec(const struct file *filp)
64434+{
64435+ return 0;
64436+}
64437+
64438+int
64439+gr_check_crash_uid(const kuid_t uid)
64440+{
64441+ return 0;
64442+}
64443+
64444+void
64445+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
64446+ struct dentry *old_dentry,
64447+ struct dentry *new_dentry,
64448+ struct vfsmount *mnt, const __u8 replace)
64449+{
64450+ return;
64451+}
64452+
64453+int
64454+gr_search_socket(const int family, const int type, const int protocol)
64455+{
64456+ return 1;
64457+}
64458+
64459+int
64460+gr_search_connectbind(const int mode, const struct socket *sock,
64461+ const struct sockaddr_in *addr)
64462+{
64463+ return 0;
64464+}
64465+
64466+void
64467+gr_handle_alertkill(struct task_struct *task)
64468+{
64469+ return;
64470+}
64471+
64472+__u32
64473+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
64474+{
64475+ return 1;
64476+}
64477+
64478+__u32
64479+gr_acl_handle_hidden_file(const struct dentry * dentry,
64480+ const struct vfsmount * mnt)
64481+{
64482+ return 1;
64483+}
64484+
64485+__u32
64486+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
64487+ int acc_mode)
64488+{
64489+ return 1;
64490+}
64491+
64492+__u32
64493+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
64494+{
64495+ return 1;
64496+}
64497+
64498+__u32
64499+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
64500+{
64501+ return 1;
64502+}
64503+
64504+int
64505+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
64506+ unsigned int *vm_flags)
64507+{
64508+ return 1;
64509+}
64510+
64511+__u32
64512+gr_acl_handle_truncate(const struct dentry * dentry,
64513+ const struct vfsmount * mnt)
64514+{
64515+ return 1;
64516+}
64517+
64518+__u32
64519+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
64520+{
64521+ return 1;
64522+}
64523+
64524+__u32
64525+gr_acl_handle_access(const struct dentry * dentry,
64526+ const struct vfsmount * mnt, const int fmode)
64527+{
64528+ return 1;
64529+}
64530+
64531+__u32
64532+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
64533+ umode_t *mode)
64534+{
64535+ return 1;
64536+}
64537+
64538+__u32
64539+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
64540+{
64541+ return 1;
64542+}
64543+
64544+__u32
64545+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
64546+{
64547+ return 1;
64548+}
64549+
64550+void
64551+grsecurity_init(void)
64552+{
64553+ return;
64554+}
64555+
64556+umode_t gr_acl_umask(void)
64557+{
64558+ return 0;
64559+}
64560+
64561+__u32
64562+gr_acl_handle_mknod(const struct dentry * new_dentry,
64563+ const struct dentry * parent_dentry,
64564+ const struct vfsmount * parent_mnt,
64565+ const int mode)
64566+{
64567+ return 1;
64568+}
64569+
64570+__u32
64571+gr_acl_handle_mkdir(const struct dentry * new_dentry,
64572+ const struct dentry * parent_dentry,
64573+ const struct vfsmount * parent_mnt)
64574+{
64575+ return 1;
64576+}
64577+
64578+__u32
64579+gr_acl_handle_symlink(const struct dentry * new_dentry,
64580+ const struct dentry * parent_dentry,
64581+ const struct vfsmount * parent_mnt, const struct filename *from)
64582+{
64583+ return 1;
64584+}
64585+
64586+__u32
64587+gr_acl_handle_link(const struct dentry * new_dentry,
64588+ const struct dentry * parent_dentry,
64589+ const struct vfsmount * parent_mnt,
64590+ const struct dentry * old_dentry,
64591+ const struct vfsmount * old_mnt, const struct filename *to)
64592+{
64593+ return 1;
64594+}
64595+
64596+int
64597+gr_acl_handle_rename(const struct dentry *new_dentry,
64598+ const struct dentry *parent_dentry,
64599+ const struct vfsmount *parent_mnt,
64600+ const struct dentry *old_dentry,
64601+ const struct inode *old_parent_inode,
64602+ const struct vfsmount *old_mnt, const struct filename *newname)
64603+{
64604+ return 0;
64605+}
64606+
64607+int
64608+gr_acl_handle_filldir(const struct file *file, const char *name,
64609+ const int namelen, const ino_t ino)
64610+{
64611+ return 1;
64612+}
64613+
64614+int
64615+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64616+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
64617+{
64618+ return 1;
64619+}
64620+
64621+int
64622+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
64623+{
64624+ return 0;
64625+}
64626+
64627+int
64628+gr_search_accept(const struct socket *sock)
64629+{
64630+ return 0;
64631+}
64632+
64633+int
64634+gr_search_listen(const struct socket *sock)
64635+{
64636+ return 0;
64637+}
64638+
64639+int
64640+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
64641+{
64642+ return 0;
64643+}
64644+
64645+__u32
64646+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
64647+{
64648+ return 1;
64649+}
64650+
64651+__u32
64652+gr_acl_handle_creat(const struct dentry * dentry,
64653+ const struct dentry * p_dentry,
64654+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
64655+ const int imode)
64656+{
64657+ return 1;
64658+}
64659+
64660+void
64661+gr_acl_handle_exit(void)
64662+{
64663+ return;
64664+}
64665+
64666+int
64667+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
64668+{
64669+ return 1;
64670+}
64671+
64672+void
64673+gr_set_role_label(const kuid_t uid, const kgid_t gid)
64674+{
64675+ return;
64676+}
64677+
64678+int
64679+gr_acl_handle_procpidmem(const struct task_struct *task)
64680+{
64681+ return 0;
64682+}
64683+
64684+int
64685+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
64686+{
64687+ return 0;
64688+}
64689+
64690+int
64691+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
64692+{
64693+ return 0;
64694+}
64695+
64696+void
64697+gr_set_kernel_label(struct task_struct *task)
64698+{
64699+ return;
64700+}
64701+
64702+int
64703+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
64704+{
64705+ return 0;
64706+}
64707+
64708+int
64709+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
64710+{
64711+ return 0;
64712+}
64713+
64714+int gr_acl_enable_at_secure(void)
64715+{
64716+ return 0;
64717+}
64718+
64719+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
64720+{
64721+ return dentry->d_inode->i_sb->s_dev;
64722+}
64723+
64724+void gr_put_exec_file(struct task_struct *task)
64725+{
64726+ return;
64727+}
64728+
64729+EXPORT_SYMBOL(gr_set_kernel_label);
64730+#ifdef CONFIG_SECURITY
64731+EXPORT_SYMBOL(gr_check_user_change);
64732+EXPORT_SYMBOL(gr_check_group_change);
64733+#endif
64734diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
64735new file mode 100644
64736index 0000000..387032b
64737--- /dev/null
64738+++ b/grsecurity/grsec_exec.c
64739@@ -0,0 +1,187 @@
64740+#include <linux/kernel.h>
64741+#include <linux/sched.h>
64742+#include <linux/file.h>
64743+#include <linux/binfmts.h>
64744+#include <linux/fs.h>
64745+#include <linux/types.h>
64746+#include <linux/grdefs.h>
64747+#include <linux/grsecurity.h>
64748+#include <linux/grinternal.h>
64749+#include <linux/capability.h>
64750+#include <linux/module.h>
64751+#include <linux/compat.h>
64752+
64753+#include <asm/uaccess.h>
64754+
64755+#ifdef CONFIG_GRKERNSEC_EXECLOG
64756+static char gr_exec_arg_buf[132];
64757+static DEFINE_MUTEX(gr_exec_arg_mutex);
64758+#endif
64759+
64760+struct user_arg_ptr {
64761+#ifdef CONFIG_COMPAT
64762+ bool is_compat;
64763+#endif
64764+ union {
64765+ const char __user *const __user *native;
64766+#ifdef CONFIG_COMPAT
64767+ const compat_uptr_t __user *compat;
64768+#endif
64769+ } ptr;
64770+};
64771+
64772+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
64773+
64774+void
64775+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
64776+{
64777+#ifdef CONFIG_GRKERNSEC_EXECLOG
64778+ char *grarg = gr_exec_arg_buf;
64779+ unsigned int i, x, execlen = 0;
64780+ char c;
64781+
64782+ if (!((grsec_enable_execlog && grsec_enable_group &&
64783+ in_group_p(grsec_audit_gid))
64784+ || (grsec_enable_execlog && !grsec_enable_group)))
64785+ return;
64786+
64787+ mutex_lock(&gr_exec_arg_mutex);
64788+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
64789+
64790+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
64791+ const char __user *p;
64792+ unsigned int len;
64793+
64794+ p = get_user_arg_ptr(argv, i);
64795+ if (IS_ERR(p))
64796+ goto log;
64797+
64798+ len = strnlen_user(p, 128 - execlen);
64799+ if (len > 128 - execlen)
64800+ len = 128 - execlen;
64801+ else if (len > 0)
64802+ len--;
64803+ if (copy_from_user(grarg + execlen, p, len))
64804+ goto log;
64805+
64806+ /* rewrite unprintable characters */
64807+ for (x = 0; x < len; x++) {
64808+ c = *(grarg + execlen + x);
64809+ if (c < 32 || c > 126)
64810+ *(grarg + execlen + x) = ' ';
64811+ }
64812+
64813+ execlen += len;
64814+ *(grarg + execlen) = ' ';
64815+ *(grarg + execlen + 1) = '\0';
64816+ execlen++;
64817+ }
64818+
64819+ log:
64820+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
64821+ bprm->file->f_path.mnt, grarg);
64822+ mutex_unlock(&gr_exec_arg_mutex);
64823+#endif
64824+ return;
64825+}
64826+
64827+#ifdef CONFIG_GRKERNSEC
64828+extern int gr_acl_is_capable(const int cap);
64829+extern int gr_acl_is_capable_nolog(const int cap);
64830+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
64831+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
64832+extern int gr_chroot_is_capable(const int cap);
64833+extern int gr_chroot_is_capable_nolog(const int cap);
64834+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
64835+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
64836+#endif
64837+
64838+const char *captab_log[] = {
64839+ "CAP_CHOWN",
64840+ "CAP_DAC_OVERRIDE",
64841+ "CAP_DAC_READ_SEARCH",
64842+ "CAP_FOWNER",
64843+ "CAP_FSETID",
64844+ "CAP_KILL",
64845+ "CAP_SETGID",
64846+ "CAP_SETUID",
64847+ "CAP_SETPCAP",
64848+ "CAP_LINUX_IMMUTABLE",
64849+ "CAP_NET_BIND_SERVICE",
64850+ "CAP_NET_BROADCAST",
64851+ "CAP_NET_ADMIN",
64852+ "CAP_NET_RAW",
64853+ "CAP_IPC_LOCK",
64854+ "CAP_IPC_OWNER",
64855+ "CAP_SYS_MODULE",
64856+ "CAP_SYS_RAWIO",
64857+ "CAP_SYS_CHROOT",
64858+ "CAP_SYS_PTRACE",
64859+ "CAP_SYS_PACCT",
64860+ "CAP_SYS_ADMIN",
64861+ "CAP_SYS_BOOT",
64862+ "CAP_SYS_NICE",
64863+ "CAP_SYS_RESOURCE",
64864+ "CAP_SYS_TIME",
64865+ "CAP_SYS_TTY_CONFIG",
64866+ "CAP_MKNOD",
64867+ "CAP_LEASE",
64868+ "CAP_AUDIT_WRITE",
64869+ "CAP_AUDIT_CONTROL",
64870+ "CAP_SETFCAP",
64871+ "CAP_MAC_OVERRIDE",
64872+ "CAP_MAC_ADMIN",
64873+ "CAP_SYSLOG",
64874+ "CAP_WAKE_ALARM"
64875+};
64876+
64877+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
64878+
64879+int gr_is_capable(const int cap)
64880+{
64881+#ifdef CONFIG_GRKERNSEC
64882+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
64883+ return 1;
64884+ return 0;
64885+#else
64886+ return 1;
64887+#endif
64888+}
64889+
64890+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
64891+{
64892+#ifdef CONFIG_GRKERNSEC
64893+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
64894+ return 1;
64895+ return 0;
64896+#else
64897+ return 1;
64898+#endif
64899+}
64900+
64901+int gr_is_capable_nolog(const int cap)
64902+{
64903+#ifdef CONFIG_GRKERNSEC
64904+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
64905+ return 1;
64906+ return 0;
64907+#else
64908+ return 1;
64909+#endif
64910+}
64911+
64912+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
64913+{
64914+#ifdef CONFIG_GRKERNSEC
64915+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
64916+ return 1;
64917+ return 0;
64918+#else
64919+ return 1;
64920+#endif
64921+}
64922+
64923+EXPORT_SYMBOL(gr_is_capable);
64924+EXPORT_SYMBOL(gr_is_capable_nolog);
64925+EXPORT_SYMBOL(gr_task_is_capable);
64926+EXPORT_SYMBOL(gr_task_is_capable_nolog);
64927diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
64928new file mode 100644
64929index 0000000..06cc6ea
64930--- /dev/null
64931+++ b/grsecurity/grsec_fifo.c
64932@@ -0,0 +1,24 @@
64933+#include <linux/kernel.h>
64934+#include <linux/sched.h>
64935+#include <linux/fs.h>
64936+#include <linux/file.h>
64937+#include <linux/grinternal.h>
64938+
64939+int
64940+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
64941+ const struct dentry *dir, const int flag, const int acc_mode)
64942+{
64943+#ifdef CONFIG_GRKERNSEC_FIFO
64944+ const struct cred *cred = current_cred();
64945+
64946+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
64947+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
64948+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
64949+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
64950+ if (!inode_permission(dentry->d_inode, acc_mode))
64951+ 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));
64952+ return -EACCES;
64953+ }
64954+#endif
64955+ return 0;
64956+}
64957diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
64958new file mode 100644
64959index 0000000..8ca18bf
64960--- /dev/null
64961+++ b/grsecurity/grsec_fork.c
64962@@ -0,0 +1,23 @@
64963+#include <linux/kernel.h>
64964+#include <linux/sched.h>
64965+#include <linux/grsecurity.h>
64966+#include <linux/grinternal.h>
64967+#include <linux/errno.h>
64968+
64969+void
64970+gr_log_forkfail(const int retval)
64971+{
64972+#ifdef CONFIG_GRKERNSEC_FORKFAIL
64973+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
64974+ switch (retval) {
64975+ case -EAGAIN:
64976+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
64977+ break;
64978+ case -ENOMEM:
64979+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
64980+ break;
64981+ }
64982+ }
64983+#endif
64984+ return;
64985+}
64986diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
64987new file mode 100644
64988index 0000000..a862e9f
64989--- /dev/null
64990+++ b/grsecurity/grsec_init.c
64991@@ -0,0 +1,283 @@
64992+#include <linux/kernel.h>
64993+#include <linux/sched.h>
64994+#include <linux/mm.h>
64995+#include <linux/gracl.h>
64996+#include <linux/slab.h>
64997+#include <linux/vmalloc.h>
64998+#include <linux/percpu.h>
64999+#include <linux/module.h>
65000+
65001+int grsec_enable_ptrace_readexec;
65002+int grsec_enable_setxid;
65003+int grsec_enable_symlinkown;
65004+kgid_t grsec_symlinkown_gid;
65005+int grsec_enable_brute;
65006+int grsec_enable_link;
65007+int grsec_enable_dmesg;
65008+int grsec_enable_harden_ptrace;
65009+int grsec_enable_fifo;
65010+int grsec_enable_execlog;
65011+int grsec_enable_signal;
65012+int grsec_enable_forkfail;
65013+int grsec_enable_audit_ptrace;
65014+int grsec_enable_time;
65015+int grsec_enable_audit_textrel;
65016+int grsec_enable_group;
65017+kgid_t grsec_audit_gid;
65018+int grsec_enable_chdir;
65019+int grsec_enable_mount;
65020+int grsec_enable_rofs;
65021+int grsec_enable_chroot_findtask;
65022+int grsec_enable_chroot_mount;
65023+int grsec_enable_chroot_shmat;
65024+int grsec_enable_chroot_fchdir;
65025+int grsec_enable_chroot_double;
65026+int grsec_enable_chroot_pivot;
65027+int grsec_enable_chroot_chdir;
65028+int grsec_enable_chroot_chmod;
65029+int grsec_enable_chroot_mknod;
65030+int grsec_enable_chroot_nice;
65031+int grsec_enable_chroot_execlog;
65032+int grsec_enable_chroot_caps;
65033+int grsec_enable_chroot_sysctl;
65034+int grsec_enable_chroot_unix;
65035+int grsec_enable_tpe;
65036+kgid_t grsec_tpe_gid;
65037+int grsec_enable_blackhole;
65038+#ifdef CONFIG_IPV6_MODULE
65039+EXPORT_SYMBOL(grsec_enable_blackhole);
65040+#endif
65041+int grsec_lastack_retries;
65042+int grsec_enable_tpe_all;
65043+int grsec_enable_tpe_invert;
65044+int grsec_enable_socket_all;
65045+kgid_t grsec_socket_all_gid;
65046+int grsec_enable_socket_client;
65047+kgid_t grsec_socket_client_gid;
65048+int grsec_enable_socket_server;
65049+kgid_t grsec_socket_server_gid;
65050+int grsec_resource_logging;
65051+int grsec_disable_privio;
65052+int grsec_enable_log_rwxmaps;
65053+int grsec_lock;
65054+
65055+DEFINE_SPINLOCK(grsec_alert_lock);
65056+unsigned long grsec_alert_wtime = 0;
65057+unsigned long grsec_alert_fyet = 0;
65058+
65059+DEFINE_SPINLOCK(grsec_audit_lock);
65060+
65061+DEFINE_RWLOCK(grsec_exec_file_lock);
65062+
65063+char *gr_shared_page[4];
65064+
65065+char *gr_alert_log_fmt;
65066+char *gr_audit_log_fmt;
65067+char *gr_alert_log_buf;
65068+char *gr_audit_log_buf;
65069+
65070+extern struct gr_arg *gr_usermode;
65071+extern unsigned char *gr_system_salt;
65072+extern unsigned char *gr_system_sum;
65073+
65074+void __init
65075+grsecurity_init(void)
65076+{
65077+ int j;
65078+ /* create the per-cpu shared pages */
65079+
65080+#ifdef CONFIG_X86
65081+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
65082+#endif
65083+
65084+ for (j = 0; j < 4; j++) {
65085+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
65086+ if (gr_shared_page[j] == NULL) {
65087+ panic("Unable to allocate grsecurity shared page");
65088+ return;
65089+ }
65090+ }
65091+
65092+ /* allocate log buffers */
65093+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
65094+ if (!gr_alert_log_fmt) {
65095+ panic("Unable to allocate grsecurity alert log format buffer");
65096+ return;
65097+ }
65098+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
65099+ if (!gr_audit_log_fmt) {
65100+ panic("Unable to allocate grsecurity audit log format buffer");
65101+ return;
65102+ }
65103+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
65104+ if (!gr_alert_log_buf) {
65105+ panic("Unable to allocate grsecurity alert log buffer");
65106+ return;
65107+ }
65108+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
65109+ if (!gr_audit_log_buf) {
65110+ panic("Unable to allocate grsecurity audit log buffer");
65111+ return;
65112+ }
65113+
65114+ /* allocate memory for authentication structure */
65115+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
65116+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
65117+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
65118+
65119+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
65120+ panic("Unable to allocate grsecurity authentication structure");
65121+ return;
65122+ }
65123+
65124+
65125+#ifdef CONFIG_GRKERNSEC_IO
65126+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
65127+ grsec_disable_privio = 1;
65128+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
65129+ grsec_disable_privio = 1;
65130+#else
65131+ grsec_disable_privio = 0;
65132+#endif
65133+#endif
65134+
65135+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
65136+ /* for backward compatibility, tpe_invert always defaults to on if
65137+ enabled in the kernel
65138+ */
65139+ grsec_enable_tpe_invert = 1;
65140+#endif
65141+
65142+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
65143+#ifndef CONFIG_GRKERNSEC_SYSCTL
65144+ grsec_lock = 1;
65145+#endif
65146+
65147+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
65148+ grsec_enable_audit_textrel = 1;
65149+#endif
65150+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65151+ grsec_enable_log_rwxmaps = 1;
65152+#endif
65153+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
65154+ grsec_enable_group = 1;
65155+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
65156+#endif
65157+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
65158+ grsec_enable_ptrace_readexec = 1;
65159+#endif
65160+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
65161+ grsec_enable_chdir = 1;
65162+#endif
65163+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65164+ grsec_enable_harden_ptrace = 1;
65165+#endif
65166+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65167+ grsec_enable_mount = 1;
65168+#endif
65169+#ifdef CONFIG_GRKERNSEC_LINK
65170+ grsec_enable_link = 1;
65171+#endif
65172+#ifdef CONFIG_GRKERNSEC_BRUTE
65173+ grsec_enable_brute = 1;
65174+#endif
65175+#ifdef CONFIG_GRKERNSEC_DMESG
65176+ grsec_enable_dmesg = 1;
65177+#endif
65178+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
65179+ grsec_enable_blackhole = 1;
65180+ grsec_lastack_retries = 4;
65181+#endif
65182+#ifdef CONFIG_GRKERNSEC_FIFO
65183+ grsec_enable_fifo = 1;
65184+#endif
65185+#ifdef CONFIG_GRKERNSEC_EXECLOG
65186+ grsec_enable_execlog = 1;
65187+#endif
65188+#ifdef CONFIG_GRKERNSEC_SETXID
65189+ grsec_enable_setxid = 1;
65190+#endif
65191+#ifdef CONFIG_GRKERNSEC_SIGNAL
65192+ grsec_enable_signal = 1;
65193+#endif
65194+#ifdef CONFIG_GRKERNSEC_FORKFAIL
65195+ grsec_enable_forkfail = 1;
65196+#endif
65197+#ifdef CONFIG_GRKERNSEC_TIME
65198+ grsec_enable_time = 1;
65199+#endif
65200+#ifdef CONFIG_GRKERNSEC_RESLOG
65201+ grsec_resource_logging = 1;
65202+#endif
65203+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
65204+ grsec_enable_chroot_findtask = 1;
65205+#endif
65206+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
65207+ grsec_enable_chroot_unix = 1;
65208+#endif
65209+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
65210+ grsec_enable_chroot_mount = 1;
65211+#endif
65212+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
65213+ grsec_enable_chroot_fchdir = 1;
65214+#endif
65215+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
65216+ grsec_enable_chroot_shmat = 1;
65217+#endif
65218+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
65219+ grsec_enable_audit_ptrace = 1;
65220+#endif
65221+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
65222+ grsec_enable_chroot_double = 1;
65223+#endif
65224+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
65225+ grsec_enable_chroot_pivot = 1;
65226+#endif
65227+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
65228+ grsec_enable_chroot_chdir = 1;
65229+#endif
65230+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
65231+ grsec_enable_chroot_chmod = 1;
65232+#endif
65233+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
65234+ grsec_enable_chroot_mknod = 1;
65235+#endif
65236+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
65237+ grsec_enable_chroot_nice = 1;
65238+#endif
65239+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
65240+ grsec_enable_chroot_execlog = 1;
65241+#endif
65242+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
65243+ grsec_enable_chroot_caps = 1;
65244+#endif
65245+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
65246+ grsec_enable_chroot_sysctl = 1;
65247+#endif
65248+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
65249+ grsec_enable_symlinkown = 1;
65250+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
65251+#endif
65252+#ifdef CONFIG_GRKERNSEC_TPE
65253+ grsec_enable_tpe = 1;
65254+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
65255+#ifdef CONFIG_GRKERNSEC_TPE_ALL
65256+ grsec_enable_tpe_all = 1;
65257+#endif
65258+#endif
65259+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
65260+ grsec_enable_socket_all = 1;
65261+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
65262+#endif
65263+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
65264+ grsec_enable_socket_client = 1;
65265+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
65266+#endif
65267+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
65268+ grsec_enable_socket_server = 1;
65269+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
65270+#endif
65271+#endif
65272+
65273+ return;
65274+}
65275diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
65276new file mode 100644
65277index 0000000..5e05e20
65278--- /dev/null
65279+++ b/grsecurity/grsec_link.c
65280@@ -0,0 +1,58 @@
65281+#include <linux/kernel.h>
65282+#include <linux/sched.h>
65283+#include <linux/fs.h>
65284+#include <linux/file.h>
65285+#include <linux/grinternal.h>
65286+
65287+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
65288+{
65289+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
65290+ const struct inode *link_inode = link->dentry->d_inode;
65291+
65292+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
65293+ /* ignore root-owned links, e.g. /proc/self */
65294+ gr_is_global_nonroot(link_inode->i_uid) && target &&
65295+ !uid_eq(link_inode->i_uid, target->i_uid)) {
65296+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
65297+ return 1;
65298+ }
65299+#endif
65300+ return 0;
65301+}
65302+
65303+int
65304+gr_handle_follow_link(const struct inode *parent,
65305+ const struct inode *inode,
65306+ const struct dentry *dentry, const struct vfsmount *mnt)
65307+{
65308+#ifdef CONFIG_GRKERNSEC_LINK
65309+ const struct cred *cred = current_cred();
65310+
65311+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
65312+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
65313+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
65314+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
65315+ return -EACCES;
65316+ }
65317+#endif
65318+ return 0;
65319+}
65320+
65321+int
65322+gr_handle_hardlink(const struct dentry *dentry,
65323+ const struct vfsmount *mnt,
65324+ struct inode *inode, const int mode, const struct filename *to)
65325+{
65326+#ifdef CONFIG_GRKERNSEC_LINK
65327+ const struct cred *cred = current_cred();
65328+
65329+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
65330+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
65331+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
65332+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
65333+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
65334+ return -EPERM;
65335+ }
65336+#endif
65337+ return 0;
65338+}
65339diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
65340new file mode 100644
65341index 0000000..7c06085
65342--- /dev/null
65343+++ b/grsecurity/grsec_log.c
65344@@ -0,0 +1,326 @@
65345+#include <linux/kernel.h>
65346+#include <linux/sched.h>
65347+#include <linux/file.h>
65348+#include <linux/tty.h>
65349+#include <linux/fs.h>
65350+#include <linux/grinternal.h>
65351+
65352+#ifdef CONFIG_TREE_PREEMPT_RCU
65353+#define DISABLE_PREEMPT() preempt_disable()
65354+#define ENABLE_PREEMPT() preempt_enable()
65355+#else
65356+#define DISABLE_PREEMPT()
65357+#define ENABLE_PREEMPT()
65358+#endif
65359+
65360+#define BEGIN_LOCKS(x) \
65361+ DISABLE_PREEMPT(); \
65362+ rcu_read_lock(); \
65363+ read_lock(&tasklist_lock); \
65364+ read_lock(&grsec_exec_file_lock); \
65365+ if (x != GR_DO_AUDIT) \
65366+ spin_lock(&grsec_alert_lock); \
65367+ else \
65368+ spin_lock(&grsec_audit_lock)
65369+
65370+#define END_LOCKS(x) \
65371+ if (x != GR_DO_AUDIT) \
65372+ spin_unlock(&grsec_alert_lock); \
65373+ else \
65374+ spin_unlock(&grsec_audit_lock); \
65375+ read_unlock(&grsec_exec_file_lock); \
65376+ read_unlock(&tasklist_lock); \
65377+ rcu_read_unlock(); \
65378+ ENABLE_PREEMPT(); \
65379+ if (x == GR_DONT_AUDIT) \
65380+ gr_handle_alertkill(current)
65381+
65382+enum {
65383+ FLOODING,
65384+ NO_FLOODING
65385+};
65386+
65387+extern char *gr_alert_log_fmt;
65388+extern char *gr_audit_log_fmt;
65389+extern char *gr_alert_log_buf;
65390+extern char *gr_audit_log_buf;
65391+
65392+static int gr_log_start(int audit)
65393+{
65394+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
65395+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
65396+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65397+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
65398+ unsigned long curr_secs = get_seconds();
65399+
65400+ if (audit == GR_DO_AUDIT)
65401+ goto set_fmt;
65402+
65403+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
65404+ grsec_alert_wtime = curr_secs;
65405+ grsec_alert_fyet = 0;
65406+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
65407+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
65408+ grsec_alert_fyet++;
65409+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
65410+ grsec_alert_wtime = curr_secs;
65411+ grsec_alert_fyet++;
65412+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
65413+ return FLOODING;
65414+ }
65415+ else return FLOODING;
65416+
65417+set_fmt:
65418+#endif
65419+ memset(buf, 0, PAGE_SIZE);
65420+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
65421+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
65422+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
65423+ } else if (current->signal->curr_ip) {
65424+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
65425+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
65426+ } else if (gr_acl_is_enabled()) {
65427+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
65428+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
65429+ } else {
65430+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
65431+ strcpy(buf, fmt);
65432+ }
65433+
65434+ return NO_FLOODING;
65435+}
65436+
65437+static void gr_log_middle(int audit, const char *msg, va_list ap)
65438+ __attribute__ ((format (printf, 2, 0)));
65439+
65440+static void gr_log_middle(int audit, const char *msg, va_list ap)
65441+{
65442+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65443+ unsigned int len = strlen(buf);
65444+
65445+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
65446+
65447+ return;
65448+}
65449+
65450+static void gr_log_middle_varargs(int audit, const char *msg, ...)
65451+ __attribute__ ((format (printf, 2, 3)));
65452+
65453+static void gr_log_middle_varargs(int audit, const char *msg, ...)
65454+{
65455+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65456+ unsigned int len = strlen(buf);
65457+ va_list ap;
65458+
65459+ va_start(ap, msg);
65460+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
65461+ va_end(ap);
65462+
65463+ return;
65464+}
65465+
65466+static void gr_log_end(int audit, int append_default)
65467+{
65468+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65469+ if (append_default) {
65470+ struct task_struct *task = current;
65471+ struct task_struct *parent = task->real_parent;
65472+ const struct cred *cred = __task_cred(task);
65473+ const struct cred *pcred = __task_cred(parent);
65474+ unsigned int len = strlen(buf);
65475+
65476+ 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));
65477+ }
65478+
65479+ printk("%s\n", buf);
65480+
65481+ return;
65482+}
65483+
65484+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
65485+{
65486+ int logtype;
65487+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
65488+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
65489+ void *voidptr = NULL;
65490+ int num1 = 0, num2 = 0;
65491+ unsigned long ulong1 = 0, ulong2 = 0;
65492+ struct dentry *dentry = NULL;
65493+ struct vfsmount *mnt = NULL;
65494+ struct file *file = NULL;
65495+ struct task_struct *task = NULL;
65496+ const struct cred *cred, *pcred;
65497+ va_list ap;
65498+
65499+ BEGIN_LOCKS(audit);
65500+ logtype = gr_log_start(audit);
65501+ if (logtype == FLOODING) {
65502+ END_LOCKS(audit);
65503+ return;
65504+ }
65505+ va_start(ap, argtypes);
65506+ switch (argtypes) {
65507+ case GR_TTYSNIFF:
65508+ task = va_arg(ap, struct task_struct *);
65509+ 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));
65510+ break;
65511+ case GR_SYSCTL_HIDDEN:
65512+ str1 = va_arg(ap, char *);
65513+ gr_log_middle_varargs(audit, msg, result, str1);
65514+ break;
65515+ case GR_RBAC:
65516+ dentry = va_arg(ap, struct dentry *);
65517+ mnt = va_arg(ap, struct vfsmount *);
65518+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
65519+ break;
65520+ case GR_RBAC_STR:
65521+ dentry = va_arg(ap, struct dentry *);
65522+ mnt = va_arg(ap, struct vfsmount *);
65523+ str1 = va_arg(ap, char *);
65524+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
65525+ break;
65526+ case GR_STR_RBAC:
65527+ str1 = va_arg(ap, char *);
65528+ dentry = va_arg(ap, struct dentry *);
65529+ mnt = va_arg(ap, struct vfsmount *);
65530+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
65531+ break;
65532+ case GR_RBAC_MODE2:
65533+ dentry = va_arg(ap, struct dentry *);
65534+ mnt = va_arg(ap, struct vfsmount *);
65535+ str1 = va_arg(ap, char *);
65536+ str2 = va_arg(ap, char *);
65537+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
65538+ break;
65539+ case GR_RBAC_MODE3:
65540+ dentry = va_arg(ap, struct dentry *);
65541+ mnt = va_arg(ap, struct vfsmount *);
65542+ str1 = va_arg(ap, char *);
65543+ str2 = va_arg(ap, char *);
65544+ str3 = va_arg(ap, char *);
65545+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
65546+ break;
65547+ case GR_FILENAME:
65548+ dentry = va_arg(ap, struct dentry *);
65549+ mnt = va_arg(ap, struct vfsmount *);
65550+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
65551+ break;
65552+ case GR_STR_FILENAME:
65553+ str1 = va_arg(ap, char *);
65554+ dentry = va_arg(ap, struct dentry *);
65555+ mnt = va_arg(ap, struct vfsmount *);
65556+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
65557+ break;
65558+ case GR_FILENAME_STR:
65559+ dentry = va_arg(ap, struct dentry *);
65560+ mnt = va_arg(ap, struct vfsmount *);
65561+ str1 = va_arg(ap, char *);
65562+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
65563+ break;
65564+ case GR_FILENAME_TWO_INT:
65565+ dentry = va_arg(ap, struct dentry *);
65566+ mnt = va_arg(ap, struct vfsmount *);
65567+ num1 = va_arg(ap, int);
65568+ num2 = va_arg(ap, int);
65569+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
65570+ break;
65571+ case GR_FILENAME_TWO_INT_STR:
65572+ dentry = va_arg(ap, struct dentry *);
65573+ mnt = va_arg(ap, struct vfsmount *);
65574+ num1 = va_arg(ap, int);
65575+ num2 = va_arg(ap, int);
65576+ str1 = va_arg(ap, char *);
65577+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
65578+ break;
65579+ case GR_TEXTREL:
65580+ file = va_arg(ap, struct file *);
65581+ ulong1 = va_arg(ap, unsigned long);
65582+ ulong2 = va_arg(ap, unsigned long);
65583+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
65584+ break;
65585+ case GR_PTRACE:
65586+ task = va_arg(ap, struct task_struct *);
65587+ 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));
65588+ break;
65589+ case GR_RESOURCE:
65590+ task = va_arg(ap, struct task_struct *);
65591+ cred = __task_cred(task);
65592+ pcred = __task_cred(task->real_parent);
65593+ ulong1 = va_arg(ap, unsigned long);
65594+ str1 = va_arg(ap, char *);
65595+ ulong2 = va_arg(ap, unsigned long);
65596+ 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));
65597+ break;
65598+ case GR_CAP:
65599+ task = va_arg(ap, struct task_struct *);
65600+ cred = __task_cred(task);
65601+ pcred = __task_cred(task->real_parent);
65602+ str1 = va_arg(ap, char *);
65603+ 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));
65604+ break;
65605+ case GR_SIG:
65606+ str1 = va_arg(ap, char *);
65607+ voidptr = va_arg(ap, void *);
65608+ gr_log_middle_varargs(audit, msg, str1, voidptr);
65609+ break;
65610+ case GR_SIG2:
65611+ task = va_arg(ap, struct task_struct *);
65612+ cred = __task_cred(task);
65613+ pcred = __task_cred(task->real_parent);
65614+ num1 = va_arg(ap, int);
65615+ 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));
65616+ break;
65617+ case GR_CRASH1:
65618+ task = va_arg(ap, struct task_struct *);
65619+ cred = __task_cred(task);
65620+ pcred = __task_cred(task->real_parent);
65621+ ulong1 = va_arg(ap, unsigned long);
65622+ 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);
65623+ break;
65624+ case GR_CRASH2:
65625+ task = va_arg(ap, struct task_struct *);
65626+ cred = __task_cred(task);
65627+ pcred = __task_cred(task->real_parent);
65628+ ulong1 = va_arg(ap, unsigned long);
65629+ 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);
65630+ break;
65631+ case GR_RWXMAP:
65632+ file = va_arg(ap, struct file *);
65633+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
65634+ break;
65635+ case GR_PSACCT:
65636+ {
65637+ unsigned int wday, cday;
65638+ __u8 whr, chr;
65639+ __u8 wmin, cmin;
65640+ __u8 wsec, csec;
65641+ char cur_tty[64] = { 0 };
65642+ char parent_tty[64] = { 0 };
65643+
65644+ task = va_arg(ap, struct task_struct *);
65645+ wday = va_arg(ap, unsigned int);
65646+ cday = va_arg(ap, unsigned int);
65647+ whr = va_arg(ap, int);
65648+ chr = va_arg(ap, int);
65649+ wmin = va_arg(ap, int);
65650+ cmin = va_arg(ap, int);
65651+ wsec = va_arg(ap, int);
65652+ csec = va_arg(ap, int);
65653+ ulong1 = va_arg(ap, unsigned long);
65654+ cred = __task_cred(task);
65655+ pcred = __task_cred(task->real_parent);
65656+
65657+ 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));
65658+ }
65659+ break;
65660+ default:
65661+ gr_log_middle(audit, msg, ap);
65662+ }
65663+ va_end(ap);
65664+ // these don't need DEFAULTSECARGS printed on the end
65665+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
65666+ gr_log_end(audit, 0);
65667+ else
65668+ gr_log_end(audit, 1);
65669+ END_LOCKS(audit);
65670+}
65671diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
65672new file mode 100644
65673index 0000000..f536303
65674--- /dev/null
65675+++ b/grsecurity/grsec_mem.c
65676@@ -0,0 +1,40 @@
65677+#include <linux/kernel.h>
65678+#include <linux/sched.h>
65679+#include <linux/mm.h>
65680+#include <linux/mman.h>
65681+#include <linux/grinternal.h>
65682+
65683+void
65684+gr_handle_ioperm(void)
65685+{
65686+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
65687+ return;
65688+}
65689+
65690+void
65691+gr_handle_iopl(void)
65692+{
65693+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
65694+ return;
65695+}
65696+
65697+void
65698+gr_handle_mem_readwrite(u64 from, u64 to)
65699+{
65700+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
65701+ return;
65702+}
65703+
65704+void
65705+gr_handle_vm86(void)
65706+{
65707+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
65708+ return;
65709+}
65710+
65711+void
65712+gr_log_badprocpid(const char *entry)
65713+{
65714+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
65715+ return;
65716+}
65717diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
65718new file mode 100644
65719index 0000000..2131422
65720--- /dev/null
65721+++ b/grsecurity/grsec_mount.c
65722@@ -0,0 +1,62 @@
65723+#include <linux/kernel.h>
65724+#include <linux/sched.h>
65725+#include <linux/mount.h>
65726+#include <linux/grsecurity.h>
65727+#include <linux/grinternal.h>
65728+
65729+void
65730+gr_log_remount(const char *devname, const int retval)
65731+{
65732+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65733+ if (grsec_enable_mount && (retval >= 0))
65734+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
65735+#endif
65736+ return;
65737+}
65738+
65739+void
65740+gr_log_unmount(const char *devname, const int retval)
65741+{
65742+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65743+ if (grsec_enable_mount && (retval >= 0))
65744+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
65745+#endif
65746+ return;
65747+}
65748+
65749+void
65750+gr_log_mount(const char *from, const char *to, const int retval)
65751+{
65752+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65753+ if (grsec_enable_mount && (retval >= 0))
65754+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
65755+#endif
65756+ return;
65757+}
65758+
65759+int
65760+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
65761+{
65762+#ifdef CONFIG_GRKERNSEC_ROFS
65763+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
65764+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
65765+ return -EPERM;
65766+ } else
65767+ return 0;
65768+#endif
65769+ return 0;
65770+}
65771+
65772+int
65773+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
65774+{
65775+#ifdef CONFIG_GRKERNSEC_ROFS
65776+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
65777+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
65778+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
65779+ return -EPERM;
65780+ } else
65781+ return 0;
65782+#endif
65783+ return 0;
65784+}
65785diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
65786new file mode 100644
65787index 0000000..a3b12a0
65788--- /dev/null
65789+++ b/grsecurity/grsec_pax.c
65790@@ -0,0 +1,36 @@
65791+#include <linux/kernel.h>
65792+#include <linux/sched.h>
65793+#include <linux/mm.h>
65794+#include <linux/file.h>
65795+#include <linux/grinternal.h>
65796+#include <linux/grsecurity.h>
65797+
65798+void
65799+gr_log_textrel(struct vm_area_struct * vma)
65800+{
65801+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
65802+ if (grsec_enable_audit_textrel)
65803+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
65804+#endif
65805+ return;
65806+}
65807+
65808+void
65809+gr_log_rwxmmap(struct file *file)
65810+{
65811+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65812+ if (grsec_enable_log_rwxmaps)
65813+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
65814+#endif
65815+ return;
65816+}
65817+
65818+void
65819+gr_log_rwxmprotect(struct file *file)
65820+{
65821+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65822+ if (grsec_enable_log_rwxmaps)
65823+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
65824+#endif
65825+ return;
65826+}
65827diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
65828new file mode 100644
65829index 0000000..f7f29aa
65830--- /dev/null
65831+++ b/grsecurity/grsec_ptrace.c
65832@@ -0,0 +1,30 @@
65833+#include <linux/kernel.h>
65834+#include <linux/sched.h>
65835+#include <linux/grinternal.h>
65836+#include <linux/security.h>
65837+
65838+void
65839+gr_audit_ptrace(struct task_struct *task)
65840+{
65841+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
65842+ if (grsec_enable_audit_ptrace)
65843+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
65844+#endif
65845+ return;
65846+}
65847+
65848+int
65849+gr_ptrace_readexec(struct file *file, int unsafe_flags)
65850+{
65851+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
65852+ const struct dentry *dentry = file->f_path.dentry;
65853+ const struct vfsmount *mnt = file->f_path.mnt;
65854+
65855+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
65856+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
65857+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
65858+ return -EACCES;
65859+ }
65860+#endif
65861+ return 0;
65862+}
65863diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
65864new file mode 100644
65865index 0000000..e09715a
65866--- /dev/null
65867+++ b/grsecurity/grsec_sig.c
65868@@ -0,0 +1,222 @@
65869+#include <linux/kernel.h>
65870+#include <linux/sched.h>
65871+#include <linux/delay.h>
65872+#include <linux/grsecurity.h>
65873+#include <linux/grinternal.h>
65874+#include <linux/hardirq.h>
65875+
65876+char *signames[] = {
65877+ [SIGSEGV] = "Segmentation fault",
65878+ [SIGILL] = "Illegal instruction",
65879+ [SIGABRT] = "Abort",
65880+ [SIGBUS] = "Invalid alignment/Bus error"
65881+};
65882+
65883+void
65884+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
65885+{
65886+#ifdef CONFIG_GRKERNSEC_SIGNAL
65887+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
65888+ (sig == SIGABRT) || (sig == SIGBUS))) {
65889+ if (task_pid_nr(t) == task_pid_nr(current)) {
65890+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
65891+ } else {
65892+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
65893+ }
65894+ }
65895+#endif
65896+ return;
65897+}
65898+
65899+int
65900+gr_handle_signal(const struct task_struct *p, const int sig)
65901+{
65902+#ifdef CONFIG_GRKERNSEC
65903+ /* ignore the 0 signal for protected task checks */
65904+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
65905+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
65906+ return -EPERM;
65907+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
65908+ return -EPERM;
65909+ }
65910+#endif
65911+ return 0;
65912+}
65913+
65914+#ifdef CONFIG_GRKERNSEC
65915+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
65916+
65917+int gr_fake_force_sig(int sig, struct task_struct *t)
65918+{
65919+ unsigned long int flags;
65920+ int ret, blocked, ignored;
65921+ struct k_sigaction *action;
65922+
65923+ spin_lock_irqsave(&t->sighand->siglock, flags);
65924+ action = &t->sighand->action[sig-1];
65925+ ignored = action->sa.sa_handler == SIG_IGN;
65926+ blocked = sigismember(&t->blocked, sig);
65927+ if (blocked || ignored) {
65928+ action->sa.sa_handler = SIG_DFL;
65929+ if (blocked) {
65930+ sigdelset(&t->blocked, sig);
65931+ recalc_sigpending_and_wake(t);
65932+ }
65933+ }
65934+ if (action->sa.sa_handler == SIG_DFL)
65935+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
65936+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
65937+
65938+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
65939+
65940+ return ret;
65941+}
65942+#endif
65943+
65944+#ifdef CONFIG_GRKERNSEC_BRUTE
65945+#define GR_USER_BAN_TIME (15 * 60)
65946+#define GR_DAEMON_BRUTE_TIME (30 * 60)
65947+
65948+static int __get_dumpable(unsigned long mm_flags)
65949+{
65950+ int ret;
65951+
65952+ ret = mm_flags & MMF_DUMPABLE_MASK;
65953+ return (ret >= 2) ? 2 : ret;
65954+}
65955+#endif
65956+
65957+void gr_handle_brute_attach(unsigned long mm_flags)
65958+{
65959+#ifdef CONFIG_GRKERNSEC_BRUTE
65960+ struct task_struct *p = current;
65961+ kuid_t uid = GLOBAL_ROOT_UID;
65962+ int daemon = 0;
65963+
65964+ if (!grsec_enable_brute)
65965+ return;
65966+
65967+ rcu_read_lock();
65968+ read_lock(&tasklist_lock);
65969+ read_lock(&grsec_exec_file_lock);
65970+ if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
65971+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
65972+ p->real_parent->brute = 1;
65973+ daemon = 1;
65974+ } else {
65975+ const struct cred *cred = __task_cred(p), *cred2;
65976+ struct task_struct *tsk, *tsk2;
65977+
65978+ if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
65979+ struct user_struct *user;
65980+
65981+ uid = cred->uid;
65982+
65983+ /* this is put upon execution past expiration */
65984+ user = find_user(uid);
65985+ if (user == NULL)
65986+ goto unlock;
65987+ user->banned = 1;
65988+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
65989+ if (user->ban_expires == ~0UL)
65990+ user->ban_expires--;
65991+
65992+ do_each_thread(tsk2, tsk) {
65993+ cred2 = __task_cred(tsk);
65994+ if (tsk != p && uid_eq(cred2->uid, uid))
65995+ gr_fake_force_sig(SIGKILL, tsk);
65996+ } while_each_thread(tsk2, tsk);
65997+ }
65998+ }
65999+unlock:
66000+ read_unlock(&grsec_exec_file_lock);
66001+ read_unlock(&tasklist_lock);
66002+ rcu_read_unlock();
66003+
66004+ if (gr_is_global_nonroot(uid))
66005+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
66006+ GR_GLOBAL_UID(uid), GR_USER_BAN_TIME / 60);
66007+ else if (daemon)
66008+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
66009+
66010+#endif
66011+ return;
66012+}
66013+
66014+void gr_handle_brute_check(void)
66015+{
66016+#ifdef CONFIG_GRKERNSEC_BRUTE
66017+ struct task_struct *p = current;
66018+
66019+ if (unlikely(p->brute)) {
66020+ if (!grsec_enable_brute)
66021+ p->brute = 0;
66022+ else if (time_before(get_seconds(), p->brute_expires))
66023+ msleep(30 * 1000);
66024+ }
66025+#endif
66026+ return;
66027+}
66028+
66029+void gr_handle_kernel_exploit(void)
66030+{
66031+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
66032+ const struct cred *cred;
66033+ struct task_struct *tsk, *tsk2;
66034+ struct user_struct *user;
66035+ kuid_t uid;
66036+
66037+ if (in_irq() || in_serving_softirq() || in_nmi())
66038+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
66039+
66040+ uid = current_uid();
66041+
66042+ if (gr_is_global_root(uid))
66043+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
66044+ else {
66045+ /* kill all the processes of this user, hold a reference
66046+ to their creds struct, and prevent them from creating
66047+ another process until system reset
66048+ */
66049+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
66050+ GR_GLOBAL_UID(uid));
66051+ /* we intentionally leak this ref */
66052+ user = get_uid(current->cred->user);
66053+ if (user) {
66054+ user->banned = 1;
66055+ user->ban_expires = ~0UL;
66056+ }
66057+
66058+ read_lock(&tasklist_lock);
66059+ do_each_thread(tsk2, tsk) {
66060+ cred = __task_cred(tsk);
66061+ if (uid_eq(cred->uid, uid))
66062+ gr_fake_force_sig(SIGKILL, tsk);
66063+ } while_each_thread(tsk2, tsk);
66064+ read_unlock(&tasklist_lock);
66065+ }
66066+#endif
66067+}
66068+
66069+int __gr_process_user_ban(struct user_struct *user)
66070+{
66071+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
66072+ if (unlikely(user->banned)) {
66073+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
66074+ user->banned = 0;
66075+ user->ban_expires = 0;
66076+ free_uid(user);
66077+ } else
66078+ return -EPERM;
66079+ }
66080+#endif
66081+ return 0;
66082+}
66083+
66084+int gr_process_user_ban(void)
66085+{
66086+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
66087+ return __gr_process_user_ban(current->cred->user);
66088+#endif
66089+ return 0;
66090+}
66091diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
66092new file mode 100644
66093index 0000000..4030d57
66094--- /dev/null
66095+++ b/grsecurity/grsec_sock.c
66096@@ -0,0 +1,244 @@
66097+#include <linux/kernel.h>
66098+#include <linux/module.h>
66099+#include <linux/sched.h>
66100+#include <linux/file.h>
66101+#include <linux/net.h>
66102+#include <linux/in.h>
66103+#include <linux/ip.h>
66104+#include <net/sock.h>
66105+#include <net/inet_sock.h>
66106+#include <linux/grsecurity.h>
66107+#include <linux/grinternal.h>
66108+#include <linux/gracl.h>
66109+
66110+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
66111+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
66112+
66113+EXPORT_SYMBOL(gr_search_udp_recvmsg);
66114+EXPORT_SYMBOL(gr_search_udp_sendmsg);
66115+
66116+#ifdef CONFIG_UNIX_MODULE
66117+EXPORT_SYMBOL(gr_acl_handle_unix);
66118+EXPORT_SYMBOL(gr_acl_handle_mknod);
66119+EXPORT_SYMBOL(gr_handle_chroot_unix);
66120+EXPORT_SYMBOL(gr_handle_create);
66121+#endif
66122+
66123+#ifdef CONFIG_GRKERNSEC
66124+#define gr_conn_table_size 32749
66125+struct conn_table_entry {
66126+ struct conn_table_entry *next;
66127+ struct signal_struct *sig;
66128+};
66129+
66130+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
66131+DEFINE_SPINLOCK(gr_conn_table_lock);
66132+
66133+extern const char * gr_socktype_to_name(unsigned char type);
66134+extern const char * gr_proto_to_name(unsigned char proto);
66135+extern const char * gr_sockfamily_to_name(unsigned char family);
66136+
66137+static __inline__ int
66138+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
66139+{
66140+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
66141+}
66142+
66143+static __inline__ int
66144+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
66145+ __u16 sport, __u16 dport)
66146+{
66147+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
66148+ sig->gr_sport == sport && sig->gr_dport == dport))
66149+ return 1;
66150+ else
66151+ return 0;
66152+}
66153+
66154+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
66155+{
66156+ struct conn_table_entry **match;
66157+ unsigned int index;
66158+
66159+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
66160+ sig->gr_sport, sig->gr_dport,
66161+ gr_conn_table_size);
66162+
66163+ newent->sig = sig;
66164+
66165+ match = &gr_conn_table[index];
66166+ newent->next = *match;
66167+ *match = newent;
66168+
66169+ return;
66170+}
66171+
66172+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
66173+{
66174+ struct conn_table_entry *match, *last = NULL;
66175+ unsigned int index;
66176+
66177+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
66178+ sig->gr_sport, sig->gr_dport,
66179+ gr_conn_table_size);
66180+
66181+ match = gr_conn_table[index];
66182+ while (match && !conn_match(match->sig,
66183+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
66184+ sig->gr_dport)) {
66185+ last = match;
66186+ match = match->next;
66187+ }
66188+
66189+ if (match) {
66190+ if (last)
66191+ last->next = match->next;
66192+ else
66193+ gr_conn_table[index] = NULL;
66194+ kfree(match);
66195+ }
66196+
66197+ return;
66198+}
66199+
66200+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
66201+ __u16 sport, __u16 dport)
66202+{
66203+ struct conn_table_entry *match;
66204+ unsigned int index;
66205+
66206+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
66207+
66208+ match = gr_conn_table[index];
66209+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
66210+ match = match->next;
66211+
66212+ if (match)
66213+ return match->sig;
66214+ else
66215+ return NULL;
66216+}
66217+
66218+#endif
66219+
66220+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
66221+{
66222+#ifdef CONFIG_GRKERNSEC
66223+ struct signal_struct *sig = task->signal;
66224+ struct conn_table_entry *newent;
66225+
66226+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
66227+ if (newent == NULL)
66228+ return;
66229+ /* no bh lock needed since we are called with bh disabled */
66230+ spin_lock(&gr_conn_table_lock);
66231+ gr_del_task_from_ip_table_nolock(sig);
66232+ sig->gr_saddr = inet->inet_rcv_saddr;
66233+ sig->gr_daddr = inet->inet_daddr;
66234+ sig->gr_sport = inet->inet_sport;
66235+ sig->gr_dport = inet->inet_dport;
66236+ gr_add_to_task_ip_table_nolock(sig, newent);
66237+ spin_unlock(&gr_conn_table_lock);
66238+#endif
66239+ return;
66240+}
66241+
66242+void gr_del_task_from_ip_table(struct task_struct *task)
66243+{
66244+#ifdef CONFIG_GRKERNSEC
66245+ spin_lock_bh(&gr_conn_table_lock);
66246+ gr_del_task_from_ip_table_nolock(task->signal);
66247+ spin_unlock_bh(&gr_conn_table_lock);
66248+#endif
66249+ return;
66250+}
66251+
66252+void
66253+gr_attach_curr_ip(const struct sock *sk)
66254+{
66255+#ifdef CONFIG_GRKERNSEC
66256+ struct signal_struct *p, *set;
66257+ const struct inet_sock *inet = inet_sk(sk);
66258+
66259+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
66260+ return;
66261+
66262+ set = current->signal;
66263+
66264+ spin_lock_bh(&gr_conn_table_lock);
66265+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
66266+ inet->inet_dport, inet->inet_sport);
66267+ if (unlikely(p != NULL)) {
66268+ set->curr_ip = p->curr_ip;
66269+ set->used_accept = 1;
66270+ gr_del_task_from_ip_table_nolock(p);
66271+ spin_unlock_bh(&gr_conn_table_lock);
66272+ return;
66273+ }
66274+ spin_unlock_bh(&gr_conn_table_lock);
66275+
66276+ set->curr_ip = inet->inet_daddr;
66277+ set->used_accept = 1;
66278+#endif
66279+ return;
66280+}
66281+
66282+int
66283+gr_handle_sock_all(const int family, const int type, const int protocol)
66284+{
66285+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
66286+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
66287+ (family != AF_UNIX)) {
66288+ if (family == AF_INET)
66289+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
66290+ else
66291+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
66292+ return -EACCES;
66293+ }
66294+#endif
66295+ return 0;
66296+}
66297+
66298+int
66299+gr_handle_sock_server(const struct sockaddr *sck)
66300+{
66301+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
66302+ if (grsec_enable_socket_server &&
66303+ in_group_p(grsec_socket_server_gid) &&
66304+ sck && (sck->sa_family != AF_UNIX) &&
66305+ (sck->sa_family != AF_LOCAL)) {
66306+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
66307+ return -EACCES;
66308+ }
66309+#endif
66310+ return 0;
66311+}
66312+
66313+int
66314+gr_handle_sock_server_other(const struct sock *sck)
66315+{
66316+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
66317+ if (grsec_enable_socket_server &&
66318+ in_group_p(grsec_socket_server_gid) &&
66319+ sck && (sck->sk_family != AF_UNIX) &&
66320+ (sck->sk_family != AF_LOCAL)) {
66321+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
66322+ return -EACCES;
66323+ }
66324+#endif
66325+ return 0;
66326+}
66327+
66328+int
66329+gr_handle_sock_client(const struct sockaddr *sck)
66330+{
66331+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
66332+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
66333+ sck && (sck->sa_family != AF_UNIX) &&
66334+ (sck->sa_family != AF_LOCAL)) {
66335+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
66336+ return -EACCES;
66337+ }
66338+#endif
66339+ return 0;
66340+}
66341diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
66342new file mode 100644
66343index 0000000..f55ef0f
66344--- /dev/null
66345+++ b/grsecurity/grsec_sysctl.c
66346@@ -0,0 +1,469 @@
66347+#include <linux/kernel.h>
66348+#include <linux/sched.h>
66349+#include <linux/sysctl.h>
66350+#include <linux/grsecurity.h>
66351+#include <linux/grinternal.h>
66352+
66353+int
66354+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
66355+{
66356+#ifdef CONFIG_GRKERNSEC_SYSCTL
66357+ if (dirname == NULL || name == NULL)
66358+ return 0;
66359+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
66360+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
66361+ return -EACCES;
66362+ }
66363+#endif
66364+ return 0;
66365+}
66366+
66367+#ifdef CONFIG_GRKERNSEC_ROFS
66368+static int __maybe_unused one = 1;
66369+#endif
66370+
66371+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
66372+struct ctl_table grsecurity_table[] = {
66373+#ifdef CONFIG_GRKERNSEC_SYSCTL
66374+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
66375+#ifdef CONFIG_GRKERNSEC_IO
66376+ {
66377+ .procname = "disable_priv_io",
66378+ .data = &grsec_disable_privio,
66379+ .maxlen = sizeof(int),
66380+ .mode = 0600,
66381+ .proc_handler = &proc_dointvec,
66382+ },
66383+#endif
66384+#endif
66385+#ifdef CONFIG_GRKERNSEC_LINK
66386+ {
66387+ .procname = "linking_restrictions",
66388+ .data = &grsec_enable_link,
66389+ .maxlen = sizeof(int),
66390+ .mode = 0600,
66391+ .proc_handler = &proc_dointvec,
66392+ },
66393+#endif
66394+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
66395+ {
66396+ .procname = "enforce_symlinksifowner",
66397+ .data = &grsec_enable_symlinkown,
66398+ .maxlen = sizeof(int),
66399+ .mode = 0600,
66400+ .proc_handler = &proc_dointvec,
66401+ },
66402+ {
66403+ .procname = "symlinkown_gid",
66404+ .data = &grsec_symlinkown_gid,
66405+ .maxlen = sizeof(int),
66406+ .mode = 0600,
66407+ .proc_handler = &proc_dointvec,
66408+ },
66409+#endif
66410+#ifdef CONFIG_GRKERNSEC_BRUTE
66411+ {
66412+ .procname = "deter_bruteforce",
66413+ .data = &grsec_enable_brute,
66414+ .maxlen = sizeof(int),
66415+ .mode = 0600,
66416+ .proc_handler = &proc_dointvec,
66417+ },
66418+#endif
66419+#ifdef CONFIG_GRKERNSEC_FIFO
66420+ {
66421+ .procname = "fifo_restrictions",
66422+ .data = &grsec_enable_fifo,
66423+ .maxlen = sizeof(int),
66424+ .mode = 0600,
66425+ .proc_handler = &proc_dointvec,
66426+ },
66427+#endif
66428+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
66429+ {
66430+ .procname = "ptrace_readexec",
66431+ .data = &grsec_enable_ptrace_readexec,
66432+ .maxlen = sizeof(int),
66433+ .mode = 0600,
66434+ .proc_handler = &proc_dointvec,
66435+ },
66436+#endif
66437+#ifdef CONFIG_GRKERNSEC_SETXID
66438+ {
66439+ .procname = "consistent_setxid",
66440+ .data = &grsec_enable_setxid,
66441+ .maxlen = sizeof(int),
66442+ .mode = 0600,
66443+ .proc_handler = &proc_dointvec,
66444+ },
66445+#endif
66446+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
66447+ {
66448+ .procname = "ip_blackhole",
66449+ .data = &grsec_enable_blackhole,
66450+ .maxlen = sizeof(int),
66451+ .mode = 0600,
66452+ .proc_handler = &proc_dointvec,
66453+ },
66454+ {
66455+ .procname = "lastack_retries",
66456+ .data = &grsec_lastack_retries,
66457+ .maxlen = sizeof(int),
66458+ .mode = 0600,
66459+ .proc_handler = &proc_dointvec,
66460+ },
66461+#endif
66462+#ifdef CONFIG_GRKERNSEC_EXECLOG
66463+ {
66464+ .procname = "exec_logging",
66465+ .data = &grsec_enable_execlog,
66466+ .maxlen = sizeof(int),
66467+ .mode = 0600,
66468+ .proc_handler = &proc_dointvec,
66469+ },
66470+#endif
66471+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
66472+ {
66473+ .procname = "rwxmap_logging",
66474+ .data = &grsec_enable_log_rwxmaps,
66475+ .maxlen = sizeof(int),
66476+ .mode = 0600,
66477+ .proc_handler = &proc_dointvec,
66478+ },
66479+#endif
66480+#ifdef CONFIG_GRKERNSEC_SIGNAL
66481+ {
66482+ .procname = "signal_logging",
66483+ .data = &grsec_enable_signal,
66484+ .maxlen = sizeof(int),
66485+ .mode = 0600,
66486+ .proc_handler = &proc_dointvec,
66487+ },
66488+#endif
66489+#ifdef CONFIG_GRKERNSEC_FORKFAIL
66490+ {
66491+ .procname = "forkfail_logging",
66492+ .data = &grsec_enable_forkfail,
66493+ .maxlen = sizeof(int),
66494+ .mode = 0600,
66495+ .proc_handler = &proc_dointvec,
66496+ },
66497+#endif
66498+#ifdef CONFIG_GRKERNSEC_TIME
66499+ {
66500+ .procname = "timechange_logging",
66501+ .data = &grsec_enable_time,
66502+ .maxlen = sizeof(int),
66503+ .mode = 0600,
66504+ .proc_handler = &proc_dointvec,
66505+ },
66506+#endif
66507+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
66508+ {
66509+ .procname = "chroot_deny_shmat",
66510+ .data = &grsec_enable_chroot_shmat,
66511+ .maxlen = sizeof(int),
66512+ .mode = 0600,
66513+ .proc_handler = &proc_dointvec,
66514+ },
66515+#endif
66516+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
66517+ {
66518+ .procname = "chroot_deny_unix",
66519+ .data = &grsec_enable_chroot_unix,
66520+ .maxlen = sizeof(int),
66521+ .mode = 0600,
66522+ .proc_handler = &proc_dointvec,
66523+ },
66524+#endif
66525+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
66526+ {
66527+ .procname = "chroot_deny_mount",
66528+ .data = &grsec_enable_chroot_mount,
66529+ .maxlen = sizeof(int),
66530+ .mode = 0600,
66531+ .proc_handler = &proc_dointvec,
66532+ },
66533+#endif
66534+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
66535+ {
66536+ .procname = "chroot_deny_fchdir",
66537+ .data = &grsec_enable_chroot_fchdir,
66538+ .maxlen = sizeof(int),
66539+ .mode = 0600,
66540+ .proc_handler = &proc_dointvec,
66541+ },
66542+#endif
66543+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
66544+ {
66545+ .procname = "chroot_deny_chroot",
66546+ .data = &grsec_enable_chroot_double,
66547+ .maxlen = sizeof(int),
66548+ .mode = 0600,
66549+ .proc_handler = &proc_dointvec,
66550+ },
66551+#endif
66552+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
66553+ {
66554+ .procname = "chroot_deny_pivot",
66555+ .data = &grsec_enable_chroot_pivot,
66556+ .maxlen = sizeof(int),
66557+ .mode = 0600,
66558+ .proc_handler = &proc_dointvec,
66559+ },
66560+#endif
66561+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
66562+ {
66563+ .procname = "chroot_enforce_chdir",
66564+ .data = &grsec_enable_chroot_chdir,
66565+ .maxlen = sizeof(int),
66566+ .mode = 0600,
66567+ .proc_handler = &proc_dointvec,
66568+ },
66569+#endif
66570+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
66571+ {
66572+ .procname = "chroot_deny_chmod",
66573+ .data = &grsec_enable_chroot_chmod,
66574+ .maxlen = sizeof(int),
66575+ .mode = 0600,
66576+ .proc_handler = &proc_dointvec,
66577+ },
66578+#endif
66579+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
66580+ {
66581+ .procname = "chroot_deny_mknod",
66582+ .data = &grsec_enable_chroot_mknod,
66583+ .maxlen = sizeof(int),
66584+ .mode = 0600,
66585+ .proc_handler = &proc_dointvec,
66586+ },
66587+#endif
66588+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
66589+ {
66590+ .procname = "chroot_restrict_nice",
66591+ .data = &grsec_enable_chroot_nice,
66592+ .maxlen = sizeof(int),
66593+ .mode = 0600,
66594+ .proc_handler = &proc_dointvec,
66595+ },
66596+#endif
66597+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
66598+ {
66599+ .procname = "chroot_execlog",
66600+ .data = &grsec_enable_chroot_execlog,
66601+ .maxlen = sizeof(int),
66602+ .mode = 0600,
66603+ .proc_handler = &proc_dointvec,
66604+ },
66605+#endif
66606+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
66607+ {
66608+ .procname = "chroot_caps",
66609+ .data = &grsec_enable_chroot_caps,
66610+ .maxlen = sizeof(int),
66611+ .mode = 0600,
66612+ .proc_handler = &proc_dointvec,
66613+ },
66614+#endif
66615+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
66616+ {
66617+ .procname = "chroot_deny_sysctl",
66618+ .data = &grsec_enable_chroot_sysctl,
66619+ .maxlen = sizeof(int),
66620+ .mode = 0600,
66621+ .proc_handler = &proc_dointvec,
66622+ },
66623+#endif
66624+#ifdef CONFIG_GRKERNSEC_TPE
66625+ {
66626+ .procname = "tpe",
66627+ .data = &grsec_enable_tpe,
66628+ .maxlen = sizeof(int),
66629+ .mode = 0600,
66630+ .proc_handler = &proc_dointvec,
66631+ },
66632+ {
66633+ .procname = "tpe_gid",
66634+ .data = &grsec_tpe_gid,
66635+ .maxlen = sizeof(int),
66636+ .mode = 0600,
66637+ .proc_handler = &proc_dointvec,
66638+ },
66639+#endif
66640+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
66641+ {
66642+ .procname = "tpe_invert",
66643+ .data = &grsec_enable_tpe_invert,
66644+ .maxlen = sizeof(int),
66645+ .mode = 0600,
66646+ .proc_handler = &proc_dointvec,
66647+ },
66648+#endif
66649+#ifdef CONFIG_GRKERNSEC_TPE_ALL
66650+ {
66651+ .procname = "tpe_restrict_all",
66652+ .data = &grsec_enable_tpe_all,
66653+ .maxlen = sizeof(int),
66654+ .mode = 0600,
66655+ .proc_handler = &proc_dointvec,
66656+ },
66657+#endif
66658+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
66659+ {
66660+ .procname = "socket_all",
66661+ .data = &grsec_enable_socket_all,
66662+ .maxlen = sizeof(int),
66663+ .mode = 0600,
66664+ .proc_handler = &proc_dointvec,
66665+ },
66666+ {
66667+ .procname = "socket_all_gid",
66668+ .data = &grsec_socket_all_gid,
66669+ .maxlen = sizeof(int),
66670+ .mode = 0600,
66671+ .proc_handler = &proc_dointvec,
66672+ },
66673+#endif
66674+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
66675+ {
66676+ .procname = "socket_client",
66677+ .data = &grsec_enable_socket_client,
66678+ .maxlen = sizeof(int),
66679+ .mode = 0600,
66680+ .proc_handler = &proc_dointvec,
66681+ },
66682+ {
66683+ .procname = "socket_client_gid",
66684+ .data = &grsec_socket_client_gid,
66685+ .maxlen = sizeof(int),
66686+ .mode = 0600,
66687+ .proc_handler = &proc_dointvec,
66688+ },
66689+#endif
66690+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
66691+ {
66692+ .procname = "socket_server",
66693+ .data = &grsec_enable_socket_server,
66694+ .maxlen = sizeof(int),
66695+ .mode = 0600,
66696+ .proc_handler = &proc_dointvec,
66697+ },
66698+ {
66699+ .procname = "socket_server_gid",
66700+ .data = &grsec_socket_server_gid,
66701+ .maxlen = sizeof(int),
66702+ .mode = 0600,
66703+ .proc_handler = &proc_dointvec,
66704+ },
66705+#endif
66706+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
66707+ {
66708+ .procname = "audit_group",
66709+ .data = &grsec_enable_group,
66710+ .maxlen = sizeof(int),
66711+ .mode = 0600,
66712+ .proc_handler = &proc_dointvec,
66713+ },
66714+ {
66715+ .procname = "audit_gid",
66716+ .data = &grsec_audit_gid,
66717+ .maxlen = sizeof(int),
66718+ .mode = 0600,
66719+ .proc_handler = &proc_dointvec,
66720+ },
66721+#endif
66722+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
66723+ {
66724+ .procname = "audit_chdir",
66725+ .data = &grsec_enable_chdir,
66726+ .maxlen = sizeof(int),
66727+ .mode = 0600,
66728+ .proc_handler = &proc_dointvec,
66729+ },
66730+#endif
66731+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
66732+ {
66733+ .procname = "audit_mount",
66734+ .data = &grsec_enable_mount,
66735+ .maxlen = sizeof(int),
66736+ .mode = 0600,
66737+ .proc_handler = &proc_dointvec,
66738+ },
66739+#endif
66740+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
66741+ {
66742+ .procname = "audit_textrel",
66743+ .data = &grsec_enable_audit_textrel,
66744+ .maxlen = sizeof(int),
66745+ .mode = 0600,
66746+ .proc_handler = &proc_dointvec,
66747+ },
66748+#endif
66749+#ifdef CONFIG_GRKERNSEC_DMESG
66750+ {
66751+ .procname = "dmesg",
66752+ .data = &grsec_enable_dmesg,
66753+ .maxlen = sizeof(int),
66754+ .mode = 0600,
66755+ .proc_handler = &proc_dointvec,
66756+ },
66757+#endif
66758+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
66759+ {
66760+ .procname = "chroot_findtask",
66761+ .data = &grsec_enable_chroot_findtask,
66762+ .maxlen = sizeof(int),
66763+ .mode = 0600,
66764+ .proc_handler = &proc_dointvec,
66765+ },
66766+#endif
66767+#ifdef CONFIG_GRKERNSEC_RESLOG
66768+ {
66769+ .procname = "resource_logging",
66770+ .data = &grsec_resource_logging,
66771+ .maxlen = sizeof(int),
66772+ .mode = 0600,
66773+ .proc_handler = &proc_dointvec,
66774+ },
66775+#endif
66776+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
66777+ {
66778+ .procname = "audit_ptrace",
66779+ .data = &grsec_enable_audit_ptrace,
66780+ .maxlen = sizeof(int),
66781+ .mode = 0600,
66782+ .proc_handler = &proc_dointvec,
66783+ },
66784+#endif
66785+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
66786+ {
66787+ .procname = "harden_ptrace",
66788+ .data = &grsec_enable_harden_ptrace,
66789+ .maxlen = sizeof(int),
66790+ .mode = 0600,
66791+ .proc_handler = &proc_dointvec,
66792+ },
66793+#endif
66794+ {
66795+ .procname = "grsec_lock",
66796+ .data = &grsec_lock,
66797+ .maxlen = sizeof(int),
66798+ .mode = 0600,
66799+ .proc_handler = &proc_dointvec,
66800+ },
66801+#endif
66802+#ifdef CONFIG_GRKERNSEC_ROFS
66803+ {
66804+ .procname = "romount_protect",
66805+ .data = &grsec_enable_rofs,
66806+ .maxlen = sizeof(int),
66807+ .mode = 0600,
66808+ .proc_handler = &proc_dointvec_minmax,
66809+ .extra1 = &one,
66810+ .extra2 = &one,
66811+ },
66812+#endif
66813+ { }
66814+};
66815+#endif
66816diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
66817new file mode 100644
66818index 0000000..0dc13c3
66819--- /dev/null
66820+++ b/grsecurity/grsec_time.c
66821@@ -0,0 +1,16 @@
66822+#include <linux/kernel.h>
66823+#include <linux/sched.h>
66824+#include <linux/grinternal.h>
66825+#include <linux/module.h>
66826+
66827+void
66828+gr_log_timechange(void)
66829+{
66830+#ifdef CONFIG_GRKERNSEC_TIME
66831+ if (grsec_enable_time)
66832+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
66833+#endif
66834+ return;
66835+}
66836+
66837+EXPORT_SYMBOL(gr_log_timechange);
66838diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
66839new file mode 100644
66840index 0000000..ee57dcf
66841--- /dev/null
66842+++ b/grsecurity/grsec_tpe.c
66843@@ -0,0 +1,73 @@
66844+#include <linux/kernel.h>
66845+#include <linux/sched.h>
66846+#include <linux/file.h>
66847+#include <linux/fs.h>
66848+#include <linux/grinternal.h>
66849+
66850+extern int gr_acl_tpe_check(void);
66851+
66852+int
66853+gr_tpe_allow(const struct file *file)
66854+{
66855+#ifdef CONFIG_GRKERNSEC
66856+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
66857+ const struct cred *cred = current_cred();
66858+ char *msg = NULL;
66859+ char *msg2 = NULL;
66860+
66861+ // never restrict root
66862+ if (gr_is_global_root(cred->uid))
66863+ return 1;
66864+
66865+ if (grsec_enable_tpe) {
66866+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
66867+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
66868+ msg = "not being in trusted group";
66869+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
66870+ msg = "being in untrusted group";
66871+#else
66872+ if (in_group_p(grsec_tpe_gid))
66873+ msg = "being in untrusted group";
66874+#endif
66875+ }
66876+ if (!msg && gr_acl_tpe_check())
66877+ msg = "being in untrusted role";
66878+
66879+ // not in any affected group/role
66880+ if (!msg)
66881+ goto next_check;
66882+
66883+ if (gr_is_global_nonroot(inode->i_uid))
66884+ msg2 = "file in non-root-owned directory";
66885+ else if (inode->i_mode & S_IWOTH)
66886+ msg2 = "file in world-writable directory";
66887+ else if (inode->i_mode & S_IWGRP)
66888+ msg2 = "file in group-writable directory";
66889+
66890+ if (msg && msg2) {
66891+ char fullmsg[70] = {0};
66892+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
66893+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
66894+ return 0;
66895+ }
66896+ msg = NULL;
66897+next_check:
66898+#ifdef CONFIG_GRKERNSEC_TPE_ALL
66899+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
66900+ return 1;
66901+
66902+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
66903+ msg = "directory not owned by user";
66904+ else if (inode->i_mode & S_IWOTH)
66905+ msg = "file in world-writable directory";
66906+ else if (inode->i_mode & S_IWGRP)
66907+ msg = "file in group-writable directory";
66908+
66909+ if (msg) {
66910+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
66911+ return 0;
66912+ }
66913+#endif
66914+#endif
66915+ return 1;
66916+}
66917diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
66918new file mode 100644
66919index 0000000..9f7b1ac
66920--- /dev/null
66921+++ b/grsecurity/grsum.c
66922@@ -0,0 +1,61 @@
66923+#include <linux/err.h>
66924+#include <linux/kernel.h>
66925+#include <linux/sched.h>
66926+#include <linux/mm.h>
66927+#include <linux/scatterlist.h>
66928+#include <linux/crypto.h>
66929+#include <linux/gracl.h>
66930+
66931+
66932+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
66933+#error "crypto and sha256 must be built into the kernel"
66934+#endif
66935+
66936+int
66937+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
66938+{
66939+ char *p;
66940+ struct crypto_hash *tfm;
66941+ struct hash_desc desc;
66942+ struct scatterlist sg;
66943+ unsigned char temp_sum[GR_SHA_LEN];
66944+ volatile int retval = 0;
66945+ volatile int dummy = 0;
66946+ unsigned int i;
66947+
66948+ sg_init_table(&sg, 1);
66949+
66950+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
66951+ if (IS_ERR(tfm)) {
66952+ /* should never happen, since sha256 should be built in */
66953+ return 1;
66954+ }
66955+
66956+ desc.tfm = tfm;
66957+ desc.flags = 0;
66958+
66959+ crypto_hash_init(&desc);
66960+
66961+ p = salt;
66962+ sg_set_buf(&sg, p, GR_SALT_LEN);
66963+ crypto_hash_update(&desc, &sg, sg.length);
66964+
66965+ p = entry->pw;
66966+ sg_set_buf(&sg, p, strlen(p));
66967+
66968+ crypto_hash_update(&desc, &sg, sg.length);
66969+
66970+ crypto_hash_final(&desc, temp_sum);
66971+
66972+ memset(entry->pw, 0, GR_PW_LEN);
66973+
66974+ for (i = 0; i < GR_SHA_LEN; i++)
66975+ if (sum[i] != temp_sum[i])
66976+ retval = 1;
66977+ else
66978+ dummy = 1; // waste a cycle
66979+
66980+ crypto_free_hash(tfm);
66981+
66982+ return retval;
66983+}
66984diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
66985index 77ff547..181834f 100644
66986--- a/include/asm-generic/4level-fixup.h
66987+++ b/include/asm-generic/4level-fixup.h
66988@@ -13,8 +13,10 @@
66989 #define pmd_alloc(mm, pud, address) \
66990 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
66991 NULL: pmd_offset(pud, address))
66992+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
66993
66994 #define pud_alloc(mm, pgd, address) (pgd)
66995+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
66996 #define pud_offset(pgd, start) (pgd)
66997 #define pud_none(pud) 0
66998 #define pud_bad(pud) 0
66999diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
67000index b7babf0..04ad282 100644
67001--- a/include/asm-generic/atomic-long.h
67002+++ b/include/asm-generic/atomic-long.h
67003@@ -22,6 +22,12 @@
67004
67005 typedef atomic64_t atomic_long_t;
67006
67007+#ifdef CONFIG_PAX_REFCOUNT
67008+typedef atomic64_unchecked_t atomic_long_unchecked_t;
67009+#else
67010+typedef atomic64_t atomic_long_unchecked_t;
67011+#endif
67012+
67013 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
67014
67015 static inline long atomic_long_read(atomic_long_t *l)
67016@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
67017 return (long)atomic64_read(v);
67018 }
67019
67020+#ifdef CONFIG_PAX_REFCOUNT
67021+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
67022+{
67023+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67024+
67025+ return (long)atomic64_read_unchecked(v);
67026+}
67027+#endif
67028+
67029 static inline void atomic_long_set(atomic_long_t *l, long i)
67030 {
67031 atomic64_t *v = (atomic64_t *)l;
67032@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
67033 atomic64_set(v, i);
67034 }
67035
67036+#ifdef CONFIG_PAX_REFCOUNT
67037+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
67038+{
67039+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67040+
67041+ atomic64_set_unchecked(v, i);
67042+}
67043+#endif
67044+
67045 static inline void atomic_long_inc(atomic_long_t *l)
67046 {
67047 atomic64_t *v = (atomic64_t *)l;
67048@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
67049 atomic64_inc(v);
67050 }
67051
67052+#ifdef CONFIG_PAX_REFCOUNT
67053+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
67054+{
67055+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67056+
67057+ atomic64_inc_unchecked(v);
67058+}
67059+#endif
67060+
67061 static inline void atomic_long_dec(atomic_long_t *l)
67062 {
67063 atomic64_t *v = (atomic64_t *)l;
67064@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
67065 atomic64_dec(v);
67066 }
67067
67068+#ifdef CONFIG_PAX_REFCOUNT
67069+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
67070+{
67071+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67072+
67073+ atomic64_dec_unchecked(v);
67074+}
67075+#endif
67076+
67077 static inline void atomic_long_add(long i, atomic_long_t *l)
67078 {
67079 atomic64_t *v = (atomic64_t *)l;
67080@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
67081 atomic64_add(i, v);
67082 }
67083
67084+#ifdef CONFIG_PAX_REFCOUNT
67085+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
67086+{
67087+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67088+
67089+ atomic64_add_unchecked(i, v);
67090+}
67091+#endif
67092+
67093 static inline void atomic_long_sub(long i, atomic_long_t *l)
67094 {
67095 atomic64_t *v = (atomic64_t *)l;
67096@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
67097 atomic64_sub(i, v);
67098 }
67099
67100+#ifdef CONFIG_PAX_REFCOUNT
67101+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
67102+{
67103+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67104+
67105+ atomic64_sub_unchecked(i, v);
67106+}
67107+#endif
67108+
67109 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
67110 {
67111 atomic64_t *v = (atomic64_t *)l;
67112@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
67113 return (long)atomic64_add_return(i, v);
67114 }
67115
67116+#ifdef CONFIG_PAX_REFCOUNT
67117+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
67118+{
67119+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67120+
67121+ return (long)atomic64_add_return_unchecked(i, v);
67122+}
67123+#endif
67124+
67125 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
67126 {
67127 atomic64_t *v = (atomic64_t *)l;
67128@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
67129 return (long)atomic64_inc_return(v);
67130 }
67131
67132+#ifdef CONFIG_PAX_REFCOUNT
67133+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
67134+{
67135+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67136+
67137+ return (long)atomic64_inc_return_unchecked(v);
67138+}
67139+#endif
67140+
67141 static inline long atomic_long_dec_return(atomic_long_t *l)
67142 {
67143 atomic64_t *v = (atomic64_t *)l;
67144@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
67145
67146 typedef atomic_t atomic_long_t;
67147
67148+#ifdef CONFIG_PAX_REFCOUNT
67149+typedef atomic_unchecked_t atomic_long_unchecked_t;
67150+#else
67151+typedef atomic_t atomic_long_unchecked_t;
67152+#endif
67153+
67154 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
67155 static inline long atomic_long_read(atomic_long_t *l)
67156 {
67157@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
67158 return (long)atomic_read(v);
67159 }
67160
67161+#ifdef CONFIG_PAX_REFCOUNT
67162+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
67163+{
67164+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67165+
67166+ return (long)atomic_read_unchecked(v);
67167+}
67168+#endif
67169+
67170 static inline void atomic_long_set(atomic_long_t *l, long i)
67171 {
67172 atomic_t *v = (atomic_t *)l;
67173@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
67174 atomic_set(v, i);
67175 }
67176
67177+#ifdef CONFIG_PAX_REFCOUNT
67178+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
67179+{
67180+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67181+
67182+ atomic_set_unchecked(v, i);
67183+}
67184+#endif
67185+
67186 static inline void atomic_long_inc(atomic_long_t *l)
67187 {
67188 atomic_t *v = (atomic_t *)l;
67189@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
67190 atomic_inc(v);
67191 }
67192
67193+#ifdef CONFIG_PAX_REFCOUNT
67194+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
67195+{
67196+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67197+
67198+ atomic_inc_unchecked(v);
67199+}
67200+#endif
67201+
67202 static inline void atomic_long_dec(atomic_long_t *l)
67203 {
67204 atomic_t *v = (atomic_t *)l;
67205@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
67206 atomic_dec(v);
67207 }
67208
67209+#ifdef CONFIG_PAX_REFCOUNT
67210+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
67211+{
67212+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67213+
67214+ atomic_dec_unchecked(v);
67215+}
67216+#endif
67217+
67218 static inline void atomic_long_add(long i, atomic_long_t *l)
67219 {
67220 atomic_t *v = (atomic_t *)l;
67221@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
67222 atomic_add(i, v);
67223 }
67224
67225+#ifdef CONFIG_PAX_REFCOUNT
67226+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
67227+{
67228+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67229+
67230+ atomic_add_unchecked(i, v);
67231+}
67232+#endif
67233+
67234 static inline void atomic_long_sub(long i, atomic_long_t *l)
67235 {
67236 atomic_t *v = (atomic_t *)l;
67237@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
67238 atomic_sub(i, v);
67239 }
67240
67241+#ifdef CONFIG_PAX_REFCOUNT
67242+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
67243+{
67244+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67245+
67246+ atomic_sub_unchecked(i, v);
67247+}
67248+#endif
67249+
67250 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
67251 {
67252 atomic_t *v = (atomic_t *)l;
67253@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
67254 return (long)atomic_add_return(i, v);
67255 }
67256
67257+#ifdef CONFIG_PAX_REFCOUNT
67258+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
67259+{
67260+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67261+
67262+ return (long)atomic_add_return_unchecked(i, v);
67263+}
67264+
67265+#endif
67266+
67267 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
67268 {
67269 atomic_t *v = (atomic_t *)l;
67270@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
67271 return (long)atomic_inc_return(v);
67272 }
67273
67274+#ifdef CONFIG_PAX_REFCOUNT
67275+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
67276+{
67277+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67278+
67279+ return (long)atomic_inc_return_unchecked(v);
67280+}
67281+#endif
67282+
67283 static inline long atomic_long_dec_return(atomic_long_t *l)
67284 {
67285 atomic_t *v = (atomic_t *)l;
67286@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
67287
67288 #endif /* BITS_PER_LONG == 64 */
67289
67290+#ifdef CONFIG_PAX_REFCOUNT
67291+static inline void pax_refcount_needs_these_functions(void)
67292+{
67293+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
67294+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
67295+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
67296+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
67297+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
67298+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
67299+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
67300+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
67301+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
67302+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
67303+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
67304+#ifdef CONFIG_X86
67305+ atomic_clear_mask_unchecked(0, NULL);
67306+ atomic_set_mask_unchecked(0, NULL);
67307+#endif
67308+
67309+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
67310+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
67311+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
67312+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
67313+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
67314+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
67315+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
67316+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
67317+}
67318+#else
67319+#define atomic_read_unchecked(v) atomic_read(v)
67320+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
67321+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
67322+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
67323+#define atomic_inc_unchecked(v) atomic_inc(v)
67324+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
67325+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
67326+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
67327+#define atomic_dec_unchecked(v) atomic_dec(v)
67328+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
67329+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
67330+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
67331+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
67332+
67333+#define atomic_long_read_unchecked(v) atomic_long_read(v)
67334+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
67335+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
67336+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
67337+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
67338+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
67339+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
67340+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
67341+#endif
67342+
67343 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
67344diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
67345index 1ced641..c896ee8 100644
67346--- a/include/asm-generic/atomic.h
67347+++ b/include/asm-generic/atomic.h
67348@@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
67349 * Atomically clears the bits set in @mask from @v
67350 */
67351 #ifndef atomic_clear_mask
67352-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
67353+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
67354 {
67355 unsigned long flags;
67356
67357diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
67358index b18ce4f..2ee2843 100644
67359--- a/include/asm-generic/atomic64.h
67360+++ b/include/asm-generic/atomic64.h
67361@@ -16,6 +16,8 @@ typedef struct {
67362 long long counter;
67363 } atomic64_t;
67364
67365+typedef atomic64_t atomic64_unchecked_t;
67366+
67367 #define ATOMIC64_INIT(i) { (i) }
67368
67369 extern long long atomic64_read(const atomic64_t *v);
67370@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
67371 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
67372 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
67373
67374+#define atomic64_read_unchecked(v) atomic64_read(v)
67375+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
67376+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
67377+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
67378+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
67379+#define atomic64_inc_unchecked(v) atomic64_inc(v)
67380+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
67381+#define atomic64_dec_unchecked(v) atomic64_dec(v)
67382+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
67383+
67384 #endif /* _ASM_GENERIC_ATOMIC64_H */
67385diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
67386index 1bfcfe5..e04c5c9 100644
67387--- a/include/asm-generic/cache.h
67388+++ b/include/asm-generic/cache.h
67389@@ -6,7 +6,7 @@
67390 * cache lines need to provide their own cache.h.
67391 */
67392
67393-#define L1_CACHE_SHIFT 5
67394-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
67395+#define L1_CACHE_SHIFT 5UL
67396+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
67397
67398 #endif /* __ASM_GENERIC_CACHE_H */
67399diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
67400index 0d68a1e..b74a761 100644
67401--- a/include/asm-generic/emergency-restart.h
67402+++ b/include/asm-generic/emergency-restart.h
67403@@ -1,7 +1,7 @@
67404 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
67405 #define _ASM_GENERIC_EMERGENCY_RESTART_H
67406
67407-static inline void machine_emergency_restart(void)
67408+static inline __noreturn void machine_emergency_restart(void)
67409 {
67410 machine_restart(NULL);
67411 }
67412diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
67413index 90f99c7..00ce236 100644
67414--- a/include/asm-generic/kmap_types.h
67415+++ b/include/asm-generic/kmap_types.h
67416@@ -2,9 +2,9 @@
67417 #define _ASM_GENERIC_KMAP_TYPES_H
67418
67419 #ifdef __WITH_KM_FENCE
67420-# define KM_TYPE_NR 41
67421+# define KM_TYPE_NR 42
67422 #else
67423-# define KM_TYPE_NR 20
67424+# define KM_TYPE_NR 21
67425 #endif
67426
67427 #endif
67428diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
67429index 9ceb03b..62b0b8f 100644
67430--- a/include/asm-generic/local.h
67431+++ b/include/asm-generic/local.h
67432@@ -23,24 +23,37 @@ typedef struct
67433 atomic_long_t a;
67434 } local_t;
67435
67436+typedef struct {
67437+ atomic_long_unchecked_t a;
67438+} local_unchecked_t;
67439+
67440 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
67441
67442 #define local_read(l) atomic_long_read(&(l)->a)
67443+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
67444 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
67445+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
67446 #define local_inc(l) atomic_long_inc(&(l)->a)
67447+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
67448 #define local_dec(l) atomic_long_dec(&(l)->a)
67449+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
67450 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
67451+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
67452 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
67453+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
67454
67455 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
67456 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
67457 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
67458 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
67459 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
67460+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
67461 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
67462 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
67463+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
67464
67465 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
67466+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
67467 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
67468 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
67469 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
67470diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
67471index 725612b..9cc513a 100644
67472--- a/include/asm-generic/pgtable-nopmd.h
67473+++ b/include/asm-generic/pgtable-nopmd.h
67474@@ -1,14 +1,19 @@
67475 #ifndef _PGTABLE_NOPMD_H
67476 #define _PGTABLE_NOPMD_H
67477
67478-#ifndef __ASSEMBLY__
67479-
67480 #include <asm-generic/pgtable-nopud.h>
67481
67482-struct mm_struct;
67483-
67484 #define __PAGETABLE_PMD_FOLDED
67485
67486+#define PMD_SHIFT PUD_SHIFT
67487+#define PTRS_PER_PMD 1
67488+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
67489+#define PMD_MASK (~(PMD_SIZE-1))
67490+
67491+#ifndef __ASSEMBLY__
67492+
67493+struct mm_struct;
67494+
67495 /*
67496 * Having the pmd type consist of a pud gets the size right, and allows
67497 * us to conceptually access the pud entry that this pmd is folded into
67498@@ -16,11 +21,6 @@ struct mm_struct;
67499 */
67500 typedef struct { pud_t pud; } pmd_t;
67501
67502-#define PMD_SHIFT PUD_SHIFT
67503-#define PTRS_PER_PMD 1
67504-#define PMD_SIZE (1UL << PMD_SHIFT)
67505-#define PMD_MASK (~(PMD_SIZE-1))
67506-
67507 /*
67508 * The "pud_xxx()" functions here are trivial for a folded two-level
67509 * setup: the pmd is never bad, and a pmd always exists (as it's folded
67510diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
67511index 810431d..0ec4804f 100644
67512--- a/include/asm-generic/pgtable-nopud.h
67513+++ b/include/asm-generic/pgtable-nopud.h
67514@@ -1,10 +1,15 @@
67515 #ifndef _PGTABLE_NOPUD_H
67516 #define _PGTABLE_NOPUD_H
67517
67518-#ifndef __ASSEMBLY__
67519-
67520 #define __PAGETABLE_PUD_FOLDED
67521
67522+#define PUD_SHIFT PGDIR_SHIFT
67523+#define PTRS_PER_PUD 1
67524+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
67525+#define PUD_MASK (~(PUD_SIZE-1))
67526+
67527+#ifndef __ASSEMBLY__
67528+
67529 /*
67530 * Having the pud type consist of a pgd gets the size right, and allows
67531 * us to conceptually access the pgd entry that this pud is folded into
67532@@ -12,11 +17,6 @@
67533 */
67534 typedef struct { pgd_t pgd; } pud_t;
67535
67536-#define PUD_SHIFT PGDIR_SHIFT
67537-#define PTRS_PER_PUD 1
67538-#define PUD_SIZE (1UL << PUD_SHIFT)
67539-#define PUD_MASK (~(PUD_SIZE-1))
67540-
67541 /*
67542 * The "pgd_xxx()" functions here are trivial for a folded two-level
67543 * setup: the pud is never bad, and a pud always exists (as it's folded
67544@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
67545 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
67546
67547 #define pgd_populate(mm, pgd, pud) do { } while (0)
67548+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
67549 /*
67550 * (puds are folded into pgds so this doesn't get actually called,
67551 * but the define is needed for a generic inline function.)
67552diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
67553index 5cf680a..4b74d62 100644
67554--- a/include/asm-generic/pgtable.h
67555+++ b/include/asm-generic/pgtable.h
67556@@ -688,6 +688,14 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
67557 }
67558 #endif /* CONFIG_NUMA_BALANCING */
67559
67560+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
67561+static inline unsigned long pax_open_kernel(void) { return 0; }
67562+#endif
67563+
67564+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
67565+static inline unsigned long pax_close_kernel(void) { return 0; }
67566+#endif
67567+
67568 #endif /* CONFIG_MMU */
67569
67570 #endif /* !__ASSEMBLY__ */
67571diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
67572index d1ea7ce..b1ebf2a 100644
67573--- a/include/asm-generic/vmlinux.lds.h
67574+++ b/include/asm-generic/vmlinux.lds.h
67575@@ -218,6 +218,7 @@
67576 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
67577 VMLINUX_SYMBOL(__start_rodata) = .; \
67578 *(.rodata) *(.rodata.*) \
67579+ *(.data..read_only) \
67580 *(__vermagic) /* Kernel version magic */ \
67581 . = ALIGN(8); \
67582 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
67583@@ -725,17 +726,18 @@
67584 * section in the linker script will go there too. @phdr should have
67585 * a leading colon.
67586 *
67587- * Note that this macros defines __per_cpu_load as an absolute symbol.
67588+ * Note that this macros defines per_cpu_load as an absolute symbol.
67589 * If there is no need to put the percpu section at a predetermined
67590 * address, use PERCPU_SECTION.
67591 */
67592 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
67593- VMLINUX_SYMBOL(__per_cpu_load) = .; \
67594- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
67595+ per_cpu_load = .; \
67596+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
67597 - LOAD_OFFSET) { \
67598+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
67599 PERCPU_INPUT(cacheline) \
67600 } phdr \
67601- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
67602+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
67603
67604 /**
67605 * PERCPU_SECTION - define output section for percpu area, simple version
67606diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
67607index 418d270..bfd2794 100644
67608--- a/include/crypto/algapi.h
67609+++ b/include/crypto/algapi.h
67610@@ -34,7 +34,7 @@ struct crypto_type {
67611 unsigned int maskclear;
67612 unsigned int maskset;
67613 unsigned int tfmsize;
67614-};
67615+} __do_const;
67616
67617 struct crypto_instance {
67618 struct crypto_alg alg;
67619diff --git a/include/drm/drmP.h b/include/drm/drmP.h
67620index fad21c9..ab858bc 100644
67621--- a/include/drm/drmP.h
67622+++ b/include/drm/drmP.h
67623@@ -72,6 +72,7 @@
67624 #include <linux/workqueue.h>
67625 #include <linux/poll.h>
67626 #include <asm/pgalloc.h>
67627+#include <asm/local.h>
67628 #include <drm/drm.h>
67629 #include <drm/drm_sarea.h>
67630
67631@@ -293,10 +294,12 @@ do { \
67632 * \param cmd command.
67633 * \param arg argument.
67634 */
67635-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
67636+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
67637+ struct drm_file *file_priv);
67638+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
67639 struct drm_file *file_priv);
67640
67641-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
67642+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
67643 unsigned long arg);
67644
67645 #define DRM_IOCTL_NR(n) _IOC_NR(n)
67646@@ -311,9 +314,9 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
67647 struct drm_ioctl_desc {
67648 unsigned int cmd;
67649 int flags;
67650- drm_ioctl_t *func;
67651+ drm_ioctl_t func;
67652 unsigned int cmd_drv;
67653-};
67654+} __do_const;
67655
67656 /**
67657 * Creates a driver or general drm_ioctl_desc array entry for the given
67658@@ -995,7 +998,7 @@ struct drm_info_list {
67659 int (*show)(struct seq_file*, void*); /** show callback */
67660 u32 driver_features; /**< Required driver features for this entry */
67661 void *data;
67662-};
67663+} __do_const;
67664
67665 /**
67666 * debugfs node structure. This structure represents a debugfs file.
67667@@ -1068,7 +1071,7 @@ struct drm_device {
67668
67669 /** \name Usage Counters */
67670 /*@{ */
67671- int open_count; /**< Outstanding files open */
67672+ local_t open_count; /**< Outstanding files open */
67673 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
67674 atomic_t vma_count; /**< Outstanding vma areas open */
67675 int buf_use; /**< Buffers in use -- cannot alloc */
67676@@ -1079,7 +1082,7 @@ struct drm_device {
67677 /*@{ */
67678 unsigned long counters;
67679 enum drm_stat_type types[15];
67680- atomic_t counts[15];
67681+ atomic_unchecked_t counts[15];
67682 /*@} */
67683
67684 struct list_head filelist;
67685diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
67686index f43d556..94d9343 100644
67687--- a/include/drm/drm_crtc_helper.h
67688+++ b/include/drm/drm_crtc_helper.h
67689@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
67690 struct drm_connector *connector);
67691 /* disable encoder when not in use - more explicit than dpms off */
67692 void (*disable)(struct drm_encoder *encoder);
67693-};
67694+} __no_const;
67695
67696 /**
67697 * drm_connector_helper_funcs - helper operations for connectors
67698diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
67699index 72dcbe8..8db58d7 100644
67700--- a/include/drm/ttm/ttm_memory.h
67701+++ b/include/drm/ttm/ttm_memory.h
67702@@ -48,7 +48,7 @@
67703
67704 struct ttm_mem_shrink {
67705 int (*do_shrink) (struct ttm_mem_shrink *);
67706-};
67707+} __no_const;
67708
67709 /**
67710 * struct ttm_mem_global - Global memory accounting structure.
67711diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
67712index 4b840e8..155d235 100644
67713--- a/include/keys/asymmetric-subtype.h
67714+++ b/include/keys/asymmetric-subtype.h
67715@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
67716 /* Verify the signature on a key of this subtype (optional) */
67717 int (*verify_signature)(const struct key *key,
67718 const struct public_key_signature *sig);
67719-};
67720+} __do_const;
67721
67722 /**
67723 * asymmetric_key_subtype - Get the subtype from an asymmetric key
67724diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
67725index c1da539..1dcec55 100644
67726--- a/include/linux/atmdev.h
67727+++ b/include/linux/atmdev.h
67728@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
67729 #endif
67730
67731 struct k_atm_aal_stats {
67732-#define __HANDLE_ITEM(i) atomic_t i
67733+#define __HANDLE_ITEM(i) atomic_unchecked_t i
67734 __AAL_STAT_ITEMS
67735 #undef __HANDLE_ITEM
67736 };
67737@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
67738 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
67739 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
67740 struct module *owner;
67741-};
67742+} __do_const ;
67743
67744 struct atmphy_ops {
67745 int (*start)(struct atm_dev *dev);
67746diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
67747index 0530b98..96a8ac0 100644
67748--- a/include/linux/binfmts.h
67749+++ b/include/linux/binfmts.h
67750@@ -73,8 +73,9 @@ struct linux_binfmt {
67751 int (*load_binary)(struct linux_binprm *);
67752 int (*load_shlib)(struct file *);
67753 int (*core_dump)(struct coredump_params *cprm);
67754+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
67755 unsigned long min_coredump; /* minimal dump size */
67756-};
67757+} __do_const;
67758
67759 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
67760
67761diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
67762index f94bc83..62b9cfe 100644
67763--- a/include/linux/blkdev.h
67764+++ b/include/linux/blkdev.h
67765@@ -1498,7 +1498,7 @@ struct block_device_operations {
67766 /* this callback is with swap_lock and sometimes page table lock held */
67767 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
67768 struct module *owner;
67769-};
67770+} __do_const;
67771
67772 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
67773 unsigned long);
67774diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
67775index 7c2e030..b72475d 100644
67776--- a/include/linux/blktrace_api.h
67777+++ b/include/linux/blktrace_api.h
67778@@ -23,7 +23,7 @@ struct blk_trace {
67779 struct dentry *dir;
67780 struct dentry *dropped_file;
67781 struct dentry *msg_file;
67782- atomic_t dropped;
67783+ atomic_unchecked_t dropped;
67784 };
67785
67786 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
67787diff --git a/include/linux/cache.h b/include/linux/cache.h
67788index 4c57065..4307975 100644
67789--- a/include/linux/cache.h
67790+++ b/include/linux/cache.h
67791@@ -16,6 +16,10 @@
67792 #define __read_mostly
67793 #endif
67794
67795+#ifndef __read_only
67796+#define __read_only __read_mostly
67797+#endif
67798+
67799 #ifndef ____cacheline_aligned
67800 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
67801 #endif
67802diff --git a/include/linux/capability.h b/include/linux/capability.h
67803index 98503b7..cc36d18 100644
67804--- a/include/linux/capability.h
67805+++ b/include/linux/capability.h
67806@@ -211,8 +211,13 @@ extern bool capable(int cap);
67807 extern bool ns_capable(struct user_namespace *ns, int cap);
67808 extern bool nsown_capable(int cap);
67809 extern bool inode_capable(const struct inode *inode, int cap);
67810+extern bool capable_nolog(int cap);
67811+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
67812+extern bool inode_capable_nolog(const struct inode *inode, int cap);
67813
67814 /* audit system wants to get cap info from files as well */
67815 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
67816
67817+extern int is_privileged_binary(const struct dentry *dentry);
67818+
67819 #endif /* !_LINUX_CAPABILITY_H */
67820diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
67821index 8609d57..86e4d79 100644
67822--- a/include/linux/cdrom.h
67823+++ b/include/linux/cdrom.h
67824@@ -87,7 +87,6 @@ struct cdrom_device_ops {
67825
67826 /* driver specifications */
67827 const int capability; /* capability flags */
67828- int n_minors; /* number of active minor devices */
67829 /* handle uniform packets for scsi type devices (scsi,atapi) */
67830 int (*generic_packet) (struct cdrom_device_info *,
67831 struct packet_command *);
67832diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
67833index 42e55de..1cd0e66 100644
67834--- a/include/linux/cleancache.h
67835+++ b/include/linux/cleancache.h
67836@@ -31,7 +31,7 @@ struct cleancache_ops {
67837 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
67838 void (*invalidate_inode)(int, struct cleancache_filekey);
67839 void (*invalidate_fs)(int);
67840-};
67841+} __no_const;
67842
67843 extern struct cleancache_ops
67844 cleancache_register_ops(struct cleancache_ops *ops);
67845diff --git a/include/linux/compat.h b/include/linux/compat.h
67846index dec7e2d..45db13f 100644
67847--- a/include/linux/compat.h
67848+++ b/include/linux/compat.h
67849@@ -311,14 +311,14 @@ long compat_sys_msgsnd(int first, int second, int third, void __user *uptr);
67850 long compat_sys_msgrcv(int first, int second, int msgtyp, int third,
67851 int version, void __user *uptr);
67852 long compat_sys_shmat(int first, int second, compat_uptr_t third, int version,
67853- void __user *uptr);
67854+ void __user *uptr) __intentional_overflow(0);
67855 #else
67856 long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
67857 long compat_sys_msgsnd(int msqid, struct compat_msgbuf __user *msgp,
67858 compat_ssize_t msgsz, int msgflg);
67859 long compat_sys_msgrcv(int msqid, struct compat_msgbuf __user *msgp,
67860 compat_ssize_t msgsz, long msgtyp, int msgflg);
67861-long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
67862+long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
67863 #endif
67864 long compat_sys_msgctl(int first, int second, void __user *uptr);
67865 long compat_sys_shmctl(int first, int second, void __user *uptr);
67866@@ -414,7 +414,7 @@ extern int compat_ptrace_request(struct task_struct *child,
67867 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
67868 compat_ulong_t addr, compat_ulong_t data);
67869 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
67870- compat_long_t addr, compat_long_t data);
67871+ compat_ulong_t addr, compat_ulong_t data);
67872
67873 /*
67874 * epoll (fs/eventpoll.c) compat bits follow ...
67875diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
67876index 662fd1b..e801992 100644
67877--- a/include/linux/compiler-gcc4.h
67878+++ b/include/linux/compiler-gcc4.h
67879@@ -34,6 +34,21 @@
67880 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
67881
67882 #if __GNUC_MINOR__ >= 5
67883+
67884+#ifdef CONSTIFY_PLUGIN
67885+#define __no_const __attribute__((no_const))
67886+#define __do_const __attribute__((do_const))
67887+#endif
67888+
67889+#ifdef SIZE_OVERFLOW_PLUGIN
67890+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
67891+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
67892+#endif
67893+
67894+#ifdef LATENT_ENTROPY_PLUGIN
67895+#define __latent_entropy __attribute__((latent_entropy))
67896+#endif
67897+
67898 /*
67899 * Mark a position in code as unreachable. This can be used to
67900 * suppress control flow warnings after asm blocks that transfer
67901@@ -49,6 +64,11 @@
67902 #define __noclone __attribute__((__noclone__))
67903
67904 #endif
67905+
67906+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
67907+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
67908+#define __bos0(ptr) __bos((ptr), 0)
67909+#define __bos1(ptr) __bos((ptr), 1)
67910 #endif
67911
67912 #if __GNUC_MINOR__ >= 6
67913diff --git a/include/linux/compiler.h b/include/linux/compiler.h
67914index dd852b7..1ad5fba 100644
67915--- a/include/linux/compiler.h
67916+++ b/include/linux/compiler.h
67917@@ -5,11 +5,14 @@
67918
67919 #ifdef __CHECKER__
67920 # define __user __attribute__((noderef, address_space(1)))
67921+# define __force_user __force __user
67922 # define __kernel __attribute__((address_space(0)))
67923+# define __force_kernel __force __kernel
67924 # define __safe __attribute__((safe))
67925 # define __force __attribute__((force))
67926 # define __nocast __attribute__((nocast))
67927 # define __iomem __attribute__((noderef, address_space(2)))
67928+# define __force_iomem __force __iomem
67929 # define __must_hold(x) __attribute__((context(x,1,1)))
67930 # define __acquires(x) __attribute__((context(x,0,1)))
67931 # define __releases(x) __attribute__((context(x,1,0)))
67932@@ -17,20 +20,37 @@
67933 # define __release(x) __context__(x,-1)
67934 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
67935 # define __percpu __attribute__((noderef, address_space(3)))
67936+# define __force_percpu __force __percpu
67937 #ifdef CONFIG_SPARSE_RCU_POINTER
67938 # define __rcu __attribute__((noderef, address_space(4)))
67939+# define __force_rcu __force __rcu
67940 #else
67941 # define __rcu
67942+# define __force_rcu
67943 #endif
67944 extern void __chk_user_ptr(const volatile void __user *);
67945 extern void __chk_io_ptr(const volatile void __iomem *);
67946 #else
67947-# define __user
67948-# define __kernel
67949+# ifdef CHECKER_PLUGIN
67950+//# define __user
67951+//# define __force_user
67952+//# define __kernel
67953+//# define __force_kernel
67954+# else
67955+# ifdef STRUCTLEAK_PLUGIN
67956+# define __user __attribute__((user))
67957+# else
67958+# define __user
67959+# endif
67960+# define __force_user
67961+# define __kernel
67962+# define __force_kernel
67963+# endif
67964 # define __safe
67965 # define __force
67966 # define __nocast
67967 # define __iomem
67968+# define __force_iomem
67969 # define __chk_user_ptr(x) (void)0
67970 # define __chk_io_ptr(x) (void)0
67971 # define __builtin_warning(x, y...) (1)
67972@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
67973 # define __release(x) (void)0
67974 # define __cond_lock(x,c) (c)
67975 # define __percpu
67976+# define __force_percpu
67977 # define __rcu
67978+# define __force_rcu
67979 #endif
67980
67981 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
67982@@ -275,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
67983 # define __attribute_const__ /* unimplemented */
67984 #endif
67985
67986+#ifndef __no_const
67987+# define __no_const
67988+#endif
67989+
67990+#ifndef __do_const
67991+# define __do_const
67992+#endif
67993+
67994+#ifndef __size_overflow
67995+# define __size_overflow(...)
67996+#endif
67997+
67998+#ifndef __intentional_overflow
67999+# define __intentional_overflow(...)
68000+#endif
68001+
68002+#ifndef __latent_entropy
68003+# define __latent_entropy
68004+#endif
68005+
68006 /*
68007 * Tell gcc if a function is cold. The compiler will assume any path
68008 * directly leading to the call is unlikely.
68009@@ -284,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
68010 #define __cold
68011 #endif
68012
68013+#ifndef __alloc_size
68014+#define __alloc_size(...)
68015+#endif
68016+
68017+#ifndef __bos
68018+#define __bos(ptr, arg)
68019+#endif
68020+
68021+#ifndef __bos0
68022+#define __bos0(ptr)
68023+#endif
68024+
68025+#ifndef __bos1
68026+#define __bos1(ptr)
68027+#endif
68028+
68029 /* Simple shorthand for a section definition */
68030 #ifndef __section
68031 # define __section(S) __attribute__ ((__section__(#S)))
68032@@ -323,6 +381,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
68033 * use is to mediate communication between process-level code and irq/NMI
68034 * handlers, all running on the same CPU.
68035 */
68036-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
68037+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
68038+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
68039
68040 #endif /* __LINUX_COMPILER_H */
68041diff --git a/include/linux/completion.h b/include/linux/completion.h
68042index 51494e6..0fd1b61 100644
68043--- a/include/linux/completion.h
68044+++ b/include/linux/completion.h
68045@@ -78,13 +78,13 @@ static inline void init_completion(struct completion *x)
68046
68047 extern void wait_for_completion(struct completion *);
68048 extern int wait_for_completion_interruptible(struct completion *x);
68049-extern int wait_for_completion_killable(struct completion *x);
68050+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
68051 extern unsigned long wait_for_completion_timeout(struct completion *x,
68052 unsigned long timeout);
68053 extern long wait_for_completion_interruptible_timeout(
68054- struct completion *x, unsigned long timeout);
68055+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
68056 extern long wait_for_completion_killable_timeout(
68057- struct completion *x, unsigned long timeout);
68058+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
68059 extern bool try_wait_for_completion(struct completion *x);
68060 extern bool completion_done(struct completion *x);
68061
68062diff --git a/include/linux/configfs.h b/include/linux/configfs.h
68063index 34025df..d94bbbc 100644
68064--- a/include/linux/configfs.h
68065+++ b/include/linux/configfs.h
68066@@ -125,7 +125,7 @@ struct configfs_attribute {
68067 const char *ca_name;
68068 struct module *ca_owner;
68069 umode_t ca_mode;
68070-};
68071+} __do_const;
68072
68073 /*
68074 * Users often need to create attribute structures for their configurable
68075diff --git a/include/linux/cpu.h b/include/linux/cpu.h
68076index ce7a074..01ab8ac 100644
68077--- a/include/linux/cpu.h
68078+++ b/include/linux/cpu.h
68079@@ -115,7 +115,7 @@ enum {
68080 /* Need to know about CPUs going up/down? */
68081 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
68082 #define cpu_notifier(fn, pri) { \
68083- static struct notifier_block fn##_nb __cpuinitdata = \
68084+ static struct notifier_block fn##_nb = \
68085 { .notifier_call = fn, .priority = pri }; \
68086 register_cpu_notifier(&fn##_nb); \
68087 }
68088diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
68089index a55b88e..fba90c5 100644
68090--- a/include/linux/cpufreq.h
68091+++ b/include/linux/cpufreq.h
68092@@ -240,7 +240,7 @@ struct cpufreq_driver {
68093 int (*suspend) (struct cpufreq_policy *policy);
68094 int (*resume) (struct cpufreq_policy *policy);
68095 struct freq_attr **attr;
68096-};
68097+} __do_const;
68098
68099 /* flags */
68100
68101@@ -299,6 +299,7 @@ struct global_attr {
68102 ssize_t (*store)(struct kobject *a, struct attribute *b,
68103 const char *c, size_t count);
68104 };
68105+typedef struct global_attr __no_const global_attr_no_const;
68106
68107 #define define_one_global_ro(_name) \
68108 static struct global_attr _name = \
68109diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
68110index 24cd1037..20a63aae 100644
68111--- a/include/linux/cpuidle.h
68112+++ b/include/linux/cpuidle.h
68113@@ -54,7 +54,8 @@ struct cpuidle_state {
68114 int index);
68115
68116 int (*enter_dead) (struct cpuidle_device *dev, int index);
68117-};
68118+} __do_const;
68119+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
68120
68121 /* Idle State Flags */
68122 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
68123@@ -216,7 +217,7 @@ struct cpuidle_governor {
68124 void (*reflect) (struct cpuidle_device *dev, int index);
68125
68126 struct module *owner;
68127-};
68128+} __do_const;
68129
68130 #ifdef CONFIG_CPU_IDLE
68131
68132diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
68133index 0325602..5e9feff 100644
68134--- a/include/linux/cpumask.h
68135+++ b/include/linux/cpumask.h
68136@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
68137 }
68138
68139 /* Valid inputs for n are -1 and 0. */
68140-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
68141+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
68142 {
68143 return n+1;
68144 }
68145
68146-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
68147+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
68148 {
68149 return n+1;
68150 }
68151
68152-static inline unsigned int cpumask_next_and(int n,
68153+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
68154 const struct cpumask *srcp,
68155 const struct cpumask *andp)
68156 {
68157@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
68158 *
68159 * Returns >= nr_cpu_ids if no further cpus set.
68160 */
68161-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
68162+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
68163 {
68164 /* -1 is a legal arg here. */
68165 if (n != -1)
68166@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
68167 *
68168 * Returns >= nr_cpu_ids if no further cpus unset.
68169 */
68170-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
68171+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
68172 {
68173 /* -1 is a legal arg here. */
68174 if (n != -1)
68175@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
68176 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
68177 }
68178
68179-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
68180+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
68181 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
68182
68183 /**
68184diff --git a/include/linux/cred.h b/include/linux/cred.h
68185index 04421e8..6bce4ef 100644
68186--- a/include/linux/cred.h
68187+++ b/include/linux/cred.h
68188@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
68189 static inline void validate_process_creds(void)
68190 {
68191 }
68192+static inline void validate_task_creds(struct task_struct *task)
68193+{
68194+}
68195 #endif
68196
68197 /**
68198diff --git a/include/linux/crypto.h b/include/linux/crypto.h
68199index b92eadf..b4ecdc1 100644
68200--- a/include/linux/crypto.h
68201+++ b/include/linux/crypto.h
68202@@ -373,7 +373,7 @@ struct cipher_tfm {
68203 const u8 *key, unsigned int keylen);
68204 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
68205 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
68206-};
68207+} __no_const;
68208
68209 struct hash_tfm {
68210 int (*init)(struct hash_desc *desc);
68211@@ -394,13 +394,13 @@ struct compress_tfm {
68212 int (*cot_decompress)(struct crypto_tfm *tfm,
68213 const u8 *src, unsigned int slen,
68214 u8 *dst, unsigned int *dlen);
68215-};
68216+} __no_const;
68217
68218 struct rng_tfm {
68219 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
68220 unsigned int dlen);
68221 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
68222-};
68223+} __no_const;
68224
68225 #define crt_ablkcipher crt_u.ablkcipher
68226 #define crt_aead crt_u.aead
68227diff --git a/include/linux/ctype.h b/include/linux/ctype.h
68228index 8acfe31..6ffccd63 100644
68229--- a/include/linux/ctype.h
68230+++ b/include/linux/ctype.h
68231@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
68232 * Fast implementation of tolower() for internal usage. Do not use in your
68233 * code.
68234 */
68235-static inline char _tolower(const char c)
68236+static inline unsigned char _tolower(const unsigned char c)
68237 {
68238 return c | 0x20;
68239 }
68240diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
68241index 7925bf0..d5143d2 100644
68242--- a/include/linux/decompress/mm.h
68243+++ b/include/linux/decompress/mm.h
68244@@ -77,7 +77,7 @@ static void free(void *where)
68245 * warnings when not needed (indeed large_malloc / large_free are not
68246 * needed by inflate */
68247
68248-#define malloc(a) kmalloc(a, GFP_KERNEL)
68249+#define malloc(a) kmalloc((a), GFP_KERNEL)
68250 #define free(a) kfree(a)
68251
68252 #define large_malloc(a) vmalloc(a)
68253diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
68254index e83ef39..33e0eb3 100644
68255--- a/include/linux/devfreq.h
68256+++ b/include/linux/devfreq.h
68257@@ -114,7 +114,7 @@ struct devfreq_governor {
68258 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
68259 int (*event_handler)(struct devfreq *devfreq,
68260 unsigned int event, void *data);
68261-};
68262+} __do_const;
68263
68264 /**
68265 * struct devfreq - Device devfreq structure
68266diff --git a/include/linux/device.h b/include/linux/device.h
68267index 43dcda9..7a1fb65 100644
68268--- a/include/linux/device.h
68269+++ b/include/linux/device.h
68270@@ -294,7 +294,7 @@ struct subsys_interface {
68271 struct list_head node;
68272 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
68273 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
68274-};
68275+} __do_const;
68276
68277 int subsys_interface_register(struct subsys_interface *sif);
68278 void subsys_interface_unregister(struct subsys_interface *sif);
68279@@ -474,7 +474,7 @@ struct device_type {
68280 void (*release)(struct device *dev);
68281
68282 const struct dev_pm_ops *pm;
68283-};
68284+} __do_const;
68285
68286 /* interface for exporting device attributes */
68287 struct device_attribute {
68288@@ -484,11 +484,12 @@ struct device_attribute {
68289 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
68290 const char *buf, size_t count);
68291 };
68292+typedef struct device_attribute __no_const device_attribute_no_const;
68293
68294 struct dev_ext_attribute {
68295 struct device_attribute attr;
68296 void *var;
68297-};
68298+} __do_const;
68299
68300 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
68301 char *buf);
68302diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
68303index 94af418..b1ca7a2 100644
68304--- a/include/linux/dma-mapping.h
68305+++ b/include/linux/dma-mapping.h
68306@@ -54,7 +54,7 @@ struct dma_map_ops {
68307 u64 (*get_required_mask)(struct device *dev);
68308 #endif
68309 int is_phys;
68310-};
68311+} __do_const;
68312
68313 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
68314
68315diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
68316index d3201e4..8281e63 100644
68317--- a/include/linux/dmaengine.h
68318+++ b/include/linux/dmaengine.h
68319@@ -1018,9 +1018,9 @@ struct dma_pinned_list {
68320 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
68321 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
68322
68323-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
68324+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
68325 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
68326-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
68327+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
68328 struct dma_pinned_list *pinned_list, struct page *page,
68329 unsigned int offset, size_t len);
68330
68331diff --git a/include/linux/efi.h b/include/linux/efi.h
68332index 7a9498a..155713d 100644
68333--- a/include/linux/efi.h
68334+++ b/include/linux/efi.h
68335@@ -733,6 +733,7 @@ struct efivar_operations {
68336 efi_set_variable_t *set_variable;
68337 efi_query_variable_info_t *query_variable_info;
68338 };
68339+typedef struct efivar_operations __no_const efivar_operations_no_const;
68340
68341 struct efivars {
68342 /*
68343diff --git a/include/linux/elf.h b/include/linux/elf.h
68344index 8c9048e..16a4665 100644
68345--- a/include/linux/elf.h
68346+++ b/include/linux/elf.h
68347@@ -20,6 +20,7 @@ extern Elf32_Dyn _DYNAMIC [];
68348 #define elf_note elf32_note
68349 #define elf_addr_t Elf32_Off
68350 #define Elf_Half Elf32_Half
68351+#define elf_dyn Elf32_Dyn
68352
68353 #else
68354
68355@@ -30,6 +31,7 @@ extern Elf64_Dyn _DYNAMIC [];
68356 #define elf_note elf64_note
68357 #define elf_addr_t Elf64_Off
68358 #define Elf_Half Elf64_Half
68359+#define elf_dyn Elf64_Dyn
68360
68361 #endif
68362
68363diff --git a/include/linux/err.h b/include/linux/err.h
68364index f2edce2..cc2082c 100644
68365--- a/include/linux/err.h
68366+++ b/include/linux/err.h
68367@@ -19,12 +19,12 @@
68368
68369 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
68370
68371-static inline void * __must_check ERR_PTR(long error)
68372+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
68373 {
68374 return (void *) error;
68375 }
68376
68377-static inline long __must_check PTR_ERR(const void *ptr)
68378+static inline long __must_check __intentional_overflow(-1) PTR_ERR(const void *ptr)
68379 {
68380 return (long) ptr;
68381 }
68382diff --git a/include/linux/extcon.h b/include/linux/extcon.h
68383index fcb51c8..bdafcf6 100644
68384--- a/include/linux/extcon.h
68385+++ b/include/linux/extcon.h
68386@@ -134,7 +134,7 @@ struct extcon_dev {
68387 /* /sys/class/extcon/.../mutually_exclusive/... */
68388 struct attribute_group attr_g_muex;
68389 struct attribute **attrs_muex;
68390- struct device_attribute *d_attrs_muex;
68391+ device_attribute_no_const *d_attrs_muex;
68392 };
68393
68394 /**
68395diff --git a/include/linux/fb.h b/include/linux/fb.h
68396index c7a9571..02eeffe 100644
68397--- a/include/linux/fb.h
68398+++ b/include/linux/fb.h
68399@@ -302,7 +302,7 @@ struct fb_ops {
68400 /* called at KDB enter and leave time to prepare the console */
68401 int (*fb_debug_enter)(struct fb_info *info);
68402 int (*fb_debug_leave)(struct fb_info *info);
68403-};
68404+} __do_const;
68405
68406 #ifdef CONFIG_FB_TILEBLITTING
68407 #define FB_TILE_CURSOR_NONE 0
68408diff --git a/include/linux/filter.h b/include/linux/filter.h
68409index c45eabc..baa0be5 100644
68410--- a/include/linux/filter.h
68411+++ b/include/linux/filter.h
68412@@ -20,6 +20,7 @@ struct compat_sock_fprog {
68413
68414 struct sk_buff;
68415 struct sock;
68416+struct bpf_jit_work;
68417
68418 struct sk_filter
68419 {
68420@@ -27,6 +28,9 @@ struct sk_filter
68421 unsigned int len; /* Number of filter blocks */
68422 unsigned int (*bpf_func)(const struct sk_buff *skb,
68423 const struct sock_filter *filter);
68424+#ifdef CONFIG_BPF_JIT
68425+ struct bpf_jit_work *work;
68426+#endif
68427 struct rcu_head rcu;
68428 struct sock_filter insns[0];
68429 };
68430diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
68431index 3044254..9767f41 100644
68432--- a/include/linux/frontswap.h
68433+++ b/include/linux/frontswap.h
68434@@ -11,7 +11,7 @@ struct frontswap_ops {
68435 int (*load)(unsigned, pgoff_t, struct page *);
68436 void (*invalidate_page)(unsigned, pgoff_t);
68437 void (*invalidate_area)(unsigned);
68438-};
68439+} __no_const;
68440
68441 extern bool frontswap_enabled;
68442 extern struct frontswap_ops
68443diff --git a/include/linux/fs.h b/include/linux/fs.h
68444index 7617ee0..b575199 100644
68445--- a/include/linux/fs.h
68446+++ b/include/linux/fs.h
68447@@ -1541,7 +1541,8 @@ struct file_operations {
68448 long (*fallocate)(struct file *file, int mode, loff_t offset,
68449 loff_t len);
68450 int (*show_fdinfo)(struct seq_file *m, struct file *f);
68451-};
68452+} __do_const;
68453+typedef struct file_operations __no_const file_operations_no_const;
68454
68455 struct inode_operations {
68456 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
68457@@ -2665,4 +2666,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
68458 inode->i_flags |= S_NOSEC;
68459 }
68460
68461+static inline bool is_sidechannel_device(const struct inode *inode)
68462+{
68463+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
68464+ umode_t mode = inode->i_mode;
68465+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
68466+#else
68467+ return false;
68468+#endif
68469+}
68470+
68471 #endif /* _LINUX_FS_H */
68472diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
68473index 324f931..f292b65 100644
68474--- a/include/linux/fs_struct.h
68475+++ b/include/linux/fs_struct.h
68476@@ -6,7 +6,7 @@
68477 #include <linux/seqlock.h>
68478
68479 struct fs_struct {
68480- int users;
68481+ atomic_t users;
68482 spinlock_t lock;
68483 seqcount_t seq;
68484 int umask;
68485diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
68486index 5dfa0aa..6acf322 100644
68487--- a/include/linux/fscache-cache.h
68488+++ b/include/linux/fscache-cache.h
68489@@ -112,7 +112,7 @@ struct fscache_operation {
68490 fscache_operation_release_t release;
68491 };
68492
68493-extern atomic_t fscache_op_debug_id;
68494+extern atomic_unchecked_t fscache_op_debug_id;
68495 extern void fscache_op_work_func(struct work_struct *work);
68496
68497 extern void fscache_enqueue_operation(struct fscache_operation *);
68498@@ -134,7 +134,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
68499 INIT_WORK(&op->work, fscache_op_work_func);
68500 atomic_set(&op->usage, 1);
68501 op->state = FSCACHE_OP_ST_INITIALISED;
68502- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
68503+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
68504 op->processor = processor;
68505 op->release = release;
68506 INIT_LIST_HEAD(&op->pend_link);
68507diff --git a/include/linux/fscache.h b/include/linux/fscache.h
68508index 7a08623..4c07b0f 100644
68509--- a/include/linux/fscache.h
68510+++ b/include/linux/fscache.h
68511@@ -152,7 +152,7 @@ struct fscache_cookie_def {
68512 * - this is mandatory for any object that may have data
68513 */
68514 void (*now_uncached)(void *cookie_netfs_data);
68515-};
68516+} __do_const;
68517
68518 /*
68519 * fscache cached network filesystem type
68520diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
68521index 0fbfb46..508eb0d 100644
68522--- a/include/linux/fsnotify.h
68523+++ b/include/linux/fsnotify.h
68524@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
68525 struct inode *inode = path->dentry->d_inode;
68526 __u32 mask = FS_ACCESS;
68527
68528+ if (is_sidechannel_device(inode))
68529+ return;
68530+
68531 if (S_ISDIR(inode->i_mode))
68532 mask |= FS_ISDIR;
68533
68534@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
68535 struct inode *inode = path->dentry->d_inode;
68536 __u32 mask = FS_MODIFY;
68537
68538+ if (is_sidechannel_device(inode))
68539+ return;
68540+
68541 if (S_ISDIR(inode->i_mode))
68542 mask |= FS_ISDIR;
68543
68544@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
68545 */
68546 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
68547 {
68548- return kstrdup(name, GFP_KERNEL);
68549+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
68550 }
68551
68552 /*
68553diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
68554index a3d4895..ddd2a50 100644
68555--- a/include/linux/ftrace_event.h
68556+++ b/include/linux/ftrace_event.h
68557@@ -272,7 +272,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
68558 extern int trace_add_event_call(struct ftrace_event_call *call);
68559 extern void trace_remove_event_call(struct ftrace_event_call *call);
68560
68561-#define is_signed_type(type) (((type)(-1)) < 0)
68562+#define is_signed_type(type) (((type)(-1)) < (type)1)
68563
68564 int trace_set_clr_event(const char *system, const char *event, int set);
68565
68566diff --git a/include/linux/genhd.h b/include/linux/genhd.h
68567index 79b8bba..86b539e 100644
68568--- a/include/linux/genhd.h
68569+++ b/include/linux/genhd.h
68570@@ -194,7 +194,7 @@ struct gendisk {
68571 struct kobject *slave_dir;
68572
68573 struct timer_rand_state *random;
68574- atomic_t sync_io; /* RAID */
68575+ atomic_unchecked_t sync_io; /* RAID */
68576 struct disk_events *ev;
68577 #ifdef CONFIG_BLK_DEV_INTEGRITY
68578 struct blk_integrity *integrity;
68579diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
68580index 023bc34..b02b46a 100644
68581--- a/include/linux/genl_magic_func.h
68582+++ b/include/linux/genl_magic_func.h
68583@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
68584 },
68585
68586 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
68587-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
68588+static struct genl_ops ZZZ_genl_ops[] = {
68589 #include GENL_MAGIC_INCLUDE_FILE
68590 };
68591
68592diff --git a/include/linux/gfp.h b/include/linux/gfp.h
68593index 0f615eb..5c3832f 100644
68594--- a/include/linux/gfp.h
68595+++ b/include/linux/gfp.h
68596@@ -35,6 +35,13 @@ struct vm_area_struct;
68597 #define ___GFP_NO_KSWAPD 0x400000u
68598 #define ___GFP_OTHER_NODE 0x800000u
68599 #define ___GFP_WRITE 0x1000000u
68600+
68601+#ifdef CONFIG_PAX_USERCOPY_SLABS
68602+#define ___GFP_USERCOPY 0x2000000u
68603+#else
68604+#define ___GFP_USERCOPY 0
68605+#endif
68606+
68607 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
68608
68609 /*
68610@@ -92,6 +99,7 @@ struct vm_area_struct;
68611 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
68612 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
68613 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
68614+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
68615
68616 /*
68617 * This may seem redundant, but it's a way of annotating false positives vs.
68618@@ -99,7 +107,7 @@ struct vm_area_struct;
68619 */
68620 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
68621
68622-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
68623+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
68624 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
68625
68626 /* This equals 0, but use constants in case they ever change */
68627@@ -153,6 +161,8 @@ struct vm_area_struct;
68628 /* 4GB DMA on some platforms */
68629 #define GFP_DMA32 __GFP_DMA32
68630
68631+#define GFP_USERCOPY __GFP_USERCOPY
68632+
68633 /* Convert GFP flags to their corresponding migrate type */
68634 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
68635 {
68636diff --git a/include/linux/gracl.h b/include/linux/gracl.h
68637new file mode 100644
68638index 0000000..ebe6d72
68639--- /dev/null
68640+++ b/include/linux/gracl.h
68641@@ -0,0 +1,319 @@
68642+#ifndef GR_ACL_H
68643+#define GR_ACL_H
68644+
68645+#include <linux/grdefs.h>
68646+#include <linux/resource.h>
68647+#include <linux/capability.h>
68648+#include <linux/dcache.h>
68649+#include <asm/resource.h>
68650+
68651+/* Major status information */
68652+
68653+#define GR_VERSION "grsecurity 2.9.1"
68654+#define GRSECURITY_VERSION 0x2901
68655+
68656+enum {
68657+ GR_SHUTDOWN = 0,
68658+ GR_ENABLE = 1,
68659+ GR_SPROLE = 2,
68660+ GR_RELOAD = 3,
68661+ GR_SEGVMOD = 4,
68662+ GR_STATUS = 5,
68663+ GR_UNSPROLE = 6,
68664+ GR_PASSSET = 7,
68665+ GR_SPROLEPAM = 8,
68666+};
68667+
68668+/* Password setup definitions
68669+ * kernel/grhash.c */
68670+enum {
68671+ GR_PW_LEN = 128,
68672+ GR_SALT_LEN = 16,
68673+ GR_SHA_LEN = 32,
68674+};
68675+
68676+enum {
68677+ GR_SPROLE_LEN = 64,
68678+};
68679+
68680+enum {
68681+ GR_NO_GLOB = 0,
68682+ GR_REG_GLOB,
68683+ GR_CREATE_GLOB
68684+};
68685+
68686+#define GR_NLIMITS 32
68687+
68688+/* Begin Data Structures */
68689+
68690+struct sprole_pw {
68691+ unsigned char *rolename;
68692+ unsigned char salt[GR_SALT_LEN];
68693+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
68694+};
68695+
68696+struct name_entry {
68697+ __u32 key;
68698+ ino_t inode;
68699+ dev_t device;
68700+ char *name;
68701+ __u16 len;
68702+ __u8 deleted;
68703+ struct name_entry *prev;
68704+ struct name_entry *next;
68705+};
68706+
68707+struct inodev_entry {
68708+ struct name_entry *nentry;
68709+ struct inodev_entry *prev;
68710+ struct inodev_entry *next;
68711+};
68712+
68713+struct acl_role_db {
68714+ struct acl_role_label **r_hash;
68715+ __u32 r_size;
68716+};
68717+
68718+struct inodev_db {
68719+ struct inodev_entry **i_hash;
68720+ __u32 i_size;
68721+};
68722+
68723+struct name_db {
68724+ struct name_entry **n_hash;
68725+ __u32 n_size;
68726+};
68727+
68728+struct crash_uid {
68729+ uid_t uid;
68730+ unsigned long expires;
68731+};
68732+
68733+struct gr_hash_struct {
68734+ void **table;
68735+ void **nametable;
68736+ void *first;
68737+ __u32 table_size;
68738+ __u32 used_size;
68739+ int type;
68740+};
68741+
68742+/* Userspace Grsecurity ACL data structures */
68743+
68744+struct acl_subject_label {
68745+ char *filename;
68746+ ino_t inode;
68747+ dev_t device;
68748+ __u32 mode;
68749+ kernel_cap_t cap_mask;
68750+ kernel_cap_t cap_lower;
68751+ kernel_cap_t cap_invert_audit;
68752+
68753+ struct rlimit res[GR_NLIMITS];
68754+ __u32 resmask;
68755+
68756+ __u8 user_trans_type;
68757+ __u8 group_trans_type;
68758+ uid_t *user_transitions;
68759+ gid_t *group_transitions;
68760+ __u16 user_trans_num;
68761+ __u16 group_trans_num;
68762+
68763+ __u32 sock_families[2];
68764+ __u32 ip_proto[8];
68765+ __u32 ip_type;
68766+ struct acl_ip_label **ips;
68767+ __u32 ip_num;
68768+ __u32 inaddr_any_override;
68769+
68770+ __u32 crashes;
68771+ unsigned long expires;
68772+
68773+ struct acl_subject_label *parent_subject;
68774+ struct gr_hash_struct *hash;
68775+ struct acl_subject_label *prev;
68776+ struct acl_subject_label *next;
68777+
68778+ struct acl_object_label **obj_hash;
68779+ __u32 obj_hash_size;
68780+ __u16 pax_flags;
68781+};
68782+
68783+struct role_allowed_ip {
68784+ __u32 addr;
68785+ __u32 netmask;
68786+
68787+ struct role_allowed_ip *prev;
68788+ struct role_allowed_ip *next;
68789+};
68790+
68791+struct role_transition {
68792+ char *rolename;
68793+
68794+ struct role_transition *prev;
68795+ struct role_transition *next;
68796+};
68797+
68798+struct acl_role_label {
68799+ char *rolename;
68800+ uid_t uidgid;
68801+ __u16 roletype;
68802+
68803+ __u16 auth_attempts;
68804+ unsigned long expires;
68805+
68806+ struct acl_subject_label *root_label;
68807+ struct gr_hash_struct *hash;
68808+
68809+ struct acl_role_label *prev;
68810+ struct acl_role_label *next;
68811+
68812+ struct role_transition *transitions;
68813+ struct role_allowed_ip *allowed_ips;
68814+ uid_t *domain_children;
68815+ __u16 domain_child_num;
68816+
68817+ umode_t umask;
68818+
68819+ struct acl_subject_label **subj_hash;
68820+ __u32 subj_hash_size;
68821+};
68822+
68823+struct user_acl_role_db {
68824+ struct acl_role_label **r_table;
68825+ __u32 num_pointers; /* Number of allocations to track */
68826+ __u32 num_roles; /* Number of roles */
68827+ __u32 num_domain_children; /* Number of domain children */
68828+ __u32 num_subjects; /* Number of subjects */
68829+ __u32 num_objects; /* Number of objects */
68830+};
68831+
68832+struct acl_object_label {
68833+ char *filename;
68834+ ino_t inode;
68835+ dev_t device;
68836+ __u32 mode;
68837+
68838+ struct acl_subject_label *nested;
68839+ struct acl_object_label *globbed;
68840+
68841+ /* next two structures not used */
68842+
68843+ struct acl_object_label *prev;
68844+ struct acl_object_label *next;
68845+};
68846+
68847+struct acl_ip_label {
68848+ char *iface;
68849+ __u32 addr;
68850+ __u32 netmask;
68851+ __u16 low, high;
68852+ __u8 mode;
68853+ __u32 type;
68854+ __u32 proto[8];
68855+
68856+ /* next two structures not used */
68857+
68858+ struct acl_ip_label *prev;
68859+ struct acl_ip_label *next;
68860+};
68861+
68862+struct gr_arg {
68863+ struct user_acl_role_db role_db;
68864+ unsigned char pw[GR_PW_LEN];
68865+ unsigned char salt[GR_SALT_LEN];
68866+ unsigned char sum[GR_SHA_LEN];
68867+ unsigned char sp_role[GR_SPROLE_LEN];
68868+ struct sprole_pw *sprole_pws;
68869+ dev_t segv_device;
68870+ ino_t segv_inode;
68871+ uid_t segv_uid;
68872+ __u16 num_sprole_pws;
68873+ __u16 mode;
68874+};
68875+
68876+struct gr_arg_wrapper {
68877+ struct gr_arg *arg;
68878+ __u32 version;
68879+ __u32 size;
68880+};
68881+
68882+struct subject_map {
68883+ struct acl_subject_label *user;
68884+ struct acl_subject_label *kernel;
68885+ struct subject_map *prev;
68886+ struct subject_map *next;
68887+};
68888+
68889+struct acl_subj_map_db {
68890+ struct subject_map **s_hash;
68891+ __u32 s_size;
68892+};
68893+
68894+/* End Data Structures Section */
68895+
68896+/* Hash functions generated by empirical testing by Brad Spengler
68897+ Makes good use of the low bits of the inode. Generally 0-1 times
68898+ in loop for successful match. 0-3 for unsuccessful match.
68899+ Shift/add algorithm with modulus of table size and an XOR*/
68900+
68901+static __inline__ unsigned int
68902+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
68903+{
68904+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
68905+}
68906+
68907+ static __inline__ unsigned int
68908+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
68909+{
68910+ return ((const unsigned long)userp % sz);
68911+}
68912+
68913+static __inline__ unsigned int
68914+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
68915+{
68916+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
68917+}
68918+
68919+static __inline__ unsigned int
68920+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
68921+{
68922+ return full_name_hash((const unsigned char *)name, len) % sz;
68923+}
68924+
68925+#define FOR_EACH_ROLE_START(role) \
68926+ role = role_list; \
68927+ while (role) {
68928+
68929+#define FOR_EACH_ROLE_END(role) \
68930+ role = role->prev; \
68931+ }
68932+
68933+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
68934+ subj = NULL; \
68935+ iter = 0; \
68936+ while (iter < role->subj_hash_size) { \
68937+ if (subj == NULL) \
68938+ subj = role->subj_hash[iter]; \
68939+ if (subj == NULL) { \
68940+ iter++; \
68941+ continue; \
68942+ }
68943+
68944+#define FOR_EACH_SUBJECT_END(subj,iter) \
68945+ subj = subj->next; \
68946+ if (subj == NULL) \
68947+ iter++; \
68948+ }
68949+
68950+
68951+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
68952+ subj = role->hash->first; \
68953+ while (subj != NULL) {
68954+
68955+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
68956+ subj = subj->next; \
68957+ }
68958+
68959+#endif
68960+
68961diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
68962new file mode 100644
68963index 0000000..323ecf2
68964--- /dev/null
68965+++ b/include/linux/gralloc.h
68966@@ -0,0 +1,9 @@
68967+#ifndef __GRALLOC_H
68968+#define __GRALLOC_H
68969+
68970+void acl_free_all(void);
68971+int acl_alloc_stack_init(unsigned long size);
68972+void *acl_alloc(unsigned long len);
68973+void *acl_alloc_num(unsigned long num, unsigned long len);
68974+
68975+#endif
68976diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
68977new file mode 100644
68978index 0000000..be66033
68979--- /dev/null
68980+++ b/include/linux/grdefs.h
68981@@ -0,0 +1,140 @@
68982+#ifndef GRDEFS_H
68983+#define GRDEFS_H
68984+
68985+/* Begin grsecurity status declarations */
68986+
68987+enum {
68988+ GR_READY = 0x01,
68989+ GR_STATUS_INIT = 0x00 // disabled state
68990+};
68991+
68992+/* Begin ACL declarations */
68993+
68994+/* Role flags */
68995+
68996+enum {
68997+ GR_ROLE_USER = 0x0001,
68998+ GR_ROLE_GROUP = 0x0002,
68999+ GR_ROLE_DEFAULT = 0x0004,
69000+ GR_ROLE_SPECIAL = 0x0008,
69001+ GR_ROLE_AUTH = 0x0010,
69002+ GR_ROLE_NOPW = 0x0020,
69003+ GR_ROLE_GOD = 0x0040,
69004+ GR_ROLE_LEARN = 0x0080,
69005+ GR_ROLE_TPE = 0x0100,
69006+ GR_ROLE_DOMAIN = 0x0200,
69007+ GR_ROLE_PAM = 0x0400,
69008+ GR_ROLE_PERSIST = 0x0800
69009+};
69010+
69011+/* ACL Subject and Object mode flags */
69012+enum {
69013+ GR_DELETED = 0x80000000
69014+};
69015+
69016+/* ACL Object-only mode flags */
69017+enum {
69018+ GR_READ = 0x00000001,
69019+ GR_APPEND = 0x00000002,
69020+ GR_WRITE = 0x00000004,
69021+ GR_EXEC = 0x00000008,
69022+ GR_FIND = 0x00000010,
69023+ GR_INHERIT = 0x00000020,
69024+ GR_SETID = 0x00000040,
69025+ GR_CREATE = 0x00000080,
69026+ GR_DELETE = 0x00000100,
69027+ GR_LINK = 0x00000200,
69028+ GR_AUDIT_READ = 0x00000400,
69029+ GR_AUDIT_APPEND = 0x00000800,
69030+ GR_AUDIT_WRITE = 0x00001000,
69031+ GR_AUDIT_EXEC = 0x00002000,
69032+ GR_AUDIT_FIND = 0x00004000,
69033+ GR_AUDIT_INHERIT= 0x00008000,
69034+ GR_AUDIT_SETID = 0x00010000,
69035+ GR_AUDIT_CREATE = 0x00020000,
69036+ GR_AUDIT_DELETE = 0x00040000,
69037+ GR_AUDIT_LINK = 0x00080000,
69038+ GR_PTRACERD = 0x00100000,
69039+ GR_NOPTRACE = 0x00200000,
69040+ GR_SUPPRESS = 0x00400000,
69041+ GR_NOLEARN = 0x00800000,
69042+ GR_INIT_TRANSFER= 0x01000000
69043+};
69044+
69045+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
69046+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
69047+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
69048+
69049+/* ACL subject-only mode flags */
69050+enum {
69051+ GR_KILL = 0x00000001,
69052+ GR_VIEW = 0x00000002,
69053+ GR_PROTECTED = 0x00000004,
69054+ GR_LEARN = 0x00000008,
69055+ GR_OVERRIDE = 0x00000010,
69056+ /* just a placeholder, this mode is only used in userspace */
69057+ GR_DUMMY = 0x00000020,
69058+ GR_PROTSHM = 0x00000040,
69059+ GR_KILLPROC = 0x00000080,
69060+ GR_KILLIPPROC = 0x00000100,
69061+ /* just a placeholder, this mode is only used in userspace */
69062+ GR_NOTROJAN = 0x00000200,
69063+ GR_PROTPROCFD = 0x00000400,
69064+ GR_PROCACCT = 0x00000800,
69065+ GR_RELAXPTRACE = 0x00001000,
69066+ //GR_NESTED = 0x00002000,
69067+ GR_INHERITLEARN = 0x00004000,
69068+ GR_PROCFIND = 0x00008000,
69069+ GR_POVERRIDE = 0x00010000,
69070+ GR_KERNELAUTH = 0x00020000,
69071+ GR_ATSECURE = 0x00040000,
69072+ GR_SHMEXEC = 0x00080000
69073+};
69074+
69075+enum {
69076+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
69077+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
69078+ GR_PAX_ENABLE_MPROTECT = 0x0004,
69079+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
69080+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
69081+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
69082+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
69083+ GR_PAX_DISABLE_MPROTECT = 0x0400,
69084+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
69085+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
69086+};
69087+
69088+enum {
69089+ GR_ID_USER = 0x01,
69090+ GR_ID_GROUP = 0x02,
69091+};
69092+
69093+enum {
69094+ GR_ID_ALLOW = 0x01,
69095+ GR_ID_DENY = 0x02,
69096+};
69097+
69098+#define GR_CRASH_RES 31
69099+#define GR_UIDTABLE_MAX 500
69100+
69101+/* begin resource learning section */
69102+enum {
69103+ GR_RLIM_CPU_BUMP = 60,
69104+ GR_RLIM_FSIZE_BUMP = 50000,
69105+ GR_RLIM_DATA_BUMP = 10000,
69106+ GR_RLIM_STACK_BUMP = 1000,
69107+ GR_RLIM_CORE_BUMP = 10000,
69108+ GR_RLIM_RSS_BUMP = 500000,
69109+ GR_RLIM_NPROC_BUMP = 1,
69110+ GR_RLIM_NOFILE_BUMP = 5,
69111+ GR_RLIM_MEMLOCK_BUMP = 50000,
69112+ GR_RLIM_AS_BUMP = 500000,
69113+ GR_RLIM_LOCKS_BUMP = 2,
69114+ GR_RLIM_SIGPENDING_BUMP = 5,
69115+ GR_RLIM_MSGQUEUE_BUMP = 10000,
69116+ GR_RLIM_NICE_BUMP = 1,
69117+ GR_RLIM_RTPRIO_BUMP = 1,
69118+ GR_RLIM_RTTIME_BUMP = 1000000
69119+};
69120+
69121+#endif
69122diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
69123new file mode 100644
69124index 0000000..9bb6662
69125--- /dev/null
69126+++ b/include/linux/grinternal.h
69127@@ -0,0 +1,215 @@
69128+#ifndef __GRINTERNAL_H
69129+#define __GRINTERNAL_H
69130+
69131+#ifdef CONFIG_GRKERNSEC
69132+
69133+#include <linux/fs.h>
69134+#include <linux/mnt_namespace.h>
69135+#include <linux/nsproxy.h>
69136+#include <linux/gracl.h>
69137+#include <linux/grdefs.h>
69138+#include <linux/grmsg.h>
69139+
69140+void gr_add_learn_entry(const char *fmt, ...)
69141+ __attribute__ ((format (printf, 1, 2)));
69142+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
69143+ const struct vfsmount *mnt);
69144+__u32 gr_check_create(const struct dentry *new_dentry,
69145+ const struct dentry *parent,
69146+ const struct vfsmount *mnt, const __u32 mode);
69147+int gr_check_protected_task(const struct task_struct *task);
69148+__u32 to_gr_audit(const __u32 reqmode);
69149+int gr_set_acls(const int type);
69150+int gr_apply_subject_to_task(struct task_struct *task);
69151+int gr_acl_is_enabled(void);
69152+char gr_roletype_to_char(void);
69153+
69154+void gr_handle_alertkill(struct task_struct *task);
69155+char *gr_to_filename(const struct dentry *dentry,
69156+ const struct vfsmount *mnt);
69157+char *gr_to_filename1(const struct dentry *dentry,
69158+ const struct vfsmount *mnt);
69159+char *gr_to_filename2(const struct dentry *dentry,
69160+ const struct vfsmount *mnt);
69161+char *gr_to_filename3(const struct dentry *dentry,
69162+ const struct vfsmount *mnt);
69163+
69164+extern int grsec_enable_ptrace_readexec;
69165+extern int grsec_enable_harden_ptrace;
69166+extern int grsec_enable_link;
69167+extern int grsec_enable_fifo;
69168+extern int grsec_enable_execve;
69169+extern int grsec_enable_shm;
69170+extern int grsec_enable_execlog;
69171+extern int grsec_enable_signal;
69172+extern int grsec_enable_audit_ptrace;
69173+extern int grsec_enable_forkfail;
69174+extern int grsec_enable_time;
69175+extern int grsec_enable_rofs;
69176+extern int grsec_enable_chroot_shmat;
69177+extern int grsec_enable_chroot_mount;
69178+extern int grsec_enable_chroot_double;
69179+extern int grsec_enable_chroot_pivot;
69180+extern int grsec_enable_chroot_chdir;
69181+extern int grsec_enable_chroot_chmod;
69182+extern int grsec_enable_chroot_mknod;
69183+extern int grsec_enable_chroot_fchdir;
69184+extern int grsec_enable_chroot_nice;
69185+extern int grsec_enable_chroot_execlog;
69186+extern int grsec_enable_chroot_caps;
69187+extern int grsec_enable_chroot_sysctl;
69188+extern int grsec_enable_chroot_unix;
69189+extern int grsec_enable_symlinkown;
69190+extern kgid_t grsec_symlinkown_gid;
69191+extern int grsec_enable_tpe;
69192+extern kgid_t grsec_tpe_gid;
69193+extern int grsec_enable_tpe_all;
69194+extern int grsec_enable_tpe_invert;
69195+extern int grsec_enable_socket_all;
69196+extern kgid_t grsec_socket_all_gid;
69197+extern int grsec_enable_socket_client;
69198+extern kgid_t grsec_socket_client_gid;
69199+extern int grsec_enable_socket_server;
69200+extern kgid_t grsec_socket_server_gid;
69201+extern kgid_t grsec_audit_gid;
69202+extern int grsec_enable_group;
69203+extern int grsec_enable_audit_textrel;
69204+extern int grsec_enable_log_rwxmaps;
69205+extern int grsec_enable_mount;
69206+extern int grsec_enable_chdir;
69207+extern int grsec_resource_logging;
69208+extern int grsec_enable_blackhole;
69209+extern int grsec_lastack_retries;
69210+extern int grsec_enable_brute;
69211+extern int grsec_lock;
69212+
69213+extern spinlock_t grsec_alert_lock;
69214+extern unsigned long grsec_alert_wtime;
69215+extern unsigned long grsec_alert_fyet;
69216+
69217+extern spinlock_t grsec_audit_lock;
69218+
69219+extern rwlock_t grsec_exec_file_lock;
69220+
69221+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
69222+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
69223+ (tsk)->exec_file->f_vfsmnt) : "/")
69224+
69225+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
69226+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
69227+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
69228+
69229+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
69230+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
69231+ (tsk)->exec_file->f_vfsmnt) : "/")
69232+
69233+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
69234+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
69235+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
69236+
69237+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
69238+
69239+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
69240+
69241+#define GR_CHROOT_CAPS {{ \
69242+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
69243+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
69244+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
69245+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
69246+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
69247+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
69248+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
69249+
69250+#define security_learn(normal_msg,args...) \
69251+({ \
69252+ read_lock(&grsec_exec_file_lock); \
69253+ gr_add_learn_entry(normal_msg "\n", ## args); \
69254+ read_unlock(&grsec_exec_file_lock); \
69255+})
69256+
69257+enum {
69258+ GR_DO_AUDIT,
69259+ GR_DONT_AUDIT,
69260+ /* used for non-audit messages that we shouldn't kill the task on */
69261+ GR_DONT_AUDIT_GOOD
69262+};
69263+
69264+enum {
69265+ GR_TTYSNIFF,
69266+ GR_RBAC,
69267+ GR_RBAC_STR,
69268+ GR_STR_RBAC,
69269+ GR_RBAC_MODE2,
69270+ GR_RBAC_MODE3,
69271+ GR_FILENAME,
69272+ GR_SYSCTL_HIDDEN,
69273+ GR_NOARGS,
69274+ GR_ONE_INT,
69275+ GR_ONE_INT_TWO_STR,
69276+ GR_ONE_STR,
69277+ GR_STR_INT,
69278+ GR_TWO_STR_INT,
69279+ GR_TWO_INT,
69280+ GR_TWO_U64,
69281+ GR_THREE_INT,
69282+ GR_FIVE_INT_TWO_STR,
69283+ GR_TWO_STR,
69284+ GR_THREE_STR,
69285+ GR_FOUR_STR,
69286+ GR_STR_FILENAME,
69287+ GR_FILENAME_STR,
69288+ GR_FILENAME_TWO_INT,
69289+ GR_FILENAME_TWO_INT_STR,
69290+ GR_TEXTREL,
69291+ GR_PTRACE,
69292+ GR_RESOURCE,
69293+ GR_CAP,
69294+ GR_SIG,
69295+ GR_SIG2,
69296+ GR_CRASH1,
69297+ GR_CRASH2,
69298+ GR_PSACCT,
69299+ GR_RWXMAP
69300+};
69301+
69302+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
69303+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
69304+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
69305+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
69306+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
69307+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
69308+#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)
69309+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
69310+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
69311+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
69312+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
69313+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
69314+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
69315+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
69316+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
69317+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
69318+#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)
69319+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
69320+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
69321+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
69322+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
69323+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
69324+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
69325+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
69326+#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)
69327+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
69328+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
69329+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
69330+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
69331+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
69332+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
69333+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
69334+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
69335+#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)
69336+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
69337+
69338+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
69339+
69340+#endif
69341+
69342+#endif
69343diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
69344new file mode 100644
69345index 0000000..2bd4c8d
69346--- /dev/null
69347+++ b/include/linux/grmsg.h
69348@@ -0,0 +1,111 @@
69349+#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"
69350+#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"
69351+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
69352+#define GR_STOPMOD_MSG "denied modification of module state by "
69353+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
69354+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
69355+#define GR_IOPERM_MSG "denied use of ioperm() by "
69356+#define GR_IOPL_MSG "denied use of iopl() by "
69357+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
69358+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
69359+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
69360+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
69361+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
69362+#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"
69363+#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"
69364+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
69365+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
69366+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
69367+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
69368+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
69369+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
69370+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
69371+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
69372+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
69373+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
69374+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
69375+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
69376+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
69377+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
69378+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
69379+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
69380+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
69381+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
69382+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
69383+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
69384+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
69385+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
69386+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
69387+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
69388+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
69389+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
69390+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
69391+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
69392+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
69393+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
69394+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
69395+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
69396+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
69397+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
69398+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
69399+#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"
69400+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
69401+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
69402+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
69403+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
69404+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
69405+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
69406+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
69407+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
69408+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
69409+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
69410+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
69411+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
69412+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
69413+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
69414+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
69415+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
69416+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
69417+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
69418+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
69419+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
69420+#define GR_FAILFORK_MSG "failed fork with errno %s by "
69421+#define GR_NICE_CHROOT_MSG "denied priority change by "
69422+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
69423+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
69424+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
69425+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
69426+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
69427+#define GR_TIME_MSG "time set by "
69428+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
69429+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
69430+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
69431+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
69432+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
69433+#define GR_BIND_MSG "denied bind() by "
69434+#define GR_CONNECT_MSG "denied connect() by "
69435+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
69436+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
69437+#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"
69438+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
69439+#define GR_CAP_ACL_MSG "use of %s denied for "
69440+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
69441+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
69442+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
69443+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
69444+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
69445+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
69446+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
69447+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
69448+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
69449+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
69450+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
69451+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
69452+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
69453+#define GR_VM86_MSG "denied use of vm86 by "
69454+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
69455+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
69456+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
69457+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
69458+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
69459+#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 "
69460diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
69461new file mode 100644
69462index 0000000..8da63a4
69463--- /dev/null
69464+++ b/include/linux/grsecurity.h
69465@@ -0,0 +1,242 @@
69466+#ifndef GR_SECURITY_H
69467+#define GR_SECURITY_H
69468+#include <linux/fs.h>
69469+#include <linux/fs_struct.h>
69470+#include <linux/binfmts.h>
69471+#include <linux/gracl.h>
69472+
69473+/* notify of brain-dead configs */
69474+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69475+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
69476+#endif
69477+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
69478+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
69479+#endif
69480+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
69481+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
69482+#endif
69483+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
69484+#error "CONFIG_PAX enabled, but no PaX options are enabled."
69485+#endif
69486+
69487+void gr_handle_brute_attach(unsigned long mm_flags);
69488+void gr_handle_brute_check(void);
69489+void gr_handle_kernel_exploit(void);
69490+int gr_process_user_ban(void);
69491+
69492+char gr_roletype_to_char(void);
69493+
69494+int gr_acl_enable_at_secure(void);
69495+
69496+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
69497+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
69498+
69499+void gr_del_task_from_ip_table(struct task_struct *p);
69500+
69501+int gr_pid_is_chrooted(struct task_struct *p);
69502+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
69503+int gr_handle_chroot_nice(void);
69504+int gr_handle_chroot_sysctl(const int op);
69505+int gr_handle_chroot_setpriority(struct task_struct *p,
69506+ const int niceval);
69507+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
69508+int gr_handle_chroot_chroot(const struct dentry *dentry,
69509+ const struct vfsmount *mnt);
69510+void gr_handle_chroot_chdir(struct path *path);
69511+int gr_handle_chroot_chmod(const struct dentry *dentry,
69512+ const struct vfsmount *mnt, const int mode);
69513+int gr_handle_chroot_mknod(const struct dentry *dentry,
69514+ const struct vfsmount *mnt, const int mode);
69515+int gr_handle_chroot_mount(const struct dentry *dentry,
69516+ const struct vfsmount *mnt,
69517+ const char *dev_name);
69518+int gr_handle_chroot_pivot(void);
69519+int gr_handle_chroot_unix(const pid_t pid);
69520+
69521+int gr_handle_rawio(const struct inode *inode);
69522+
69523+void gr_handle_ioperm(void);
69524+void gr_handle_iopl(void);
69525+
69526+umode_t gr_acl_umask(void);
69527+
69528+int gr_tpe_allow(const struct file *file);
69529+
69530+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
69531+void gr_clear_chroot_entries(struct task_struct *task);
69532+
69533+void gr_log_forkfail(const int retval);
69534+void gr_log_timechange(void);
69535+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
69536+void gr_log_chdir(const struct dentry *dentry,
69537+ const struct vfsmount *mnt);
69538+void gr_log_chroot_exec(const struct dentry *dentry,
69539+ const struct vfsmount *mnt);
69540+void gr_log_remount(const char *devname, const int retval);
69541+void gr_log_unmount(const char *devname, const int retval);
69542+void gr_log_mount(const char *from, const char *to, const int retval);
69543+void gr_log_textrel(struct vm_area_struct *vma);
69544+void gr_log_rwxmmap(struct file *file);
69545+void gr_log_rwxmprotect(struct file *file);
69546+
69547+int gr_handle_follow_link(const struct inode *parent,
69548+ const struct inode *inode,
69549+ const struct dentry *dentry,
69550+ const struct vfsmount *mnt);
69551+int gr_handle_fifo(const struct dentry *dentry,
69552+ const struct vfsmount *mnt,
69553+ const struct dentry *dir, const int flag,
69554+ const int acc_mode);
69555+int gr_handle_hardlink(const struct dentry *dentry,
69556+ const struct vfsmount *mnt,
69557+ struct inode *inode,
69558+ const int mode, const struct filename *to);
69559+
69560+int gr_is_capable(const int cap);
69561+int gr_is_capable_nolog(const int cap);
69562+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
69563+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
69564+
69565+void gr_copy_label(struct task_struct *tsk);
69566+void gr_handle_crash(struct task_struct *task, const int sig);
69567+int gr_handle_signal(const struct task_struct *p, const int sig);
69568+int gr_check_crash_uid(const kuid_t uid);
69569+int gr_check_protected_task(const struct task_struct *task);
69570+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
69571+int gr_acl_handle_mmap(const struct file *file,
69572+ const unsigned long prot);
69573+int gr_acl_handle_mprotect(const struct file *file,
69574+ const unsigned long prot);
69575+int gr_check_hidden_task(const struct task_struct *tsk);
69576+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
69577+ const struct vfsmount *mnt);
69578+__u32 gr_acl_handle_utime(const struct dentry *dentry,
69579+ const struct vfsmount *mnt);
69580+__u32 gr_acl_handle_access(const struct dentry *dentry,
69581+ const struct vfsmount *mnt, const int fmode);
69582+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
69583+ const struct vfsmount *mnt, umode_t *mode);
69584+__u32 gr_acl_handle_chown(const struct dentry *dentry,
69585+ const struct vfsmount *mnt);
69586+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
69587+ const struct vfsmount *mnt);
69588+int gr_handle_ptrace(struct task_struct *task, const long request);
69589+int gr_handle_proc_ptrace(struct task_struct *task);
69590+__u32 gr_acl_handle_execve(const struct dentry *dentry,
69591+ const struct vfsmount *mnt);
69592+int gr_check_crash_exec(const struct file *filp);
69593+int gr_acl_is_enabled(void);
69594+void gr_set_kernel_label(struct task_struct *task);
69595+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
69596+ const kgid_t gid);
69597+int gr_set_proc_label(const struct dentry *dentry,
69598+ const struct vfsmount *mnt,
69599+ const int unsafe_flags);
69600+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
69601+ const struct vfsmount *mnt);
69602+__u32 gr_acl_handle_open(const struct dentry *dentry,
69603+ const struct vfsmount *mnt, int acc_mode);
69604+__u32 gr_acl_handle_creat(const struct dentry *dentry,
69605+ const struct dentry *p_dentry,
69606+ const struct vfsmount *p_mnt,
69607+ int open_flags, int acc_mode, const int imode);
69608+void gr_handle_create(const struct dentry *dentry,
69609+ const struct vfsmount *mnt);
69610+void gr_handle_proc_create(const struct dentry *dentry,
69611+ const struct inode *inode);
69612+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
69613+ const struct dentry *parent_dentry,
69614+ const struct vfsmount *parent_mnt,
69615+ const int mode);
69616+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
69617+ const struct dentry *parent_dentry,
69618+ const struct vfsmount *parent_mnt);
69619+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
69620+ const struct vfsmount *mnt);
69621+void gr_handle_delete(const ino_t ino, const dev_t dev);
69622+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
69623+ const struct vfsmount *mnt);
69624+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
69625+ const struct dentry *parent_dentry,
69626+ const struct vfsmount *parent_mnt,
69627+ const struct filename *from);
69628+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
69629+ const struct dentry *parent_dentry,
69630+ const struct vfsmount *parent_mnt,
69631+ const struct dentry *old_dentry,
69632+ const struct vfsmount *old_mnt, const struct filename *to);
69633+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
69634+int gr_acl_handle_rename(struct dentry *new_dentry,
69635+ struct dentry *parent_dentry,
69636+ const struct vfsmount *parent_mnt,
69637+ struct dentry *old_dentry,
69638+ struct inode *old_parent_inode,
69639+ struct vfsmount *old_mnt, const struct filename *newname);
69640+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
69641+ struct dentry *old_dentry,
69642+ struct dentry *new_dentry,
69643+ struct vfsmount *mnt, const __u8 replace);
69644+__u32 gr_check_link(const struct dentry *new_dentry,
69645+ const struct dentry *parent_dentry,
69646+ const struct vfsmount *parent_mnt,
69647+ const struct dentry *old_dentry,
69648+ const struct vfsmount *old_mnt);
69649+int gr_acl_handle_filldir(const struct file *file, const char *name,
69650+ const unsigned int namelen, const ino_t ino);
69651+
69652+__u32 gr_acl_handle_unix(const struct dentry *dentry,
69653+ const struct vfsmount *mnt);
69654+void gr_acl_handle_exit(void);
69655+void gr_acl_handle_psacct(struct task_struct *task, const long code);
69656+int gr_acl_handle_procpidmem(const struct task_struct *task);
69657+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
69658+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
69659+void gr_audit_ptrace(struct task_struct *task);
69660+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
69661+void gr_put_exec_file(struct task_struct *task);
69662+
69663+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
69664+
69665+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
69666+extern void gr_learn_resource(const struct task_struct *task, const int res,
69667+ const unsigned long wanted, const int gt);
69668+#else
69669+static inline void gr_learn_resource(const struct task_struct *task, const int res,
69670+ const unsigned long wanted, const int gt)
69671+{
69672+}
69673+#endif
69674+
69675+#ifdef CONFIG_GRKERNSEC_RESLOG
69676+extern void gr_log_resource(const struct task_struct *task, const int res,
69677+ const unsigned long wanted, const int gt);
69678+#else
69679+static inline void gr_log_resource(const struct task_struct *task, const int res,
69680+ const unsigned long wanted, const int gt)
69681+{
69682+}
69683+#endif
69684+
69685+#ifdef CONFIG_GRKERNSEC
69686+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
69687+void gr_handle_vm86(void);
69688+void gr_handle_mem_readwrite(u64 from, u64 to);
69689+
69690+void gr_log_badprocpid(const char *entry);
69691+
69692+extern int grsec_enable_dmesg;
69693+extern int grsec_disable_privio;
69694+
69695+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
69696+extern kgid_t grsec_proc_gid;
69697+#endif
69698+
69699+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69700+extern int grsec_enable_chroot_findtask;
69701+#endif
69702+#ifdef CONFIG_GRKERNSEC_SETXID
69703+extern int grsec_enable_setxid;
69704+#endif
69705+#endif
69706+
69707+#endif
69708diff --git a/include/linux/grsock.h b/include/linux/grsock.h
69709new file mode 100644
69710index 0000000..e7ffaaf
69711--- /dev/null
69712+++ b/include/linux/grsock.h
69713@@ -0,0 +1,19 @@
69714+#ifndef __GRSOCK_H
69715+#define __GRSOCK_H
69716+
69717+extern void gr_attach_curr_ip(const struct sock *sk);
69718+extern int gr_handle_sock_all(const int family, const int type,
69719+ const int protocol);
69720+extern int gr_handle_sock_server(const struct sockaddr *sck);
69721+extern int gr_handle_sock_server_other(const struct sock *sck);
69722+extern int gr_handle_sock_client(const struct sockaddr *sck);
69723+extern int gr_search_connect(struct socket * sock,
69724+ struct sockaddr_in * addr);
69725+extern int gr_search_bind(struct socket * sock,
69726+ struct sockaddr_in * addr);
69727+extern int gr_search_listen(struct socket * sock);
69728+extern int gr_search_accept(struct socket * sock);
69729+extern int gr_search_socket(const int domain, const int type,
69730+ const int protocol);
69731+
69732+#endif
69733diff --git a/include/linux/highmem.h b/include/linux/highmem.h
69734index ef788b5..ac41b7b 100644
69735--- a/include/linux/highmem.h
69736+++ b/include/linux/highmem.h
69737@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
69738 kunmap_atomic(kaddr);
69739 }
69740
69741+static inline void sanitize_highpage(struct page *page)
69742+{
69743+ void *kaddr;
69744+ unsigned long flags;
69745+
69746+ local_irq_save(flags);
69747+ kaddr = kmap_atomic(page);
69748+ clear_page(kaddr);
69749+ kunmap_atomic(kaddr);
69750+ local_irq_restore(flags);
69751+}
69752+
69753 static inline void zero_user_segments(struct page *page,
69754 unsigned start1, unsigned end1,
69755 unsigned start2, unsigned end2)
69756diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
69757index 1c7b89a..7f52502 100644
69758--- a/include/linux/hwmon-sysfs.h
69759+++ b/include/linux/hwmon-sysfs.h
69760@@ -25,7 +25,8 @@
69761 struct sensor_device_attribute{
69762 struct device_attribute dev_attr;
69763 int index;
69764-};
69765+} __do_const;
69766+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
69767 #define to_sensor_dev_attr(_dev_attr) \
69768 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
69769
69770@@ -41,7 +42,7 @@ struct sensor_device_attribute_2 {
69771 struct device_attribute dev_attr;
69772 u8 index;
69773 u8 nr;
69774-};
69775+} __do_const;
69776 #define to_sensor_dev_attr_2(_dev_attr) \
69777 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
69778
69779diff --git a/include/linux/i2c.h b/include/linux/i2c.h
69780index d0c4db7..61b3577 100644
69781--- a/include/linux/i2c.h
69782+++ b/include/linux/i2c.h
69783@@ -369,6 +369,7 @@ struct i2c_algorithm {
69784 /* To determine what the adapter supports */
69785 u32 (*functionality) (struct i2c_adapter *);
69786 };
69787+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
69788
69789 /*
69790 * i2c_adapter is the structure used to identify a physical i2c bus along
69791diff --git a/include/linux/i2o.h b/include/linux/i2o.h
69792index d23c3c2..eb63c81 100644
69793--- a/include/linux/i2o.h
69794+++ b/include/linux/i2o.h
69795@@ -565,7 +565,7 @@ struct i2o_controller {
69796 struct i2o_device *exec; /* Executive */
69797 #if BITS_PER_LONG == 64
69798 spinlock_t context_list_lock; /* lock for context_list */
69799- atomic_t context_list_counter; /* needed for unique contexts */
69800+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
69801 struct list_head context_list; /* list of context id's
69802 and pointers */
69803 #endif
69804diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
69805index aff7ad8..3942bbd 100644
69806--- a/include/linux/if_pppox.h
69807+++ b/include/linux/if_pppox.h
69808@@ -76,7 +76,7 @@ struct pppox_proto {
69809 int (*ioctl)(struct socket *sock, unsigned int cmd,
69810 unsigned long arg);
69811 struct module *owner;
69812-};
69813+} __do_const;
69814
69815 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
69816 extern void unregister_pppox_proto(int proto_num);
69817diff --git a/include/linux/init.h b/include/linux/init.h
69818index 10ed4f4..8e8490d 100644
69819--- a/include/linux/init.h
69820+++ b/include/linux/init.h
69821@@ -39,9 +39,36 @@
69822 * Also note, that this data cannot be "const".
69823 */
69824
69825+#ifdef MODULE
69826+#define add_init_latent_entropy
69827+#define add_devinit_latent_entropy
69828+#define add_cpuinit_latent_entropy
69829+#define add_meminit_latent_entropy
69830+#else
69831+#define add_init_latent_entropy __latent_entropy
69832+
69833+#ifdef CONFIG_HOTPLUG
69834+#define add_devinit_latent_entropy
69835+#else
69836+#define add_devinit_latent_entropy __latent_entropy
69837+#endif
69838+
69839+#ifdef CONFIG_HOTPLUG_CPU
69840+#define add_cpuinit_latent_entropy
69841+#else
69842+#define add_cpuinit_latent_entropy __latent_entropy
69843+#endif
69844+
69845+#ifdef CONFIG_MEMORY_HOTPLUG
69846+#define add_meminit_latent_entropy
69847+#else
69848+#define add_meminit_latent_entropy __latent_entropy
69849+#endif
69850+#endif
69851+
69852 /* These are for everybody (although not all archs will actually
69853 discard it in modules) */
69854-#define __init __section(.init.text) __cold notrace
69855+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
69856 #define __initdata __section(.init.data)
69857 #define __initconst __constsection(.init.rodata)
69858 #define __exitdata __section(.exit.data)
69859@@ -94,7 +121,7 @@
69860 #define __exit __section(.exit.text) __exitused __cold notrace
69861
69862 /* Used for HOTPLUG_CPU */
69863-#define __cpuinit __section(.cpuinit.text) __cold notrace
69864+#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
69865 #define __cpuinitdata __section(.cpuinit.data)
69866 #define __cpuinitconst __constsection(.cpuinit.rodata)
69867 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
69868@@ -102,7 +129,7 @@
69869 #define __cpuexitconst __constsection(.cpuexit.rodata)
69870
69871 /* Used for MEMORY_HOTPLUG */
69872-#define __meminit __section(.meminit.text) __cold notrace
69873+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
69874 #define __meminitdata __section(.meminit.data)
69875 #define __meminitconst __constsection(.meminit.rodata)
69876 #define __memexit __section(.memexit.text) __exitused __cold notrace
69877diff --git a/include/linux/init_task.h b/include/linux/init_task.h
69878index 6d087c5..401cab8 100644
69879--- a/include/linux/init_task.h
69880+++ b/include/linux/init_task.h
69881@@ -143,6 +143,12 @@ extern struct task_group root_task_group;
69882
69883 #define INIT_TASK_COMM "swapper"
69884
69885+#ifdef CONFIG_X86
69886+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
69887+#else
69888+#define INIT_TASK_THREAD_INFO
69889+#endif
69890+
69891 /*
69892 * INIT_TASK is used to set up the first task table, touch at
69893 * your own risk!. Base=0, limit=0x1fffff (=2MB)
69894@@ -182,6 +188,7 @@ extern struct task_group root_task_group;
69895 RCU_POINTER_INITIALIZER(cred, &init_cred), \
69896 .comm = INIT_TASK_COMM, \
69897 .thread = INIT_THREAD, \
69898+ INIT_TASK_THREAD_INFO \
69899 .fs = &init_fs, \
69900 .files = &init_files, \
69901 .signal = &init_signals, \
69902diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
69903index 5fa5afe..ac55b25 100644
69904--- a/include/linux/interrupt.h
69905+++ b/include/linux/interrupt.h
69906@@ -430,7 +430,7 @@ enum
69907 /* map softirq index to softirq name. update 'softirq_to_name' in
69908 * kernel/softirq.c when adding a new softirq.
69909 */
69910-extern char *softirq_to_name[NR_SOFTIRQS];
69911+extern const char * const softirq_to_name[NR_SOFTIRQS];
69912
69913 /* softirq mask and active fields moved to irq_cpustat_t in
69914 * asm/hardirq.h to get better cache usage. KAO
69915@@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
69916
69917 struct softirq_action
69918 {
69919- void (*action)(struct softirq_action *);
69920-};
69921+ void (*action)(void);
69922+} __no_const;
69923
69924 asmlinkage void do_softirq(void);
69925 asmlinkage void __do_softirq(void);
69926-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
69927+extern void open_softirq(int nr, void (*action)(void));
69928 extern void softirq_init(void);
69929 extern void __raise_softirq_irqoff(unsigned int nr);
69930
69931diff --git a/include/linux/iommu.h b/include/linux/iommu.h
69932index f3b99e1..9b73cee 100644
69933--- a/include/linux/iommu.h
69934+++ b/include/linux/iommu.h
69935@@ -101,7 +101,7 @@ struct iommu_ops {
69936 int (*domain_set_attr)(struct iommu_domain *domain,
69937 enum iommu_attr attr, void *data);
69938 unsigned long pgsize_bitmap;
69939-};
69940+} __do_const;
69941
69942 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
69943 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
69944diff --git a/include/linux/ioport.h b/include/linux/ioport.h
69945index 85ac9b9b..e5759ab 100644
69946--- a/include/linux/ioport.h
69947+++ b/include/linux/ioport.h
69948@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
69949 int adjust_resource(struct resource *res, resource_size_t start,
69950 resource_size_t size);
69951 resource_size_t resource_alignment(struct resource *res);
69952-static inline resource_size_t resource_size(const struct resource *res)
69953+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
69954 {
69955 return res->end - res->start + 1;
69956 }
69957diff --git a/include/linux/irq.h b/include/linux/irq.h
69958index fdf2c4a..5332486 100644
69959--- a/include/linux/irq.h
69960+++ b/include/linux/irq.h
69961@@ -328,7 +328,8 @@ struct irq_chip {
69962 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
69963
69964 unsigned long flags;
69965-};
69966+} __do_const;
69967+typedef struct irq_chip __no_const irq_chip_no_const;
69968
69969 /*
69970 * irq_chip specific flags
69971diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
69972index 6883e19..06992b1 100644
69973--- a/include/linux/kallsyms.h
69974+++ b/include/linux/kallsyms.h
69975@@ -15,7 +15,8 @@
69976
69977 struct module;
69978
69979-#ifdef CONFIG_KALLSYMS
69980+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
69981+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
69982 /* Lookup the address for a symbol. Returns 0 if not found. */
69983 unsigned long kallsyms_lookup_name(const char *name);
69984
69985@@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
69986 /* Stupid that this does nothing, but I didn't create this mess. */
69987 #define __print_symbol(fmt, addr)
69988 #endif /*CONFIG_KALLSYMS*/
69989+#else /* when included by kallsyms.c, vsnprintf.c, or
69990+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
69991+extern void __print_symbol(const char *fmt, unsigned long address);
69992+extern int sprint_backtrace(char *buffer, unsigned long address);
69993+extern int sprint_symbol(char *buffer, unsigned long address);
69994+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
69995+const char *kallsyms_lookup(unsigned long addr,
69996+ unsigned long *symbolsize,
69997+ unsigned long *offset,
69998+ char **modname, char *namebuf);
69999+#endif
70000
70001 /* This macro allows us to keep printk typechecking */
70002 static __printf(1, 2)
70003diff --git a/include/linux/key-type.h b/include/linux/key-type.h
70004index 518a53a..5e28358 100644
70005--- a/include/linux/key-type.h
70006+++ b/include/linux/key-type.h
70007@@ -125,7 +125,7 @@ struct key_type {
70008 /* internal fields */
70009 struct list_head link; /* link in types list */
70010 struct lock_class_key lock_class; /* key->sem lock class */
70011-};
70012+} __do_const;
70013
70014 extern struct key_type key_type_keyring;
70015
70016diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
70017index 4dff0c6..1ca9b72 100644
70018--- a/include/linux/kgdb.h
70019+++ b/include/linux/kgdb.h
70020@@ -53,7 +53,7 @@ extern int kgdb_connected;
70021 extern int kgdb_io_module_registered;
70022
70023 extern atomic_t kgdb_setting_breakpoint;
70024-extern atomic_t kgdb_cpu_doing_single_step;
70025+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
70026
70027 extern struct task_struct *kgdb_usethread;
70028 extern struct task_struct *kgdb_contthread;
70029@@ -255,7 +255,7 @@ struct kgdb_arch {
70030 void (*correct_hw_break)(void);
70031
70032 void (*enable_nmi)(bool on);
70033-};
70034+} __do_const;
70035
70036 /**
70037 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
70038@@ -280,7 +280,7 @@ struct kgdb_io {
70039 void (*pre_exception) (void);
70040 void (*post_exception) (void);
70041 int is_console;
70042-};
70043+} __do_const;
70044
70045 extern struct kgdb_arch arch_kgdb_ops;
70046
70047diff --git a/include/linux/kmod.h b/include/linux/kmod.h
70048index 5398d58..5883a34 100644
70049--- a/include/linux/kmod.h
70050+++ b/include/linux/kmod.h
70051@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
70052 * usually useless though. */
70053 extern __printf(2, 3)
70054 int __request_module(bool wait, const char *name, ...);
70055+extern __printf(3, 4)
70056+int ___request_module(bool wait, char *param_name, const char *name, ...);
70057 #define request_module(mod...) __request_module(true, mod)
70058 #define request_module_nowait(mod...) __request_module(false, mod)
70059 #define try_then_request_module(x, mod...) \
70060diff --git a/include/linux/kobject.h b/include/linux/kobject.h
70061index 939b112..ed6ed51 100644
70062--- a/include/linux/kobject.h
70063+++ b/include/linux/kobject.h
70064@@ -111,7 +111,7 @@ struct kobj_type {
70065 struct attribute **default_attrs;
70066 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
70067 const void *(*namespace)(struct kobject *kobj);
70068-};
70069+} __do_const;
70070
70071 struct kobj_uevent_env {
70072 char *envp[UEVENT_NUM_ENVP];
70073@@ -134,6 +134,7 @@ struct kobj_attribute {
70074 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
70075 const char *buf, size_t count);
70076 };
70077+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
70078
70079 extern const struct sysfs_ops kobj_sysfs_ops;
70080
70081diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
70082index f66b065..c2c29b4 100644
70083--- a/include/linux/kobject_ns.h
70084+++ b/include/linux/kobject_ns.h
70085@@ -43,7 +43,7 @@ struct kobj_ns_type_operations {
70086 const void *(*netlink_ns)(struct sock *sk);
70087 const void *(*initial_ns)(void);
70088 void (*drop_ns)(void *);
70089-};
70090+} __do_const;
70091
70092 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
70093 int kobj_ns_type_registered(enum kobj_ns_type type);
70094diff --git a/include/linux/kref.h b/include/linux/kref.h
70095index 4972e6e..de4d19b 100644
70096--- a/include/linux/kref.h
70097+++ b/include/linux/kref.h
70098@@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
70099 static inline int kref_sub(struct kref *kref, unsigned int count,
70100 void (*release)(struct kref *kref))
70101 {
70102- WARN_ON(release == NULL);
70103+ BUG_ON(release == NULL);
70104
70105 if (atomic_sub_and_test((int) count, &kref->refcount)) {
70106 release(kref);
70107diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
70108index 2c497ab..afe32f5 100644
70109--- a/include/linux/kvm_host.h
70110+++ b/include/linux/kvm_host.h
70111@@ -418,7 +418,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
70112 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
70113 void vcpu_put(struct kvm_vcpu *vcpu);
70114
70115-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
70116+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
70117 struct module *module);
70118 void kvm_exit(void);
70119
70120@@ -574,7 +574,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
70121 struct kvm_guest_debug *dbg);
70122 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
70123
70124-int kvm_arch_init(void *opaque);
70125+int kvm_arch_init(const void *opaque);
70126 void kvm_arch_exit(void);
70127
70128 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
70129diff --git a/include/linux/libata.h b/include/linux/libata.h
70130index 0621bca..24d6851 100644
70131--- a/include/linux/libata.h
70132+++ b/include/linux/libata.h
70133@@ -916,7 +916,7 @@ struct ata_port_operations {
70134 * fields must be pointers.
70135 */
70136 const struct ata_port_operations *inherits;
70137-};
70138+} __do_const;
70139
70140 struct ata_port_info {
70141 unsigned long flags;
70142diff --git a/include/linux/list.h b/include/linux/list.h
70143index cc6d2aa..c10ee83 100644
70144--- a/include/linux/list.h
70145+++ b/include/linux/list.h
70146@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
70147 extern void list_del(struct list_head *entry);
70148 #endif
70149
70150+extern void __pax_list_add(struct list_head *new,
70151+ struct list_head *prev,
70152+ struct list_head *next);
70153+static inline void pax_list_add(struct list_head *new, struct list_head *head)
70154+{
70155+ __pax_list_add(new, head, head->next);
70156+}
70157+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
70158+{
70159+ __pax_list_add(new, head->prev, head);
70160+}
70161+extern void pax_list_del(struct list_head *entry);
70162+
70163 /**
70164 * list_replace - replace old entry by new one
70165 * @old : the element to be replaced
70166@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
70167 INIT_LIST_HEAD(entry);
70168 }
70169
70170+extern void pax_list_del_init(struct list_head *entry);
70171+
70172 /**
70173 * list_move - delete from one list and add as another's head
70174 * @list: the entry to move
70175diff --git a/include/linux/math64.h b/include/linux/math64.h
70176index b8ba855..0148090 100644
70177--- a/include/linux/math64.h
70178+++ b/include/linux/math64.h
70179@@ -14,7 +14,7 @@
70180 * This is commonly provided by 32bit archs to provide an optimized 64bit
70181 * divide.
70182 */
70183-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70184+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70185 {
70186 *remainder = dividend % divisor;
70187 return dividend / divisor;
70188@@ -50,7 +50,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
70189 #define div64_long(x,y) div_s64((x),(y))
70190
70191 #ifndef div_u64_rem
70192-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70193+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70194 {
70195 *remainder = do_div(dividend, divisor);
70196 return dividend;
70197@@ -79,7 +79,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
70198 * divide.
70199 */
70200 #ifndef div_u64
70201-static inline u64 div_u64(u64 dividend, u32 divisor)
70202+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
70203 {
70204 u32 remainder;
70205 return div_u64_rem(dividend, divisor, &remainder);
70206diff --git a/include/linux/mm.h b/include/linux/mm.h
70207index 66e2f7c..b916b9a 100644
70208--- a/include/linux/mm.h
70209+++ b/include/linux/mm.h
70210@@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
70211 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
70212 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
70213 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
70214+
70215+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
70216+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
70217+#endif
70218+
70219 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
70220
70221 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
70222@@ -200,8 +205,8 @@ struct vm_operations_struct {
70223 /* called by access_process_vm when get_user_pages() fails, typically
70224 * for use by special VMAs that can switch between memory and hardware
70225 */
70226- int (*access)(struct vm_area_struct *vma, unsigned long addr,
70227- void *buf, int len, int write);
70228+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
70229+ void *buf, size_t len, int write);
70230 #ifdef CONFIG_NUMA
70231 /*
70232 * set_policy() op must add a reference to any non-NULL @new mempolicy
70233@@ -231,6 +236,7 @@ struct vm_operations_struct {
70234 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
70235 unsigned long size, pgoff_t pgoff);
70236 };
70237+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
70238
70239 struct mmu_gather;
70240 struct inode;
70241@@ -995,8 +1001,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
70242 unsigned long *pfn);
70243 int follow_phys(struct vm_area_struct *vma, unsigned long address,
70244 unsigned int flags, unsigned long *prot, resource_size_t *phys);
70245-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
70246- void *buf, int len, int write);
70247+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
70248+ void *buf, size_t len, int write);
70249
70250 static inline void unmap_shared_mapping_range(struct address_space *mapping,
70251 loff_t const holebegin, loff_t const holelen)
70252@@ -1035,10 +1041,10 @@ static inline int fixup_user_fault(struct task_struct *tsk,
70253 }
70254 #endif
70255
70256-extern int make_pages_present(unsigned long addr, unsigned long end);
70257-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
70258-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
70259- void *buf, int len, int write);
70260+extern ssize_t make_pages_present(unsigned long addr, unsigned long end);
70261+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
70262+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
70263+ void *buf, size_t len, int write);
70264
70265 int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70266 unsigned long start, int len, unsigned int foll_flags,
70267@@ -1068,34 +1074,6 @@ int set_page_dirty(struct page *page);
70268 int set_page_dirty_lock(struct page *page);
70269 int clear_page_dirty_for_io(struct page *page);
70270
70271-/* Is the vma a continuation of the stack vma above it? */
70272-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
70273-{
70274- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
70275-}
70276-
70277-static inline int stack_guard_page_start(struct vm_area_struct *vma,
70278- unsigned long addr)
70279-{
70280- return (vma->vm_flags & VM_GROWSDOWN) &&
70281- (vma->vm_start == addr) &&
70282- !vma_growsdown(vma->vm_prev, addr);
70283-}
70284-
70285-/* Is the vma a continuation of the stack vma below it? */
70286-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
70287-{
70288- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
70289-}
70290-
70291-static inline int stack_guard_page_end(struct vm_area_struct *vma,
70292- unsigned long addr)
70293-{
70294- return (vma->vm_flags & VM_GROWSUP) &&
70295- (vma->vm_end == addr) &&
70296- !vma_growsup(vma->vm_next, addr);
70297-}
70298-
70299 extern pid_t
70300 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
70301
70302@@ -1198,6 +1176,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
70303 }
70304 #endif
70305
70306+#ifdef CONFIG_MMU
70307+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
70308+#else
70309+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
70310+{
70311+ return __pgprot(0);
70312+}
70313+#endif
70314+
70315 int vma_wants_writenotify(struct vm_area_struct *vma);
70316
70317 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
70318@@ -1216,8 +1203,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
70319 {
70320 return 0;
70321 }
70322+
70323+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
70324+ unsigned long address)
70325+{
70326+ return 0;
70327+}
70328 #else
70329 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
70330+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
70331 #endif
70332
70333 #ifdef __PAGETABLE_PMD_FOLDED
70334@@ -1226,8 +1220,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
70335 {
70336 return 0;
70337 }
70338+
70339+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
70340+ unsigned long address)
70341+{
70342+ return 0;
70343+}
70344 #else
70345 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
70346+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
70347 #endif
70348
70349 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
70350@@ -1245,11 +1246,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
70351 NULL: pud_offset(pgd, address);
70352 }
70353
70354+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
70355+{
70356+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
70357+ NULL: pud_offset(pgd, address);
70358+}
70359+
70360 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
70361 {
70362 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
70363 NULL: pmd_offset(pud, address);
70364 }
70365+
70366+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
70367+{
70368+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
70369+ NULL: pmd_offset(pud, address);
70370+}
70371 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
70372
70373 #if USE_SPLIT_PTLOCKS
70374@@ -1479,6 +1492,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
70375 unsigned long, unsigned long,
70376 unsigned long, unsigned long);
70377 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
70378+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
70379
70380 /* These take the mm semaphore themselves */
70381 extern unsigned long vm_brk(unsigned long, unsigned long);
70382@@ -1573,6 +1587,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
70383 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
70384 struct vm_area_struct **pprev);
70385
70386+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
70387+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
70388+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
70389+
70390 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
70391 NULL if none. Assume start_addr < end_addr. */
70392 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
70393@@ -1601,15 +1619,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
70394 return vma;
70395 }
70396
70397-#ifdef CONFIG_MMU
70398-pgprot_t vm_get_page_prot(unsigned long vm_flags);
70399-#else
70400-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
70401-{
70402- return __pgprot(0);
70403-}
70404-#endif
70405-
70406 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
70407 unsigned long change_prot_numa(struct vm_area_struct *vma,
70408 unsigned long start, unsigned long end);
70409@@ -1649,6 +1658,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
70410 static inline void vm_stat_account(struct mm_struct *mm,
70411 unsigned long flags, struct file *file, long pages)
70412 {
70413+
70414+#ifdef CONFIG_PAX_RANDMMAP
70415+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
70416+#endif
70417+
70418 mm->total_vm += pages;
70419 }
70420 #endif /* CONFIG_PROC_FS */
70421@@ -1721,7 +1735,7 @@ extern int unpoison_memory(unsigned long pfn);
70422 extern int sysctl_memory_failure_early_kill;
70423 extern int sysctl_memory_failure_recovery;
70424 extern void shake_page(struct page *p, int access);
70425-extern atomic_long_t mce_bad_pages;
70426+extern atomic_long_unchecked_t mce_bad_pages;
70427 extern int soft_offline_page(struct page *page, int flags);
70428
70429 extern void dump_page(struct page *page);
70430@@ -1752,5 +1766,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
70431 static inline bool page_is_guard(struct page *page) { return false; }
70432 #endif /* CONFIG_DEBUG_PAGEALLOC */
70433
70434+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
70435+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
70436+#else
70437+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
70438+#endif
70439+
70440 #endif /* __KERNEL__ */
70441 #endif /* _LINUX_MM_H */
70442diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
70443index f8f5162..3aaf20f 100644
70444--- a/include/linux/mm_types.h
70445+++ b/include/linux/mm_types.h
70446@@ -288,6 +288,8 @@ struct vm_area_struct {
70447 #ifdef CONFIG_NUMA
70448 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
70449 #endif
70450+
70451+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
70452 };
70453
70454 struct core_thread {
70455@@ -436,6 +438,24 @@ struct mm_struct {
70456 int first_nid;
70457 #endif
70458 struct uprobes_state uprobes_state;
70459+
70460+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
70461+ unsigned long pax_flags;
70462+#endif
70463+
70464+#ifdef CONFIG_PAX_DLRESOLVE
70465+ unsigned long call_dl_resolve;
70466+#endif
70467+
70468+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
70469+ unsigned long call_syscall;
70470+#endif
70471+
70472+#ifdef CONFIG_PAX_ASLR
70473+ unsigned long delta_mmap; /* randomized offset */
70474+ unsigned long delta_stack; /* randomized offset */
70475+#endif
70476+
70477 };
70478
70479 /* first nid will either be a valid NID or one of these values */
70480diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
70481index c5d5278..f0b68c8 100644
70482--- a/include/linux/mmiotrace.h
70483+++ b/include/linux/mmiotrace.h
70484@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
70485 /* Called from ioremap.c */
70486 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
70487 void __iomem *addr);
70488-extern void mmiotrace_iounmap(volatile void __iomem *addr);
70489+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
70490
70491 /* For anyone to insert markers. Remember trailing newline. */
70492 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
70493@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
70494 {
70495 }
70496
70497-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
70498+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
70499 {
70500 }
70501
70502diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
70503index 73b64a3..6562925 100644
70504--- a/include/linux/mmzone.h
70505+++ b/include/linux/mmzone.h
70506@@ -412,7 +412,7 @@ struct zone {
70507 unsigned long flags; /* zone flags, see below */
70508
70509 /* Zone statistics */
70510- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
70511+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
70512
70513 /*
70514 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
70515diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
70516index fed3def..c933f99 100644
70517--- a/include/linux/mod_devicetable.h
70518+++ b/include/linux/mod_devicetable.h
70519@@ -12,7 +12,7 @@
70520 typedef unsigned long kernel_ulong_t;
70521 #endif
70522
70523-#define PCI_ANY_ID (~0)
70524+#define PCI_ANY_ID ((__u16)~0)
70525
70526 struct pci_device_id {
70527 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
70528@@ -139,7 +139,7 @@ struct usb_device_id {
70529 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
70530 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
70531
70532-#define HID_ANY_ID (~0)
70533+#define HID_ANY_ID (~0U)
70534 #define HID_BUS_ANY 0xffff
70535 #define HID_GROUP_ANY 0x0000
70536
70537@@ -498,7 +498,7 @@ struct dmi_system_id {
70538 const char *ident;
70539 struct dmi_strmatch matches[4];
70540 void *driver_data;
70541-};
70542+} __do_const;
70543 /*
70544 * struct dmi_device_id appears during expansion of
70545 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
70546diff --git a/include/linux/module.h b/include/linux/module.h
70547index 1375ee3..ced8177 100644
70548--- a/include/linux/module.h
70549+++ b/include/linux/module.h
70550@@ -17,9 +17,11 @@
70551 #include <linux/moduleparam.h>
70552 #include <linux/tracepoint.h>
70553 #include <linux/export.h>
70554+#include <linux/fs.h>
70555
70556 #include <linux/percpu.h>
70557 #include <asm/module.h>
70558+#include <asm/pgtable.h>
70559
70560 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
70561 #define MODULE_SIG_STRING "~Module signature appended~\n"
70562@@ -54,12 +56,13 @@ struct module_attribute {
70563 int (*test)(struct module *);
70564 void (*free)(struct module *);
70565 };
70566+typedef struct module_attribute __no_const module_attribute_no_const;
70567
70568 struct module_version_attribute {
70569 struct module_attribute mattr;
70570 const char *module_name;
70571 const char *version;
70572-} __attribute__ ((__aligned__(sizeof(void *))));
70573+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
70574
70575 extern ssize_t __modver_version_show(struct module_attribute *,
70576 struct module_kobject *, char *);
70577@@ -232,7 +235,7 @@ struct module
70578
70579 /* Sysfs stuff. */
70580 struct module_kobject mkobj;
70581- struct module_attribute *modinfo_attrs;
70582+ module_attribute_no_const *modinfo_attrs;
70583 const char *version;
70584 const char *srcversion;
70585 struct kobject *holders_dir;
70586@@ -281,19 +284,16 @@ struct module
70587 int (*init)(void);
70588
70589 /* If this is non-NULL, vfree after init() returns */
70590- void *module_init;
70591+ void *module_init_rx, *module_init_rw;
70592
70593 /* Here is the actual code + data, vfree'd on unload. */
70594- void *module_core;
70595+ void *module_core_rx, *module_core_rw;
70596
70597 /* Here are the sizes of the init and core sections */
70598- unsigned int init_size, core_size;
70599+ unsigned int init_size_rw, core_size_rw;
70600
70601 /* The size of the executable code in each section. */
70602- unsigned int init_text_size, core_text_size;
70603-
70604- /* Size of RO sections of the module (text+rodata) */
70605- unsigned int init_ro_size, core_ro_size;
70606+ unsigned int init_size_rx, core_size_rx;
70607
70608 /* Arch-specific module values */
70609 struct mod_arch_specific arch;
70610@@ -349,6 +349,10 @@ struct module
70611 #ifdef CONFIG_EVENT_TRACING
70612 struct ftrace_event_call **trace_events;
70613 unsigned int num_trace_events;
70614+ struct file_operations trace_id;
70615+ struct file_operations trace_enable;
70616+ struct file_operations trace_format;
70617+ struct file_operations trace_filter;
70618 #endif
70619 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
70620 unsigned int num_ftrace_callsites;
70621@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
70622 bool is_module_percpu_address(unsigned long addr);
70623 bool is_module_text_address(unsigned long addr);
70624
70625+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
70626+{
70627+
70628+#ifdef CONFIG_PAX_KERNEXEC
70629+ if (ktla_ktva(addr) >= (unsigned long)start &&
70630+ ktla_ktva(addr) < (unsigned long)start + size)
70631+ return 1;
70632+#endif
70633+
70634+ return ((void *)addr >= start && (void *)addr < start + size);
70635+}
70636+
70637+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
70638+{
70639+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
70640+}
70641+
70642+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
70643+{
70644+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
70645+}
70646+
70647+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
70648+{
70649+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
70650+}
70651+
70652+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
70653+{
70654+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
70655+}
70656+
70657 static inline int within_module_core(unsigned long addr, struct module *mod)
70658 {
70659- return (unsigned long)mod->module_core <= addr &&
70660- addr < (unsigned long)mod->module_core + mod->core_size;
70661+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
70662 }
70663
70664 static inline int within_module_init(unsigned long addr, struct module *mod)
70665 {
70666- return (unsigned long)mod->module_init <= addr &&
70667- addr < (unsigned long)mod->module_init + mod->init_size;
70668+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
70669 }
70670
70671 /* Search for module by name: must hold module_mutex. */
70672diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
70673index 560ca53..ef621ef 100644
70674--- a/include/linux/moduleloader.h
70675+++ b/include/linux/moduleloader.h
70676@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
70677 sections. Returns NULL on failure. */
70678 void *module_alloc(unsigned long size);
70679
70680+#ifdef CONFIG_PAX_KERNEXEC
70681+void *module_alloc_exec(unsigned long size);
70682+#else
70683+#define module_alloc_exec(x) module_alloc(x)
70684+#endif
70685+
70686 /* Free memory returned from module_alloc. */
70687 void module_free(struct module *mod, void *module_region);
70688
70689+#ifdef CONFIG_PAX_KERNEXEC
70690+void module_free_exec(struct module *mod, void *module_region);
70691+#else
70692+#define module_free_exec(x, y) module_free((x), (y))
70693+#endif
70694+
70695 /*
70696 * Apply the given relocation to the (simplified) ELF. Return -error
70697 * or 0.
70698@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
70699 unsigned int relsec,
70700 struct module *me)
70701 {
70702+#ifdef CONFIG_MODULES
70703 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
70704+#endif
70705 return -ENOEXEC;
70706 }
70707 #endif
70708@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
70709 unsigned int relsec,
70710 struct module *me)
70711 {
70712+#ifdef CONFIG_MODULES
70713 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
70714+#endif
70715 return -ENOEXEC;
70716 }
70717 #endif
70718diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
70719index 137b419..fe663ec 100644
70720--- a/include/linux/moduleparam.h
70721+++ b/include/linux/moduleparam.h
70722@@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
70723 * @len is usually just sizeof(string).
70724 */
70725 #define module_param_string(name, string, len, perm) \
70726- static const struct kparam_string __param_string_##name \
70727+ static const struct kparam_string __param_string_##name __used \
70728 = { len, string }; \
70729 __module_param_call(MODULE_PARAM_PREFIX, name, \
70730 &param_ops_string, \
70731@@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
70732 */
70733 #define module_param_array_named(name, array, type, nump, perm) \
70734 param_check_##type(name, &(array)[0]); \
70735- static const struct kparam_array __param_arr_##name \
70736+ static const struct kparam_array __param_arr_##name __used \
70737 = { .max = ARRAY_SIZE(array), .num = nump, \
70738 .ops = &param_ops_##type, \
70739 .elemsize = sizeof(array[0]), .elem = array }; \
70740diff --git a/include/linux/namei.h b/include/linux/namei.h
70741index 5a5ff57..5ae5070 100644
70742--- a/include/linux/namei.h
70743+++ b/include/linux/namei.h
70744@@ -19,7 +19,7 @@ struct nameidata {
70745 unsigned seq;
70746 int last_type;
70747 unsigned depth;
70748- char *saved_names[MAX_NESTED_LINKS + 1];
70749+ const char *saved_names[MAX_NESTED_LINKS + 1];
70750 };
70751
70752 /*
70753@@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
70754
70755 extern void nd_jump_link(struct nameidata *nd, struct path *path);
70756
70757-static inline void nd_set_link(struct nameidata *nd, char *path)
70758+static inline void nd_set_link(struct nameidata *nd, const char *path)
70759 {
70760 nd->saved_names[nd->depth] = path;
70761 }
70762
70763-static inline char *nd_get_link(struct nameidata *nd)
70764+static inline const char *nd_get_link(const struct nameidata *nd)
70765 {
70766 return nd->saved_names[nd->depth];
70767 }
70768diff --git a/include/linux/net.h b/include/linux/net.h
70769index aa16731..514b875 100644
70770--- a/include/linux/net.h
70771+++ b/include/linux/net.h
70772@@ -183,7 +183,7 @@ struct net_proto_family {
70773 int (*create)(struct net *net, struct socket *sock,
70774 int protocol, int kern);
70775 struct module *owner;
70776-};
70777+} __do_const;
70778
70779 struct iovec;
70780 struct kvec;
70781diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
70782index 9ef07d0..130a5d9 100644
70783--- a/include/linux/netdevice.h
70784+++ b/include/linux/netdevice.h
70785@@ -1012,6 +1012,7 @@ struct net_device_ops {
70786 u32 pid, u32 seq,
70787 struct net_device *dev);
70788 };
70789+typedef struct net_device_ops __no_const net_device_ops_no_const;
70790
70791 /*
70792 * The DEVICE structure.
70793@@ -1078,7 +1079,7 @@ struct net_device {
70794 int iflink;
70795
70796 struct net_device_stats stats;
70797- atomic_long_t rx_dropped; /* dropped packets by core network
70798+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
70799 * Do not use this in drivers.
70800 */
70801
70802diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
70803index ee14284..bc65d63 100644
70804--- a/include/linux/netfilter.h
70805+++ b/include/linux/netfilter.h
70806@@ -82,7 +82,7 @@ struct nf_sockopt_ops {
70807 #endif
70808 /* Use the module struct to lock set/get code in place */
70809 struct module *owner;
70810-};
70811+} __do_const;
70812
70813 /* Function to register/unregister hook points. */
70814 int nf_register_hook(struct nf_hook_ops *reg);
70815diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
70816index 7958e84..ed74d7a 100644
70817--- a/include/linux/netfilter/ipset/ip_set.h
70818+++ b/include/linux/netfilter/ipset/ip_set.h
70819@@ -98,7 +98,7 @@ struct ip_set_type_variant {
70820 /* Return true if "b" set is the same as "a"
70821 * according to the create set parameters */
70822 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
70823-};
70824+} __do_const;
70825
70826 /* The core set type structure */
70827 struct ip_set_type {
70828diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
70829index 4966dde..7d8ce06 100644
70830--- a/include/linux/netfilter/nfnetlink.h
70831+++ b/include/linux/netfilter/nfnetlink.h
70832@@ -16,7 +16,7 @@ struct nfnl_callback {
70833 const struct nlattr * const cda[]);
70834 const struct nla_policy *policy; /* netlink attribute policy */
70835 const u_int16_t attr_count; /* number of nlattr's */
70836-};
70837+} __do_const;
70838
70839 struct nfnetlink_subsystem {
70840 const char *name;
70841diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
70842new file mode 100644
70843index 0000000..33f4af8
70844--- /dev/null
70845+++ b/include/linux/netfilter/xt_gradm.h
70846@@ -0,0 +1,9 @@
70847+#ifndef _LINUX_NETFILTER_XT_GRADM_H
70848+#define _LINUX_NETFILTER_XT_GRADM_H 1
70849+
70850+struct xt_gradm_mtinfo {
70851+ __u16 flags;
70852+ __u16 invflags;
70853+};
70854+
70855+#endif
70856diff --git a/include/linux/nls.h b/include/linux/nls.h
70857index 5dc635f..35f5e11 100644
70858--- a/include/linux/nls.h
70859+++ b/include/linux/nls.h
70860@@ -31,7 +31,7 @@ struct nls_table {
70861 const unsigned char *charset2upper;
70862 struct module *owner;
70863 struct nls_table *next;
70864-};
70865+} __do_const;
70866
70867 /* this value hold the maximum octet of charset */
70868 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
70869diff --git a/include/linux/notifier.h b/include/linux/notifier.h
70870index d65746e..62e72c2 100644
70871--- a/include/linux/notifier.h
70872+++ b/include/linux/notifier.h
70873@@ -51,7 +51,8 @@ struct notifier_block {
70874 int (*notifier_call)(struct notifier_block *, unsigned long, void *);
70875 struct notifier_block __rcu *next;
70876 int priority;
70877-};
70878+} __do_const;
70879+typedef struct notifier_block __no_const notifier_block_no_const;
70880
70881 struct atomic_notifier_head {
70882 spinlock_t lock;
70883diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
70884index a4c5624..79d6d88 100644
70885--- a/include/linux/oprofile.h
70886+++ b/include/linux/oprofile.h
70887@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
70888 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
70889 char const * name, ulong * val);
70890
70891-/** Create a file for read-only access to an atomic_t. */
70892+/** Create a file for read-only access to an atomic_unchecked_t. */
70893 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
70894- char const * name, atomic_t * val);
70895+ char const * name, atomic_unchecked_t * val);
70896
70897 /** create a directory */
70898 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
70899diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
70900index 45fc162..01a4068 100644
70901--- a/include/linux/pci_hotplug.h
70902+++ b/include/linux/pci_hotplug.h
70903@@ -80,7 +80,8 @@ struct hotplug_slot_ops {
70904 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
70905 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
70906 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
70907-};
70908+} __do_const;
70909+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
70910
70911 /**
70912 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
70913diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
70914index a280650..2b67b91 100644
70915--- a/include/linux/perf_event.h
70916+++ b/include/linux/perf_event.h
70917@@ -328,8 +328,8 @@ struct perf_event {
70918
70919 enum perf_event_active_state state;
70920 unsigned int attach_state;
70921- local64_t count;
70922- atomic64_t child_count;
70923+ local64_t count; /* PaX: fix it one day */
70924+ atomic64_unchecked_t child_count;
70925
70926 /*
70927 * These are the total time in nanoseconds that the event
70928@@ -380,8 +380,8 @@ struct perf_event {
70929 * These accumulate total time (in nanoseconds) that children
70930 * events have been enabled and running, respectively.
70931 */
70932- atomic64_t child_total_time_enabled;
70933- atomic64_t child_total_time_running;
70934+ atomic64_unchecked_t child_total_time_enabled;
70935+ atomic64_unchecked_t child_total_time_running;
70936
70937 /*
70938 * Protect attach/detach and child_list:
70939@@ -807,7 +807,7 @@ static inline void perf_restore_debug_store(void) { }
70940 */
70941 #define perf_cpu_notifier(fn) \
70942 do { \
70943- static struct notifier_block fn##_nb __cpuinitdata = \
70944+ static struct notifier_block fn##_nb = \
70945 { .notifier_call = fn, .priority = CPU_PRI_PERF }; \
70946 unsigned long cpu = smp_processor_id(); \
70947 unsigned long flags; \
70948diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
70949index ad1a427..6419649 100644
70950--- a/include/linux/pipe_fs_i.h
70951+++ b/include/linux/pipe_fs_i.h
70952@@ -45,9 +45,9 @@ struct pipe_buffer {
70953 struct pipe_inode_info {
70954 wait_queue_head_t wait;
70955 unsigned int nrbufs, curbuf, buffers;
70956- unsigned int readers;
70957- unsigned int writers;
70958- unsigned int waiting_writers;
70959+ atomic_t readers;
70960+ atomic_t writers;
70961+ atomic_t waiting_writers;
70962 unsigned int r_counter;
70963 unsigned int w_counter;
70964 struct page *tmp_page;
70965diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
70966index 5f28cae..3d23723 100644
70967--- a/include/linux/platform_data/usb-ehci-s5p.h
70968+++ b/include/linux/platform_data/usb-ehci-s5p.h
70969@@ -14,7 +14,7 @@
70970 struct s5p_ehci_platdata {
70971 int (*phy_init)(struct platform_device *pdev, int type);
70972 int (*phy_exit)(struct platform_device *pdev, int type);
70973-};
70974+} __no_const;
70975
70976 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
70977
70978diff --git a/include/linux/platform_data/usb-exynos.h b/include/linux/platform_data/usb-exynos.h
70979index c256c59..8ea94c7 100644
70980--- a/include/linux/platform_data/usb-exynos.h
70981+++ b/include/linux/platform_data/usb-exynos.h
70982@@ -14,7 +14,7 @@
70983 struct exynos4_ohci_platdata {
70984 int (*phy_init)(struct platform_device *pdev, int type);
70985 int (*phy_exit)(struct platform_device *pdev, int type);
70986-};
70987+} __no_const;
70988
70989 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
70990
70991diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
70992index 7c1d252..c5c773e 100644
70993--- a/include/linux/pm_domain.h
70994+++ b/include/linux/pm_domain.h
70995@@ -48,7 +48,7 @@ struct gpd_dev_ops {
70996
70997 struct gpd_cpu_data {
70998 unsigned int saved_exit_latency;
70999- struct cpuidle_state *idle_state;
71000+ cpuidle_state_no_const *idle_state;
71001 };
71002
71003 struct generic_pm_domain {
71004diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
71005index f271860..6b3bec5 100644
71006--- a/include/linux/pm_runtime.h
71007+++ b/include/linux/pm_runtime.h
71008@@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
71009
71010 static inline void pm_runtime_mark_last_busy(struct device *dev)
71011 {
71012- ACCESS_ONCE(dev->power.last_busy) = jiffies;
71013+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
71014 }
71015
71016 #else /* !CONFIG_PM_RUNTIME */
71017diff --git a/include/linux/pnp.h b/include/linux/pnp.h
71018index 195aafc..49a7bc2 100644
71019--- a/include/linux/pnp.h
71020+++ b/include/linux/pnp.h
71021@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
71022 struct pnp_fixup {
71023 char id[7];
71024 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
71025-};
71026+} __do_const;
71027
71028 /* config parameters */
71029 #define PNP_CONFIG_NORMAL 0x0001
71030diff --git a/include/linux/poison.h b/include/linux/poison.h
71031index 2110a81..13a11bb 100644
71032--- a/include/linux/poison.h
71033+++ b/include/linux/poison.h
71034@@ -19,8 +19,8 @@
71035 * under normal circumstances, used to verify that nobody uses
71036 * non-initialized list entries.
71037 */
71038-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
71039-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
71040+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
71041+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
71042
71043 /********** include/linux/timer.h **********/
71044 /*
71045diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
71046index c0f44c2..1572583 100644
71047--- a/include/linux/power/smartreflex.h
71048+++ b/include/linux/power/smartreflex.h
71049@@ -238,7 +238,7 @@ struct omap_sr_class_data {
71050 int (*notify)(struct omap_sr *sr, u32 status);
71051 u8 notify_flags;
71052 u8 class_type;
71053-};
71054+} __do_const;
71055
71056 /**
71057 * struct omap_sr_nvalue_table - Smartreflex n-target value info
71058diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
71059index 4ea1d37..80f4b33 100644
71060--- a/include/linux/ppp-comp.h
71061+++ b/include/linux/ppp-comp.h
71062@@ -84,7 +84,7 @@ struct compressor {
71063 struct module *owner;
71064 /* Extra skb space needed by the compressor algorithm */
71065 unsigned int comp_extra;
71066-};
71067+} __do_const;
71068
71069 /*
71070 * The return value from decompress routine is the length of the
71071diff --git a/include/linux/printk.h b/include/linux/printk.h
71072index 9afc01e..92c32e8 100644
71073--- a/include/linux/printk.h
71074+++ b/include/linux/printk.h
71075@@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
71076 extern int printk_needs_cpu(int cpu);
71077 extern void printk_tick(void);
71078
71079+extern int kptr_restrict;
71080+
71081 #ifdef CONFIG_PRINTK
71082 asmlinkage __printf(5, 0)
71083 int vprintk_emit(int facility, int level,
71084@@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
71085
71086 extern int printk_delay_msec;
71087 extern int dmesg_restrict;
71088-extern int kptr_restrict;
71089
71090 void log_buf_kexec_setup(void);
71091 void __init setup_log_buf(int early);
71092diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
71093index 32676b3..e46f2c0 100644
71094--- a/include/linux/proc_fs.h
71095+++ b/include/linux/proc_fs.h
71096@@ -159,6 +159,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
71097 return proc_create_data(name, mode, parent, proc_fops, NULL);
71098 }
71099
71100+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
71101+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
71102+{
71103+#ifdef CONFIG_GRKERNSEC_PROC_USER
71104+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
71105+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
71106+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
71107+#else
71108+ return proc_create_data(name, mode, parent, proc_fops, NULL);
71109+#endif
71110+}
71111+
71112 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
71113 umode_t mode, struct proc_dir_entry *base,
71114 read_proc_t *read_proc, void * data)
71115@@ -268,7 +280,7 @@ struct proc_ns_operations {
71116 void (*put)(void *ns);
71117 int (*install)(struct nsproxy *nsproxy, void *ns);
71118 unsigned int (*inum)(void *ns);
71119-};
71120+} __do_const;
71121 extern const struct proc_ns_operations netns_operations;
71122 extern const struct proc_ns_operations utsns_operations;
71123 extern const struct proc_ns_operations ipcns_operations;
71124diff --git a/include/linux/random.h b/include/linux/random.h
71125index d984608..d6f0042 100644
71126--- a/include/linux/random.h
71127+++ b/include/linux/random.h
71128@@ -39,6 +39,11 @@ void prandom_seed(u32 seed);
71129 u32 prandom_u32_state(struct rnd_state *);
71130 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
71131
71132+static inline unsigned long pax_get_random_long(void)
71133+{
71134+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
71135+}
71136+
71137 /*
71138 * Handle minimum values for seeds
71139 */
71140diff --git a/include/linux/rculist.h b/include/linux/rculist.h
71141index c92dd28..08f4eab 100644
71142--- a/include/linux/rculist.h
71143+++ b/include/linux/rculist.h
71144@@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
71145 struct list_head *prev, struct list_head *next);
71146 #endif
71147
71148+extern void __pax_list_add_rcu(struct list_head *new,
71149+ struct list_head *prev, struct list_head *next);
71150+
71151 /**
71152 * list_add_rcu - add a new entry to rcu-protected list
71153 * @new: new entry to be added
71154@@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
71155 __list_add_rcu(new, head, head->next);
71156 }
71157
71158+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
71159+{
71160+ __pax_list_add_rcu(new, head, head->next);
71161+}
71162+
71163 /**
71164 * list_add_tail_rcu - add a new entry to rcu-protected list
71165 * @new: new entry to be added
71166@@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
71167 __list_add_rcu(new, head->prev, head);
71168 }
71169
71170+static inline void pax_list_add_tail_rcu(struct list_head *new,
71171+ struct list_head *head)
71172+{
71173+ __pax_list_add_rcu(new, head->prev, head);
71174+}
71175+
71176 /**
71177 * list_del_rcu - deletes entry from list without re-initialization
71178 * @entry: the element to delete from the list.
71179@@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
71180 entry->prev = LIST_POISON2;
71181 }
71182
71183+extern void pax_list_del_rcu(struct list_head *entry);
71184+
71185 /**
71186 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
71187 * @n: the element to delete from the hash list.
71188diff --git a/include/linux/reboot.h b/include/linux/reboot.h
71189index 23b3630..e1bc12b 100644
71190--- a/include/linux/reboot.h
71191+++ b/include/linux/reboot.h
71192@@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
71193 * Architecture-specific implementations of sys_reboot commands.
71194 */
71195
71196-extern void machine_restart(char *cmd);
71197-extern void machine_halt(void);
71198-extern void machine_power_off(void);
71199+extern void machine_restart(char *cmd) __noreturn;
71200+extern void machine_halt(void) __noreturn;
71201+extern void machine_power_off(void) __noreturn;
71202
71203 extern void machine_shutdown(void);
71204 struct pt_regs;
71205@@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
71206 */
71207
71208 extern void kernel_restart_prepare(char *cmd);
71209-extern void kernel_restart(char *cmd);
71210-extern void kernel_halt(void);
71211-extern void kernel_power_off(void);
71212+extern void kernel_restart(char *cmd) __noreturn;
71213+extern void kernel_halt(void) __noreturn;
71214+extern void kernel_power_off(void) __noreturn;
71215
71216 extern int C_A_D; /* for sysctl */
71217 void ctrl_alt_del(void);
71218@@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
71219 * Emergency restart, callable from an interrupt handler.
71220 */
71221
71222-extern void emergency_restart(void);
71223+extern void emergency_restart(void) __noreturn;
71224 #include <asm/emergency-restart.h>
71225
71226 #endif /* _LINUX_REBOOT_H */
71227diff --git a/include/linux/regset.h b/include/linux/regset.h
71228index 8e0c9fe..ac4d221 100644
71229--- a/include/linux/regset.h
71230+++ b/include/linux/regset.h
71231@@ -161,7 +161,8 @@ struct user_regset {
71232 unsigned int align;
71233 unsigned int bias;
71234 unsigned int core_note_type;
71235-};
71236+} __do_const;
71237+typedef struct user_regset __no_const user_regset_no_const;
71238
71239 /**
71240 * struct user_regset_view - available regsets
71241diff --git a/include/linux/relay.h b/include/linux/relay.h
71242index 91cacc3..b55ff74 100644
71243--- a/include/linux/relay.h
71244+++ b/include/linux/relay.h
71245@@ -160,7 +160,7 @@ struct rchan_callbacks
71246 * The callback should return 0 if successful, negative if not.
71247 */
71248 int (*remove_buf_file)(struct dentry *dentry);
71249-};
71250+} __no_const;
71251
71252 /*
71253 * CONFIG_RELAY kernel API, kernel/relay.c
71254diff --git a/include/linux/rio.h b/include/linux/rio.h
71255index a3e7842..d973ca6 100644
71256--- a/include/linux/rio.h
71257+++ b/include/linux/rio.h
71258@@ -339,7 +339,7 @@ struct rio_ops {
71259 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
71260 u64 rstart, u32 size, u32 flags);
71261 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
71262-};
71263+} __no_const;
71264
71265 #define RIO_RESOURCE_MEM 0x00000100
71266 #define RIO_RESOURCE_DOORBELL 0x00000200
71267diff --git a/include/linux/rmap.h b/include/linux/rmap.h
71268index c20635c..2f5def4 100644
71269--- a/include/linux/rmap.h
71270+++ b/include/linux/rmap.h
71271@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
71272 void anon_vma_init(void); /* create anon_vma_cachep */
71273 int anon_vma_prepare(struct vm_area_struct *);
71274 void unlink_anon_vmas(struct vm_area_struct *);
71275-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
71276-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
71277+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
71278+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
71279
71280 static inline void anon_vma_merge(struct vm_area_struct *vma,
71281 struct vm_area_struct *next)
71282diff --git a/include/linux/sched.h b/include/linux/sched.h
71283index d211247..eac6c2c 100644
71284--- a/include/linux/sched.h
71285+++ b/include/linux/sched.h
71286@@ -61,6 +61,7 @@ struct bio_list;
71287 struct fs_struct;
71288 struct perf_event_context;
71289 struct blk_plug;
71290+struct linux_binprm;
71291
71292 /*
71293 * List of flags we want to share for kernel threads,
71294@@ -327,7 +328,7 @@ extern char __sched_text_start[], __sched_text_end[];
71295 extern int in_sched_functions(unsigned long addr);
71296
71297 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
71298-extern signed long schedule_timeout(signed long timeout);
71299+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
71300 extern signed long schedule_timeout_interruptible(signed long timeout);
71301 extern signed long schedule_timeout_killable(signed long timeout);
71302 extern signed long schedule_timeout_uninterruptible(signed long timeout);
71303@@ -354,10 +355,23 @@ struct user_namespace;
71304 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
71305
71306 extern int sysctl_max_map_count;
71307+extern unsigned long sysctl_heap_stack_gap;
71308
71309 #include <linux/aio.h>
71310
71311 #ifdef CONFIG_MMU
71312+
71313+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
71314+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
71315+#else
71316+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
71317+{
71318+ return 0;
71319+}
71320+#endif
71321+
71322+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
71323+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
71324 extern void arch_pick_mmap_layout(struct mm_struct *mm);
71325 extern unsigned long
71326 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
71327@@ -639,6 +653,17 @@ struct signal_struct {
71328 #ifdef CONFIG_TASKSTATS
71329 struct taskstats *stats;
71330 #endif
71331+
71332+#ifdef CONFIG_GRKERNSEC
71333+ u32 curr_ip;
71334+ u32 saved_ip;
71335+ u32 gr_saddr;
71336+ u32 gr_daddr;
71337+ u16 gr_sport;
71338+ u16 gr_dport;
71339+ u8 used_accept:1;
71340+#endif
71341+
71342 #ifdef CONFIG_AUDIT
71343 unsigned audit_tty;
71344 struct tty_audit_buf *tty_audit_buf;
71345@@ -717,6 +742,11 @@ struct user_struct {
71346 struct key *session_keyring; /* UID's default session keyring */
71347 #endif
71348
71349+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
71350+ unsigned int banned;
71351+ unsigned long ban_expires;
71352+#endif
71353+
71354 /* Hash table maintenance information */
71355 struct hlist_node uidhash_node;
71356 kuid_t uid;
71357@@ -1116,7 +1146,7 @@ struct sched_class {
71358 #ifdef CONFIG_FAIR_GROUP_SCHED
71359 void (*task_move_group) (struct task_struct *p, int on_rq);
71360 #endif
71361-};
71362+} __do_const;
71363
71364 struct load_weight {
71365 unsigned long weight, inv_weight;
71366@@ -1360,8 +1390,8 @@ struct task_struct {
71367 struct list_head thread_group;
71368
71369 struct completion *vfork_done; /* for vfork() */
71370- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
71371- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
71372+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
71373+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
71374
71375 cputime_t utime, stime, utimescaled, stimescaled;
71376 cputime_t gtime;
71377@@ -1377,11 +1407,6 @@ struct task_struct {
71378 struct task_cputime cputime_expires;
71379 struct list_head cpu_timers[3];
71380
71381-/* process credentials */
71382- const struct cred __rcu *real_cred; /* objective and real subjective task
71383- * credentials (COW) */
71384- const struct cred __rcu *cred; /* effective (overridable) subjective task
71385- * credentials (COW) */
71386 char comm[TASK_COMM_LEN]; /* executable name excluding path
71387 - access with [gs]et_task_comm (which lock
71388 it with task_lock())
71389@@ -1398,6 +1423,10 @@ struct task_struct {
71390 #endif
71391 /* CPU-specific state of this task */
71392 struct thread_struct thread;
71393+/* thread_info moved to task_struct */
71394+#ifdef CONFIG_X86
71395+ struct thread_info tinfo;
71396+#endif
71397 /* filesystem information */
71398 struct fs_struct *fs;
71399 /* open file information */
71400@@ -1471,6 +1500,10 @@ struct task_struct {
71401 gfp_t lockdep_reclaim_gfp;
71402 #endif
71403
71404+/* process credentials */
71405+ const struct cred __rcu *real_cred; /* objective and real subjective task
71406+ * credentials (COW) */
71407+
71408 /* journalling filesystem info */
71409 void *journal_info;
71410
71411@@ -1509,6 +1542,10 @@ struct task_struct {
71412 /* cg_list protected by css_set_lock and tsk->alloc_lock */
71413 struct list_head cg_list;
71414 #endif
71415+
71416+ const struct cred __rcu *cred; /* effective (overridable) subjective task
71417+ * credentials (COW) */
71418+
71419 #ifdef CONFIG_FUTEX
71420 struct robust_list_head __user *robust_list;
71421 #ifdef CONFIG_COMPAT
71422@@ -1605,8 +1642,74 @@ struct task_struct {
71423 #ifdef CONFIG_UPROBES
71424 struct uprobe_task *utask;
71425 #endif
71426+
71427+#ifdef CONFIG_GRKERNSEC
71428+ /* grsecurity */
71429+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71430+ u64 exec_id;
71431+#endif
71432+#ifdef CONFIG_GRKERNSEC_SETXID
71433+ const struct cred *delayed_cred;
71434+#endif
71435+ struct dentry *gr_chroot_dentry;
71436+ struct acl_subject_label *acl;
71437+ struct acl_role_label *role;
71438+ struct file *exec_file;
71439+ unsigned long brute_expires;
71440+ u16 acl_role_id;
71441+ /* is this the task that authenticated to the special role */
71442+ u8 acl_sp_role;
71443+ u8 is_writable;
71444+ u8 brute;
71445+ u8 gr_is_chrooted;
71446+#endif
71447+
71448 };
71449
71450+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
71451+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
71452+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
71453+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
71454+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
71455+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
71456+
71457+#ifdef CONFIG_PAX_SOFTMODE
71458+extern int pax_softmode;
71459+#endif
71460+
71461+extern int pax_check_flags(unsigned long *);
71462+
71463+/* if tsk != current then task_lock must be held on it */
71464+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
71465+static inline unsigned long pax_get_flags(struct task_struct *tsk)
71466+{
71467+ if (likely(tsk->mm))
71468+ return tsk->mm->pax_flags;
71469+ else
71470+ return 0UL;
71471+}
71472+
71473+/* if tsk != current then task_lock must be held on it */
71474+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
71475+{
71476+ if (likely(tsk->mm)) {
71477+ tsk->mm->pax_flags = flags;
71478+ return 0;
71479+ }
71480+ return -EINVAL;
71481+}
71482+#endif
71483+
71484+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
71485+extern void pax_set_initial_flags(struct linux_binprm *bprm);
71486+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
71487+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
71488+#endif
71489+
71490+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
71491+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
71492+extern void pax_report_refcount_overflow(struct pt_regs *regs);
71493+
71494 /* Future-safe accessor for struct task_struct's cpus_allowed. */
71495 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
71496
71497@@ -1696,7 +1799,7 @@ struct pid_namespace;
71498 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
71499 struct pid_namespace *ns);
71500
71501-static inline pid_t task_pid_nr(struct task_struct *tsk)
71502+static inline pid_t task_pid_nr(const struct task_struct *tsk)
71503 {
71504 return tsk->pid;
71505 }
71506@@ -2155,7 +2258,9 @@ void yield(void);
71507 extern struct exec_domain default_exec_domain;
71508
71509 union thread_union {
71510+#ifndef CONFIG_X86
71511 struct thread_info thread_info;
71512+#endif
71513 unsigned long stack[THREAD_SIZE/sizeof(long)];
71514 };
71515
71516@@ -2188,6 +2293,7 @@ extern struct pid_namespace init_pid_ns;
71517 */
71518
71519 extern struct task_struct *find_task_by_vpid(pid_t nr);
71520+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
71521 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
71522 struct pid_namespace *ns);
71523
71524@@ -2344,7 +2450,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
71525 extern void exit_itimers(struct signal_struct *);
71526 extern void flush_itimer_signals(void);
71527
71528-extern void do_group_exit(int);
71529+extern __noreturn void do_group_exit(int);
71530
71531 extern int allow_signal(int);
71532 extern int disallow_signal(int);
71533@@ -2545,9 +2651,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
71534
71535 #endif
71536
71537-static inline int object_is_on_stack(void *obj)
71538+static inline int object_starts_on_stack(void *obj)
71539 {
71540- void *stack = task_stack_page(current);
71541+ const void *stack = task_stack_page(current);
71542
71543 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
71544 }
71545diff --git a/include/linux/security.h b/include/linux/security.h
71546index eee7478..290f7ba 100644
71547--- a/include/linux/security.h
71548+++ b/include/linux/security.h
71549@@ -26,6 +26,7 @@
71550 #include <linux/capability.h>
71551 #include <linux/slab.h>
71552 #include <linux/err.h>
71553+#include <linux/grsecurity.h>
71554
71555 struct linux_binprm;
71556 struct cred;
71557diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
71558index 68a04a3..866e6a1 100644
71559--- a/include/linux/seq_file.h
71560+++ b/include/linux/seq_file.h
71561@@ -26,6 +26,9 @@ struct seq_file {
71562 struct mutex lock;
71563 const struct seq_operations *op;
71564 int poll_event;
71565+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71566+ u64 exec_id;
71567+#endif
71568 #ifdef CONFIG_USER_NS
71569 struct user_namespace *user_ns;
71570 #endif
71571@@ -38,6 +41,7 @@ struct seq_operations {
71572 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
71573 int (*show) (struct seq_file *m, void *v);
71574 };
71575+typedef struct seq_operations __no_const seq_operations_no_const;
71576
71577 #define SEQ_SKIP 1
71578
71579diff --git a/include/linux/shm.h b/include/linux/shm.h
71580index 429c199..4d42e38 100644
71581--- a/include/linux/shm.h
71582+++ b/include/linux/shm.h
71583@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
71584
71585 /* The task created the shm object. NULL if the task is dead. */
71586 struct task_struct *shm_creator;
71587+#ifdef CONFIG_GRKERNSEC
71588+ time_t shm_createtime;
71589+ pid_t shm_lapid;
71590+#endif
71591 };
71592
71593 /* shm_mode upper byte flags */
71594diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
71595index 98399e2..7c74c41 100644
71596--- a/include/linux/skbuff.h
71597+++ b/include/linux/skbuff.h
71598@@ -590,7 +590,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
71599 extern struct sk_buff *__alloc_skb(unsigned int size,
71600 gfp_t priority, int flags, int node);
71601 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
71602-static inline struct sk_buff *alloc_skb(unsigned int size,
71603+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
71604 gfp_t priority)
71605 {
71606 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
71607@@ -700,7 +700,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
71608 */
71609 static inline int skb_queue_empty(const struct sk_buff_head *list)
71610 {
71611- return list->next == (struct sk_buff *)list;
71612+ return list->next == (const struct sk_buff *)list;
71613 }
71614
71615 /**
71616@@ -713,7 +713,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
71617 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
71618 const struct sk_buff *skb)
71619 {
71620- return skb->next == (struct sk_buff *)list;
71621+ return skb->next == (const struct sk_buff *)list;
71622 }
71623
71624 /**
71625@@ -726,7 +726,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
71626 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
71627 const struct sk_buff *skb)
71628 {
71629- return skb->prev == (struct sk_buff *)list;
71630+ return skb->prev == (const struct sk_buff *)list;
71631 }
71632
71633 /**
71634@@ -1727,7 +1727,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
71635 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
71636 */
71637 #ifndef NET_SKB_PAD
71638-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
71639+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
71640 #endif
71641
71642 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
71643@@ -2305,7 +2305,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
71644 int noblock, int *err);
71645 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
71646 struct poll_table_struct *wait);
71647-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
71648+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
71649 int offset, struct iovec *to,
71650 int size);
71651 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
71652@@ -2595,6 +2595,9 @@ static inline void nf_reset(struct sk_buff *skb)
71653 nf_bridge_put(skb->nf_bridge);
71654 skb->nf_bridge = NULL;
71655 #endif
71656+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
71657+ skb->nf_trace = 0;
71658+#endif
71659 }
71660
71661 /* Note: This doesn't put any conntrack and bridge info in dst. */
71662diff --git a/include/linux/slab.h b/include/linux/slab.h
71663index 5d168d7..720bff3 100644
71664--- a/include/linux/slab.h
71665+++ b/include/linux/slab.h
71666@@ -12,13 +12,20 @@
71667 #include <linux/gfp.h>
71668 #include <linux/types.h>
71669 #include <linux/workqueue.h>
71670-
71671+#include <linux/err.h>
71672
71673 /*
71674 * Flags to pass to kmem_cache_create().
71675 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
71676 */
71677 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
71678+
71679+#ifdef CONFIG_PAX_USERCOPY_SLABS
71680+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
71681+#else
71682+#define SLAB_USERCOPY 0x00000000UL
71683+#endif
71684+
71685 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
71686 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
71687 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
71688@@ -89,10 +96,13 @@
71689 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
71690 * Both make kfree a no-op.
71691 */
71692-#define ZERO_SIZE_PTR ((void *)16)
71693+#define ZERO_SIZE_PTR \
71694+({ \
71695+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
71696+ (void *)(-MAX_ERRNO-1L); \
71697+})
71698
71699-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
71700- (unsigned long)ZERO_SIZE_PTR)
71701+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
71702
71703 /*
71704 * Common fields provided in kmem_cache by all slab allocators
71705@@ -112,7 +122,7 @@ struct kmem_cache {
71706 unsigned int align; /* Alignment as calculated */
71707 unsigned long flags; /* Active flags on the slab */
71708 const char *name; /* Slab name for sysfs */
71709- int refcount; /* Use counter */
71710+ atomic_t refcount; /* Use counter */
71711 void (*ctor)(void *); /* Called on object slot creation */
71712 struct list_head list; /* List of all slab caches on the system */
71713 };
71714@@ -232,6 +242,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
71715 void kfree(const void *);
71716 void kzfree(const void *);
71717 size_t ksize(const void *);
71718+const char *check_heap_object(const void *ptr, unsigned long n);
71719+bool is_usercopy_object(const void *ptr);
71720
71721 /*
71722 * Allocator specific definitions. These are mainly used to establish optimized
71723@@ -311,6 +323,7 @@ size_t ksize(const void *);
71724 * for general use, and so are not documented here. For a full list of
71725 * potential flags, always refer to linux/gfp.h.
71726 */
71727+
71728 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
71729 {
71730 if (size != 0 && n > SIZE_MAX / size)
71731@@ -370,7 +383,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
71732 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
71733 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
71734 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
71735-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
71736+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
71737 #define kmalloc_track_caller(size, flags) \
71738 __kmalloc_track_caller(size, flags, _RET_IP_)
71739 #else
71740@@ -390,7 +403,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
71741 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
71742 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
71743 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
71744-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
71745+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
71746 #define kmalloc_node_track_caller(size, flags, node) \
71747 __kmalloc_node_track_caller(size, flags, node, \
71748 _RET_IP_)
71749diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
71750index 8bb6e0e..8eb0dbe 100644
71751--- a/include/linux/slab_def.h
71752+++ b/include/linux/slab_def.h
71753@@ -52,7 +52,7 @@ struct kmem_cache {
71754 /* 4) cache creation/removal */
71755 const char *name;
71756 struct list_head list;
71757- int refcount;
71758+ atomic_t refcount;
71759 int object_size;
71760 int align;
71761
71762@@ -68,10 +68,10 @@ struct kmem_cache {
71763 unsigned long node_allocs;
71764 unsigned long node_frees;
71765 unsigned long node_overflow;
71766- atomic_t allochit;
71767- atomic_t allocmiss;
71768- atomic_t freehit;
71769- atomic_t freemiss;
71770+ atomic_unchecked_t allochit;
71771+ atomic_unchecked_t allocmiss;
71772+ atomic_unchecked_t freehit;
71773+ atomic_unchecked_t freemiss;
71774
71775 /*
71776 * If debugging is enabled, then the allocator can add additional
71777@@ -111,11 +111,16 @@ struct cache_sizes {
71778 #ifdef CONFIG_ZONE_DMA
71779 struct kmem_cache *cs_dmacachep;
71780 #endif
71781+
71782+#ifdef CONFIG_PAX_USERCOPY_SLABS
71783+ struct kmem_cache *cs_usercopycachep;
71784+#endif
71785+
71786 };
71787 extern struct cache_sizes malloc_sizes[];
71788
71789 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
71790-void *__kmalloc(size_t size, gfp_t flags);
71791+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
71792
71793 #ifdef CONFIG_TRACING
71794 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
71795@@ -152,6 +157,13 @@ found:
71796 cachep = malloc_sizes[i].cs_dmacachep;
71797 else
71798 #endif
71799+
71800+#ifdef CONFIG_PAX_USERCOPY_SLABS
71801+ if (flags & GFP_USERCOPY)
71802+ cachep = malloc_sizes[i].cs_usercopycachep;
71803+ else
71804+#endif
71805+
71806 cachep = malloc_sizes[i].cs_cachep;
71807
71808 ret = kmem_cache_alloc_trace(cachep, flags, size);
71809@@ -162,7 +174,7 @@ found:
71810 }
71811
71812 #ifdef CONFIG_NUMA
71813-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
71814+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
71815 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
71816
71817 #ifdef CONFIG_TRACING
71818@@ -205,6 +217,13 @@ found:
71819 cachep = malloc_sizes[i].cs_dmacachep;
71820 else
71821 #endif
71822+
71823+#ifdef CONFIG_PAX_USERCOPY_SLABS
71824+ if (flags & GFP_USERCOPY)
71825+ cachep = malloc_sizes[i].cs_usercopycachep;
71826+ else
71827+#endif
71828+
71829 cachep = malloc_sizes[i].cs_cachep;
71830
71831 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
71832diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
71833index f28e14a..7831211 100644
71834--- a/include/linux/slob_def.h
71835+++ b/include/linux/slob_def.h
71836@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
71837 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
71838 }
71839
71840-void *__kmalloc_node(size_t size, gfp_t flags, int node);
71841+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
71842
71843 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
71844 {
71845@@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
71846 return __kmalloc_node(size, flags, NUMA_NO_NODE);
71847 }
71848
71849-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
71850+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
71851 {
71852 return kmalloc(size, flags);
71853 }
71854diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
71855index 9db4825..ed42fb5 100644
71856--- a/include/linux/slub_def.h
71857+++ b/include/linux/slub_def.h
71858@@ -91,7 +91,7 @@ struct kmem_cache {
71859 struct kmem_cache_order_objects max;
71860 struct kmem_cache_order_objects min;
71861 gfp_t allocflags; /* gfp flags to use on each alloc */
71862- int refcount; /* Refcount for slab cache destroy */
71863+ atomic_t refcount; /* Refcount for slab cache destroy */
71864 void (*ctor)(void *);
71865 int inuse; /* Offset to metadata */
71866 int align; /* Alignment */
71867@@ -156,7 +156,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
71868 * Sorry that the following has to be that ugly but some versions of GCC
71869 * have trouble with constant propagation and loops.
71870 */
71871-static __always_inline int kmalloc_index(size_t size)
71872+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
71873 {
71874 if (!size)
71875 return 0;
71876@@ -221,7 +221,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
71877 }
71878
71879 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
71880-void *__kmalloc(size_t size, gfp_t flags);
71881+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
71882
71883 static __always_inline void *
71884 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
71885@@ -265,7 +265,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
71886 }
71887 #endif
71888
71889-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
71890+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
71891 {
71892 unsigned int order = get_order(size);
71893 return kmalloc_order_trace(size, flags, order);
71894@@ -290,7 +290,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
71895 }
71896
71897 #ifdef CONFIG_NUMA
71898-void *__kmalloc_node(size_t size, gfp_t flags, int node);
71899+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
71900 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
71901
71902 #ifdef CONFIG_TRACING
71903diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
71904index e8d702e..0a56eb4 100644
71905--- a/include/linux/sock_diag.h
71906+++ b/include/linux/sock_diag.h
71907@@ -10,7 +10,7 @@ struct sock;
71908 struct sock_diag_handler {
71909 __u8 family;
71910 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
71911-};
71912+} __do_const;
71913
71914 int sock_diag_register(const struct sock_diag_handler *h);
71915 void sock_diag_unregister(const struct sock_diag_handler *h);
71916diff --git a/include/linux/sonet.h b/include/linux/sonet.h
71917index 680f9a3..f13aeb0 100644
71918--- a/include/linux/sonet.h
71919+++ b/include/linux/sonet.h
71920@@ -7,7 +7,7 @@
71921 #include <uapi/linux/sonet.h>
71922
71923 struct k_sonet_stats {
71924-#define __HANDLE_ITEM(i) atomic_t i
71925+#define __HANDLE_ITEM(i) atomic_unchecked_t i
71926 __SONET_ITEMS
71927 #undef __HANDLE_ITEM
71928 };
71929diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
71930index 34206b8..3db7f1c 100644
71931--- a/include/linux/sunrpc/clnt.h
71932+++ b/include/linux/sunrpc/clnt.h
71933@@ -96,7 +96,7 @@ struct rpc_procinfo {
71934 unsigned int p_timer; /* Which RTT timer to use */
71935 u32 p_statidx; /* Which procedure to account */
71936 const char * p_name; /* name of procedure */
71937-};
71938+} __do_const;
71939
71940 #ifdef __KERNEL__
71941
71942@@ -176,9 +176,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
71943 {
71944 switch (sap->sa_family) {
71945 case AF_INET:
71946- return ntohs(((struct sockaddr_in *)sap)->sin_port);
71947+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
71948 case AF_INET6:
71949- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
71950+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
71951 }
71952 return 0;
71953 }
71954@@ -211,7 +211,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
71955 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
71956 const struct sockaddr *src)
71957 {
71958- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
71959+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
71960 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
71961
71962 dsin->sin_family = ssin->sin_family;
71963@@ -314,7 +314,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
71964 if (sa->sa_family != AF_INET6)
71965 return 0;
71966
71967- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
71968+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
71969 }
71970
71971 #endif /* __KERNEL__ */
71972diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
71973index 676ddf5..4c519a1 100644
71974--- a/include/linux/sunrpc/svc.h
71975+++ b/include/linux/sunrpc/svc.h
71976@@ -410,7 +410,7 @@ struct svc_procedure {
71977 unsigned int pc_count; /* call count */
71978 unsigned int pc_cachetype; /* cache info (NFS) */
71979 unsigned int pc_xdrressize; /* maximum size of XDR reply */
71980-};
71981+} __do_const;
71982
71983 /*
71984 * Function prototypes.
71985diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
71986index 0b8e3e6..33e0a01 100644
71987--- a/include/linux/sunrpc/svc_rdma.h
71988+++ b/include/linux/sunrpc/svc_rdma.h
71989@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
71990 extern unsigned int svcrdma_max_requests;
71991 extern unsigned int svcrdma_max_req_size;
71992
71993-extern atomic_t rdma_stat_recv;
71994-extern atomic_t rdma_stat_read;
71995-extern atomic_t rdma_stat_write;
71996-extern atomic_t rdma_stat_sq_starve;
71997-extern atomic_t rdma_stat_rq_starve;
71998-extern atomic_t rdma_stat_rq_poll;
71999-extern atomic_t rdma_stat_rq_prod;
72000-extern atomic_t rdma_stat_sq_poll;
72001-extern atomic_t rdma_stat_sq_prod;
72002+extern atomic_unchecked_t rdma_stat_recv;
72003+extern atomic_unchecked_t rdma_stat_read;
72004+extern atomic_unchecked_t rdma_stat_write;
72005+extern atomic_unchecked_t rdma_stat_sq_starve;
72006+extern atomic_unchecked_t rdma_stat_rq_starve;
72007+extern atomic_unchecked_t rdma_stat_rq_poll;
72008+extern atomic_unchecked_t rdma_stat_rq_prod;
72009+extern atomic_unchecked_t rdma_stat_sq_poll;
72010+extern atomic_unchecked_t rdma_stat_sq_prod;
72011
72012 #define RPCRDMA_VERSION 1
72013
72014diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
72015index dd74084a..7f509d5 100644
72016--- a/include/linux/sunrpc/svcauth.h
72017+++ b/include/linux/sunrpc/svcauth.h
72018@@ -109,7 +109,7 @@ struct auth_ops {
72019 int (*release)(struct svc_rqst *rq);
72020 void (*domain_release)(struct auth_domain *);
72021 int (*set_client)(struct svc_rqst *rq);
72022-};
72023+} __do_const;
72024
72025 #define SVC_GARBAGE 1
72026 #define SVC_SYSERR 2
72027diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
72028index 071d62c..4ccc7ac 100644
72029--- a/include/linux/swiotlb.h
72030+++ b/include/linux/swiotlb.h
72031@@ -59,7 +59,8 @@ extern void
72032
72033 extern void
72034 swiotlb_free_coherent(struct device *hwdev, size_t size,
72035- void *vaddr, dma_addr_t dma_handle);
72036+ void *vaddr, dma_addr_t dma_handle,
72037+ struct dma_attrs *attrs);
72038
72039 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
72040 unsigned long offset, size_t size,
72041diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
72042index 45e2db2..1635156a 100644
72043--- a/include/linux/syscalls.h
72044+++ b/include/linux/syscalls.h
72045@@ -615,7 +615,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
72046 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
72047 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
72048 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
72049- struct sockaddr __user *, int);
72050+ struct sockaddr __user *, int) __intentional_overflow(0);
72051 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
72052 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
72053 unsigned int vlen, unsigned flags);
72054diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
72055index 27b3b0b..e093dd9 100644
72056--- a/include/linux/syscore_ops.h
72057+++ b/include/linux/syscore_ops.h
72058@@ -16,7 +16,7 @@ struct syscore_ops {
72059 int (*suspend)(void);
72060 void (*resume)(void);
72061 void (*shutdown)(void);
72062-};
72063+} __do_const;
72064
72065 extern void register_syscore_ops(struct syscore_ops *ops);
72066 extern void unregister_syscore_ops(struct syscore_ops *ops);
72067diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
72068index 14a8ff2..af52bad 100644
72069--- a/include/linux/sysctl.h
72070+++ b/include/linux/sysctl.h
72071@@ -34,13 +34,13 @@ struct ctl_table_root;
72072 struct ctl_table_header;
72073 struct ctl_dir;
72074
72075-typedef struct ctl_table ctl_table;
72076-
72077 typedef int proc_handler (struct ctl_table *ctl, int write,
72078 void __user *buffer, size_t *lenp, loff_t *ppos);
72079
72080 extern int proc_dostring(struct ctl_table *, int,
72081 void __user *, size_t *, loff_t *);
72082+extern int proc_dostring_modpriv(struct ctl_table *, int,
72083+ void __user *, size_t *, loff_t *);
72084 extern int proc_dointvec(struct ctl_table *, int,
72085 void __user *, size_t *, loff_t *);
72086 extern int proc_dointvec_minmax(struct ctl_table *, int,
72087@@ -115,7 +115,9 @@ struct ctl_table
72088 struct ctl_table_poll *poll;
72089 void *extra1;
72090 void *extra2;
72091-};
72092+} __do_const;
72093+typedef struct ctl_table __no_const ctl_table_no_const;
72094+typedef struct ctl_table ctl_table;
72095
72096 struct ctl_node {
72097 struct rb_node node;
72098diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
72099index 381f06d..dc16cc7 100644
72100--- a/include/linux/sysfs.h
72101+++ b/include/linux/sysfs.h
72102@@ -31,7 +31,8 @@ struct attribute {
72103 struct lock_class_key *key;
72104 struct lock_class_key skey;
72105 #endif
72106-};
72107+} __do_const;
72108+typedef struct attribute __no_const attribute_no_const;
72109
72110 /**
72111 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
72112@@ -59,8 +60,8 @@ struct attribute_group {
72113 umode_t (*is_visible)(struct kobject *,
72114 struct attribute *, int);
72115 struct attribute **attrs;
72116-};
72117-
72118+} __do_const;
72119+typedef struct attribute_group __no_const attribute_group_no_const;
72120
72121
72122 /**
72123@@ -107,7 +108,8 @@ struct bin_attribute {
72124 char *, loff_t, size_t);
72125 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
72126 struct vm_area_struct *vma);
72127-};
72128+} __do_const;
72129+typedef struct bin_attribute __no_const bin_attribute_no_const;
72130
72131 /**
72132 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
72133diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
72134index 7faf933..9b85a0c 100644
72135--- a/include/linux/sysrq.h
72136+++ b/include/linux/sysrq.h
72137@@ -16,6 +16,7 @@
72138
72139 #include <linux/errno.h>
72140 #include <linux/types.h>
72141+#include <linux/compiler.h>
72142
72143 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
72144 #define SYSRQ_DEFAULT_ENABLE 1
72145@@ -36,7 +37,7 @@ struct sysrq_key_op {
72146 char *help_msg;
72147 char *action_msg;
72148 int enable_mask;
72149-};
72150+} __do_const;
72151
72152 #ifdef CONFIG_MAGIC_SYSRQ
72153
72154diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
72155index e7e0473..7989295 100644
72156--- a/include/linux/thread_info.h
72157+++ b/include/linux/thread_info.h
72158@@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
72159 #error "no set_restore_sigmask() provided and default one won't work"
72160 #endif
72161
72162+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
72163+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
72164+{
72165+#ifndef CONFIG_PAX_USERCOPY_DEBUG
72166+ if (!__builtin_constant_p(n))
72167+#endif
72168+ __check_object_size(ptr, n, to_user);
72169+}
72170+
72171 #endif /* __KERNEL__ */
72172
72173 #endif /* _LINUX_THREAD_INFO_H */
72174diff --git a/include/linux/tty.h b/include/linux/tty.h
72175index 8db1b56..c16a040 100644
72176--- a/include/linux/tty.h
72177+++ b/include/linux/tty.h
72178@@ -194,7 +194,7 @@ struct tty_port {
72179 const struct tty_port_operations *ops; /* Port operations */
72180 spinlock_t lock; /* Lock protecting tty field */
72181 int blocked_open; /* Waiting to open */
72182- int count; /* Usage count */
72183+ atomic_t count; /* Usage count */
72184 wait_queue_head_t open_wait; /* Open waiters */
72185 wait_queue_head_t close_wait; /* Close waiters */
72186 wait_queue_head_t delta_msr_wait; /* Modem status change */
72187@@ -490,7 +490,7 @@ extern int tty_port_open(struct tty_port *port,
72188 struct tty_struct *tty, struct file *filp);
72189 static inline int tty_port_users(struct tty_port *port)
72190 {
72191- return port->count + port->blocked_open;
72192+ return atomic_read(&port->count) + port->blocked_open;
72193 }
72194
72195 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
72196diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
72197index dd976cf..e272742 100644
72198--- a/include/linux/tty_driver.h
72199+++ b/include/linux/tty_driver.h
72200@@ -284,7 +284,7 @@ struct tty_operations {
72201 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
72202 #endif
72203 const struct file_operations *proc_fops;
72204-};
72205+} __do_const;
72206
72207 struct tty_driver {
72208 int magic; /* magic number for this structure */
72209diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
72210index fb79dd8d..07d4773 100644
72211--- a/include/linux/tty_ldisc.h
72212+++ b/include/linux/tty_ldisc.h
72213@@ -149,7 +149,7 @@ struct tty_ldisc_ops {
72214
72215 struct module *owner;
72216
72217- int refcount;
72218+ atomic_t refcount;
72219 };
72220
72221 struct tty_ldisc {
72222diff --git a/include/linux/types.h b/include/linux/types.h
72223index 4d118ba..c3ee9bf 100644
72224--- a/include/linux/types.h
72225+++ b/include/linux/types.h
72226@@ -176,10 +176,26 @@ typedef struct {
72227 int counter;
72228 } atomic_t;
72229
72230+#ifdef CONFIG_PAX_REFCOUNT
72231+typedef struct {
72232+ int counter;
72233+} atomic_unchecked_t;
72234+#else
72235+typedef atomic_t atomic_unchecked_t;
72236+#endif
72237+
72238 #ifdef CONFIG_64BIT
72239 typedef struct {
72240 long counter;
72241 } atomic64_t;
72242+
72243+#ifdef CONFIG_PAX_REFCOUNT
72244+typedef struct {
72245+ long counter;
72246+} atomic64_unchecked_t;
72247+#else
72248+typedef atomic64_t atomic64_unchecked_t;
72249+#endif
72250 #endif
72251
72252 struct list_head {
72253diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
72254index 5ca0951..ab496a5 100644
72255--- a/include/linux/uaccess.h
72256+++ b/include/linux/uaccess.h
72257@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
72258 long ret; \
72259 mm_segment_t old_fs = get_fs(); \
72260 \
72261- set_fs(KERNEL_DS); \
72262 pagefault_disable(); \
72263- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
72264- pagefault_enable(); \
72265+ set_fs(KERNEL_DS); \
72266+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
72267 set_fs(old_fs); \
72268+ pagefault_enable(); \
72269 ret; \
72270 })
72271
72272diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
72273index 8e522cbc..aa8572d 100644
72274--- a/include/linux/uidgid.h
72275+++ b/include/linux/uidgid.h
72276@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
72277
72278 #endif /* CONFIG_USER_NS */
72279
72280+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
72281+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
72282+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
72283+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
72284+
72285 #endif /* _LINUX_UIDGID_H */
72286diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
72287index 99c1b4d..562e6f3 100644
72288--- a/include/linux/unaligned/access_ok.h
72289+++ b/include/linux/unaligned/access_ok.h
72290@@ -4,34 +4,34 @@
72291 #include <linux/kernel.h>
72292 #include <asm/byteorder.h>
72293
72294-static inline u16 get_unaligned_le16(const void *p)
72295+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
72296 {
72297- return le16_to_cpup((__le16 *)p);
72298+ return le16_to_cpup((const __le16 *)p);
72299 }
72300
72301-static inline u32 get_unaligned_le32(const void *p)
72302+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
72303 {
72304- return le32_to_cpup((__le32 *)p);
72305+ return le32_to_cpup((const __le32 *)p);
72306 }
72307
72308-static inline u64 get_unaligned_le64(const void *p)
72309+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
72310 {
72311- return le64_to_cpup((__le64 *)p);
72312+ return le64_to_cpup((const __le64 *)p);
72313 }
72314
72315-static inline u16 get_unaligned_be16(const void *p)
72316+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
72317 {
72318- return be16_to_cpup((__be16 *)p);
72319+ return be16_to_cpup((const __be16 *)p);
72320 }
72321
72322-static inline u32 get_unaligned_be32(const void *p)
72323+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
72324 {
72325- return be32_to_cpup((__be32 *)p);
72326+ return be32_to_cpup((const __be32 *)p);
72327 }
72328
72329-static inline u64 get_unaligned_be64(const void *p)
72330+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
72331 {
72332- return be64_to_cpup((__be64 *)p);
72333+ return be64_to_cpup((const __be64 *)p);
72334 }
72335
72336 static inline void put_unaligned_le16(u16 val, void *p)
72337diff --git a/include/linux/usb.h b/include/linux/usb.h
72338index 4d22d0f..8d0e8f8 100644
72339--- a/include/linux/usb.h
72340+++ b/include/linux/usb.h
72341@@ -554,7 +554,7 @@ struct usb_device {
72342 int maxchild;
72343
72344 u32 quirks;
72345- atomic_t urbnum;
72346+ atomic_unchecked_t urbnum;
72347
72348 unsigned long active_duration;
72349
72350@@ -1604,7 +1604,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
72351
72352 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
72353 __u8 request, __u8 requesttype, __u16 value, __u16 index,
72354- void *data, __u16 size, int timeout);
72355+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
72356 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
72357 void *data, int len, int *actual_length, int timeout);
72358 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
72359diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
72360index c5d36c6..108f4f9 100644
72361--- a/include/linux/usb/renesas_usbhs.h
72362+++ b/include/linux/usb/renesas_usbhs.h
72363@@ -39,7 +39,7 @@ enum {
72364 */
72365 struct renesas_usbhs_driver_callback {
72366 int (*notify_hotplug)(struct platform_device *pdev);
72367-};
72368+} __no_const;
72369
72370 /*
72371 * callback functions for platform
72372diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
72373index 5209cfe..b6b215f 100644
72374--- a/include/linux/user_namespace.h
72375+++ b/include/linux/user_namespace.h
72376@@ -21,7 +21,7 @@ struct user_namespace {
72377 struct uid_gid_map uid_map;
72378 struct uid_gid_map gid_map;
72379 struct uid_gid_map projid_map;
72380- struct kref kref;
72381+ atomic_t count;
72382 struct user_namespace *parent;
72383 kuid_t owner;
72384 kgid_t group;
72385@@ -37,18 +37,18 @@ extern struct user_namespace init_user_ns;
72386 static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
72387 {
72388 if (ns)
72389- kref_get(&ns->kref);
72390+ atomic_inc(&ns->count);
72391 return ns;
72392 }
72393
72394 extern int create_user_ns(struct cred *new);
72395 extern int unshare_userns(unsigned long unshare_flags, struct cred **new_cred);
72396-extern void free_user_ns(struct kref *kref);
72397+extern void free_user_ns(struct user_namespace *ns);
72398
72399 static inline void put_user_ns(struct user_namespace *ns)
72400 {
72401- if (ns)
72402- kref_put(&ns->kref, free_user_ns);
72403+ if (ns && atomic_dec_and_test(&ns->count))
72404+ free_user_ns(ns);
72405 }
72406
72407 struct seq_operations;
72408diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
72409index 6f8fbcf..8259001 100644
72410--- a/include/linux/vermagic.h
72411+++ b/include/linux/vermagic.h
72412@@ -25,9 +25,35 @@
72413 #define MODULE_ARCH_VERMAGIC ""
72414 #endif
72415
72416+#ifdef CONFIG_PAX_REFCOUNT
72417+#define MODULE_PAX_REFCOUNT "REFCOUNT "
72418+#else
72419+#define MODULE_PAX_REFCOUNT ""
72420+#endif
72421+
72422+#ifdef CONSTIFY_PLUGIN
72423+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
72424+#else
72425+#define MODULE_CONSTIFY_PLUGIN ""
72426+#endif
72427+
72428+#ifdef STACKLEAK_PLUGIN
72429+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
72430+#else
72431+#define MODULE_STACKLEAK_PLUGIN ""
72432+#endif
72433+
72434+#ifdef CONFIG_GRKERNSEC
72435+#define MODULE_GRSEC "GRSEC "
72436+#else
72437+#define MODULE_GRSEC ""
72438+#endif
72439+
72440 #define VERMAGIC_STRING \
72441 UTS_RELEASE " " \
72442 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
72443 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
72444- MODULE_ARCH_VERMAGIC
72445+ MODULE_ARCH_VERMAGIC \
72446+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
72447+ MODULE_GRSEC
72448
72449diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
72450index 6071e91..ca6a489 100644
72451--- a/include/linux/vmalloc.h
72452+++ b/include/linux/vmalloc.h
72453@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
72454 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
72455 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
72456 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
72457+
72458+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
72459+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
72460+#endif
72461+
72462 /* bits [20..32] reserved for arch specific ioremap internals */
72463
72464 /*
72465@@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
72466 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
72467 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
72468 unsigned long start, unsigned long end, gfp_t gfp_mask,
72469- pgprot_t prot, int node, const void *caller);
72470+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
72471 extern void vfree(const void *addr);
72472
72473 extern void *vmap(struct page **pages, unsigned int count,
72474@@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
72475 extern void free_vm_area(struct vm_struct *area);
72476
72477 /* for /dev/kmem */
72478-extern long vread(char *buf, char *addr, unsigned long count);
72479-extern long vwrite(char *buf, char *addr, unsigned long count);
72480+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
72481+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
72482
72483 /*
72484 * Internals. Dont't use..
72485diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
72486index a13291f..af51fa3 100644
72487--- a/include/linux/vmstat.h
72488+++ b/include/linux/vmstat.h
72489@@ -95,18 +95,18 @@ static inline void vm_events_fold_cpu(int cpu)
72490 /*
72491 * Zone based page accounting with per cpu differentials.
72492 */
72493-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
72494+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
72495
72496 static inline void zone_page_state_add(long x, struct zone *zone,
72497 enum zone_stat_item item)
72498 {
72499- atomic_long_add(x, &zone->vm_stat[item]);
72500- atomic_long_add(x, &vm_stat[item]);
72501+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
72502+ atomic_long_add_unchecked(x, &vm_stat[item]);
72503 }
72504
72505 static inline unsigned long global_page_state(enum zone_stat_item item)
72506 {
72507- long x = atomic_long_read(&vm_stat[item]);
72508+ long x = atomic_long_read_unchecked(&vm_stat[item]);
72509 #ifdef CONFIG_SMP
72510 if (x < 0)
72511 x = 0;
72512@@ -117,7 +117,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
72513 static inline unsigned long zone_page_state(struct zone *zone,
72514 enum zone_stat_item item)
72515 {
72516- long x = atomic_long_read(&zone->vm_stat[item]);
72517+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
72518 #ifdef CONFIG_SMP
72519 if (x < 0)
72520 x = 0;
72521@@ -134,7 +134,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
72522 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
72523 enum zone_stat_item item)
72524 {
72525- long x = atomic_long_read(&zone->vm_stat[item]);
72526+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
72527
72528 #ifdef CONFIG_SMP
72529 int cpu;
72530@@ -226,8 +226,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
72531
72532 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
72533 {
72534- atomic_long_inc(&zone->vm_stat[item]);
72535- atomic_long_inc(&vm_stat[item]);
72536+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
72537+ atomic_long_inc_unchecked(&vm_stat[item]);
72538 }
72539
72540 static inline void __inc_zone_page_state(struct page *page,
72541@@ -238,8 +238,8 @@ static inline void __inc_zone_page_state(struct page *page,
72542
72543 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
72544 {
72545- atomic_long_dec(&zone->vm_stat[item]);
72546- atomic_long_dec(&vm_stat[item]);
72547+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
72548+ atomic_long_dec_unchecked(&vm_stat[item]);
72549 }
72550
72551 static inline void __dec_zone_page_state(struct page *page,
72552diff --git a/include/linux/xattr.h b/include/linux/xattr.h
72553index fdbafc6..b7ffd47 100644
72554--- a/include/linux/xattr.h
72555+++ b/include/linux/xattr.h
72556@@ -28,7 +28,7 @@ struct xattr_handler {
72557 size_t size, int handler_flags);
72558 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
72559 size_t size, int flags, int handler_flags);
72560-};
72561+} __do_const;
72562
72563 struct xattr {
72564 char *name;
72565diff --git a/include/linux/zlib.h b/include/linux/zlib.h
72566index 9c5a6b4..09c9438 100644
72567--- a/include/linux/zlib.h
72568+++ b/include/linux/zlib.h
72569@@ -31,6 +31,7 @@
72570 #define _ZLIB_H
72571
72572 #include <linux/zconf.h>
72573+#include <linux/compiler.h>
72574
72575 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
72576 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
72577@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
72578
72579 /* basic functions */
72580
72581-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
72582+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
72583 /*
72584 Returns the number of bytes that needs to be allocated for a per-
72585 stream workspace with the specified parameters. A pointer to this
72586diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
72587index 95d1c91..6798cca 100644
72588--- a/include/media/v4l2-dev.h
72589+++ b/include/media/v4l2-dev.h
72590@@ -76,7 +76,7 @@ struct v4l2_file_operations {
72591 int (*mmap) (struct file *, struct vm_area_struct *);
72592 int (*open) (struct file *);
72593 int (*release) (struct file *);
72594-};
72595+} __do_const;
72596
72597 /*
72598 * Newer version of video_device, handled by videodev2.c
72599diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
72600index 4118ad1..cb7e25f 100644
72601--- a/include/media/v4l2-ioctl.h
72602+++ b/include/media/v4l2-ioctl.h
72603@@ -284,7 +284,6 @@ struct v4l2_ioctl_ops {
72604 bool valid_prio, int cmd, void *arg);
72605 };
72606
72607-
72608 /* v4l debugging and diagnostics */
72609
72610 /* Debug bitmask flags to be used on V4L2 */
72611diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
72612index adcbb20..62c2559 100644
72613--- a/include/net/9p/transport.h
72614+++ b/include/net/9p/transport.h
72615@@ -57,7 +57,7 @@ struct p9_trans_module {
72616 int (*cancel) (struct p9_client *, struct p9_req_t *req);
72617 int (*zc_request)(struct p9_client *, struct p9_req_t *,
72618 char *, char *, int , int, int, int);
72619-};
72620+} __do_const;
72621
72622 void v9fs_register_trans(struct p9_trans_module *m);
72623 void v9fs_unregister_trans(struct p9_trans_module *m);
72624diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
72625index 7588ef4..e62d35f 100644
72626--- a/include/net/bluetooth/l2cap.h
72627+++ b/include/net/bluetooth/l2cap.h
72628@@ -552,7 +552,7 @@ struct l2cap_ops {
72629 void (*defer) (struct l2cap_chan *chan);
72630 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
72631 unsigned long len, int nb);
72632-};
72633+} __do_const;
72634
72635 struct l2cap_conn {
72636 struct hci_conn *hcon;
72637diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
72638index 9e5425b..8136ffc 100644
72639--- a/include/net/caif/cfctrl.h
72640+++ b/include/net/caif/cfctrl.h
72641@@ -52,7 +52,7 @@ struct cfctrl_rsp {
72642 void (*radioset_rsp)(void);
72643 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
72644 struct cflayer *client_layer);
72645-};
72646+} __no_const;
72647
72648 /* Link Setup Parameters for CAIF-Links. */
72649 struct cfctrl_link_param {
72650@@ -101,8 +101,8 @@ struct cfctrl_request_info {
72651 struct cfctrl {
72652 struct cfsrvl serv;
72653 struct cfctrl_rsp res;
72654- atomic_t req_seq_no;
72655- atomic_t rsp_seq_no;
72656+ atomic_unchecked_t req_seq_no;
72657+ atomic_unchecked_t rsp_seq_no;
72658 struct list_head list;
72659 /* Protects from simultaneous access to first_req list */
72660 spinlock_t info_list_lock;
72661diff --git a/include/net/flow.h b/include/net/flow.h
72662index 628e11b..4c475df 100644
72663--- a/include/net/flow.h
72664+++ b/include/net/flow.h
72665@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
72666
72667 extern void flow_cache_flush(void);
72668 extern void flow_cache_flush_deferred(void);
72669-extern atomic_t flow_cache_genid;
72670+extern atomic_unchecked_t flow_cache_genid;
72671
72672 #endif
72673diff --git a/include/net/genetlink.h b/include/net/genetlink.h
72674index bdfbe68..4402ebe 100644
72675--- a/include/net/genetlink.h
72676+++ b/include/net/genetlink.h
72677@@ -118,7 +118,7 @@ struct genl_ops {
72678 struct netlink_callback *cb);
72679 int (*done)(struct netlink_callback *cb);
72680 struct list_head ops_list;
72681-};
72682+} __do_const;
72683
72684 extern int genl_register_family(struct genl_family *family);
72685 extern int genl_register_family_with_ops(struct genl_family *family,
72686diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
72687index e5062c9..48a9a4b 100644
72688--- a/include/net/gro_cells.h
72689+++ b/include/net/gro_cells.h
72690@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
72691 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
72692
72693 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
72694- atomic_long_inc(&dev->rx_dropped);
72695+ atomic_long_inc_unchecked(&dev->rx_dropped);
72696 kfree_skb(skb);
72697 return;
72698 }
72699@@ -73,8 +73,8 @@ static inline int gro_cells_init(struct gro_cells *gcells, struct net_device *de
72700 int i;
72701
72702 gcells->gro_cells_mask = roundup_pow_of_two(netif_get_num_default_rss_queues()) - 1;
72703- gcells->cells = kcalloc(sizeof(struct gro_cell),
72704- gcells->gro_cells_mask + 1,
72705+ gcells->cells = kcalloc(gcells->gro_cells_mask + 1,
72706+ sizeof(struct gro_cell),
72707 GFP_KERNEL);
72708 if (!gcells->cells)
72709 return -ENOMEM;
72710diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
72711index 1832927..ce39aea 100644
72712--- a/include/net/inet_connection_sock.h
72713+++ b/include/net/inet_connection_sock.h
72714@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
72715 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
72716 int (*bind_conflict)(const struct sock *sk,
72717 const struct inet_bind_bucket *tb, bool relax);
72718-};
72719+} __do_const;
72720
72721 /** inet_connection_sock - INET connection oriented sock
72722 *
72723diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
72724index 53f464d..ba76aaa 100644
72725--- a/include/net/inetpeer.h
72726+++ b/include/net/inetpeer.h
72727@@ -47,8 +47,8 @@ struct inet_peer {
72728 */
72729 union {
72730 struct {
72731- atomic_t rid; /* Frag reception counter */
72732- atomic_t ip_id_count; /* IP ID for the next packet */
72733+ atomic_unchecked_t rid; /* Frag reception counter */
72734+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
72735 };
72736 struct rcu_head rcu;
72737 struct inet_peer *gc_next;
72738@@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
72739 more++;
72740 inet_peer_refcheck(p);
72741 do {
72742- old = atomic_read(&p->ip_id_count);
72743+ old = atomic_read_unchecked(&p->ip_id_count);
72744 new = old + more;
72745 if (!new)
72746 new = 1;
72747- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
72748+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
72749 return new;
72750 }
72751
72752diff --git a/include/net/ip.h b/include/net/ip.h
72753index a68f838..74518ab 100644
72754--- a/include/net/ip.h
72755+++ b/include/net/ip.h
72756@@ -202,7 +202,7 @@ extern struct local_ports {
72757 } sysctl_local_ports;
72758 extern void inet_get_local_port_range(int *low, int *high);
72759
72760-extern unsigned long *sysctl_local_reserved_ports;
72761+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
72762 static inline int inet_is_reserved_local_port(int port)
72763 {
72764 return test_bit(port, sysctl_local_reserved_ports);
72765diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
72766index e49db91..76a81de 100644
72767--- a/include/net/ip_fib.h
72768+++ b/include/net/ip_fib.h
72769@@ -167,7 +167,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
72770
72771 #define FIB_RES_SADDR(net, res) \
72772 ((FIB_RES_NH(res).nh_saddr_genid == \
72773- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
72774+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
72775 FIB_RES_NH(res).nh_saddr : \
72776 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
72777 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
72778diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
72779index 68c69d5..bdab192 100644
72780--- a/include/net/ip_vs.h
72781+++ b/include/net/ip_vs.h
72782@@ -599,7 +599,7 @@ struct ip_vs_conn {
72783 struct ip_vs_conn *control; /* Master control connection */
72784 atomic_t n_control; /* Number of controlled ones */
72785 struct ip_vs_dest *dest; /* real server */
72786- atomic_t in_pkts; /* incoming packet counter */
72787+ atomic_unchecked_t in_pkts; /* incoming packet counter */
72788
72789 /* packet transmitter for different forwarding methods. If it
72790 mangles the packet, it must return NF_DROP or better NF_STOLEN,
72791@@ -737,7 +737,7 @@ struct ip_vs_dest {
72792 __be16 port; /* port number of the server */
72793 union nf_inet_addr addr; /* IP address of the server */
72794 volatile unsigned int flags; /* dest status flags */
72795- atomic_t conn_flags; /* flags to copy to conn */
72796+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
72797 atomic_t weight; /* server weight */
72798
72799 atomic_t refcnt; /* reference counter */
72800@@ -980,11 +980,11 @@ struct netns_ipvs {
72801 /* ip_vs_lblc */
72802 int sysctl_lblc_expiration;
72803 struct ctl_table_header *lblc_ctl_header;
72804- struct ctl_table *lblc_ctl_table;
72805+ ctl_table_no_const *lblc_ctl_table;
72806 /* ip_vs_lblcr */
72807 int sysctl_lblcr_expiration;
72808 struct ctl_table_header *lblcr_ctl_header;
72809- struct ctl_table *lblcr_ctl_table;
72810+ ctl_table_no_const *lblcr_ctl_table;
72811 /* ip_vs_est */
72812 struct list_head est_list; /* estimator list */
72813 spinlock_t est_lock;
72814diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
72815index 80ffde3..968b0f4 100644
72816--- a/include/net/irda/ircomm_tty.h
72817+++ b/include/net/irda/ircomm_tty.h
72818@@ -35,6 +35,7 @@
72819 #include <linux/termios.h>
72820 #include <linux/timer.h>
72821 #include <linux/tty.h> /* struct tty_struct */
72822+#include <asm/local.h>
72823
72824 #include <net/irda/irias_object.h>
72825 #include <net/irda/ircomm_core.h>
72826diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
72827index cc7c197..9f2da2a 100644
72828--- a/include/net/iucv/af_iucv.h
72829+++ b/include/net/iucv/af_iucv.h
72830@@ -141,7 +141,7 @@ struct iucv_sock {
72831 struct iucv_sock_list {
72832 struct hlist_head head;
72833 rwlock_t lock;
72834- atomic_t autobind_name;
72835+ atomic_unchecked_t autobind_name;
72836 };
72837
72838 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
72839diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
72840index df83f69..9b640b8 100644
72841--- a/include/net/llc_c_ac.h
72842+++ b/include/net/llc_c_ac.h
72843@@ -87,7 +87,7 @@
72844 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
72845 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
72846
72847-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
72848+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
72849
72850 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
72851 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
72852diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
72853index 6ca3113..f8026dd 100644
72854--- a/include/net/llc_c_ev.h
72855+++ b/include/net/llc_c_ev.h
72856@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
72857 return (struct llc_conn_state_ev *)skb->cb;
72858 }
72859
72860-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
72861-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
72862+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
72863+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
72864
72865 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
72866 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
72867diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
72868index 0e79cfb..f46db31 100644
72869--- a/include/net/llc_c_st.h
72870+++ b/include/net/llc_c_st.h
72871@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
72872 u8 next_state;
72873 llc_conn_ev_qfyr_t *ev_qualifiers;
72874 llc_conn_action_t *ev_actions;
72875-};
72876+} __do_const;
72877
72878 struct llc_conn_state {
72879 u8 current_state;
72880diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
72881index 37a3bbd..55a4241 100644
72882--- a/include/net/llc_s_ac.h
72883+++ b/include/net/llc_s_ac.h
72884@@ -23,7 +23,7 @@
72885 #define SAP_ACT_TEST_IND 9
72886
72887 /* All action functions must look like this */
72888-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
72889+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
72890
72891 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
72892 struct sk_buff *skb);
72893diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
72894index 567c681..cd73ac0 100644
72895--- a/include/net/llc_s_st.h
72896+++ b/include/net/llc_s_st.h
72897@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
72898 llc_sap_ev_t ev;
72899 u8 next_state;
72900 llc_sap_action_t *ev_actions;
72901-};
72902+} __do_const;
72903
72904 struct llc_sap_state {
72905 u8 curr_state;
72906diff --git a/include/net/mac80211.h b/include/net/mac80211.h
72907index ee50c5e..1bc3b1a 100644
72908--- a/include/net/mac80211.h
72909+++ b/include/net/mac80211.h
72910@@ -3996,7 +3996,7 @@ struct rate_control_ops {
72911 void (*add_sta_debugfs)(void *priv, void *priv_sta,
72912 struct dentry *dir);
72913 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
72914-};
72915+} __do_const;
72916
72917 static inline int rate_supported(struct ieee80211_sta *sta,
72918 enum ieee80211_band band,
72919diff --git a/include/net/neighbour.h b/include/net/neighbour.h
72920index 0dab173..1b76af0 100644
72921--- a/include/net/neighbour.h
72922+++ b/include/net/neighbour.h
72923@@ -123,7 +123,7 @@ struct neigh_ops {
72924 void (*error_report)(struct neighbour *, struct sk_buff *);
72925 int (*output)(struct neighbour *, struct sk_buff *);
72926 int (*connected_output)(struct neighbour *, struct sk_buff *);
72927-};
72928+} __do_const;
72929
72930 struct pneigh_entry {
72931 struct pneigh_entry *next;
72932diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
72933index de644bc..dfbcc4c 100644
72934--- a/include/net/net_namespace.h
72935+++ b/include/net/net_namespace.h
72936@@ -115,7 +115,7 @@ struct net {
72937 #endif
72938 struct netns_ipvs *ipvs;
72939 struct sock *diag_nlsk;
72940- atomic_t rt_genid;
72941+ atomic_unchecked_t rt_genid;
72942 };
72943
72944 /*
72945@@ -272,7 +272,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
72946 #define __net_init __init
72947 #define __net_exit __exit_refok
72948 #define __net_initdata __initdata
72949+#ifdef CONSTIFY_PLUGIN
72950 #define __net_initconst __initconst
72951+#else
72952+#define __net_initconst __initdata
72953+#endif
72954 #endif
72955
72956 struct pernet_operations {
72957@@ -282,7 +286,7 @@ struct pernet_operations {
72958 void (*exit_batch)(struct list_head *net_exit_list);
72959 int *id;
72960 size_t size;
72961-};
72962+} __do_const;
72963
72964 /*
72965 * Use these carefully. If you implement a network device and it
72966@@ -330,12 +334,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
72967
72968 static inline int rt_genid(struct net *net)
72969 {
72970- return atomic_read(&net->rt_genid);
72971+ return atomic_read_unchecked(&net->rt_genid);
72972 }
72973
72974 static inline void rt_genid_bump(struct net *net)
72975 {
72976- atomic_inc(&net->rt_genid);
72977+ atomic_inc_unchecked(&net->rt_genid);
72978 }
72979
72980 #endif /* __NET_NET_NAMESPACE_H */
72981diff --git a/include/net/netdma.h b/include/net/netdma.h
72982index 8ba8ce2..99b7fff 100644
72983--- a/include/net/netdma.h
72984+++ b/include/net/netdma.h
72985@@ -24,7 +24,7 @@
72986 #include <linux/dmaengine.h>
72987 #include <linux/skbuff.h>
72988
72989-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
72990+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
72991 struct sk_buff *skb, int offset, struct iovec *to,
72992 size_t len, struct dma_pinned_list *pinned_list);
72993
72994diff --git a/include/net/netlink.h b/include/net/netlink.h
72995index 9690b0f..87aded7 100644
72996--- a/include/net/netlink.h
72997+++ b/include/net/netlink.h
72998@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
72999 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
73000 {
73001 if (mark)
73002- skb_trim(skb, (unsigned char *) mark - skb->data);
73003+ skb_trim(skb, (const unsigned char *) mark - skb->data);
73004 }
73005
73006 /**
73007diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
73008index 923cb20..deae816 100644
73009--- a/include/net/netns/conntrack.h
73010+++ b/include/net/netns/conntrack.h
73011@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
73012 struct nf_proto_net {
73013 #ifdef CONFIG_SYSCTL
73014 struct ctl_table_header *ctl_table_header;
73015- struct ctl_table *ctl_table;
73016+ ctl_table_no_const *ctl_table;
73017 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
73018 struct ctl_table_header *ctl_compat_header;
73019- struct ctl_table *ctl_compat_table;
73020+ ctl_table_no_const *ctl_compat_table;
73021 #endif
73022 #endif
73023 unsigned int users;
73024@@ -58,7 +58,7 @@ struct nf_ip_net {
73025 struct nf_icmp_net icmpv6;
73026 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
73027 struct ctl_table_header *ctl_table_header;
73028- struct ctl_table *ctl_table;
73029+ ctl_table_no_const *ctl_table;
73030 #endif
73031 };
73032
73033diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
73034index 2ae2b83..dbdc85e 100644
73035--- a/include/net/netns/ipv4.h
73036+++ b/include/net/netns/ipv4.h
73037@@ -64,7 +64,7 @@ struct netns_ipv4 {
73038 kgid_t sysctl_ping_group_range[2];
73039 long sysctl_tcp_mem[3];
73040
73041- atomic_t dev_addr_genid;
73042+ atomic_unchecked_t dev_addr_genid;
73043
73044 #ifdef CONFIG_IP_MROUTE
73045 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
73046diff --git a/include/net/protocol.h b/include/net/protocol.h
73047index 047c047..b9dad15 100644
73048--- a/include/net/protocol.h
73049+++ b/include/net/protocol.h
73050@@ -44,7 +44,7 @@ struct net_protocol {
73051 void (*err_handler)(struct sk_buff *skb, u32 info);
73052 unsigned int no_policy:1,
73053 netns_ok:1;
73054-};
73055+} __do_const;
73056
73057 #if IS_ENABLED(CONFIG_IPV6)
73058 struct inet6_protocol {
73059@@ -57,7 +57,7 @@ struct inet6_protocol {
73060 u8 type, u8 code, int offset,
73061 __be32 info);
73062 unsigned int flags; /* INET6_PROTO_xxx */
73063-};
73064+} __do_const;
73065
73066 #define INET6_PROTO_NOPOLICY 0x1
73067 #define INET6_PROTO_FINAL 0x2
73068diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
73069index 5a15fab..d799ea7 100644
73070--- a/include/net/rtnetlink.h
73071+++ b/include/net/rtnetlink.h
73072@@ -81,7 +81,7 @@ struct rtnl_link_ops {
73073 const struct net_device *dev);
73074 unsigned int (*get_num_tx_queues)(void);
73075 unsigned int (*get_num_rx_queues)(void);
73076-};
73077+} __do_const;
73078
73079 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
73080 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
73081diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
73082index 7fdf298..197e9f7 100644
73083--- a/include/net/sctp/sctp.h
73084+++ b/include/net/sctp/sctp.h
73085@@ -330,9 +330,9 @@ do { \
73086
73087 #else /* SCTP_DEBUG */
73088
73089-#define SCTP_DEBUG_PRINTK(whatever...)
73090-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
73091-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
73092+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
73093+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
73094+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
73095 #define SCTP_ENABLE_DEBUG
73096 #define SCTP_DISABLE_DEBUG
73097 #define SCTP_ASSERT(expr, str, func)
73098diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
73099index 2a82d13..62a31c2 100644
73100--- a/include/net/sctp/sm.h
73101+++ b/include/net/sctp/sm.h
73102@@ -87,7 +87,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
73103 typedef struct {
73104 sctp_state_fn_t *fn;
73105 const char *name;
73106-} sctp_sm_table_entry_t;
73107+} __do_const sctp_sm_table_entry_t;
73108
73109 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
73110 * currently in use.
73111@@ -299,7 +299,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
73112 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
73113
73114 /* Extern declarations for major data structures. */
73115-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
73116+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
73117
73118
73119 /* Get the size of a DATA chunk payload. */
73120diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
73121index fdeb85a..1329d95 100644
73122--- a/include/net/sctp/structs.h
73123+++ b/include/net/sctp/structs.h
73124@@ -517,7 +517,7 @@ struct sctp_pf {
73125 struct sctp_association *asoc);
73126 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
73127 struct sctp_af *af;
73128-};
73129+} __do_const;
73130
73131
73132 /* Structure to track chunk fragments that have been acked, but peer
73133diff --git a/include/net/sock.h b/include/net/sock.h
73134index 25afaa0..8bb0070 100644
73135--- a/include/net/sock.h
73136+++ b/include/net/sock.h
73137@@ -322,7 +322,7 @@ struct sock {
73138 #ifdef CONFIG_RPS
73139 __u32 sk_rxhash;
73140 #endif
73141- atomic_t sk_drops;
73142+ atomic_unchecked_t sk_drops;
73143 int sk_rcvbuf;
73144
73145 struct sk_filter __rcu *sk_filter;
73146@@ -1781,7 +1781,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
73147 }
73148
73149 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
73150- char __user *from, char *to,
73151+ char __user *from, unsigned char *to,
73152 int copy, int offset)
73153 {
73154 if (skb->ip_summed == CHECKSUM_NONE) {
73155@@ -2040,7 +2040,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
73156 }
73157 }
73158
73159-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
73160+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
73161
73162 /**
73163 * sk_page_frag - return an appropriate page_frag
73164diff --git a/include/net/tcp.h b/include/net/tcp.h
73165index aed42c7..43890c6 100644
73166--- a/include/net/tcp.h
73167+++ b/include/net/tcp.h
73168@@ -530,7 +530,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
73169 extern void tcp_xmit_retransmit_queue(struct sock *);
73170 extern void tcp_simple_retransmit(struct sock *);
73171 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
73172-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
73173+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
73174
73175 extern void tcp_send_probe0(struct sock *);
73176 extern void tcp_send_partial(struct sock *);
73177@@ -701,8 +701,8 @@ struct tcp_skb_cb {
73178 struct inet6_skb_parm h6;
73179 #endif
73180 } header; /* For incoming frames */
73181- __u32 seq; /* Starting sequence number */
73182- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
73183+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
73184+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
73185 __u32 when; /* used to compute rtt's */
73186 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
73187
73188@@ -716,7 +716,7 @@ struct tcp_skb_cb {
73189
73190 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
73191 /* 1 byte hole */
73192- __u32 ack_seq; /* Sequence number ACK'd */
73193+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
73194 };
73195
73196 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
73197diff --git a/include/net/xfrm.h b/include/net/xfrm.h
73198index 63445ed..d6fc34f 100644
73199--- a/include/net/xfrm.h
73200+++ b/include/net/xfrm.h
73201@@ -304,7 +304,7 @@ struct xfrm_policy_afinfo {
73202 struct net_device *dev,
73203 const struct flowi *fl);
73204 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
73205-};
73206+} __do_const;
73207
73208 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
73209 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
73210@@ -340,7 +340,7 @@ struct xfrm_state_afinfo {
73211 struct sk_buff *skb);
73212 int (*transport_finish)(struct sk_buff *skb,
73213 int async);
73214-};
73215+} __do_const;
73216
73217 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
73218 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
73219@@ -423,7 +423,7 @@ struct xfrm_mode {
73220 struct module *owner;
73221 unsigned int encap;
73222 int flags;
73223-};
73224+} __do_const;
73225
73226 /* Flags for xfrm_mode. */
73227 enum {
73228@@ -514,7 +514,7 @@ struct xfrm_policy {
73229 struct timer_list timer;
73230
73231 struct flow_cache_object flo;
73232- atomic_t genid;
73233+ atomic_unchecked_t genid;
73234 u32 priority;
73235 u32 index;
73236 struct xfrm_mark mark;
73237diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
73238index 1a046b1..ee0bef0 100644
73239--- a/include/rdma/iw_cm.h
73240+++ b/include/rdma/iw_cm.h
73241@@ -122,7 +122,7 @@ struct iw_cm_verbs {
73242 int backlog);
73243
73244 int (*destroy_listen)(struct iw_cm_id *cm_id);
73245-};
73246+} __no_const;
73247
73248 /**
73249 * iw_create_cm_id - Create an IW CM identifier.
73250diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
73251index 399162b..b337f1a 100644
73252--- a/include/scsi/libfc.h
73253+++ b/include/scsi/libfc.h
73254@@ -762,6 +762,7 @@ struct libfc_function_template {
73255 */
73256 void (*disc_stop_final) (struct fc_lport *);
73257 };
73258+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
73259
73260 /**
73261 * struct fc_disc - Discovery context
73262@@ -866,7 +867,7 @@ struct fc_lport {
73263 struct fc_vport *vport;
73264
73265 /* Operational Information */
73266- struct libfc_function_template tt;
73267+ libfc_function_template_no_const tt;
73268 u8 link_up;
73269 u8 qfull;
73270 enum fc_lport_state state;
73271diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
73272index e65c62e..aa2e5a2 100644
73273--- a/include/scsi/scsi_device.h
73274+++ b/include/scsi/scsi_device.h
73275@@ -170,9 +170,9 @@ struct scsi_device {
73276 unsigned int max_device_blocked; /* what device_blocked counts down from */
73277 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
73278
73279- atomic_t iorequest_cnt;
73280- atomic_t iodone_cnt;
73281- atomic_t ioerr_cnt;
73282+ atomic_unchecked_t iorequest_cnt;
73283+ atomic_unchecked_t iodone_cnt;
73284+ atomic_unchecked_t ioerr_cnt;
73285
73286 struct device sdev_gendev,
73287 sdev_dev;
73288diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
73289index b797e8f..8e2c3aa 100644
73290--- a/include/scsi/scsi_transport_fc.h
73291+++ b/include/scsi/scsi_transport_fc.h
73292@@ -751,7 +751,8 @@ struct fc_function_template {
73293 unsigned long show_host_system_hostname:1;
73294
73295 unsigned long disable_target_scan:1;
73296-};
73297+} __do_const;
73298+typedef struct fc_function_template __no_const fc_function_template_no_const;
73299
73300
73301 /**
73302diff --git a/include/sound/soc.h b/include/sound/soc.h
73303index bc56738..a4be132 100644
73304--- a/include/sound/soc.h
73305+++ b/include/sound/soc.h
73306@@ -771,7 +771,7 @@ struct snd_soc_codec_driver {
73307 /* probe ordering - for components with runtime dependencies */
73308 int probe_order;
73309 int remove_order;
73310-};
73311+} __do_const;
73312
73313 /* SoC platform interface */
73314 struct snd_soc_platform_driver {
73315@@ -817,7 +817,7 @@ struct snd_soc_platform_driver {
73316 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
73317 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
73318 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
73319-};
73320+} __do_const;
73321
73322 struct snd_soc_platform {
73323 const char *name;
73324diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
73325index 663e34a..91b306a 100644
73326--- a/include/target/target_core_base.h
73327+++ b/include/target/target_core_base.h
73328@@ -654,7 +654,7 @@ struct se_device {
73329 spinlock_t stats_lock;
73330 /* Active commands on this virtual SE device */
73331 atomic_t simple_cmds;
73332- atomic_t dev_ordered_id;
73333+ atomic_unchecked_t dev_ordered_id;
73334 atomic_t dev_ordered_sync;
73335 atomic_t dev_qf_count;
73336 int export_count;
73337diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
73338new file mode 100644
73339index 0000000..fb634b7
73340--- /dev/null
73341+++ b/include/trace/events/fs.h
73342@@ -0,0 +1,53 @@
73343+#undef TRACE_SYSTEM
73344+#define TRACE_SYSTEM fs
73345+
73346+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
73347+#define _TRACE_FS_H
73348+
73349+#include <linux/fs.h>
73350+#include <linux/tracepoint.h>
73351+
73352+TRACE_EVENT(do_sys_open,
73353+
73354+ TP_PROTO(const char *filename, int flags, int mode),
73355+
73356+ TP_ARGS(filename, flags, mode),
73357+
73358+ TP_STRUCT__entry(
73359+ __string( filename, filename )
73360+ __field( int, flags )
73361+ __field( int, mode )
73362+ ),
73363+
73364+ TP_fast_assign(
73365+ __assign_str(filename, filename);
73366+ __entry->flags = flags;
73367+ __entry->mode = mode;
73368+ ),
73369+
73370+ TP_printk("\"%s\" %x %o",
73371+ __get_str(filename), __entry->flags, __entry->mode)
73372+);
73373+
73374+TRACE_EVENT(open_exec,
73375+
73376+ TP_PROTO(const char *filename),
73377+
73378+ TP_ARGS(filename),
73379+
73380+ TP_STRUCT__entry(
73381+ __string( filename, filename )
73382+ ),
73383+
73384+ TP_fast_assign(
73385+ __assign_str(filename, filename);
73386+ ),
73387+
73388+ TP_printk("\"%s\"",
73389+ __get_str(filename))
73390+);
73391+
73392+#endif /* _TRACE_FS_H */
73393+
73394+/* This part must be outside protection */
73395+#include <trace/define_trace.h>
73396diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
73397index 1c09820..7f5ec79 100644
73398--- a/include/trace/events/irq.h
73399+++ b/include/trace/events/irq.h
73400@@ -36,7 +36,7 @@ struct softirq_action;
73401 */
73402 TRACE_EVENT(irq_handler_entry,
73403
73404- TP_PROTO(int irq, struct irqaction *action),
73405+ TP_PROTO(int irq, const struct irqaction *action),
73406
73407 TP_ARGS(irq, action),
73408
73409@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
73410 */
73411 TRACE_EVENT(irq_handler_exit,
73412
73413- TP_PROTO(int irq, struct irqaction *action, int ret),
73414+ TP_PROTO(int irq, const struct irqaction *action, int ret),
73415
73416 TP_ARGS(irq, action, ret),
73417
73418diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
73419index 7caf44c..23c6f27 100644
73420--- a/include/uapi/linux/a.out.h
73421+++ b/include/uapi/linux/a.out.h
73422@@ -39,6 +39,14 @@ enum machine_type {
73423 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
73424 };
73425
73426+/* Constants for the N_FLAGS field */
73427+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
73428+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
73429+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
73430+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
73431+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
73432+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
73433+
73434 #if !defined (N_MAGIC)
73435 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
73436 #endif
73437diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
73438index d876736..ccce5c0 100644
73439--- a/include/uapi/linux/byteorder/little_endian.h
73440+++ b/include/uapi/linux/byteorder/little_endian.h
73441@@ -42,51 +42,51 @@
73442
73443 static inline __le64 __cpu_to_le64p(const __u64 *p)
73444 {
73445- return (__force __le64)*p;
73446+ return (__force const __le64)*p;
73447 }
73448-static inline __u64 __le64_to_cpup(const __le64 *p)
73449+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
73450 {
73451- return (__force __u64)*p;
73452+ return (__force const __u64)*p;
73453 }
73454 static inline __le32 __cpu_to_le32p(const __u32 *p)
73455 {
73456- return (__force __le32)*p;
73457+ return (__force const __le32)*p;
73458 }
73459 static inline __u32 __le32_to_cpup(const __le32 *p)
73460 {
73461- return (__force __u32)*p;
73462+ return (__force const __u32)*p;
73463 }
73464 static inline __le16 __cpu_to_le16p(const __u16 *p)
73465 {
73466- return (__force __le16)*p;
73467+ return (__force const __le16)*p;
73468 }
73469 static inline __u16 __le16_to_cpup(const __le16 *p)
73470 {
73471- return (__force __u16)*p;
73472+ return (__force const __u16)*p;
73473 }
73474 static inline __be64 __cpu_to_be64p(const __u64 *p)
73475 {
73476- return (__force __be64)__swab64p(p);
73477+ return (__force const __be64)__swab64p(p);
73478 }
73479 static inline __u64 __be64_to_cpup(const __be64 *p)
73480 {
73481- return __swab64p((__u64 *)p);
73482+ return __swab64p((const __u64 *)p);
73483 }
73484 static inline __be32 __cpu_to_be32p(const __u32 *p)
73485 {
73486- return (__force __be32)__swab32p(p);
73487+ return (__force const __be32)__swab32p(p);
73488 }
73489-static inline __u32 __be32_to_cpup(const __be32 *p)
73490+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
73491 {
73492- return __swab32p((__u32 *)p);
73493+ return __swab32p((const __u32 *)p);
73494 }
73495 static inline __be16 __cpu_to_be16p(const __u16 *p)
73496 {
73497- return (__force __be16)__swab16p(p);
73498+ return (__force const __be16)__swab16p(p);
73499 }
73500 static inline __u16 __be16_to_cpup(const __be16 *p)
73501 {
73502- return __swab16p((__u16 *)p);
73503+ return __swab16p((const __u16 *)p);
73504 }
73505 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
73506 #define __le64_to_cpus(x) do { (void)(x); } while (0)
73507diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
73508index 126a817..d522bd1 100644
73509--- a/include/uapi/linux/elf.h
73510+++ b/include/uapi/linux/elf.h
73511@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
73512 #define PT_GNU_EH_FRAME 0x6474e550
73513
73514 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
73515+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
73516+
73517+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
73518+
73519+/* Constants for the e_flags field */
73520+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
73521+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
73522+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
73523+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
73524+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
73525+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
73526
73527 /*
73528 * Extended Numbering
73529@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
73530 #define DT_DEBUG 21
73531 #define DT_TEXTREL 22
73532 #define DT_JMPREL 23
73533+#define DT_FLAGS 30
73534+ #define DF_TEXTREL 0x00000004
73535 #define DT_ENCODING 32
73536 #define OLD_DT_LOOS 0x60000000
73537 #define DT_LOOS 0x6000000d
73538@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
73539 #define PF_W 0x2
73540 #define PF_X 0x1
73541
73542+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
73543+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
73544+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
73545+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
73546+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
73547+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
73548+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
73549+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
73550+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
73551+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
73552+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
73553+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
73554+
73555 typedef struct elf32_phdr{
73556 Elf32_Word p_type;
73557 Elf32_Off p_offset;
73558@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
73559 #define EI_OSABI 7
73560 #define EI_PAD 8
73561
73562+#define EI_PAX 14
73563+
73564 #define ELFMAG0 0x7f /* EI_MAG */
73565 #define ELFMAG1 'E'
73566 #define ELFMAG2 'L'
73567diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
73568index aa169c4..6a2771d 100644
73569--- a/include/uapi/linux/personality.h
73570+++ b/include/uapi/linux/personality.h
73571@@ -30,6 +30,7 @@ enum {
73572 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
73573 ADDR_NO_RANDOMIZE | \
73574 ADDR_COMPAT_LAYOUT | \
73575+ ADDR_LIMIT_3GB | \
73576 MMAP_PAGE_ZERO)
73577
73578 /*
73579diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
73580index 7530e74..e714828 100644
73581--- a/include/uapi/linux/screen_info.h
73582+++ b/include/uapi/linux/screen_info.h
73583@@ -43,7 +43,8 @@ struct screen_info {
73584 __u16 pages; /* 0x32 */
73585 __u16 vesa_attributes; /* 0x34 */
73586 __u32 capabilities; /* 0x36 */
73587- __u8 _reserved[6]; /* 0x3a */
73588+ __u16 vesapm_size; /* 0x3a */
73589+ __u8 _reserved[4]; /* 0x3c */
73590 } __attribute__((packed));
73591
73592 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
73593diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
73594index 0e011eb..82681b1 100644
73595--- a/include/uapi/linux/swab.h
73596+++ b/include/uapi/linux/swab.h
73597@@ -43,7 +43,7 @@
73598 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
73599 */
73600
73601-static inline __attribute_const__ __u16 __fswab16(__u16 val)
73602+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
73603 {
73604 #ifdef __HAVE_BUILTIN_BSWAP16__
73605 return __builtin_bswap16(val);
73606@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
73607 #endif
73608 }
73609
73610-static inline __attribute_const__ __u32 __fswab32(__u32 val)
73611+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
73612 {
73613 #ifdef __HAVE_BUILTIN_BSWAP32__
73614 return __builtin_bswap32(val);
73615@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
73616 #endif
73617 }
73618
73619-static inline __attribute_const__ __u64 __fswab64(__u64 val)
73620+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
73621 {
73622 #ifdef __HAVE_BUILTIN_BSWAP64__
73623 return __builtin_bswap64(val);
73624diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
73625index 6d67213..8dab561 100644
73626--- a/include/uapi/linux/sysctl.h
73627+++ b/include/uapi/linux/sysctl.h
73628@@ -155,7 +155,11 @@ enum
73629 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
73630 };
73631
73632-
73633+#ifdef CONFIG_PAX_SOFTMODE
73634+enum {
73635+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
73636+};
73637+#endif
73638
73639 /* CTL_VM names: */
73640 enum
73641diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
73642index 26607bd..588b65f 100644
73643--- a/include/uapi/linux/xattr.h
73644+++ b/include/uapi/linux/xattr.h
73645@@ -60,5 +60,9 @@
73646 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
73647 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
73648
73649+/* User namespace */
73650+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
73651+#define XATTR_PAX_FLAGS_SUFFIX "flags"
73652+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
73653
73654 #endif /* _UAPI_LINUX_XATTR_H */
73655diff --git a/include/video/udlfb.h b/include/video/udlfb.h
73656index f9466fa..f4e2b81 100644
73657--- a/include/video/udlfb.h
73658+++ b/include/video/udlfb.h
73659@@ -53,10 +53,10 @@ struct dlfb_data {
73660 u32 pseudo_palette[256];
73661 int blank_mode; /*one of FB_BLANK_ */
73662 /* blit-only rendering path metrics, exposed through sysfs */
73663- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
73664- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
73665- atomic_t bytes_sent; /* to usb, after compression including overhead */
73666- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
73667+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
73668+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
73669+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
73670+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
73671 };
73672
73673 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
73674diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
73675index 0993a22..32ba2fe 100644
73676--- a/include/video/uvesafb.h
73677+++ b/include/video/uvesafb.h
73678@@ -177,6 +177,7 @@ struct uvesafb_par {
73679 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
73680 u8 pmi_setpal; /* PMI for palette changes */
73681 u16 *pmi_base; /* protected mode interface location */
73682+ u8 *pmi_code; /* protected mode code location */
73683 void *pmi_start;
73684 void *pmi_pal;
73685 u8 *vbe_state_orig; /*
73686diff --git a/init/Kconfig b/init/Kconfig
73687index be8b7f5..1eeca9b 100644
73688--- a/init/Kconfig
73689+++ b/init/Kconfig
73690@@ -990,6 +990,7 @@ endif # CGROUPS
73691
73692 config CHECKPOINT_RESTORE
73693 bool "Checkpoint/restore support" if EXPERT
73694+ depends on !GRKERNSEC
73695 default n
73696 help
73697 Enables additional kernel features in a sake of checkpoint/restore.
73698@@ -1468,7 +1469,7 @@ config SLUB_DEBUG
73699
73700 config COMPAT_BRK
73701 bool "Disable heap randomization"
73702- default y
73703+ default n
73704 help
73705 Randomizing heap placement makes heap exploits harder, but it
73706 also breaks ancient binaries (including anything libc5 based).
73707@@ -1711,7 +1712,7 @@ config INIT_ALL_POSSIBLE
73708 config STOP_MACHINE
73709 bool
73710 default y
73711- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
73712+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
73713 help
73714 Need stop_machine() primitive.
73715
73716diff --git a/init/Makefile b/init/Makefile
73717index 7bc47ee..6da2dc7 100644
73718--- a/init/Makefile
73719+++ b/init/Makefile
73720@@ -2,6 +2,9 @@
73721 # Makefile for the linux kernel.
73722 #
73723
73724+ccflags-y := $(GCC_PLUGINS_CFLAGS)
73725+asflags-y := $(GCC_PLUGINS_AFLAGS)
73726+
73727 obj-y := main.o version.o mounts.o
73728 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
73729 obj-y += noinitramfs.o
73730diff --git a/init/do_mounts.c b/init/do_mounts.c
73731index 1d1b634..a1c810f 100644
73732--- a/init/do_mounts.c
73733+++ b/init/do_mounts.c
73734@@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
73735 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
73736 {
73737 struct super_block *s;
73738- int err = sys_mount(name, "/root", fs, flags, data);
73739+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
73740 if (err)
73741 return err;
73742
73743- sys_chdir("/root");
73744+ sys_chdir((const char __force_user *)"/root");
73745 s = current->fs->pwd.dentry->d_sb;
73746 ROOT_DEV = s->s_dev;
73747 printk(KERN_INFO
73748@@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
73749 va_start(args, fmt);
73750 vsprintf(buf, fmt, args);
73751 va_end(args);
73752- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
73753+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
73754 if (fd >= 0) {
73755 sys_ioctl(fd, FDEJECT, 0);
73756 sys_close(fd);
73757 }
73758 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
73759- fd = sys_open("/dev/console", O_RDWR, 0);
73760+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
73761 if (fd >= 0) {
73762 sys_ioctl(fd, TCGETS, (long)&termios);
73763 termios.c_lflag &= ~ICANON;
73764 sys_ioctl(fd, TCSETSF, (long)&termios);
73765- sys_read(fd, &c, 1);
73766+ sys_read(fd, (char __user *)&c, 1);
73767 termios.c_lflag |= ICANON;
73768 sys_ioctl(fd, TCSETSF, (long)&termios);
73769 sys_close(fd);
73770@@ -585,6 +585,6 @@ void __init prepare_namespace(void)
73771 mount_root();
73772 out:
73773 devtmpfs_mount("dev");
73774- sys_mount(".", "/", NULL, MS_MOVE, NULL);
73775- sys_chroot(".");
73776+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
73777+ sys_chroot((const char __force_user *)".");
73778 }
73779diff --git a/init/do_mounts.h b/init/do_mounts.h
73780index f5b978a..69dbfe8 100644
73781--- a/init/do_mounts.h
73782+++ b/init/do_mounts.h
73783@@ -15,15 +15,15 @@ extern int root_mountflags;
73784
73785 static inline int create_dev(char *name, dev_t dev)
73786 {
73787- sys_unlink(name);
73788- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
73789+ sys_unlink((char __force_user *)name);
73790+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
73791 }
73792
73793 #if BITS_PER_LONG == 32
73794 static inline u32 bstat(char *name)
73795 {
73796 struct stat64 stat;
73797- if (sys_stat64(name, &stat) != 0)
73798+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
73799 return 0;
73800 if (!S_ISBLK(stat.st_mode))
73801 return 0;
73802@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
73803 static inline u32 bstat(char *name)
73804 {
73805 struct stat stat;
73806- if (sys_newstat(name, &stat) != 0)
73807+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
73808 return 0;
73809 if (!S_ISBLK(stat.st_mode))
73810 return 0;
73811diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
73812index f9acf71..1e19144 100644
73813--- a/init/do_mounts_initrd.c
73814+++ b/init/do_mounts_initrd.c
73815@@ -58,8 +58,8 @@ static void __init handle_initrd(void)
73816 create_dev("/dev/root.old", Root_RAM0);
73817 /* mount initrd on rootfs' /root */
73818 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
73819- sys_mkdir("/old", 0700);
73820- sys_chdir("/old");
73821+ sys_mkdir((const char __force_user *)"/old", 0700);
73822+ sys_chdir((const char __force_user *)"/old");
73823
73824 /*
73825 * In case that a resume from disk is carried out by linuxrc or one of
73826@@ -73,31 +73,31 @@ static void __init handle_initrd(void)
73827 current->flags &= ~PF_FREEZER_SKIP;
73828
73829 /* move initrd to rootfs' /old */
73830- sys_mount("..", ".", NULL, MS_MOVE, NULL);
73831+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
73832 /* switch root and cwd back to / of rootfs */
73833- sys_chroot("..");
73834+ sys_chroot((const char __force_user *)"..");
73835
73836 if (new_decode_dev(real_root_dev) == Root_RAM0) {
73837- sys_chdir("/old");
73838+ sys_chdir((const char __force_user *)"/old");
73839 return;
73840 }
73841
73842- sys_chdir("/");
73843+ sys_chdir((const char __force_user *)"/");
73844 ROOT_DEV = new_decode_dev(real_root_dev);
73845 mount_root();
73846
73847 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
73848- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
73849+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
73850 if (!error)
73851 printk("okay\n");
73852 else {
73853- int fd = sys_open("/dev/root.old", O_RDWR, 0);
73854+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
73855 if (error == -ENOENT)
73856 printk("/initrd does not exist. Ignored.\n");
73857 else
73858 printk("failed\n");
73859 printk(KERN_NOTICE "Unmounting old root\n");
73860- sys_umount("/old", MNT_DETACH);
73861+ sys_umount((char __force_user *)"/old", MNT_DETACH);
73862 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
73863 if (fd < 0) {
73864 error = fd;
73865@@ -120,11 +120,11 @@ int __init initrd_load(void)
73866 * mounted in the normal path.
73867 */
73868 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
73869- sys_unlink("/initrd.image");
73870+ sys_unlink((const char __force_user *)"/initrd.image");
73871 handle_initrd();
73872 return 1;
73873 }
73874 }
73875- sys_unlink("/initrd.image");
73876+ sys_unlink((const char __force_user *)"/initrd.image");
73877 return 0;
73878 }
73879diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
73880index 8cb6db5..d729f50 100644
73881--- a/init/do_mounts_md.c
73882+++ b/init/do_mounts_md.c
73883@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
73884 partitioned ? "_d" : "", minor,
73885 md_setup_args[ent].device_names);
73886
73887- fd = sys_open(name, 0, 0);
73888+ fd = sys_open((char __force_user *)name, 0, 0);
73889 if (fd < 0) {
73890 printk(KERN_ERR "md: open failed - cannot start "
73891 "array %s\n", name);
73892@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
73893 * array without it
73894 */
73895 sys_close(fd);
73896- fd = sys_open(name, 0, 0);
73897+ fd = sys_open((char __force_user *)name, 0, 0);
73898 sys_ioctl(fd, BLKRRPART, 0);
73899 }
73900 sys_close(fd);
73901@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
73902
73903 wait_for_device_probe();
73904
73905- fd = sys_open("/dev/md0", 0, 0);
73906+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
73907 if (fd >= 0) {
73908 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
73909 sys_close(fd);
73910diff --git a/init/init_task.c b/init/init_task.c
73911index 8b2f399..f0797c9 100644
73912--- a/init/init_task.c
73913+++ b/init/init_task.c
73914@@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
73915 * Initial thread structure. Alignment of this is handled by a special
73916 * linker map entry.
73917 */
73918+#ifdef CONFIG_X86
73919+union thread_union init_thread_union __init_task_data;
73920+#else
73921 union thread_union init_thread_union __init_task_data =
73922 { INIT_THREAD_INFO(init_task) };
73923+#endif
73924diff --git a/init/initramfs.c b/init/initramfs.c
73925index 84c6bf1..8899338 100644
73926--- a/init/initramfs.c
73927+++ b/init/initramfs.c
73928@@ -84,7 +84,7 @@ static void __init free_hash(void)
73929 }
73930 }
73931
73932-static long __init do_utime(char *filename, time_t mtime)
73933+static long __init do_utime(char __force_user *filename, time_t mtime)
73934 {
73935 struct timespec t[2];
73936
73937@@ -119,7 +119,7 @@ static void __init dir_utime(void)
73938 struct dir_entry *de, *tmp;
73939 list_for_each_entry_safe(de, tmp, &dir_list, list) {
73940 list_del(&de->list);
73941- do_utime(de->name, de->mtime);
73942+ do_utime((char __force_user *)de->name, de->mtime);
73943 kfree(de->name);
73944 kfree(de);
73945 }
73946@@ -281,7 +281,7 @@ static int __init maybe_link(void)
73947 if (nlink >= 2) {
73948 char *old = find_link(major, minor, ino, mode, collected);
73949 if (old)
73950- return (sys_link(old, collected) < 0) ? -1 : 1;
73951+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
73952 }
73953 return 0;
73954 }
73955@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
73956 {
73957 struct stat st;
73958
73959- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
73960+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
73961 if (S_ISDIR(st.st_mode))
73962- sys_rmdir(path);
73963+ sys_rmdir((char __force_user *)path);
73964 else
73965- sys_unlink(path);
73966+ sys_unlink((char __force_user *)path);
73967 }
73968 }
73969
73970@@ -315,7 +315,7 @@ static int __init do_name(void)
73971 int openflags = O_WRONLY|O_CREAT;
73972 if (ml != 1)
73973 openflags |= O_TRUNC;
73974- wfd = sys_open(collected, openflags, mode);
73975+ wfd = sys_open((char __force_user *)collected, openflags, mode);
73976
73977 if (wfd >= 0) {
73978 sys_fchown(wfd, uid, gid);
73979@@ -327,17 +327,17 @@ static int __init do_name(void)
73980 }
73981 }
73982 } else if (S_ISDIR(mode)) {
73983- sys_mkdir(collected, mode);
73984- sys_chown(collected, uid, gid);
73985- sys_chmod(collected, mode);
73986+ sys_mkdir((char __force_user *)collected, mode);
73987+ sys_chown((char __force_user *)collected, uid, gid);
73988+ sys_chmod((char __force_user *)collected, mode);
73989 dir_add(collected, mtime);
73990 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
73991 S_ISFIFO(mode) || S_ISSOCK(mode)) {
73992 if (maybe_link() == 0) {
73993- sys_mknod(collected, mode, rdev);
73994- sys_chown(collected, uid, gid);
73995- sys_chmod(collected, mode);
73996- do_utime(collected, mtime);
73997+ sys_mknod((char __force_user *)collected, mode, rdev);
73998+ sys_chown((char __force_user *)collected, uid, gid);
73999+ sys_chmod((char __force_user *)collected, mode);
74000+ do_utime((char __force_user *)collected, mtime);
74001 }
74002 }
74003 return 0;
74004@@ -346,15 +346,15 @@ static int __init do_name(void)
74005 static int __init do_copy(void)
74006 {
74007 if (count >= body_len) {
74008- sys_write(wfd, victim, body_len);
74009+ sys_write(wfd, (char __force_user *)victim, body_len);
74010 sys_close(wfd);
74011- do_utime(vcollected, mtime);
74012+ do_utime((char __force_user *)vcollected, mtime);
74013 kfree(vcollected);
74014 eat(body_len);
74015 state = SkipIt;
74016 return 0;
74017 } else {
74018- sys_write(wfd, victim, count);
74019+ sys_write(wfd, (char __force_user *)victim, count);
74020 body_len -= count;
74021 eat(count);
74022 return 1;
74023@@ -365,9 +365,9 @@ static int __init do_symlink(void)
74024 {
74025 collected[N_ALIGN(name_len) + body_len] = '\0';
74026 clean_path(collected, 0);
74027- sys_symlink(collected + N_ALIGN(name_len), collected);
74028- sys_lchown(collected, uid, gid);
74029- do_utime(collected, mtime);
74030+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
74031+ sys_lchown((char __force_user *)collected, uid, gid);
74032+ do_utime((char __force_user *)collected, mtime);
74033 state = SkipIt;
74034 next_state = Reset;
74035 return 0;
74036diff --git a/init/main.c b/init/main.c
74037index cee4b5c..360e10a 100644
74038--- a/init/main.c
74039+++ b/init/main.c
74040@@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
74041 extern void tc_init(void);
74042 #endif
74043
74044+extern void grsecurity_init(void);
74045+
74046 /*
74047 * Debug helper: via this flag we know that we are in 'early bootup code'
74048 * where only the boot processor is running with IRQ disabled. This means
74049@@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
74050
74051 __setup("reset_devices", set_reset_devices);
74052
74053+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
74054+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
74055+static int __init setup_grsec_proc_gid(char *str)
74056+{
74057+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
74058+ return 1;
74059+}
74060+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
74061+#endif
74062+
74063+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
74064+extern char pax_enter_kernel_user[];
74065+extern char pax_exit_kernel_user[];
74066+extern pgdval_t clone_pgd_mask;
74067+#endif
74068+
74069+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
74070+static int __init setup_pax_nouderef(char *str)
74071+{
74072+#ifdef CONFIG_X86_32
74073+ unsigned int cpu;
74074+ struct desc_struct *gdt;
74075+
74076+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
74077+ gdt = get_cpu_gdt_table(cpu);
74078+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
74079+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
74080+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
74081+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
74082+ }
74083+ loadsegment(ds, __KERNEL_DS);
74084+ loadsegment(es, __KERNEL_DS);
74085+ loadsegment(ss, __KERNEL_DS);
74086+#else
74087+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
74088+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
74089+ clone_pgd_mask = ~(pgdval_t)0UL;
74090+#endif
74091+
74092+ return 0;
74093+}
74094+early_param("pax_nouderef", setup_pax_nouderef);
74095+#endif
74096+
74097+#ifdef CONFIG_PAX_SOFTMODE
74098+int pax_softmode;
74099+
74100+static int __init setup_pax_softmode(char *str)
74101+{
74102+ get_option(&str, &pax_softmode);
74103+ return 1;
74104+}
74105+__setup("pax_softmode=", setup_pax_softmode);
74106+#endif
74107+
74108 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
74109 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
74110 static const char *panic_later, *panic_param;
74111@@ -681,6 +738,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
74112 {
74113 int count = preempt_count();
74114 int ret;
74115+ const char *msg1 = "", *msg2 = "";
74116
74117 if (initcall_debug)
74118 ret = do_one_initcall_debug(fn);
74119@@ -693,15 +751,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
74120 sprintf(msgbuf, "error code %d ", ret);
74121
74122 if (preempt_count() != count) {
74123- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
74124+ msg1 = " preemption imbalance";
74125 preempt_count() = count;
74126 }
74127 if (irqs_disabled()) {
74128- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
74129+ msg2 = " disabled interrupts";
74130 local_irq_enable();
74131 }
74132- if (msgbuf[0]) {
74133- printk("initcall %pF returned with %s\n", fn, msgbuf);
74134+ if (msgbuf[0] || *msg1 || *msg2) {
74135+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
74136 }
74137
74138 return ret;
74139@@ -755,8 +813,14 @@ static void __init do_initcall_level(int level)
74140 level, level,
74141 &repair_env_string);
74142
74143- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
74144+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
74145 do_one_initcall(*fn);
74146+
74147+#ifdef LATENT_ENTROPY_PLUGIN
74148+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
74149+#endif
74150+
74151+ }
74152 }
74153
74154 static void __init do_initcalls(void)
74155@@ -790,8 +854,14 @@ static void __init do_pre_smp_initcalls(void)
74156 {
74157 initcall_t *fn;
74158
74159- for (fn = __initcall_start; fn < __initcall0_start; fn++)
74160+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
74161 do_one_initcall(*fn);
74162+
74163+#ifdef LATENT_ENTROPY_PLUGIN
74164+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
74165+#endif
74166+
74167+ }
74168 }
74169
74170 static int run_init_process(const char *init_filename)
74171@@ -877,7 +947,7 @@ static noinline void __init kernel_init_freeable(void)
74172 do_basic_setup();
74173
74174 /* Open the /dev/console on the rootfs, this should never fail */
74175- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
74176+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
74177 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
74178
74179 (void) sys_dup(0);
74180@@ -890,11 +960,13 @@ static noinline void __init kernel_init_freeable(void)
74181 if (!ramdisk_execute_command)
74182 ramdisk_execute_command = "/init";
74183
74184- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
74185+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
74186 ramdisk_execute_command = NULL;
74187 prepare_namespace();
74188 }
74189
74190+ grsecurity_init();
74191+
74192 /*
74193 * Ok, we have completed the initial bootup, and
74194 * we're essentially up and running. Get rid of the
74195diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
74196index 130dfec..cc88451 100644
74197--- a/ipc/ipc_sysctl.c
74198+++ b/ipc/ipc_sysctl.c
74199@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
74200 static int proc_ipc_dointvec(ctl_table *table, int write,
74201 void __user *buffer, size_t *lenp, loff_t *ppos)
74202 {
74203- struct ctl_table ipc_table;
74204+ ctl_table_no_const ipc_table;
74205
74206 memcpy(&ipc_table, table, sizeof(ipc_table));
74207 ipc_table.data = get_ipc(table);
74208@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
74209 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
74210 void __user *buffer, size_t *lenp, loff_t *ppos)
74211 {
74212- struct ctl_table ipc_table;
74213+ ctl_table_no_const ipc_table;
74214
74215 memcpy(&ipc_table, table, sizeof(ipc_table));
74216 ipc_table.data = get_ipc(table);
74217@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
74218 static int proc_ipc_callback_dointvec(ctl_table *table, int write,
74219 void __user *buffer, size_t *lenp, loff_t *ppos)
74220 {
74221- struct ctl_table ipc_table;
74222+ ctl_table_no_const ipc_table;
74223 size_t lenp_bef = *lenp;
74224 int rc;
74225
74226@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
74227 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
74228 void __user *buffer, size_t *lenp, loff_t *ppos)
74229 {
74230- struct ctl_table ipc_table;
74231+ ctl_table_no_const ipc_table;
74232 memcpy(&ipc_table, table, sizeof(ipc_table));
74233 ipc_table.data = get_ipc(table);
74234
74235@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
74236 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
74237 void __user *buffer, size_t *lenp, loff_t *ppos)
74238 {
74239- struct ctl_table ipc_table;
74240+ ctl_table_no_const ipc_table;
74241 size_t lenp_bef = *lenp;
74242 int oldval;
74243 int rc;
74244diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
74245index 383d638..943fdbb 100644
74246--- a/ipc/mq_sysctl.c
74247+++ b/ipc/mq_sysctl.c
74248@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
74249 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
74250 void __user *buffer, size_t *lenp, loff_t *ppos)
74251 {
74252- struct ctl_table mq_table;
74253+ ctl_table_no_const mq_table;
74254 memcpy(&mq_table, table, sizeof(mq_table));
74255 mq_table.data = get_mq(table);
74256
74257diff --git a/ipc/mqueue.c b/ipc/mqueue.c
74258index f3f40dc..ffe5a3a 100644
74259--- a/ipc/mqueue.c
74260+++ b/ipc/mqueue.c
74261@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
74262 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
74263 info->attr.mq_msgsize);
74264
74265+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
74266 spin_lock(&mq_lock);
74267 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
74268 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
74269diff --git a/ipc/msg.c b/ipc/msg.c
74270index fede1d0..9778e0f8 100644
74271--- a/ipc/msg.c
74272+++ b/ipc/msg.c
74273@@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
74274 return security_msg_queue_associate(msq, msgflg);
74275 }
74276
74277+static struct ipc_ops msg_ops = {
74278+ .getnew = newque,
74279+ .associate = msg_security,
74280+ .more_checks = NULL
74281+};
74282+
74283 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
74284 {
74285 struct ipc_namespace *ns;
74286- struct ipc_ops msg_ops;
74287 struct ipc_params msg_params;
74288
74289 ns = current->nsproxy->ipc_ns;
74290
74291- msg_ops.getnew = newque;
74292- msg_ops.associate = msg_security;
74293- msg_ops.more_checks = NULL;
74294-
74295 msg_params.key = key;
74296 msg_params.flg = msgflg;
74297
74298diff --git a/ipc/sem.c b/ipc/sem.c
74299index 58d31f1..cce7a55 100644
74300--- a/ipc/sem.c
74301+++ b/ipc/sem.c
74302@@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
74303 return 0;
74304 }
74305
74306+static struct ipc_ops sem_ops = {
74307+ .getnew = newary,
74308+ .associate = sem_security,
74309+ .more_checks = sem_more_checks
74310+};
74311+
74312 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
74313 {
74314 struct ipc_namespace *ns;
74315- struct ipc_ops sem_ops;
74316 struct ipc_params sem_params;
74317
74318 ns = current->nsproxy->ipc_ns;
74319@@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
74320 if (nsems < 0 || nsems > ns->sc_semmsl)
74321 return -EINVAL;
74322
74323- sem_ops.getnew = newary;
74324- sem_ops.associate = sem_security;
74325- sem_ops.more_checks = sem_more_checks;
74326-
74327 sem_params.key = key;
74328 sem_params.flg = semflg;
74329 sem_params.u.nsems = nsems;
74330diff --git a/ipc/shm.c b/ipc/shm.c
74331index 4fa6d8f..55cff14 100644
74332--- a/ipc/shm.c
74333+++ b/ipc/shm.c
74334@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
74335 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
74336 #endif
74337
74338+#ifdef CONFIG_GRKERNSEC
74339+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74340+ const time_t shm_createtime, const kuid_t cuid,
74341+ const int shmid);
74342+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74343+ const time_t shm_createtime);
74344+#endif
74345+
74346 void shm_init_ns(struct ipc_namespace *ns)
74347 {
74348 ns->shm_ctlmax = SHMMAX;
74349@@ -521,6 +529,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
74350 shp->shm_lprid = 0;
74351 shp->shm_atim = shp->shm_dtim = 0;
74352 shp->shm_ctim = get_seconds();
74353+#ifdef CONFIG_GRKERNSEC
74354+ {
74355+ struct timespec timeval;
74356+ do_posix_clock_monotonic_gettime(&timeval);
74357+
74358+ shp->shm_createtime = timeval.tv_sec;
74359+ }
74360+#endif
74361 shp->shm_segsz = size;
74362 shp->shm_nattch = 0;
74363 shp->shm_file = file;
74364@@ -572,18 +588,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
74365 return 0;
74366 }
74367
74368+static struct ipc_ops shm_ops = {
74369+ .getnew = newseg,
74370+ .associate = shm_security,
74371+ .more_checks = shm_more_checks
74372+};
74373+
74374 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
74375 {
74376 struct ipc_namespace *ns;
74377- struct ipc_ops shm_ops;
74378 struct ipc_params shm_params;
74379
74380 ns = current->nsproxy->ipc_ns;
74381
74382- shm_ops.getnew = newseg;
74383- shm_ops.associate = shm_security;
74384- shm_ops.more_checks = shm_more_checks;
74385-
74386 shm_params.key = key;
74387 shm_params.flg = shmflg;
74388 shm_params.u.size = size;
74389@@ -1004,6 +1021,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
74390 f_mode = FMODE_READ | FMODE_WRITE;
74391 }
74392 if (shmflg & SHM_EXEC) {
74393+
74394+#ifdef CONFIG_PAX_MPROTECT
74395+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
74396+ goto out;
74397+#endif
74398+
74399 prot |= PROT_EXEC;
74400 acc_mode |= S_IXUGO;
74401 }
74402@@ -1027,9 +1050,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
74403 if (err)
74404 goto out_unlock;
74405
74406+#ifdef CONFIG_GRKERNSEC
74407+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
74408+ shp->shm_perm.cuid, shmid) ||
74409+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
74410+ err = -EACCES;
74411+ goto out_unlock;
74412+ }
74413+#endif
74414+
74415 path = shp->shm_file->f_path;
74416 path_get(&path);
74417 shp->shm_nattch++;
74418+#ifdef CONFIG_GRKERNSEC
74419+ shp->shm_lapid = current->pid;
74420+#endif
74421 size = i_size_read(path.dentry->d_inode);
74422 shm_unlock(shp);
74423
74424diff --git a/kernel/acct.c b/kernel/acct.c
74425index 051e071..15e0920 100644
74426--- a/kernel/acct.c
74427+++ b/kernel/acct.c
74428@@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
74429 */
74430 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
74431 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
74432- file->f_op->write(file, (char *)&ac,
74433+ file->f_op->write(file, (char __force_user *)&ac,
74434 sizeof(acct_t), &file->f_pos);
74435 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
74436 set_fs(fs);
74437diff --git a/kernel/audit.c b/kernel/audit.c
74438index d596e53..dbef3c3 100644
74439--- a/kernel/audit.c
74440+++ b/kernel/audit.c
74441@@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
74442 3) suppressed due to audit_rate_limit
74443 4) suppressed due to audit_backlog_limit
74444 */
74445-static atomic_t audit_lost = ATOMIC_INIT(0);
74446+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
74447
74448 /* The netlink socket. */
74449 static struct sock *audit_sock;
74450@@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
74451 unsigned long now;
74452 int print;
74453
74454- atomic_inc(&audit_lost);
74455+ atomic_inc_unchecked(&audit_lost);
74456
74457 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
74458
74459@@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
74460 printk(KERN_WARNING
74461 "audit: audit_lost=%d audit_rate_limit=%d "
74462 "audit_backlog_limit=%d\n",
74463- atomic_read(&audit_lost),
74464+ atomic_read_unchecked(&audit_lost),
74465 audit_rate_limit,
74466 audit_backlog_limit);
74467 audit_panic(message);
74468@@ -681,7 +681,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
74469 status_set.pid = audit_pid;
74470 status_set.rate_limit = audit_rate_limit;
74471 status_set.backlog_limit = audit_backlog_limit;
74472- status_set.lost = atomic_read(&audit_lost);
74473+ status_set.lost = atomic_read_unchecked(&audit_lost);
74474 status_set.backlog = skb_queue_len(&audit_skb_queue);
74475 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
74476 &status_set, sizeof(status_set));
74477diff --git a/kernel/auditsc.c b/kernel/auditsc.c
74478index a371f85..da826c1 100644
74479--- a/kernel/auditsc.c
74480+++ b/kernel/auditsc.c
74481@@ -2292,7 +2292,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
74482 }
74483
74484 /* global counter which is incremented every time something logs in */
74485-static atomic_t session_id = ATOMIC_INIT(0);
74486+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
74487
74488 /**
74489 * audit_set_loginuid - set current task's audit_context loginuid
74490@@ -2316,7 +2316,7 @@ int audit_set_loginuid(kuid_t loginuid)
74491 return -EPERM;
74492 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
74493
74494- sessionid = atomic_inc_return(&session_id);
74495+ sessionid = atomic_inc_return_unchecked(&session_id);
74496 if (context && context->in_syscall) {
74497 struct audit_buffer *ab;
74498
74499diff --git a/kernel/capability.c b/kernel/capability.c
74500index 493d972..f87dfbd 100644
74501--- a/kernel/capability.c
74502+++ b/kernel/capability.c
74503@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
74504 * before modification is attempted and the application
74505 * fails.
74506 */
74507+ if (tocopy > ARRAY_SIZE(kdata))
74508+ return -EFAULT;
74509+
74510 if (copy_to_user(dataptr, kdata, tocopy
74511 * sizeof(struct __user_cap_data_struct))) {
74512 return -EFAULT;
74513@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
74514 int ret;
74515
74516 rcu_read_lock();
74517- ret = security_capable(__task_cred(t), ns, cap);
74518+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
74519+ gr_task_is_capable(t, __task_cred(t), cap);
74520 rcu_read_unlock();
74521
74522- return (ret == 0);
74523+ return ret;
74524 }
74525
74526 /**
74527@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
74528 int ret;
74529
74530 rcu_read_lock();
74531- ret = security_capable_noaudit(__task_cred(t), ns, cap);
74532+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
74533 rcu_read_unlock();
74534
74535- return (ret == 0);
74536+ return ret;
74537 }
74538
74539 /**
74540@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
74541 BUG();
74542 }
74543
74544- if (security_capable(current_cred(), ns, cap) == 0) {
74545+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
74546 current->flags |= PF_SUPERPRIV;
74547 return true;
74548 }
74549@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
74550 }
74551 EXPORT_SYMBOL(ns_capable);
74552
74553+bool ns_capable_nolog(struct user_namespace *ns, int cap)
74554+{
74555+ if (unlikely(!cap_valid(cap))) {
74556+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
74557+ BUG();
74558+ }
74559+
74560+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
74561+ current->flags |= PF_SUPERPRIV;
74562+ return true;
74563+ }
74564+ return false;
74565+}
74566+EXPORT_SYMBOL(ns_capable_nolog);
74567+
74568 /**
74569 * capable - Determine if the current task has a superior capability in effect
74570 * @cap: The capability to be tested for
74571@@ -408,6 +427,12 @@ bool capable(int cap)
74572 }
74573 EXPORT_SYMBOL(capable);
74574
74575+bool capable_nolog(int cap)
74576+{
74577+ return ns_capable_nolog(&init_user_ns, cap);
74578+}
74579+EXPORT_SYMBOL(capable_nolog);
74580+
74581 /**
74582 * nsown_capable - Check superior capability to one's own user_ns
74583 * @cap: The capability in question
74584@@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
74585
74586 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
74587 }
74588+
74589+bool inode_capable_nolog(const struct inode *inode, int cap)
74590+{
74591+ struct user_namespace *ns = current_user_ns();
74592+
74593+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
74594+}
74595diff --git a/kernel/cgroup.c b/kernel/cgroup.c
74596index 1e23664..570a83d 100644
74597--- a/kernel/cgroup.c
74598+++ b/kernel/cgroup.c
74599@@ -5543,7 +5543,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
74600 struct css_set *cg = link->cg;
74601 struct task_struct *task;
74602 int count = 0;
74603- seq_printf(seq, "css_set %p\n", cg);
74604+ seq_printf(seq, "css_set %pK\n", cg);
74605 list_for_each_entry(task, &cg->tasks, cg_list) {
74606 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
74607 seq_puts(seq, " ...\n");
74608diff --git a/kernel/compat.c b/kernel/compat.c
74609index 36700e9..73d770c 100644
74610--- a/kernel/compat.c
74611+++ b/kernel/compat.c
74612@@ -13,6 +13,7 @@
74613
74614 #include <linux/linkage.h>
74615 #include <linux/compat.h>
74616+#include <linux/module.h>
74617 #include <linux/errno.h>
74618 #include <linux/time.h>
74619 #include <linux/signal.h>
74620@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
74621 mm_segment_t oldfs;
74622 long ret;
74623
74624- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
74625+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
74626 oldfs = get_fs();
74627 set_fs(KERNEL_DS);
74628 ret = hrtimer_nanosleep_restart(restart);
74629@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
74630 oldfs = get_fs();
74631 set_fs(KERNEL_DS);
74632 ret = hrtimer_nanosleep(&tu,
74633- rmtp ? (struct timespec __user *)&rmt : NULL,
74634+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
74635 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
74636 set_fs(oldfs);
74637
74638@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
74639 mm_segment_t old_fs = get_fs();
74640
74641 set_fs(KERNEL_DS);
74642- ret = sys_sigpending((old_sigset_t __user *) &s);
74643+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
74644 set_fs(old_fs);
74645 if (ret == 0)
74646 ret = put_user(s, set);
74647@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
74648 mm_segment_t old_fs = get_fs();
74649
74650 set_fs(KERNEL_DS);
74651- ret = sys_old_getrlimit(resource, &r);
74652+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
74653 set_fs(old_fs);
74654
74655 if (!ret) {
74656@@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
74657 mm_segment_t old_fs = get_fs();
74658
74659 set_fs(KERNEL_DS);
74660- ret = sys_getrusage(who, (struct rusage __user *) &r);
74661+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
74662 set_fs(old_fs);
74663
74664 if (ret)
74665@@ -552,8 +553,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
74666 set_fs (KERNEL_DS);
74667 ret = sys_wait4(pid,
74668 (stat_addr ?
74669- (unsigned int __user *) &status : NULL),
74670- options, (struct rusage __user *) &r);
74671+ (unsigned int __force_user *) &status : NULL),
74672+ options, (struct rusage __force_user *) &r);
74673 set_fs (old_fs);
74674
74675 if (ret > 0) {
74676@@ -579,8 +580,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
74677 memset(&info, 0, sizeof(info));
74678
74679 set_fs(KERNEL_DS);
74680- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
74681- uru ? (struct rusage __user *)&ru : NULL);
74682+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
74683+ uru ? (struct rusage __force_user *)&ru : NULL);
74684 set_fs(old_fs);
74685
74686 if ((ret < 0) || (info.si_signo == 0))
74687@@ -714,8 +715,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
74688 oldfs = get_fs();
74689 set_fs(KERNEL_DS);
74690 err = sys_timer_settime(timer_id, flags,
74691- (struct itimerspec __user *) &newts,
74692- (struct itimerspec __user *) &oldts);
74693+ (struct itimerspec __force_user *) &newts,
74694+ (struct itimerspec __force_user *) &oldts);
74695 set_fs(oldfs);
74696 if (!err && old && put_compat_itimerspec(old, &oldts))
74697 return -EFAULT;
74698@@ -732,7 +733,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
74699 oldfs = get_fs();
74700 set_fs(KERNEL_DS);
74701 err = sys_timer_gettime(timer_id,
74702- (struct itimerspec __user *) &ts);
74703+ (struct itimerspec __force_user *) &ts);
74704 set_fs(oldfs);
74705 if (!err && put_compat_itimerspec(setting, &ts))
74706 return -EFAULT;
74707@@ -751,7 +752,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
74708 oldfs = get_fs();
74709 set_fs(KERNEL_DS);
74710 err = sys_clock_settime(which_clock,
74711- (struct timespec __user *) &ts);
74712+ (struct timespec __force_user *) &ts);
74713 set_fs(oldfs);
74714 return err;
74715 }
74716@@ -766,7 +767,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
74717 oldfs = get_fs();
74718 set_fs(KERNEL_DS);
74719 err = sys_clock_gettime(which_clock,
74720- (struct timespec __user *) &ts);
74721+ (struct timespec __force_user *) &ts);
74722 set_fs(oldfs);
74723 if (!err && put_compat_timespec(&ts, tp))
74724 return -EFAULT;
74725@@ -786,7 +787,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
74726
74727 oldfs = get_fs();
74728 set_fs(KERNEL_DS);
74729- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
74730+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
74731 set_fs(oldfs);
74732
74733 err = compat_put_timex(utp, &txc);
74734@@ -806,7 +807,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
74735 oldfs = get_fs();
74736 set_fs(KERNEL_DS);
74737 err = sys_clock_getres(which_clock,
74738- (struct timespec __user *) &ts);
74739+ (struct timespec __force_user *) &ts);
74740 set_fs(oldfs);
74741 if (!err && tp && put_compat_timespec(&ts, tp))
74742 return -EFAULT;
74743@@ -818,9 +819,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
74744 long err;
74745 mm_segment_t oldfs;
74746 struct timespec tu;
74747- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
74748+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
74749
74750- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
74751+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
74752 oldfs = get_fs();
74753 set_fs(KERNEL_DS);
74754 err = clock_nanosleep_restart(restart);
74755@@ -852,8 +853,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
74756 oldfs = get_fs();
74757 set_fs(KERNEL_DS);
74758 err = sys_clock_nanosleep(which_clock, flags,
74759- (struct timespec __user *) &in,
74760- (struct timespec __user *) &out);
74761+ (struct timespec __force_user *) &in,
74762+ (struct timespec __force_user *) &out);
74763 set_fs(oldfs);
74764
74765 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
74766diff --git a/kernel/configs.c b/kernel/configs.c
74767index 42e8fa0..9e7406b 100644
74768--- a/kernel/configs.c
74769+++ b/kernel/configs.c
74770@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
74771 struct proc_dir_entry *entry;
74772
74773 /* create the current config file */
74774+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
74775+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
74776+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
74777+ &ikconfig_file_ops);
74778+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
74779+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
74780+ &ikconfig_file_ops);
74781+#endif
74782+#else
74783 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
74784 &ikconfig_file_ops);
74785+#endif
74786+
74787 if (!entry)
74788 return -ENOMEM;
74789
74790diff --git a/kernel/cred.c b/kernel/cred.c
74791index e0573a4..3874e41 100644
74792--- a/kernel/cred.c
74793+++ b/kernel/cred.c
74794@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
74795 validate_creds(cred);
74796 alter_cred_subscribers(cred, -1);
74797 put_cred(cred);
74798+
74799+#ifdef CONFIG_GRKERNSEC_SETXID
74800+ cred = (struct cred *) tsk->delayed_cred;
74801+ if (cred != NULL) {
74802+ tsk->delayed_cred = NULL;
74803+ validate_creds(cred);
74804+ alter_cred_subscribers(cred, -1);
74805+ put_cred(cred);
74806+ }
74807+#endif
74808 }
74809
74810 /**
74811@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
74812 * Always returns 0 thus allowing this function to be tail-called at the end
74813 * of, say, sys_setgid().
74814 */
74815-int commit_creds(struct cred *new)
74816+static int __commit_creds(struct cred *new)
74817 {
74818 struct task_struct *task = current;
74819 const struct cred *old = task->real_cred;
74820@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
74821
74822 get_cred(new); /* we will require a ref for the subj creds too */
74823
74824+ gr_set_role_label(task, new->uid, new->gid);
74825+
74826 /* dumpability changes */
74827 if (!uid_eq(old->euid, new->euid) ||
74828 !gid_eq(old->egid, new->egid) ||
74829@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
74830 put_cred(old);
74831 return 0;
74832 }
74833+#ifdef CONFIG_GRKERNSEC_SETXID
74834+extern int set_user(struct cred *new);
74835+
74836+void gr_delayed_cred_worker(void)
74837+{
74838+ const struct cred *new = current->delayed_cred;
74839+ struct cred *ncred;
74840+
74841+ current->delayed_cred = NULL;
74842+
74843+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
74844+ // from doing get_cred on it when queueing this
74845+ put_cred(new);
74846+ return;
74847+ } else if (new == NULL)
74848+ return;
74849+
74850+ ncred = prepare_creds();
74851+ if (!ncred)
74852+ goto die;
74853+ // uids
74854+ ncred->uid = new->uid;
74855+ ncred->euid = new->euid;
74856+ ncred->suid = new->suid;
74857+ ncred->fsuid = new->fsuid;
74858+ // gids
74859+ ncred->gid = new->gid;
74860+ ncred->egid = new->egid;
74861+ ncred->sgid = new->sgid;
74862+ ncred->fsgid = new->fsgid;
74863+ // groups
74864+ if (set_groups(ncred, new->group_info) < 0) {
74865+ abort_creds(ncred);
74866+ goto die;
74867+ }
74868+ // caps
74869+ ncred->securebits = new->securebits;
74870+ ncred->cap_inheritable = new->cap_inheritable;
74871+ ncred->cap_permitted = new->cap_permitted;
74872+ ncred->cap_effective = new->cap_effective;
74873+ ncred->cap_bset = new->cap_bset;
74874+
74875+ if (set_user(ncred)) {
74876+ abort_creds(ncred);
74877+ goto die;
74878+ }
74879+
74880+ // from doing get_cred on it when queueing this
74881+ put_cred(new);
74882+
74883+ __commit_creds(ncred);
74884+ return;
74885+die:
74886+ // from doing get_cred on it when queueing this
74887+ put_cred(new);
74888+ do_group_exit(SIGKILL);
74889+}
74890+#endif
74891+
74892+int commit_creds(struct cred *new)
74893+{
74894+#ifdef CONFIG_GRKERNSEC_SETXID
74895+ int ret;
74896+ int schedule_it = 0;
74897+ struct task_struct *t;
74898+
74899+ /* we won't get called with tasklist_lock held for writing
74900+ and interrupts disabled as the cred struct in that case is
74901+ init_cred
74902+ */
74903+ if (grsec_enable_setxid && !current_is_single_threaded() &&
74904+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
74905+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
74906+ schedule_it = 1;
74907+ }
74908+ ret = __commit_creds(new);
74909+ if (schedule_it) {
74910+ rcu_read_lock();
74911+ read_lock(&tasklist_lock);
74912+ for (t = next_thread(current); t != current;
74913+ t = next_thread(t)) {
74914+ if (t->delayed_cred == NULL) {
74915+ t->delayed_cred = get_cred(new);
74916+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
74917+ set_tsk_need_resched(t);
74918+ }
74919+ }
74920+ read_unlock(&tasklist_lock);
74921+ rcu_read_unlock();
74922+ }
74923+ return ret;
74924+#else
74925+ return __commit_creds(new);
74926+#endif
74927+}
74928+
74929 EXPORT_SYMBOL(commit_creds);
74930
74931 /**
74932diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
74933index 9a61738..c5c8f3a 100644
74934--- a/kernel/debug/debug_core.c
74935+++ b/kernel/debug/debug_core.c
74936@@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
74937 */
74938 static atomic_t masters_in_kgdb;
74939 static atomic_t slaves_in_kgdb;
74940-static atomic_t kgdb_break_tasklet_var;
74941+static atomic_unchecked_t kgdb_break_tasklet_var;
74942 atomic_t kgdb_setting_breakpoint;
74943
74944 struct task_struct *kgdb_usethread;
74945@@ -132,7 +132,7 @@ int kgdb_single_step;
74946 static pid_t kgdb_sstep_pid;
74947
74948 /* to keep track of the CPU which is doing the single stepping*/
74949-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
74950+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
74951
74952 /*
74953 * If you are debugging a problem where roundup (the collection of
74954@@ -540,7 +540,7 @@ return_normal:
74955 * kernel will only try for the value of sstep_tries before
74956 * giving up and continuing on.
74957 */
74958- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
74959+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
74960 (kgdb_info[cpu].task &&
74961 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
74962 atomic_set(&kgdb_active, -1);
74963@@ -634,8 +634,8 @@ cpu_master_loop:
74964 }
74965
74966 kgdb_restore:
74967- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
74968- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
74969+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
74970+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
74971 if (kgdb_info[sstep_cpu].task)
74972 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
74973 else
74974@@ -887,18 +887,18 @@ static void kgdb_unregister_callbacks(void)
74975 static void kgdb_tasklet_bpt(unsigned long ing)
74976 {
74977 kgdb_breakpoint();
74978- atomic_set(&kgdb_break_tasklet_var, 0);
74979+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
74980 }
74981
74982 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
74983
74984 void kgdb_schedule_breakpoint(void)
74985 {
74986- if (atomic_read(&kgdb_break_tasklet_var) ||
74987+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
74988 atomic_read(&kgdb_active) != -1 ||
74989 atomic_read(&kgdb_setting_breakpoint))
74990 return;
74991- atomic_inc(&kgdb_break_tasklet_var);
74992+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
74993 tasklet_schedule(&kgdb_tasklet_breakpoint);
74994 }
74995 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
74996diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
74997index 8875254..7cf4928 100644
74998--- a/kernel/debug/kdb/kdb_main.c
74999+++ b/kernel/debug/kdb/kdb_main.c
75000@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
75001 continue;
75002
75003 kdb_printf("%-20s%8u 0x%p ", mod->name,
75004- mod->core_size, (void *)mod);
75005+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
75006 #ifdef CONFIG_MODULE_UNLOAD
75007 kdb_printf("%4ld ", module_refcount(mod));
75008 #endif
75009@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
75010 kdb_printf(" (Loading)");
75011 else
75012 kdb_printf(" (Live)");
75013- kdb_printf(" 0x%p", mod->module_core);
75014+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
75015
75016 #ifdef CONFIG_MODULE_UNLOAD
75017 {
75018diff --git a/kernel/events/core.c b/kernel/events/core.c
75019index 7b6646a..3cb1135 100644
75020--- a/kernel/events/core.c
75021+++ b/kernel/events/core.c
75022@@ -182,7 +182,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
75023 return 0;
75024 }
75025
75026-static atomic64_t perf_event_id;
75027+static atomic64_unchecked_t perf_event_id;
75028
75029 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
75030 enum event_type_t event_type);
75031@@ -2677,7 +2677,7 @@ static void __perf_event_read(void *info)
75032
75033 static inline u64 perf_event_count(struct perf_event *event)
75034 {
75035- return local64_read(&event->count) + atomic64_read(&event->child_count);
75036+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
75037 }
75038
75039 static u64 perf_event_read(struct perf_event *event)
75040@@ -3007,9 +3007,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
75041 mutex_lock(&event->child_mutex);
75042 total += perf_event_read(event);
75043 *enabled += event->total_time_enabled +
75044- atomic64_read(&event->child_total_time_enabled);
75045+ atomic64_read_unchecked(&event->child_total_time_enabled);
75046 *running += event->total_time_running +
75047- atomic64_read(&event->child_total_time_running);
75048+ atomic64_read_unchecked(&event->child_total_time_running);
75049
75050 list_for_each_entry(child, &event->child_list, child_list) {
75051 total += perf_event_read(child);
75052@@ -3412,10 +3412,10 @@ void perf_event_update_userpage(struct perf_event *event)
75053 userpg->offset -= local64_read(&event->hw.prev_count);
75054
75055 userpg->time_enabled = enabled +
75056- atomic64_read(&event->child_total_time_enabled);
75057+ atomic64_read_unchecked(&event->child_total_time_enabled);
75058
75059 userpg->time_running = running +
75060- atomic64_read(&event->child_total_time_running);
75061+ atomic64_read_unchecked(&event->child_total_time_running);
75062
75063 arch_perf_update_userpage(userpg, now);
75064
75065@@ -3974,11 +3974,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
75066 values[n++] = perf_event_count(event);
75067 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
75068 values[n++] = enabled +
75069- atomic64_read(&event->child_total_time_enabled);
75070+ atomic64_read_unchecked(&event->child_total_time_enabled);
75071 }
75072 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
75073 values[n++] = running +
75074- atomic64_read(&event->child_total_time_running);
75075+ atomic64_read_unchecked(&event->child_total_time_running);
75076 }
75077 if (read_format & PERF_FORMAT_ID)
75078 values[n++] = primary_event_id(event);
75079@@ -4721,12 +4721,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
75080 * need to add enough zero bytes after the string to handle
75081 * the 64bit alignment we do later.
75082 */
75083- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
75084+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
75085 if (!buf) {
75086 name = strncpy(tmp, "//enomem", sizeof(tmp));
75087 goto got_name;
75088 }
75089- name = d_path(&file->f_path, buf, PATH_MAX);
75090+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
75091 if (IS_ERR(name)) {
75092 name = strncpy(tmp, "//toolong", sizeof(tmp));
75093 goto got_name;
75094@@ -6165,7 +6165,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
75095 event->parent = parent_event;
75096
75097 event->ns = get_pid_ns(task_active_pid_ns(current));
75098- event->id = atomic64_inc_return(&perf_event_id);
75099+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
75100
75101 event->state = PERF_EVENT_STATE_INACTIVE;
75102
75103@@ -6790,10 +6790,10 @@ static void sync_child_event(struct perf_event *child_event,
75104 /*
75105 * Add back the child's count to the parent's count:
75106 */
75107- atomic64_add(child_val, &parent_event->child_count);
75108- atomic64_add(child_event->total_time_enabled,
75109+ atomic64_add_unchecked(child_val, &parent_event->child_count);
75110+ atomic64_add_unchecked(child_event->total_time_enabled,
75111 &parent_event->child_total_time_enabled);
75112- atomic64_add(child_event->total_time_running,
75113+ atomic64_add_unchecked(child_event->total_time_running,
75114 &parent_event->child_total_time_running);
75115
75116 /*
75117diff --git a/kernel/exit.c b/kernel/exit.c
75118index b4df219..f13c02d 100644
75119--- a/kernel/exit.c
75120+++ b/kernel/exit.c
75121@@ -170,6 +170,10 @@ void release_task(struct task_struct * p)
75122 struct task_struct *leader;
75123 int zap_leader;
75124 repeat:
75125+#ifdef CONFIG_NET
75126+ gr_del_task_from_ip_table(p);
75127+#endif
75128+
75129 /* don't need to get the RCU readlock here - the process is dead and
75130 * can't be modifying its own credentials. But shut RCU-lockdep up */
75131 rcu_read_lock();
75132@@ -338,7 +342,7 @@ int allow_signal(int sig)
75133 * know it'll be handled, so that they don't get converted to
75134 * SIGKILL or just silently dropped.
75135 */
75136- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
75137+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
75138 recalc_sigpending();
75139 spin_unlock_irq(&current->sighand->siglock);
75140 return 0;
75141@@ -708,6 +712,8 @@ void do_exit(long code)
75142 struct task_struct *tsk = current;
75143 int group_dead;
75144
75145+ set_fs(USER_DS);
75146+
75147 profile_task_exit(tsk);
75148
75149 WARN_ON(blk_needs_flush_plug(tsk));
75150@@ -724,7 +730,6 @@ void do_exit(long code)
75151 * mm_release()->clear_child_tid() from writing to a user-controlled
75152 * kernel address.
75153 */
75154- set_fs(USER_DS);
75155
75156 ptrace_event(PTRACE_EVENT_EXIT, code);
75157
75158@@ -783,6 +788,9 @@ void do_exit(long code)
75159 tsk->exit_code = code;
75160 taskstats_exit(tsk, group_dead);
75161
75162+ gr_acl_handle_psacct(tsk, code);
75163+ gr_acl_handle_exit();
75164+
75165 exit_mm(tsk);
75166
75167 if (group_dead)
75168@@ -903,7 +911,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
75169 * Take down every thread in the group. This is called by fatal signals
75170 * as well as by sys_exit_group (below).
75171 */
75172-void
75173+__noreturn void
75174 do_group_exit(int exit_code)
75175 {
75176 struct signal_struct *sig = current->signal;
75177diff --git a/kernel/fork.c b/kernel/fork.c
75178index 5630e52..0cee608 100644
75179--- a/kernel/fork.c
75180+++ b/kernel/fork.c
75181@@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
75182 *stackend = STACK_END_MAGIC; /* for overflow detection */
75183
75184 #ifdef CONFIG_CC_STACKPROTECTOR
75185- tsk->stack_canary = get_random_int();
75186+ tsk->stack_canary = pax_get_random_long();
75187 #endif
75188
75189 /*
75190@@ -344,13 +344,81 @@ free_tsk:
75191 }
75192
75193 #ifdef CONFIG_MMU
75194+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
75195+{
75196+ struct vm_area_struct *tmp;
75197+ unsigned long charge;
75198+ struct mempolicy *pol;
75199+ struct file *file;
75200+
75201+ charge = 0;
75202+ if (mpnt->vm_flags & VM_ACCOUNT) {
75203+ unsigned long len = vma_pages(mpnt);
75204+
75205+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
75206+ goto fail_nomem;
75207+ charge = len;
75208+ }
75209+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
75210+ if (!tmp)
75211+ goto fail_nomem;
75212+ *tmp = *mpnt;
75213+ tmp->vm_mm = mm;
75214+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
75215+ pol = mpol_dup(vma_policy(mpnt));
75216+ if (IS_ERR(pol))
75217+ goto fail_nomem_policy;
75218+ vma_set_policy(tmp, pol);
75219+ if (anon_vma_fork(tmp, mpnt))
75220+ goto fail_nomem_anon_vma_fork;
75221+ tmp->vm_flags &= ~VM_LOCKED;
75222+ tmp->vm_next = tmp->vm_prev = NULL;
75223+ tmp->vm_mirror = NULL;
75224+ file = tmp->vm_file;
75225+ if (file) {
75226+ struct inode *inode = file->f_path.dentry->d_inode;
75227+ struct address_space *mapping = file->f_mapping;
75228+
75229+ get_file(file);
75230+ if (tmp->vm_flags & VM_DENYWRITE)
75231+ atomic_dec(&inode->i_writecount);
75232+ mutex_lock(&mapping->i_mmap_mutex);
75233+ if (tmp->vm_flags & VM_SHARED)
75234+ mapping->i_mmap_writable++;
75235+ flush_dcache_mmap_lock(mapping);
75236+ /* insert tmp into the share list, just after mpnt */
75237+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
75238+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
75239+ else
75240+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
75241+ flush_dcache_mmap_unlock(mapping);
75242+ mutex_unlock(&mapping->i_mmap_mutex);
75243+ }
75244+
75245+ /*
75246+ * Clear hugetlb-related page reserves for children. This only
75247+ * affects MAP_PRIVATE mappings. Faults generated by the child
75248+ * are not guaranteed to succeed, even if read-only
75249+ */
75250+ if (is_vm_hugetlb_page(tmp))
75251+ reset_vma_resv_huge_pages(tmp);
75252+
75253+ return tmp;
75254+
75255+fail_nomem_anon_vma_fork:
75256+ mpol_put(pol);
75257+fail_nomem_policy:
75258+ kmem_cache_free(vm_area_cachep, tmp);
75259+fail_nomem:
75260+ vm_unacct_memory(charge);
75261+ return NULL;
75262+}
75263+
75264 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75265 {
75266 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
75267 struct rb_node **rb_link, *rb_parent;
75268 int retval;
75269- unsigned long charge;
75270- struct mempolicy *pol;
75271
75272 uprobe_start_dup_mmap();
75273 down_write(&oldmm->mmap_sem);
75274@@ -364,8 +432,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75275 mm->locked_vm = 0;
75276 mm->mmap = NULL;
75277 mm->mmap_cache = NULL;
75278- mm->free_area_cache = oldmm->mmap_base;
75279- mm->cached_hole_size = ~0UL;
75280+ mm->free_area_cache = oldmm->free_area_cache;
75281+ mm->cached_hole_size = oldmm->cached_hole_size;
75282 mm->map_count = 0;
75283 cpumask_clear(mm_cpumask(mm));
75284 mm->mm_rb = RB_ROOT;
75285@@ -381,57 +449,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75286
75287 prev = NULL;
75288 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
75289- struct file *file;
75290-
75291 if (mpnt->vm_flags & VM_DONTCOPY) {
75292 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
75293 -vma_pages(mpnt));
75294 continue;
75295 }
75296- charge = 0;
75297- if (mpnt->vm_flags & VM_ACCOUNT) {
75298- unsigned long len = vma_pages(mpnt);
75299-
75300- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
75301- goto fail_nomem;
75302- charge = len;
75303- }
75304- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
75305- if (!tmp)
75306- goto fail_nomem;
75307- *tmp = *mpnt;
75308- INIT_LIST_HEAD(&tmp->anon_vma_chain);
75309- pol = mpol_dup(vma_policy(mpnt));
75310- retval = PTR_ERR(pol);
75311- if (IS_ERR(pol))
75312- goto fail_nomem_policy;
75313- vma_set_policy(tmp, pol);
75314- tmp->vm_mm = mm;
75315- if (anon_vma_fork(tmp, mpnt))
75316- goto fail_nomem_anon_vma_fork;
75317- tmp->vm_flags &= ~VM_LOCKED;
75318- tmp->vm_next = tmp->vm_prev = NULL;
75319- file = tmp->vm_file;
75320- if (file) {
75321- struct inode *inode = file->f_path.dentry->d_inode;
75322- struct address_space *mapping = file->f_mapping;
75323-
75324- get_file(file);
75325- if (tmp->vm_flags & VM_DENYWRITE)
75326- atomic_dec(&inode->i_writecount);
75327- mutex_lock(&mapping->i_mmap_mutex);
75328- if (tmp->vm_flags & VM_SHARED)
75329- mapping->i_mmap_writable++;
75330- flush_dcache_mmap_lock(mapping);
75331- /* insert tmp into the share list, just after mpnt */
75332- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
75333- vma_nonlinear_insert(tmp,
75334- &mapping->i_mmap_nonlinear);
75335- else
75336- vma_interval_tree_insert_after(tmp, mpnt,
75337- &mapping->i_mmap);
75338- flush_dcache_mmap_unlock(mapping);
75339- mutex_unlock(&mapping->i_mmap_mutex);
75340+ tmp = dup_vma(mm, oldmm, mpnt);
75341+ if (!tmp) {
75342+ retval = -ENOMEM;
75343+ goto out;
75344 }
75345
75346 /*
75347@@ -463,6 +489,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75348 if (retval)
75349 goto out;
75350 }
75351+
75352+#ifdef CONFIG_PAX_SEGMEXEC
75353+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
75354+ struct vm_area_struct *mpnt_m;
75355+
75356+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
75357+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
75358+
75359+ if (!mpnt->vm_mirror)
75360+ continue;
75361+
75362+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
75363+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
75364+ mpnt->vm_mirror = mpnt_m;
75365+ } else {
75366+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
75367+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
75368+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
75369+ mpnt->vm_mirror->vm_mirror = mpnt;
75370+ }
75371+ }
75372+ BUG_ON(mpnt_m);
75373+ }
75374+#endif
75375+
75376 /* a new mm has just been created */
75377 arch_dup_mmap(oldmm, mm);
75378 retval = 0;
75379@@ -472,14 +523,6 @@ out:
75380 up_write(&oldmm->mmap_sem);
75381 uprobe_end_dup_mmap();
75382 return retval;
75383-fail_nomem_anon_vma_fork:
75384- mpol_put(pol);
75385-fail_nomem_policy:
75386- kmem_cache_free(vm_area_cachep, tmp);
75387-fail_nomem:
75388- retval = -ENOMEM;
75389- vm_unacct_memory(charge);
75390- goto out;
75391 }
75392
75393 static inline int mm_alloc_pgd(struct mm_struct *mm)
75394@@ -694,8 +737,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
75395 return ERR_PTR(err);
75396
75397 mm = get_task_mm(task);
75398- if (mm && mm != current->mm &&
75399- !ptrace_may_access(task, mode)) {
75400+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
75401+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
75402 mmput(mm);
75403 mm = ERR_PTR(-EACCES);
75404 }
75405@@ -917,13 +960,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
75406 spin_unlock(&fs->lock);
75407 return -EAGAIN;
75408 }
75409- fs->users++;
75410+ atomic_inc(&fs->users);
75411 spin_unlock(&fs->lock);
75412 return 0;
75413 }
75414 tsk->fs = copy_fs_struct(fs);
75415 if (!tsk->fs)
75416 return -ENOMEM;
75417+ /* Carry through gr_chroot_dentry and is_chrooted instead
75418+ of recomputing it here. Already copied when the task struct
75419+ is duplicated. This allows pivot_root to not be treated as
75420+ a chroot
75421+ */
75422+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
75423+
75424 return 0;
75425 }
75426
75427@@ -1196,6 +1246,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
75428 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
75429 #endif
75430 retval = -EAGAIN;
75431+
75432+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
75433+
75434 if (atomic_read(&p->real_cred->user->processes) >=
75435 task_rlimit(p, RLIMIT_NPROC)) {
75436 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
75437@@ -1435,6 +1488,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
75438 goto bad_fork_free_pid;
75439 }
75440
75441+ /* synchronizes with gr_set_acls()
75442+ we need to call this past the point of no return for fork()
75443+ */
75444+ gr_copy_label(p);
75445+
75446 if (clone_flags & CLONE_THREAD) {
75447 current->signal->nr_threads++;
75448 atomic_inc(&current->signal->live);
75449@@ -1518,6 +1576,8 @@ bad_fork_cleanup_count:
75450 bad_fork_free:
75451 free_task(p);
75452 fork_out:
75453+ gr_log_forkfail(retval);
75454+
75455 return ERR_PTR(retval);
75456 }
75457
75458@@ -1568,6 +1628,23 @@ long do_fork(unsigned long clone_flags,
75459 return -EINVAL;
75460 }
75461
75462+#ifdef CONFIG_GRKERNSEC
75463+ if (clone_flags & CLONE_NEWUSER) {
75464+ /*
75465+ * This doesn't really inspire confidence:
75466+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
75467+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
75468+ * Increases kernel attack surface in areas developers
75469+ * previously cared little about ("low importance due
75470+ * to requiring "root" capability")
75471+ * To be removed when this code receives *proper* review
75472+ */
75473+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
75474+ !capable(CAP_SETGID))
75475+ return -EPERM;
75476+ }
75477+#endif
75478+
75479 /*
75480 * Determine whether and which event to report to ptracer. When
75481 * called from kernel_thread or CLONE_UNTRACED is explicitly
75482@@ -1602,6 +1679,8 @@ long do_fork(unsigned long clone_flags,
75483 if (clone_flags & CLONE_PARENT_SETTID)
75484 put_user(nr, parent_tidptr);
75485
75486+ gr_handle_brute_check();
75487+
75488 if (clone_flags & CLONE_VFORK) {
75489 p->vfork_done = &vfork;
75490 init_completion(&vfork);
75491@@ -1755,7 +1834,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
75492 return 0;
75493
75494 /* don't need lock here; in the worst case we'll do useless copy */
75495- if (fs->users == 1)
75496+ if (atomic_read(&fs->users) == 1)
75497 return 0;
75498
75499 *new_fsp = copy_fs_struct(fs);
75500@@ -1869,7 +1948,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
75501 fs = current->fs;
75502 spin_lock(&fs->lock);
75503 current->fs = new_fs;
75504- if (--fs->users)
75505+ gr_set_chroot_entries(current, &current->fs->root);
75506+ if (atomic_dec_return(&fs->users))
75507 new_fs = NULL;
75508 else
75509 new_fs = fs;
75510diff --git a/kernel/futex.c b/kernel/futex.c
75511index 8879430..31696f1 100644
75512--- a/kernel/futex.c
75513+++ b/kernel/futex.c
75514@@ -54,6 +54,7 @@
75515 #include <linux/mount.h>
75516 #include <linux/pagemap.h>
75517 #include <linux/syscalls.h>
75518+#include <linux/ptrace.h>
75519 #include <linux/signal.h>
75520 #include <linux/export.h>
75521 #include <linux/magic.h>
75522@@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
75523 struct page *page, *page_head;
75524 int err, ro = 0;
75525
75526+#ifdef CONFIG_PAX_SEGMEXEC
75527+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
75528+ return -EFAULT;
75529+#endif
75530+
75531 /*
75532 * The futex address must be "naturally" aligned.
75533 */
75534@@ -2731,6 +2737,7 @@ static int __init futex_init(void)
75535 {
75536 u32 curval;
75537 int i;
75538+ mm_segment_t oldfs;
75539
75540 /*
75541 * This will fail and we want it. Some arch implementations do
75542@@ -2742,8 +2749,11 @@ static int __init futex_init(void)
75543 * implementation, the non-functional ones will return
75544 * -ENOSYS.
75545 */
75546+ oldfs = get_fs();
75547+ set_fs(USER_DS);
75548 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
75549 futex_cmpxchg_enabled = 1;
75550+ set_fs(oldfs);
75551
75552 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
75553 plist_head_init(&futex_queues[i].chain);
75554diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
75555index a9642d5..51eb98c 100644
75556--- a/kernel/futex_compat.c
75557+++ b/kernel/futex_compat.c
75558@@ -31,7 +31,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
75559 return 0;
75560 }
75561
75562-static void __user *futex_uaddr(struct robust_list __user *entry,
75563+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
75564 compat_long_t futex_offset)
75565 {
75566 compat_uptr_t base = ptr_to_compat(entry);
75567diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
75568index 9b22d03..6295b62 100644
75569--- a/kernel/gcov/base.c
75570+++ b/kernel/gcov/base.c
75571@@ -102,11 +102,6 @@ void gcov_enable_events(void)
75572 }
75573
75574 #ifdef CONFIG_MODULES
75575-static inline int within(void *addr, void *start, unsigned long size)
75576-{
75577- return ((addr >= start) && (addr < start + size));
75578-}
75579-
75580 /* Update list and generate events when modules are unloaded. */
75581 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
75582 void *data)
75583@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
75584 prev = NULL;
75585 /* Remove entries located in module from linked list. */
75586 for (info = gcov_info_head; info; info = info->next) {
75587- if (within(info, mod->module_core, mod->core_size)) {
75588+ if (within_module_core_rw((unsigned long)info, mod)) {
75589 if (prev)
75590 prev->next = info->next;
75591 else
75592diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
75593index cdd5607..c3fc919 100644
75594--- a/kernel/hrtimer.c
75595+++ b/kernel/hrtimer.c
75596@@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
75597 local_irq_restore(flags);
75598 }
75599
75600-static void run_hrtimer_softirq(struct softirq_action *h)
75601+static void run_hrtimer_softirq(void)
75602 {
75603 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
75604
75605@@ -1751,7 +1751,7 @@ static int __cpuinit hrtimer_cpu_notify(struct notifier_block *self,
75606 return NOTIFY_OK;
75607 }
75608
75609-static struct notifier_block __cpuinitdata hrtimers_nb = {
75610+static struct notifier_block hrtimers_nb = {
75611 .notifier_call = hrtimer_cpu_notify,
75612 };
75613
75614diff --git a/kernel/jump_label.c b/kernel/jump_label.c
75615index 60f48fa..7f3a770 100644
75616--- a/kernel/jump_label.c
75617+++ b/kernel/jump_label.c
75618@@ -13,6 +13,7 @@
75619 #include <linux/sort.h>
75620 #include <linux/err.h>
75621 #include <linux/static_key.h>
75622+#include <linux/mm.h>
75623
75624 #ifdef HAVE_JUMP_LABEL
75625
75626@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
75627
75628 size = (((unsigned long)stop - (unsigned long)start)
75629 / sizeof(struct jump_entry));
75630+ pax_open_kernel();
75631 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
75632+ pax_close_kernel();
75633 }
75634
75635 static void jump_label_update(struct static_key *key, int enable);
75636@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
75637 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
75638 struct jump_entry *iter;
75639
75640+ pax_open_kernel();
75641 for (iter = iter_start; iter < iter_stop; iter++) {
75642 if (within_module_init(iter->code, mod))
75643 iter->code = 0;
75644 }
75645+ pax_close_kernel();
75646 }
75647
75648 static int
75649diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
75650index 2169fee..706ccca 100644
75651--- a/kernel/kallsyms.c
75652+++ b/kernel/kallsyms.c
75653@@ -11,6 +11,9 @@
75654 * Changed the compression method from stem compression to "table lookup"
75655 * compression (see scripts/kallsyms.c for a more complete description)
75656 */
75657+#ifdef CONFIG_GRKERNSEC_HIDESYM
75658+#define __INCLUDED_BY_HIDESYM 1
75659+#endif
75660 #include <linux/kallsyms.h>
75661 #include <linux/module.h>
75662 #include <linux/init.h>
75663@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
75664
75665 static inline int is_kernel_inittext(unsigned long addr)
75666 {
75667+ if (system_state != SYSTEM_BOOTING)
75668+ return 0;
75669+
75670 if (addr >= (unsigned long)_sinittext
75671 && addr <= (unsigned long)_einittext)
75672 return 1;
75673 return 0;
75674 }
75675
75676+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75677+#ifdef CONFIG_MODULES
75678+static inline int is_module_text(unsigned long addr)
75679+{
75680+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
75681+ return 1;
75682+
75683+ addr = ktla_ktva(addr);
75684+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
75685+}
75686+#else
75687+static inline int is_module_text(unsigned long addr)
75688+{
75689+ return 0;
75690+}
75691+#endif
75692+#endif
75693+
75694 static inline int is_kernel_text(unsigned long addr)
75695 {
75696 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
75697@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
75698
75699 static inline int is_kernel(unsigned long addr)
75700 {
75701+
75702+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75703+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
75704+ return 1;
75705+
75706+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
75707+#else
75708 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
75709+#endif
75710+
75711 return 1;
75712 return in_gate_area_no_mm(addr);
75713 }
75714
75715 static int is_ksym_addr(unsigned long addr)
75716 {
75717+
75718+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75719+ if (is_module_text(addr))
75720+ return 0;
75721+#endif
75722+
75723 if (all_var)
75724 return is_kernel(addr);
75725
75726@@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
75727
75728 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
75729 {
75730- iter->name[0] = '\0';
75731 iter->nameoff = get_symbol_offset(new_pos);
75732 iter->pos = new_pos;
75733 }
75734@@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
75735 {
75736 struct kallsym_iter *iter = m->private;
75737
75738+#ifdef CONFIG_GRKERNSEC_HIDESYM
75739+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
75740+ return 0;
75741+#endif
75742+
75743 /* Some debugging symbols have no name. Ignore them. */
75744 if (!iter->name[0])
75745 return 0;
75746@@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
75747 */
75748 type = iter->exported ? toupper(iter->type) :
75749 tolower(iter->type);
75750+
75751 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
75752 type, iter->name, iter->module_name);
75753 } else
75754@@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
75755 struct kallsym_iter *iter;
75756 int ret;
75757
75758- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
75759+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
75760 if (!iter)
75761 return -ENOMEM;
75762 reset_iter(iter, 0);
75763diff --git a/kernel/kcmp.c b/kernel/kcmp.c
75764index e30ac0f..3528cac 100644
75765--- a/kernel/kcmp.c
75766+++ b/kernel/kcmp.c
75767@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
75768 struct task_struct *task1, *task2;
75769 int ret;
75770
75771+#ifdef CONFIG_GRKERNSEC
75772+ return -ENOSYS;
75773+#endif
75774+
75775 rcu_read_lock();
75776
75777 /*
75778diff --git a/kernel/kexec.c b/kernel/kexec.c
75779index 5e4bd78..00c5b91 100644
75780--- a/kernel/kexec.c
75781+++ b/kernel/kexec.c
75782@@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
75783 unsigned long flags)
75784 {
75785 struct compat_kexec_segment in;
75786- struct kexec_segment out, __user *ksegments;
75787+ struct kexec_segment out;
75788+ struct kexec_segment __user *ksegments;
75789 unsigned long i, result;
75790
75791 /* Don't allow clients that don't understand the native
75792diff --git a/kernel/kmod.c b/kernel/kmod.c
75793index 0023a87..9c0c068 100644
75794--- a/kernel/kmod.c
75795+++ b/kernel/kmod.c
75796@@ -74,7 +74,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
75797 kfree(info->argv);
75798 }
75799
75800-static int call_modprobe(char *module_name, int wait)
75801+static int call_modprobe(char *module_name, char *module_param, int wait)
75802 {
75803 static char *envp[] = {
75804 "HOME=/",
75805@@ -83,7 +83,7 @@ static int call_modprobe(char *module_name, int wait)
75806 NULL
75807 };
75808
75809- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
75810+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
75811 if (!argv)
75812 goto out;
75813
75814@@ -95,7 +95,8 @@ static int call_modprobe(char *module_name, int wait)
75815 argv[1] = "-q";
75816 argv[2] = "--";
75817 argv[3] = module_name; /* check free_modprobe_argv() */
75818- argv[4] = NULL;
75819+ argv[4] = module_param;
75820+ argv[5] = NULL;
75821
75822 return call_usermodehelper_fns(modprobe_path, argv, envp,
75823 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
75824@@ -120,9 +121,8 @@ out:
75825 * If module auto-loading support is disabled then this function
75826 * becomes a no-operation.
75827 */
75828-int __request_module(bool wait, const char *fmt, ...)
75829+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
75830 {
75831- va_list args;
75832 char module_name[MODULE_NAME_LEN];
75833 unsigned int max_modprobes;
75834 int ret;
75835@@ -130,9 +130,7 @@ int __request_module(bool wait, const char *fmt, ...)
75836 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
75837 static int kmod_loop_msg;
75838
75839- va_start(args, fmt);
75840- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
75841- va_end(args);
75842+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
75843 if (ret >= MODULE_NAME_LEN)
75844 return -ENAMETOOLONG;
75845
75846@@ -140,6 +138,20 @@ int __request_module(bool wait, const char *fmt, ...)
75847 if (ret)
75848 return ret;
75849
75850+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75851+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
75852+ /* hack to workaround consolekit/udisks stupidity */
75853+ read_lock(&tasklist_lock);
75854+ if (!strcmp(current->comm, "mount") &&
75855+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
75856+ read_unlock(&tasklist_lock);
75857+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
75858+ return -EPERM;
75859+ }
75860+ read_unlock(&tasklist_lock);
75861+ }
75862+#endif
75863+
75864 /* If modprobe needs a service that is in a module, we get a recursive
75865 * loop. Limit the number of running kmod threads to max_threads/2 or
75866 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
75867@@ -168,11 +180,52 @@ int __request_module(bool wait, const char *fmt, ...)
75868
75869 trace_module_request(module_name, wait, _RET_IP_);
75870
75871- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
75872+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
75873
75874 atomic_dec(&kmod_concurrent);
75875 return ret;
75876 }
75877+
75878+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
75879+{
75880+ va_list args;
75881+ int ret;
75882+
75883+ va_start(args, fmt);
75884+ ret = ____request_module(wait, module_param, fmt, args);
75885+ va_end(args);
75886+
75887+ return ret;
75888+}
75889+
75890+int __request_module(bool wait, const char *fmt, ...)
75891+{
75892+ va_list args;
75893+ int ret;
75894+
75895+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75896+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
75897+ char module_param[MODULE_NAME_LEN];
75898+
75899+ memset(module_param, 0, sizeof(module_param));
75900+
75901+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
75902+
75903+ va_start(args, fmt);
75904+ ret = ____request_module(wait, module_param, fmt, args);
75905+ va_end(args);
75906+
75907+ return ret;
75908+ }
75909+#endif
75910+
75911+ va_start(args, fmt);
75912+ ret = ____request_module(wait, NULL, fmt, args);
75913+ va_end(args);
75914+
75915+ return ret;
75916+}
75917+
75918 EXPORT_SYMBOL(__request_module);
75919 #endif /* CONFIG_MODULES */
75920
75921@@ -283,7 +336,7 @@ static int wait_for_helper(void *data)
75922 *
75923 * Thus the __user pointer cast is valid here.
75924 */
75925- sys_wait4(pid, (int __user *)&ret, 0, NULL);
75926+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
75927
75928 /*
75929 * If ret is 0, either ____call_usermodehelper failed and the
75930@@ -635,7 +688,7 @@ EXPORT_SYMBOL(call_usermodehelper_fns);
75931 static int proc_cap_handler(struct ctl_table *table, int write,
75932 void __user *buffer, size_t *lenp, loff_t *ppos)
75933 {
75934- struct ctl_table t;
75935+ ctl_table_no_const t;
75936 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
75937 kernel_cap_t new_cap;
75938 int err, i;
75939diff --git a/kernel/kprobes.c b/kernel/kprobes.c
75940index 098f396..fe85ff1 100644
75941--- a/kernel/kprobes.c
75942+++ b/kernel/kprobes.c
75943@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
75944 * kernel image and loaded module images reside. This is required
75945 * so x86_64 can correctly handle the %rip-relative fixups.
75946 */
75947- kip->insns = module_alloc(PAGE_SIZE);
75948+ kip->insns = module_alloc_exec(PAGE_SIZE);
75949 if (!kip->insns) {
75950 kfree(kip);
75951 return NULL;
75952@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
75953 */
75954 if (!list_is_singular(&kip->list)) {
75955 list_del(&kip->list);
75956- module_free(NULL, kip->insns);
75957+ module_free_exec(NULL, kip->insns);
75958 kfree(kip);
75959 }
75960 return 1;
75961@@ -2063,7 +2063,7 @@ static int __init init_kprobes(void)
75962 {
75963 int i, err = 0;
75964 unsigned long offset = 0, size = 0;
75965- char *modname, namebuf[128];
75966+ char *modname, namebuf[KSYM_NAME_LEN];
75967 const char *symbol_name;
75968 void *addr;
75969 struct kprobe_blackpoint *kb;
75970@@ -2148,11 +2148,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
75971 kprobe_type = "k";
75972
75973 if (sym)
75974- seq_printf(pi, "%p %s %s+0x%x %s ",
75975+ seq_printf(pi, "%pK %s %s+0x%x %s ",
75976 p->addr, kprobe_type, sym, offset,
75977 (modname ? modname : " "));
75978 else
75979- seq_printf(pi, "%p %s %p ",
75980+ seq_printf(pi, "%pK %s %pK ",
75981 p->addr, kprobe_type, p->addr);
75982
75983 if (!pp)
75984@@ -2190,7 +2190,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
75985 const char *sym = NULL;
75986 unsigned int i = *(loff_t *) v;
75987 unsigned long offset = 0;
75988- char *modname, namebuf[128];
75989+ char *modname, namebuf[KSYM_NAME_LEN];
75990
75991 head = &kprobe_table[i];
75992 preempt_disable();
75993diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
75994index 6ada93c..dce7d5d 100644
75995--- a/kernel/ksysfs.c
75996+++ b/kernel/ksysfs.c
75997@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
75998 {
75999 if (count+1 > UEVENT_HELPER_PATH_LEN)
76000 return -ENOENT;
76001+ if (!capable(CAP_SYS_ADMIN))
76002+ return -EPERM;
76003 memcpy(uevent_helper, buf, count);
76004 uevent_helper[count] = '\0';
76005 if (count && uevent_helper[count-1] == '\n')
76006@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
76007 return count;
76008 }
76009
76010-static struct bin_attribute notes_attr = {
76011+static bin_attribute_no_const notes_attr __read_only = {
76012 .attr = {
76013 .name = "notes",
76014 .mode = S_IRUGO,
76015diff --git a/kernel/lockdep.c b/kernel/lockdep.c
76016index 7981e5b..7f2105c 100644
76017--- a/kernel/lockdep.c
76018+++ b/kernel/lockdep.c
76019@@ -590,6 +590,10 @@ static int static_obj(void *obj)
76020 end = (unsigned long) &_end,
76021 addr = (unsigned long) obj;
76022
76023+#ifdef CONFIG_PAX_KERNEXEC
76024+ start = ktla_ktva(start);
76025+#endif
76026+
76027 /*
76028 * static variable?
76029 */
76030@@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
76031 if (!static_obj(lock->key)) {
76032 debug_locks_off();
76033 printk("INFO: trying to register non-static key.\n");
76034+ printk("lock:%pS key:%pS.\n", lock, lock->key);
76035 printk("the code is fine but needs lockdep annotation.\n");
76036 printk("turning off the locking correctness validator.\n");
76037 dump_stack();
76038@@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
76039 if (!class)
76040 return 0;
76041 }
76042- atomic_inc((atomic_t *)&class->ops);
76043+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
76044 if (very_verbose(class)) {
76045 printk("\nacquire class [%p] %s", class->key, class->name);
76046 if (class->name_version > 1)
76047diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
76048index b2c71c5..7b88d63 100644
76049--- a/kernel/lockdep_proc.c
76050+++ b/kernel/lockdep_proc.c
76051@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
76052 return 0;
76053 }
76054
76055- seq_printf(m, "%p", class->key);
76056+ seq_printf(m, "%pK", class->key);
76057 #ifdef CONFIG_DEBUG_LOCKDEP
76058 seq_printf(m, " OPS:%8ld", class->ops);
76059 #endif
76060@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
76061
76062 list_for_each_entry(entry, &class->locks_after, entry) {
76063 if (entry->distance == 1) {
76064- seq_printf(m, " -> [%p] ", entry->class->key);
76065+ seq_printf(m, " -> [%pK] ", entry->class->key);
76066 print_name(m, entry->class);
76067 seq_puts(m, "\n");
76068 }
76069@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
76070 if (!class->key)
76071 continue;
76072
76073- seq_printf(m, "[%p] ", class->key);
76074+ seq_printf(m, "[%pK] ", class->key);
76075 print_name(m, class);
76076 seq_puts(m, "\n");
76077 }
76078@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
76079 if (!i)
76080 seq_line(m, '-', 40-namelen, namelen);
76081
76082- snprintf(ip, sizeof(ip), "[<%p>]",
76083+ snprintf(ip, sizeof(ip), "[<%pK>]",
76084 (void *)class->contention_point[i]);
76085 seq_printf(m, "%40s %14lu %29s %pS\n",
76086 name, stats->contention_point[i],
76087@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
76088 if (!i)
76089 seq_line(m, '-', 40-namelen, namelen);
76090
76091- snprintf(ip, sizeof(ip), "[<%p>]",
76092+ snprintf(ip, sizeof(ip), "[<%pK>]",
76093 (void *)class->contending_point[i]);
76094 seq_printf(m, "%40s %14lu %29s %pS\n",
76095 name, stats->contending_point[i],
76096diff --git a/kernel/module.c b/kernel/module.c
76097index eab0827..f488603 100644
76098--- a/kernel/module.c
76099+++ b/kernel/module.c
76100@@ -61,6 +61,7 @@
76101 #include <linux/pfn.h>
76102 #include <linux/bsearch.h>
76103 #include <linux/fips.h>
76104+#include <linux/grsecurity.h>
76105 #include <uapi/linux/module.h>
76106 #include "module-internal.h"
76107
76108@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
76109
76110 /* Bounds of module allocation, for speeding __module_address.
76111 * Protected by module_mutex. */
76112-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
76113+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
76114+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
76115
76116 int register_module_notifier(struct notifier_block * nb)
76117 {
76118@@ -322,7 +324,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
76119 return true;
76120
76121 list_for_each_entry_rcu(mod, &modules, list) {
76122- struct symsearch arr[] = {
76123+ struct symsearch modarr[] = {
76124 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
76125 NOT_GPL_ONLY, false },
76126 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
76127@@ -347,7 +349,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
76128 if (mod->state == MODULE_STATE_UNFORMED)
76129 continue;
76130
76131- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
76132+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
76133 return true;
76134 }
76135 return false;
76136@@ -484,7 +486,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
76137 static int percpu_modalloc(struct module *mod,
76138 unsigned long size, unsigned long align)
76139 {
76140- if (align > PAGE_SIZE) {
76141+ if (align-1 >= PAGE_SIZE) {
76142 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
76143 mod->name, align, PAGE_SIZE);
76144 align = PAGE_SIZE;
76145@@ -1088,7 +1090,7 @@ struct module_attribute module_uevent =
76146 static ssize_t show_coresize(struct module_attribute *mattr,
76147 struct module_kobject *mk, char *buffer)
76148 {
76149- return sprintf(buffer, "%u\n", mk->mod->core_size);
76150+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
76151 }
76152
76153 static struct module_attribute modinfo_coresize =
76154@@ -1097,7 +1099,7 @@ static struct module_attribute modinfo_coresize =
76155 static ssize_t show_initsize(struct module_attribute *mattr,
76156 struct module_kobject *mk, char *buffer)
76157 {
76158- return sprintf(buffer, "%u\n", mk->mod->init_size);
76159+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
76160 }
76161
76162 static struct module_attribute modinfo_initsize =
76163@@ -1311,7 +1313,7 @@ resolve_symbol_wait(struct module *mod,
76164 */
76165 #ifdef CONFIG_SYSFS
76166
76167-#ifdef CONFIG_KALLSYMS
76168+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
76169 static inline bool sect_empty(const Elf_Shdr *sect)
76170 {
76171 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
76172@@ -1451,7 +1453,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
76173 {
76174 unsigned int notes, loaded, i;
76175 struct module_notes_attrs *notes_attrs;
76176- struct bin_attribute *nattr;
76177+ bin_attribute_no_const *nattr;
76178
76179 /* failed to create section attributes, so can't create notes */
76180 if (!mod->sect_attrs)
76181@@ -1563,7 +1565,7 @@ static void del_usage_links(struct module *mod)
76182 static int module_add_modinfo_attrs(struct module *mod)
76183 {
76184 struct module_attribute *attr;
76185- struct module_attribute *temp_attr;
76186+ module_attribute_no_const *temp_attr;
76187 int error = 0;
76188 int i;
76189
76190@@ -1777,21 +1779,21 @@ static void set_section_ro_nx(void *base,
76191
76192 static void unset_module_core_ro_nx(struct module *mod)
76193 {
76194- set_page_attributes(mod->module_core + mod->core_text_size,
76195- mod->module_core + mod->core_size,
76196+ set_page_attributes(mod->module_core_rw,
76197+ mod->module_core_rw + mod->core_size_rw,
76198 set_memory_x);
76199- set_page_attributes(mod->module_core,
76200- mod->module_core + mod->core_ro_size,
76201+ set_page_attributes(mod->module_core_rx,
76202+ mod->module_core_rx + mod->core_size_rx,
76203 set_memory_rw);
76204 }
76205
76206 static void unset_module_init_ro_nx(struct module *mod)
76207 {
76208- set_page_attributes(mod->module_init + mod->init_text_size,
76209- mod->module_init + mod->init_size,
76210+ set_page_attributes(mod->module_init_rw,
76211+ mod->module_init_rw + mod->init_size_rw,
76212 set_memory_x);
76213- set_page_attributes(mod->module_init,
76214- mod->module_init + mod->init_ro_size,
76215+ set_page_attributes(mod->module_init_rx,
76216+ mod->module_init_rx + mod->init_size_rx,
76217 set_memory_rw);
76218 }
76219
76220@@ -1804,14 +1806,14 @@ void set_all_modules_text_rw(void)
76221 list_for_each_entry_rcu(mod, &modules, list) {
76222 if (mod->state == MODULE_STATE_UNFORMED)
76223 continue;
76224- if ((mod->module_core) && (mod->core_text_size)) {
76225- set_page_attributes(mod->module_core,
76226- mod->module_core + mod->core_text_size,
76227+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
76228+ set_page_attributes(mod->module_core_rx,
76229+ mod->module_core_rx + mod->core_size_rx,
76230 set_memory_rw);
76231 }
76232- if ((mod->module_init) && (mod->init_text_size)) {
76233- set_page_attributes(mod->module_init,
76234- mod->module_init + mod->init_text_size,
76235+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
76236+ set_page_attributes(mod->module_init_rx,
76237+ mod->module_init_rx + mod->init_size_rx,
76238 set_memory_rw);
76239 }
76240 }
76241@@ -1827,14 +1829,14 @@ void set_all_modules_text_ro(void)
76242 list_for_each_entry_rcu(mod, &modules, list) {
76243 if (mod->state == MODULE_STATE_UNFORMED)
76244 continue;
76245- if ((mod->module_core) && (mod->core_text_size)) {
76246- set_page_attributes(mod->module_core,
76247- mod->module_core + mod->core_text_size,
76248+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
76249+ set_page_attributes(mod->module_core_rx,
76250+ mod->module_core_rx + mod->core_size_rx,
76251 set_memory_ro);
76252 }
76253- if ((mod->module_init) && (mod->init_text_size)) {
76254- set_page_attributes(mod->module_init,
76255- mod->module_init + mod->init_text_size,
76256+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
76257+ set_page_attributes(mod->module_init_rx,
76258+ mod->module_init_rx + mod->init_size_rx,
76259 set_memory_ro);
76260 }
76261 }
76262@@ -1880,16 +1882,19 @@ static void free_module(struct module *mod)
76263
76264 /* This may be NULL, but that's OK */
76265 unset_module_init_ro_nx(mod);
76266- module_free(mod, mod->module_init);
76267+ module_free(mod, mod->module_init_rw);
76268+ module_free_exec(mod, mod->module_init_rx);
76269 kfree(mod->args);
76270 percpu_modfree(mod);
76271
76272 /* Free lock-classes: */
76273- lockdep_free_key_range(mod->module_core, mod->core_size);
76274+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
76275+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
76276
76277 /* Finally, free the core (containing the module structure) */
76278 unset_module_core_ro_nx(mod);
76279- module_free(mod, mod->module_core);
76280+ module_free_exec(mod, mod->module_core_rx);
76281+ module_free(mod, mod->module_core_rw);
76282
76283 #ifdef CONFIG_MPU
76284 update_protections(current->mm);
76285@@ -1959,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
76286 int ret = 0;
76287 const struct kernel_symbol *ksym;
76288
76289+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76290+ int is_fs_load = 0;
76291+ int register_filesystem_found = 0;
76292+ char *p;
76293+
76294+ p = strstr(mod->args, "grsec_modharden_fs");
76295+ if (p) {
76296+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
76297+ /* copy \0 as well */
76298+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
76299+ is_fs_load = 1;
76300+ }
76301+#endif
76302+
76303 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
76304 const char *name = info->strtab + sym[i].st_name;
76305
76306+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76307+ /* it's a real shame this will never get ripped and copied
76308+ upstream! ;(
76309+ */
76310+ if (is_fs_load && !strcmp(name, "register_filesystem"))
76311+ register_filesystem_found = 1;
76312+#endif
76313+
76314 switch (sym[i].st_shndx) {
76315 case SHN_COMMON:
76316 /* We compiled with -fno-common. These are not
76317@@ -1982,7 +2009,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
76318 ksym = resolve_symbol_wait(mod, info, name);
76319 /* Ok if resolved. */
76320 if (ksym && !IS_ERR(ksym)) {
76321+ pax_open_kernel();
76322 sym[i].st_value = ksym->value;
76323+ pax_close_kernel();
76324 break;
76325 }
76326
76327@@ -2001,11 +2030,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
76328 secbase = (unsigned long)mod_percpu(mod);
76329 else
76330 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
76331+ pax_open_kernel();
76332 sym[i].st_value += secbase;
76333+ pax_close_kernel();
76334 break;
76335 }
76336 }
76337
76338+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76339+ if (is_fs_load && !register_filesystem_found) {
76340+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
76341+ ret = -EPERM;
76342+ }
76343+#endif
76344+
76345 return ret;
76346 }
76347
76348@@ -2089,22 +2127,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
76349 || s->sh_entsize != ~0UL
76350 || strstarts(sname, ".init"))
76351 continue;
76352- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
76353+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
76354+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
76355+ else
76356+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
76357 pr_debug("\t%s\n", sname);
76358 }
76359- switch (m) {
76360- case 0: /* executable */
76361- mod->core_size = debug_align(mod->core_size);
76362- mod->core_text_size = mod->core_size;
76363- break;
76364- case 1: /* RO: text and ro-data */
76365- mod->core_size = debug_align(mod->core_size);
76366- mod->core_ro_size = mod->core_size;
76367- break;
76368- case 3: /* whole core */
76369- mod->core_size = debug_align(mod->core_size);
76370- break;
76371- }
76372 }
76373
76374 pr_debug("Init section allocation order:\n");
76375@@ -2118,23 +2146,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
76376 || s->sh_entsize != ~0UL
76377 || !strstarts(sname, ".init"))
76378 continue;
76379- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
76380- | INIT_OFFSET_MASK);
76381+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
76382+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
76383+ else
76384+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
76385+ s->sh_entsize |= INIT_OFFSET_MASK;
76386 pr_debug("\t%s\n", sname);
76387 }
76388- switch (m) {
76389- case 0: /* executable */
76390- mod->init_size = debug_align(mod->init_size);
76391- mod->init_text_size = mod->init_size;
76392- break;
76393- case 1: /* RO: text and ro-data */
76394- mod->init_size = debug_align(mod->init_size);
76395- mod->init_ro_size = mod->init_size;
76396- break;
76397- case 3: /* whole init */
76398- mod->init_size = debug_align(mod->init_size);
76399- break;
76400- }
76401 }
76402 }
76403
76404@@ -2306,7 +2324,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
76405
76406 /* Put symbol section at end of init part of module. */
76407 symsect->sh_flags |= SHF_ALLOC;
76408- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
76409+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
76410 info->index.sym) | INIT_OFFSET_MASK;
76411 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
76412
76413@@ -2323,13 +2341,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
76414 }
76415
76416 /* Append room for core symbols at end of core part. */
76417- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
76418- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
76419- mod->core_size += strtab_size;
76420+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
76421+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
76422+ mod->core_size_rx += strtab_size;
76423
76424 /* Put string table section at end of init part of module. */
76425 strsect->sh_flags |= SHF_ALLOC;
76426- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
76427+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
76428 info->index.str) | INIT_OFFSET_MASK;
76429 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
76430 }
76431@@ -2347,12 +2365,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
76432 /* Make sure we get permanent strtab: don't use info->strtab. */
76433 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
76434
76435+ pax_open_kernel();
76436+
76437 /* Set types up while we still have access to sections. */
76438 for (i = 0; i < mod->num_symtab; i++)
76439 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
76440
76441- mod->core_symtab = dst = mod->module_core + info->symoffs;
76442- mod->core_strtab = s = mod->module_core + info->stroffs;
76443+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
76444+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
76445 src = mod->symtab;
76446 for (ndst = i = 0; i < mod->num_symtab; i++) {
76447 if (i == 0 ||
76448@@ -2364,6 +2384,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
76449 }
76450 }
76451 mod->core_num_syms = ndst;
76452+
76453+ pax_close_kernel();
76454 }
76455 #else
76456 static inline void layout_symtab(struct module *mod, struct load_info *info)
76457@@ -2397,17 +2419,33 @@ void * __weak module_alloc(unsigned long size)
76458 return vmalloc_exec(size);
76459 }
76460
76461-static void *module_alloc_update_bounds(unsigned long size)
76462+static void *module_alloc_update_bounds_rw(unsigned long size)
76463 {
76464 void *ret = module_alloc(size);
76465
76466 if (ret) {
76467 mutex_lock(&module_mutex);
76468 /* Update module bounds. */
76469- if ((unsigned long)ret < module_addr_min)
76470- module_addr_min = (unsigned long)ret;
76471- if ((unsigned long)ret + size > module_addr_max)
76472- module_addr_max = (unsigned long)ret + size;
76473+ if ((unsigned long)ret < module_addr_min_rw)
76474+ module_addr_min_rw = (unsigned long)ret;
76475+ if ((unsigned long)ret + size > module_addr_max_rw)
76476+ module_addr_max_rw = (unsigned long)ret + size;
76477+ mutex_unlock(&module_mutex);
76478+ }
76479+ return ret;
76480+}
76481+
76482+static void *module_alloc_update_bounds_rx(unsigned long size)
76483+{
76484+ void *ret = module_alloc_exec(size);
76485+
76486+ if (ret) {
76487+ mutex_lock(&module_mutex);
76488+ /* Update module bounds. */
76489+ if ((unsigned long)ret < module_addr_min_rx)
76490+ module_addr_min_rx = (unsigned long)ret;
76491+ if ((unsigned long)ret + size > module_addr_max_rx)
76492+ module_addr_max_rx = (unsigned long)ret + size;
76493 mutex_unlock(&module_mutex);
76494 }
76495 return ret;
76496@@ -2683,8 +2721,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
76497 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
76498 {
76499 const char *modmagic = get_modinfo(info, "vermagic");
76500+ const char *license = get_modinfo(info, "license");
76501 int err;
76502
76503+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
76504+ if (!license || !license_is_gpl_compatible(license))
76505+ return -ENOEXEC;
76506+#endif
76507+
76508 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
76509 modmagic = NULL;
76510
76511@@ -2710,7 +2754,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
76512 }
76513
76514 /* Set up license info based on the info section */
76515- set_license(mod, get_modinfo(info, "license"));
76516+ set_license(mod, license);
76517
76518 return 0;
76519 }
76520@@ -2804,7 +2848,7 @@ static int move_module(struct module *mod, struct load_info *info)
76521 void *ptr;
76522
76523 /* Do the allocs. */
76524- ptr = module_alloc_update_bounds(mod->core_size);
76525+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
76526 /*
76527 * The pointer to this block is stored in the module structure
76528 * which is inside the block. Just mark it as not being a
76529@@ -2814,11 +2858,11 @@ static int move_module(struct module *mod, struct load_info *info)
76530 if (!ptr)
76531 return -ENOMEM;
76532
76533- memset(ptr, 0, mod->core_size);
76534- mod->module_core = ptr;
76535+ memset(ptr, 0, mod->core_size_rw);
76536+ mod->module_core_rw = ptr;
76537
76538- if (mod->init_size) {
76539- ptr = module_alloc_update_bounds(mod->init_size);
76540+ if (mod->init_size_rw) {
76541+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
76542 /*
76543 * The pointer to this block is stored in the module structure
76544 * which is inside the block. This block doesn't need to be
76545@@ -2827,13 +2871,45 @@ static int move_module(struct module *mod, struct load_info *info)
76546 */
76547 kmemleak_ignore(ptr);
76548 if (!ptr) {
76549- module_free(mod, mod->module_core);
76550+ module_free(mod, mod->module_core_rw);
76551 return -ENOMEM;
76552 }
76553- memset(ptr, 0, mod->init_size);
76554- mod->module_init = ptr;
76555+ memset(ptr, 0, mod->init_size_rw);
76556+ mod->module_init_rw = ptr;
76557 } else
76558- mod->module_init = NULL;
76559+ mod->module_init_rw = NULL;
76560+
76561+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
76562+ kmemleak_not_leak(ptr);
76563+ if (!ptr) {
76564+ if (mod->module_init_rw)
76565+ module_free(mod, mod->module_init_rw);
76566+ module_free(mod, mod->module_core_rw);
76567+ return -ENOMEM;
76568+ }
76569+
76570+ pax_open_kernel();
76571+ memset(ptr, 0, mod->core_size_rx);
76572+ pax_close_kernel();
76573+ mod->module_core_rx = ptr;
76574+
76575+ if (mod->init_size_rx) {
76576+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
76577+ kmemleak_ignore(ptr);
76578+ if (!ptr && mod->init_size_rx) {
76579+ module_free_exec(mod, mod->module_core_rx);
76580+ if (mod->module_init_rw)
76581+ module_free(mod, mod->module_init_rw);
76582+ module_free(mod, mod->module_core_rw);
76583+ return -ENOMEM;
76584+ }
76585+
76586+ pax_open_kernel();
76587+ memset(ptr, 0, mod->init_size_rx);
76588+ pax_close_kernel();
76589+ mod->module_init_rx = ptr;
76590+ } else
76591+ mod->module_init_rx = NULL;
76592
76593 /* Transfer each section which specifies SHF_ALLOC */
76594 pr_debug("final section addresses:\n");
76595@@ -2844,16 +2920,45 @@ static int move_module(struct module *mod, struct load_info *info)
76596 if (!(shdr->sh_flags & SHF_ALLOC))
76597 continue;
76598
76599- if (shdr->sh_entsize & INIT_OFFSET_MASK)
76600- dest = mod->module_init
76601- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
76602- else
76603- dest = mod->module_core + shdr->sh_entsize;
76604+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
76605+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
76606+ dest = mod->module_init_rw
76607+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
76608+ else
76609+ dest = mod->module_init_rx
76610+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
76611+ } else {
76612+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
76613+ dest = mod->module_core_rw + shdr->sh_entsize;
76614+ else
76615+ dest = mod->module_core_rx + shdr->sh_entsize;
76616+ }
76617+
76618+ if (shdr->sh_type != SHT_NOBITS) {
76619+
76620+#ifdef CONFIG_PAX_KERNEXEC
76621+#ifdef CONFIG_X86_64
76622+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
76623+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
76624+#endif
76625+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
76626+ pax_open_kernel();
76627+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
76628+ pax_close_kernel();
76629+ } else
76630+#endif
76631
76632- if (shdr->sh_type != SHT_NOBITS)
76633 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
76634+ }
76635 /* Update sh_addr to point to copy in image. */
76636- shdr->sh_addr = (unsigned long)dest;
76637+
76638+#ifdef CONFIG_PAX_KERNEXEC
76639+ if (shdr->sh_flags & SHF_EXECINSTR)
76640+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
76641+ else
76642+#endif
76643+
76644+ shdr->sh_addr = (unsigned long)dest;
76645 pr_debug("\t0x%lx %s\n",
76646 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
76647 }
76648@@ -2908,12 +3013,12 @@ static void flush_module_icache(const struct module *mod)
76649 * Do it before processing of module parameters, so the module
76650 * can provide parameter accessor functions of its own.
76651 */
76652- if (mod->module_init)
76653- flush_icache_range((unsigned long)mod->module_init,
76654- (unsigned long)mod->module_init
76655- + mod->init_size);
76656- flush_icache_range((unsigned long)mod->module_core,
76657- (unsigned long)mod->module_core + mod->core_size);
76658+ if (mod->module_init_rx)
76659+ flush_icache_range((unsigned long)mod->module_init_rx,
76660+ (unsigned long)mod->module_init_rx
76661+ + mod->init_size_rx);
76662+ flush_icache_range((unsigned long)mod->module_core_rx,
76663+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
76664
76665 set_fs(old_fs);
76666 }
76667@@ -2983,8 +3088,10 @@ out:
76668 static void module_deallocate(struct module *mod, struct load_info *info)
76669 {
76670 percpu_modfree(mod);
76671- module_free(mod, mod->module_init);
76672- module_free(mod, mod->module_core);
76673+ module_free_exec(mod, mod->module_init_rx);
76674+ module_free_exec(mod, mod->module_core_rx);
76675+ module_free(mod, mod->module_init_rw);
76676+ module_free(mod, mod->module_core_rw);
76677 }
76678
76679 int __weak module_finalize(const Elf_Ehdr *hdr,
76680@@ -2997,7 +3104,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
76681 static int post_relocation(struct module *mod, const struct load_info *info)
76682 {
76683 /* Sort exception table now relocations are done. */
76684+ pax_open_kernel();
76685 sort_extable(mod->extable, mod->extable + mod->num_exentries);
76686+ pax_close_kernel();
76687
76688 /* Copy relocated percpu area over. */
76689 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
76690@@ -3051,16 +3160,16 @@ static int do_init_module(struct module *mod)
76691 MODULE_STATE_COMING, mod);
76692
76693 /* Set RO and NX regions for core */
76694- set_section_ro_nx(mod->module_core,
76695- mod->core_text_size,
76696- mod->core_ro_size,
76697- mod->core_size);
76698+ set_section_ro_nx(mod->module_core_rx,
76699+ mod->core_size_rx,
76700+ mod->core_size_rx,
76701+ mod->core_size_rx);
76702
76703 /* Set RO and NX regions for init */
76704- set_section_ro_nx(mod->module_init,
76705- mod->init_text_size,
76706- mod->init_ro_size,
76707- mod->init_size);
76708+ set_section_ro_nx(mod->module_init_rx,
76709+ mod->init_size_rx,
76710+ mod->init_size_rx,
76711+ mod->init_size_rx);
76712
76713 do_mod_ctors(mod);
76714 /* Start the module */
76715@@ -3122,11 +3231,12 @@ static int do_init_module(struct module *mod)
76716 mod->strtab = mod->core_strtab;
76717 #endif
76718 unset_module_init_ro_nx(mod);
76719- module_free(mod, mod->module_init);
76720- mod->module_init = NULL;
76721- mod->init_size = 0;
76722- mod->init_ro_size = 0;
76723- mod->init_text_size = 0;
76724+ module_free(mod, mod->module_init_rw);
76725+ module_free_exec(mod, mod->module_init_rx);
76726+ mod->module_init_rw = NULL;
76727+ mod->module_init_rx = NULL;
76728+ mod->init_size_rw = 0;
76729+ mod->init_size_rx = 0;
76730 mutex_unlock(&module_mutex);
76731 wake_up_all(&module_wq);
76732
76733@@ -3209,9 +3319,38 @@ again:
76734 if (err)
76735 goto free_unload;
76736
76737+ /* Now copy in args */
76738+ mod->args = strndup_user(uargs, ~0UL >> 1);
76739+ if (IS_ERR(mod->args)) {
76740+ err = PTR_ERR(mod->args);
76741+ goto free_unload;
76742+ }
76743+
76744 /* Set up MODINFO_ATTR fields */
76745 setup_modinfo(mod, info);
76746
76747+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76748+ {
76749+ char *p, *p2;
76750+
76751+ if (strstr(mod->args, "grsec_modharden_netdev")) {
76752+ 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);
76753+ err = -EPERM;
76754+ goto free_modinfo;
76755+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
76756+ p += sizeof("grsec_modharden_normal") - 1;
76757+ p2 = strstr(p, "_");
76758+ if (p2) {
76759+ *p2 = '\0';
76760+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
76761+ *p2 = '_';
76762+ }
76763+ err = -EPERM;
76764+ goto free_modinfo;
76765+ }
76766+ }
76767+#endif
76768+
76769 /* Fix up syms, so that st_value is a pointer to location. */
76770 err = simplify_symbols(mod, info);
76771 if (err < 0)
76772@@ -3227,13 +3366,6 @@ again:
76773
76774 flush_module_icache(mod);
76775
76776- /* Now copy in args */
76777- mod->args = strndup_user(uargs, ~0UL >> 1);
76778- if (IS_ERR(mod->args)) {
76779- err = PTR_ERR(mod->args);
76780- goto free_arch_cleanup;
76781- }
76782-
76783 dynamic_debug_setup(info->debug, info->num_debug);
76784
76785 mutex_lock(&module_mutex);
76786@@ -3278,11 +3410,10 @@ again:
76787 mutex_unlock(&module_mutex);
76788 dynamic_debug_remove(info->debug);
76789 synchronize_sched();
76790- kfree(mod->args);
76791- free_arch_cleanup:
76792 module_arch_cleanup(mod);
76793 free_modinfo:
76794 free_modinfo(mod);
76795+ kfree(mod->args);
76796 free_unload:
76797 module_unload_free(mod);
76798 unlink_mod:
76799@@ -3365,10 +3496,16 @@ static const char *get_ksymbol(struct module *mod,
76800 unsigned long nextval;
76801
76802 /* At worse, next value is at end of module */
76803- if (within_module_init(addr, mod))
76804- nextval = (unsigned long)mod->module_init+mod->init_text_size;
76805+ if (within_module_init_rx(addr, mod))
76806+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
76807+ else if (within_module_init_rw(addr, mod))
76808+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
76809+ else if (within_module_core_rx(addr, mod))
76810+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
76811+ else if (within_module_core_rw(addr, mod))
76812+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
76813 else
76814- nextval = (unsigned long)mod->module_core+mod->core_text_size;
76815+ return NULL;
76816
76817 /* Scan for closest preceding symbol, and next symbol. (ELF
76818 starts real symbols at 1). */
76819@@ -3621,7 +3758,7 @@ static int m_show(struct seq_file *m, void *p)
76820 return 0;
76821
76822 seq_printf(m, "%s %u",
76823- mod->name, mod->init_size + mod->core_size);
76824+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
76825 print_unload_info(m, mod);
76826
76827 /* Informative for users. */
76828@@ -3630,7 +3767,7 @@ static int m_show(struct seq_file *m, void *p)
76829 mod->state == MODULE_STATE_COMING ? "Loading":
76830 "Live");
76831 /* Used by oprofile and other similar tools. */
76832- seq_printf(m, " 0x%pK", mod->module_core);
76833+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
76834
76835 /* Taints info */
76836 if (mod->taints)
76837@@ -3666,7 +3803,17 @@ static const struct file_operations proc_modules_operations = {
76838
76839 static int __init proc_modules_init(void)
76840 {
76841+#ifndef CONFIG_GRKERNSEC_HIDESYM
76842+#ifdef CONFIG_GRKERNSEC_PROC_USER
76843+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
76844+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
76845+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
76846+#else
76847 proc_create("modules", 0, NULL, &proc_modules_operations);
76848+#endif
76849+#else
76850+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
76851+#endif
76852 return 0;
76853 }
76854 module_init(proc_modules_init);
76855@@ -3727,14 +3874,14 @@ struct module *__module_address(unsigned long addr)
76856 {
76857 struct module *mod;
76858
76859- if (addr < module_addr_min || addr > module_addr_max)
76860+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
76861+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
76862 return NULL;
76863
76864 list_for_each_entry_rcu(mod, &modules, list) {
76865 if (mod->state == MODULE_STATE_UNFORMED)
76866 continue;
76867- if (within_module_core(addr, mod)
76868- || within_module_init(addr, mod))
76869+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
76870 return mod;
76871 }
76872 return NULL;
76873@@ -3769,11 +3916,20 @@ bool is_module_text_address(unsigned long addr)
76874 */
76875 struct module *__module_text_address(unsigned long addr)
76876 {
76877- struct module *mod = __module_address(addr);
76878+ struct module *mod;
76879+
76880+#ifdef CONFIG_X86_32
76881+ addr = ktla_ktva(addr);
76882+#endif
76883+
76884+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
76885+ return NULL;
76886+
76887+ mod = __module_address(addr);
76888+
76889 if (mod) {
76890 /* Make sure it's within the text section. */
76891- if (!within(addr, mod->module_init, mod->init_text_size)
76892- && !within(addr, mod->module_core, mod->core_text_size))
76893+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
76894 mod = NULL;
76895 }
76896 return mod;
76897diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
76898index 7e3443f..b2a1e6b 100644
76899--- a/kernel/mutex-debug.c
76900+++ b/kernel/mutex-debug.c
76901@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
76902 }
76903
76904 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
76905- struct thread_info *ti)
76906+ struct task_struct *task)
76907 {
76908 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
76909
76910 /* Mark the current thread as blocked on the lock: */
76911- ti->task->blocked_on = waiter;
76912+ task->blocked_on = waiter;
76913 }
76914
76915 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
76916- struct thread_info *ti)
76917+ struct task_struct *task)
76918 {
76919 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
76920- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
76921- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
76922- ti->task->blocked_on = NULL;
76923+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
76924+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
76925+ task->blocked_on = NULL;
76926
76927 list_del_init(&waiter->list);
76928 waiter->task = NULL;
76929diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
76930index 0799fd3..d06ae3b 100644
76931--- a/kernel/mutex-debug.h
76932+++ b/kernel/mutex-debug.h
76933@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
76934 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
76935 extern void debug_mutex_add_waiter(struct mutex *lock,
76936 struct mutex_waiter *waiter,
76937- struct thread_info *ti);
76938+ struct task_struct *task);
76939 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
76940- struct thread_info *ti);
76941+ struct task_struct *task);
76942 extern void debug_mutex_unlock(struct mutex *lock);
76943 extern void debug_mutex_init(struct mutex *lock, const char *name,
76944 struct lock_class_key *key);
76945diff --git a/kernel/mutex.c b/kernel/mutex.c
76946index a307cc9..27fd2e9 100644
76947--- a/kernel/mutex.c
76948+++ b/kernel/mutex.c
76949@@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
76950 spin_lock_mutex(&lock->wait_lock, flags);
76951
76952 debug_mutex_lock_common(lock, &waiter);
76953- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
76954+ debug_mutex_add_waiter(lock, &waiter, task);
76955
76956 /* add waiting tasks to the end of the waitqueue (FIFO): */
76957 list_add_tail(&waiter.list, &lock->wait_list);
76958@@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
76959 * TASK_UNINTERRUPTIBLE case.)
76960 */
76961 if (unlikely(signal_pending_state(state, task))) {
76962- mutex_remove_waiter(lock, &waiter,
76963- task_thread_info(task));
76964+ mutex_remove_waiter(lock, &waiter, task);
76965 mutex_release(&lock->dep_map, 1, ip);
76966 spin_unlock_mutex(&lock->wait_lock, flags);
76967
76968@@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
76969 done:
76970 lock_acquired(&lock->dep_map, ip);
76971 /* got the lock - rejoice! */
76972- mutex_remove_waiter(lock, &waiter, current_thread_info());
76973+ mutex_remove_waiter(lock, &waiter, task);
76974 mutex_set_owner(lock);
76975
76976 /* set it to 0 if there are no waiters left: */
76977diff --git a/kernel/notifier.c b/kernel/notifier.c
76978index 2d5cc4c..d9ea600 100644
76979--- a/kernel/notifier.c
76980+++ b/kernel/notifier.c
76981@@ -5,6 +5,7 @@
76982 #include <linux/rcupdate.h>
76983 #include <linux/vmalloc.h>
76984 #include <linux/reboot.h>
76985+#include <linux/mm.h>
76986
76987 /*
76988 * Notifier list for kernel code which wants to be called
76989@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
76990 while ((*nl) != NULL) {
76991 if (n->priority > (*nl)->priority)
76992 break;
76993- nl = &((*nl)->next);
76994+ nl = (struct notifier_block **)&((*nl)->next);
76995 }
76996- n->next = *nl;
76997+ pax_open_kernel();
76998+ *(const void **)&n->next = *nl;
76999 rcu_assign_pointer(*nl, n);
77000+ pax_close_kernel();
77001 return 0;
77002 }
77003
77004@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
77005 return 0;
77006 if (n->priority > (*nl)->priority)
77007 break;
77008- nl = &((*nl)->next);
77009+ nl = (struct notifier_block **)&((*nl)->next);
77010 }
77011- n->next = *nl;
77012+ pax_open_kernel();
77013+ *(const void **)&n->next = *nl;
77014 rcu_assign_pointer(*nl, n);
77015+ pax_close_kernel();
77016 return 0;
77017 }
77018
77019@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
77020 {
77021 while ((*nl) != NULL) {
77022 if ((*nl) == n) {
77023+ pax_open_kernel();
77024 rcu_assign_pointer(*nl, n->next);
77025+ pax_close_kernel();
77026 return 0;
77027 }
77028- nl = &((*nl)->next);
77029+ nl = (struct notifier_block **)&((*nl)->next);
77030 }
77031 return -ENOENT;
77032 }
77033diff --git a/kernel/panic.c b/kernel/panic.c
77034index e1b2822..5edc1d9 100644
77035--- a/kernel/panic.c
77036+++ b/kernel/panic.c
77037@@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
77038 const char *board;
77039
77040 printk(KERN_WARNING "------------[ cut here ]------------\n");
77041- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
77042+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
77043 board = dmi_get_system_info(DMI_PRODUCT_NAME);
77044 if (board)
77045 printk(KERN_WARNING "Hardware name: %s\n", board);
77046@@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
77047 */
77048 void __stack_chk_fail(void)
77049 {
77050- panic("stack-protector: Kernel stack is corrupted in: %p\n",
77051+ dump_stack();
77052+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
77053 __builtin_return_address(0));
77054 }
77055 EXPORT_SYMBOL(__stack_chk_fail);
77056diff --git a/kernel/pid.c b/kernel/pid.c
77057index f2c6a68..4922d97 100644
77058--- a/kernel/pid.c
77059+++ b/kernel/pid.c
77060@@ -33,6 +33,7 @@
77061 #include <linux/rculist.h>
77062 #include <linux/bootmem.h>
77063 #include <linux/hash.h>
77064+#include <linux/security.h>
77065 #include <linux/pid_namespace.h>
77066 #include <linux/init_task.h>
77067 #include <linux/syscalls.h>
77068@@ -46,7 +47,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
77069
77070 int pid_max = PID_MAX_DEFAULT;
77071
77072-#define RESERVED_PIDS 300
77073+#define RESERVED_PIDS 500
77074
77075 int pid_max_min = RESERVED_PIDS + 1;
77076 int pid_max_max = PID_MAX_LIMIT;
77077@@ -441,10 +442,18 @@ EXPORT_SYMBOL(pid_task);
77078 */
77079 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
77080 {
77081+ struct task_struct *task;
77082+
77083 rcu_lockdep_assert(rcu_read_lock_held(),
77084 "find_task_by_pid_ns() needs rcu_read_lock()"
77085 " protection");
77086- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
77087+
77088+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
77089+
77090+ if (gr_pid_is_chrooted(task))
77091+ return NULL;
77092+
77093+ return task;
77094 }
77095
77096 struct task_struct *find_task_by_vpid(pid_t vnr)
77097@@ -452,6 +461,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
77098 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
77099 }
77100
77101+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
77102+{
77103+ rcu_lockdep_assert(rcu_read_lock_held(),
77104+ "find_task_by_pid_ns() needs rcu_read_lock()"
77105+ " protection");
77106+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
77107+}
77108+
77109 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
77110 {
77111 struct pid *pid;
77112diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
77113index bea15bd..789f3d0 100644
77114--- a/kernel/pid_namespace.c
77115+++ b/kernel/pid_namespace.c
77116@@ -249,7 +249,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
77117 void __user *buffer, size_t *lenp, loff_t *ppos)
77118 {
77119 struct pid_namespace *pid_ns = task_active_pid_ns(current);
77120- struct ctl_table tmp = *table;
77121+ ctl_table_no_const tmp = *table;
77122
77123 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
77124 return -EPERM;
77125diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
77126index 942ca27..111e609 100644
77127--- a/kernel/posix-cpu-timers.c
77128+++ b/kernel/posix-cpu-timers.c
77129@@ -1576,14 +1576,14 @@ struct k_clock clock_posix_cpu = {
77130
77131 static __init int init_posix_cpu_timers(void)
77132 {
77133- struct k_clock process = {
77134+ static struct k_clock process = {
77135 .clock_getres = process_cpu_clock_getres,
77136 .clock_get = process_cpu_clock_get,
77137 .timer_create = process_cpu_timer_create,
77138 .nsleep = process_cpu_nsleep,
77139 .nsleep_restart = process_cpu_nsleep_restart,
77140 };
77141- struct k_clock thread = {
77142+ static struct k_clock thread = {
77143 .clock_getres = thread_cpu_clock_getres,
77144 .clock_get = thread_cpu_clock_get,
77145 .timer_create = thread_cpu_timer_create,
77146diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
77147index e885be1..380fe76 100644
77148--- a/kernel/posix-timers.c
77149+++ b/kernel/posix-timers.c
77150@@ -43,6 +43,7 @@
77151 #include <linux/idr.h>
77152 #include <linux/posix-clock.h>
77153 #include <linux/posix-timers.h>
77154+#include <linux/grsecurity.h>
77155 #include <linux/syscalls.h>
77156 #include <linux/wait.h>
77157 #include <linux/workqueue.h>
77158@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
77159 * which we beg off on and pass to do_sys_settimeofday().
77160 */
77161
77162-static struct k_clock posix_clocks[MAX_CLOCKS];
77163+static struct k_clock *posix_clocks[MAX_CLOCKS];
77164
77165 /*
77166 * These ones are defined below.
77167@@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
77168 */
77169 static __init int init_posix_timers(void)
77170 {
77171- struct k_clock clock_realtime = {
77172+ static struct k_clock clock_realtime = {
77173 .clock_getres = hrtimer_get_res,
77174 .clock_get = posix_clock_realtime_get,
77175 .clock_set = posix_clock_realtime_set,
77176@@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
77177 .timer_get = common_timer_get,
77178 .timer_del = common_timer_del,
77179 };
77180- struct k_clock clock_monotonic = {
77181+ static struct k_clock clock_monotonic = {
77182 .clock_getres = hrtimer_get_res,
77183 .clock_get = posix_ktime_get_ts,
77184 .nsleep = common_nsleep,
77185@@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
77186 .timer_get = common_timer_get,
77187 .timer_del = common_timer_del,
77188 };
77189- struct k_clock clock_monotonic_raw = {
77190+ static struct k_clock clock_monotonic_raw = {
77191 .clock_getres = hrtimer_get_res,
77192 .clock_get = posix_get_monotonic_raw,
77193 };
77194- struct k_clock clock_realtime_coarse = {
77195+ static struct k_clock clock_realtime_coarse = {
77196 .clock_getres = posix_get_coarse_res,
77197 .clock_get = posix_get_realtime_coarse,
77198 };
77199- struct k_clock clock_monotonic_coarse = {
77200+ static struct k_clock clock_monotonic_coarse = {
77201 .clock_getres = posix_get_coarse_res,
77202 .clock_get = posix_get_monotonic_coarse,
77203 };
77204- struct k_clock clock_boottime = {
77205+ static struct k_clock clock_boottime = {
77206 .clock_getres = hrtimer_get_res,
77207 .clock_get = posix_get_boottime,
77208 .nsleep = common_nsleep,
77209@@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
77210 return;
77211 }
77212
77213- posix_clocks[clock_id] = *new_clock;
77214+ posix_clocks[clock_id] = new_clock;
77215 }
77216 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
77217
77218@@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
77219 return (id & CLOCKFD_MASK) == CLOCKFD ?
77220 &clock_posix_dynamic : &clock_posix_cpu;
77221
77222- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
77223+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
77224 return NULL;
77225- return &posix_clocks[id];
77226+ return posix_clocks[id];
77227 }
77228
77229 static int common_timer_create(struct k_itimer *new_timer)
77230@@ -966,6 +967,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
77231 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
77232 return -EFAULT;
77233
77234+ /* only the CLOCK_REALTIME clock can be set, all other clocks
77235+ have their clock_set fptr set to a nosettime dummy function
77236+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
77237+ call common_clock_set, which calls do_sys_settimeofday, which
77238+ we hook
77239+ */
77240+
77241 return kc->clock_set(which_clock, &new_tp);
77242 }
77243
77244diff --git a/kernel/power/process.c b/kernel/power/process.c
77245index d5a258b..4271191 100644
77246--- a/kernel/power/process.c
77247+++ b/kernel/power/process.c
77248@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
77249 u64 elapsed_csecs64;
77250 unsigned int elapsed_csecs;
77251 bool wakeup = false;
77252+ bool timedout = false;
77253
77254 do_gettimeofday(&start);
77255
77256@@ -43,13 +44,20 @@ static int try_to_freeze_tasks(bool user_only)
77257
77258 while (true) {
77259 todo = 0;
77260+ if (time_after(jiffies, end_time))
77261+ timedout = true;
77262 read_lock(&tasklist_lock);
77263 do_each_thread(g, p) {
77264 if (p == current || !freeze_task(p))
77265 continue;
77266
77267- if (!freezer_should_skip(p))
77268+ if (!freezer_should_skip(p)) {
77269 todo++;
77270+ if (timedout) {
77271+ printk(KERN_ERR "Task refusing to freeze:\n");
77272+ sched_show_task(p);
77273+ }
77274+ }
77275 } while_each_thread(g, p);
77276 read_unlock(&tasklist_lock);
77277
77278@@ -58,7 +66,7 @@ static int try_to_freeze_tasks(bool user_only)
77279 todo += wq_busy;
77280 }
77281
77282- if (!todo || time_after(jiffies, end_time))
77283+ if (!todo || timedout)
77284 break;
77285
77286 if (pm_wakeup_pending()) {
77287diff --git a/kernel/printk.c b/kernel/printk.c
77288index 267ce78..2487112 100644
77289--- a/kernel/printk.c
77290+++ b/kernel/printk.c
77291@@ -609,11 +609,17 @@ static unsigned int devkmsg_poll(struct file *file, poll_table *wait)
77292 return ret;
77293 }
77294
77295+static int check_syslog_permissions(int type, bool from_file);
77296+
77297 static int devkmsg_open(struct inode *inode, struct file *file)
77298 {
77299 struct devkmsg_user *user;
77300 int err;
77301
77302+ err = check_syslog_permissions(SYSLOG_ACTION_OPEN, SYSLOG_FROM_FILE);
77303+ if (err)
77304+ return err;
77305+
77306 /* write-only does not need any file context */
77307 if ((file->f_flags & O_ACCMODE) == O_WRONLY)
77308 return 0;
77309@@ -822,7 +828,7 @@ static int syslog_action_restricted(int type)
77310 if (dmesg_restrict)
77311 return 1;
77312 /* Unless restricted, we allow "read all" and "get buffer size" for everybody */
77313- return type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
77314+ return type != SYSLOG_ACTION_OPEN && type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
77315 }
77316
77317 static int check_syslog_permissions(int type, bool from_file)
77318@@ -834,6 +840,11 @@ static int check_syslog_permissions(int type, bool from_file)
77319 if (from_file && type != SYSLOG_ACTION_OPEN)
77320 return 0;
77321
77322+#ifdef CONFIG_GRKERNSEC_DMESG
77323+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
77324+ return -EPERM;
77325+#endif
77326+
77327 if (syslog_action_restricted(type)) {
77328 if (capable(CAP_SYSLOG))
77329 return 0;
77330diff --git a/kernel/profile.c b/kernel/profile.c
77331index 1f39181..86093471 100644
77332--- a/kernel/profile.c
77333+++ b/kernel/profile.c
77334@@ -40,7 +40,7 @@ struct profile_hit {
77335 /* Oprofile timer tick hook */
77336 static int (*timer_hook)(struct pt_regs *) __read_mostly;
77337
77338-static atomic_t *prof_buffer;
77339+static atomic_unchecked_t *prof_buffer;
77340 static unsigned long prof_len, prof_shift;
77341
77342 int prof_on __read_mostly;
77343@@ -282,7 +282,7 @@ static void profile_flip_buffers(void)
77344 hits[i].pc = 0;
77345 continue;
77346 }
77347- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
77348+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
77349 hits[i].hits = hits[i].pc = 0;
77350 }
77351 }
77352@@ -343,9 +343,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
77353 * Add the current hit(s) and flush the write-queue out
77354 * to the global buffer:
77355 */
77356- atomic_add(nr_hits, &prof_buffer[pc]);
77357+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
77358 for (i = 0; i < NR_PROFILE_HIT; ++i) {
77359- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
77360+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
77361 hits[i].pc = hits[i].hits = 0;
77362 }
77363 out:
77364@@ -420,7 +420,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
77365 {
77366 unsigned long pc;
77367 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
77368- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
77369+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
77370 }
77371 #endif /* !CONFIG_SMP */
77372
77373@@ -518,7 +518,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
77374 return -EFAULT;
77375 buf++; p++; count--; read++;
77376 }
77377- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
77378+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
77379 if (copy_to_user(buf, (void *)pnt, count))
77380 return -EFAULT;
77381 read += count;
77382@@ -549,7 +549,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
77383 }
77384 #endif
77385 profile_discard_flip_buffers();
77386- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
77387+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
77388 return count;
77389 }
77390
77391diff --git a/kernel/ptrace.c b/kernel/ptrace.c
77392index 6cbeaae..cfe7ff0 100644
77393--- a/kernel/ptrace.c
77394+++ b/kernel/ptrace.c
77395@@ -324,7 +324,7 @@ static int ptrace_attach(struct task_struct *task, long request,
77396 if (seize)
77397 flags |= PT_SEIZED;
77398 rcu_read_lock();
77399- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
77400+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
77401 flags |= PT_PTRACE_CAP;
77402 rcu_read_unlock();
77403 task->ptrace = flags;
77404@@ -535,7 +535,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
77405 break;
77406 return -EIO;
77407 }
77408- if (copy_to_user(dst, buf, retval))
77409+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
77410 return -EFAULT;
77411 copied += retval;
77412 src += retval;
77413@@ -720,7 +720,7 @@ int ptrace_request(struct task_struct *child, long request,
77414 bool seized = child->ptrace & PT_SEIZED;
77415 int ret = -EIO;
77416 siginfo_t siginfo, *si;
77417- void __user *datavp = (void __user *) data;
77418+ void __user *datavp = (__force void __user *) data;
77419 unsigned long __user *datalp = datavp;
77420 unsigned long flags;
77421
77422@@ -922,14 +922,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
77423 goto out;
77424 }
77425
77426+ if (gr_handle_ptrace(child, request)) {
77427+ ret = -EPERM;
77428+ goto out_put_task_struct;
77429+ }
77430+
77431 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
77432 ret = ptrace_attach(child, request, addr, data);
77433 /*
77434 * Some architectures need to do book-keeping after
77435 * a ptrace attach.
77436 */
77437- if (!ret)
77438+ if (!ret) {
77439 arch_ptrace_attach(child);
77440+ gr_audit_ptrace(child);
77441+ }
77442 goto out_put_task_struct;
77443 }
77444
77445@@ -957,7 +964,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
77446 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
77447 if (copied != sizeof(tmp))
77448 return -EIO;
77449- return put_user(tmp, (unsigned long __user *)data);
77450+ return put_user(tmp, (__force unsigned long __user *)data);
77451 }
77452
77453 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
77454@@ -1051,7 +1058,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
77455 }
77456
77457 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77458- compat_long_t addr, compat_long_t data)
77459+ compat_ulong_t addr, compat_ulong_t data)
77460 {
77461 struct task_struct *child;
77462 long ret;
77463@@ -1067,14 +1074,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77464 goto out;
77465 }
77466
77467+ if (gr_handle_ptrace(child, request)) {
77468+ ret = -EPERM;
77469+ goto out_put_task_struct;
77470+ }
77471+
77472 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
77473 ret = ptrace_attach(child, request, addr, data);
77474 /*
77475 * Some architectures need to do book-keeping after
77476 * a ptrace attach.
77477 */
77478- if (!ret)
77479+ if (!ret) {
77480 arch_ptrace_attach(child);
77481+ gr_audit_ptrace(child);
77482+ }
77483 goto out_put_task_struct;
77484 }
77485
77486diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
77487index e7dce58..ad0d7b7 100644
77488--- a/kernel/rcutiny.c
77489+++ b/kernel/rcutiny.c
77490@@ -46,7 +46,7 @@
77491 struct rcu_ctrlblk;
77492 static void invoke_rcu_callbacks(void);
77493 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
77494-static void rcu_process_callbacks(struct softirq_action *unused);
77495+static void rcu_process_callbacks(void);
77496 static void __call_rcu(struct rcu_head *head,
77497 void (*func)(struct rcu_head *rcu),
77498 struct rcu_ctrlblk *rcp);
77499@@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
77500 rcu_is_callbacks_kthread()));
77501 }
77502
77503-static void rcu_process_callbacks(struct softirq_action *unused)
77504+static void rcu_process_callbacks(void)
77505 {
77506 __rcu_process_callbacks(&rcu_sched_ctrlblk);
77507 __rcu_process_callbacks(&rcu_bh_ctrlblk);
77508diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
77509index f85016a..91cb03b 100644
77510--- a/kernel/rcutiny_plugin.h
77511+++ b/kernel/rcutiny_plugin.h
77512@@ -896,7 +896,7 @@ static int rcu_kthread(void *arg)
77513 have_rcu_kthread_work = morework;
77514 local_irq_restore(flags);
77515 if (work)
77516- rcu_process_callbacks(NULL);
77517+ rcu_process_callbacks();
77518 schedule_timeout_interruptible(1); /* Leave CPU for others. */
77519 }
77520
77521diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
77522index 31dea01..ad91ffb 100644
77523--- a/kernel/rcutorture.c
77524+++ b/kernel/rcutorture.c
77525@@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
77526 { 0 };
77527 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
77528 { 0 };
77529-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
77530-static atomic_t n_rcu_torture_alloc;
77531-static atomic_t n_rcu_torture_alloc_fail;
77532-static atomic_t n_rcu_torture_free;
77533-static atomic_t n_rcu_torture_mberror;
77534-static atomic_t n_rcu_torture_error;
77535+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
77536+static atomic_unchecked_t n_rcu_torture_alloc;
77537+static atomic_unchecked_t n_rcu_torture_alloc_fail;
77538+static atomic_unchecked_t n_rcu_torture_free;
77539+static atomic_unchecked_t n_rcu_torture_mberror;
77540+static atomic_unchecked_t n_rcu_torture_error;
77541 static long n_rcu_torture_barrier_error;
77542 static long n_rcu_torture_boost_ktrerror;
77543 static long n_rcu_torture_boost_rterror;
77544@@ -272,11 +272,11 @@ rcu_torture_alloc(void)
77545
77546 spin_lock_bh(&rcu_torture_lock);
77547 if (list_empty(&rcu_torture_freelist)) {
77548- atomic_inc(&n_rcu_torture_alloc_fail);
77549+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
77550 spin_unlock_bh(&rcu_torture_lock);
77551 return NULL;
77552 }
77553- atomic_inc(&n_rcu_torture_alloc);
77554+ atomic_inc_unchecked(&n_rcu_torture_alloc);
77555 p = rcu_torture_freelist.next;
77556 list_del_init(p);
77557 spin_unlock_bh(&rcu_torture_lock);
77558@@ -289,7 +289,7 @@ rcu_torture_alloc(void)
77559 static void
77560 rcu_torture_free(struct rcu_torture *p)
77561 {
77562- atomic_inc(&n_rcu_torture_free);
77563+ atomic_inc_unchecked(&n_rcu_torture_free);
77564 spin_lock_bh(&rcu_torture_lock);
77565 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
77566 spin_unlock_bh(&rcu_torture_lock);
77567@@ -409,7 +409,7 @@ rcu_torture_cb(struct rcu_head *p)
77568 i = rp->rtort_pipe_count;
77569 if (i > RCU_TORTURE_PIPE_LEN)
77570 i = RCU_TORTURE_PIPE_LEN;
77571- atomic_inc(&rcu_torture_wcount[i]);
77572+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
77573 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
77574 rp->rtort_mbtest = 0;
77575 rcu_torture_free(rp);
77576@@ -457,7 +457,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
77577 i = rp->rtort_pipe_count;
77578 if (i > RCU_TORTURE_PIPE_LEN)
77579 i = RCU_TORTURE_PIPE_LEN;
77580- atomic_inc(&rcu_torture_wcount[i]);
77581+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
77582 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
77583 rp->rtort_mbtest = 0;
77584 list_del(&rp->rtort_free);
77585@@ -975,7 +975,7 @@ rcu_torture_writer(void *arg)
77586 i = old_rp->rtort_pipe_count;
77587 if (i > RCU_TORTURE_PIPE_LEN)
77588 i = RCU_TORTURE_PIPE_LEN;
77589- atomic_inc(&rcu_torture_wcount[i]);
77590+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
77591 old_rp->rtort_pipe_count++;
77592 cur_ops->deferred_free(old_rp);
77593 }
77594@@ -1060,7 +1060,7 @@ static void rcu_torture_timer(unsigned long unused)
77595 }
77596 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
77597 if (p->rtort_mbtest == 0)
77598- atomic_inc(&n_rcu_torture_mberror);
77599+ atomic_inc_unchecked(&n_rcu_torture_mberror);
77600 spin_lock(&rand_lock);
77601 cur_ops->read_delay(&rand);
77602 n_rcu_torture_timers++;
77603@@ -1124,7 +1124,7 @@ rcu_torture_reader(void *arg)
77604 }
77605 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
77606 if (p->rtort_mbtest == 0)
77607- atomic_inc(&n_rcu_torture_mberror);
77608+ atomic_inc_unchecked(&n_rcu_torture_mberror);
77609 cur_ops->read_delay(&rand);
77610 preempt_disable();
77611 pipe_count = p->rtort_pipe_count;
77612@@ -1183,11 +1183,11 @@ rcu_torture_printk(char *page)
77613 rcu_torture_current,
77614 rcu_torture_current_version,
77615 list_empty(&rcu_torture_freelist),
77616- atomic_read(&n_rcu_torture_alloc),
77617- atomic_read(&n_rcu_torture_alloc_fail),
77618- atomic_read(&n_rcu_torture_free));
77619+ atomic_read_unchecked(&n_rcu_torture_alloc),
77620+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
77621+ atomic_read_unchecked(&n_rcu_torture_free));
77622 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
77623- atomic_read(&n_rcu_torture_mberror),
77624+ atomic_read_unchecked(&n_rcu_torture_mberror),
77625 n_rcu_torture_boost_ktrerror,
77626 n_rcu_torture_boost_rterror);
77627 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
77628@@ -1206,14 +1206,14 @@ rcu_torture_printk(char *page)
77629 n_barrier_attempts,
77630 n_rcu_torture_barrier_error);
77631 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
77632- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
77633+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
77634 n_rcu_torture_barrier_error != 0 ||
77635 n_rcu_torture_boost_ktrerror != 0 ||
77636 n_rcu_torture_boost_rterror != 0 ||
77637 n_rcu_torture_boost_failure != 0 ||
77638 i > 1) {
77639 cnt += sprintf(&page[cnt], "!!! ");
77640- atomic_inc(&n_rcu_torture_error);
77641+ atomic_inc_unchecked(&n_rcu_torture_error);
77642 WARN_ON_ONCE(1);
77643 }
77644 cnt += sprintf(&page[cnt], "Reader Pipe: ");
77645@@ -1227,7 +1227,7 @@ rcu_torture_printk(char *page)
77646 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
77647 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
77648 cnt += sprintf(&page[cnt], " %d",
77649- atomic_read(&rcu_torture_wcount[i]));
77650+ atomic_read_unchecked(&rcu_torture_wcount[i]));
77651 }
77652 cnt += sprintf(&page[cnt], "\n");
77653 if (cur_ops->stats)
77654@@ -1920,7 +1920,7 @@ rcu_torture_cleanup(void)
77655
77656 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
77657
77658- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
77659+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
77660 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
77661 else if (n_online_successes != n_online_attempts ||
77662 n_offline_successes != n_offline_attempts)
77663@@ -1989,18 +1989,18 @@ rcu_torture_init(void)
77664
77665 rcu_torture_current = NULL;
77666 rcu_torture_current_version = 0;
77667- atomic_set(&n_rcu_torture_alloc, 0);
77668- atomic_set(&n_rcu_torture_alloc_fail, 0);
77669- atomic_set(&n_rcu_torture_free, 0);
77670- atomic_set(&n_rcu_torture_mberror, 0);
77671- atomic_set(&n_rcu_torture_error, 0);
77672+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
77673+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
77674+ atomic_set_unchecked(&n_rcu_torture_free, 0);
77675+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
77676+ atomic_set_unchecked(&n_rcu_torture_error, 0);
77677 n_rcu_torture_barrier_error = 0;
77678 n_rcu_torture_boost_ktrerror = 0;
77679 n_rcu_torture_boost_rterror = 0;
77680 n_rcu_torture_boost_failure = 0;
77681 n_rcu_torture_boosts = 0;
77682 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
77683- atomic_set(&rcu_torture_wcount[i], 0);
77684+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
77685 for_each_possible_cpu(cpu) {
77686 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
77687 per_cpu(rcu_torture_count, cpu)[i] = 0;
77688diff --git a/kernel/rcutree.c b/kernel/rcutree.c
77689index e441b77..dd54f17 100644
77690--- a/kernel/rcutree.c
77691+++ b/kernel/rcutree.c
77692@@ -349,9 +349,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
77693 rcu_prepare_for_idle(smp_processor_id());
77694 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
77695 smp_mb__before_atomic_inc(); /* See above. */
77696- atomic_inc(&rdtp->dynticks);
77697+ atomic_inc_unchecked(&rdtp->dynticks);
77698 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
77699- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
77700+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
77701
77702 /*
77703 * It is illegal to enter an extended quiescent state while
77704@@ -487,10 +487,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
77705 int user)
77706 {
77707 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
77708- atomic_inc(&rdtp->dynticks);
77709+ atomic_inc_unchecked(&rdtp->dynticks);
77710 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
77711 smp_mb__after_atomic_inc(); /* See above. */
77712- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
77713+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
77714 rcu_cleanup_after_idle(smp_processor_id());
77715 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
77716 if (!user && !is_idle_task(current)) {
77717@@ -629,14 +629,14 @@ void rcu_nmi_enter(void)
77718 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
77719
77720 if (rdtp->dynticks_nmi_nesting == 0 &&
77721- (atomic_read(&rdtp->dynticks) & 0x1))
77722+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
77723 return;
77724 rdtp->dynticks_nmi_nesting++;
77725 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
77726- atomic_inc(&rdtp->dynticks);
77727+ atomic_inc_unchecked(&rdtp->dynticks);
77728 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
77729 smp_mb__after_atomic_inc(); /* See above. */
77730- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
77731+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
77732 }
77733
77734 /**
77735@@ -655,9 +655,9 @@ void rcu_nmi_exit(void)
77736 return;
77737 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
77738 smp_mb__before_atomic_inc(); /* See above. */
77739- atomic_inc(&rdtp->dynticks);
77740+ atomic_inc_unchecked(&rdtp->dynticks);
77741 smp_mb__after_atomic_inc(); /* Force delay to next write. */
77742- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
77743+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
77744 }
77745
77746 /**
77747@@ -671,7 +671,7 @@ int rcu_is_cpu_idle(void)
77748 int ret;
77749
77750 preempt_disable();
77751- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
77752+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
77753 preempt_enable();
77754 return ret;
77755 }
77756@@ -739,7 +739,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
77757 */
77758 static int dyntick_save_progress_counter(struct rcu_data *rdp)
77759 {
77760- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
77761+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
77762 return (rdp->dynticks_snap & 0x1) == 0;
77763 }
77764
77765@@ -754,7 +754,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
77766 unsigned int curr;
77767 unsigned int snap;
77768
77769- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
77770+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
77771 snap = (unsigned int)rdp->dynticks_snap;
77772
77773 /*
77774@@ -802,10 +802,10 @@ static int jiffies_till_stall_check(void)
77775 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
77776 */
77777 if (till_stall_check < 3) {
77778- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
77779+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
77780 till_stall_check = 3;
77781 } else if (till_stall_check > 300) {
77782- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
77783+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
77784 till_stall_check = 300;
77785 }
77786 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
77787@@ -1592,7 +1592,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
77788 rsp->qlen += rdp->qlen;
77789 rdp->n_cbs_orphaned += rdp->qlen;
77790 rdp->qlen_lazy = 0;
77791- ACCESS_ONCE(rdp->qlen) = 0;
77792+ ACCESS_ONCE_RW(rdp->qlen) = 0;
77793 }
77794
77795 /*
77796@@ -1838,7 +1838,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
77797 }
77798 smp_mb(); /* List handling before counting for rcu_barrier(). */
77799 rdp->qlen_lazy -= count_lazy;
77800- ACCESS_ONCE(rdp->qlen) -= count;
77801+ ACCESS_ONCE_RW(rdp->qlen) -= count;
77802 rdp->n_cbs_invoked += count;
77803
77804 /* Reinstate batch limit if we have worked down the excess. */
77805@@ -2031,7 +2031,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
77806 /*
77807 * Do RCU core processing for the current CPU.
77808 */
77809-static void rcu_process_callbacks(struct softirq_action *unused)
77810+static void rcu_process_callbacks(void)
77811 {
77812 struct rcu_state *rsp;
77813
77814@@ -2154,7 +2154,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
77815 local_irq_restore(flags);
77816 return;
77817 }
77818- ACCESS_ONCE(rdp->qlen)++;
77819+ ACCESS_ONCE_RW(rdp->qlen)++;
77820 if (lazy)
77821 rdp->qlen_lazy++;
77822 else
77823@@ -2363,11 +2363,11 @@ void synchronize_sched_expedited(void)
77824 * counter wrap on a 32-bit system. Quite a few more CPUs would of
77825 * course be required on a 64-bit system.
77826 */
77827- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
77828+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
77829 (ulong)atomic_long_read(&rsp->expedited_done) +
77830 ULONG_MAX / 8)) {
77831 synchronize_sched();
77832- atomic_long_inc(&rsp->expedited_wrap);
77833+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
77834 return;
77835 }
77836
77837@@ -2375,7 +2375,7 @@ void synchronize_sched_expedited(void)
77838 * Take a ticket. Note that atomic_inc_return() implies a
77839 * full memory barrier.
77840 */
77841- snap = atomic_long_inc_return(&rsp->expedited_start);
77842+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
77843 firstsnap = snap;
77844 get_online_cpus();
77845 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
77846@@ -2388,14 +2388,14 @@ void synchronize_sched_expedited(void)
77847 synchronize_sched_expedited_cpu_stop,
77848 NULL) == -EAGAIN) {
77849 put_online_cpus();
77850- atomic_long_inc(&rsp->expedited_tryfail);
77851+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
77852
77853 /* Check to see if someone else did our work for us. */
77854 s = atomic_long_read(&rsp->expedited_done);
77855 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
77856 /* ensure test happens before caller kfree */
77857 smp_mb__before_atomic_inc(); /* ^^^ */
77858- atomic_long_inc(&rsp->expedited_workdone1);
77859+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
77860 return;
77861 }
77862
77863@@ -2404,7 +2404,7 @@ void synchronize_sched_expedited(void)
77864 udelay(trycount * num_online_cpus());
77865 } else {
77866 wait_rcu_gp(call_rcu_sched);
77867- atomic_long_inc(&rsp->expedited_normal);
77868+ atomic_long_inc_unchecked(&rsp->expedited_normal);
77869 return;
77870 }
77871
77872@@ -2413,7 +2413,7 @@ void synchronize_sched_expedited(void)
77873 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
77874 /* ensure test happens before caller kfree */
77875 smp_mb__before_atomic_inc(); /* ^^^ */
77876- atomic_long_inc(&rsp->expedited_workdone2);
77877+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
77878 return;
77879 }
77880
77881@@ -2425,10 +2425,10 @@ void synchronize_sched_expedited(void)
77882 * period works for us.
77883 */
77884 get_online_cpus();
77885- snap = atomic_long_read(&rsp->expedited_start);
77886+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
77887 smp_mb(); /* ensure read is before try_stop_cpus(). */
77888 }
77889- atomic_long_inc(&rsp->expedited_stoppedcpus);
77890+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
77891
77892 /*
77893 * Everyone up to our most recent fetch is covered by our grace
77894@@ -2437,16 +2437,16 @@ void synchronize_sched_expedited(void)
77895 * than we did already did their update.
77896 */
77897 do {
77898- atomic_long_inc(&rsp->expedited_done_tries);
77899+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
77900 s = atomic_long_read(&rsp->expedited_done);
77901 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
77902 /* ensure test happens before caller kfree */
77903 smp_mb__before_atomic_inc(); /* ^^^ */
77904- atomic_long_inc(&rsp->expedited_done_lost);
77905+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
77906 break;
77907 }
77908 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
77909- atomic_long_inc(&rsp->expedited_done_exit);
77910+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
77911
77912 put_online_cpus();
77913 }
77914@@ -2620,7 +2620,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
77915 * ACCESS_ONCE() to prevent the compiler from speculating
77916 * the increment to precede the early-exit check.
77917 */
77918- ACCESS_ONCE(rsp->n_barrier_done)++;
77919+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
77920 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
77921 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
77922 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
77923@@ -2670,7 +2670,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
77924
77925 /* Increment ->n_barrier_done to prevent duplicate work. */
77926 smp_mb(); /* Keep increment after above mechanism. */
77927- ACCESS_ONCE(rsp->n_barrier_done)++;
77928+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
77929 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
77930 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
77931 smp_mb(); /* Keep increment before caller's subsequent code. */
77932@@ -2715,10 +2715,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
77933 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
77934 init_callback_list(rdp);
77935 rdp->qlen_lazy = 0;
77936- ACCESS_ONCE(rdp->qlen) = 0;
77937+ ACCESS_ONCE_RW(rdp->qlen) = 0;
77938 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
77939 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
77940- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
77941+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
77942 #ifdef CONFIG_RCU_USER_QS
77943 WARN_ON_ONCE(rdp->dynticks->in_user);
77944 #endif
77945@@ -2754,8 +2754,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
77946 rdp->blimit = blimit;
77947 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
77948 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
77949- atomic_set(&rdp->dynticks->dynticks,
77950- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
77951+ atomic_set_unchecked(&rdp->dynticks->dynticks,
77952+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
77953 rcu_prepare_for_idle_init(cpu);
77954 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
77955
77956diff --git a/kernel/rcutree.h b/kernel/rcutree.h
77957index 4b69291..704c92e 100644
77958--- a/kernel/rcutree.h
77959+++ b/kernel/rcutree.h
77960@@ -86,7 +86,7 @@ struct rcu_dynticks {
77961 long long dynticks_nesting; /* Track irq/process nesting level. */
77962 /* Process level is worth LLONG_MAX/2. */
77963 int dynticks_nmi_nesting; /* Track NMI nesting level. */
77964- atomic_t dynticks; /* Even value for idle, else odd. */
77965+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
77966 #ifdef CONFIG_RCU_FAST_NO_HZ
77967 int dyntick_drain; /* Prepare-for-idle state variable. */
77968 unsigned long dyntick_holdoff;
77969@@ -423,17 +423,17 @@ struct rcu_state {
77970 /* _rcu_barrier(). */
77971 /* End of fields guarded by barrier_mutex. */
77972
77973- atomic_long_t expedited_start; /* Starting ticket. */
77974- atomic_long_t expedited_done; /* Done ticket. */
77975- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
77976- atomic_long_t expedited_tryfail; /* # acquisition failures. */
77977- atomic_long_t expedited_workdone1; /* # done by others #1. */
77978- atomic_long_t expedited_workdone2; /* # done by others #2. */
77979- atomic_long_t expedited_normal; /* # fallbacks to normal. */
77980- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
77981- atomic_long_t expedited_done_tries; /* # tries to update _done. */
77982- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
77983- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
77984+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
77985+ atomic_long_t expedited_done; /* Done ticket. */
77986+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
77987+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
77988+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
77989+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
77990+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
77991+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
77992+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
77993+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
77994+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
77995
77996 unsigned long jiffies_force_qs; /* Time at which to invoke */
77997 /* force_quiescent_state(). */
77998diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
77999index c1cc7e1..f62e436 100644
78000--- a/kernel/rcutree_plugin.h
78001+++ b/kernel/rcutree_plugin.h
78002@@ -892,7 +892,7 @@ void synchronize_rcu_expedited(void)
78003
78004 /* Clean up and exit. */
78005 smp_mb(); /* ensure expedited GP seen before counter increment. */
78006- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
78007+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
78008 unlock_mb_ret:
78009 mutex_unlock(&sync_rcu_preempt_exp_mutex);
78010 mb_ret:
78011@@ -1440,7 +1440,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
78012 free_cpumask_var(cm);
78013 }
78014
78015-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
78016+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
78017 .store = &rcu_cpu_kthread_task,
78018 .thread_should_run = rcu_cpu_kthread_should_run,
78019 .thread_fn = rcu_cpu_kthread,
78020@@ -2072,7 +2072,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
78021 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
78022 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
78023 cpu, ticks_value, ticks_title,
78024- atomic_read(&rdtp->dynticks) & 0xfff,
78025+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
78026 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
78027 fast_no_hz);
78028 }
78029@@ -2192,7 +2192,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
78030
78031 /* Enqueue the callback on the nocb list and update counts. */
78032 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
78033- ACCESS_ONCE(*old_rhpp) = rhp;
78034+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
78035 atomic_long_add(rhcount, &rdp->nocb_q_count);
78036 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
78037
78038@@ -2384,12 +2384,12 @@ static int rcu_nocb_kthread(void *arg)
78039 * Extract queued callbacks, update counts, and wait
78040 * for a grace period to elapse.
78041 */
78042- ACCESS_ONCE(rdp->nocb_head) = NULL;
78043+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
78044 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
78045 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
78046 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
78047- ACCESS_ONCE(rdp->nocb_p_count) += c;
78048- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
78049+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
78050+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
78051 wait_rcu_gp(rdp->rsp->call_remote);
78052
78053 /* Each pass through the following loop invokes a callback. */
78054@@ -2411,8 +2411,8 @@ static int rcu_nocb_kthread(void *arg)
78055 list = next;
78056 }
78057 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
78058- ACCESS_ONCE(rdp->nocb_p_count) -= c;
78059- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
78060+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
78061+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
78062 rdp->n_nocbs_invoked += c;
78063 }
78064 return 0;
78065@@ -2438,7 +2438,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
78066 rdp = per_cpu_ptr(rsp->rda, cpu);
78067 t = kthread_run(rcu_nocb_kthread, rdp, "rcuo%d", cpu);
78068 BUG_ON(IS_ERR(t));
78069- ACCESS_ONCE(rdp->nocb_kthread) = t;
78070+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
78071 }
78072 }
78073
78074diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
78075index 0d095dc..1985b19 100644
78076--- a/kernel/rcutree_trace.c
78077+++ b/kernel/rcutree_trace.c
78078@@ -123,7 +123,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
78079 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
78080 rdp->passed_quiesce, rdp->qs_pending);
78081 seq_printf(m, " dt=%d/%llx/%d df=%lu",
78082- atomic_read(&rdp->dynticks->dynticks),
78083+ atomic_read_unchecked(&rdp->dynticks->dynticks),
78084 rdp->dynticks->dynticks_nesting,
78085 rdp->dynticks->dynticks_nmi_nesting,
78086 rdp->dynticks_fqs);
78087@@ -184,17 +184,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
78088 struct rcu_state *rsp = (struct rcu_state *)m->private;
78089
78090 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",
78091- atomic_long_read(&rsp->expedited_start),
78092+ atomic_long_read_unchecked(&rsp->expedited_start),
78093 atomic_long_read(&rsp->expedited_done),
78094- atomic_long_read(&rsp->expedited_wrap),
78095- atomic_long_read(&rsp->expedited_tryfail),
78096- atomic_long_read(&rsp->expedited_workdone1),
78097- atomic_long_read(&rsp->expedited_workdone2),
78098- atomic_long_read(&rsp->expedited_normal),
78099- atomic_long_read(&rsp->expedited_stoppedcpus),
78100- atomic_long_read(&rsp->expedited_done_tries),
78101- atomic_long_read(&rsp->expedited_done_lost),
78102- atomic_long_read(&rsp->expedited_done_exit));
78103+ atomic_long_read_unchecked(&rsp->expedited_wrap),
78104+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
78105+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
78106+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
78107+ atomic_long_read_unchecked(&rsp->expedited_normal),
78108+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
78109+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
78110+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
78111+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
78112 return 0;
78113 }
78114
78115diff --git a/kernel/resource.c b/kernel/resource.c
78116index 73f35d4..4684fc4 100644
78117--- a/kernel/resource.c
78118+++ b/kernel/resource.c
78119@@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
78120
78121 static int __init ioresources_init(void)
78122 {
78123+#ifdef CONFIG_GRKERNSEC_PROC_ADD
78124+#ifdef CONFIG_GRKERNSEC_PROC_USER
78125+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
78126+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
78127+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78128+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
78129+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
78130+#endif
78131+#else
78132 proc_create("ioports", 0, NULL, &proc_ioports_operations);
78133 proc_create("iomem", 0, NULL, &proc_iomem_operations);
78134+#endif
78135 return 0;
78136 }
78137 __initcall(ioresources_init);
78138diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
78139index 98ec494..4241d6d 100644
78140--- a/kernel/rtmutex-tester.c
78141+++ b/kernel/rtmutex-tester.c
78142@@ -20,7 +20,7 @@
78143 #define MAX_RT_TEST_MUTEXES 8
78144
78145 static spinlock_t rttest_lock;
78146-static atomic_t rttest_event;
78147+static atomic_unchecked_t rttest_event;
78148
78149 struct test_thread_data {
78150 int opcode;
78151@@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78152
78153 case RTTEST_LOCKCONT:
78154 td->mutexes[td->opdata] = 1;
78155- td->event = atomic_add_return(1, &rttest_event);
78156+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78157 return 0;
78158
78159 case RTTEST_RESET:
78160@@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78161 return 0;
78162
78163 case RTTEST_RESETEVENT:
78164- atomic_set(&rttest_event, 0);
78165+ atomic_set_unchecked(&rttest_event, 0);
78166 return 0;
78167
78168 default:
78169@@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78170 return ret;
78171
78172 td->mutexes[id] = 1;
78173- td->event = atomic_add_return(1, &rttest_event);
78174+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78175 rt_mutex_lock(&mutexes[id]);
78176- td->event = atomic_add_return(1, &rttest_event);
78177+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78178 td->mutexes[id] = 4;
78179 return 0;
78180
78181@@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78182 return ret;
78183
78184 td->mutexes[id] = 1;
78185- td->event = atomic_add_return(1, &rttest_event);
78186+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78187 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
78188- td->event = atomic_add_return(1, &rttest_event);
78189+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78190 td->mutexes[id] = ret ? 0 : 4;
78191 return ret ? -EINTR : 0;
78192
78193@@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78194 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
78195 return ret;
78196
78197- td->event = atomic_add_return(1, &rttest_event);
78198+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78199 rt_mutex_unlock(&mutexes[id]);
78200- td->event = atomic_add_return(1, &rttest_event);
78201+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78202 td->mutexes[id] = 0;
78203 return 0;
78204
78205@@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
78206 break;
78207
78208 td->mutexes[dat] = 2;
78209- td->event = atomic_add_return(1, &rttest_event);
78210+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78211 break;
78212
78213 default:
78214@@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
78215 return;
78216
78217 td->mutexes[dat] = 3;
78218- td->event = atomic_add_return(1, &rttest_event);
78219+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78220 break;
78221
78222 case RTTEST_LOCKNOWAIT:
78223@@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
78224 return;
78225
78226 td->mutexes[dat] = 1;
78227- td->event = atomic_add_return(1, &rttest_event);
78228+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78229 return;
78230
78231 default:
78232diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
78233index 0984a21..939f183 100644
78234--- a/kernel/sched/auto_group.c
78235+++ b/kernel/sched/auto_group.c
78236@@ -11,7 +11,7 @@
78237
78238 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
78239 static struct autogroup autogroup_default;
78240-static atomic_t autogroup_seq_nr;
78241+static atomic_unchecked_t autogroup_seq_nr;
78242
78243 void __init autogroup_init(struct task_struct *init_task)
78244 {
78245@@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
78246
78247 kref_init(&ag->kref);
78248 init_rwsem(&ag->lock);
78249- ag->id = atomic_inc_return(&autogroup_seq_nr);
78250+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
78251 ag->tg = tg;
78252 #ifdef CONFIG_RT_GROUP_SCHED
78253 /*
78254diff --git a/kernel/sched/core.c b/kernel/sched/core.c
78255index 26058d0..e315889 100644
78256--- a/kernel/sched/core.c
78257+++ b/kernel/sched/core.c
78258@@ -3367,7 +3367,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
78259 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
78260 * positive (at least 1, or number of jiffies left till timeout) if completed.
78261 */
78262-long __sched
78263+long __sched __intentional_overflow(-1)
78264 wait_for_completion_interruptible_timeout(struct completion *x,
78265 unsigned long timeout)
78266 {
78267@@ -3384,7 +3384,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
78268 *
78269 * The return value is -ERESTARTSYS if interrupted, 0 if completed.
78270 */
78271-int __sched wait_for_completion_killable(struct completion *x)
78272+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
78273 {
78274 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
78275 if (t == -ERESTARTSYS)
78276@@ -3405,7 +3405,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
78277 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
78278 * positive (at least 1, or number of jiffies left till timeout) if completed.
78279 */
78280-long __sched
78281+long __sched __intentional_overflow(-1)
78282 wait_for_completion_killable_timeout(struct completion *x,
78283 unsigned long timeout)
78284 {
78285@@ -3631,6 +3631,8 @@ int can_nice(const struct task_struct *p, const int nice)
78286 /* convert nice value [19,-20] to rlimit style value [1,40] */
78287 int nice_rlim = 20 - nice;
78288
78289+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
78290+
78291 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
78292 capable(CAP_SYS_NICE));
78293 }
78294@@ -3664,7 +3666,8 @@ SYSCALL_DEFINE1(nice, int, increment)
78295 if (nice > 19)
78296 nice = 19;
78297
78298- if (increment < 0 && !can_nice(current, nice))
78299+ if (increment < 0 && (!can_nice(current, nice) ||
78300+ gr_handle_chroot_nice()))
78301 return -EPERM;
78302
78303 retval = security_task_setnice(current, nice);
78304@@ -3818,6 +3821,7 @@ recheck:
78305 unsigned long rlim_rtprio =
78306 task_rlimit(p, RLIMIT_RTPRIO);
78307
78308+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
78309 /* can't set/change the rt policy */
78310 if (policy != p->policy && !rlim_rtprio)
78311 return -EPERM;
78312@@ -4901,7 +4905,7 @@ static void migrate_tasks(unsigned int dead_cpu)
78313
78314 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
78315
78316-static struct ctl_table sd_ctl_dir[] = {
78317+static ctl_table_no_const sd_ctl_dir[] __read_only = {
78318 {
78319 .procname = "sched_domain",
78320 .mode = 0555,
78321@@ -4918,17 +4922,17 @@ static struct ctl_table sd_ctl_root[] = {
78322 {}
78323 };
78324
78325-static struct ctl_table *sd_alloc_ctl_entry(int n)
78326+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
78327 {
78328- struct ctl_table *entry =
78329+ ctl_table_no_const *entry =
78330 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
78331
78332 return entry;
78333 }
78334
78335-static void sd_free_ctl_entry(struct ctl_table **tablep)
78336+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
78337 {
78338- struct ctl_table *entry;
78339+ ctl_table_no_const *entry;
78340
78341 /*
78342 * In the intermediate directories, both the child directory and
78343@@ -4936,22 +4940,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
78344 * will always be set. In the lowest directory the names are
78345 * static strings and all have proc handlers.
78346 */
78347- for (entry = *tablep; entry->mode; entry++) {
78348- if (entry->child)
78349- sd_free_ctl_entry(&entry->child);
78350+ for (entry = tablep; entry->mode; entry++) {
78351+ if (entry->child) {
78352+ sd_free_ctl_entry(entry->child);
78353+ pax_open_kernel();
78354+ entry->child = NULL;
78355+ pax_close_kernel();
78356+ }
78357 if (entry->proc_handler == NULL)
78358 kfree(entry->procname);
78359 }
78360
78361- kfree(*tablep);
78362- *tablep = NULL;
78363+ kfree(tablep);
78364 }
78365
78366 static int min_load_idx = 0;
78367 static int max_load_idx = CPU_LOAD_IDX_MAX;
78368
78369 static void
78370-set_table_entry(struct ctl_table *entry,
78371+set_table_entry(ctl_table_no_const *entry,
78372 const char *procname, void *data, int maxlen,
78373 umode_t mode, proc_handler *proc_handler,
78374 bool load_idx)
78375@@ -4971,7 +4978,7 @@ set_table_entry(struct ctl_table *entry,
78376 static struct ctl_table *
78377 sd_alloc_ctl_domain_table(struct sched_domain *sd)
78378 {
78379- struct ctl_table *table = sd_alloc_ctl_entry(13);
78380+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
78381
78382 if (table == NULL)
78383 return NULL;
78384@@ -5006,9 +5013,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
78385 return table;
78386 }
78387
78388-static ctl_table *sd_alloc_ctl_cpu_table(int cpu)
78389+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
78390 {
78391- struct ctl_table *entry, *table;
78392+ ctl_table_no_const *entry, *table;
78393 struct sched_domain *sd;
78394 int domain_num = 0, i;
78395 char buf[32];
78396@@ -5035,11 +5042,13 @@ static struct ctl_table_header *sd_sysctl_header;
78397 static void register_sched_domain_sysctl(void)
78398 {
78399 int i, cpu_num = num_possible_cpus();
78400- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
78401+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
78402 char buf[32];
78403
78404 WARN_ON(sd_ctl_dir[0].child);
78405+ pax_open_kernel();
78406 sd_ctl_dir[0].child = entry;
78407+ pax_close_kernel();
78408
78409 if (entry == NULL)
78410 return;
78411@@ -5062,8 +5071,12 @@ static void unregister_sched_domain_sysctl(void)
78412 if (sd_sysctl_header)
78413 unregister_sysctl_table(sd_sysctl_header);
78414 sd_sysctl_header = NULL;
78415- if (sd_ctl_dir[0].child)
78416- sd_free_ctl_entry(&sd_ctl_dir[0].child);
78417+ if (sd_ctl_dir[0].child) {
78418+ sd_free_ctl_entry(sd_ctl_dir[0].child);
78419+ pax_open_kernel();
78420+ sd_ctl_dir[0].child = NULL;
78421+ pax_close_kernel();
78422+ }
78423 }
78424 #else
78425 static void register_sched_domain_sysctl(void)
78426@@ -5162,7 +5175,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
78427 * happens before everything else. This has to be lower priority than
78428 * the notifier in the perf_event subsystem, though.
78429 */
78430-static struct notifier_block __cpuinitdata migration_notifier = {
78431+static struct notifier_block migration_notifier = {
78432 .notifier_call = migration_call,
78433 .priority = CPU_PRI_MIGRATION,
78434 };
78435diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
78436index 81fa536..6ccf96a 100644
78437--- a/kernel/sched/fair.c
78438+++ b/kernel/sched/fair.c
78439@@ -830,7 +830,7 @@ void task_numa_fault(int node, int pages, bool migrated)
78440
78441 static void reset_ptenuma_scan(struct task_struct *p)
78442 {
78443- ACCESS_ONCE(p->mm->numa_scan_seq)++;
78444+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
78445 p->mm->numa_scan_offset = 0;
78446 }
78447
78448@@ -3254,25 +3254,18 @@ find_idlest_cpu(struct sched_group *group, struct task_struct *p, int this_cpu)
78449 */
78450 static int select_idle_sibling(struct task_struct *p, int target)
78451 {
78452- int cpu = smp_processor_id();
78453- int prev_cpu = task_cpu(p);
78454 struct sched_domain *sd;
78455 struct sched_group *sg;
78456- int i;
78457+ int i = task_cpu(p);
78458
78459- /*
78460- * If the task is going to be woken-up on this cpu and if it is
78461- * already idle, then it is the right target.
78462- */
78463- if (target == cpu && idle_cpu(cpu))
78464- return cpu;
78465+ if (idle_cpu(target))
78466+ return target;
78467
78468 /*
78469- * If the task is going to be woken-up on the cpu where it previously
78470- * ran and if it is currently idle, then it the right target.
78471+ * If the prevous cpu is cache affine and idle, don't be stupid.
78472 */
78473- if (target == prev_cpu && idle_cpu(prev_cpu))
78474- return prev_cpu;
78475+ if (i != target && cpus_share_cache(i, target) && idle_cpu(i))
78476+ return i;
78477
78478 /*
78479 * Otherwise, iterate the domains and find an elegible idle cpu.
78480@@ -3286,7 +3279,7 @@ static int select_idle_sibling(struct task_struct *p, int target)
78481 goto next;
78482
78483 for_each_cpu(i, sched_group_cpus(sg)) {
78484- if (!idle_cpu(i))
78485+ if (i == target || !idle_cpu(i))
78486 goto next;
78487 }
78488
78489@@ -5663,7 +5656,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
78490 * run_rebalance_domains is triggered when needed from the scheduler tick.
78491 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
78492 */
78493-static void run_rebalance_domains(struct softirq_action *h)
78494+static void run_rebalance_domains(void)
78495 {
78496 int this_cpu = smp_processor_id();
78497 struct rq *this_rq = cpu_rq(this_cpu);
78498diff --git a/kernel/signal.c b/kernel/signal.c
78499index dec9c30..92c8f65 100644
78500--- a/kernel/signal.c
78501+++ b/kernel/signal.c
78502@@ -50,12 +50,12 @@ static struct kmem_cache *sigqueue_cachep;
78503
78504 int print_fatal_signals __read_mostly;
78505
78506-static void __user *sig_handler(struct task_struct *t, int sig)
78507+static __sighandler_t sig_handler(struct task_struct *t, int sig)
78508 {
78509 return t->sighand->action[sig - 1].sa.sa_handler;
78510 }
78511
78512-static int sig_handler_ignored(void __user *handler, int sig)
78513+static int sig_handler_ignored(__sighandler_t handler, int sig)
78514 {
78515 /* Is it explicitly or implicitly ignored? */
78516 return handler == SIG_IGN ||
78517@@ -64,7 +64,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
78518
78519 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
78520 {
78521- void __user *handler;
78522+ __sighandler_t handler;
78523
78524 handler = sig_handler(t, sig);
78525
78526@@ -368,6 +368,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
78527 atomic_inc(&user->sigpending);
78528 rcu_read_unlock();
78529
78530+ if (!override_rlimit)
78531+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
78532+
78533 if (override_rlimit ||
78534 atomic_read(&user->sigpending) <=
78535 task_rlimit(t, RLIMIT_SIGPENDING)) {
78536@@ -495,7 +498,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
78537
78538 int unhandled_signal(struct task_struct *tsk, int sig)
78539 {
78540- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
78541+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
78542 if (is_global_init(tsk))
78543 return 1;
78544 if (handler != SIG_IGN && handler != SIG_DFL)
78545@@ -815,6 +818,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
78546 }
78547 }
78548
78549+ /* allow glibc communication via tgkill to other threads in our
78550+ thread group */
78551+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
78552+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
78553+ && gr_handle_signal(t, sig))
78554+ return -EPERM;
78555+
78556 return security_task_kill(t, info, sig, 0);
78557 }
78558
78559@@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
78560 return send_signal(sig, info, p, 1);
78561 }
78562
78563-static int
78564+int
78565 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
78566 {
78567 return send_signal(sig, info, t, 0);
78568@@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
78569 unsigned long int flags;
78570 int ret, blocked, ignored;
78571 struct k_sigaction *action;
78572+ int is_unhandled = 0;
78573
78574 spin_lock_irqsave(&t->sighand->siglock, flags);
78575 action = &t->sighand->action[sig-1];
78576@@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
78577 }
78578 if (action->sa.sa_handler == SIG_DFL)
78579 t->signal->flags &= ~SIGNAL_UNKILLABLE;
78580+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
78581+ is_unhandled = 1;
78582 ret = specific_send_sig_info(sig, info, t);
78583 spin_unlock_irqrestore(&t->sighand->siglock, flags);
78584
78585+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
78586+ normal operation */
78587+ if (is_unhandled) {
78588+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
78589+ gr_handle_crash(t, sig);
78590+ }
78591+
78592 return ret;
78593 }
78594
78595@@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
78596 ret = check_kill_permission(sig, info, p);
78597 rcu_read_unlock();
78598
78599- if (!ret && sig)
78600+ if (!ret && sig) {
78601 ret = do_send_sig_info(sig, info, p, true);
78602+ if (!ret)
78603+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
78604+ }
78605
78606 return ret;
78607 }
78608@@ -2855,7 +2878,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
78609 int error = -ESRCH;
78610
78611 rcu_read_lock();
78612- p = find_task_by_vpid(pid);
78613+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
78614+ /* allow glibc communication via tgkill to other threads in our
78615+ thread group */
78616+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
78617+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
78618+ p = find_task_by_vpid_unrestricted(pid);
78619+ else
78620+#endif
78621+ p = find_task_by_vpid(pid);
78622 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
78623 error = check_kill_permission(sig, info, p);
78624 /*
78625@@ -2880,7 +2911,7 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
78626
78627 static int do_tkill(pid_t tgid, pid_t pid, int sig)
78628 {
78629- struct siginfo info;
78630+ struct siginfo info = {};
78631
78632 info.si_signo = sig;
78633 info.si_errno = 0;
78634@@ -3138,8 +3169,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
78635 }
78636 seg = get_fs();
78637 set_fs(KERNEL_DS);
78638- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
78639- (stack_t __force __user *) &uoss,
78640+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
78641+ (stack_t __force_user *) &uoss,
78642 compat_user_stack_pointer());
78643 set_fs(seg);
78644 if (ret >= 0 && uoss_ptr) {
78645diff --git a/kernel/smp.c b/kernel/smp.c
78646index 69f38bd..77bbf12 100644
78647--- a/kernel/smp.c
78648+++ b/kernel/smp.c
78649@@ -77,7 +77,7 @@ hotplug_cfd(struct notifier_block *nfb, unsigned long action, void *hcpu)
78650 return NOTIFY_OK;
78651 }
78652
78653-static struct notifier_block __cpuinitdata hotplug_cfd_notifier = {
78654+static struct notifier_block hotplug_cfd_notifier = {
78655 .notifier_call = hotplug_cfd,
78656 };
78657
78658diff --git a/kernel/smpboot.c b/kernel/smpboot.c
78659index d6c5fc0..530560c 100644
78660--- a/kernel/smpboot.c
78661+++ b/kernel/smpboot.c
78662@@ -275,7 +275,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
78663 }
78664 smpboot_unpark_thread(plug_thread, cpu);
78665 }
78666- list_add(&plug_thread->list, &hotplug_threads);
78667+ pax_list_add(&plug_thread->list, &hotplug_threads);
78668 out:
78669 mutex_unlock(&smpboot_threads_lock);
78670 return ret;
78671@@ -292,7 +292,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
78672 {
78673 get_online_cpus();
78674 mutex_lock(&smpboot_threads_lock);
78675- list_del(&plug_thread->list);
78676+ pax_list_del(&plug_thread->list);
78677 smpboot_destroy_threads(plug_thread);
78678 mutex_unlock(&smpboot_threads_lock);
78679 put_online_cpus();
78680diff --git a/kernel/softirq.c b/kernel/softirq.c
78681index ed567ba..e71dabf 100644
78682--- a/kernel/softirq.c
78683+++ b/kernel/softirq.c
78684@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
78685 EXPORT_SYMBOL(irq_stat);
78686 #endif
78687
78688-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
78689+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
78690
78691 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
78692
78693-char *softirq_to_name[NR_SOFTIRQS] = {
78694+const char * const softirq_to_name[NR_SOFTIRQS] = {
78695 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
78696 "TASKLET", "SCHED", "HRTIMER", "RCU"
78697 };
78698@@ -244,7 +244,7 @@ restart:
78699 kstat_incr_softirqs_this_cpu(vec_nr);
78700
78701 trace_softirq_entry(vec_nr);
78702- h->action(h);
78703+ h->action();
78704 trace_softirq_exit(vec_nr);
78705 if (unlikely(prev_count != preempt_count())) {
78706 printk(KERN_ERR "huh, entered softirq %u %s %p"
78707@@ -391,7 +391,7 @@ void __raise_softirq_irqoff(unsigned int nr)
78708 or_softirq_pending(1UL << nr);
78709 }
78710
78711-void open_softirq(int nr, void (*action)(struct softirq_action *))
78712+void __init open_softirq(int nr, void (*action)(void))
78713 {
78714 softirq_vec[nr].action = action;
78715 }
78716@@ -447,7 +447,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
78717
78718 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
78719
78720-static void tasklet_action(struct softirq_action *a)
78721+static void tasklet_action(void)
78722 {
78723 struct tasklet_struct *list;
78724
78725@@ -482,7 +482,7 @@ static void tasklet_action(struct softirq_action *a)
78726 }
78727 }
78728
78729-static void tasklet_hi_action(struct softirq_action *a)
78730+static void tasklet_hi_action(void)
78731 {
78732 struct tasklet_struct *list;
78733
78734@@ -718,7 +718,7 @@ static int __cpuinit remote_softirq_cpu_notify(struct notifier_block *self,
78735 return NOTIFY_OK;
78736 }
78737
78738-static struct notifier_block __cpuinitdata remote_softirq_cpu_notifier = {
78739+static struct notifier_block remote_softirq_cpu_notifier = {
78740 .notifier_call = remote_softirq_cpu_notify,
78741 };
78742
78743@@ -835,11 +835,11 @@ static int __cpuinit cpu_callback(struct notifier_block *nfb,
78744 return NOTIFY_OK;
78745 }
78746
78747-static struct notifier_block __cpuinitdata cpu_nfb = {
78748+static struct notifier_block cpu_nfb = {
78749 .notifier_call = cpu_callback
78750 };
78751
78752-static struct smp_hotplug_thread softirq_threads = {
78753+static struct smp_hotplug_thread softirq_threads __read_only = {
78754 .store = &ksoftirqd,
78755 .thread_should_run = ksoftirqd_should_run,
78756 .thread_fn = run_ksoftirqd,
78757diff --git a/kernel/srcu.c b/kernel/srcu.c
78758index 2b85982..d52ab26 100644
78759--- a/kernel/srcu.c
78760+++ b/kernel/srcu.c
78761@@ -305,9 +305,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
78762 preempt_disable();
78763 idx = rcu_dereference_index_check(sp->completed,
78764 rcu_read_lock_sched_held()) & 0x1;
78765- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
78766+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
78767 smp_mb(); /* B */ /* Avoid leaking the critical section. */
78768- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
78769+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
78770 preempt_enable();
78771 return idx;
78772 }
78773@@ -323,7 +323,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
78774 {
78775 preempt_disable();
78776 smp_mb(); /* C */ /* Avoid leaking the critical section. */
78777- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
78778+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
78779 preempt_enable();
78780 }
78781 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
78782diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c
78783index 2f194e9..2c05ea9 100644
78784--- a/kernel/stop_machine.c
78785+++ b/kernel/stop_machine.c
78786@@ -362,7 +362,7 @@ static int __cpuinit cpu_stop_cpu_callback(struct notifier_block *nfb,
78787 * cpu notifiers. It currently shares the same priority as sched
78788 * migration_notifier.
78789 */
78790-static struct notifier_block __cpuinitdata cpu_stop_cpu_notifier = {
78791+static struct notifier_block cpu_stop_cpu_notifier = {
78792 .notifier_call = cpu_stop_cpu_callback,
78793 .priority = 10,
78794 };
78795diff --git a/kernel/sys.c b/kernel/sys.c
78796index 47f1d1b..04c769e 100644
78797--- a/kernel/sys.c
78798+++ b/kernel/sys.c
78799@@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
78800 error = -EACCES;
78801 goto out;
78802 }
78803+
78804+ if (gr_handle_chroot_setpriority(p, niceval)) {
78805+ error = -EACCES;
78806+ goto out;
78807+ }
78808+
78809 no_nice = security_task_setnice(p, niceval);
78810 if (no_nice) {
78811 error = no_nice;
78812@@ -596,6 +602,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
78813 goto error;
78814 }
78815
78816+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
78817+ goto error;
78818+
78819 if (rgid != (gid_t) -1 ||
78820 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
78821 new->sgid = new->egid;
78822@@ -631,6 +640,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
78823 old = current_cred();
78824
78825 retval = -EPERM;
78826+
78827+ if (gr_check_group_change(kgid, kgid, kgid))
78828+ goto error;
78829+
78830 if (nsown_capable(CAP_SETGID))
78831 new->gid = new->egid = new->sgid = new->fsgid = kgid;
78832 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
78833@@ -648,7 +661,7 @@ error:
78834 /*
78835 * change the user struct in a credentials set to match the new UID
78836 */
78837-static int set_user(struct cred *new)
78838+int set_user(struct cred *new)
78839 {
78840 struct user_struct *new_user;
78841
78842@@ -728,6 +741,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
78843 goto error;
78844 }
78845
78846+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
78847+ goto error;
78848+
78849 if (!uid_eq(new->uid, old->uid)) {
78850 retval = set_user(new);
78851 if (retval < 0)
78852@@ -778,6 +794,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
78853 old = current_cred();
78854
78855 retval = -EPERM;
78856+
78857+ if (gr_check_crash_uid(kuid))
78858+ goto error;
78859+ if (gr_check_user_change(kuid, kuid, kuid))
78860+ goto error;
78861+
78862 if (nsown_capable(CAP_SETUID)) {
78863 new->suid = new->uid = kuid;
78864 if (!uid_eq(kuid, old->uid)) {
78865@@ -847,6 +869,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
78866 goto error;
78867 }
78868
78869+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
78870+ goto error;
78871+
78872 if (ruid != (uid_t) -1) {
78873 new->uid = kruid;
78874 if (!uid_eq(kruid, old->uid)) {
78875@@ -929,6 +954,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
78876 goto error;
78877 }
78878
78879+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
78880+ goto error;
78881+
78882 if (rgid != (gid_t) -1)
78883 new->gid = krgid;
78884 if (egid != (gid_t) -1)
78885@@ -990,12 +1018,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
78886 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
78887 nsown_capable(CAP_SETUID)) {
78888 if (!uid_eq(kuid, old->fsuid)) {
78889+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
78890+ goto error;
78891+
78892 new->fsuid = kuid;
78893 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
78894 goto change_okay;
78895 }
78896 }
78897
78898+error:
78899 abort_creds(new);
78900 return old_fsuid;
78901
78902@@ -1028,12 +1060,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
78903 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
78904 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
78905 nsown_capable(CAP_SETGID)) {
78906+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
78907+ goto error;
78908+
78909 if (!gid_eq(kgid, old->fsgid)) {
78910 new->fsgid = kgid;
78911 goto change_okay;
78912 }
78913 }
78914
78915+error:
78916 abort_creds(new);
78917 return old_fsgid;
78918
78919@@ -1341,19 +1377,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
78920 return -EFAULT;
78921
78922 down_read(&uts_sem);
78923- error = __copy_to_user(&name->sysname, &utsname()->sysname,
78924+ error = __copy_to_user(name->sysname, &utsname()->sysname,
78925 __OLD_UTS_LEN);
78926 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
78927- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
78928+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
78929 __OLD_UTS_LEN);
78930 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
78931- error |= __copy_to_user(&name->release, &utsname()->release,
78932+ error |= __copy_to_user(name->release, &utsname()->release,
78933 __OLD_UTS_LEN);
78934 error |= __put_user(0, name->release + __OLD_UTS_LEN);
78935- error |= __copy_to_user(&name->version, &utsname()->version,
78936+ error |= __copy_to_user(name->version, &utsname()->version,
78937 __OLD_UTS_LEN);
78938 error |= __put_user(0, name->version + __OLD_UTS_LEN);
78939- error |= __copy_to_user(&name->machine, &utsname()->machine,
78940+ error |= __copy_to_user(name->machine, &utsname()->machine,
78941 __OLD_UTS_LEN);
78942 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
78943 up_read(&uts_sem);
78944@@ -2027,7 +2063,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
78945 error = get_dumpable(me->mm);
78946 break;
78947 case PR_SET_DUMPABLE:
78948- if (arg2 < 0 || arg2 > 1) {
78949+ if (arg2 > 1) {
78950 error = -EINVAL;
78951 break;
78952 }
78953diff --git a/kernel/sysctl.c b/kernel/sysctl.c
78954index c88878d..e4fa5d1 100644
78955--- a/kernel/sysctl.c
78956+++ b/kernel/sysctl.c
78957@@ -92,7 +92,6 @@
78958
78959
78960 #if defined(CONFIG_SYSCTL)
78961-
78962 /* External variables not in a header file. */
78963 extern int sysctl_overcommit_memory;
78964 extern int sysctl_overcommit_ratio;
78965@@ -172,10 +171,8 @@ static int proc_taint(struct ctl_table *table, int write,
78966 void __user *buffer, size_t *lenp, loff_t *ppos);
78967 #endif
78968
78969-#ifdef CONFIG_PRINTK
78970 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
78971 void __user *buffer, size_t *lenp, loff_t *ppos);
78972-#endif
78973
78974 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
78975 void __user *buffer, size_t *lenp, loff_t *ppos);
78976@@ -206,6 +203,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
78977
78978 #endif
78979
78980+extern struct ctl_table grsecurity_table[];
78981+
78982 static struct ctl_table kern_table[];
78983 static struct ctl_table vm_table[];
78984 static struct ctl_table fs_table[];
78985@@ -220,6 +219,20 @@ extern struct ctl_table epoll_table[];
78986 int sysctl_legacy_va_layout;
78987 #endif
78988
78989+#ifdef CONFIG_PAX_SOFTMODE
78990+static ctl_table pax_table[] = {
78991+ {
78992+ .procname = "softmode",
78993+ .data = &pax_softmode,
78994+ .maxlen = sizeof(unsigned int),
78995+ .mode = 0600,
78996+ .proc_handler = &proc_dointvec,
78997+ },
78998+
78999+ { }
79000+};
79001+#endif
79002+
79003 /* The default sysctl tables: */
79004
79005 static struct ctl_table sysctl_base_table[] = {
79006@@ -268,6 +281,22 @@ static int max_extfrag_threshold = 1000;
79007 #endif
79008
79009 static struct ctl_table kern_table[] = {
79010+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
79011+ {
79012+ .procname = "grsecurity",
79013+ .mode = 0500,
79014+ .child = grsecurity_table,
79015+ },
79016+#endif
79017+
79018+#ifdef CONFIG_PAX_SOFTMODE
79019+ {
79020+ .procname = "pax",
79021+ .mode = 0500,
79022+ .child = pax_table,
79023+ },
79024+#endif
79025+
79026 {
79027 .procname = "sched_child_runs_first",
79028 .data = &sysctl_sched_child_runs_first,
79029@@ -593,7 +622,7 @@ static struct ctl_table kern_table[] = {
79030 .data = &modprobe_path,
79031 .maxlen = KMOD_PATH_LEN,
79032 .mode = 0644,
79033- .proc_handler = proc_dostring,
79034+ .proc_handler = proc_dostring_modpriv,
79035 },
79036 {
79037 .procname = "modules_disabled",
79038@@ -760,16 +789,20 @@ static struct ctl_table kern_table[] = {
79039 .extra1 = &zero,
79040 .extra2 = &one,
79041 },
79042+#endif
79043 {
79044 .procname = "kptr_restrict",
79045 .data = &kptr_restrict,
79046 .maxlen = sizeof(int),
79047 .mode = 0644,
79048 .proc_handler = proc_dointvec_minmax_sysadmin,
79049+#ifdef CONFIG_GRKERNSEC_HIDESYM
79050+ .extra1 = &two,
79051+#else
79052 .extra1 = &zero,
79053+#endif
79054 .extra2 = &two,
79055 },
79056-#endif
79057 {
79058 .procname = "ngroups_max",
79059 .data = &ngroups_max,
79060@@ -1266,6 +1299,13 @@ static struct ctl_table vm_table[] = {
79061 .proc_handler = proc_dointvec_minmax,
79062 .extra1 = &zero,
79063 },
79064+ {
79065+ .procname = "heap_stack_gap",
79066+ .data = &sysctl_heap_stack_gap,
79067+ .maxlen = sizeof(sysctl_heap_stack_gap),
79068+ .mode = 0644,
79069+ .proc_handler = proc_doulongvec_minmax,
79070+ },
79071 #else
79072 {
79073 .procname = "nr_trim_pages",
79074@@ -1716,6 +1756,16 @@ int proc_dostring(struct ctl_table *table, int write,
79075 buffer, lenp, ppos);
79076 }
79077
79078+int proc_dostring_modpriv(struct ctl_table *table, int write,
79079+ void __user *buffer, size_t *lenp, loff_t *ppos)
79080+{
79081+ if (write && !capable(CAP_SYS_MODULE))
79082+ return -EPERM;
79083+
79084+ return _proc_do_string(table->data, table->maxlen, write,
79085+ buffer, lenp, ppos);
79086+}
79087+
79088 static size_t proc_skip_spaces(char **buf)
79089 {
79090 size_t ret;
79091@@ -1821,6 +1871,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
79092 len = strlen(tmp);
79093 if (len > *size)
79094 len = *size;
79095+ if (len > sizeof(tmp))
79096+ len = sizeof(tmp);
79097 if (copy_to_user(*buf, tmp, len))
79098 return -EFAULT;
79099 *size -= len;
79100@@ -1985,7 +2037,7 @@ int proc_dointvec(struct ctl_table *table, int write,
79101 static int proc_taint(struct ctl_table *table, int write,
79102 void __user *buffer, size_t *lenp, loff_t *ppos)
79103 {
79104- struct ctl_table t;
79105+ ctl_table_no_const t;
79106 unsigned long tmptaint = get_taint();
79107 int err;
79108
79109@@ -2013,7 +2065,6 @@ static int proc_taint(struct ctl_table *table, int write,
79110 return err;
79111 }
79112
79113-#ifdef CONFIG_PRINTK
79114 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
79115 void __user *buffer, size_t *lenp, loff_t *ppos)
79116 {
79117@@ -2022,7 +2073,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
79118
79119 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
79120 }
79121-#endif
79122
79123 struct do_proc_dointvec_minmax_conv_param {
79124 int *min;
79125@@ -2169,8 +2219,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
79126 *i = val;
79127 } else {
79128 val = convdiv * (*i) / convmul;
79129- if (!first)
79130+ if (!first) {
79131 err = proc_put_char(&buffer, &left, '\t');
79132+ if (err)
79133+ break;
79134+ }
79135 err = proc_put_long(&buffer, &left, val, false);
79136 if (err)
79137 break;
79138@@ -2562,6 +2615,12 @@ int proc_dostring(struct ctl_table *table, int write,
79139 return -ENOSYS;
79140 }
79141
79142+int proc_dostring_modpriv(struct ctl_table *table, int write,
79143+ void __user *buffer, size_t *lenp, loff_t *ppos)
79144+{
79145+ return -ENOSYS;
79146+}
79147+
79148 int proc_dointvec(struct ctl_table *table, int write,
79149 void __user *buffer, size_t *lenp, loff_t *ppos)
79150 {
79151@@ -2618,5 +2677,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
79152 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
79153 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
79154 EXPORT_SYMBOL(proc_dostring);
79155+EXPORT_SYMBOL(proc_dostring_modpriv);
79156 EXPORT_SYMBOL(proc_doulongvec_minmax);
79157 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
79158diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
79159index 0ddf3a0..a199f50 100644
79160--- a/kernel/sysctl_binary.c
79161+++ b/kernel/sysctl_binary.c
79162@@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
79163 int i;
79164
79165 set_fs(KERNEL_DS);
79166- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
79167+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
79168 set_fs(old_fs);
79169 if (result < 0)
79170 goto out_kfree;
79171@@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
79172 }
79173
79174 set_fs(KERNEL_DS);
79175- result = vfs_write(file, buffer, str - buffer, &pos);
79176+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
79177 set_fs(old_fs);
79178 if (result < 0)
79179 goto out_kfree;
79180@@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
79181 int i;
79182
79183 set_fs(KERNEL_DS);
79184- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
79185+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
79186 set_fs(old_fs);
79187 if (result < 0)
79188 goto out_kfree;
79189@@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
79190 }
79191
79192 set_fs(KERNEL_DS);
79193- result = vfs_write(file, buffer, str - buffer, &pos);
79194+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
79195 set_fs(old_fs);
79196 if (result < 0)
79197 goto out_kfree;
79198@@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
79199 int i;
79200
79201 set_fs(KERNEL_DS);
79202- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
79203+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
79204 set_fs(old_fs);
79205 if (result < 0)
79206 goto out;
79207@@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
79208 __le16 dnaddr;
79209
79210 set_fs(KERNEL_DS);
79211- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
79212+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
79213 set_fs(old_fs);
79214 if (result < 0)
79215 goto out;
79216@@ -1234,7 +1234,7 @@ static ssize_t bin_dn_node_address(struct file *file,
79217 le16_to_cpu(dnaddr) & 0x3ff);
79218
79219 set_fs(KERNEL_DS);
79220- result = vfs_write(file, buf, len, &pos);
79221+ result = vfs_write(file, (const char __force_user *)buf, len, &pos);
79222 set_fs(old_fs);
79223 if (result < 0)
79224 goto out;
79225diff --git a/kernel/taskstats.c b/kernel/taskstats.c
79226index 145bb4d..b2aa969 100644
79227--- a/kernel/taskstats.c
79228+++ b/kernel/taskstats.c
79229@@ -28,9 +28,12 @@
79230 #include <linux/fs.h>
79231 #include <linux/file.h>
79232 #include <linux/pid_namespace.h>
79233+#include <linux/grsecurity.h>
79234 #include <net/genetlink.h>
79235 #include <linux/atomic.h>
79236
79237+extern int gr_is_taskstats_denied(int pid);
79238+
79239 /*
79240 * Maximum length of a cpumask that can be specified in
79241 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
79242@@ -570,6 +573,9 @@ err:
79243
79244 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
79245 {
79246+ if (gr_is_taskstats_denied(current->pid))
79247+ return -EACCES;
79248+
79249 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
79250 return cmd_attr_register_cpumask(info);
79251 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
79252diff --git a/kernel/time.c b/kernel/time.c
79253index d226c6a..2f0d217 100644
79254--- a/kernel/time.c
79255+++ b/kernel/time.c
79256@@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
79257 return error;
79258
79259 if (tz) {
79260+ /* we log in do_settimeofday called below, so don't log twice
79261+ */
79262+ if (!tv)
79263+ gr_log_timechange();
79264+
79265 sys_tz = *tz;
79266 update_vsyscall_tz();
79267 if (firsttime) {
79268@@ -493,7 +498,7 @@ EXPORT_SYMBOL(usecs_to_jiffies);
79269 * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec
79270 * value to a scaled second value.
79271 */
79272-unsigned long
79273+unsigned long __intentional_overflow(-1)
79274 timespec_to_jiffies(const struct timespec *value)
79275 {
79276 unsigned long sec = value->tv_sec;
79277diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
79278index f11d83b..d016d91 100644
79279--- a/kernel/time/alarmtimer.c
79280+++ b/kernel/time/alarmtimer.c
79281@@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
79282 struct platform_device *pdev;
79283 int error = 0;
79284 int i;
79285- struct k_clock alarm_clock = {
79286+ static struct k_clock alarm_clock = {
79287 .clock_getres = alarm_clock_getres,
79288 .clock_get = alarm_clock_get,
79289 .timer_create = alarm_timer_create,
79290diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
79291index a13987a..36cd791 100644
79292--- a/kernel/time/tick-broadcast.c
79293+++ b/kernel/time/tick-broadcast.c
79294@@ -116,7 +116,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
79295 * then clear the broadcast bit.
79296 */
79297 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
79298- int cpu = smp_processor_id();
79299+ cpu = smp_processor_id();
79300
79301 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
79302 tick_broadcast_clear_oneshot(cpu);
79303diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
79304index cbc6acb..3a77191 100644
79305--- a/kernel/time/timekeeping.c
79306+++ b/kernel/time/timekeeping.c
79307@@ -15,6 +15,7 @@
79308 #include <linux/init.h>
79309 #include <linux/mm.h>
79310 #include <linux/sched.h>
79311+#include <linux/grsecurity.h>
79312 #include <linux/syscore_ops.h>
79313 #include <linux/clocksource.h>
79314 #include <linux/jiffies.h>
79315@@ -412,6 +413,8 @@ int do_settimeofday(const struct timespec *tv)
79316 if (!timespec_valid_strict(tv))
79317 return -EINVAL;
79318
79319+ gr_log_timechange();
79320+
79321 write_seqlock_irqsave(&tk->lock, flags);
79322
79323 timekeeping_forward_now(tk);
79324diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
79325index af5a7e9..715611a 100644
79326--- a/kernel/time/timer_list.c
79327+++ b/kernel/time/timer_list.c
79328@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
79329
79330 static void print_name_offset(struct seq_file *m, void *sym)
79331 {
79332+#ifdef CONFIG_GRKERNSEC_HIDESYM
79333+ SEQ_printf(m, "<%p>", NULL);
79334+#else
79335 char symname[KSYM_NAME_LEN];
79336
79337 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
79338 SEQ_printf(m, "<%pK>", sym);
79339 else
79340 SEQ_printf(m, "%s", symname);
79341+#endif
79342 }
79343
79344 static void
79345@@ -112,7 +116,11 @@ next_one:
79346 static void
79347 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
79348 {
79349+#ifdef CONFIG_GRKERNSEC_HIDESYM
79350+ SEQ_printf(m, " .base: %p\n", NULL);
79351+#else
79352 SEQ_printf(m, " .base: %pK\n", base);
79353+#endif
79354 SEQ_printf(m, " .index: %d\n",
79355 base->index);
79356 SEQ_printf(m, " .resolution: %Lu nsecs\n",
79357@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
79358 {
79359 struct proc_dir_entry *pe;
79360
79361+#ifdef CONFIG_GRKERNSEC_PROC_ADD
79362+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
79363+#else
79364 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
79365+#endif
79366 if (!pe)
79367 return -ENOMEM;
79368 return 0;
79369diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
79370index 0b537f2..40d6c20 100644
79371--- a/kernel/time/timer_stats.c
79372+++ b/kernel/time/timer_stats.c
79373@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
79374 static unsigned long nr_entries;
79375 static struct entry entries[MAX_ENTRIES];
79376
79377-static atomic_t overflow_count;
79378+static atomic_unchecked_t overflow_count;
79379
79380 /*
79381 * The entries are in a hash-table, for fast lookup:
79382@@ -140,7 +140,7 @@ static void reset_entries(void)
79383 nr_entries = 0;
79384 memset(entries, 0, sizeof(entries));
79385 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
79386- atomic_set(&overflow_count, 0);
79387+ atomic_set_unchecked(&overflow_count, 0);
79388 }
79389
79390 static struct entry *alloc_entry(void)
79391@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
79392 if (likely(entry))
79393 entry->count++;
79394 else
79395- atomic_inc(&overflow_count);
79396+ atomic_inc_unchecked(&overflow_count);
79397
79398 out_unlock:
79399 raw_spin_unlock_irqrestore(lock, flags);
79400@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
79401
79402 static void print_name_offset(struct seq_file *m, unsigned long addr)
79403 {
79404+#ifdef CONFIG_GRKERNSEC_HIDESYM
79405+ seq_printf(m, "<%p>", NULL);
79406+#else
79407 char symname[KSYM_NAME_LEN];
79408
79409 if (lookup_symbol_name(addr, symname) < 0)
79410- seq_printf(m, "<%p>", (void *)addr);
79411+ seq_printf(m, "<%pK>", (void *)addr);
79412 else
79413 seq_printf(m, "%s", symname);
79414+#endif
79415 }
79416
79417 static int tstats_show(struct seq_file *m, void *v)
79418@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
79419
79420 seq_puts(m, "Timer Stats Version: v0.2\n");
79421 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
79422- if (atomic_read(&overflow_count))
79423+ if (atomic_read_unchecked(&overflow_count))
79424 seq_printf(m, "Overflow: %d entries\n",
79425- atomic_read(&overflow_count));
79426+ atomic_read_unchecked(&overflow_count));
79427
79428 for (i = 0; i < nr_entries; i++) {
79429 entry = entries + i;
79430@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
79431 {
79432 struct proc_dir_entry *pe;
79433
79434+#ifdef CONFIG_GRKERNSEC_PROC_ADD
79435+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
79436+#else
79437 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
79438+#endif
79439 if (!pe)
79440 return -ENOMEM;
79441 return 0;
79442diff --git a/kernel/timer.c b/kernel/timer.c
79443index 367d008..5dee98f 100644
79444--- a/kernel/timer.c
79445+++ b/kernel/timer.c
79446@@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
79447 /*
79448 * This function runs timers and the timer-tq in bottom half context.
79449 */
79450-static void run_timer_softirq(struct softirq_action *h)
79451+static void run_timer_softirq(void)
79452 {
79453 struct tvec_base *base = __this_cpu_read(tvec_bases);
79454
79455@@ -1481,7 +1481,7 @@ static void process_timeout(unsigned long __data)
79456 *
79457 * In all cases the return value is guaranteed to be non-negative.
79458 */
79459-signed long __sched schedule_timeout(signed long timeout)
79460+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
79461 {
79462 struct timer_list timer;
79463 unsigned long expire;
79464@@ -1772,7 +1772,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
79465 return NOTIFY_OK;
79466 }
79467
79468-static struct notifier_block __cpuinitdata timers_nb = {
79469+static struct notifier_block timers_nb = {
79470 .notifier_call = timer_cpu_notify,
79471 };
79472
79473diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
79474index c0bd030..62a1927 100644
79475--- a/kernel/trace/blktrace.c
79476+++ b/kernel/trace/blktrace.c
79477@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
79478 struct blk_trace *bt = filp->private_data;
79479 char buf[16];
79480
79481- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
79482+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
79483
79484 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
79485 }
79486@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
79487 return 1;
79488
79489 bt = buf->chan->private_data;
79490- atomic_inc(&bt->dropped);
79491+ atomic_inc_unchecked(&bt->dropped);
79492 return 0;
79493 }
79494
79495@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
79496
79497 bt->dir = dir;
79498 bt->dev = dev;
79499- atomic_set(&bt->dropped, 0);
79500+ atomic_set_unchecked(&bt->dropped, 0);
79501
79502 ret = -EIO;
79503 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
79504diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
79505index 35cc3a8..2a47da3 100644
79506--- a/kernel/trace/ftrace.c
79507+++ b/kernel/trace/ftrace.c
79508@@ -1886,12 +1886,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
79509 if (unlikely(ftrace_disabled))
79510 return 0;
79511
79512+ ret = ftrace_arch_code_modify_prepare();
79513+ FTRACE_WARN_ON(ret);
79514+ if (ret)
79515+ return 0;
79516+
79517 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
79518+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
79519 if (ret) {
79520 ftrace_bug(ret, ip);
79521- return 0;
79522 }
79523- return 1;
79524+ return ret ? 0 : 1;
79525 }
79526
79527 /*
79528@@ -2964,7 +2969,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
79529
79530 int
79531 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
79532- void *data)
79533+ void *data)
79534 {
79535 struct ftrace_func_probe *entry;
79536 struct ftrace_page *pg;
79537@@ -3831,8 +3836,10 @@ static int ftrace_process_locs(struct module *mod,
79538 if (!count)
79539 return 0;
79540
79541+ pax_open_kernel();
79542 sort(start, count, sizeof(*start),
79543 ftrace_cmp_ips, ftrace_swap_ips);
79544+ pax_close_kernel();
79545
79546 start_pg = ftrace_allocate_pages(count);
79547 if (!start_pg)
79548@@ -4554,8 +4561,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
79549 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
79550
79551 static int ftrace_graph_active;
79552-static struct notifier_block ftrace_suspend_notifier;
79553-
79554 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
79555 {
79556 return 0;
79557@@ -4699,6 +4704,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
79558 return NOTIFY_DONE;
79559 }
79560
79561+static struct notifier_block ftrace_suspend_notifier = {
79562+ .notifier_call = ftrace_suspend_notifier_call
79563+};
79564+
79565 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
79566 trace_func_graph_ent_t entryfunc)
79567 {
79568@@ -4712,7 +4721,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
79569 goto out;
79570 }
79571
79572- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
79573 register_pm_notifier(&ftrace_suspend_notifier);
79574
79575 ftrace_graph_active++;
79576diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
79577index ce8514f..8233573 100644
79578--- a/kernel/trace/ring_buffer.c
79579+++ b/kernel/trace/ring_buffer.c
79580@@ -346,9 +346,9 @@ struct buffer_data_page {
79581 */
79582 struct buffer_page {
79583 struct list_head list; /* list of buffer pages */
79584- local_t write; /* index for next write */
79585+ local_unchecked_t write; /* index for next write */
79586 unsigned read; /* index for next read */
79587- local_t entries; /* entries on this page */
79588+ local_unchecked_t entries; /* entries on this page */
79589 unsigned long real_end; /* real end of data */
79590 struct buffer_data_page *page; /* Actual data page */
79591 };
79592@@ -461,8 +461,8 @@ struct ring_buffer_per_cpu {
79593 unsigned long last_overrun;
79594 local_t entries_bytes;
79595 local_t entries;
79596- local_t overrun;
79597- local_t commit_overrun;
79598+ local_unchecked_t overrun;
79599+ local_unchecked_t commit_overrun;
79600 local_t dropped_events;
79601 local_t committing;
79602 local_t commits;
79603@@ -861,8 +861,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
79604 *
79605 * We add a counter to the write field to denote this.
79606 */
79607- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
79608- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
79609+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
79610+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
79611
79612 /*
79613 * Just make sure we have seen our old_write and synchronize
79614@@ -890,8 +890,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
79615 * cmpxchg to only update if an interrupt did not already
79616 * do it for us. If the cmpxchg fails, we don't care.
79617 */
79618- (void)local_cmpxchg(&next_page->write, old_write, val);
79619- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
79620+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
79621+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
79622
79623 /*
79624 * No need to worry about races with clearing out the commit.
79625@@ -1250,12 +1250,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
79626
79627 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
79628 {
79629- return local_read(&bpage->entries) & RB_WRITE_MASK;
79630+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
79631 }
79632
79633 static inline unsigned long rb_page_write(struct buffer_page *bpage)
79634 {
79635- return local_read(&bpage->write) & RB_WRITE_MASK;
79636+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
79637 }
79638
79639 static int
79640@@ -1350,7 +1350,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
79641 * bytes consumed in ring buffer from here.
79642 * Increment overrun to account for the lost events.
79643 */
79644- local_add(page_entries, &cpu_buffer->overrun);
79645+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
79646 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
79647 }
79648
79649@@ -1906,7 +1906,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
79650 * it is our responsibility to update
79651 * the counters.
79652 */
79653- local_add(entries, &cpu_buffer->overrun);
79654+ local_add_unchecked(entries, &cpu_buffer->overrun);
79655 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
79656
79657 /*
79658@@ -2056,7 +2056,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
79659 if (tail == BUF_PAGE_SIZE)
79660 tail_page->real_end = 0;
79661
79662- local_sub(length, &tail_page->write);
79663+ local_sub_unchecked(length, &tail_page->write);
79664 return;
79665 }
79666
79667@@ -2091,7 +2091,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
79668 rb_event_set_padding(event);
79669
79670 /* Set the write back to the previous setting */
79671- local_sub(length, &tail_page->write);
79672+ local_sub_unchecked(length, &tail_page->write);
79673 return;
79674 }
79675
79676@@ -2103,7 +2103,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
79677
79678 /* Set write to end of buffer */
79679 length = (tail + length) - BUF_PAGE_SIZE;
79680- local_sub(length, &tail_page->write);
79681+ local_sub_unchecked(length, &tail_page->write);
79682 }
79683
79684 /*
79685@@ -2129,7 +2129,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
79686 * about it.
79687 */
79688 if (unlikely(next_page == commit_page)) {
79689- local_inc(&cpu_buffer->commit_overrun);
79690+ local_inc_unchecked(&cpu_buffer->commit_overrun);
79691 goto out_reset;
79692 }
79693
79694@@ -2185,7 +2185,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
79695 cpu_buffer->tail_page) &&
79696 (cpu_buffer->commit_page ==
79697 cpu_buffer->reader_page))) {
79698- local_inc(&cpu_buffer->commit_overrun);
79699+ local_inc_unchecked(&cpu_buffer->commit_overrun);
79700 goto out_reset;
79701 }
79702 }
79703@@ -2233,7 +2233,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
79704 length += RB_LEN_TIME_EXTEND;
79705
79706 tail_page = cpu_buffer->tail_page;
79707- write = local_add_return(length, &tail_page->write);
79708+ write = local_add_return_unchecked(length, &tail_page->write);
79709
79710 /* set write to only the index of the write */
79711 write &= RB_WRITE_MASK;
79712@@ -2250,7 +2250,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
79713 kmemcheck_annotate_bitfield(event, bitfield);
79714 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
79715
79716- local_inc(&tail_page->entries);
79717+ local_inc_unchecked(&tail_page->entries);
79718
79719 /*
79720 * If this is the first commit on the page, then update
79721@@ -2283,7 +2283,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
79722
79723 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
79724 unsigned long write_mask =
79725- local_read(&bpage->write) & ~RB_WRITE_MASK;
79726+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
79727 unsigned long event_length = rb_event_length(event);
79728 /*
79729 * This is on the tail page. It is possible that
79730@@ -2293,7 +2293,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
79731 */
79732 old_index += write_mask;
79733 new_index += write_mask;
79734- index = local_cmpxchg(&bpage->write, old_index, new_index);
79735+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
79736 if (index == old_index) {
79737 /* update counters */
79738 local_sub(event_length, &cpu_buffer->entries_bytes);
79739@@ -2632,7 +2632,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
79740
79741 /* Do the likely case first */
79742 if (likely(bpage->page == (void *)addr)) {
79743- local_dec(&bpage->entries);
79744+ local_dec_unchecked(&bpage->entries);
79745 return;
79746 }
79747
79748@@ -2644,7 +2644,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
79749 start = bpage;
79750 do {
79751 if (bpage->page == (void *)addr) {
79752- local_dec(&bpage->entries);
79753+ local_dec_unchecked(&bpage->entries);
79754 return;
79755 }
79756 rb_inc_page(cpu_buffer, &bpage);
79757@@ -2926,7 +2926,7 @@ static inline unsigned long
79758 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
79759 {
79760 return local_read(&cpu_buffer->entries) -
79761- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
79762+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
79763 }
79764
79765 /**
79766@@ -3015,7 +3015,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
79767 return 0;
79768
79769 cpu_buffer = buffer->buffers[cpu];
79770- ret = local_read(&cpu_buffer->overrun);
79771+ ret = local_read_unchecked(&cpu_buffer->overrun);
79772
79773 return ret;
79774 }
79775@@ -3038,7 +3038,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
79776 return 0;
79777
79778 cpu_buffer = buffer->buffers[cpu];
79779- ret = local_read(&cpu_buffer->commit_overrun);
79780+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
79781
79782 return ret;
79783 }
79784@@ -3105,7 +3105,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
79785 /* if you care about this being correct, lock the buffer */
79786 for_each_buffer_cpu(buffer, cpu) {
79787 cpu_buffer = buffer->buffers[cpu];
79788- overruns += local_read(&cpu_buffer->overrun);
79789+ overruns += local_read_unchecked(&cpu_buffer->overrun);
79790 }
79791
79792 return overruns;
79793@@ -3281,8 +3281,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
79794 /*
79795 * Reset the reader page to size zero.
79796 */
79797- local_set(&cpu_buffer->reader_page->write, 0);
79798- local_set(&cpu_buffer->reader_page->entries, 0);
79799+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
79800+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
79801 local_set(&cpu_buffer->reader_page->page->commit, 0);
79802 cpu_buffer->reader_page->real_end = 0;
79803
79804@@ -3316,7 +3316,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
79805 * want to compare with the last_overrun.
79806 */
79807 smp_mb();
79808- overwrite = local_read(&(cpu_buffer->overrun));
79809+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
79810
79811 /*
79812 * Here's the tricky part.
79813@@ -3886,8 +3886,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
79814
79815 cpu_buffer->head_page
79816 = list_entry(cpu_buffer->pages, struct buffer_page, list);
79817- local_set(&cpu_buffer->head_page->write, 0);
79818- local_set(&cpu_buffer->head_page->entries, 0);
79819+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
79820+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
79821 local_set(&cpu_buffer->head_page->page->commit, 0);
79822
79823 cpu_buffer->head_page->read = 0;
79824@@ -3897,14 +3897,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
79825
79826 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
79827 INIT_LIST_HEAD(&cpu_buffer->new_pages);
79828- local_set(&cpu_buffer->reader_page->write, 0);
79829- local_set(&cpu_buffer->reader_page->entries, 0);
79830+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
79831+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
79832 local_set(&cpu_buffer->reader_page->page->commit, 0);
79833 cpu_buffer->reader_page->read = 0;
79834
79835 local_set(&cpu_buffer->entries_bytes, 0);
79836- local_set(&cpu_buffer->overrun, 0);
79837- local_set(&cpu_buffer->commit_overrun, 0);
79838+ local_set_unchecked(&cpu_buffer->overrun, 0);
79839+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
79840 local_set(&cpu_buffer->dropped_events, 0);
79841 local_set(&cpu_buffer->entries, 0);
79842 local_set(&cpu_buffer->committing, 0);
79843@@ -4308,8 +4308,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
79844 rb_init_page(bpage);
79845 bpage = reader->page;
79846 reader->page = *data_page;
79847- local_set(&reader->write, 0);
79848- local_set(&reader->entries, 0);
79849+ local_set_unchecked(&reader->write, 0);
79850+ local_set_unchecked(&reader->entries, 0);
79851 reader->read = 0;
79852 *data_page = bpage;
79853
79854diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
79855index fe1d581..43a0f38 100644
79856--- a/kernel/trace/trace.c
79857+++ b/kernel/trace/trace.c
79858@@ -4494,10 +4494,9 @@ static const struct file_operations tracing_dyn_info_fops = {
79859 };
79860 #endif
79861
79862-static struct dentry *d_tracer;
79863-
79864 struct dentry *tracing_init_dentry(void)
79865 {
79866+ static struct dentry *d_tracer;
79867 static int once;
79868
79869 if (d_tracer)
79870@@ -4517,10 +4516,9 @@ struct dentry *tracing_init_dentry(void)
79871 return d_tracer;
79872 }
79873
79874-static struct dentry *d_percpu;
79875-
79876 struct dentry *tracing_dentry_percpu(void)
79877 {
79878+ static struct dentry *d_percpu;
79879 static int once;
79880 struct dentry *d_tracer;
79881
79882diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
79883index 880073d..42db7c3 100644
79884--- a/kernel/trace/trace_events.c
79885+++ b/kernel/trace/trace_events.c
79886@@ -1330,10 +1330,6 @@ static LIST_HEAD(ftrace_module_file_list);
79887 struct ftrace_module_file_ops {
79888 struct list_head list;
79889 struct module *mod;
79890- struct file_operations id;
79891- struct file_operations enable;
79892- struct file_operations format;
79893- struct file_operations filter;
79894 };
79895
79896 static struct ftrace_module_file_ops *
79897@@ -1354,17 +1350,12 @@ trace_create_file_ops(struct module *mod)
79898
79899 file_ops->mod = mod;
79900
79901- file_ops->id = ftrace_event_id_fops;
79902- file_ops->id.owner = mod;
79903-
79904- file_ops->enable = ftrace_enable_fops;
79905- file_ops->enable.owner = mod;
79906-
79907- file_ops->filter = ftrace_event_filter_fops;
79908- file_ops->filter.owner = mod;
79909-
79910- file_ops->format = ftrace_event_format_fops;
79911- file_ops->format.owner = mod;
79912+ pax_open_kernel();
79913+ mod->trace_id.owner = mod;
79914+ mod->trace_enable.owner = mod;
79915+ mod->trace_filter.owner = mod;
79916+ mod->trace_format.owner = mod;
79917+ pax_close_kernel();
79918
79919 list_add(&file_ops->list, &ftrace_module_file_list);
79920
79921@@ -1388,8 +1379,8 @@ static void trace_module_add_events(struct module *mod)
79922
79923 for_each_event(call, start, end) {
79924 __trace_add_event_call(*call, mod,
79925- &file_ops->id, &file_ops->enable,
79926- &file_ops->filter, &file_ops->format);
79927+ &mod->trace_id, &mod->trace_enable,
79928+ &mod->trace_filter, &mod->trace_format);
79929 }
79930 }
79931
79932diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
79933index fd3c8aa..5f324a6 100644
79934--- a/kernel/trace/trace_mmiotrace.c
79935+++ b/kernel/trace/trace_mmiotrace.c
79936@@ -24,7 +24,7 @@ struct header_iter {
79937 static struct trace_array *mmio_trace_array;
79938 static bool overrun_detected;
79939 static unsigned long prev_overruns;
79940-static atomic_t dropped_count;
79941+static atomic_unchecked_t dropped_count;
79942
79943 static void mmio_reset_data(struct trace_array *tr)
79944 {
79945@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
79946
79947 static unsigned long count_overruns(struct trace_iterator *iter)
79948 {
79949- unsigned long cnt = atomic_xchg(&dropped_count, 0);
79950+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
79951 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
79952
79953 if (over > prev_overruns)
79954@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
79955 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
79956 sizeof(*entry), 0, pc);
79957 if (!event) {
79958- atomic_inc(&dropped_count);
79959+ atomic_inc_unchecked(&dropped_count);
79960 return;
79961 }
79962 entry = ring_buffer_event_data(event);
79963@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
79964 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
79965 sizeof(*entry), 0, pc);
79966 if (!event) {
79967- atomic_inc(&dropped_count);
79968+ atomic_inc_unchecked(&dropped_count);
79969 return;
79970 }
79971 entry = ring_buffer_event_data(event);
79972diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
79973index 194d796..76edb8f 100644
79974--- a/kernel/trace/trace_output.c
79975+++ b/kernel/trace/trace_output.c
79976@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
79977
79978 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
79979 if (!IS_ERR(p)) {
79980- p = mangle_path(s->buffer + s->len, p, "\n");
79981+ p = mangle_path(s->buffer + s->len, p, "\n\\");
79982 if (p) {
79983 s->len = p - s->buffer;
79984 return 1;
79985@@ -852,14 +852,16 @@ int register_ftrace_event(struct trace_event *event)
79986 goto out;
79987 }
79988
79989+ pax_open_kernel();
79990 if (event->funcs->trace == NULL)
79991- event->funcs->trace = trace_nop_print;
79992+ *(void **)&event->funcs->trace = trace_nop_print;
79993 if (event->funcs->raw == NULL)
79994- event->funcs->raw = trace_nop_print;
79995+ *(void **)&event->funcs->raw = trace_nop_print;
79996 if (event->funcs->hex == NULL)
79997- event->funcs->hex = trace_nop_print;
79998+ *(void **)&event->funcs->hex = trace_nop_print;
79999 if (event->funcs->binary == NULL)
80000- event->funcs->binary = trace_nop_print;
80001+ *(void **)&event->funcs->binary = trace_nop_print;
80002+ pax_close_kernel();
80003
80004 key = event->type & (EVENT_HASHSIZE - 1);
80005
80006diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
80007index 83a8b5b..0bf39a9 100644
80008--- a/kernel/trace/trace_stack.c
80009+++ b/kernel/trace/trace_stack.c
80010@@ -52,7 +52,7 @@ static inline void check_stack(void)
80011 return;
80012
80013 /* we do not handle interrupt stacks yet */
80014- if (!object_is_on_stack(&this_size))
80015+ if (!object_starts_on_stack(&this_size))
80016 return;
80017
80018 local_irq_save(flags);
80019diff --git a/kernel/user.c b/kernel/user.c
80020index 7f6ff2b..1ac8f18 100644
80021--- a/kernel/user.c
80022+++ b/kernel/user.c
80023@@ -47,9 +47,7 @@ struct user_namespace init_user_ns = {
80024 .count = 4294967295U,
80025 },
80026 },
80027- .kref = {
80028- .refcount = ATOMIC_INIT(3),
80029- },
80030+ .count = ATOMIC_INIT(3),
80031 .owner = GLOBAL_ROOT_UID,
80032 .group = GLOBAL_ROOT_GID,
80033 .proc_inum = PROC_USER_INIT_INO,
80034diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
80035index f45e128..a5a5fb6 100644
80036--- a/kernel/user_namespace.c
80037+++ b/kernel/user_namespace.c
80038@@ -88,7 +88,7 @@ int create_user_ns(struct cred *new)
80039 return ret;
80040 }
80041
80042- kref_init(&ns->kref);
80043+ atomic_set(&ns->count, 1);
80044 /* Leave the new->user_ns reference with the new user namespace. */
80045 ns->parent = parent_ns;
80046 ns->owner = owner;
80047@@ -116,15 +116,16 @@ int unshare_userns(unsigned long unshare_flags, struct cred **new_cred)
80048 return create_user_ns(cred);
80049 }
80050
80051-void free_user_ns(struct kref *kref)
80052+void free_user_ns(struct user_namespace *ns)
80053 {
80054- struct user_namespace *parent, *ns =
80055- container_of(kref, struct user_namespace, kref);
80056+ struct user_namespace *parent;
80057
80058- parent = ns->parent;
80059- proc_free_inum(ns->proc_inum);
80060- kmem_cache_free(user_ns_cachep, ns);
80061- put_user_ns(parent);
80062+ do {
80063+ parent = ns->parent;
80064+ proc_free_inum(ns->proc_inum);
80065+ kmem_cache_free(user_ns_cachep, ns);
80066+ ns = parent;
80067+ } while (atomic_dec_and_test(&parent->count));
80068 }
80069 EXPORT_SYMBOL(free_user_ns);
80070
80071@@ -815,7 +816,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
80072 if (atomic_read(&current->mm->mm_users) > 1)
80073 return -EINVAL;
80074
80075- if (current->fs->users != 1)
80076+ if (atomic_read(&current->fs->users) != 1)
80077 return -EINVAL;
80078
80079 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
80080diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
80081index 63da38c..639904e 100644
80082--- a/kernel/utsname_sysctl.c
80083+++ b/kernel/utsname_sysctl.c
80084@@ -46,7 +46,7 @@ static void put_uts(ctl_table *table, int write, void *which)
80085 static int proc_do_uts_string(ctl_table *table, int write,
80086 void __user *buffer, size_t *lenp, loff_t *ppos)
80087 {
80088- struct ctl_table uts_table;
80089+ ctl_table_no_const uts_table;
80090 int r;
80091 memcpy(&uts_table, table, sizeof(uts_table));
80092 uts_table.data = get_uts(table, write);
80093diff --git a/kernel/watchdog.c b/kernel/watchdog.c
80094index 75a2ab3..5961da7 100644
80095--- a/kernel/watchdog.c
80096+++ b/kernel/watchdog.c
80097@@ -527,7 +527,7 @@ int proc_dowatchdog(struct ctl_table *table, int write,
80098 }
80099 #endif /* CONFIG_SYSCTL */
80100
80101-static struct smp_hotplug_thread watchdog_threads = {
80102+static struct smp_hotplug_thread watchdog_threads __read_only = {
80103 .store = &softlockup_watchdog,
80104 .thread_should_run = watchdog_should_run,
80105 .thread_fn = watchdog,
80106diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
80107index 67604e5..fe94fb1 100644
80108--- a/lib/Kconfig.debug
80109+++ b/lib/Kconfig.debug
80110@@ -550,7 +550,7 @@ config DEBUG_MUTEXES
80111
80112 config DEBUG_LOCK_ALLOC
80113 bool "Lock debugging: detect incorrect freeing of live locks"
80114- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
80115+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
80116 select DEBUG_SPINLOCK
80117 select DEBUG_MUTEXES
80118 select LOCKDEP
80119@@ -564,7 +564,7 @@ config DEBUG_LOCK_ALLOC
80120
80121 config PROVE_LOCKING
80122 bool "Lock debugging: prove locking correctness"
80123- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
80124+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
80125 select LOCKDEP
80126 select DEBUG_SPINLOCK
80127 select DEBUG_MUTEXES
80128@@ -670,7 +670,7 @@ config LOCKDEP
80129
80130 config LOCK_STAT
80131 bool "Lock usage statistics"
80132- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
80133+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
80134 select LOCKDEP
80135 select DEBUG_SPINLOCK
80136 select DEBUG_MUTEXES
80137@@ -1278,6 +1278,7 @@ config LATENCYTOP
80138 depends on DEBUG_KERNEL
80139 depends on STACKTRACE_SUPPORT
80140 depends on PROC_FS
80141+ depends on !GRKERNSEC_HIDESYM
80142 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
80143 select KALLSYMS
80144 select KALLSYMS_ALL
80145@@ -1306,7 +1307,7 @@ config INTERVAL_TREE_TEST
80146
80147 config PROVIDE_OHCI1394_DMA_INIT
80148 bool "Remote debugging over FireWire early on boot"
80149- depends on PCI && X86
80150+ depends on PCI && X86 && !GRKERNSEC
80151 help
80152 If you want to debug problems which hang or crash the kernel early
80153 on boot and the crashing machine has a FireWire port, you can use
80154@@ -1335,7 +1336,7 @@ config PROVIDE_OHCI1394_DMA_INIT
80155
80156 config FIREWIRE_OHCI_REMOTE_DMA
80157 bool "Remote debugging over FireWire with firewire-ohci"
80158- depends on FIREWIRE_OHCI
80159+ depends on FIREWIRE_OHCI && !GRKERNSEC
80160 help
80161 This option lets you use the FireWire bus for remote debugging
80162 with help of the firewire-ohci driver. It enables unfiltered
80163diff --git a/lib/Makefile b/lib/Makefile
80164index 02ed6c0..bd243da 100644
80165--- a/lib/Makefile
80166+++ b/lib/Makefile
80167@@ -47,7 +47,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
80168
80169 obj-$(CONFIG_BTREE) += btree.o
80170 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
80171-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
80172+obj-y += list_debug.o
80173 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
80174
80175 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
80176diff --git a/lib/bitmap.c b/lib/bitmap.c
80177index 06f7e4f..f3cf2b0 100644
80178--- a/lib/bitmap.c
80179+++ b/lib/bitmap.c
80180@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
80181 {
80182 int c, old_c, totaldigits, ndigits, nchunks, nbits;
80183 u32 chunk;
80184- const char __user __force *ubuf = (const char __user __force *)buf;
80185+ const char __user *ubuf = (const char __force_user *)buf;
80186
80187 bitmap_zero(maskp, nmaskbits);
80188
80189@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
80190 {
80191 if (!access_ok(VERIFY_READ, ubuf, ulen))
80192 return -EFAULT;
80193- return __bitmap_parse((const char __force *)ubuf,
80194+ return __bitmap_parse((const char __force_kernel *)ubuf,
80195 ulen, 1, maskp, nmaskbits);
80196
80197 }
80198@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
80199 {
80200 unsigned a, b;
80201 int c, old_c, totaldigits;
80202- const char __user __force *ubuf = (const char __user __force *)buf;
80203+ const char __user *ubuf = (const char __force_user *)buf;
80204 int exp_digit, in_range;
80205
80206 totaldigits = c = 0;
80207@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
80208 {
80209 if (!access_ok(VERIFY_READ, ubuf, ulen))
80210 return -EFAULT;
80211- return __bitmap_parselist((const char __force *)ubuf,
80212+ return __bitmap_parselist((const char __force_kernel *)ubuf,
80213 ulen, 1, maskp, nmaskbits);
80214 }
80215 EXPORT_SYMBOL(bitmap_parselist_user);
80216diff --git a/lib/bug.c b/lib/bug.c
80217index d0cdf14..4d07bd2 100644
80218--- a/lib/bug.c
80219+++ b/lib/bug.c
80220@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
80221 return BUG_TRAP_TYPE_NONE;
80222
80223 bug = find_bug(bugaddr);
80224+ if (!bug)
80225+ return BUG_TRAP_TYPE_NONE;
80226
80227 file = NULL;
80228 line = 0;
80229diff --git a/lib/debugobjects.c b/lib/debugobjects.c
80230index d11808c..dc2d6f8 100644
80231--- a/lib/debugobjects.c
80232+++ b/lib/debugobjects.c
80233@@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
80234 if (limit > 4)
80235 return;
80236
80237- is_on_stack = object_is_on_stack(addr);
80238+ is_on_stack = object_starts_on_stack(addr);
80239 if (is_on_stack == onstack)
80240 return;
80241
80242diff --git a/lib/devres.c b/lib/devres.c
80243index 80b9c76..9e32279 100644
80244--- a/lib/devres.c
80245+++ b/lib/devres.c
80246@@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
80247 void devm_iounmap(struct device *dev, void __iomem *addr)
80248 {
80249 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
80250- (void *)addr));
80251+ (void __force *)addr));
80252 iounmap(addr);
80253 }
80254 EXPORT_SYMBOL(devm_iounmap);
80255@@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
80256 {
80257 ioport_unmap(addr);
80258 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
80259- devm_ioport_map_match, (void *)addr));
80260+ devm_ioport_map_match, (void __force *)addr));
80261 }
80262 EXPORT_SYMBOL(devm_ioport_unmap);
80263
80264diff --git a/lib/div64.c b/lib/div64.c
80265index a163b6c..9618fa5 100644
80266--- a/lib/div64.c
80267+++ b/lib/div64.c
80268@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
80269 EXPORT_SYMBOL(__div64_32);
80270
80271 #ifndef div_s64_rem
80272-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
80273+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
80274 {
80275 u64 quotient;
80276
80277@@ -90,7 +90,7 @@ EXPORT_SYMBOL(div_s64_rem);
80278 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
80279 */
80280 #ifndef div64_u64
80281-u64 div64_u64(u64 dividend, u64 divisor)
80282+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
80283 {
80284 u32 high = divisor >> 32;
80285 u64 quot;
80286diff --git a/lib/dma-debug.c b/lib/dma-debug.c
80287index 5e396ac..58d5de1 100644
80288--- a/lib/dma-debug.c
80289+++ b/lib/dma-debug.c
80290@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
80291
80292 void dma_debug_add_bus(struct bus_type *bus)
80293 {
80294- struct notifier_block *nb;
80295+ notifier_block_no_const *nb;
80296
80297 if (global_disable)
80298 return;
80299@@ -942,7 +942,7 @@ out:
80300
80301 static void check_for_stack(struct device *dev, void *addr)
80302 {
80303- if (object_is_on_stack(addr))
80304+ if (object_starts_on_stack(addr))
80305 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
80306 "stack [addr=%p]\n", addr);
80307 }
80308diff --git a/lib/inflate.c b/lib/inflate.c
80309index 013a761..c28f3fc 100644
80310--- a/lib/inflate.c
80311+++ b/lib/inflate.c
80312@@ -269,7 +269,7 @@ static void free(void *where)
80313 malloc_ptr = free_mem_ptr;
80314 }
80315 #else
80316-#define malloc(a) kmalloc(a, GFP_KERNEL)
80317+#define malloc(a) kmalloc((a), GFP_KERNEL)
80318 #define free(a) kfree(a)
80319 #endif
80320
80321diff --git a/lib/ioremap.c b/lib/ioremap.c
80322index 0c9216c..863bd89 100644
80323--- a/lib/ioremap.c
80324+++ b/lib/ioremap.c
80325@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
80326 unsigned long next;
80327
80328 phys_addr -= addr;
80329- pmd = pmd_alloc(&init_mm, pud, addr);
80330+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
80331 if (!pmd)
80332 return -ENOMEM;
80333 do {
80334@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
80335 unsigned long next;
80336
80337 phys_addr -= addr;
80338- pud = pud_alloc(&init_mm, pgd, addr);
80339+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
80340 if (!pud)
80341 return -ENOMEM;
80342 do {
80343diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
80344index bd2bea9..6b3c95e 100644
80345--- a/lib/is_single_threaded.c
80346+++ b/lib/is_single_threaded.c
80347@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
80348 struct task_struct *p, *t;
80349 bool ret;
80350
80351+ if (!mm)
80352+ return true;
80353+
80354 if (atomic_read(&task->signal->live) != 1)
80355 return false;
80356
80357diff --git a/lib/kobject.c b/lib/kobject.c
80358index a654866..a4fd13d 100644
80359--- a/lib/kobject.c
80360+++ b/lib/kobject.c
80361@@ -859,9 +859,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
80362
80363
80364 static DEFINE_SPINLOCK(kobj_ns_type_lock);
80365-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
80366+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
80367
80368-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
80369+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
80370 {
80371 enum kobj_ns_type type = ops->type;
80372 int error;
80373diff --git a/lib/list_debug.c b/lib/list_debug.c
80374index c24c2f7..06e070b 100644
80375--- a/lib/list_debug.c
80376+++ b/lib/list_debug.c
80377@@ -11,7 +11,9 @@
80378 #include <linux/bug.h>
80379 #include <linux/kernel.h>
80380 #include <linux/rculist.h>
80381+#include <linux/mm.h>
80382
80383+#ifdef CONFIG_DEBUG_LIST
80384 /*
80385 * Insert a new entry between two known consecutive entries.
80386 *
80387@@ -19,21 +21,32 @@
80388 * the prev/next entries already!
80389 */
80390
80391-void __list_add(struct list_head *new,
80392- struct list_head *prev,
80393- struct list_head *next)
80394+static bool __list_add_debug(struct list_head *new,
80395+ struct list_head *prev,
80396+ struct list_head *next)
80397 {
80398- WARN(next->prev != prev,
80399+ if (WARN(next->prev != prev,
80400 "list_add corruption. next->prev should be "
80401 "prev (%p), but was %p. (next=%p).\n",
80402- prev, next->prev, next);
80403- WARN(prev->next != next,
80404+ prev, next->prev, next) ||
80405+ WARN(prev->next != next,
80406 "list_add corruption. prev->next should be "
80407 "next (%p), but was %p. (prev=%p).\n",
80408- next, prev->next, prev);
80409- WARN(new == prev || new == next,
80410- "list_add double add: new=%p, prev=%p, next=%p.\n",
80411- new, prev, next);
80412+ next, prev->next, prev) ||
80413+ WARN(new == prev || new == next,
80414+ "list_add double add: new=%p, prev=%p, next=%p.\n",
80415+ new, prev, next))
80416+ return false;
80417+ return true;
80418+}
80419+
80420+void __list_add(struct list_head *new,
80421+ struct list_head *prev,
80422+ struct list_head *next)
80423+{
80424+ if (!__list_add_debug(new, prev, next))
80425+ return;
80426+
80427 next->prev = new;
80428 new->next = next;
80429 new->prev = prev;
80430@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
80431 }
80432 EXPORT_SYMBOL(__list_add);
80433
80434-void __list_del_entry(struct list_head *entry)
80435+static bool __list_del_entry_debug(struct list_head *entry)
80436 {
80437 struct list_head *prev, *next;
80438
80439@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
80440 WARN(next->prev != entry,
80441 "list_del corruption. next->prev should be %p, "
80442 "but was %p\n", entry, next->prev))
80443+ return false;
80444+ return true;
80445+}
80446+
80447+void __list_del_entry(struct list_head *entry)
80448+{
80449+ if (!__list_del_entry_debug(entry))
80450 return;
80451
80452- __list_del(prev, next);
80453+ __list_del(entry->prev, entry->next);
80454 }
80455 EXPORT_SYMBOL(__list_del_entry);
80456
80457@@ -86,15 +106,85 @@ EXPORT_SYMBOL(list_del);
80458 void __list_add_rcu(struct list_head *new,
80459 struct list_head *prev, struct list_head *next)
80460 {
80461- WARN(next->prev != prev,
80462- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
80463- prev, next->prev, next);
80464- WARN(prev->next != next,
80465- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
80466- next, prev->next, prev);
80467+ if (!__list_add_debug(new, prev, next))
80468+ return;
80469+
80470 new->next = next;
80471 new->prev = prev;
80472 rcu_assign_pointer(list_next_rcu(prev), new);
80473 next->prev = new;
80474 }
80475 EXPORT_SYMBOL(__list_add_rcu);
80476+#endif
80477+
80478+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
80479+{
80480+#ifdef CONFIG_DEBUG_LIST
80481+ if (!__list_add_debug(new, prev, next))
80482+ return;
80483+#endif
80484+
80485+ pax_open_kernel();
80486+ next->prev = new;
80487+ new->next = next;
80488+ new->prev = prev;
80489+ prev->next = new;
80490+ pax_close_kernel();
80491+}
80492+EXPORT_SYMBOL(__pax_list_add);
80493+
80494+void pax_list_del(struct list_head *entry)
80495+{
80496+#ifdef CONFIG_DEBUG_LIST
80497+ if (!__list_del_entry_debug(entry))
80498+ return;
80499+#endif
80500+
80501+ pax_open_kernel();
80502+ __list_del(entry->prev, entry->next);
80503+ entry->next = LIST_POISON1;
80504+ entry->prev = LIST_POISON2;
80505+ pax_close_kernel();
80506+}
80507+EXPORT_SYMBOL(pax_list_del);
80508+
80509+void pax_list_del_init(struct list_head *entry)
80510+{
80511+ pax_open_kernel();
80512+ __list_del(entry->prev, entry->next);
80513+ INIT_LIST_HEAD(entry);
80514+ pax_close_kernel();
80515+}
80516+EXPORT_SYMBOL(pax_list_del_init);
80517+
80518+void __pax_list_add_rcu(struct list_head *new,
80519+ struct list_head *prev, struct list_head *next)
80520+{
80521+#ifdef CONFIG_DEBUG_LIST
80522+ if (!__list_add_debug(new, prev, next))
80523+ return;
80524+#endif
80525+
80526+ pax_open_kernel();
80527+ new->next = next;
80528+ new->prev = prev;
80529+ rcu_assign_pointer(list_next_rcu(prev), new);
80530+ next->prev = new;
80531+ pax_close_kernel();
80532+}
80533+EXPORT_SYMBOL(__pax_list_add_rcu);
80534+
80535+void pax_list_del_rcu(struct list_head *entry)
80536+{
80537+#ifdef CONFIG_DEBUG_LIST
80538+ if (!__list_del_entry_debug(entry))
80539+ return;
80540+#endif
80541+
80542+ pax_open_kernel();
80543+ __list_del(entry->prev, entry->next);
80544+ entry->next = LIST_POISON1;
80545+ entry->prev = LIST_POISON2;
80546+ pax_close_kernel();
80547+}
80548+EXPORT_SYMBOL(pax_list_del_rcu);
80549diff --git a/lib/radix-tree.c b/lib/radix-tree.c
80550index e796429..6e38f9f 100644
80551--- a/lib/radix-tree.c
80552+++ b/lib/radix-tree.c
80553@@ -92,7 +92,7 @@ struct radix_tree_preload {
80554 int nr;
80555 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
80556 };
80557-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
80558+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
80559
80560 static inline void *ptr_to_indirect(void *ptr)
80561 {
80562diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
80563index bb2b201..46abaf9 100644
80564--- a/lib/strncpy_from_user.c
80565+++ b/lib/strncpy_from_user.c
80566@@ -21,7 +21,7 @@
80567 */
80568 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
80569 {
80570- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80571+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80572 long res = 0;
80573
80574 /*
80575diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
80576index a28df52..3d55877 100644
80577--- a/lib/strnlen_user.c
80578+++ b/lib/strnlen_user.c
80579@@ -26,7 +26,7 @@
80580 */
80581 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
80582 {
80583- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80584+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80585 long align, res = 0;
80586 unsigned long c;
80587
80588diff --git a/lib/swiotlb.c b/lib/swiotlb.c
80589index 196b069..358f342 100644
80590--- a/lib/swiotlb.c
80591+++ b/lib/swiotlb.c
80592@@ -642,7 +642,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
80593
80594 void
80595 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
80596- dma_addr_t dev_addr)
80597+ dma_addr_t dev_addr, struct dma_attrs *attrs)
80598 {
80599 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
80600
80601diff --git a/lib/vsprintf.c b/lib/vsprintf.c
80602index fab33a9..3b5fe68 100644
80603--- a/lib/vsprintf.c
80604+++ b/lib/vsprintf.c
80605@@ -16,6 +16,9 @@
80606 * - scnprintf and vscnprintf
80607 */
80608
80609+#ifdef CONFIG_GRKERNSEC_HIDESYM
80610+#define __INCLUDED_BY_HIDESYM 1
80611+#endif
80612 #include <stdarg.h>
80613 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
80614 #include <linux/types.h>
80615@@ -541,7 +544,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
80616 char sym[KSYM_SYMBOL_LEN];
80617 if (ext == 'B')
80618 sprint_backtrace(sym, value);
80619- else if (ext != 'f' && ext != 's')
80620+ else if (ext != 'f' && ext != 's' && ext != 'a')
80621 sprint_symbol(sym, value);
80622 else
80623 sprint_symbol_no_offset(sym, value);
80624@@ -974,7 +977,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
80625 return number(buf, end, *(const netdev_features_t *)addr, spec);
80626 }
80627
80628+#ifdef CONFIG_GRKERNSEC_HIDESYM
80629+int kptr_restrict __read_mostly = 2;
80630+#else
80631 int kptr_restrict __read_mostly;
80632+#endif
80633
80634 /*
80635 * Show a '%p' thing. A kernel extension is that the '%p' is followed
80636@@ -988,6 +995,8 @@ int kptr_restrict __read_mostly;
80637 * - 'S' For symbolic direct pointers with offset
80638 * - 's' For symbolic direct pointers without offset
80639 * - 'B' For backtraced symbolic direct pointers with offset
80640+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
80641+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
80642 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
80643 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
80644 * - 'M' For a 6-byte MAC address, it prints the address in the
80645@@ -1043,12 +1052,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
80646
80647 if (!ptr && *fmt != 'K') {
80648 /*
80649- * Print (null) with the same width as a pointer so it makes
80650+ * Print (nil) with the same width as a pointer so it makes
80651 * tabular output look nice.
80652 */
80653 if (spec.field_width == -1)
80654 spec.field_width = default_width;
80655- return string(buf, end, "(null)", spec);
80656+ return string(buf, end, "(nil)", spec);
80657 }
80658
80659 switch (*fmt) {
80660@@ -1058,6 +1067,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
80661 /* Fallthrough */
80662 case 'S':
80663 case 's':
80664+#ifdef CONFIG_GRKERNSEC_HIDESYM
80665+ break;
80666+#else
80667+ return symbol_string(buf, end, ptr, spec, *fmt);
80668+#endif
80669+ case 'A':
80670+ case 'a':
80671 case 'B':
80672 return symbol_string(buf, end, ptr, spec, *fmt);
80673 case 'R':
80674@@ -1098,6 +1114,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
80675 va_end(va);
80676 return buf;
80677 }
80678+ case 'P':
80679+ break;
80680 case 'K':
80681 /*
80682 * %pK cannot be used in IRQ context because its test
80683@@ -1121,6 +1139,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
80684 }
80685 break;
80686 }
80687+
80688+#ifdef CONFIG_GRKERNSEC_HIDESYM
80689+ /* 'P' = approved pointers to copy to userland,
80690+ as in the /proc/kallsyms case, as we make it display nothing
80691+ for non-root users, and the real contents for root users
80692+ Also ignore 'K' pointers, since we force their NULLing for non-root users
80693+ above
80694+ */
80695+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
80696+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
80697+ dump_stack();
80698+ ptr = NULL;
80699+ }
80700+#endif
80701+
80702 spec.flags |= SMALL;
80703 if (spec.field_width == -1) {
80704 spec.field_width = default_width;
80705@@ -1842,11 +1875,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
80706 typeof(type) value; \
80707 if (sizeof(type) == 8) { \
80708 args = PTR_ALIGN(args, sizeof(u32)); \
80709- *(u32 *)&value = *(u32 *)args; \
80710- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
80711+ *(u32 *)&value = *(const u32 *)args; \
80712+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
80713 } else { \
80714 args = PTR_ALIGN(args, sizeof(type)); \
80715- value = *(typeof(type) *)args; \
80716+ value = *(const typeof(type) *)args; \
80717 } \
80718 args += sizeof(type); \
80719 value; \
80720@@ -1909,7 +1942,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
80721 case FORMAT_TYPE_STR: {
80722 const char *str_arg = args;
80723 args += strlen(str_arg) + 1;
80724- str = string(str, end, (char *)str_arg, spec);
80725+ str = string(str, end, str_arg, spec);
80726 break;
80727 }
80728
80729diff --git a/localversion-grsec b/localversion-grsec
80730new file mode 100644
80731index 0000000..7cd6065
80732--- /dev/null
80733+++ b/localversion-grsec
80734@@ -0,0 +1 @@
80735+-grsec
80736diff --git a/mm/Kconfig b/mm/Kconfig
80737index 278e3ab..87c384d 100644
80738--- a/mm/Kconfig
80739+++ b/mm/Kconfig
80740@@ -286,10 +286,10 @@ config KSM
80741 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
80742
80743 config DEFAULT_MMAP_MIN_ADDR
80744- int "Low address space to protect from user allocation"
80745+ int "Low address space to protect from user allocation"
80746 depends on MMU
80747- default 4096
80748- help
80749+ default 65536
80750+ help
80751 This is the portion of low virtual memory which should be protected
80752 from userspace allocation. Keeping a user from writing to low pages
80753 can help reduce the impact of kernel NULL pointer bugs.
80754@@ -320,7 +320,7 @@ config MEMORY_FAILURE
80755
80756 config HWPOISON_INJECT
80757 tristate "HWPoison pages injector"
80758- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
80759+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
80760 select PROC_PAGE_MONITOR
80761
80762 config NOMMU_INITIAL_TRIM_EXCESS
80763diff --git a/mm/filemap.c b/mm/filemap.c
80764index 83efee7..3f99381 100644
80765--- a/mm/filemap.c
80766+++ b/mm/filemap.c
80767@@ -1747,7 +1747,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
80768 struct address_space *mapping = file->f_mapping;
80769
80770 if (!mapping->a_ops->readpage)
80771- return -ENOEXEC;
80772+ return -ENODEV;
80773 file_accessed(file);
80774 vma->vm_ops = &generic_file_vm_ops;
80775 return 0;
80776@@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
80777 *pos = i_size_read(inode);
80778
80779 if (limit != RLIM_INFINITY) {
80780+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
80781 if (*pos >= limit) {
80782 send_sig(SIGXFSZ, current, 0);
80783 return -EFBIG;
80784diff --git a/mm/fremap.c b/mm/fremap.c
80785index a0aaf0e..20325c3 100644
80786--- a/mm/fremap.c
80787+++ b/mm/fremap.c
80788@@ -157,6 +157,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
80789 retry:
80790 vma = find_vma(mm, start);
80791
80792+#ifdef CONFIG_PAX_SEGMEXEC
80793+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
80794+ goto out;
80795+#endif
80796+
80797 /*
80798 * Make sure the vma is shared, that it supports prefaulting,
80799 * and that the remapped range is valid and fully within
80800diff --git a/mm/highmem.c b/mm/highmem.c
80801index b32b70c..e512eb0 100644
80802--- a/mm/highmem.c
80803+++ b/mm/highmem.c
80804@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
80805 * So no dangers, even with speculative execution.
80806 */
80807 page = pte_page(pkmap_page_table[i]);
80808+ pax_open_kernel();
80809 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
80810-
80811+ pax_close_kernel();
80812 set_page_address(page, NULL);
80813 need_flush = 1;
80814 }
80815@@ -198,9 +199,11 @@ start:
80816 }
80817 }
80818 vaddr = PKMAP_ADDR(last_pkmap_nr);
80819+
80820+ pax_open_kernel();
80821 set_pte_at(&init_mm, vaddr,
80822 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
80823-
80824+ pax_close_kernel();
80825 pkmap_count[last_pkmap_nr] = 1;
80826 set_page_address(page, (void *)vaddr);
80827
80828diff --git a/mm/hugetlb.c b/mm/hugetlb.c
80829index d7cec92..b05cc33 100644
80830--- a/mm/hugetlb.c
80831+++ b/mm/hugetlb.c
80832@@ -2008,15 +2008,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
80833 struct hstate *h = &default_hstate;
80834 unsigned long tmp;
80835 int ret;
80836+ ctl_table_no_const hugetlb_table;
80837
80838 tmp = h->max_huge_pages;
80839
80840 if (write && h->order >= MAX_ORDER)
80841 return -EINVAL;
80842
80843- table->data = &tmp;
80844- table->maxlen = sizeof(unsigned long);
80845- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
80846+ hugetlb_table = *table;
80847+ hugetlb_table.data = &tmp;
80848+ hugetlb_table.maxlen = sizeof(unsigned long);
80849+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
80850 if (ret)
80851 goto out;
80852
80853@@ -2073,15 +2075,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
80854 struct hstate *h = &default_hstate;
80855 unsigned long tmp;
80856 int ret;
80857+ ctl_table_no_const hugetlb_table;
80858
80859 tmp = h->nr_overcommit_huge_pages;
80860
80861 if (write && h->order >= MAX_ORDER)
80862 return -EINVAL;
80863
80864- table->data = &tmp;
80865- table->maxlen = sizeof(unsigned long);
80866- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
80867+ hugetlb_table = *table;
80868+ hugetlb_table.data = &tmp;
80869+ hugetlb_table.maxlen = sizeof(unsigned long);
80870+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
80871 if (ret)
80872 goto out;
80873
80874@@ -2515,6 +2519,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
80875 return 1;
80876 }
80877
80878+#ifdef CONFIG_PAX_SEGMEXEC
80879+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
80880+{
80881+ struct mm_struct *mm = vma->vm_mm;
80882+ struct vm_area_struct *vma_m;
80883+ unsigned long address_m;
80884+ pte_t *ptep_m;
80885+
80886+ vma_m = pax_find_mirror_vma(vma);
80887+ if (!vma_m)
80888+ return;
80889+
80890+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
80891+ address_m = address + SEGMEXEC_TASK_SIZE;
80892+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
80893+ get_page(page_m);
80894+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
80895+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
80896+}
80897+#endif
80898+
80899 /*
80900 * Hugetlb_cow() should be called with page lock of the original hugepage held.
80901 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
80902@@ -2633,6 +2658,11 @@ retry_avoidcopy:
80903 make_huge_pte(vma, new_page, 1));
80904 page_remove_rmap(old_page);
80905 hugepage_add_new_anon_rmap(new_page, vma, address);
80906+
80907+#ifdef CONFIG_PAX_SEGMEXEC
80908+ pax_mirror_huge_pte(vma, address, new_page);
80909+#endif
80910+
80911 /* Make the old page be freed below */
80912 new_page = old_page;
80913 }
80914@@ -2792,6 +2822,10 @@ retry:
80915 && (vma->vm_flags & VM_SHARED)));
80916 set_huge_pte_at(mm, address, ptep, new_pte);
80917
80918+#ifdef CONFIG_PAX_SEGMEXEC
80919+ pax_mirror_huge_pte(vma, address, page);
80920+#endif
80921+
80922 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
80923 /* Optimization, do the COW without a second fault */
80924 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
80925@@ -2821,6 +2855,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
80926 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
80927 struct hstate *h = hstate_vma(vma);
80928
80929+#ifdef CONFIG_PAX_SEGMEXEC
80930+ struct vm_area_struct *vma_m;
80931+#endif
80932+
80933 address &= huge_page_mask(h);
80934
80935 ptep = huge_pte_offset(mm, address);
80936@@ -2834,6 +2872,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
80937 VM_FAULT_SET_HINDEX(hstate_index(h));
80938 }
80939
80940+#ifdef CONFIG_PAX_SEGMEXEC
80941+ vma_m = pax_find_mirror_vma(vma);
80942+ if (vma_m) {
80943+ unsigned long address_m;
80944+
80945+ if (vma->vm_start > vma_m->vm_start) {
80946+ address_m = address;
80947+ address -= SEGMEXEC_TASK_SIZE;
80948+ vma = vma_m;
80949+ h = hstate_vma(vma);
80950+ } else
80951+ address_m = address + SEGMEXEC_TASK_SIZE;
80952+
80953+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
80954+ return VM_FAULT_OOM;
80955+ address_m &= HPAGE_MASK;
80956+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
80957+ }
80958+#endif
80959+
80960 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
80961 if (!ptep)
80962 return VM_FAULT_OOM;
80963diff --git a/mm/internal.h b/mm/internal.h
80964index 9ba2110..eaf0674 100644
80965--- a/mm/internal.h
80966+++ b/mm/internal.h
80967@@ -100,6 +100,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
80968 * in mm/page_alloc.c
80969 */
80970 extern void __free_pages_bootmem(struct page *page, unsigned int order);
80971+extern void free_compound_page(struct page *page);
80972 extern void prep_compound_page(struct page *page, unsigned long order);
80973 #ifdef CONFIG_MEMORY_FAILURE
80974 extern bool is_free_buddy_page(struct page *page);
80975diff --git a/mm/kmemleak.c b/mm/kmemleak.c
80976index 752a705..6c3102e 100644
80977--- a/mm/kmemleak.c
80978+++ b/mm/kmemleak.c
80979@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
80980
80981 for (i = 0; i < object->trace_len; i++) {
80982 void *ptr = (void *)object->trace[i];
80983- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
80984+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
80985 }
80986 }
80987
80988@@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
80989 return -ENOMEM;
80990 }
80991
80992- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
80993+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
80994 &kmemleak_fops);
80995 if (!dentry)
80996 pr_warning("Failed to create the debugfs kmemleak file\n");
80997diff --git a/mm/maccess.c b/mm/maccess.c
80998index d53adf9..03a24bf 100644
80999--- a/mm/maccess.c
81000+++ b/mm/maccess.c
81001@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
81002 set_fs(KERNEL_DS);
81003 pagefault_disable();
81004 ret = __copy_from_user_inatomic(dst,
81005- (__force const void __user *)src, size);
81006+ (const void __force_user *)src, size);
81007 pagefault_enable();
81008 set_fs(old_fs);
81009
81010@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
81011
81012 set_fs(KERNEL_DS);
81013 pagefault_disable();
81014- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
81015+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
81016 pagefault_enable();
81017 set_fs(old_fs);
81018
81019diff --git a/mm/madvise.c b/mm/madvise.c
81020index 03dfa5c..b032917 100644
81021--- a/mm/madvise.c
81022+++ b/mm/madvise.c
81023@@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
81024 pgoff_t pgoff;
81025 unsigned long new_flags = vma->vm_flags;
81026
81027+#ifdef CONFIG_PAX_SEGMEXEC
81028+ struct vm_area_struct *vma_m;
81029+#endif
81030+
81031 switch (behavior) {
81032 case MADV_NORMAL:
81033 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
81034@@ -123,6 +127,13 @@ success:
81035 /*
81036 * vm_flags is protected by the mmap_sem held in write mode.
81037 */
81038+
81039+#ifdef CONFIG_PAX_SEGMEXEC
81040+ vma_m = pax_find_mirror_vma(vma);
81041+ if (vma_m)
81042+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
81043+#endif
81044+
81045 vma->vm_flags = new_flags;
81046
81047 out:
81048@@ -181,6 +192,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
81049 struct vm_area_struct ** prev,
81050 unsigned long start, unsigned long end)
81051 {
81052+
81053+#ifdef CONFIG_PAX_SEGMEXEC
81054+ struct vm_area_struct *vma_m;
81055+#endif
81056+
81057 *prev = vma;
81058 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
81059 return -EINVAL;
81060@@ -193,6 +209,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
81061 zap_page_range(vma, start, end - start, &details);
81062 } else
81063 zap_page_range(vma, start, end - start, NULL);
81064+
81065+#ifdef CONFIG_PAX_SEGMEXEC
81066+ vma_m = pax_find_mirror_vma(vma);
81067+ if (vma_m) {
81068+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
81069+ struct zap_details details = {
81070+ .nonlinear_vma = vma_m,
81071+ .last_index = ULONG_MAX,
81072+ };
81073+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
81074+ } else
81075+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
81076+ }
81077+#endif
81078+
81079 return 0;
81080 }
81081
81082@@ -397,6 +428,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
81083 if (end < start)
81084 goto out;
81085
81086+#ifdef CONFIG_PAX_SEGMEXEC
81087+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
81088+ if (end > SEGMEXEC_TASK_SIZE)
81089+ goto out;
81090+ } else
81091+#endif
81092+
81093+ if (end > TASK_SIZE)
81094+ goto out;
81095+
81096 error = 0;
81097 if (end == start)
81098 goto out;
81099diff --git a/mm/memory-failure.c b/mm/memory-failure.c
81100index c6e4dd3..1f41988 100644
81101--- a/mm/memory-failure.c
81102+++ b/mm/memory-failure.c
81103@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
81104
81105 int sysctl_memory_failure_recovery __read_mostly = 1;
81106
81107-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
81108+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
81109
81110 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
81111
81112@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
81113 pfn, t->comm, t->pid);
81114 si.si_signo = SIGBUS;
81115 si.si_errno = 0;
81116- si.si_addr = (void *)addr;
81117+ si.si_addr = (void __user *)addr;
81118 #ifdef __ARCH_SI_TRAPNO
81119 si.si_trapno = trapno;
81120 #endif
81121@@ -760,7 +760,7 @@ static struct page_state {
81122 unsigned long res;
81123 char *msg;
81124 int (*action)(struct page *p, unsigned long pfn);
81125-} error_states[] = {
81126+} __do_const error_states[] = {
81127 { reserved, reserved, "reserved kernel", me_kernel },
81128 /*
81129 * free pages are specially detected outside this table:
81130@@ -1040,7 +1040,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
81131 }
81132
81133 nr_pages = 1 << compound_trans_order(hpage);
81134- atomic_long_add(nr_pages, &mce_bad_pages);
81135+ atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
81136
81137 /*
81138 * We need/can do nothing about count=0 pages.
81139@@ -1070,7 +1070,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
81140 if (!PageHWPoison(hpage)
81141 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
81142 || (p != hpage && TestSetPageHWPoison(hpage))) {
81143- atomic_long_sub(nr_pages, &mce_bad_pages);
81144+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
81145 return 0;
81146 }
81147 set_page_hwpoison_huge_page(hpage);
81148@@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
81149 }
81150 if (hwpoison_filter(p)) {
81151 if (TestClearPageHWPoison(p))
81152- atomic_long_sub(nr_pages, &mce_bad_pages);
81153+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
81154 unlock_page(hpage);
81155 put_page(hpage);
81156 return 0;
81157@@ -1323,7 +1323,7 @@ int unpoison_memory(unsigned long pfn)
81158 return 0;
81159 }
81160 if (TestClearPageHWPoison(p))
81161- atomic_long_sub(nr_pages, &mce_bad_pages);
81162+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
81163 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
81164 return 0;
81165 }
81166@@ -1337,7 +1337,7 @@ int unpoison_memory(unsigned long pfn)
81167 */
81168 if (TestClearPageHWPoison(page)) {
81169 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
81170- atomic_long_sub(nr_pages, &mce_bad_pages);
81171+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
81172 freeit = 1;
81173 if (PageHuge(page))
81174 clear_page_hwpoison_huge_page(page);
81175@@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
81176 }
81177 done:
81178 if (!PageHWPoison(hpage))
81179- atomic_long_add(1 << compound_trans_order(hpage),
81180+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
81181 &mce_bad_pages);
81182 set_page_hwpoison_huge_page(hpage);
81183 dequeue_hwpoisoned_huge_page(hpage);
81184@@ -1583,7 +1583,7 @@ int soft_offline_page(struct page *page, int flags)
81185 return ret;
81186
81187 done:
81188- atomic_long_add(1, &mce_bad_pages);
81189+ atomic_long_add_unchecked(1, &mce_bad_pages);
81190 SetPageHWPoison(page);
81191 /* keep elevated page count for bad page */
81192 return ret;
81193diff --git a/mm/memory.c b/mm/memory.c
81194index f8b734a..38014f5 100644
81195--- a/mm/memory.c
81196+++ b/mm/memory.c
81197@@ -434,6 +434,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
81198 free_pte_range(tlb, pmd, addr);
81199 } while (pmd++, addr = next, addr != end);
81200
81201+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
81202 start &= PUD_MASK;
81203 if (start < floor)
81204 return;
81205@@ -448,6 +449,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
81206 pmd = pmd_offset(pud, start);
81207 pud_clear(pud);
81208 pmd_free_tlb(tlb, pmd, start);
81209+#endif
81210+
81211 }
81212
81213 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
81214@@ -467,6 +470,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
81215 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
81216 } while (pud++, addr = next, addr != end);
81217
81218+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
81219 start &= PGDIR_MASK;
81220 if (start < floor)
81221 return;
81222@@ -481,6 +485,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
81223 pud = pud_offset(pgd, start);
81224 pgd_clear(pgd);
81225 pud_free_tlb(tlb, pud, start);
81226+#endif
81227+
81228 }
81229
81230 /*
81231@@ -1619,12 +1625,6 @@ no_page_table:
81232 return page;
81233 }
81234
81235-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
81236-{
81237- return stack_guard_page_start(vma, addr) ||
81238- stack_guard_page_end(vma, addr+PAGE_SIZE);
81239-}
81240-
81241 /**
81242 * __get_user_pages() - pin user pages in memory
81243 * @tsk: task_struct of target task
81244@@ -1710,10 +1710,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
81245
81246 i = 0;
81247
81248- do {
81249+ while (nr_pages) {
81250 struct vm_area_struct *vma;
81251
81252- vma = find_extend_vma(mm, start);
81253+ vma = find_vma(mm, start);
81254 if (!vma && in_gate_area(mm, start)) {
81255 unsigned long pg = start & PAGE_MASK;
81256 pgd_t *pgd;
81257@@ -1761,7 +1761,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
81258 goto next_page;
81259 }
81260
81261- if (!vma ||
81262+ if (!vma || start < vma->vm_start ||
81263 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
81264 !(vm_flags & vma->vm_flags))
81265 return i ? : -EFAULT;
81266@@ -1788,11 +1788,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
81267 int ret;
81268 unsigned int fault_flags = 0;
81269
81270- /* For mlock, just skip the stack guard page. */
81271- if (foll_flags & FOLL_MLOCK) {
81272- if (stack_guard_page(vma, start))
81273- goto next_page;
81274- }
81275 if (foll_flags & FOLL_WRITE)
81276 fault_flags |= FAULT_FLAG_WRITE;
81277 if (nonblocking)
81278@@ -1866,7 +1861,7 @@ next_page:
81279 start += PAGE_SIZE;
81280 nr_pages--;
81281 } while (nr_pages && start < vma->vm_end);
81282- } while (nr_pages);
81283+ }
81284 return i;
81285 }
81286 EXPORT_SYMBOL(__get_user_pages);
81287@@ -2073,6 +2068,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
81288 page_add_file_rmap(page);
81289 set_pte_at(mm, addr, pte, mk_pte(page, prot));
81290
81291+#ifdef CONFIG_PAX_SEGMEXEC
81292+ pax_mirror_file_pte(vma, addr, page, ptl);
81293+#endif
81294+
81295 retval = 0;
81296 pte_unmap_unlock(pte, ptl);
81297 return retval;
81298@@ -2117,9 +2116,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
81299 if (!page_count(page))
81300 return -EINVAL;
81301 if (!(vma->vm_flags & VM_MIXEDMAP)) {
81302+
81303+#ifdef CONFIG_PAX_SEGMEXEC
81304+ struct vm_area_struct *vma_m;
81305+#endif
81306+
81307 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
81308 BUG_ON(vma->vm_flags & VM_PFNMAP);
81309 vma->vm_flags |= VM_MIXEDMAP;
81310+
81311+#ifdef CONFIG_PAX_SEGMEXEC
81312+ vma_m = pax_find_mirror_vma(vma);
81313+ if (vma_m)
81314+ vma_m->vm_flags |= VM_MIXEDMAP;
81315+#endif
81316+
81317 }
81318 return insert_page(vma, addr, page, vma->vm_page_prot);
81319 }
81320@@ -2202,6 +2213,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
81321 unsigned long pfn)
81322 {
81323 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
81324+ BUG_ON(vma->vm_mirror);
81325
81326 if (addr < vma->vm_start || addr >= vma->vm_end)
81327 return -EFAULT;
81328@@ -2402,7 +2414,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
81329
81330 BUG_ON(pud_huge(*pud));
81331
81332- pmd = pmd_alloc(mm, pud, addr);
81333+ pmd = (mm == &init_mm) ?
81334+ pmd_alloc_kernel(mm, pud, addr) :
81335+ pmd_alloc(mm, pud, addr);
81336 if (!pmd)
81337 return -ENOMEM;
81338 do {
81339@@ -2422,7 +2436,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
81340 unsigned long next;
81341 int err;
81342
81343- pud = pud_alloc(mm, pgd, addr);
81344+ pud = (mm == &init_mm) ?
81345+ pud_alloc_kernel(mm, pgd, addr) :
81346+ pud_alloc(mm, pgd, addr);
81347 if (!pud)
81348 return -ENOMEM;
81349 do {
81350@@ -2510,6 +2526,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
81351 copy_user_highpage(dst, src, va, vma);
81352 }
81353
81354+#ifdef CONFIG_PAX_SEGMEXEC
81355+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
81356+{
81357+ struct mm_struct *mm = vma->vm_mm;
81358+ spinlock_t *ptl;
81359+ pte_t *pte, entry;
81360+
81361+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
81362+ entry = *pte;
81363+ if (!pte_present(entry)) {
81364+ if (!pte_none(entry)) {
81365+ BUG_ON(pte_file(entry));
81366+ free_swap_and_cache(pte_to_swp_entry(entry));
81367+ pte_clear_not_present_full(mm, address, pte, 0);
81368+ }
81369+ } else {
81370+ struct page *page;
81371+
81372+ flush_cache_page(vma, address, pte_pfn(entry));
81373+ entry = ptep_clear_flush(vma, address, pte);
81374+ BUG_ON(pte_dirty(entry));
81375+ page = vm_normal_page(vma, address, entry);
81376+ if (page) {
81377+ update_hiwater_rss(mm);
81378+ if (PageAnon(page))
81379+ dec_mm_counter_fast(mm, MM_ANONPAGES);
81380+ else
81381+ dec_mm_counter_fast(mm, MM_FILEPAGES);
81382+ page_remove_rmap(page);
81383+ page_cache_release(page);
81384+ }
81385+ }
81386+ pte_unmap_unlock(pte, ptl);
81387+}
81388+
81389+/* PaX: if vma is mirrored, synchronize the mirror's PTE
81390+ *
81391+ * the ptl of the lower mapped page is held on entry and is not released on exit
81392+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
81393+ */
81394+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
81395+{
81396+ struct mm_struct *mm = vma->vm_mm;
81397+ unsigned long address_m;
81398+ spinlock_t *ptl_m;
81399+ struct vm_area_struct *vma_m;
81400+ pmd_t *pmd_m;
81401+ pte_t *pte_m, entry_m;
81402+
81403+ BUG_ON(!page_m || !PageAnon(page_m));
81404+
81405+ vma_m = pax_find_mirror_vma(vma);
81406+ if (!vma_m)
81407+ return;
81408+
81409+ BUG_ON(!PageLocked(page_m));
81410+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
81411+ address_m = address + SEGMEXEC_TASK_SIZE;
81412+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
81413+ pte_m = pte_offset_map(pmd_m, address_m);
81414+ ptl_m = pte_lockptr(mm, pmd_m);
81415+ if (ptl != ptl_m) {
81416+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
81417+ if (!pte_none(*pte_m))
81418+ goto out;
81419+ }
81420+
81421+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
81422+ page_cache_get(page_m);
81423+ page_add_anon_rmap(page_m, vma_m, address_m);
81424+ inc_mm_counter_fast(mm, MM_ANONPAGES);
81425+ set_pte_at(mm, address_m, pte_m, entry_m);
81426+ update_mmu_cache(vma_m, address_m, entry_m);
81427+out:
81428+ if (ptl != ptl_m)
81429+ spin_unlock(ptl_m);
81430+ pte_unmap(pte_m);
81431+ unlock_page(page_m);
81432+}
81433+
81434+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
81435+{
81436+ struct mm_struct *mm = vma->vm_mm;
81437+ unsigned long address_m;
81438+ spinlock_t *ptl_m;
81439+ struct vm_area_struct *vma_m;
81440+ pmd_t *pmd_m;
81441+ pte_t *pte_m, entry_m;
81442+
81443+ BUG_ON(!page_m || PageAnon(page_m));
81444+
81445+ vma_m = pax_find_mirror_vma(vma);
81446+ if (!vma_m)
81447+ return;
81448+
81449+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
81450+ address_m = address + SEGMEXEC_TASK_SIZE;
81451+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
81452+ pte_m = pte_offset_map(pmd_m, address_m);
81453+ ptl_m = pte_lockptr(mm, pmd_m);
81454+ if (ptl != ptl_m) {
81455+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
81456+ if (!pte_none(*pte_m))
81457+ goto out;
81458+ }
81459+
81460+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
81461+ page_cache_get(page_m);
81462+ page_add_file_rmap(page_m);
81463+ inc_mm_counter_fast(mm, MM_FILEPAGES);
81464+ set_pte_at(mm, address_m, pte_m, entry_m);
81465+ update_mmu_cache(vma_m, address_m, entry_m);
81466+out:
81467+ if (ptl != ptl_m)
81468+ spin_unlock(ptl_m);
81469+ pte_unmap(pte_m);
81470+}
81471+
81472+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
81473+{
81474+ struct mm_struct *mm = vma->vm_mm;
81475+ unsigned long address_m;
81476+ spinlock_t *ptl_m;
81477+ struct vm_area_struct *vma_m;
81478+ pmd_t *pmd_m;
81479+ pte_t *pte_m, entry_m;
81480+
81481+ vma_m = pax_find_mirror_vma(vma);
81482+ if (!vma_m)
81483+ return;
81484+
81485+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
81486+ address_m = address + SEGMEXEC_TASK_SIZE;
81487+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
81488+ pte_m = pte_offset_map(pmd_m, address_m);
81489+ ptl_m = pte_lockptr(mm, pmd_m);
81490+ if (ptl != ptl_m) {
81491+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
81492+ if (!pte_none(*pte_m))
81493+ goto out;
81494+ }
81495+
81496+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
81497+ set_pte_at(mm, address_m, pte_m, entry_m);
81498+out:
81499+ if (ptl != ptl_m)
81500+ spin_unlock(ptl_m);
81501+ pte_unmap(pte_m);
81502+}
81503+
81504+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
81505+{
81506+ struct page *page_m;
81507+ pte_t entry;
81508+
81509+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
81510+ goto out;
81511+
81512+ entry = *pte;
81513+ page_m = vm_normal_page(vma, address, entry);
81514+ if (!page_m)
81515+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
81516+ else if (PageAnon(page_m)) {
81517+ if (pax_find_mirror_vma(vma)) {
81518+ pte_unmap_unlock(pte, ptl);
81519+ lock_page(page_m);
81520+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
81521+ if (pte_same(entry, *pte))
81522+ pax_mirror_anon_pte(vma, address, page_m, ptl);
81523+ else
81524+ unlock_page(page_m);
81525+ }
81526+ } else
81527+ pax_mirror_file_pte(vma, address, page_m, ptl);
81528+
81529+out:
81530+ pte_unmap_unlock(pte, ptl);
81531+}
81532+#endif
81533+
81534 /*
81535 * This routine handles present pages, when users try to write
81536 * to a shared page. It is done by copying the page to a new address
81537@@ -2726,6 +2922,12 @@ gotten:
81538 */
81539 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
81540 if (likely(pte_same(*page_table, orig_pte))) {
81541+
81542+#ifdef CONFIG_PAX_SEGMEXEC
81543+ if (pax_find_mirror_vma(vma))
81544+ BUG_ON(!trylock_page(new_page));
81545+#endif
81546+
81547 if (old_page) {
81548 if (!PageAnon(old_page)) {
81549 dec_mm_counter_fast(mm, MM_FILEPAGES);
81550@@ -2777,6 +2979,10 @@ gotten:
81551 page_remove_rmap(old_page);
81552 }
81553
81554+#ifdef CONFIG_PAX_SEGMEXEC
81555+ pax_mirror_anon_pte(vma, address, new_page, ptl);
81556+#endif
81557+
81558 /* Free the old page.. */
81559 new_page = old_page;
81560 ret |= VM_FAULT_WRITE;
81561@@ -3052,6 +3258,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
81562 swap_free(entry);
81563 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
81564 try_to_free_swap(page);
81565+
81566+#ifdef CONFIG_PAX_SEGMEXEC
81567+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
81568+#endif
81569+
81570 unlock_page(page);
81571 if (swapcache) {
81572 /*
81573@@ -3075,6 +3286,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
81574
81575 /* No need to invalidate - it was non-present before */
81576 update_mmu_cache(vma, address, page_table);
81577+
81578+#ifdef CONFIG_PAX_SEGMEXEC
81579+ pax_mirror_anon_pte(vma, address, page, ptl);
81580+#endif
81581+
81582 unlock:
81583 pte_unmap_unlock(page_table, ptl);
81584 out:
81585@@ -3094,40 +3310,6 @@ out_release:
81586 }
81587
81588 /*
81589- * This is like a special single-page "expand_{down|up}wards()",
81590- * except we must first make sure that 'address{-|+}PAGE_SIZE'
81591- * doesn't hit another vma.
81592- */
81593-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
81594-{
81595- address &= PAGE_MASK;
81596- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
81597- struct vm_area_struct *prev = vma->vm_prev;
81598-
81599- /*
81600- * Is there a mapping abutting this one below?
81601- *
81602- * That's only ok if it's the same stack mapping
81603- * that has gotten split..
81604- */
81605- if (prev && prev->vm_end == address)
81606- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
81607-
81608- expand_downwards(vma, address - PAGE_SIZE);
81609- }
81610- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
81611- struct vm_area_struct *next = vma->vm_next;
81612-
81613- /* As VM_GROWSDOWN but s/below/above/ */
81614- if (next && next->vm_start == address + PAGE_SIZE)
81615- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
81616-
81617- expand_upwards(vma, address + PAGE_SIZE);
81618- }
81619- return 0;
81620-}
81621-
81622-/*
81623 * We enter with non-exclusive mmap_sem (to exclude vma changes,
81624 * but allow concurrent faults), and pte mapped but not yet locked.
81625 * We return with mmap_sem still held, but pte unmapped and unlocked.
81626@@ -3136,27 +3318,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
81627 unsigned long address, pte_t *page_table, pmd_t *pmd,
81628 unsigned int flags)
81629 {
81630- struct page *page;
81631+ struct page *page = NULL;
81632 spinlock_t *ptl;
81633 pte_t entry;
81634
81635- pte_unmap(page_table);
81636-
81637- /* Check if we need to add a guard page to the stack */
81638- if (check_stack_guard_page(vma, address) < 0)
81639- return VM_FAULT_SIGBUS;
81640-
81641- /* Use the zero-page for reads */
81642 if (!(flags & FAULT_FLAG_WRITE)) {
81643 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
81644 vma->vm_page_prot));
81645- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
81646+ ptl = pte_lockptr(mm, pmd);
81647+ spin_lock(ptl);
81648 if (!pte_none(*page_table))
81649 goto unlock;
81650 goto setpte;
81651 }
81652
81653 /* Allocate our own private page. */
81654+ pte_unmap(page_table);
81655+
81656 if (unlikely(anon_vma_prepare(vma)))
81657 goto oom;
81658 page = alloc_zeroed_user_highpage_movable(vma, address);
81659@@ -3175,6 +3353,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
81660 if (!pte_none(*page_table))
81661 goto release;
81662
81663+#ifdef CONFIG_PAX_SEGMEXEC
81664+ if (pax_find_mirror_vma(vma))
81665+ BUG_ON(!trylock_page(page));
81666+#endif
81667+
81668 inc_mm_counter_fast(mm, MM_ANONPAGES);
81669 page_add_new_anon_rmap(page, vma, address);
81670 setpte:
81671@@ -3182,6 +3365,12 @@ setpte:
81672
81673 /* No need to invalidate - it was non-present before */
81674 update_mmu_cache(vma, address, page_table);
81675+
81676+#ifdef CONFIG_PAX_SEGMEXEC
81677+ if (page)
81678+ pax_mirror_anon_pte(vma, address, page, ptl);
81679+#endif
81680+
81681 unlock:
81682 pte_unmap_unlock(page_table, ptl);
81683 return 0;
81684@@ -3325,6 +3514,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81685 */
81686 /* Only go through if we didn't race with anybody else... */
81687 if (likely(pte_same(*page_table, orig_pte))) {
81688+
81689+#ifdef CONFIG_PAX_SEGMEXEC
81690+ if (anon && pax_find_mirror_vma(vma))
81691+ BUG_ON(!trylock_page(page));
81692+#endif
81693+
81694 flush_icache_page(vma, page);
81695 entry = mk_pte(page, vma->vm_page_prot);
81696 if (flags & FAULT_FLAG_WRITE)
81697@@ -3344,6 +3539,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81698
81699 /* no need to invalidate: a not-present page won't be cached */
81700 update_mmu_cache(vma, address, page_table);
81701+
81702+#ifdef CONFIG_PAX_SEGMEXEC
81703+ if (anon)
81704+ pax_mirror_anon_pte(vma, address, page, ptl);
81705+ else
81706+ pax_mirror_file_pte(vma, address, page, ptl);
81707+#endif
81708+
81709 } else {
81710 if (cow_page)
81711 mem_cgroup_uncharge_page(cow_page);
81712@@ -3665,6 +3868,12 @@ int handle_pte_fault(struct mm_struct *mm,
81713 if (flags & FAULT_FLAG_WRITE)
81714 flush_tlb_fix_spurious_fault(vma, address);
81715 }
81716+
81717+#ifdef CONFIG_PAX_SEGMEXEC
81718+ pax_mirror_pte(vma, address, pte, pmd, ptl);
81719+ return 0;
81720+#endif
81721+
81722 unlock:
81723 pte_unmap_unlock(pte, ptl);
81724 return 0;
81725@@ -3681,6 +3890,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81726 pmd_t *pmd;
81727 pte_t *pte;
81728
81729+#ifdef CONFIG_PAX_SEGMEXEC
81730+ struct vm_area_struct *vma_m;
81731+#endif
81732+
81733 __set_current_state(TASK_RUNNING);
81734
81735 count_vm_event(PGFAULT);
81736@@ -3692,6 +3905,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81737 if (unlikely(is_vm_hugetlb_page(vma)))
81738 return hugetlb_fault(mm, vma, address, flags);
81739
81740+#ifdef CONFIG_PAX_SEGMEXEC
81741+ vma_m = pax_find_mirror_vma(vma);
81742+ if (vma_m) {
81743+ unsigned long address_m;
81744+ pgd_t *pgd_m;
81745+ pud_t *pud_m;
81746+ pmd_t *pmd_m;
81747+
81748+ if (vma->vm_start > vma_m->vm_start) {
81749+ address_m = address;
81750+ address -= SEGMEXEC_TASK_SIZE;
81751+ vma = vma_m;
81752+ } else
81753+ address_m = address + SEGMEXEC_TASK_SIZE;
81754+
81755+ pgd_m = pgd_offset(mm, address_m);
81756+ pud_m = pud_alloc(mm, pgd_m, address_m);
81757+ if (!pud_m)
81758+ return VM_FAULT_OOM;
81759+ pmd_m = pmd_alloc(mm, pud_m, address_m);
81760+ if (!pmd_m)
81761+ return VM_FAULT_OOM;
81762+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
81763+ return VM_FAULT_OOM;
81764+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
81765+ }
81766+#endif
81767+
81768 retry:
81769 pgd = pgd_offset(mm, address);
81770 pud = pud_alloc(mm, pgd, address);
81771@@ -3790,6 +4031,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
81772 spin_unlock(&mm->page_table_lock);
81773 return 0;
81774 }
81775+
81776+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
81777+{
81778+ pud_t *new = pud_alloc_one(mm, address);
81779+ if (!new)
81780+ return -ENOMEM;
81781+
81782+ smp_wmb(); /* See comment in __pte_alloc */
81783+
81784+ spin_lock(&mm->page_table_lock);
81785+ if (pgd_present(*pgd)) /* Another has populated it */
81786+ pud_free(mm, new);
81787+ else
81788+ pgd_populate_kernel(mm, pgd, new);
81789+ spin_unlock(&mm->page_table_lock);
81790+ return 0;
81791+}
81792 #endif /* __PAGETABLE_PUD_FOLDED */
81793
81794 #ifndef __PAGETABLE_PMD_FOLDED
81795@@ -3820,11 +4078,35 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
81796 spin_unlock(&mm->page_table_lock);
81797 return 0;
81798 }
81799+
81800+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
81801+{
81802+ pmd_t *new = pmd_alloc_one(mm, address);
81803+ if (!new)
81804+ return -ENOMEM;
81805+
81806+ smp_wmb(); /* See comment in __pte_alloc */
81807+
81808+ spin_lock(&mm->page_table_lock);
81809+#ifndef __ARCH_HAS_4LEVEL_HACK
81810+ if (pud_present(*pud)) /* Another has populated it */
81811+ pmd_free(mm, new);
81812+ else
81813+ pud_populate_kernel(mm, pud, new);
81814+#else
81815+ if (pgd_present(*pud)) /* Another has populated it */
81816+ pmd_free(mm, new);
81817+ else
81818+ pgd_populate_kernel(mm, pud, new);
81819+#endif /* __ARCH_HAS_4LEVEL_HACK */
81820+ spin_unlock(&mm->page_table_lock);
81821+ return 0;
81822+}
81823 #endif /* __PAGETABLE_PMD_FOLDED */
81824
81825-int make_pages_present(unsigned long addr, unsigned long end)
81826+ssize_t make_pages_present(unsigned long addr, unsigned long end)
81827 {
81828- int ret, len, write;
81829+ ssize_t ret, len, write;
81830 struct vm_area_struct * vma;
81831
81832 vma = find_vma(current->mm, addr);
81833@@ -3857,7 +4139,7 @@ static int __init gate_vma_init(void)
81834 gate_vma.vm_start = FIXADDR_USER_START;
81835 gate_vma.vm_end = FIXADDR_USER_END;
81836 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
81837- gate_vma.vm_page_prot = __P101;
81838+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
81839
81840 return 0;
81841 }
81842@@ -3991,8 +4273,8 @@ out:
81843 return ret;
81844 }
81845
81846-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
81847- void *buf, int len, int write)
81848+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
81849+ void *buf, size_t len, int write)
81850 {
81851 resource_size_t phys_addr;
81852 unsigned long prot = 0;
81853@@ -4017,8 +4299,8 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
81854 * Access another process' address space as given in mm. If non-NULL, use the
81855 * given task for page fault accounting.
81856 */
81857-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
81858- unsigned long addr, void *buf, int len, int write)
81859+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
81860+ unsigned long addr, void *buf, size_t len, int write)
81861 {
81862 struct vm_area_struct *vma;
81863 void *old_buf = buf;
81864@@ -4026,7 +4308,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
81865 down_read(&mm->mmap_sem);
81866 /* ignore errors, just check how much was successfully transferred */
81867 while (len) {
81868- int bytes, ret, offset;
81869+ ssize_t bytes, ret, offset;
81870 void *maddr;
81871 struct page *page = NULL;
81872
81873@@ -4085,8 +4367,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
81874 *
81875 * The caller must hold a reference on @mm.
81876 */
81877-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
81878- void *buf, int len, int write)
81879+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
81880+ void *buf, size_t len, int write)
81881 {
81882 return __access_remote_vm(NULL, mm, addr, buf, len, write);
81883 }
81884@@ -4096,11 +4378,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
81885 * Source/target buffer must be kernel space,
81886 * Do not walk the page table directly, use get_user_pages
81887 */
81888-int access_process_vm(struct task_struct *tsk, unsigned long addr,
81889- void *buf, int len, int write)
81890+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
81891+ void *buf, size_t len, int write)
81892 {
81893 struct mm_struct *mm;
81894- int ret;
81895+ ssize_t ret;
81896
81897 mm = get_task_mm(tsk);
81898 if (!mm)
81899diff --git a/mm/mempolicy.c b/mm/mempolicy.c
81900index 3df6d12..a11056a 100644
81901--- a/mm/mempolicy.c
81902+++ b/mm/mempolicy.c
81903@@ -721,6 +721,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
81904 unsigned long vmstart;
81905 unsigned long vmend;
81906
81907+#ifdef CONFIG_PAX_SEGMEXEC
81908+ struct vm_area_struct *vma_m;
81909+#endif
81910+
81911 vma = find_vma(mm, start);
81912 if (!vma || vma->vm_start > start)
81913 return -EFAULT;
81914@@ -757,9 +761,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
81915 if (err)
81916 goto out;
81917 }
81918+
81919 err = vma_replace_policy(vma, new_pol);
81920 if (err)
81921 goto out;
81922+
81923+#ifdef CONFIG_PAX_SEGMEXEC
81924+ vma_m = pax_find_mirror_vma(vma);
81925+ if (vma_m) {
81926+ err = vma_replace_policy(vma_m, new_pol);
81927+ if (err)
81928+ goto out;
81929+ }
81930+#endif
81931+
81932 }
81933
81934 out:
81935@@ -1216,6 +1231,17 @@ static long do_mbind(unsigned long start, unsigned long len,
81936
81937 if (end < start)
81938 return -EINVAL;
81939+
81940+#ifdef CONFIG_PAX_SEGMEXEC
81941+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
81942+ if (end > SEGMEXEC_TASK_SIZE)
81943+ return -EINVAL;
81944+ } else
81945+#endif
81946+
81947+ if (end > TASK_SIZE)
81948+ return -EINVAL;
81949+
81950 if (end == start)
81951 return 0;
81952
81953@@ -1445,8 +1471,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
81954 */
81955 tcred = __task_cred(task);
81956 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
81957- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
81958- !capable(CAP_SYS_NICE)) {
81959+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
81960 rcu_read_unlock();
81961 err = -EPERM;
81962 goto out_put;
81963@@ -1477,6 +1502,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
81964 goto out;
81965 }
81966
81967+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
81968+ if (mm != current->mm &&
81969+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
81970+ mmput(mm);
81971+ err = -EPERM;
81972+ goto out;
81973+ }
81974+#endif
81975+
81976 err = do_migrate_pages(mm, old, new,
81977 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
81978
81979diff --git a/mm/migrate.c b/mm/migrate.c
81980index 2fd8b4a..d70358f 100644
81981--- a/mm/migrate.c
81982+++ b/mm/migrate.c
81983@@ -1401,8 +1401,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
81984 */
81985 tcred = __task_cred(task);
81986 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
81987- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
81988- !capable(CAP_SYS_NICE)) {
81989+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
81990 rcu_read_unlock();
81991 err = -EPERM;
81992 goto out;
81993diff --git a/mm/mlock.c b/mm/mlock.c
81994index c9bd528..da8d069 100644
81995--- a/mm/mlock.c
81996+++ b/mm/mlock.c
81997@@ -13,6 +13,7 @@
81998 #include <linux/pagemap.h>
81999 #include <linux/mempolicy.h>
82000 #include <linux/syscalls.h>
82001+#include <linux/security.h>
82002 #include <linux/sched.h>
82003 #include <linux/export.h>
82004 #include <linux/rmap.h>
82005@@ -369,7 +370,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
82006 {
82007 unsigned long nstart, end, tmp;
82008 struct vm_area_struct * vma, * prev;
82009- int error;
82010+ int error = 0;
82011
82012 VM_BUG_ON(start & ~PAGE_MASK);
82013 VM_BUG_ON(len != PAGE_ALIGN(len));
82014@@ -378,6 +379,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
82015 return -EINVAL;
82016 if (end == start)
82017 return 0;
82018+ if (end > TASK_SIZE)
82019+ return -EINVAL;
82020+
82021 vma = find_vma(current->mm, start);
82022 if (!vma || vma->vm_start > start)
82023 return -ENOMEM;
82024@@ -389,6 +393,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
82025 for (nstart = start ; ; ) {
82026 vm_flags_t newflags;
82027
82028+#ifdef CONFIG_PAX_SEGMEXEC
82029+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
82030+ break;
82031+#endif
82032+
82033 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
82034
82035 newflags = vma->vm_flags | VM_LOCKED;
82036@@ -494,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
82037 lock_limit >>= PAGE_SHIFT;
82038
82039 /* check against resource limits */
82040+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
82041 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
82042 error = do_mlock(start, len, 1);
82043 up_write(&current->mm->mmap_sem);
82044@@ -528,6 +538,12 @@ static int do_mlockall(int flags)
82045 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
82046 vm_flags_t newflags;
82047
82048+#ifdef CONFIG_PAX_SEGMEXEC
82049+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
82050+ break;
82051+#endif
82052+
82053+ BUG_ON(vma->vm_end > TASK_SIZE);
82054 newflags = vma->vm_flags | VM_LOCKED;
82055 if (!(flags & MCL_CURRENT))
82056 newflags &= ~VM_LOCKED;
82057@@ -560,6 +576,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
82058 lock_limit >>= PAGE_SHIFT;
82059
82060 ret = -ENOMEM;
82061+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
82062 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
82063 capable(CAP_IPC_LOCK))
82064 ret = do_mlockall(flags);
82065diff --git a/mm/mmap.c b/mm/mmap.c
82066index 90db251..04240d1 100644
82067--- a/mm/mmap.c
82068+++ b/mm/mmap.c
82069@@ -32,6 +32,7 @@
82070 #include <linux/khugepaged.h>
82071 #include <linux/uprobes.h>
82072 #include <linux/rbtree_augmented.h>
82073+#include <linux/random.h>
82074
82075 #include <asm/uaccess.h>
82076 #include <asm/cacheflush.h>
82077@@ -48,6 +49,16 @@
82078 #define arch_rebalance_pgtables(addr, len) (addr)
82079 #endif
82080
82081+static inline void verify_mm_writelocked(struct mm_struct *mm)
82082+{
82083+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
82084+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
82085+ up_read(&mm->mmap_sem);
82086+ BUG();
82087+ }
82088+#endif
82089+}
82090+
82091 static void unmap_region(struct mm_struct *mm,
82092 struct vm_area_struct *vma, struct vm_area_struct *prev,
82093 unsigned long start, unsigned long end);
82094@@ -67,22 +78,32 @@ static void unmap_region(struct mm_struct *mm,
82095 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
82096 *
82097 */
82098-pgprot_t protection_map[16] = {
82099+pgprot_t protection_map[16] __read_only = {
82100 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
82101 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
82102 };
82103
82104-pgprot_t vm_get_page_prot(unsigned long vm_flags)
82105+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
82106 {
82107- return __pgprot(pgprot_val(protection_map[vm_flags &
82108+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
82109 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
82110 pgprot_val(arch_vm_get_page_prot(vm_flags)));
82111+
82112+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
82113+ if (!(__supported_pte_mask & _PAGE_NX) &&
82114+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
82115+ (vm_flags & (VM_READ | VM_WRITE)))
82116+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
82117+#endif
82118+
82119+ return prot;
82120 }
82121 EXPORT_SYMBOL(vm_get_page_prot);
82122
82123 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
82124 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
82125 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
82126+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
82127 /*
82128 * Make sure vm_committed_as in one cacheline and not cacheline shared with
82129 * other variables. It can be updated by several CPUs frequently.
82130@@ -238,6 +259,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
82131 struct vm_area_struct *next = vma->vm_next;
82132
82133 might_sleep();
82134+ BUG_ON(vma->vm_mirror);
82135 if (vma->vm_ops && vma->vm_ops->close)
82136 vma->vm_ops->close(vma);
82137 if (vma->vm_file)
82138@@ -281,6 +303,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
82139 * not page aligned -Ram Gupta
82140 */
82141 rlim = rlimit(RLIMIT_DATA);
82142+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
82143 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
82144 (mm->end_data - mm->start_data) > rlim)
82145 goto out;
82146@@ -888,6 +911,12 @@ static int
82147 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
82148 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
82149 {
82150+
82151+#ifdef CONFIG_PAX_SEGMEXEC
82152+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
82153+ return 0;
82154+#endif
82155+
82156 if (is_mergeable_vma(vma, file, vm_flags) &&
82157 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
82158 if (vma->vm_pgoff == vm_pgoff)
82159@@ -907,6 +936,12 @@ static int
82160 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
82161 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
82162 {
82163+
82164+#ifdef CONFIG_PAX_SEGMEXEC
82165+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
82166+ return 0;
82167+#endif
82168+
82169 if (is_mergeable_vma(vma, file, vm_flags) &&
82170 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
82171 pgoff_t vm_pglen;
82172@@ -949,13 +984,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
82173 struct vm_area_struct *vma_merge(struct mm_struct *mm,
82174 struct vm_area_struct *prev, unsigned long addr,
82175 unsigned long end, unsigned long vm_flags,
82176- struct anon_vma *anon_vma, struct file *file,
82177+ struct anon_vma *anon_vma, struct file *file,
82178 pgoff_t pgoff, struct mempolicy *policy)
82179 {
82180 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
82181 struct vm_area_struct *area, *next;
82182 int err;
82183
82184+#ifdef CONFIG_PAX_SEGMEXEC
82185+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
82186+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
82187+
82188+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
82189+#endif
82190+
82191 /*
82192 * We later require that vma->vm_flags == vm_flags,
82193 * so this tests vma->vm_flags & VM_SPECIAL, too.
82194@@ -971,6 +1013,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
82195 if (next && next->vm_end == end) /* cases 6, 7, 8 */
82196 next = next->vm_next;
82197
82198+#ifdef CONFIG_PAX_SEGMEXEC
82199+ if (prev)
82200+ prev_m = pax_find_mirror_vma(prev);
82201+ if (area)
82202+ area_m = pax_find_mirror_vma(area);
82203+ if (next)
82204+ next_m = pax_find_mirror_vma(next);
82205+#endif
82206+
82207 /*
82208 * Can it merge with the predecessor?
82209 */
82210@@ -990,9 +1041,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
82211 /* cases 1, 6 */
82212 err = vma_adjust(prev, prev->vm_start,
82213 next->vm_end, prev->vm_pgoff, NULL);
82214- } else /* cases 2, 5, 7 */
82215+
82216+#ifdef CONFIG_PAX_SEGMEXEC
82217+ if (!err && prev_m)
82218+ err = vma_adjust(prev_m, prev_m->vm_start,
82219+ next_m->vm_end, prev_m->vm_pgoff, NULL);
82220+#endif
82221+
82222+ } else { /* cases 2, 5, 7 */
82223 err = vma_adjust(prev, prev->vm_start,
82224 end, prev->vm_pgoff, NULL);
82225+
82226+#ifdef CONFIG_PAX_SEGMEXEC
82227+ if (!err && prev_m)
82228+ err = vma_adjust(prev_m, prev_m->vm_start,
82229+ end_m, prev_m->vm_pgoff, NULL);
82230+#endif
82231+
82232+ }
82233 if (err)
82234 return NULL;
82235 khugepaged_enter_vma_merge(prev);
82236@@ -1006,12 +1072,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
82237 mpol_equal(policy, vma_policy(next)) &&
82238 can_vma_merge_before(next, vm_flags,
82239 anon_vma, file, pgoff+pglen)) {
82240- if (prev && addr < prev->vm_end) /* case 4 */
82241+ if (prev && addr < prev->vm_end) { /* case 4 */
82242 err = vma_adjust(prev, prev->vm_start,
82243 addr, prev->vm_pgoff, NULL);
82244- else /* cases 3, 8 */
82245+
82246+#ifdef CONFIG_PAX_SEGMEXEC
82247+ if (!err && prev_m)
82248+ err = vma_adjust(prev_m, prev_m->vm_start,
82249+ addr_m, prev_m->vm_pgoff, NULL);
82250+#endif
82251+
82252+ } else { /* cases 3, 8 */
82253 err = vma_adjust(area, addr, next->vm_end,
82254 next->vm_pgoff - pglen, NULL);
82255+
82256+#ifdef CONFIG_PAX_SEGMEXEC
82257+ if (!err && area_m)
82258+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
82259+ next_m->vm_pgoff - pglen, NULL);
82260+#endif
82261+
82262+ }
82263 if (err)
82264 return NULL;
82265 khugepaged_enter_vma_merge(area);
82266@@ -1120,8 +1201,10 @@ none:
82267 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
82268 struct file *file, long pages)
82269 {
82270- const unsigned long stack_flags
82271- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
82272+
82273+#ifdef CONFIG_PAX_RANDMMAP
82274+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
82275+#endif
82276
82277 mm->total_vm += pages;
82278
82279@@ -1129,7 +1212,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
82280 mm->shared_vm += pages;
82281 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
82282 mm->exec_vm += pages;
82283- } else if (flags & stack_flags)
82284+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
82285 mm->stack_vm += pages;
82286 }
82287 #endif /* CONFIG_PROC_FS */
82288@@ -1165,7 +1248,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82289 * (the exception is when the underlying filesystem is noexec
82290 * mounted, in which case we dont add PROT_EXEC.)
82291 */
82292- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
82293+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
82294 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
82295 prot |= PROT_EXEC;
82296
82297@@ -1191,7 +1274,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82298 /* Obtain the address to map to. we verify (or select) it and ensure
82299 * that it represents a valid section of the address space.
82300 */
82301- addr = get_unmapped_area(file, addr, len, pgoff, flags);
82302+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
82303 if (addr & ~PAGE_MASK)
82304 return addr;
82305
82306@@ -1202,6 +1285,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82307 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
82308 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
82309
82310+#ifdef CONFIG_PAX_MPROTECT
82311+ if (mm->pax_flags & MF_PAX_MPROTECT) {
82312+#ifndef CONFIG_PAX_MPROTECT_COMPAT
82313+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
82314+ gr_log_rwxmmap(file);
82315+
82316+#ifdef CONFIG_PAX_EMUPLT
82317+ vm_flags &= ~VM_EXEC;
82318+#else
82319+ return -EPERM;
82320+#endif
82321+
82322+ }
82323+
82324+ if (!(vm_flags & VM_EXEC))
82325+ vm_flags &= ~VM_MAYEXEC;
82326+#else
82327+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
82328+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
82329+#endif
82330+ else
82331+ vm_flags &= ~VM_MAYWRITE;
82332+ }
82333+#endif
82334+
82335+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
82336+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
82337+ vm_flags &= ~VM_PAGEEXEC;
82338+#endif
82339+
82340 if (flags & MAP_LOCKED)
82341 if (!can_do_mlock())
82342 return -EPERM;
82343@@ -1213,6 +1326,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82344 locked += mm->locked_vm;
82345 lock_limit = rlimit(RLIMIT_MEMLOCK);
82346 lock_limit >>= PAGE_SHIFT;
82347+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
82348 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
82349 return -EAGAIN;
82350 }
82351@@ -1279,6 +1393,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82352 }
82353 }
82354
82355+ if (!gr_acl_handle_mmap(file, prot))
82356+ return -EACCES;
82357+
82358 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
82359 }
82360
82361@@ -1356,7 +1473,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
82362 vm_flags_t vm_flags = vma->vm_flags;
82363
82364 /* If it was private or non-writable, the write bit is already clear */
82365- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
82366+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
82367 return 0;
82368
82369 /* The backer wishes to know when pages are first written to? */
82370@@ -1405,16 +1522,30 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
82371 unsigned long charged = 0;
82372 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
82373
82374+#ifdef CONFIG_PAX_SEGMEXEC
82375+ struct vm_area_struct *vma_m = NULL;
82376+#endif
82377+
82378+ /*
82379+ * mm->mmap_sem is required to protect against another thread
82380+ * changing the mappings in case we sleep.
82381+ */
82382+ verify_mm_writelocked(mm);
82383+
82384 /* Clear old maps */
82385 error = -ENOMEM;
82386-munmap_back:
82387 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
82388 if (do_munmap(mm, addr, len))
82389 return -ENOMEM;
82390- goto munmap_back;
82391+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
82392 }
82393
82394 /* Check against address space limit. */
82395+
82396+#ifdef CONFIG_PAX_RANDMMAP
82397+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
82398+#endif
82399+
82400 if (!may_expand_vm(mm, len >> PAGE_SHIFT))
82401 return -ENOMEM;
82402
82403@@ -1460,6 +1591,16 @@ munmap_back:
82404 goto unacct_error;
82405 }
82406
82407+#ifdef CONFIG_PAX_SEGMEXEC
82408+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
82409+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
82410+ if (!vma_m) {
82411+ error = -ENOMEM;
82412+ goto free_vma;
82413+ }
82414+ }
82415+#endif
82416+
82417 vma->vm_mm = mm;
82418 vma->vm_start = addr;
82419 vma->vm_end = addr + len;
82420@@ -1484,6 +1625,13 @@ munmap_back:
82421 if (error)
82422 goto unmap_and_free_vma;
82423
82424+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
82425+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
82426+ vma->vm_flags |= VM_PAGEEXEC;
82427+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
82428+ }
82429+#endif
82430+
82431 /* Can addr have changed??
82432 *
82433 * Answer: Yes, several device drivers can do it in their
82434@@ -1522,6 +1670,11 @@ munmap_back:
82435 vma_link(mm, vma, prev, rb_link, rb_parent);
82436 file = vma->vm_file;
82437
82438+#ifdef CONFIG_PAX_SEGMEXEC
82439+ if (vma_m)
82440+ BUG_ON(pax_mirror_vma(vma_m, vma));
82441+#endif
82442+
82443 /* Once vma denies write, undo our temporary denial count */
82444 if (correct_wcount)
82445 atomic_inc(&inode->i_writecount);
82446@@ -1529,6 +1682,7 @@ out:
82447 perf_event_mmap(vma);
82448
82449 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
82450+ track_exec_limit(mm, addr, addr + len, vm_flags);
82451 if (vm_flags & VM_LOCKED) {
82452 if (!mlock_vma_pages_range(vma, addr, addr + len))
82453 mm->locked_vm += (len >> PAGE_SHIFT);
82454@@ -1550,6 +1704,12 @@ unmap_and_free_vma:
82455 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
82456 charged = 0;
82457 free_vma:
82458+
82459+#ifdef CONFIG_PAX_SEGMEXEC
82460+ if (vma_m)
82461+ kmem_cache_free(vm_area_cachep, vma_m);
82462+#endif
82463+
82464 kmem_cache_free(vm_area_cachep, vma);
82465 unacct_error:
82466 if (charged)
82467@@ -1557,6 +1717,62 @@ unacct_error:
82468 return error;
82469 }
82470
82471+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
82472+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
82473+{
82474+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
82475+ return (random32() & 0xFF) << PAGE_SHIFT;
82476+
82477+ return 0;
82478+}
82479+#endif
82480+
82481+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
82482+{
82483+ if (!vma) {
82484+#ifdef CONFIG_STACK_GROWSUP
82485+ if (addr > sysctl_heap_stack_gap)
82486+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
82487+ else
82488+ vma = find_vma(current->mm, 0);
82489+ if (vma && (vma->vm_flags & VM_GROWSUP))
82490+ return false;
82491+#endif
82492+ return true;
82493+ }
82494+
82495+ if (addr + len > vma->vm_start)
82496+ return false;
82497+
82498+ if (vma->vm_flags & VM_GROWSDOWN)
82499+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
82500+#ifdef CONFIG_STACK_GROWSUP
82501+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
82502+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
82503+#endif
82504+ else if (offset)
82505+ return offset <= vma->vm_start - addr - len;
82506+
82507+ return true;
82508+}
82509+
82510+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
82511+{
82512+ if (vma->vm_start < len)
82513+ return -ENOMEM;
82514+
82515+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
82516+ if (offset <= vma->vm_start - len)
82517+ return vma->vm_start - len - offset;
82518+ else
82519+ return -ENOMEM;
82520+ }
82521+
82522+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
82523+ return vma->vm_start - len - sysctl_heap_stack_gap;
82524+ return -ENOMEM;
82525+}
82526+
82527 unsigned long unmapped_area(struct vm_unmapped_area_info *info)
82528 {
82529 /*
82530@@ -1776,6 +1992,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
82531 struct mm_struct *mm = current->mm;
82532 struct vm_area_struct *vma;
82533 struct vm_unmapped_area_info info;
82534+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
82535
82536 if (len > TASK_SIZE)
82537 return -ENOMEM;
82538@@ -1783,17 +2000,26 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
82539 if (flags & MAP_FIXED)
82540 return addr;
82541
82542+#ifdef CONFIG_PAX_RANDMMAP
82543+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
82544+#endif
82545+
82546 if (addr) {
82547 addr = PAGE_ALIGN(addr);
82548 vma = find_vma(mm, addr);
82549- if (TASK_SIZE - len >= addr &&
82550- (!vma || addr + len <= vma->vm_start))
82551+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
82552 return addr;
82553 }
82554
82555 info.flags = 0;
82556 info.length = len;
82557 info.low_limit = TASK_UNMAPPED_BASE;
82558+
82559+#ifdef CONFIG_PAX_RANDMMAP
82560+ if (mm->pax_flags & MF_PAX_RANDMMAP)
82561+ info.low_limit += mm->delta_mmap;
82562+#endif
82563+
82564 info.high_limit = TASK_SIZE;
82565 info.align_mask = 0;
82566 return vm_unmapped_area(&info);
82567@@ -1802,10 +2028,16 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
82568
82569 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
82570 {
82571+
82572+#ifdef CONFIG_PAX_SEGMEXEC
82573+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
82574+ return;
82575+#endif
82576+
82577 /*
82578 * Is this a new hole at the lowest possible address?
82579 */
82580- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
82581+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
82582 mm->free_area_cache = addr;
82583 }
82584
82585@@ -1823,6 +2055,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
82586 struct mm_struct *mm = current->mm;
82587 unsigned long addr = addr0;
82588 struct vm_unmapped_area_info info;
82589+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
82590
82591 /* requested length too big for entire address space */
82592 if (len > TASK_SIZE)
82593@@ -1831,12 +2064,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
82594 if (flags & MAP_FIXED)
82595 return addr;
82596
82597+#ifdef CONFIG_PAX_RANDMMAP
82598+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
82599+#endif
82600+
82601 /* requesting a specific address */
82602 if (addr) {
82603 addr = PAGE_ALIGN(addr);
82604 vma = find_vma(mm, addr);
82605- if (TASK_SIZE - len >= addr &&
82606- (!vma || addr + len <= vma->vm_start))
82607+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
82608 return addr;
82609 }
82610
82611@@ -1857,6 +2093,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
82612 VM_BUG_ON(addr != -ENOMEM);
82613 info.flags = 0;
82614 info.low_limit = TASK_UNMAPPED_BASE;
82615+
82616+#ifdef CONFIG_PAX_RANDMMAP
82617+ if (mm->pax_flags & MF_PAX_RANDMMAP)
82618+ info.low_limit += mm->delta_mmap;
82619+#endif
82620+
82621 info.high_limit = TASK_SIZE;
82622 addr = vm_unmapped_area(&info);
82623 }
82624@@ -1867,6 +2109,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
82625
82626 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
82627 {
82628+
82629+#ifdef CONFIG_PAX_SEGMEXEC
82630+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
82631+ return;
82632+#endif
82633+
82634 /*
82635 * Is this a new hole at the highest possible address?
82636 */
82637@@ -1874,8 +2122,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
82638 mm->free_area_cache = addr;
82639
82640 /* dont allow allocations above current base */
82641- if (mm->free_area_cache > mm->mmap_base)
82642+ if (mm->free_area_cache > mm->mmap_base) {
82643 mm->free_area_cache = mm->mmap_base;
82644+ mm->cached_hole_size = ~0UL;
82645+ }
82646 }
82647
82648 unsigned long
82649@@ -1974,6 +2224,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
82650 return vma;
82651 }
82652
82653+#ifdef CONFIG_PAX_SEGMEXEC
82654+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
82655+{
82656+ struct vm_area_struct *vma_m;
82657+
82658+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
82659+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
82660+ BUG_ON(vma->vm_mirror);
82661+ return NULL;
82662+ }
82663+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
82664+ vma_m = vma->vm_mirror;
82665+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
82666+ BUG_ON(vma->vm_file != vma_m->vm_file);
82667+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
82668+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
82669+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
82670+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
82671+ return vma_m;
82672+}
82673+#endif
82674+
82675 /*
82676 * Verify that the stack growth is acceptable and
82677 * update accounting. This is shared with both the
82678@@ -1990,6 +2262,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
82679 return -ENOMEM;
82680
82681 /* Stack limit test */
82682+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
82683 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
82684 return -ENOMEM;
82685
82686@@ -2000,6 +2273,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
82687 locked = mm->locked_vm + grow;
82688 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
82689 limit >>= PAGE_SHIFT;
82690+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
82691 if (locked > limit && !capable(CAP_IPC_LOCK))
82692 return -ENOMEM;
82693 }
82694@@ -2029,37 +2303,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
82695 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
82696 * vma is the last one with address > vma->vm_end. Have to extend vma.
82697 */
82698+#ifndef CONFIG_IA64
82699+static
82700+#endif
82701 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
82702 {
82703 int error;
82704+ bool locknext;
82705
82706 if (!(vma->vm_flags & VM_GROWSUP))
82707 return -EFAULT;
82708
82709+ /* Also guard against wrapping around to address 0. */
82710+ if (address < PAGE_ALIGN(address+1))
82711+ address = PAGE_ALIGN(address+1);
82712+ else
82713+ return -ENOMEM;
82714+
82715 /*
82716 * We must make sure the anon_vma is allocated
82717 * so that the anon_vma locking is not a noop.
82718 */
82719 if (unlikely(anon_vma_prepare(vma)))
82720 return -ENOMEM;
82721+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
82722+ if (locknext && anon_vma_prepare(vma->vm_next))
82723+ return -ENOMEM;
82724 vma_lock_anon_vma(vma);
82725+ if (locknext)
82726+ vma_lock_anon_vma(vma->vm_next);
82727
82728 /*
82729 * vma->vm_start/vm_end cannot change under us because the caller
82730 * is required to hold the mmap_sem in read mode. We need the
82731- * anon_vma lock to serialize against concurrent expand_stacks.
82732- * Also guard against wrapping around to address 0.
82733+ * anon_vma locks to serialize against concurrent expand_stacks
82734+ * and expand_upwards.
82735 */
82736- if (address < PAGE_ALIGN(address+4))
82737- address = PAGE_ALIGN(address+4);
82738- else {
82739- vma_unlock_anon_vma(vma);
82740- return -ENOMEM;
82741- }
82742 error = 0;
82743
82744 /* Somebody else might have raced and expanded it already */
82745- if (address > vma->vm_end) {
82746+ 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)
82747+ error = -ENOMEM;
82748+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
82749 unsigned long size, grow;
82750
82751 size = address - vma->vm_start;
82752@@ -2094,6 +2379,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
82753 }
82754 }
82755 }
82756+ if (locknext)
82757+ vma_unlock_anon_vma(vma->vm_next);
82758 vma_unlock_anon_vma(vma);
82759 khugepaged_enter_vma_merge(vma);
82760 validate_mm(vma->vm_mm);
82761@@ -2108,6 +2395,8 @@ int expand_downwards(struct vm_area_struct *vma,
82762 unsigned long address)
82763 {
82764 int error;
82765+ bool lockprev = false;
82766+ struct vm_area_struct *prev;
82767
82768 /*
82769 * We must make sure the anon_vma is allocated
82770@@ -2121,6 +2410,15 @@ int expand_downwards(struct vm_area_struct *vma,
82771 if (error)
82772 return error;
82773
82774+ prev = vma->vm_prev;
82775+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
82776+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
82777+#endif
82778+ if (lockprev && anon_vma_prepare(prev))
82779+ return -ENOMEM;
82780+ if (lockprev)
82781+ vma_lock_anon_vma(prev);
82782+
82783 vma_lock_anon_vma(vma);
82784
82785 /*
82786@@ -2130,9 +2428,17 @@ int expand_downwards(struct vm_area_struct *vma,
82787 */
82788
82789 /* Somebody else might have raced and expanded it already */
82790- if (address < vma->vm_start) {
82791+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
82792+ error = -ENOMEM;
82793+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
82794 unsigned long size, grow;
82795
82796+#ifdef CONFIG_PAX_SEGMEXEC
82797+ struct vm_area_struct *vma_m;
82798+
82799+ vma_m = pax_find_mirror_vma(vma);
82800+#endif
82801+
82802 size = vma->vm_end - address;
82803 grow = (vma->vm_start - address) >> PAGE_SHIFT;
82804
82805@@ -2157,6 +2463,18 @@ int expand_downwards(struct vm_area_struct *vma,
82806 vma->vm_pgoff -= grow;
82807 anon_vma_interval_tree_post_update_vma(vma);
82808 vma_gap_update(vma);
82809+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
82810+
82811+#ifdef CONFIG_PAX_SEGMEXEC
82812+ if (vma_m) {
82813+ anon_vma_interval_tree_pre_update_vma(vma_m);
82814+ vma_m->vm_start -= grow << PAGE_SHIFT;
82815+ vma_m->vm_pgoff -= grow;
82816+ anon_vma_interval_tree_post_update_vma(vma_m);
82817+ vma_gap_update(vma_m);
82818+ }
82819+#endif
82820+
82821 spin_unlock(&vma->vm_mm->page_table_lock);
82822
82823 perf_event_mmap(vma);
82824@@ -2263,6 +2581,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
82825 do {
82826 long nrpages = vma_pages(vma);
82827
82828+#ifdef CONFIG_PAX_SEGMEXEC
82829+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
82830+ vma = remove_vma(vma);
82831+ continue;
82832+ }
82833+#endif
82834+
82835 if (vma->vm_flags & VM_ACCOUNT)
82836 nr_accounted += nrpages;
82837 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
82838@@ -2308,6 +2633,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
82839 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
82840 vma->vm_prev = NULL;
82841 do {
82842+
82843+#ifdef CONFIG_PAX_SEGMEXEC
82844+ if (vma->vm_mirror) {
82845+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
82846+ vma->vm_mirror->vm_mirror = NULL;
82847+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
82848+ vma->vm_mirror = NULL;
82849+ }
82850+#endif
82851+
82852 vma_rb_erase(vma, &mm->mm_rb);
82853 mm->map_count--;
82854 tail_vma = vma;
82855@@ -2339,14 +2674,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
82856 struct vm_area_struct *new;
82857 int err = -ENOMEM;
82858
82859+#ifdef CONFIG_PAX_SEGMEXEC
82860+ struct vm_area_struct *vma_m, *new_m = NULL;
82861+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
82862+#endif
82863+
82864 if (is_vm_hugetlb_page(vma) && (addr &
82865 ~(huge_page_mask(hstate_vma(vma)))))
82866 return -EINVAL;
82867
82868+#ifdef CONFIG_PAX_SEGMEXEC
82869+ vma_m = pax_find_mirror_vma(vma);
82870+#endif
82871+
82872 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
82873 if (!new)
82874 goto out_err;
82875
82876+#ifdef CONFIG_PAX_SEGMEXEC
82877+ if (vma_m) {
82878+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
82879+ if (!new_m) {
82880+ kmem_cache_free(vm_area_cachep, new);
82881+ goto out_err;
82882+ }
82883+ }
82884+#endif
82885+
82886 /* most fields are the same, copy all, and then fixup */
82887 *new = *vma;
82888
82889@@ -2359,6 +2713,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
82890 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
82891 }
82892
82893+#ifdef CONFIG_PAX_SEGMEXEC
82894+ if (vma_m) {
82895+ *new_m = *vma_m;
82896+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
82897+ new_m->vm_mirror = new;
82898+ new->vm_mirror = new_m;
82899+
82900+ if (new_below)
82901+ new_m->vm_end = addr_m;
82902+ else {
82903+ new_m->vm_start = addr_m;
82904+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
82905+ }
82906+ }
82907+#endif
82908+
82909 pol = mpol_dup(vma_policy(vma));
82910 if (IS_ERR(pol)) {
82911 err = PTR_ERR(pol);
82912@@ -2381,6 +2751,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
82913 else
82914 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
82915
82916+#ifdef CONFIG_PAX_SEGMEXEC
82917+ if (!err && vma_m) {
82918+ if (anon_vma_clone(new_m, vma_m))
82919+ goto out_free_mpol;
82920+
82921+ mpol_get(pol);
82922+ vma_set_policy(new_m, pol);
82923+
82924+ if (new_m->vm_file)
82925+ get_file(new_m->vm_file);
82926+
82927+ if (new_m->vm_ops && new_m->vm_ops->open)
82928+ new_m->vm_ops->open(new_m);
82929+
82930+ if (new_below)
82931+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
82932+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
82933+ else
82934+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
82935+
82936+ if (err) {
82937+ if (new_m->vm_ops && new_m->vm_ops->close)
82938+ new_m->vm_ops->close(new_m);
82939+ if (new_m->vm_file)
82940+ fput(new_m->vm_file);
82941+ mpol_put(pol);
82942+ }
82943+ }
82944+#endif
82945+
82946 /* Success. */
82947 if (!err)
82948 return 0;
82949@@ -2390,10 +2790,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
82950 new->vm_ops->close(new);
82951 if (new->vm_file)
82952 fput(new->vm_file);
82953- unlink_anon_vmas(new);
82954 out_free_mpol:
82955 mpol_put(pol);
82956 out_free_vma:
82957+
82958+#ifdef CONFIG_PAX_SEGMEXEC
82959+ if (new_m) {
82960+ unlink_anon_vmas(new_m);
82961+ kmem_cache_free(vm_area_cachep, new_m);
82962+ }
82963+#endif
82964+
82965+ unlink_anon_vmas(new);
82966 kmem_cache_free(vm_area_cachep, new);
82967 out_err:
82968 return err;
82969@@ -2406,6 +2814,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
82970 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
82971 unsigned long addr, int new_below)
82972 {
82973+
82974+#ifdef CONFIG_PAX_SEGMEXEC
82975+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
82976+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
82977+ if (mm->map_count >= sysctl_max_map_count-1)
82978+ return -ENOMEM;
82979+ } else
82980+#endif
82981+
82982 if (mm->map_count >= sysctl_max_map_count)
82983 return -ENOMEM;
82984
82985@@ -2417,11 +2834,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
82986 * work. This now handles partial unmappings.
82987 * Jeremy Fitzhardinge <jeremy@goop.org>
82988 */
82989+#ifdef CONFIG_PAX_SEGMEXEC
82990 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
82991 {
82992+ int ret = __do_munmap(mm, start, len);
82993+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
82994+ return ret;
82995+
82996+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
82997+}
82998+
82999+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
83000+#else
83001+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
83002+#endif
83003+{
83004 unsigned long end;
83005 struct vm_area_struct *vma, *prev, *last;
83006
83007+ /*
83008+ * mm->mmap_sem is required to protect against another thread
83009+ * changing the mappings in case we sleep.
83010+ */
83011+ verify_mm_writelocked(mm);
83012+
83013 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
83014 return -EINVAL;
83015
83016@@ -2496,6 +2932,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
83017 /* Fix up all other VM information */
83018 remove_vma_list(mm, vma);
83019
83020+ track_exec_limit(mm, start, end, 0UL);
83021+
83022 return 0;
83023 }
83024
83025@@ -2504,6 +2942,13 @@ int vm_munmap(unsigned long start, size_t len)
83026 int ret;
83027 struct mm_struct *mm = current->mm;
83028
83029+
83030+#ifdef CONFIG_PAX_SEGMEXEC
83031+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
83032+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
83033+ return -EINVAL;
83034+#endif
83035+
83036 down_write(&mm->mmap_sem);
83037 ret = do_munmap(mm, start, len);
83038 up_write(&mm->mmap_sem);
83039@@ -2517,16 +2962,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
83040 return vm_munmap(addr, len);
83041 }
83042
83043-static inline void verify_mm_writelocked(struct mm_struct *mm)
83044-{
83045-#ifdef CONFIG_DEBUG_VM
83046- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
83047- WARN_ON(1);
83048- up_read(&mm->mmap_sem);
83049- }
83050-#endif
83051-}
83052-
83053 /*
83054 * this is really a simplified "do_mmap". it only handles
83055 * anonymous maps. eventually we may be able to do some
83056@@ -2540,6 +2975,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83057 struct rb_node ** rb_link, * rb_parent;
83058 pgoff_t pgoff = addr >> PAGE_SHIFT;
83059 int error;
83060+ unsigned long charged;
83061
83062 len = PAGE_ALIGN(len);
83063 if (!len)
83064@@ -2547,16 +2983,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83065
83066 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
83067
83068+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
83069+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
83070+ flags &= ~VM_EXEC;
83071+
83072+#ifdef CONFIG_PAX_MPROTECT
83073+ if (mm->pax_flags & MF_PAX_MPROTECT)
83074+ flags &= ~VM_MAYEXEC;
83075+#endif
83076+
83077+ }
83078+#endif
83079+
83080 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
83081 if (error & ~PAGE_MASK)
83082 return error;
83083
83084+ charged = len >> PAGE_SHIFT;
83085+
83086 /*
83087 * mlock MCL_FUTURE?
83088 */
83089 if (mm->def_flags & VM_LOCKED) {
83090 unsigned long locked, lock_limit;
83091- locked = len >> PAGE_SHIFT;
83092+ locked = charged;
83093 locked += mm->locked_vm;
83094 lock_limit = rlimit(RLIMIT_MEMLOCK);
83095 lock_limit >>= PAGE_SHIFT;
83096@@ -2573,21 +3023,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83097 /*
83098 * Clear old maps. this also does some error checking for us
83099 */
83100- munmap_back:
83101 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
83102 if (do_munmap(mm, addr, len))
83103 return -ENOMEM;
83104- goto munmap_back;
83105+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
83106 }
83107
83108 /* Check against address space limits *after* clearing old maps... */
83109- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
83110+ if (!may_expand_vm(mm, charged))
83111 return -ENOMEM;
83112
83113 if (mm->map_count > sysctl_max_map_count)
83114 return -ENOMEM;
83115
83116- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
83117+ if (security_vm_enough_memory_mm(mm, charged))
83118 return -ENOMEM;
83119
83120 /* Can we just expand an old private anonymous mapping? */
83121@@ -2601,7 +3050,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83122 */
83123 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
83124 if (!vma) {
83125- vm_unacct_memory(len >> PAGE_SHIFT);
83126+ vm_unacct_memory(charged);
83127 return -ENOMEM;
83128 }
83129
83130@@ -2615,11 +3064,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83131 vma_link(mm, vma, prev, rb_link, rb_parent);
83132 out:
83133 perf_event_mmap(vma);
83134- mm->total_vm += len >> PAGE_SHIFT;
83135+ mm->total_vm += charged;
83136 if (flags & VM_LOCKED) {
83137 if (!mlock_vma_pages_range(vma, addr, addr + len))
83138- mm->locked_vm += (len >> PAGE_SHIFT);
83139+ mm->locked_vm += charged;
83140 }
83141+ track_exec_limit(mm, addr, addr + len, flags);
83142 return addr;
83143 }
83144
83145@@ -2677,6 +3127,7 @@ void exit_mmap(struct mm_struct *mm)
83146 while (vma) {
83147 if (vma->vm_flags & VM_ACCOUNT)
83148 nr_accounted += vma_pages(vma);
83149+ vma->vm_mirror = NULL;
83150 vma = remove_vma(vma);
83151 }
83152 vm_unacct_memory(nr_accounted);
83153@@ -2693,6 +3144,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
83154 struct vm_area_struct *prev;
83155 struct rb_node **rb_link, *rb_parent;
83156
83157+#ifdef CONFIG_PAX_SEGMEXEC
83158+ struct vm_area_struct *vma_m = NULL;
83159+#endif
83160+
83161+ if (security_mmap_addr(vma->vm_start))
83162+ return -EPERM;
83163+
83164 /*
83165 * The vm_pgoff of a purely anonymous vma should be irrelevant
83166 * until its first write fault, when page's anon_vma and index
83167@@ -2716,7 +3174,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
83168 security_vm_enough_memory_mm(mm, vma_pages(vma)))
83169 return -ENOMEM;
83170
83171+#ifdef CONFIG_PAX_SEGMEXEC
83172+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
83173+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
83174+ if (!vma_m)
83175+ return -ENOMEM;
83176+ }
83177+#endif
83178+
83179 vma_link(mm, vma, prev, rb_link, rb_parent);
83180+
83181+#ifdef CONFIG_PAX_SEGMEXEC
83182+ if (vma_m)
83183+ BUG_ON(pax_mirror_vma(vma_m, vma));
83184+#endif
83185+
83186 return 0;
83187 }
83188
83189@@ -2736,6 +3208,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
83190 struct mempolicy *pol;
83191 bool faulted_in_anon_vma = true;
83192
83193+ BUG_ON(vma->vm_mirror);
83194+
83195 /*
83196 * If anonymous vma has not yet been faulted, update new pgoff
83197 * to match new location, to increase its chance of merging.
83198@@ -2802,6 +3276,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
83199 return NULL;
83200 }
83201
83202+#ifdef CONFIG_PAX_SEGMEXEC
83203+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
83204+{
83205+ struct vm_area_struct *prev_m;
83206+ struct rb_node **rb_link_m, *rb_parent_m;
83207+ struct mempolicy *pol_m;
83208+
83209+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
83210+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
83211+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
83212+ *vma_m = *vma;
83213+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
83214+ if (anon_vma_clone(vma_m, vma))
83215+ return -ENOMEM;
83216+ pol_m = vma_policy(vma_m);
83217+ mpol_get(pol_m);
83218+ vma_set_policy(vma_m, pol_m);
83219+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
83220+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
83221+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
83222+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
83223+ if (vma_m->vm_file)
83224+ get_file(vma_m->vm_file);
83225+ if (vma_m->vm_ops && vma_m->vm_ops->open)
83226+ vma_m->vm_ops->open(vma_m);
83227+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
83228+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
83229+ vma_m->vm_mirror = vma;
83230+ vma->vm_mirror = vma_m;
83231+ return 0;
83232+}
83233+#endif
83234+
83235 /*
83236 * Return true if the calling process may expand its vm space by the passed
83237 * number of pages
83238@@ -2813,6 +3320,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
83239
83240 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
83241
83242+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
83243 if (cur + npages > lim)
83244 return 0;
83245 return 1;
83246@@ -2883,6 +3391,22 @@ int install_special_mapping(struct mm_struct *mm,
83247 vma->vm_start = addr;
83248 vma->vm_end = addr + len;
83249
83250+#ifdef CONFIG_PAX_MPROTECT
83251+ if (mm->pax_flags & MF_PAX_MPROTECT) {
83252+#ifndef CONFIG_PAX_MPROTECT_COMPAT
83253+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
83254+ return -EPERM;
83255+ if (!(vm_flags & VM_EXEC))
83256+ vm_flags &= ~VM_MAYEXEC;
83257+#else
83258+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
83259+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
83260+#endif
83261+ else
83262+ vm_flags &= ~VM_MAYWRITE;
83263+ }
83264+#endif
83265+
83266 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
83267 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
83268
83269diff --git a/mm/mprotect.c b/mm/mprotect.c
83270index 94722a4..9837984 100644
83271--- a/mm/mprotect.c
83272+++ b/mm/mprotect.c
83273@@ -23,10 +23,17 @@
83274 #include <linux/mmu_notifier.h>
83275 #include <linux/migrate.h>
83276 #include <linux/perf_event.h>
83277+
83278+#ifdef CONFIG_PAX_MPROTECT
83279+#include <linux/elf.h>
83280+#include <linux/binfmts.h>
83281+#endif
83282+
83283 #include <asm/uaccess.h>
83284 #include <asm/pgtable.h>
83285 #include <asm/cacheflush.h>
83286 #include <asm/tlbflush.h>
83287+#include <asm/mmu_context.h>
83288
83289 #ifndef pgprot_modify
83290 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
83291@@ -233,6 +240,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
83292 return pages;
83293 }
83294
83295+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
83296+/* called while holding the mmap semaphor for writing except stack expansion */
83297+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
83298+{
83299+ unsigned long oldlimit, newlimit = 0UL;
83300+
83301+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
83302+ return;
83303+
83304+ spin_lock(&mm->page_table_lock);
83305+ oldlimit = mm->context.user_cs_limit;
83306+ if ((prot & VM_EXEC) && oldlimit < end)
83307+ /* USER_CS limit moved up */
83308+ newlimit = end;
83309+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
83310+ /* USER_CS limit moved down */
83311+ newlimit = start;
83312+
83313+ if (newlimit) {
83314+ mm->context.user_cs_limit = newlimit;
83315+
83316+#ifdef CONFIG_SMP
83317+ wmb();
83318+ cpus_clear(mm->context.cpu_user_cs_mask);
83319+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
83320+#endif
83321+
83322+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
83323+ }
83324+ spin_unlock(&mm->page_table_lock);
83325+ if (newlimit == end) {
83326+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
83327+
83328+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
83329+ if (is_vm_hugetlb_page(vma))
83330+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
83331+ else
83332+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
83333+ }
83334+}
83335+#endif
83336+
83337 int
83338 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
83339 unsigned long start, unsigned long end, unsigned long newflags)
83340@@ -245,11 +294,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
83341 int error;
83342 int dirty_accountable = 0;
83343
83344+#ifdef CONFIG_PAX_SEGMEXEC
83345+ struct vm_area_struct *vma_m = NULL;
83346+ unsigned long start_m, end_m;
83347+
83348+ start_m = start + SEGMEXEC_TASK_SIZE;
83349+ end_m = end + SEGMEXEC_TASK_SIZE;
83350+#endif
83351+
83352 if (newflags == oldflags) {
83353 *pprev = vma;
83354 return 0;
83355 }
83356
83357+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
83358+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
83359+
83360+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
83361+ return -ENOMEM;
83362+
83363+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
83364+ return -ENOMEM;
83365+ }
83366+
83367 /*
83368 * If we make a private mapping writable we increase our commit;
83369 * but (without finer accounting) cannot reduce our commit if we
83370@@ -266,6 +333,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
83371 }
83372 }
83373
83374+#ifdef CONFIG_PAX_SEGMEXEC
83375+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
83376+ if (start != vma->vm_start) {
83377+ error = split_vma(mm, vma, start, 1);
83378+ if (error)
83379+ goto fail;
83380+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
83381+ *pprev = (*pprev)->vm_next;
83382+ }
83383+
83384+ if (end != vma->vm_end) {
83385+ error = split_vma(mm, vma, end, 0);
83386+ if (error)
83387+ goto fail;
83388+ }
83389+
83390+ if (pax_find_mirror_vma(vma)) {
83391+ error = __do_munmap(mm, start_m, end_m - start_m);
83392+ if (error)
83393+ goto fail;
83394+ } else {
83395+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
83396+ if (!vma_m) {
83397+ error = -ENOMEM;
83398+ goto fail;
83399+ }
83400+ vma->vm_flags = newflags;
83401+ error = pax_mirror_vma(vma_m, vma);
83402+ if (error) {
83403+ vma->vm_flags = oldflags;
83404+ goto fail;
83405+ }
83406+ }
83407+ }
83408+#endif
83409+
83410 /*
83411 * First try to merge with previous and/or next vma.
83412 */
83413@@ -296,9 +399,21 @@ success:
83414 * vm_flags and vm_page_prot are protected by the mmap_sem
83415 * held in write mode.
83416 */
83417+
83418+#ifdef CONFIG_PAX_SEGMEXEC
83419+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
83420+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
83421+#endif
83422+
83423 vma->vm_flags = newflags;
83424+
83425+#ifdef CONFIG_PAX_MPROTECT
83426+ if (mm->binfmt && mm->binfmt->handle_mprotect)
83427+ mm->binfmt->handle_mprotect(vma, newflags);
83428+#endif
83429+
83430 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
83431- vm_get_page_prot(newflags));
83432+ vm_get_page_prot(vma->vm_flags));
83433
83434 if (vma_wants_writenotify(vma)) {
83435 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
83436@@ -337,6 +452,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83437 end = start + len;
83438 if (end <= start)
83439 return -ENOMEM;
83440+
83441+#ifdef CONFIG_PAX_SEGMEXEC
83442+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
83443+ if (end > SEGMEXEC_TASK_SIZE)
83444+ return -EINVAL;
83445+ } else
83446+#endif
83447+
83448+ if (end > TASK_SIZE)
83449+ return -EINVAL;
83450+
83451 if (!arch_validate_prot(prot))
83452 return -EINVAL;
83453
83454@@ -344,7 +470,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83455 /*
83456 * Does the application expect PROT_READ to imply PROT_EXEC:
83457 */
83458- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
83459+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
83460 prot |= PROT_EXEC;
83461
83462 vm_flags = calc_vm_prot_bits(prot);
83463@@ -376,6 +502,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83464 if (start > vma->vm_start)
83465 prev = vma;
83466
83467+#ifdef CONFIG_PAX_MPROTECT
83468+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
83469+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
83470+#endif
83471+
83472 for (nstart = start ; ; ) {
83473 unsigned long newflags;
83474
83475@@ -386,6 +517,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83476
83477 /* newflags >> 4 shift VM_MAY% in place of VM_% */
83478 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
83479+ if (prot & (PROT_WRITE | PROT_EXEC))
83480+ gr_log_rwxmprotect(vma->vm_file);
83481+
83482+ error = -EACCES;
83483+ goto out;
83484+ }
83485+
83486+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
83487 error = -EACCES;
83488 goto out;
83489 }
83490@@ -400,6 +539,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83491 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
83492 if (error)
83493 goto out;
83494+
83495+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
83496+
83497 nstart = tmp;
83498
83499 if (nstart < prev->vm_end)
83500diff --git a/mm/mremap.c b/mm/mremap.c
83501index e1031e1..1f2a0a1 100644
83502--- a/mm/mremap.c
83503+++ b/mm/mremap.c
83504@@ -125,6 +125,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
83505 continue;
83506 pte = ptep_get_and_clear(mm, old_addr, old_pte);
83507 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
83508+
83509+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
83510+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
83511+ pte = pte_exprotect(pte);
83512+#endif
83513+
83514 set_pte_at(mm, new_addr, new_pte, pte);
83515 }
83516
83517@@ -319,6 +325,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
83518 if (is_vm_hugetlb_page(vma))
83519 goto Einval;
83520
83521+#ifdef CONFIG_PAX_SEGMEXEC
83522+ if (pax_find_mirror_vma(vma))
83523+ goto Einval;
83524+#endif
83525+
83526 /* We can't remap across vm area boundaries */
83527 if (old_len > vma->vm_end - addr)
83528 goto Efault;
83529@@ -375,20 +386,25 @@ static unsigned long mremap_to(unsigned long addr,
83530 unsigned long ret = -EINVAL;
83531 unsigned long charged = 0;
83532 unsigned long map_flags;
83533+ unsigned long pax_task_size = TASK_SIZE;
83534
83535 if (new_addr & ~PAGE_MASK)
83536 goto out;
83537
83538- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
83539+#ifdef CONFIG_PAX_SEGMEXEC
83540+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
83541+ pax_task_size = SEGMEXEC_TASK_SIZE;
83542+#endif
83543+
83544+ pax_task_size -= PAGE_SIZE;
83545+
83546+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
83547 goto out;
83548
83549 /* Check if the location we're moving into overlaps the
83550 * old location at all, and fail if it does.
83551 */
83552- if ((new_addr <= addr) && (new_addr+new_len) > addr)
83553- goto out;
83554-
83555- if ((addr <= new_addr) && (addr+old_len) > new_addr)
83556+ if (addr + old_len > new_addr && new_addr + new_len > addr)
83557 goto out;
83558
83559 ret = do_munmap(mm, new_addr, new_len);
83560@@ -456,6 +472,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
83561 struct vm_area_struct *vma;
83562 unsigned long ret = -EINVAL;
83563 unsigned long charged = 0;
83564+ unsigned long pax_task_size = TASK_SIZE;
83565
83566 down_write(&current->mm->mmap_sem);
83567
83568@@ -476,6 +493,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
83569 if (!new_len)
83570 goto out;
83571
83572+#ifdef CONFIG_PAX_SEGMEXEC
83573+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
83574+ pax_task_size = SEGMEXEC_TASK_SIZE;
83575+#endif
83576+
83577+ pax_task_size -= PAGE_SIZE;
83578+
83579+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
83580+ old_len > pax_task_size || addr > pax_task_size-old_len)
83581+ goto out;
83582+
83583 if (flags & MREMAP_FIXED) {
83584 if (flags & MREMAP_MAYMOVE)
83585 ret = mremap_to(addr, old_len, new_addr, new_len);
83586@@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
83587 addr + new_len);
83588 }
83589 ret = addr;
83590+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
83591 goto out;
83592 }
83593 }
83594@@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
83595 goto out;
83596 }
83597
83598+ map_flags = vma->vm_flags;
83599 ret = move_vma(vma, addr, old_len, new_len, new_addr);
83600+ if (!(ret & ~PAGE_MASK)) {
83601+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
83602+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
83603+ }
83604 }
83605 out:
83606 if (ret & ~PAGE_MASK)
83607diff --git a/mm/nommu.c b/mm/nommu.c
83608index bbe1f3f..b2601ea 100644
83609--- a/mm/nommu.c
83610+++ b/mm/nommu.c
83611@@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
83612 int sysctl_overcommit_ratio = 50; /* default is 50% */
83613 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
83614 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
83615-int heap_stack_gap = 0;
83616
83617 atomic_long_t mmap_pages_allocated;
83618
83619@@ -839,15 +838,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
83620 EXPORT_SYMBOL(find_vma);
83621
83622 /*
83623- * find a VMA
83624- * - we don't extend stack VMAs under NOMMU conditions
83625- */
83626-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
83627-{
83628- return find_vma(mm, addr);
83629-}
83630-
83631-/*
83632 * expand a stack to a given address
83633 * - not supported under NOMMU conditions
83634 */
83635@@ -1555,6 +1545,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
83636
83637 /* most fields are the same, copy all, and then fixup */
83638 *new = *vma;
83639+ INIT_LIST_HEAD(&new->anon_vma_chain);
83640 *region = *vma->vm_region;
83641 new->vm_region = region;
83642
83643@@ -1975,8 +1966,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
83644 }
83645 EXPORT_SYMBOL(generic_file_remap_pages);
83646
83647-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
83648- unsigned long addr, void *buf, int len, int write)
83649+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
83650+ unsigned long addr, void *buf, size_t len, int write)
83651 {
83652 struct vm_area_struct *vma;
83653
83654@@ -2017,8 +2008,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
83655 *
83656 * The caller must hold a reference on @mm.
83657 */
83658-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
83659- void *buf, int len, int write)
83660+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
83661+ void *buf, size_t len, int write)
83662 {
83663 return __access_remote_vm(NULL, mm, addr, buf, len, write);
83664 }
83665@@ -2027,7 +2018,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
83666 * Access another process' address space.
83667 * - source/target buffer must be kernel space
83668 */
83669-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
83670+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
83671 {
83672 struct mm_struct *mm;
83673
83674diff --git a/mm/page-writeback.c b/mm/page-writeback.c
83675index 0713bfb..b95bb87 100644
83676--- a/mm/page-writeback.c
83677+++ b/mm/page-writeback.c
83678@@ -655,7 +655,7 @@ unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)
83679 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
83680 * - the bdi dirty thresh drops quickly due to change of JBOD workload
83681 */
83682-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
83683+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
83684 unsigned long thresh,
83685 unsigned long bg_thresh,
83686 unsigned long dirty,
83687@@ -1630,7 +1630,7 @@ ratelimit_handler(struct notifier_block *self, unsigned long action,
83688 }
83689 }
83690
83691-static struct notifier_block __cpuinitdata ratelimit_nb = {
83692+static struct notifier_block ratelimit_nb = {
83693 .notifier_call = ratelimit_handler,
83694 .next = NULL,
83695 };
83696diff --git a/mm/page_alloc.c b/mm/page_alloc.c
83697index 6a83cd3..3ab04ef 100644
83698--- a/mm/page_alloc.c
83699+++ b/mm/page_alloc.c
83700@@ -58,6 +58,7 @@
83701 #include <linux/prefetch.h>
83702 #include <linux/migrate.h>
83703 #include <linux/page-debug-flags.h>
83704+#include <linux/random.h>
83705
83706 #include <asm/tlbflush.h>
83707 #include <asm/div64.h>
83708@@ -338,7 +339,7 @@ out:
83709 * This usage means that zero-order pages may not be compound.
83710 */
83711
83712-static void free_compound_page(struct page *page)
83713+void free_compound_page(struct page *page)
83714 {
83715 __free_pages_ok(page, compound_order(page));
83716 }
83717@@ -693,6 +694,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
83718 int i;
83719 int bad = 0;
83720
83721+#ifdef CONFIG_PAX_MEMORY_SANITIZE
83722+ unsigned long index = 1UL << order;
83723+#endif
83724+
83725 trace_mm_page_free(page, order);
83726 kmemcheck_free_shadow(page, order);
83727
83728@@ -708,6 +713,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
83729 debug_check_no_obj_freed(page_address(page),
83730 PAGE_SIZE << order);
83731 }
83732+
83733+#ifdef CONFIG_PAX_MEMORY_SANITIZE
83734+ for (; index; --index)
83735+ sanitize_highpage(page + index - 1);
83736+#endif
83737+
83738 arch_free_page(page, order);
83739 kernel_map_pages(page, 1 << order, 0);
83740
83741@@ -730,6 +741,19 @@ static void __free_pages_ok(struct page *page, unsigned int order)
83742 local_irq_restore(flags);
83743 }
83744
83745+#ifdef CONFIG_PAX_LATENT_ENTROPY
83746+bool __meminitdata extra_latent_entropy;
83747+
83748+static int __init setup_pax_extra_latent_entropy(char *str)
83749+{
83750+ extra_latent_entropy = true;
83751+ return 0;
83752+}
83753+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
83754+
83755+volatile u64 latent_entropy;
83756+#endif
83757+
83758 /*
83759 * Read access to zone->managed_pages is safe because it's unsigned long,
83760 * but we still need to serialize writers. Currently all callers of
83761@@ -752,6 +776,19 @@ void __meminit __free_pages_bootmem(struct page *page, unsigned int order)
83762 set_page_count(p, 0);
83763 }
83764
83765+#ifdef CONFIG_PAX_LATENT_ENTROPY
83766+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
83767+ u64 hash = 0;
83768+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
83769+ const u64 *data = lowmem_page_address(page);
83770+
83771+ for (index = 0; index < end; index++)
83772+ hash ^= hash + data[index];
83773+ latent_entropy ^= hash;
83774+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
83775+ }
83776+#endif
83777+
83778 page_zone(page)->managed_pages += 1 << order;
83779 set_page_refcounted(page);
83780 __free_pages(page, order);
83781@@ -861,8 +898,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
83782 arch_alloc_page(page, order);
83783 kernel_map_pages(page, 1 << order, 1);
83784
83785+#ifndef CONFIG_PAX_MEMORY_SANITIZE
83786 if (gfp_flags & __GFP_ZERO)
83787 prep_zero_page(page, order, gfp_flags);
83788+#endif
83789
83790 if (order && (gfp_flags & __GFP_COMP))
83791 prep_compound_page(page, order);
83792@@ -3752,7 +3791,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
83793 unsigned long pfn;
83794
83795 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
83796+#ifdef CONFIG_X86_32
83797+ /* boot failures in VMware 8 on 32bit vanilla since
83798+ this change */
83799+ if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
83800+#else
83801 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
83802+#endif
83803 return 1;
83804 }
83805 return 0;
83806diff --git a/mm/percpu.c b/mm/percpu.c
83807index 8c8e08f..73a5cda 100644
83808--- a/mm/percpu.c
83809+++ b/mm/percpu.c
83810@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
83811 static unsigned int pcpu_high_unit_cpu __read_mostly;
83812
83813 /* the address of the first chunk which starts with the kernel static area */
83814-void *pcpu_base_addr __read_mostly;
83815+void *pcpu_base_addr __read_only;
83816 EXPORT_SYMBOL_GPL(pcpu_base_addr);
83817
83818 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
83819diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
83820index fd26d04..0cea1b0 100644
83821--- a/mm/process_vm_access.c
83822+++ b/mm/process_vm_access.c
83823@@ -13,6 +13,7 @@
83824 #include <linux/uio.h>
83825 #include <linux/sched.h>
83826 #include <linux/highmem.h>
83827+#include <linux/security.h>
83828 #include <linux/ptrace.h>
83829 #include <linux/slab.h>
83830 #include <linux/syscalls.h>
83831@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
83832 size_t iov_l_curr_offset = 0;
83833 ssize_t iov_len;
83834
83835+ return -ENOSYS; // PaX: until properly audited
83836+
83837 /*
83838 * Work out how many pages of struct pages we're going to need
83839 * when eventually calling get_user_pages
83840 */
83841 for (i = 0; i < riovcnt; i++) {
83842 iov_len = rvec[i].iov_len;
83843- if (iov_len > 0) {
83844- nr_pages_iov = ((unsigned long)rvec[i].iov_base
83845- + iov_len)
83846- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
83847- / PAGE_SIZE + 1;
83848- nr_pages = max(nr_pages, nr_pages_iov);
83849- }
83850+ if (iov_len <= 0)
83851+ continue;
83852+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
83853+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
83854+ nr_pages = max(nr_pages, nr_pages_iov);
83855 }
83856
83857 if (nr_pages == 0)
83858@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
83859 goto free_proc_pages;
83860 }
83861
83862+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
83863+ rc = -EPERM;
83864+ goto put_task_struct;
83865+ }
83866+
83867 mm = mm_access(task, PTRACE_MODE_ATTACH);
83868 if (!mm || IS_ERR(mm)) {
83869 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
83870diff --git a/mm/rmap.c b/mm/rmap.c
83871index 2c78f8c..9e9c624 100644
83872--- a/mm/rmap.c
83873+++ b/mm/rmap.c
83874@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
83875 struct anon_vma *anon_vma = vma->anon_vma;
83876 struct anon_vma_chain *avc;
83877
83878+#ifdef CONFIG_PAX_SEGMEXEC
83879+ struct anon_vma_chain *avc_m = NULL;
83880+#endif
83881+
83882 might_sleep();
83883 if (unlikely(!anon_vma)) {
83884 struct mm_struct *mm = vma->vm_mm;
83885@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
83886 if (!avc)
83887 goto out_enomem;
83888
83889+#ifdef CONFIG_PAX_SEGMEXEC
83890+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
83891+ if (!avc_m)
83892+ goto out_enomem_free_avc;
83893+#endif
83894+
83895 anon_vma = find_mergeable_anon_vma(vma);
83896 allocated = NULL;
83897 if (!anon_vma) {
83898@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
83899 /* page_table_lock to protect against threads */
83900 spin_lock(&mm->page_table_lock);
83901 if (likely(!vma->anon_vma)) {
83902+
83903+#ifdef CONFIG_PAX_SEGMEXEC
83904+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
83905+
83906+ if (vma_m) {
83907+ BUG_ON(vma_m->anon_vma);
83908+ vma_m->anon_vma = anon_vma;
83909+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
83910+ avc_m = NULL;
83911+ }
83912+#endif
83913+
83914 vma->anon_vma = anon_vma;
83915 anon_vma_chain_link(vma, avc, anon_vma);
83916 allocated = NULL;
83917@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
83918
83919 if (unlikely(allocated))
83920 put_anon_vma(allocated);
83921+
83922+#ifdef CONFIG_PAX_SEGMEXEC
83923+ if (unlikely(avc_m))
83924+ anon_vma_chain_free(avc_m);
83925+#endif
83926+
83927 if (unlikely(avc))
83928 anon_vma_chain_free(avc);
83929 }
83930 return 0;
83931
83932 out_enomem_free_avc:
83933+
83934+#ifdef CONFIG_PAX_SEGMEXEC
83935+ if (avc_m)
83936+ anon_vma_chain_free(avc_m);
83937+#endif
83938+
83939 anon_vma_chain_free(avc);
83940 out_enomem:
83941 return -ENOMEM;
83942@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
83943 * Attach the anon_vmas from src to dst.
83944 * Returns 0 on success, -ENOMEM on failure.
83945 */
83946-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
83947+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
83948 {
83949 struct anon_vma_chain *avc, *pavc;
83950 struct anon_vma *root = NULL;
83951@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
83952 * the corresponding VMA in the parent process is attached to.
83953 * Returns 0 on success, non-zero on failure.
83954 */
83955-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
83956+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
83957 {
83958 struct anon_vma_chain *avc;
83959 struct anon_vma *anon_vma;
83960diff --git a/mm/shmem.c b/mm/shmem.c
83961index efd0b3a..994b702 100644
83962--- a/mm/shmem.c
83963+++ b/mm/shmem.c
83964@@ -31,7 +31,7 @@
83965 #include <linux/export.h>
83966 #include <linux/swap.h>
83967
83968-static struct vfsmount *shm_mnt;
83969+struct vfsmount *shm_mnt;
83970
83971 #ifdef CONFIG_SHMEM
83972 /*
83973@@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
83974 #define BOGO_DIRENT_SIZE 20
83975
83976 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
83977-#define SHORT_SYMLINK_LEN 128
83978+#define SHORT_SYMLINK_LEN 64
83979
83980 /*
83981 * shmem_fallocate and shmem_writepage communicate via inode->i_private
83982@@ -2202,6 +2202,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
83983 static int shmem_xattr_validate(const char *name)
83984 {
83985 struct { const char *prefix; size_t len; } arr[] = {
83986+
83987+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
83988+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
83989+#endif
83990+
83991 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
83992 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
83993 };
83994@@ -2257,6 +2262,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
83995 if (err)
83996 return err;
83997
83998+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
83999+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
84000+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
84001+ return -EOPNOTSUPP;
84002+ if (size > 8)
84003+ return -EINVAL;
84004+ }
84005+#endif
84006+
84007 return simple_xattr_set(&info->xattrs, name, value, size, flags);
84008 }
84009
84010@@ -2562,8 +2576,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
84011 int err = -ENOMEM;
84012
84013 /* Round up to L1_CACHE_BYTES to resist false sharing */
84014- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
84015- L1_CACHE_BYTES), GFP_KERNEL);
84016+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
84017 if (!sbinfo)
84018 return -ENOMEM;
84019
84020diff --git a/mm/slab.c b/mm/slab.c
84021index e7667a3..a48e73b 100644
84022--- a/mm/slab.c
84023+++ b/mm/slab.c
84024@@ -306,7 +306,7 @@ struct kmem_list3 {
84025 * Need this for bootstrapping a per node allocator.
84026 */
84027 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
84028-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
84029+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
84030 #define CACHE_CACHE 0
84031 #define SIZE_AC MAX_NUMNODES
84032 #define SIZE_L3 (2 * MAX_NUMNODES)
84033@@ -407,10 +407,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
84034 if ((x)->max_freeable < i) \
84035 (x)->max_freeable = i; \
84036 } while (0)
84037-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
84038-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
84039-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
84040-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
84041+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
84042+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
84043+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
84044+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
84045 #else
84046 #define STATS_INC_ACTIVE(x) do { } while (0)
84047 #define STATS_DEC_ACTIVE(x) do { } while (0)
84048@@ -518,7 +518,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
84049 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
84050 */
84051 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
84052- const struct slab *slab, void *obj)
84053+ const struct slab *slab, const void *obj)
84054 {
84055 u32 offset = (obj - slab->s_mem);
84056 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
84057@@ -539,12 +539,13 @@ EXPORT_SYMBOL(malloc_sizes);
84058 struct cache_names {
84059 char *name;
84060 char *name_dma;
84061+ char *name_usercopy;
84062 };
84063
84064 static struct cache_names __initdata cache_names[] = {
84065-#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
84066+#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
84067 #include <linux/kmalloc_sizes.h>
84068- {NULL,}
84069+ {NULL}
84070 #undef CACHE
84071 };
84072
84073@@ -729,6 +730,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
84074 if (unlikely(gfpflags & GFP_DMA))
84075 return csizep->cs_dmacachep;
84076 #endif
84077+
84078+#ifdef CONFIG_PAX_USERCOPY_SLABS
84079+ if (unlikely(gfpflags & GFP_USERCOPY))
84080+ return csizep->cs_usercopycachep;
84081+#endif
84082+
84083 return csizep->cs_cachep;
84084 }
84085
84086@@ -1482,7 +1489,7 @@ static int __cpuinit cpuup_callback(struct notifier_block *nfb,
84087 return notifier_from_errno(err);
84088 }
84089
84090-static struct notifier_block __cpuinitdata cpucache_notifier = {
84091+static struct notifier_block cpucache_notifier = {
84092 &cpuup_callback, NULL, 0
84093 };
84094
84095@@ -1667,12 +1674,12 @@ void __init kmem_cache_init(void)
84096 */
84097
84098 sizes[INDEX_AC].cs_cachep = create_kmalloc_cache(names[INDEX_AC].name,
84099- sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS);
84100+ sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
84101
84102 if (INDEX_AC != INDEX_L3)
84103 sizes[INDEX_L3].cs_cachep =
84104 create_kmalloc_cache(names[INDEX_L3].name,
84105- sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS);
84106+ sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
84107
84108 slab_early_init = 0;
84109
84110@@ -1686,13 +1693,20 @@ void __init kmem_cache_init(void)
84111 */
84112 if (!sizes->cs_cachep)
84113 sizes->cs_cachep = create_kmalloc_cache(names->name,
84114- sizes->cs_size, ARCH_KMALLOC_FLAGS);
84115+ sizes->cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
84116
84117 #ifdef CONFIG_ZONE_DMA
84118 sizes->cs_dmacachep = create_kmalloc_cache(
84119 names->name_dma, sizes->cs_size,
84120 SLAB_CACHE_DMA|ARCH_KMALLOC_FLAGS);
84121 #endif
84122+
84123+#ifdef CONFIG_PAX_USERCOPY_SLABS
84124+ sizes->cs_usercopycachep = create_kmalloc_cache(
84125+ names->name_usercopy, sizes->cs_size,
84126+ ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
84127+#endif
84128+
84129 sizes++;
84130 names++;
84131 }
84132@@ -3924,6 +3938,7 @@ void kfree(const void *objp)
84133
84134 if (unlikely(ZERO_OR_NULL_PTR(objp)))
84135 return;
84136+ VM_BUG_ON(!virt_addr_valid(objp));
84137 local_irq_save(flags);
84138 kfree_debugcheck(objp);
84139 c = virt_to_cache(objp);
84140@@ -4365,10 +4380,10 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
84141 }
84142 /* cpu stats */
84143 {
84144- unsigned long allochit = atomic_read(&cachep->allochit);
84145- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
84146- unsigned long freehit = atomic_read(&cachep->freehit);
84147- unsigned long freemiss = atomic_read(&cachep->freemiss);
84148+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
84149+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
84150+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
84151+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
84152
84153 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
84154 allochit, allocmiss, freehit, freemiss);
84155@@ -4600,13 +4615,71 @@ static const struct file_operations proc_slabstats_operations = {
84156 static int __init slab_proc_init(void)
84157 {
84158 #ifdef CONFIG_DEBUG_SLAB_LEAK
84159- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
84160+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
84161 #endif
84162 return 0;
84163 }
84164 module_init(slab_proc_init);
84165 #endif
84166
84167+bool is_usercopy_object(const void *ptr)
84168+{
84169+ struct page *page;
84170+ struct kmem_cache *cachep;
84171+
84172+ if (ZERO_OR_NULL_PTR(ptr))
84173+ return false;
84174+
84175+ if (!slab_is_available())
84176+ return false;
84177+
84178+ if (!virt_addr_valid(ptr))
84179+ return false;
84180+
84181+ page = virt_to_head_page(ptr);
84182+
84183+ if (!PageSlab(page))
84184+ return false;
84185+
84186+ cachep = page->slab_cache;
84187+ return cachep->flags & SLAB_USERCOPY;
84188+}
84189+
84190+#ifdef CONFIG_PAX_USERCOPY
84191+const char *check_heap_object(const void *ptr, unsigned long n)
84192+{
84193+ struct page *page;
84194+ struct kmem_cache *cachep;
84195+ struct slab *slabp;
84196+ unsigned int objnr;
84197+ unsigned long offset;
84198+
84199+ if (ZERO_OR_NULL_PTR(ptr))
84200+ return "<null>";
84201+
84202+ if (!virt_addr_valid(ptr))
84203+ return NULL;
84204+
84205+ page = virt_to_head_page(ptr);
84206+
84207+ if (!PageSlab(page))
84208+ return NULL;
84209+
84210+ cachep = page->slab_cache;
84211+ if (!(cachep->flags & SLAB_USERCOPY))
84212+ return cachep->name;
84213+
84214+ slabp = page->slab_page;
84215+ objnr = obj_to_index(cachep, slabp, ptr);
84216+ BUG_ON(objnr >= cachep->num);
84217+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
84218+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
84219+ return NULL;
84220+
84221+ return cachep->name;
84222+}
84223+#endif
84224+
84225 /**
84226 * ksize - get the actual amount of memory allocated for a given object
84227 * @objp: Pointer to the object
84228diff --git a/mm/slab.h b/mm/slab.h
84229index 34a98d6..73633d1 100644
84230--- a/mm/slab.h
84231+++ b/mm/slab.h
84232@@ -58,7 +58,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
84233
84234 /* Legal flag mask for kmem_cache_create(), for various configurations */
84235 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
84236- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
84237+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | SLAB_USERCOPY)
84238
84239 #if defined(CONFIG_DEBUG_SLAB)
84240 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
84241@@ -220,6 +220,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
84242 return s;
84243
84244 page = virt_to_head_page(x);
84245+
84246+ BUG_ON(!PageSlab(page));
84247+
84248 cachep = page->slab_cache;
84249 if (slab_equal_or_root(cachep, s))
84250 return cachep;
84251diff --git a/mm/slab_common.c b/mm/slab_common.c
84252index 3f3cd97..93b0236 100644
84253--- a/mm/slab_common.c
84254+++ b/mm/slab_common.c
84255@@ -22,7 +22,7 @@
84256
84257 #include "slab.h"
84258
84259-enum slab_state slab_state;
84260+enum slab_state slab_state __read_only;
84261 LIST_HEAD(slab_caches);
84262 DEFINE_MUTEX(slab_mutex);
84263 struct kmem_cache *kmem_cache;
84264@@ -209,7 +209,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
84265
84266 err = __kmem_cache_create(s, flags);
84267 if (!err) {
84268- s->refcount = 1;
84269+ atomic_set(&s->refcount, 1);
84270 list_add(&s->list, &slab_caches);
84271 memcg_cache_list_add(memcg, s);
84272 } else {
84273@@ -255,8 +255,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
84274
84275 get_online_cpus();
84276 mutex_lock(&slab_mutex);
84277- s->refcount--;
84278- if (!s->refcount) {
84279+ if (atomic_dec_and_test(&s->refcount)) {
84280 list_del(&s->list);
84281
84282 if (!__kmem_cache_shutdown(s)) {
84283@@ -302,7 +301,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
84284 panic("Creation of kmalloc slab %s size=%zd failed. Reason %d\n",
84285 name, size, err);
84286
84287- s->refcount = -1; /* Exempt from merging for now */
84288+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
84289 }
84290
84291 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
84292@@ -315,7 +314,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
84293
84294 create_boot_cache(s, name, size, flags);
84295 list_add(&s->list, &slab_caches);
84296- s->refcount = 1;
84297+ atomic_set(&s->refcount, 1);
84298 return s;
84299 }
84300
84301diff --git a/mm/slob.c b/mm/slob.c
84302index a99fdf7..6ee34ec 100644
84303--- a/mm/slob.c
84304+++ b/mm/slob.c
84305@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
84306 /*
84307 * Return the size of a slob block.
84308 */
84309-static slobidx_t slob_units(slob_t *s)
84310+static slobidx_t slob_units(const slob_t *s)
84311 {
84312 if (s->units > 0)
84313 return s->units;
84314@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
84315 /*
84316 * Return the next free slob block pointer after this one.
84317 */
84318-static slob_t *slob_next(slob_t *s)
84319+static slob_t *slob_next(const slob_t *s)
84320 {
84321 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
84322 slobidx_t next;
84323@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
84324 /*
84325 * Returns true if s is the last free block in its page.
84326 */
84327-static int slob_last(slob_t *s)
84328+static int slob_last(const slob_t *s)
84329 {
84330 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
84331 }
84332
84333-static void *slob_new_pages(gfp_t gfp, int order, int node)
84334+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
84335 {
84336- void *page;
84337+ struct page *page;
84338
84339 #ifdef CONFIG_NUMA
84340 if (node != NUMA_NO_NODE)
84341@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
84342 if (!page)
84343 return NULL;
84344
84345- return page_address(page);
84346+ __SetPageSlab(page);
84347+ return page;
84348 }
84349
84350-static void slob_free_pages(void *b, int order)
84351+static void slob_free_pages(struct page *sp, int order)
84352 {
84353 if (current->reclaim_state)
84354 current->reclaim_state->reclaimed_slab += 1 << order;
84355- free_pages((unsigned long)b, order);
84356+ __ClearPageSlab(sp);
84357+ reset_page_mapcount(sp);
84358+ sp->private = 0;
84359+ __free_pages(sp, order);
84360 }
84361
84362 /*
84363@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
84364
84365 /* Not enough space: must allocate a new page */
84366 if (!b) {
84367- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
84368- if (!b)
84369+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
84370+ if (!sp)
84371 return NULL;
84372- sp = virt_to_page(b);
84373- __SetPageSlab(sp);
84374+ b = page_address(sp);
84375
84376 spin_lock_irqsave(&slob_lock, flags);
84377 sp->units = SLOB_UNITS(PAGE_SIZE);
84378 sp->freelist = b;
84379+ sp->private = 0;
84380 INIT_LIST_HEAD(&sp->list);
84381 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
84382 set_slob_page_free(sp, slob_list);
84383@@ -359,9 +363,7 @@ static void slob_free(void *block, int size)
84384 if (slob_page_free(sp))
84385 clear_slob_page_free(sp);
84386 spin_unlock_irqrestore(&slob_lock, flags);
84387- __ClearPageSlab(sp);
84388- reset_page_mapcount(sp);
84389- slob_free_pages(b, 0);
84390+ slob_free_pages(sp, 0);
84391 return;
84392 }
84393
84394@@ -424,11 +426,10 @@ out:
84395 */
84396
84397 static __always_inline void *
84398-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
84399+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
84400 {
84401- unsigned int *m;
84402- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
84403- void *ret;
84404+ slob_t *m;
84405+ void *ret = NULL;
84406
84407 gfp &= gfp_allowed_mask;
84408
84409@@ -442,23 +443,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
84410
84411 if (!m)
84412 return NULL;
84413- *m = size;
84414+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
84415+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
84416+ m[0].units = size;
84417+ m[1].units = align;
84418 ret = (void *)m + align;
84419
84420 trace_kmalloc_node(caller, ret,
84421 size, size + align, gfp, node);
84422 } else {
84423 unsigned int order = get_order(size);
84424+ struct page *page;
84425
84426 if (likely(order))
84427 gfp |= __GFP_COMP;
84428- ret = slob_new_pages(gfp, order, node);
84429+ page = slob_new_pages(gfp, order, node);
84430+ if (page) {
84431+ ret = page_address(page);
84432+ page->private = size;
84433+ }
84434
84435 trace_kmalloc_node(caller, ret,
84436 size, PAGE_SIZE << order, gfp, node);
84437 }
84438
84439- kmemleak_alloc(ret, size, 1, gfp);
84440+ return ret;
84441+}
84442+
84443+static __always_inline void *
84444+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
84445+{
84446+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
84447+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
84448+
84449+ if (!ZERO_OR_NULL_PTR(ret))
84450+ kmemleak_alloc(ret, size, 1, gfp);
84451 return ret;
84452 }
84453
84454@@ -493,34 +512,112 @@ void kfree(const void *block)
84455 return;
84456 kmemleak_free(block);
84457
84458+ VM_BUG_ON(!virt_addr_valid(block));
84459 sp = virt_to_page(block);
84460- if (PageSlab(sp)) {
84461+ VM_BUG_ON(!PageSlab(sp));
84462+ if (!sp->private) {
84463 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
84464- unsigned int *m = (unsigned int *)(block - align);
84465- slob_free(m, *m + align);
84466- } else
84467+ slob_t *m = (slob_t *)(block - align);
84468+ slob_free(m, m[0].units + align);
84469+ } else {
84470+ __ClearPageSlab(sp);
84471+ reset_page_mapcount(sp);
84472+ sp->private = 0;
84473 __free_pages(sp, compound_order(sp));
84474+ }
84475 }
84476 EXPORT_SYMBOL(kfree);
84477
84478+bool is_usercopy_object(const void *ptr)
84479+{
84480+ if (!slab_is_available())
84481+ return false;
84482+
84483+ // PAX: TODO
84484+
84485+ return false;
84486+}
84487+
84488+#ifdef CONFIG_PAX_USERCOPY
84489+const char *check_heap_object(const void *ptr, unsigned long n)
84490+{
84491+ struct page *page;
84492+ const slob_t *free;
84493+ const void *base;
84494+ unsigned long flags;
84495+
84496+ if (ZERO_OR_NULL_PTR(ptr))
84497+ return "<null>";
84498+
84499+ if (!virt_addr_valid(ptr))
84500+ return NULL;
84501+
84502+ page = virt_to_head_page(ptr);
84503+ if (!PageSlab(page))
84504+ return NULL;
84505+
84506+ if (page->private) {
84507+ base = page;
84508+ if (base <= ptr && n <= page->private - (ptr - base))
84509+ return NULL;
84510+ return "<slob>";
84511+ }
84512+
84513+ /* some tricky double walking to find the chunk */
84514+ spin_lock_irqsave(&slob_lock, flags);
84515+ base = (void *)((unsigned long)ptr & PAGE_MASK);
84516+ free = page->freelist;
84517+
84518+ while (!slob_last(free) && (void *)free <= ptr) {
84519+ base = free + slob_units(free);
84520+ free = slob_next(free);
84521+ }
84522+
84523+ while (base < (void *)free) {
84524+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
84525+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
84526+ int offset;
84527+
84528+ if (ptr < base + align)
84529+ break;
84530+
84531+ offset = ptr - base - align;
84532+ if (offset >= m) {
84533+ base += size;
84534+ continue;
84535+ }
84536+
84537+ if (n > m - offset)
84538+ break;
84539+
84540+ spin_unlock_irqrestore(&slob_lock, flags);
84541+ return NULL;
84542+ }
84543+
84544+ spin_unlock_irqrestore(&slob_lock, flags);
84545+ return "<slob>";
84546+}
84547+#endif
84548+
84549 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
84550 size_t ksize(const void *block)
84551 {
84552 struct page *sp;
84553 int align;
84554- unsigned int *m;
84555+ slob_t *m;
84556
84557 BUG_ON(!block);
84558 if (unlikely(block == ZERO_SIZE_PTR))
84559 return 0;
84560
84561 sp = virt_to_page(block);
84562- if (unlikely(!PageSlab(sp)))
84563- return PAGE_SIZE << compound_order(sp);
84564+ VM_BUG_ON(!PageSlab(sp));
84565+ if (sp->private)
84566+ return sp->private;
84567
84568 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
84569- m = (unsigned int *)(block - align);
84570- return SLOB_UNITS(*m) * SLOB_UNIT;
84571+ m = (slob_t *)(block - align);
84572+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
84573 }
84574 EXPORT_SYMBOL(ksize);
84575
84576@@ -536,23 +633,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
84577
84578 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
84579 {
84580- void *b;
84581+ void *b = NULL;
84582
84583 flags &= gfp_allowed_mask;
84584
84585 lockdep_trace_alloc(flags);
84586
84587+#ifdef CONFIG_PAX_USERCOPY_SLABS
84588+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
84589+#else
84590 if (c->size < PAGE_SIZE) {
84591 b = slob_alloc(c->size, flags, c->align, node);
84592 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
84593 SLOB_UNITS(c->size) * SLOB_UNIT,
84594 flags, node);
84595 } else {
84596- b = slob_new_pages(flags, get_order(c->size), node);
84597+ struct page *sp;
84598+
84599+ sp = slob_new_pages(flags, get_order(c->size), node);
84600+ if (sp) {
84601+ b = page_address(sp);
84602+ sp->private = c->size;
84603+ }
84604 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
84605 PAGE_SIZE << get_order(c->size),
84606 flags, node);
84607 }
84608+#endif
84609
84610 if (c->ctor)
84611 c->ctor(b);
84612@@ -564,10 +671,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
84613
84614 static void __kmem_cache_free(void *b, int size)
84615 {
84616- if (size < PAGE_SIZE)
84617+ struct page *sp;
84618+
84619+ sp = virt_to_page(b);
84620+ BUG_ON(!PageSlab(sp));
84621+ if (!sp->private)
84622 slob_free(b, size);
84623 else
84624- slob_free_pages(b, get_order(size));
84625+ slob_free_pages(sp, get_order(size));
84626 }
84627
84628 static void kmem_rcu_free(struct rcu_head *head)
84629@@ -580,17 +691,31 @@ static void kmem_rcu_free(struct rcu_head *head)
84630
84631 void kmem_cache_free(struct kmem_cache *c, void *b)
84632 {
84633+ int size = c->size;
84634+
84635+#ifdef CONFIG_PAX_USERCOPY_SLABS
84636+ if (size + c->align < PAGE_SIZE) {
84637+ size += c->align;
84638+ b -= c->align;
84639+ }
84640+#endif
84641+
84642 kmemleak_free_recursive(b, c->flags);
84643 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
84644 struct slob_rcu *slob_rcu;
84645- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
84646- slob_rcu->size = c->size;
84647+ slob_rcu = b + (size - sizeof(struct slob_rcu));
84648+ slob_rcu->size = size;
84649 call_rcu(&slob_rcu->head, kmem_rcu_free);
84650 } else {
84651- __kmem_cache_free(b, c->size);
84652+ __kmem_cache_free(b, size);
84653 }
84654
84655+#ifdef CONFIG_PAX_USERCOPY_SLABS
84656+ trace_kfree(_RET_IP_, b);
84657+#else
84658 trace_kmem_cache_free(_RET_IP_, b);
84659+#endif
84660+
84661 }
84662 EXPORT_SYMBOL(kmem_cache_free);
84663
84664diff --git a/mm/slub.c b/mm/slub.c
84665index ba2ca53..991c4f7 100644
84666--- a/mm/slub.c
84667+++ b/mm/slub.c
84668@@ -197,7 +197,7 @@ struct track {
84669
84670 enum track_item { TRACK_ALLOC, TRACK_FREE };
84671
84672-#ifdef CONFIG_SYSFS
84673+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
84674 static int sysfs_slab_add(struct kmem_cache *);
84675 static int sysfs_slab_alias(struct kmem_cache *, const char *);
84676 static void sysfs_slab_remove(struct kmem_cache *);
84677@@ -518,7 +518,7 @@ static void print_track(const char *s, struct track *t)
84678 if (!t->addr)
84679 return;
84680
84681- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
84682+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
84683 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
84684 #ifdef CONFIG_STACKTRACE
84685 {
84686@@ -2653,7 +2653,7 @@ static int slub_min_objects;
84687 * Merge control. If this is set then no merging of slab caches will occur.
84688 * (Could be removed. This was introduced to pacify the merge skeptics.)
84689 */
84690-static int slub_nomerge;
84691+static int slub_nomerge = 1;
84692
84693 /*
84694 * Calculate the order of allocation given an slab object size.
84695@@ -3181,6 +3181,10 @@ EXPORT_SYMBOL(kmalloc_caches);
84696 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
84697 #endif
84698
84699+#ifdef CONFIG_PAX_USERCOPY_SLABS
84700+static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
84701+#endif
84702+
84703 static int __init setup_slub_min_order(char *str)
84704 {
84705 get_option(&str, &slub_min_order);
84706@@ -3272,6 +3276,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
84707 return kmalloc_dma_caches[index];
84708
84709 #endif
84710+
84711+#ifdef CONFIG_PAX_USERCOPY_SLABS
84712+ if (flags & SLAB_USERCOPY)
84713+ return kmalloc_usercopy_caches[index];
84714+
84715+#endif
84716+
84717 return kmalloc_caches[index];
84718 }
84719
84720@@ -3340,6 +3351,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
84721 EXPORT_SYMBOL(__kmalloc_node);
84722 #endif
84723
84724+bool is_usercopy_object(const void *ptr)
84725+{
84726+ struct page *page;
84727+ struct kmem_cache *s;
84728+
84729+ if (ZERO_OR_NULL_PTR(ptr))
84730+ return false;
84731+
84732+ if (!slab_is_available())
84733+ return false;
84734+
84735+ if (!virt_addr_valid(ptr))
84736+ return false;
84737+
84738+ page = virt_to_head_page(ptr);
84739+
84740+ if (!PageSlab(page))
84741+ return false;
84742+
84743+ s = page->slab_cache;
84744+ return s->flags & SLAB_USERCOPY;
84745+}
84746+
84747+#ifdef CONFIG_PAX_USERCOPY
84748+const char *check_heap_object(const void *ptr, unsigned long n)
84749+{
84750+ struct page *page;
84751+ struct kmem_cache *s;
84752+ unsigned long offset;
84753+
84754+ if (ZERO_OR_NULL_PTR(ptr))
84755+ return "<null>";
84756+
84757+ if (!virt_addr_valid(ptr))
84758+ return NULL;
84759+
84760+ page = virt_to_head_page(ptr);
84761+
84762+ if (!PageSlab(page))
84763+ return NULL;
84764+
84765+ s = page->slab_cache;
84766+ if (!(s->flags & SLAB_USERCOPY))
84767+ return s->name;
84768+
84769+ offset = (ptr - page_address(page)) % s->size;
84770+ if (offset <= s->object_size && n <= s->object_size - offset)
84771+ return NULL;
84772+
84773+ return s->name;
84774+}
84775+#endif
84776+
84777 size_t ksize(const void *object)
84778 {
84779 struct page *page;
84780@@ -3404,6 +3468,7 @@ void kfree(const void *x)
84781 if (unlikely(ZERO_OR_NULL_PTR(x)))
84782 return;
84783
84784+ VM_BUG_ON(!virt_addr_valid(x));
84785 page = virt_to_head_page(x);
84786 if (unlikely(!PageSlab(page))) {
84787 BUG_ON(!PageCompound(page));
84788@@ -3712,17 +3777,17 @@ void __init kmem_cache_init(void)
84789
84790 /* Caches that are not of the two-to-the-power-of size */
84791 if (KMALLOC_MIN_SIZE <= 32) {
84792- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
84793+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
84794 caches++;
84795 }
84796
84797 if (KMALLOC_MIN_SIZE <= 64) {
84798- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
84799+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
84800 caches++;
84801 }
84802
84803 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
84804- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
84805+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
84806 caches++;
84807 }
84808
84809@@ -3764,6 +3829,22 @@ void __init kmem_cache_init(void)
84810 }
84811 }
84812 #endif
84813+
84814+#ifdef CONFIG_PAX_USERCOPY_SLABS
84815+ for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
84816+ struct kmem_cache *s = kmalloc_caches[i];
84817+
84818+ if (s && s->size) {
84819+ char *name = kasprintf(GFP_NOWAIT,
84820+ "usercopy-kmalloc-%d", s->object_size);
84821+
84822+ BUG_ON(!name);
84823+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
84824+ s->object_size, SLAB_USERCOPY);
84825+ }
84826+ }
84827+#endif
84828+
84829 printk(KERN_INFO
84830 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
84831 " CPUs=%d, Nodes=%d\n",
84832@@ -3790,7 +3871,7 @@ static int slab_unmergeable(struct kmem_cache *s)
84833 /*
84834 * We may have set a slab to be unmergeable during bootstrap.
84835 */
84836- if (s->refcount < 0)
84837+ if (atomic_read(&s->refcount) < 0)
84838 return 1;
84839
84840 return 0;
84841@@ -3848,7 +3929,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
84842
84843 s = find_mergeable(memcg, size, align, flags, name, ctor);
84844 if (s) {
84845- s->refcount++;
84846+ atomic_inc(&s->refcount);
84847 /*
84848 * Adjust the object sizes so that we clear
84849 * the complete object on kzalloc.
84850@@ -3857,7 +3938,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
84851 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
84852
84853 if (sysfs_slab_alias(s, name)) {
84854- s->refcount--;
84855+ atomic_dec(&s->refcount);
84856 s = NULL;
84857 }
84858 }
84859@@ -3919,7 +4000,7 @@ static int __cpuinit slab_cpuup_callback(struct notifier_block *nfb,
84860 return NOTIFY_OK;
84861 }
84862
84863-static struct notifier_block __cpuinitdata slab_notifier = {
84864+static struct notifier_block slab_notifier = {
84865 .notifier_call = slab_cpuup_callback
84866 };
84867
84868@@ -3977,7 +4058,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
84869 }
84870 #endif
84871
84872-#ifdef CONFIG_SYSFS
84873+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
84874 static int count_inuse(struct page *page)
84875 {
84876 return page->inuse;
84877@@ -4364,12 +4445,12 @@ static void resiliency_test(void)
84878 validate_slab_cache(kmalloc_caches[9]);
84879 }
84880 #else
84881-#ifdef CONFIG_SYSFS
84882+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
84883 static void resiliency_test(void) {};
84884 #endif
84885 #endif
84886
84887-#ifdef CONFIG_SYSFS
84888+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
84889 enum slab_stat_type {
84890 SL_ALL, /* All slabs */
84891 SL_PARTIAL, /* Only partially allocated slabs */
84892@@ -4613,7 +4694,7 @@ SLAB_ATTR_RO(ctor);
84893
84894 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
84895 {
84896- return sprintf(buf, "%d\n", s->refcount - 1);
84897+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
84898 }
84899 SLAB_ATTR_RO(aliases);
84900
84901@@ -5266,6 +5347,7 @@ static char *create_unique_id(struct kmem_cache *s)
84902 return name;
84903 }
84904
84905+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
84906 static int sysfs_slab_add(struct kmem_cache *s)
84907 {
84908 int err;
84909@@ -5323,6 +5405,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
84910 kobject_del(&s->kobj);
84911 kobject_put(&s->kobj);
84912 }
84913+#endif
84914
84915 /*
84916 * Need to buffer aliases during bootup until sysfs becomes
84917@@ -5336,6 +5419,7 @@ struct saved_alias {
84918
84919 static struct saved_alias *alias_list;
84920
84921+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
84922 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
84923 {
84924 struct saved_alias *al;
84925@@ -5358,6 +5442,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
84926 alias_list = al;
84927 return 0;
84928 }
84929+#endif
84930
84931 static int __init slab_sysfs_init(void)
84932 {
84933diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
84934index 1b7e22a..3fcd4f3 100644
84935--- a/mm/sparse-vmemmap.c
84936+++ b/mm/sparse-vmemmap.c
84937@@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
84938 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
84939 if (!p)
84940 return NULL;
84941- pud_populate(&init_mm, pud, p);
84942+ pud_populate_kernel(&init_mm, pud, p);
84943 }
84944 return pud;
84945 }
84946@@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
84947 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
84948 if (!p)
84949 return NULL;
84950- pgd_populate(&init_mm, pgd, p);
84951+ pgd_populate_kernel(&init_mm, pgd, p);
84952 }
84953 return pgd;
84954 }
84955diff --git a/mm/sparse.c b/mm/sparse.c
84956index 6b5fb76..db0c190 100644
84957--- a/mm/sparse.c
84958+++ b/mm/sparse.c
84959@@ -782,7 +782,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
84960
84961 for (i = 0; i < PAGES_PER_SECTION; i++) {
84962 if (PageHWPoison(&memmap[i])) {
84963- atomic_long_sub(1, &mce_bad_pages);
84964+ atomic_long_sub_unchecked(1, &mce_bad_pages);
84965 ClearPageHWPoison(&memmap[i]);
84966 }
84967 }
84968diff --git a/mm/swap.c b/mm/swap.c
84969index 6310dc2..3662b3f 100644
84970--- a/mm/swap.c
84971+++ b/mm/swap.c
84972@@ -30,6 +30,7 @@
84973 #include <linux/backing-dev.h>
84974 #include <linux/memcontrol.h>
84975 #include <linux/gfp.h>
84976+#include <linux/hugetlb.h>
84977
84978 #include "internal.h"
84979
84980@@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
84981
84982 __page_cache_release(page);
84983 dtor = get_compound_page_dtor(page);
84984+ if (!PageHuge(page))
84985+ BUG_ON(dtor != free_compound_page);
84986 (*dtor)(page);
84987 }
84988
84989diff --git a/mm/swapfile.c b/mm/swapfile.c
84990index e97a0e5..b50e796 100644
84991--- a/mm/swapfile.c
84992+++ b/mm/swapfile.c
84993@@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
84994
84995 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
84996 /* Activity counter to indicate that a swapon or swapoff has occurred */
84997-static atomic_t proc_poll_event = ATOMIC_INIT(0);
84998+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
84999
85000 static inline unsigned char swap_count(unsigned char ent)
85001 {
85002@@ -1608,7 +1608,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
85003 }
85004 filp_close(swap_file, NULL);
85005 err = 0;
85006- atomic_inc(&proc_poll_event);
85007+ atomic_inc_unchecked(&proc_poll_event);
85008 wake_up_interruptible(&proc_poll_wait);
85009
85010 out_dput:
85011@@ -1625,8 +1625,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
85012
85013 poll_wait(file, &proc_poll_wait, wait);
85014
85015- if (seq->poll_event != atomic_read(&proc_poll_event)) {
85016- seq->poll_event = atomic_read(&proc_poll_event);
85017+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
85018+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
85019 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
85020 }
85021
85022@@ -1724,7 +1724,7 @@ static int swaps_open(struct inode *inode, struct file *file)
85023 return ret;
85024
85025 seq = file->private_data;
85026- seq->poll_event = atomic_read(&proc_poll_event);
85027+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
85028 return 0;
85029 }
85030
85031@@ -2066,7 +2066,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
85032 (frontswap_map) ? "FS" : "");
85033
85034 mutex_unlock(&swapon_mutex);
85035- atomic_inc(&proc_poll_event);
85036+ atomic_inc_unchecked(&proc_poll_event);
85037 wake_up_interruptible(&proc_poll_wait);
85038
85039 if (S_ISREG(inode->i_mode))
85040diff --git a/mm/util.c b/mm/util.c
85041index c55e26b..3f913a9 100644
85042--- a/mm/util.c
85043+++ b/mm/util.c
85044@@ -292,6 +292,12 @@ done:
85045 void arch_pick_mmap_layout(struct mm_struct *mm)
85046 {
85047 mm->mmap_base = TASK_UNMAPPED_BASE;
85048+
85049+#ifdef CONFIG_PAX_RANDMMAP
85050+ if (mm->pax_flags & MF_PAX_RANDMMAP)
85051+ mm->mmap_base += mm->delta_mmap;
85052+#endif
85053+
85054 mm->get_unmapped_area = arch_get_unmapped_area;
85055 mm->unmap_area = arch_unmap_area;
85056 }
85057diff --git a/mm/vmalloc.c b/mm/vmalloc.c
85058index 5123a16..f234a48 100644
85059--- a/mm/vmalloc.c
85060+++ b/mm/vmalloc.c
85061@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
85062
85063 pte = pte_offset_kernel(pmd, addr);
85064 do {
85065- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
85066- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
85067+
85068+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85069+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
85070+ BUG_ON(!pte_exec(*pte));
85071+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
85072+ continue;
85073+ }
85074+#endif
85075+
85076+ {
85077+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
85078+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
85079+ }
85080 } while (pte++, addr += PAGE_SIZE, addr != end);
85081 }
85082
85083@@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
85084 pte = pte_alloc_kernel(pmd, addr);
85085 if (!pte)
85086 return -ENOMEM;
85087+
85088+ pax_open_kernel();
85089 do {
85090 struct page *page = pages[*nr];
85091
85092- if (WARN_ON(!pte_none(*pte)))
85093+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85094+ if (pgprot_val(prot) & _PAGE_NX)
85095+#endif
85096+
85097+ if (!pte_none(*pte)) {
85098+ pax_close_kernel();
85099+ WARN_ON(1);
85100 return -EBUSY;
85101- if (WARN_ON(!page))
85102+ }
85103+ if (!page) {
85104+ pax_close_kernel();
85105+ WARN_ON(1);
85106 return -ENOMEM;
85107+ }
85108 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
85109 (*nr)++;
85110 } while (pte++, addr += PAGE_SIZE, addr != end);
85111+ pax_close_kernel();
85112 return 0;
85113 }
85114
85115@@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
85116 pmd_t *pmd;
85117 unsigned long next;
85118
85119- pmd = pmd_alloc(&init_mm, pud, addr);
85120+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
85121 if (!pmd)
85122 return -ENOMEM;
85123 do {
85124@@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
85125 pud_t *pud;
85126 unsigned long next;
85127
85128- pud = pud_alloc(&init_mm, pgd, addr);
85129+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
85130 if (!pud)
85131 return -ENOMEM;
85132 do {
85133@@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
85134 * and fall back on vmalloc() if that fails. Others
85135 * just put it in the vmalloc space.
85136 */
85137-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
85138+#ifdef CONFIG_MODULES
85139+#ifdef MODULES_VADDR
85140 unsigned long addr = (unsigned long)x;
85141 if (addr >= MODULES_VADDR && addr < MODULES_END)
85142 return 1;
85143 #endif
85144+
85145+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85146+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
85147+ return 1;
85148+#endif
85149+
85150+#endif
85151+
85152 return is_vmalloc_addr(x);
85153 }
85154
85155@@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
85156
85157 if (!pgd_none(*pgd)) {
85158 pud_t *pud = pud_offset(pgd, addr);
85159+#ifdef CONFIG_X86
85160+ if (!pud_large(*pud))
85161+#endif
85162 if (!pud_none(*pud)) {
85163 pmd_t *pmd = pmd_offset(pud, addr);
85164+#ifdef CONFIG_X86
85165+ if (!pmd_large(*pmd))
85166+#endif
85167 if (!pmd_none(*pmd)) {
85168 pte_t *ptep, pte;
85169
85170@@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
85171 * Allocate a region of KVA of the specified size and alignment, within the
85172 * vstart and vend.
85173 */
85174-static struct vmap_area *alloc_vmap_area(unsigned long size,
85175+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
85176 unsigned long align,
85177 unsigned long vstart, unsigned long vend,
85178 int node, gfp_t gfp_mask)
85179@@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
85180 struct vm_struct *area;
85181
85182 BUG_ON(in_interrupt());
85183+
85184+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
85185+ if (flags & VM_KERNEXEC) {
85186+ if (start != VMALLOC_START || end != VMALLOC_END)
85187+ return NULL;
85188+ start = (unsigned long)MODULES_EXEC_VADDR;
85189+ end = (unsigned long)MODULES_EXEC_END;
85190+ }
85191+#endif
85192+
85193 if (flags & VM_IOREMAP) {
85194 int bit = fls(size);
85195
85196@@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
85197 if (count > totalram_pages)
85198 return NULL;
85199
85200+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
85201+ if (!(pgprot_val(prot) & _PAGE_NX))
85202+ flags |= VM_KERNEXEC;
85203+#endif
85204+
85205 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
85206 __builtin_return_address(0));
85207 if (!area)
85208@@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
85209 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
85210 goto fail;
85211
85212+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
85213+ if (!(pgprot_val(prot) & _PAGE_NX))
85214+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
85215+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
85216+ else
85217+#endif
85218+
85219 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
85220 start, end, node, gfp_mask, caller);
85221 if (!area)
85222@@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
85223 * For tight control over page level allocator and protection flags
85224 * use __vmalloc() instead.
85225 */
85226-
85227 void *vmalloc_exec(unsigned long size)
85228 {
85229- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
85230+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
85231 -1, __builtin_return_address(0));
85232 }
85233
85234@@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
85235 unsigned long uaddr = vma->vm_start;
85236 unsigned long usize = vma->vm_end - vma->vm_start;
85237
85238+ BUG_ON(vma->vm_mirror);
85239+
85240 if ((PAGE_SIZE-1) & (unsigned long)addr)
85241 return -EINVAL;
85242
85243@@ -2575,7 +2637,11 @@ static int s_show(struct seq_file *m, void *p)
85244 v->addr, v->addr + v->size, v->size);
85245
85246 if (v->caller)
85247+#ifdef CONFIG_GRKERNSEC_HIDESYM
85248+ seq_printf(m, " %pK", v->caller);
85249+#else
85250 seq_printf(m, " %pS", v->caller);
85251+#endif
85252
85253 if (v->nr_pages)
85254 seq_printf(m, " pages=%d", v->nr_pages);
85255diff --git a/mm/vmstat.c b/mm/vmstat.c
85256index 9800306..76b4b27 100644
85257--- a/mm/vmstat.c
85258+++ b/mm/vmstat.c
85259@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
85260 *
85261 * vm_stat contains the global counters
85262 */
85263-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
85264+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
85265 EXPORT_SYMBOL(vm_stat);
85266
85267 #ifdef CONFIG_SMP
85268@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
85269 v = p->vm_stat_diff[i];
85270 p->vm_stat_diff[i] = 0;
85271 local_irq_restore(flags);
85272- atomic_long_add(v, &zone->vm_stat[i]);
85273+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
85274 global_diff[i] += v;
85275 #ifdef CONFIG_NUMA
85276 /* 3 seconds idle till flush */
85277@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
85278
85279 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
85280 if (global_diff[i])
85281- atomic_long_add(global_diff[i], &vm_stat[i]);
85282+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
85283 }
85284
85285 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
85286@@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
85287 if (pset->vm_stat_diff[i]) {
85288 int v = pset->vm_stat_diff[i];
85289 pset->vm_stat_diff[i] = 0;
85290- atomic_long_add(v, &zone->vm_stat[i]);
85291- atomic_long_add(v, &vm_stat[i]);
85292+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
85293+ atomic_long_add_unchecked(v, &vm_stat[i]);
85294 }
85295 }
85296 #endif
85297@@ -1223,7 +1223,7 @@ static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb,
85298 return NOTIFY_OK;
85299 }
85300
85301-static struct notifier_block __cpuinitdata vmstat_notifier =
85302+static struct notifier_block vmstat_notifier =
85303 { &vmstat_cpuup_callback, NULL, 0 };
85304 #endif
85305
85306@@ -1238,10 +1238,20 @@ static int __init setup_vmstat(void)
85307 start_cpu_timer(cpu);
85308 #endif
85309 #ifdef CONFIG_PROC_FS
85310- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
85311- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
85312- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
85313- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
85314+ {
85315+ mode_t gr_mode = S_IRUGO;
85316+#ifdef CONFIG_GRKERNSEC_PROC_ADD
85317+ gr_mode = S_IRUSR;
85318+#endif
85319+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
85320+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
85321+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
85322+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
85323+#else
85324+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
85325+#endif
85326+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
85327+ }
85328 #endif
85329 return 0;
85330 }
85331diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
85332index acc74ad..be02639 100644
85333--- a/net/8021q/vlan.c
85334+++ b/net/8021q/vlan.c
85335@@ -108,6 +108,13 @@ void unregister_vlan_dev(struct net_device *dev, struct list_head *head)
85336 if (vlan_id)
85337 vlan_vid_del(real_dev, vlan_id);
85338
85339+ /* Take it out of our own structures, but be sure to interlock with
85340+ * HW accelerating devices or SW vlan input packet processing if
85341+ * VLAN is not 0 (leave it there for 802.1p).
85342+ */
85343+ if (vlan_id)
85344+ vlan_vid_del(real_dev, vlan_id);
85345+
85346 /* Get rid of the vlan's reference to real_dev */
85347 dev_put(real_dev);
85348 }
85349@@ -485,7 +492,7 @@ out:
85350 return NOTIFY_DONE;
85351 }
85352
85353-static struct notifier_block vlan_notifier_block __read_mostly = {
85354+static struct notifier_block vlan_notifier_block = {
85355 .notifier_call = vlan_device_event,
85356 };
85357
85358@@ -560,8 +567,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
85359 err = -EPERM;
85360 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
85361 break;
85362- if ((args.u.name_type >= 0) &&
85363- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
85364+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
85365 struct vlan_net *vn;
85366
85367 vn = net_generic(net, vlan_net_id);
85368diff --git a/net/9p/mod.c b/net/9p/mod.c
85369index 6ab36ae..6f1841b 100644
85370--- a/net/9p/mod.c
85371+++ b/net/9p/mod.c
85372@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
85373 void v9fs_register_trans(struct p9_trans_module *m)
85374 {
85375 spin_lock(&v9fs_trans_lock);
85376- list_add_tail(&m->list, &v9fs_trans_list);
85377+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
85378 spin_unlock(&v9fs_trans_lock);
85379 }
85380 EXPORT_SYMBOL(v9fs_register_trans);
85381@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
85382 void v9fs_unregister_trans(struct p9_trans_module *m)
85383 {
85384 spin_lock(&v9fs_trans_lock);
85385- list_del_init(&m->list);
85386+ pax_list_del_init((struct list_head *)&m->list);
85387 spin_unlock(&v9fs_trans_lock);
85388 }
85389 EXPORT_SYMBOL(v9fs_unregister_trans);
85390diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
85391index 02efb25..41541a9 100644
85392--- a/net/9p/trans_fd.c
85393+++ b/net/9p/trans_fd.c
85394@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
85395 oldfs = get_fs();
85396 set_fs(get_ds());
85397 /* The cast to a user pointer is valid due to the set_fs() */
85398- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
85399+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
85400 set_fs(oldfs);
85401
85402 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
85403diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
85404index 876fbe8..8bbea9f 100644
85405--- a/net/atm/atm_misc.c
85406+++ b/net/atm/atm_misc.c
85407@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
85408 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
85409 return 1;
85410 atm_return(vcc, truesize);
85411- atomic_inc(&vcc->stats->rx_drop);
85412+ atomic_inc_unchecked(&vcc->stats->rx_drop);
85413 return 0;
85414 }
85415 EXPORT_SYMBOL(atm_charge);
85416@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
85417 }
85418 }
85419 atm_return(vcc, guess);
85420- atomic_inc(&vcc->stats->rx_drop);
85421+ atomic_inc_unchecked(&vcc->stats->rx_drop);
85422 return NULL;
85423 }
85424 EXPORT_SYMBOL(atm_alloc_charge);
85425@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
85426
85427 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
85428 {
85429-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
85430+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
85431 __SONET_ITEMS
85432 #undef __HANDLE_ITEM
85433 }
85434@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
85435
85436 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
85437 {
85438-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
85439+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
85440 __SONET_ITEMS
85441 #undef __HANDLE_ITEM
85442 }
85443diff --git a/net/atm/lec.h b/net/atm/lec.h
85444index a86aff9..3a0d6f6 100644
85445--- a/net/atm/lec.h
85446+++ b/net/atm/lec.h
85447@@ -48,7 +48,7 @@ struct lane2_ops {
85448 const u8 *tlvs, u32 sizeoftlvs);
85449 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
85450 const u8 *tlvs, u32 sizeoftlvs);
85451-};
85452+} __no_const;
85453
85454 /*
85455 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
85456diff --git a/net/atm/proc.c b/net/atm/proc.c
85457index 0d020de..011c7bb 100644
85458--- a/net/atm/proc.c
85459+++ b/net/atm/proc.c
85460@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
85461 const struct k_atm_aal_stats *stats)
85462 {
85463 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
85464- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
85465- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
85466- atomic_read(&stats->rx_drop));
85467+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
85468+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
85469+ atomic_read_unchecked(&stats->rx_drop));
85470 }
85471
85472 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
85473diff --git a/net/atm/resources.c b/net/atm/resources.c
85474index 0447d5d..3cf4728 100644
85475--- a/net/atm/resources.c
85476+++ b/net/atm/resources.c
85477@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
85478 static void copy_aal_stats(struct k_atm_aal_stats *from,
85479 struct atm_aal_stats *to)
85480 {
85481-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
85482+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
85483 __AAL_STAT_ITEMS
85484 #undef __HANDLE_ITEM
85485 }
85486@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
85487 static void subtract_aal_stats(struct k_atm_aal_stats *from,
85488 struct atm_aal_stats *to)
85489 {
85490-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
85491+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
85492 __AAL_STAT_ITEMS
85493 #undef __HANDLE_ITEM
85494 }
85495diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
85496index d5744b7..506bae3 100644
85497--- a/net/ax25/sysctl_net_ax25.c
85498+++ b/net/ax25/sysctl_net_ax25.c
85499@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
85500 {
85501 char path[sizeof("net/ax25/") + IFNAMSIZ];
85502 int k;
85503- struct ctl_table *table;
85504+ ctl_table_no_const *table;
85505
85506 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
85507 if (!table)
85508diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
85509index 1ee94d0..14beea2 100644
85510--- a/net/batman-adv/bat_iv_ogm.c
85511+++ b/net/batman-adv/bat_iv_ogm.c
85512@@ -63,7 +63,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
85513
85514 /* randomize initial seqno to avoid collision */
85515 get_random_bytes(&random_seqno, sizeof(random_seqno));
85516- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
85517+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
85518
85519 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
85520 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
85521@@ -615,9 +615,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
85522 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
85523
85524 /* change sequence number to network order */
85525- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
85526+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
85527 batadv_ogm_packet->seqno = htonl(seqno);
85528- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
85529+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
85530
85531 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
85532 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
85533@@ -1022,7 +1022,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
85534 return;
85535
85536 /* could be changed by schedule_own_packet() */
85537- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
85538+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
85539
85540 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
85541 has_directlink_flag = 1;
85542diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
85543index f1d37cd..4190879 100644
85544--- a/net/batman-adv/hard-interface.c
85545+++ b/net/batman-adv/hard-interface.c
85546@@ -370,7 +370,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
85547 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
85548 dev_add_pack(&hard_iface->batman_adv_ptype);
85549
85550- atomic_set(&hard_iface->frag_seqno, 1);
85551+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
85552 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
85553 hard_iface->net_dev->name);
85554
85555@@ -493,7 +493,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
85556 /* This can't be called via a bat_priv callback because
85557 * we have no bat_priv yet.
85558 */
85559- atomic_set(&hard_iface->bat_iv.ogm_seqno, 1);
85560+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, 1);
85561 hard_iface->bat_iv.ogm_buff = NULL;
85562
85563 return hard_iface;
85564diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
85565index 6b548fd..fc32c8d 100644
85566--- a/net/batman-adv/soft-interface.c
85567+++ b/net/batman-adv/soft-interface.c
85568@@ -252,7 +252,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
85569 primary_if->net_dev->dev_addr, ETH_ALEN);
85570
85571 /* set broadcast sequence number */
85572- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
85573+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
85574 bcast_packet->seqno = htonl(seqno);
85575
85576 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
85577@@ -497,7 +497,7 @@ struct net_device *batadv_softif_create(const char *name)
85578 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
85579
85580 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
85581- atomic_set(&bat_priv->bcast_seqno, 1);
85582+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
85583 atomic_set(&bat_priv->tt.vn, 0);
85584 atomic_set(&bat_priv->tt.local_changes, 0);
85585 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
85586diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
85587index ae9ac9a..11e0fe7 100644
85588--- a/net/batman-adv/types.h
85589+++ b/net/batman-adv/types.h
85590@@ -48,7 +48,7 @@
85591 struct batadv_hard_iface_bat_iv {
85592 unsigned char *ogm_buff;
85593 int ogm_buff_len;
85594- atomic_t ogm_seqno;
85595+ atomic_unchecked_t ogm_seqno;
85596 };
85597
85598 struct batadv_hard_iface {
85599@@ -56,7 +56,7 @@ struct batadv_hard_iface {
85600 int16_t if_num;
85601 char if_status;
85602 struct net_device *net_dev;
85603- atomic_t frag_seqno;
85604+ atomic_unchecked_t frag_seqno;
85605 struct kobject *hardif_obj;
85606 atomic_t refcount;
85607 struct packet_type batman_adv_ptype;
85608@@ -284,7 +284,7 @@ struct batadv_priv {
85609 atomic_t orig_interval; /* uint */
85610 atomic_t hop_penalty; /* uint */
85611 atomic_t log_level; /* uint */
85612- atomic_t bcast_seqno;
85613+ atomic_unchecked_t bcast_seqno;
85614 atomic_t bcast_queue_left;
85615 atomic_t batman_queue_left;
85616 char num_ifaces;
85617diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
85618index 10aff49..ea8e021 100644
85619--- a/net/batman-adv/unicast.c
85620+++ b/net/batman-adv/unicast.c
85621@@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
85622 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
85623 frag2->flags = large_tail;
85624
85625- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
85626+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
85627 frag1->seqno = htons(seqno - 1);
85628 frag2->seqno = htons(seqno);
85629
85630diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
85631index 07f0739..3c42e34 100644
85632--- a/net/bluetooth/hci_sock.c
85633+++ b/net/bluetooth/hci_sock.c
85634@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
85635 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
85636 }
85637
85638- len = min_t(unsigned int, len, sizeof(uf));
85639+ len = min((size_t)len, sizeof(uf));
85640 if (copy_from_user(&uf, optval, len)) {
85641 err = -EFAULT;
85642 break;
85643diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
85644index 22e6583..426e2f3 100644
85645--- a/net/bluetooth/l2cap_core.c
85646+++ b/net/bluetooth/l2cap_core.c
85647@@ -3400,8 +3400,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
85648 break;
85649
85650 case L2CAP_CONF_RFC:
85651- if (olen == sizeof(rfc))
85652- memcpy(&rfc, (void *)val, olen);
85653+ if (olen != sizeof(rfc))
85654+ break;
85655+
85656+ memcpy(&rfc, (void *)val, olen);
85657
85658 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
85659 rfc.mode != chan->mode)
85660diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
85661index 1bcfb84..dad9f98 100644
85662--- a/net/bluetooth/l2cap_sock.c
85663+++ b/net/bluetooth/l2cap_sock.c
85664@@ -479,7 +479,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
85665 struct sock *sk = sock->sk;
85666 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
85667 struct l2cap_options opts;
85668- int len, err = 0;
85669+ int err = 0;
85670+ size_t len = optlen;
85671 u32 opt;
85672
85673 BT_DBG("sk %p", sk);
85674@@ -501,7 +502,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
85675 opts.max_tx = chan->max_tx;
85676 opts.txwin_size = chan->tx_win;
85677
85678- len = min_t(unsigned int, sizeof(opts), optlen);
85679+ len = min(sizeof(opts), len);
85680 if (copy_from_user((char *) &opts, optval, len)) {
85681 err = -EFAULT;
85682 break;
85683@@ -581,7 +582,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
85684 struct bt_security sec;
85685 struct bt_power pwr;
85686 struct l2cap_conn *conn;
85687- int len, err = 0;
85688+ int err = 0;
85689+ size_t len = optlen;
85690 u32 opt;
85691
85692 BT_DBG("sk %p", sk);
85693@@ -604,7 +606,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
85694
85695 sec.level = BT_SECURITY_LOW;
85696
85697- len = min_t(unsigned int, sizeof(sec), optlen);
85698+ len = min(sizeof(sec), len);
85699 if (copy_from_user((char *) &sec, optval, len)) {
85700 err = -EFAULT;
85701 break;
85702@@ -701,7 +703,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
85703
85704 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
85705
85706- len = min_t(unsigned int, sizeof(pwr), optlen);
85707+ len = min(sizeof(pwr), len);
85708 if (copy_from_user((char *) &pwr, optval, len)) {
85709 err = -EFAULT;
85710 break;
85711diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
85712index ce3f665..2c7d08f 100644
85713--- a/net/bluetooth/rfcomm/sock.c
85714+++ b/net/bluetooth/rfcomm/sock.c
85715@@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
85716 struct sock *sk = sock->sk;
85717 struct bt_security sec;
85718 int err = 0;
85719- size_t len;
85720+ size_t len = optlen;
85721 u32 opt;
85722
85723 BT_DBG("sk %p", sk);
85724@@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
85725
85726 sec.level = BT_SECURITY_LOW;
85727
85728- len = min_t(unsigned int, sizeof(sec), optlen);
85729+ len = min(sizeof(sec), len);
85730 if (copy_from_user((char *) &sec, optval, len)) {
85731 err = -EFAULT;
85732 break;
85733diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
85734index bd6fd0f..6492cba 100644
85735--- a/net/bluetooth/rfcomm/tty.c
85736+++ b/net/bluetooth/rfcomm/tty.c
85737@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
85738 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
85739
85740 spin_lock_irqsave(&dev->port.lock, flags);
85741- if (dev->port.count > 0) {
85742+ if (atomic_read(&dev->port.count) > 0) {
85743 spin_unlock_irqrestore(&dev->port.lock, flags);
85744 return;
85745 }
85746@@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
85747 return -ENODEV;
85748
85749 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
85750- dev->channel, dev->port.count);
85751+ dev->channel, atomic_read(&dev->port.count));
85752
85753 spin_lock_irqsave(&dev->port.lock, flags);
85754- if (++dev->port.count > 1) {
85755+ if (atomic_inc_return(&dev->port.count) > 1) {
85756 spin_unlock_irqrestore(&dev->port.lock, flags);
85757 return 0;
85758 }
85759@@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
85760 return;
85761
85762 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
85763- dev->port.count);
85764+ atomic_read(&dev->port.count));
85765
85766 spin_lock_irqsave(&dev->port.lock, flags);
85767- if (!--dev->port.count) {
85768+ if (!atomic_dec_return(&dev->port.count)) {
85769 spin_unlock_irqrestore(&dev->port.lock, flags);
85770 if (dev->tty_dev->parent)
85771 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
85772diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c
85773index d9576e6..85f4f4e 100644
85774--- a/net/bridge/br_fdb.c
85775+++ b/net/bridge/br_fdb.c
85776@@ -386,7 +386,7 @@ static int fdb_insert(struct net_bridge *br, struct net_bridge_port *source,
85777 return 0;
85778 br_warn(br, "adding interface %s with same address "
85779 "as a received packet\n",
85780- source->dev->name);
85781+ source ? source->dev->name : br->dev->name);
85782 fdb_delete(br, fdb);
85783 }
85784
85785diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
85786index 5fe2ff3..121d696 100644
85787--- a/net/bridge/netfilter/ebtables.c
85788+++ b/net/bridge/netfilter/ebtables.c
85789@@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
85790 tmp.valid_hooks = t->table->valid_hooks;
85791 }
85792 mutex_unlock(&ebt_mutex);
85793- if (copy_to_user(user, &tmp, *len) != 0){
85794+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
85795 BUGPRINT("c2u Didn't work\n");
85796 ret = -EFAULT;
85797 break;
85798@@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
85799 goto out;
85800 tmp.valid_hooks = t->valid_hooks;
85801
85802- if (copy_to_user(user, &tmp, *len) != 0) {
85803+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
85804 ret = -EFAULT;
85805 break;
85806 }
85807@@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
85808 tmp.entries_size = t->table->entries_size;
85809 tmp.valid_hooks = t->table->valid_hooks;
85810
85811- if (copy_to_user(user, &tmp, *len) != 0) {
85812+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
85813 ret = -EFAULT;
85814 break;
85815 }
85816diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
85817index a376ec1..1fbd6be 100644
85818--- a/net/caif/cfctrl.c
85819+++ b/net/caif/cfctrl.c
85820@@ -10,6 +10,7 @@
85821 #include <linux/spinlock.h>
85822 #include <linux/slab.h>
85823 #include <linux/pkt_sched.h>
85824+#include <linux/sched.h>
85825 #include <net/caif/caif_layer.h>
85826 #include <net/caif/cfpkt.h>
85827 #include <net/caif/cfctrl.h>
85828@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
85829 memset(&dev_info, 0, sizeof(dev_info));
85830 dev_info.id = 0xff;
85831 cfsrvl_init(&this->serv, 0, &dev_info, false);
85832- atomic_set(&this->req_seq_no, 1);
85833- atomic_set(&this->rsp_seq_no, 1);
85834+ atomic_set_unchecked(&this->req_seq_no, 1);
85835+ atomic_set_unchecked(&this->rsp_seq_no, 1);
85836 this->serv.layer.receive = cfctrl_recv;
85837 sprintf(this->serv.layer.name, "ctrl");
85838 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
85839@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
85840 struct cfctrl_request_info *req)
85841 {
85842 spin_lock_bh(&ctrl->info_list_lock);
85843- atomic_inc(&ctrl->req_seq_no);
85844- req->sequence_no = atomic_read(&ctrl->req_seq_no);
85845+ atomic_inc_unchecked(&ctrl->req_seq_no);
85846+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
85847 list_add_tail(&req->list, &ctrl->list);
85848 spin_unlock_bh(&ctrl->info_list_lock);
85849 }
85850@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
85851 if (p != first)
85852 pr_warn("Requests are not received in order\n");
85853
85854- atomic_set(&ctrl->rsp_seq_no,
85855+ atomic_set_unchecked(&ctrl->rsp_seq_no,
85856 p->sequence_no);
85857 list_del(&p->list);
85858 goto out;
85859diff --git a/net/can/af_can.c b/net/can/af_can.c
85860index ddac1ee..3ee0a78 100644
85861--- a/net/can/af_can.c
85862+++ b/net/can/af_can.c
85863@@ -872,7 +872,7 @@ static const struct net_proto_family can_family_ops = {
85864 };
85865
85866 /* notifier block for netdevice event */
85867-static struct notifier_block can_netdev_notifier __read_mostly = {
85868+static struct notifier_block can_netdev_notifier = {
85869 .notifier_call = can_notifier,
85870 };
85871
85872diff --git a/net/can/gw.c b/net/can/gw.c
85873index 28e7bdc..d42c4cd 100644
85874--- a/net/can/gw.c
85875+++ b/net/can/gw.c
85876@@ -67,7 +67,6 @@ MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
85877 MODULE_ALIAS("can-gw");
85878
85879 static HLIST_HEAD(cgw_list);
85880-static struct notifier_block notifier;
85881
85882 static struct kmem_cache *cgw_cache __read_mostly;
85883
85884@@ -893,6 +892,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
85885 return err;
85886 }
85887
85888+static struct notifier_block notifier = {
85889+ .notifier_call = cgw_notifier
85890+};
85891+
85892 static __init int cgw_module_init(void)
85893 {
85894 printk(banner);
85895@@ -904,7 +907,6 @@ static __init int cgw_module_init(void)
85896 return -ENOMEM;
85897
85898 /* set notifier */
85899- notifier.notifier_call = cgw_notifier;
85900 register_netdevice_notifier(&notifier);
85901
85902 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
85903diff --git a/net/compat.c b/net/compat.c
85904index 79ae884..17c5c09 100644
85905--- a/net/compat.c
85906+++ b/net/compat.c
85907@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
85908 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
85909 __get_user(kmsg->msg_flags, &umsg->msg_flags))
85910 return -EFAULT;
85911- kmsg->msg_name = compat_ptr(tmp1);
85912- kmsg->msg_iov = compat_ptr(tmp2);
85913- kmsg->msg_control = compat_ptr(tmp3);
85914+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
85915+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
85916+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
85917 return 0;
85918 }
85919
85920@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
85921
85922 if (kern_msg->msg_namelen) {
85923 if (mode == VERIFY_READ) {
85924- int err = move_addr_to_kernel(kern_msg->msg_name,
85925+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
85926 kern_msg->msg_namelen,
85927 kern_address);
85928 if (err < 0)
85929@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
85930 kern_msg->msg_name = NULL;
85931
85932 tot_len = iov_from_user_compat_to_kern(kern_iov,
85933- (struct compat_iovec __user *)kern_msg->msg_iov,
85934+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
85935 kern_msg->msg_iovlen);
85936 if (tot_len >= 0)
85937 kern_msg->msg_iov = kern_iov;
85938@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
85939
85940 #define CMSG_COMPAT_FIRSTHDR(msg) \
85941 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
85942- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
85943+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
85944 (struct compat_cmsghdr __user *)NULL)
85945
85946 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
85947 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
85948 (ucmlen) <= (unsigned long) \
85949 ((mhdr)->msg_controllen - \
85950- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
85951+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
85952
85953 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
85954 struct compat_cmsghdr __user *cmsg, int cmsg_len)
85955 {
85956 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
85957- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
85958+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
85959 msg->msg_controllen)
85960 return NULL;
85961 return (struct compat_cmsghdr __user *)ptr;
85962@@ -219,7 +219,7 @@ Efault:
85963
85964 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
85965 {
85966- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
85967+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
85968 struct compat_cmsghdr cmhdr;
85969 struct compat_timeval ctv;
85970 struct compat_timespec cts[3];
85971@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
85972
85973 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
85974 {
85975- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
85976+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
85977 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
85978 int fdnum = scm->fp->count;
85979 struct file **fp = scm->fp->fp;
85980@@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
85981 return -EFAULT;
85982 old_fs = get_fs();
85983 set_fs(KERNEL_DS);
85984- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
85985+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
85986 set_fs(old_fs);
85987
85988 return err;
85989@@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
85990 len = sizeof(ktime);
85991 old_fs = get_fs();
85992 set_fs(KERNEL_DS);
85993- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
85994+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
85995 set_fs(old_fs);
85996
85997 if (!err) {
85998@@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
85999 case MCAST_JOIN_GROUP:
86000 case MCAST_LEAVE_GROUP:
86001 {
86002- struct compat_group_req __user *gr32 = (void *)optval;
86003+ struct compat_group_req __user *gr32 = (void __user *)optval;
86004 struct group_req __user *kgr =
86005 compat_alloc_user_space(sizeof(struct group_req));
86006 u32 interface;
86007@@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
86008 case MCAST_BLOCK_SOURCE:
86009 case MCAST_UNBLOCK_SOURCE:
86010 {
86011- struct compat_group_source_req __user *gsr32 = (void *)optval;
86012+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
86013 struct group_source_req __user *kgsr = compat_alloc_user_space(
86014 sizeof(struct group_source_req));
86015 u32 interface;
86016@@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
86017 }
86018 case MCAST_MSFILTER:
86019 {
86020- struct compat_group_filter __user *gf32 = (void *)optval;
86021+ struct compat_group_filter __user *gf32 = (void __user *)optval;
86022 struct group_filter __user *kgf;
86023 u32 interface, fmode, numsrc;
86024
86025@@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
86026 char __user *optval, int __user *optlen,
86027 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
86028 {
86029- struct compat_group_filter __user *gf32 = (void *)optval;
86030+ struct compat_group_filter __user *gf32 = (void __user *)optval;
86031 struct group_filter __user *kgf;
86032 int __user *koptlen;
86033 u32 interface, fmode, numsrc;
86034@@ -796,7 +796,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
86035
86036 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
86037 return -EINVAL;
86038- if (copy_from_user(a, args, nas[call]))
86039+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
86040 return -EFAULT;
86041 a0 = a[0];
86042 a1 = a[1];
86043diff --git a/net/core/datagram.c b/net/core/datagram.c
86044index 368f9c3..f82d4a3 100644
86045--- a/net/core/datagram.c
86046+++ b/net/core/datagram.c
86047@@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
86048 }
86049
86050 kfree_skb(skb);
86051- atomic_inc(&sk->sk_drops);
86052+ atomic_inc_unchecked(&sk->sk_drops);
86053 sk_mem_reclaim_partial(sk);
86054
86055 return err;
86056diff --git a/net/core/dev.c b/net/core/dev.c
86057index 5d9c43d..b471558 100644
86058--- a/net/core/dev.c
86059+++ b/net/core/dev.c
86060@@ -1250,9 +1250,13 @@ void dev_load(struct net *net, const char *name)
86061 if (no_module && capable(CAP_NET_ADMIN))
86062 no_module = request_module("netdev-%s", name);
86063 if (no_module && capable(CAP_SYS_MODULE)) {
86064+#ifdef CONFIG_GRKERNSEC_MODHARDEN
86065+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
86066+#else
86067 if (!request_module("%s", name))
86068 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
86069 name);
86070+#endif
86071 }
86072 }
86073 EXPORT_SYMBOL(dev_load);
86074@@ -1714,7 +1718,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
86075 {
86076 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
86077 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
86078- atomic_long_inc(&dev->rx_dropped);
86079+ atomic_long_inc_unchecked(&dev->rx_dropped);
86080 kfree_skb(skb);
86081 return NET_RX_DROP;
86082 }
86083@@ -1724,7 +1728,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
86084 nf_reset(skb);
86085
86086 if (unlikely(!is_skb_forwardable(dev, skb))) {
86087- atomic_long_inc(&dev->rx_dropped);
86088+ atomic_long_inc_unchecked(&dev->rx_dropped);
86089 kfree_skb(skb);
86090 return NET_RX_DROP;
86091 }
86092@@ -2179,7 +2183,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
86093
86094 struct dev_gso_cb {
86095 void (*destructor)(struct sk_buff *skb);
86096-};
86097+} __no_const;
86098
86099 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
86100
86101@@ -3052,7 +3056,7 @@ enqueue:
86102
86103 local_irq_restore(flags);
86104
86105- atomic_long_inc(&skb->dev->rx_dropped);
86106+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
86107 kfree_skb(skb);
86108 return NET_RX_DROP;
86109 }
86110@@ -3124,7 +3128,7 @@ int netif_rx_ni(struct sk_buff *skb)
86111 }
86112 EXPORT_SYMBOL(netif_rx_ni);
86113
86114-static void net_tx_action(struct softirq_action *h)
86115+static void net_tx_action(void)
86116 {
86117 struct softnet_data *sd = &__get_cpu_var(softnet_data);
86118
86119@@ -3462,7 +3466,7 @@ ncls:
86120 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
86121 } else {
86122 drop:
86123- atomic_long_inc(&skb->dev->rx_dropped);
86124+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
86125 kfree_skb(skb);
86126 /* Jamal, now you will not able to escape explaining
86127 * me how you were going to use this. :-)
86128@@ -4045,7 +4049,7 @@ void netif_napi_del(struct napi_struct *napi)
86129 }
86130 EXPORT_SYMBOL(netif_napi_del);
86131
86132-static void net_rx_action(struct softirq_action *h)
86133+static void net_rx_action(void)
86134 {
86135 struct softnet_data *sd = &__get_cpu_var(softnet_data);
86136 unsigned long time_limit = jiffies + 2;
86137@@ -4529,8 +4533,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
86138 else
86139 seq_printf(seq, "%04x", ntohs(pt->type));
86140
86141+#ifdef CONFIG_GRKERNSEC_HIDESYM
86142+ seq_printf(seq, " %-8s %p\n",
86143+ pt->dev ? pt->dev->name : "", NULL);
86144+#else
86145 seq_printf(seq, " %-8s %pF\n",
86146 pt->dev ? pt->dev->name : "", pt->func);
86147+#endif
86148 }
86149
86150 return 0;
86151@@ -6102,7 +6111,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
86152 } else {
86153 netdev_stats_to_stats64(storage, &dev->stats);
86154 }
86155- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
86156+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
86157 return storage;
86158 }
86159 EXPORT_SYMBOL(dev_get_stats);
86160diff --git a/net/core/flow.c b/net/core/flow.c
86161index 3bad824..2071a55 100644
86162--- a/net/core/flow.c
86163+++ b/net/core/flow.c
86164@@ -61,7 +61,7 @@ struct flow_cache {
86165 struct timer_list rnd_timer;
86166 };
86167
86168-atomic_t flow_cache_genid = ATOMIC_INIT(0);
86169+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
86170 EXPORT_SYMBOL(flow_cache_genid);
86171 static struct flow_cache flow_cache_global;
86172 static struct kmem_cache *flow_cachep __read_mostly;
86173@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
86174
86175 static int flow_entry_valid(struct flow_cache_entry *fle)
86176 {
86177- if (atomic_read(&flow_cache_genid) != fle->genid)
86178+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
86179 return 0;
86180 if (fle->object && !fle->object->ops->check(fle->object))
86181 return 0;
86182@@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
86183 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
86184 fcp->hash_count++;
86185 }
86186- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
86187+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
86188 flo = fle->object;
86189 if (!flo)
86190 goto ret_object;
86191@@ -280,7 +280,7 @@ nocache:
86192 }
86193 flo = resolver(net, key, family, dir, flo, ctx);
86194 if (fle) {
86195- fle->genid = atomic_read(&flow_cache_genid);
86196+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
86197 if (!IS_ERR(flo))
86198 fle->object = flo;
86199 else
86200diff --git a/net/core/iovec.c b/net/core/iovec.c
86201index 7e7aeb0..2a998cb 100644
86202--- a/net/core/iovec.c
86203+++ b/net/core/iovec.c
86204@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
86205 if (m->msg_namelen) {
86206 if (mode == VERIFY_READ) {
86207 void __user *namep;
86208- namep = (void __user __force *) m->msg_name;
86209+ namep = (void __force_user *) m->msg_name;
86210 err = move_addr_to_kernel(namep, m->msg_namelen,
86211 address);
86212 if (err < 0)
86213@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
86214 }
86215
86216 size = m->msg_iovlen * sizeof(struct iovec);
86217- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
86218+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
86219 return -EFAULT;
86220
86221 m->msg_iov = iov;
86222diff --git a/net/core/neighbour.c b/net/core/neighbour.c
86223index c815f28..e6403f2 100644
86224--- a/net/core/neighbour.c
86225+++ b/net/core/neighbour.c
86226@@ -2776,7 +2776,7 @@ static int proc_unres_qlen(ctl_table *ctl, int write, void __user *buffer,
86227 size_t *lenp, loff_t *ppos)
86228 {
86229 int size, ret;
86230- ctl_table tmp = *ctl;
86231+ ctl_table_no_const tmp = *ctl;
86232
86233 tmp.extra1 = &zero;
86234 tmp.extra2 = &unres_qlen_max;
86235diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
86236index 28c5f5a..7edf2e2 100644
86237--- a/net/core/net-sysfs.c
86238+++ b/net/core/net-sysfs.c
86239@@ -1455,7 +1455,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
86240 }
86241 EXPORT_SYMBOL(netdev_class_remove_file);
86242
86243-int netdev_kobject_init(void)
86244+int __init netdev_kobject_init(void)
86245 {
86246 kobj_ns_type_register(&net_ns_type_operations);
86247 return class_register(&net_class);
86248diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
86249index 8acce01..2e306bb 100644
86250--- a/net/core/net_namespace.c
86251+++ b/net/core/net_namespace.c
86252@@ -442,7 +442,7 @@ static int __register_pernet_operations(struct list_head *list,
86253 int error;
86254 LIST_HEAD(net_exit_list);
86255
86256- list_add_tail(&ops->list, list);
86257+ pax_list_add_tail((struct list_head *)&ops->list, list);
86258 if (ops->init || (ops->id && ops->size)) {
86259 for_each_net(net) {
86260 error = ops_init(ops, net);
86261@@ -455,7 +455,7 @@ static int __register_pernet_operations(struct list_head *list,
86262
86263 out_undo:
86264 /* If I have an error cleanup all namespaces I initialized */
86265- list_del(&ops->list);
86266+ pax_list_del((struct list_head *)&ops->list);
86267 ops_exit_list(ops, &net_exit_list);
86268 ops_free_list(ops, &net_exit_list);
86269 return error;
86270@@ -466,7 +466,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
86271 struct net *net;
86272 LIST_HEAD(net_exit_list);
86273
86274- list_del(&ops->list);
86275+ pax_list_del((struct list_head *)&ops->list);
86276 for_each_net(net)
86277 list_add_tail(&net->exit_list, &net_exit_list);
86278 ops_exit_list(ops, &net_exit_list);
86279@@ -600,7 +600,7 @@ int register_pernet_device(struct pernet_operations *ops)
86280 mutex_lock(&net_mutex);
86281 error = register_pernet_operations(&pernet_list, ops);
86282 if (!error && (first_device == &pernet_list))
86283- first_device = &ops->list;
86284+ first_device = (struct list_head *)&ops->list;
86285 mutex_unlock(&net_mutex);
86286 return error;
86287 }
86288diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
86289index 6212ec9..5ee16b2 100644
86290--- a/net/core/rtnetlink.c
86291+++ b/net/core/rtnetlink.c
86292@@ -58,7 +58,7 @@ struct rtnl_link {
86293 rtnl_doit_func doit;
86294 rtnl_dumpit_func dumpit;
86295 rtnl_calcit_func calcit;
86296-};
86297+} __no_const;
86298
86299 static DEFINE_MUTEX(rtnl_mutex);
86300
86301@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
86302 if (rtnl_link_ops_get(ops->kind))
86303 return -EEXIST;
86304
86305- if (!ops->dellink)
86306- ops->dellink = unregister_netdevice_queue;
86307+ if (!ops->dellink) {
86308+ pax_open_kernel();
86309+ *(void **)&ops->dellink = unregister_netdevice_queue;
86310+ pax_close_kernel();
86311+ }
86312
86313- list_add_tail(&ops->list, &link_ops);
86314+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
86315 return 0;
86316 }
86317 EXPORT_SYMBOL_GPL(__rtnl_link_register);
86318@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
86319 for_each_net(net) {
86320 __rtnl_kill_links(net, ops);
86321 }
86322- list_del(&ops->list);
86323+ pax_list_del((struct list_head *)&ops->list);
86324 }
86325 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
86326
86327@@ -1068,7 +1071,7 @@ static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
86328 rcu_read_lock();
86329 cb->seq = net->dev_base_seq;
86330
86331- if (nlmsg_parse(cb->nlh, sizeof(struct rtgenmsg), tb, IFLA_MAX,
86332+ if (nlmsg_parse(cb->nlh, sizeof(struct ifinfomsg), tb, IFLA_MAX,
86333 ifla_policy) >= 0) {
86334
86335 if (tb[IFLA_EXT_MASK])
86336@@ -1924,7 +1927,7 @@ static u16 rtnl_calcit(struct sk_buff *skb, struct nlmsghdr *nlh)
86337 u32 ext_filter_mask = 0;
86338 u16 min_ifinfo_dump_size = 0;
86339
86340- if (nlmsg_parse(nlh, sizeof(struct rtgenmsg), tb, IFLA_MAX,
86341+ if (nlmsg_parse(nlh, sizeof(struct ifinfomsg), tb, IFLA_MAX,
86342 ifla_policy) >= 0) {
86343 if (tb[IFLA_EXT_MASK])
86344 ext_filter_mask = nla_get_u32(tb[IFLA_EXT_MASK]);
86345diff --git a/net/core/scm.c b/net/core/scm.c
86346index 2dc6cda..2159524 100644
86347--- a/net/core/scm.c
86348+++ b/net/core/scm.c
86349@@ -226,7 +226,7 @@ EXPORT_SYMBOL(__scm_send);
86350 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
86351 {
86352 struct cmsghdr __user *cm
86353- = (__force struct cmsghdr __user *)msg->msg_control;
86354+ = (struct cmsghdr __force_user *)msg->msg_control;
86355 struct cmsghdr cmhdr;
86356 int cmlen = CMSG_LEN(len);
86357 int err;
86358@@ -249,7 +249,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
86359 err = -EFAULT;
86360 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
86361 goto out;
86362- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
86363+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
86364 goto out;
86365 cmlen = CMSG_SPACE(len);
86366 if (msg->msg_controllen < cmlen)
86367@@ -265,7 +265,7 @@ EXPORT_SYMBOL(put_cmsg);
86368 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
86369 {
86370 struct cmsghdr __user *cm
86371- = (__force struct cmsghdr __user*)msg->msg_control;
86372+ = (struct cmsghdr __force_user *)msg->msg_control;
86373
86374 int fdmax = 0;
86375 int fdnum = scm->fp->count;
86376@@ -285,7 +285,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
86377 if (fdnum < fdmax)
86378 fdmax = fdnum;
86379
86380- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
86381+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
86382 i++, cmfptr++)
86383 {
86384 struct socket *sock;
86385diff --git a/net/core/sock.c b/net/core/sock.c
86386index bc131d4..029e378 100644
86387--- a/net/core/sock.c
86388+++ b/net/core/sock.c
86389@@ -388,7 +388,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86390 struct sk_buff_head *list = &sk->sk_receive_queue;
86391
86392 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
86393- atomic_inc(&sk->sk_drops);
86394+ atomic_inc_unchecked(&sk->sk_drops);
86395 trace_sock_rcvqueue_full(sk, skb);
86396 return -ENOMEM;
86397 }
86398@@ -398,7 +398,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86399 return err;
86400
86401 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
86402- atomic_inc(&sk->sk_drops);
86403+ atomic_inc_unchecked(&sk->sk_drops);
86404 return -ENOBUFS;
86405 }
86406
86407@@ -418,7 +418,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86408 skb_dst_force(skb);
86409
86410 spin_lock_irqsave(&list->lock, flags);
86411- skb->dropcount = atomic_read(&sk->sk_drops);
86412+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
86413 __skb_queue_tail(list, skb);
86414 spin_unlock_irqrestore(&list->lock, flags);
86415
86416@@ -438,7 +438,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
86417 skb->dev = NULL;
86418
86419 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
86420- atomic_inc(&sk->sk_drops);
86421+ atomic_inc_unchecked(&sk->sk_drops);
86422 goto discard_and_relse;
86423 }
86424 if (nested)
86425@@ -456,7 +456,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
86426 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
86427 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
86428 bh_unlock_sock(sk);
86429- atomic_inc(&sk->sk_drops);
86430+ atomic_inc_unchecked(&sk->sk_drops);
86431 goto discard_and_relse;
86432 }
86433
86434@@ -930,12 +930,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
86435 struct timeval tm;
86436 } v;
86437
86438- int lv = sizeof(int);
86439- int len;
86440+ unsigned int lv = sizeof(int);
86441+ unsigned int len;
86442
86443 if (get_user(len, optlen))
86444 return -EFAULT;
86445- if (len < 0)
86446+ if (len > INT_MAX)
86447 return -EINVAL;
86448
86449 memset(&v, 0, sizeof(v));
86450@@ -1083,11 +1083,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
86451
86452 case SO_PEERNAME:
86453 {
86454- char address[128];
86455+ char address[_K_SS_MAXSIZE];
86456
86457 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
86458 return -ENOTCONN;
86459- if (lv < len)
86460+ if (lv < len || sizeof address < len)
86461 return -EINVAL;
86462 if (copy_to_user(optval, address, len))
86463 return -EFAULT;
86464@@ -1146,7 +1146,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
86465
86466 if (len > lv)
86467 len = lv;
86468- if (copy_to_user(optval, &v, len))
86469+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
86470 return -EFAULT;
86471 lenout:
86472 if (put_user(len, optlen))
86473@@ -2276,7 +2276,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
86474 */
86475 smp_wmb();
86476 atomic_set(&sk->sk_refcnt, 1);
86477- atomic_set(&sk->sk_drops, 0);
86478+ atomic_set_unchecked(&sk->sk_drops, 0);
86479 }
86480 EXPORT_SYMBOL(sock_init_data);
86481
86482diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
86483index 750f44f..922399c 100644
86484--- a/net/core/sock_diag.c
86485+++ b/net/core/sock_diag.c
86486@@ -9,26 +9,33 @@
86487 #include <linux/inet_diag.h>
86488 #include <linux/sock_diag.h>
86489
86490-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
86491+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
86492 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
86493 static DEFINE_MUTEX(sock_diag_table_mutex);
86494
86495 int sock_diag_check_cookie(void *sk, __u32 *cookie)
86496 {
86497+#ifndef CONFIG_GRKERNSEC_HIDESYM
86498 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
86499 cookie[1] != INET_DIAG_NOCOOKIE) &&
86500 ((u32)(unsigned long)sk != cookie[0] ||
86501 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
86502 return -ESTALE;
86503 else
86504+#endif
86505 return 0;
86506 }
86507 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
86508
86509 void sock_diag_save_cookie(void *sk, __u32 *cookie)
86510 {
86511+#ifdef CONFIG_GRKERNSEC_HIDESYM
86512+ cookie[0] = 0;
86513+ cookie[1] = 0;
86514+#else
86515 cookie[0] = (u32)(unsigned long)sk;
86516 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
86517+#endif
86518 }
86519 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
86520
86521@@ -75,8 +82,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
86522 mutex_lock(&sock_diag_table_mutex);
86523 if (sock_diag_handlers[hndl->family])
86524 err = -EBUSY;
86525- else
86526+ else {
86527+ pax_open_kernel();
86528 sock_diag_handlers[hndl->family] = hndl;
86529+ pax_close_kernel();
86530+ }
86531 mutex_unlock(&sock_diag_table_mutex);
86532
86533 return err;
86534@@ -92,26 +102,13 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
86535
86536 mutex_lock(&sock_diag_table_mutex);
86537 BUG_ON(sock_diag_handlers[family] != hnld);
86538+ pax_open_kernel();
86539 sock_diag_handlers[family] = NULL;
86540+ pax_close_kernel();
86541 mutex_unlock(&sock_diag_table_mutex);
86542 }
86543 EXPORT_SYMBOL_GPL(sock_diag_unregister);
86544
86545-static const inline struct sock_diag_handler *sock_diag_lock_handler(int family)
86546-{
86547- if (sock_diag_handlers[family] == NULL)
86548- request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
86549- NETLINK_SOCK_DIAG, family);
86550-
86551- mutex_lock(&sock_diag_table_mutex);
86552- return sock_diag_handlers[family];
86553-}
86554-
86555-static inline void sock_diag_unlock_handler(const struct sock_diag_handler *h)
86556-{
86557- mutex_unlock(&sock_diag_table_mutex);
86558-}
86559-
86560 static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
86561 {
86562 int err;
86563@@ -124,12 +121,17 @@ static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
86564 if (req->sdiag_family >= AF_MAX)
86565 return -EINVAL;
86566
86567- hndl = sock_diag_lock_handler(req->sdiag_family);
86568+ if (sock_diag_handlers[req->sdiag_family] == NULL)
86569+ request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
86570+ NETLINK_SOCK_DIAG, req->sdiag_family);
86571+
86572+ mutex_lock(&sock_diag_table_mutex);
86573+ hndl = sock_diag_handlers[req->sdiag_family];
86574 if (hndl == NULL)
86575 err = -ENOENT;
86576 else
86577 err = hndl->dump(skb, nlh);
86578- sock_diag_unlock_handler(hndl);
86579+ mutex_unlock(&sock_diag_table_mutex);
86580
86581 return err;
86582 }
86583diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
86584index d1b0804..98cf5f7 100644
86585--- a/net/core/sysctl_net_core.c
86586+++ b/net/core/sysctl_net_core.c
86587@@ -26,7 +26,7 @@ static int rps_sock_flow_sysctl(ctl_table *table, int write,
86588 {
86589 unsigned int orig_size, size;
86590 int ret, i;
86591- ctl_table tmp = {
86592+ ctl_table_no_const tmp = {
86593 .data = &size,
86594 .maxlen = sizeof(size),
86595 .mode = table->mode
86596@@ -205,13 +205,12 @@ static struct ctl_table netns_core_table[] = {
86597
86598 static __net_init int sysctl_core_net_init(struct net *net)
86599 {
86600- struct ctl_table *tbl;
86601+ ctl_table_no_const *tbl = NULL;
86602
86603 net->core.sysctl_somaxconn = SOMAXCONN;
86604
86605- tbl = netns_core_table;
86606 if (!net_eq(net, &init_net)) {
86607- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
86608+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
86609 if (tbl == NULL)
86610 goto err_dup;
86611
86612@@ -221,17 +220,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
86613 if (net->user_ns != &init_user_ns) {
86614 tbl[0].procname = NULL;
86615 }
86616- }
86617-
86618- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
86619+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
86620+ } else
86621+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
86622 if (net->core.sysctl_hdr == NULL)
86623 goto err_reg;
86624
86625 return 0;
86626
86627 err_reg:
86628- if (tbl != netns_core_table)
86629- kfree(tbl);
86630+ kfree(tbl);
86631 err_dup:
86632 return -ENOMEM;
86633 }
86634@@ -246,7 +244,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
86635 kfree(tbl);
86636 }
86637
86638-static __net_initdata struct pernet_operations sysctl_core_ops = {
86639+static __net_initconst struct pernet_operations sysctl_core_ops = {
86640 .init = sysctl_core_net_init,
86641 .exit = sysctl_core_net_exit,
86642 };
86643diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
86644index 307c322..78a4c6f 100644
86645--- a/net/decnet/af_decnet.c
86646+++ b/net/decnet/af_decnet.c
86647@@ -468,6 +468,7 @@ static struct proto dn_proto = {
86648 .sysctl_rmem = sysctl_decnet_rmem,
86649 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
86650 .obj_size = sizeof(struct dn_sock),
86651+ .slab_flags = SLAB_USERCOPY,
86652 };
86653
86654 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
86655diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
86656index a55eecc..dd8428c 100644
86657--- a/net/decnet/sysctl_net_decnet.c
86658+++ b/net/decnet/sysctl_net_decnet.c
86659@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
86660
86661 if (len > *lenp) len = *lenp;
86662
86663- if (copy_to_user(buffer, addr, len))
86664+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
86665 return -EFAULT;
86666
86667 *lenp = len;
86668@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
86669
86670 if (len > *lenp) len = *lenp;
86671
86672- if (copy_to_user(buffer, devname, len))
86673+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
86674 return -EFAULT;
86675
86676 *lenp = len;
86677diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
86678index fcf104e..95552d4 100644
86679--- a/net/ipv4/af_inet.c
86680+++ b/net/ipv4/af_inet.c
86681@@ -1717,13 +1717,9 @@ static int __init inet_init(void)
86682
86683 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > sizeof(dummy_skb->cb));
86684
86685- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
86686- if (!sysctl_local_reserved_ports)
86687- goto out;
86688-
86689 rc = proto_register(&tcp_prot, 1);
86690 if (rc)
86691- goto out_free_reserved_ports;
86692+ goto out;
86693
86694 rc = proto_register(&udp_prot, 1);
86695 if (rc)
86696@@ -1832,8 +1828,6 @@ out_unregister_udp_proto:
86697 proto_unregister(&udp_prot);
86698 out_unregister_tcp_proto:
86699 proto_unregister(&tcp_prot);
86700-out_free_reserved_ports:
86701- kfree(sysctl_local_reserved_ports);
86702 goto out;
86703 }
86704
86705diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
86706index a69b4e4..dbccba5 100644
86707--- a/net/ipv4/ah4.c
86708+++ b/net/ipv4/ah4.c
86709@@ -421,7 +421,7 @@ static void ah4_err(struct sk_buff *skb, u32 info)
86710 return;
86711
86712 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
86713- atomic_inc(&flow_cache_genid);
86714+ atomic_inc_unchecked(&flow_cache_genid);
86715 rt_genid_bump(net);
86716
86717 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_AH, 0);
86718diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
86719index a8e4f26..25e5f40 100644
86720--- a/net/ipv4/devinet.c
86721+++ b/net/ipv4/devinet.c
86722@@ -1763,7 +1763,7 @@ static int ipv4_doint_and_flush(ctl_table *ctl, int write,
86723 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
86724 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
86725
86726-static struct devinet_sysctl_table {
86727+static const struct devinet_sysctl_table {
86728 struct ctl_table_header *sysctl_header;
86729 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
86730 } devinet_sysctl = {
86731@@ -1881,7 +1881,7 @@ static __net_init int devinet_init_net(struct net *net)
86732 int err;
86733 struct ipv4_devconf *all, *dflt;
86734 #ifdef CONFIG_SYSCTL
86735- struct ctl_table *tbl = ctl_forward_entry;
86736+ ctl_table_no_const *tbl = NULL;
86737 struct ctl_table_header *forw_hdr;
86738 #endif
86739
86740@@ -1899,7 +1899,7 @@ static __net_init int devinet_init_net(struct net *net)
86741 goto err_alloc_dflt;
86742
86743 #ifdef CONFIG_SYSCTL
86744- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
86745+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
86746 if (tbl == NULL)
86747 goto err_alloc_ctl;
86748
86749@@ -1919,7 +1919,10 @@ static __net_init int devinet_init_net(struct net *net)
86750 goto err_reg_dflt;
86751
86752 err = -ENOMEM;
86753- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
86754+ if (!net_eq(net, &init_net))
86755+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
86756+ else
86757+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
86758 if (forw_hdr == NULL)
86759 goto err_reg_ctl;
86760 net->ipv4.forw_hdr = forw_hdr;
86761@@ -1935,8 +1938,7 @@ err_reg_ctl:
86762 err_reg_dflt:
86763 __devinet_sysctl_unregister(all);
86764 err_reg_all:
86765- if (tbl != ctl_forward_entry)
86766- kfree(tbl);
86767+ kfree(tbl);
86768 err_alloc_ctl:
86769 #endif
86770 if (dflt != &ipv4_devconf_dflt)
86771diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
86772index 3b4f0cd..a6ba66e 100644
86773--- a/net/ipv4/esp4.c
86774+++ b/net/ipv4/esp4.c
86775@@ -139,8 +139,6 @@ static int esp_output(struct xfrm_state *x, struct sk_buff *skb)
86776
86777 /* skb is pure payload to encrypt */
86778
86779- err = -ENOMEM;
86780-
86781 esp = x->data;
86782 aead = esp->aead;
86783 alen = crypto_aead_authsize(aead);
86784@@ -176,8 +174,10 @@ static int esp_output(struct xfrm_state *x, struct sk_buff *skb)
86785 }
86786
86787 tmp = esp_alloc_tmp(aead, nfrags + sglists, seqhilen);
86788- if (!tmp)
86789+ if (!tmp) {
86790+ err = -ENOMEM;
86791 goto error;
86792+ }
86793
86794 seqhi = esp_tmp_seqhi(tmp);
86795 iv = esp_tmp_iv(aead, tmp, seqhilen);
86796@@ -503,7 +503,7 @@ static void esp4_err(struct sk_buff *skb, u32 info)
86797 return;
86798
86799 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
86800- atomic_inc(&flow_cache_genid);
86801+ atomic_inc_unchecked(&flow_cache_genid);
86802 rt_genid_bump(net);
86803
86804 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_ESP, 0);
86805diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
86806index 5cd75e2..f57ef39 100644
86807--- a/net/ipv4/fib_frontend.c
86808+++ b/net/ipv4/fib_frontend.c
86809@@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
86810 #ifdef CONFIG_IP_ROUTE_MULTIPATH
86811 fib_sync_up(dev);
86812 #endif
86813- atomic_inc(&net->ipv4.dev_addr_genid);
86814+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
86815 rt_cache_flush(dev_net(dev));
86816 break;
86817 case NETDEV_DOWN:
86818 fib_del_ifaddr(ifa, NULL);
86819- atomic_inc(&net->ipv4.dev_addr_genid);
86820+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
86821 if (ifa->ifa_dev->ifa_list == NULL) {
86822 /* Last address was deleted from this interface.
86823 * Disable IP.
86824@@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
86825 #ifdef CONFIG_IP_ROUTE_MULTIPATH
86826 fib_sync_up(dev);
86827 #endif
86828- atomic_inc(&net->ipv4.dev_addr_genid);
86829+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
86830 rt_cache_flush(net);
86831 break;
86832 case NETDEV_DOWN:
86833diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
86834index 4797a80..2bd54e9 100644
86835--- a/net/ipv4/fib_semantics.c
86836+++ b/net/ipv4/fib_semantics.c
86837@@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
86838 nh->nh_saddr = inet_select_addr(nh->nh_dev,
86839 nh->nh_gw,
86840 nh->nh_parent->fib_scope);
86841- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
86842+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
86843
86844 return nh->nh_saddr;
86845 }
86846diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
86847index d0670f0..744ac80 100644
86848--- a/net/ipv4/inet_connection_sock.c
86849+++ b/net/ipv4/inet_connection_sock.c
86850@@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
86851 .range = { 32768, 61000 },
86852 };
86853
86854-unsigned long *sysctl_local_reserved_ports;
86855+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
86856 EXPORT_SYMBOL(sysctl_local_reserved_ports);
86857
86858 void inet_get_local_port_range(int *low, int *high)
86859diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
86860index fa3ae81..0dbe6b8 100644
86861--- a/net/ipv4/inet_hashtables.c
86862+++ b/net/ipv4/inet_hashtables.c
86863@@ -18,12 +18,15 @@
86864 #include <linux/sched.h>
86865 #include <linux/slab.h>
86866 #include <linux/wait.h>
86867+#include <linux/security.h>
86868
86869 #include <net/inet_connection_sock.h>
86870 #include <net/inet_hashtables.h>
86871 #include <net/secure_seq.h>
86872 #include <net/ip.h>
86873
86874+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
86875+
86876 /*
86877 * Allocate and initialize a new local port bind bucket.
86878 * The bindhash mutex for snum's hash chain must be held here.
86879@@ -540,6 +543,8 @@ ok:
86880 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
86881 spin_unlock(&head->lock);
86882
86883+ gr_update_task_in_ip_table(current, inet_sk(sk));
86884+
86885 if (tw) {
86886 inet_twsk_deschedule(tw, death_row);
86887 while (twrefcnt) {
86888diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
86889index 000e3d2..5472da3 100644
86890--- a/net/ipv4/inetpeer.c
86891+++ b/net/ipv4/inetpeer.c
86892@@ -503,8 +503,8 @@ relookup:
86893 if (p) {
86894 p->daddr = *daddr;
86895 atomic_set(&p->refcnt, 1);
86896- atomic_set(&p->rid, 0);
86897- atomic_set(&p->ip_id_count,
86898+ atomic_set_unchecked(&p->rid, 0);
86899+ atomic_set_unchecked(&p->ip_id_count,
86900 (daddr->family == AF_INET) ?
86901 secure_ip_id(daddr->addr.a4) :
86902 secure_ipv6_id(daddr->addr.a6));
86903diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
86904index a8fc332..4ca4ca65 100644
86905--- a/net/ipv4/ip_fragment.c
86906+++ b/net/ipv4/ip_fragment.c
86907@@ -319,7 +319,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
86908 return 0;
86909
86910 start = qp->rid;
86911- end = atomic_inc_return(&peer->rid);
86912+ end = atomic_inc_return_unchecked(&peer->rid);
86913 qp->rid = end;
86914
86915 rc = qp->q.fragments && (end - start) > max;
86916@@ -786,12 +786,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
86917
86918 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
86919 {
86920- struct ctl_table *table;
86921+ ctl_table_no_const *table = NULL;
86922 struct ctl_table_header *hdr;
86923
86924- table = ip4_frags_ns_ctl_table;
86925 if (!net_eq(net, &init_net)) {
86926- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
86927+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
86928 if (table == NULL)
86929 goto err_alloc;
86930
86931@@ -802,9 +801,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
86932 /* Don't export sysctls to unprivileged users */
86933 if (net->user_ns != &init_user_ns)
86934 table[0].procname = NULL;
86935- }
86936+ hdr = register_net_sysctl(net, "net/ipv4", table);
86937+ } else
86938+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
86939
86940- hdr = register_net_sysctl(net, "net/ipv4", table);
86941 if (hdr == NULL)
86942 goto err_reg;
86943
86944@@ -812,8 +812,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
86945 return 0;
86946
86947 err_reg:
86948- if (!net_eq(net, &init_net))
86949- kfree(table);
86950+ kfree(table);
86951 err_alloc:
86952 return -ENOMEM;
86953 }
86954diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
86955index a85062b..2958a9b 100644
86956--- a/net/ipv4/ip_gre.c
86957+++ b/net/ipv4/ip_gre.c
86958@@ -124,7 +124,7 @@ static bool log_ecn_error = true;
86959 module_param(log_ecn_error, bool, 0644);
86960 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
86961
86962-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
86963+static struct rtnl_link_ops ipgre_link_ops;
86964 static int ipgre_tunnel_init(struct net_device *dev);
86965 static void ipgre_tunnel_setup(struct net_device *dev);
86966 static int ipgre_tunnel_bind_dev(struct net_device *dev);
86967@@ -1753,7 +1753,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
86968 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
86969 };
86970
86971-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
86972+static struct rtnl_link_ops ipgre_link_ops = {
86973 .kind = "gre",
86974 .maxtype = IFLA_GRE_MAX,
86975 .policy = ipgre_policy,
86976@@ -1766,7 +1766,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
86977 .fill_info = ipgre_fill_info,
86978 };
86979
86980-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
86981+static struct rtnl_link_ops ipgre_tap_ops = {
86982 .kind = "gretap",
86983 .maxtype = IFLA_GRE_MAX,
86984 .policy = ipgre_policy,
86985diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
86986index d9c4f11..02b82dbc 100644
86987--- a/net/ipv4/ip_sockglue.c
86988+++ b/net/ipv4/ip_sockglue.c
86989@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
86990 len = min_t(unsigned int, len, opt->optlen);
86991 if (put_user(len, optlen))
86992 return -EFAULT;
86993- if (copy_to_user(optval, opt->__data, len))
86994+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
86995+ copy_to_user(optval, opt->__data, len))
86996 return -EFAULT;
86997 return 0;
86998 }
86999@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
87000 if (sk->sk_type != SOCK_STREAM)
87001 return -ENOPROTOOPT;
87002
87003- msg.msg_control = optval;
87004+ msg.msg_control = (void __force_kernel *)optval;
87005 msg.msg_controllen = len;
87006 msg.msg_flags = flags;
87007
87008diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
87009index c3a4233..1412161 100644
87010--- a/net/ipv4/ip_vti.c
87011+++ b/net/ipv4/ip_vti.c
87012@@ -47,7 +47,7 @@
87013 #define HASH_SIZE 16
87014 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&(HASH_SIZE-1))
87015
87016-static struct rtnl_link_ops vti_link_ops __read_mostly;
87017+static struct rtnl_link_ops vti_link_ops;
87018
87019 static int vti_net_id __read_mostly;
87020 struct vti_net {
87021@@ -886,7 +886,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
87022 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
87023 };
87024
87025-static struct rtnl_link_ops vti_link_ops __read_mostly = {
87026+static struct rtnl_link_ops vti_link_ops = {
87027 .kind = "vti",
87028 .maxtype = IFLA_VTI_MAX,
87029 .policy = vti_policy,
87030diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c
87031index 9a46dae..5f793a0 100644
87032--- a/net/ipv4/ipcomp.c
87033+++ b/net/ipv4/ipcomp.c
87034@@ -48,7 +48,7 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
87035 return;
87036
87037 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
87038- atomic_inc(&flow_cache_genid);
87039+ atomic_inc_unchecked(&flow_cache_genid);
87040 rt_genid_bump(net);
87041
87042 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_COMP, 0);
87043diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
87044index a2e50ae..e152b7c 100644
87045--- a/net/ipv4/ipconfig.c
87046+++ b/net/ipv4/ipconfig.c
87047@@ -323,7 +323,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
87048
87049 mm_segment_t oldfs = get_fs();
87050 set_fs(get_ds());
87051- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
87052+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
87053 set_fs(oldfs);
87054 return res;
87055 }
87056@@ -334,7 +334,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
87057
87058 mm_segment_t oldfs = get_fs();
87059 set_fs(get_ds());
87060- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
87061+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
87062 set_fs(oldfs);
87063 return res;
87064 }
87065@@ -345,7 +345,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
87066
87067 mm_segment_t oldfs = get_fs();
87068 set_fs(get_ds());
87069- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
87070+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
87071 set_fs(oldfs);
87072 return res;
87073 }
87074diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
87075index 191fc24..1b3b804 100644
87076--- a/net/ipv4/ipip.c
87077+++ b/net/ipv4/ipip.c
87078@@ -138,7 +138,7 @@ struct ipip_net {
87079 static int ipip_tunnel_init(struct net_device *dev);
87080 static void ipip_tunnel_setup(struct net_device *dev);
87081 static void ipip_dev_free(struct net_device *dev);
87082-static struct rtnl_link_ops ipip_link_ops __read_mostly;
87083+static struct rtnl_link_ops ipip_link_ops;
87084
87085 static struct rtnl_link_stats64 *ipip_get_stats64(struct net_device *dev,
87086 struct rtnl_link_stats64 *tot)
87087@@ -972,7 +972,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
87088 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
87089 };
87090
87091-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
87092+static struct rtnl_link_ops ipip_link_ops = {
87093 .kind = "ipip",
87094 .maxtype = IFLA_IPTUN_MAX,
87095 .policy = ipip_policy,
87096diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
87097index 3ea4127..849297b 100644
87098--- a/net/ipv4/netfilter/arp_tables.c
87099+++ b/net/ipv4/netfilter/arp_tables.c
87100@@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
87101 #endif
87102
87103 static int get_info(struct net *net, void __user *user,
87104- const int *len, int compat)
87105+ int len, int compat)
87106 {
87107 char name[XT_TABLE_MAXNAMELEN];
87108 struct xt_table *t;
87109 int ret;
87110
87111- if (*len != sizeof(struct arpt_getinfo)) {
87112- duprintf("length %u != %Zu\n", *len,
87113+ if (len != sizeof(struct arpt_getinfo)) {
87114+ duprintf("length %u != %Zu\n", len,
87115 sizeof(struct arpt_getinfo));
87116 return -EINVAL;
87117 }
87118@@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
87119 info.size = private->size;
87120 strcpy(info.name, name);
87121
87122- if (copy_to_user(user, &info, *len) != 0)
87123+ if (copy_to_user(user, &info, len) != 0)
87124 ret = -EFAULT;
87125 else
87126 ret = 0;
87127@@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
87128
87129 switch (cmd) {
87130 case ARPT_SO_GET_INFO:
87131- ret = get_info(sock_net(sk), user, len, 1);
87132+ ret = get_info(sock_net(sk), user, *len, 1);
87133 break;
87134 case ARPT_SO_GET_ENTRIES:
87135 ret = compat_get_entries(sock_net(sk), user, len);
87136@@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
87137
87138 switch (cmd) {
87139 case ARPT_SO_GET_INFO:
87140- ret = get_info(sock_net(sk), user, len, 0);
87141+ ret = get_info(sock_net(sk), user, *len, 0);
87142 break;
87143
87144 case ARPT_SO_GET_ENTRIES:
87145diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
87146index 17c5e06..1b91206 100644
87147--- a/net/ipv4/netfilter/ip_tables.c
87148+++ b/net/ipv4/netfilter/ip_tables.c
87149@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
87150 #endif
87151
87152 static int get_info(struct net *net, void __user *user,
87153- const int *len, int compat)
87154+ int len, int compat)
87155 {
87156 char name[XT_TABLE_MAXNAMELEN];
87157 struct xt_table *t;
87158 int ret;
87159
87160- if (*len != sizeof(struct ipt_getinfo)) {
87161- duprintf("length %u != %zu\n", *len,
87162+ if (len != sizeof(struct ipt_getinfo)) {
87163+ duprintf("length %u != %zu\n", len,
87164 sizeof(struct ipt_getinfo));
87165 return -EINVAL;
87166 }
87167@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
87168 info.size = private->size;
87169 strcpy(info.name, name);
87170
87171- if (copy_to_user(user, &info, *len) != 0)
87172+ if (copy_to_user(user, &info, len) != 0)
87173 ret = -EFAULT;
87174 else
87175 ret = 0;
87176@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
87177
87178 switch (cmd) {
87179 case IPT_SO_GET_INFO:
87180- ret = get_info(sock_net(sk), user, len, 1);
87181+ ret = get_info(sock_net(sk), user, *len, 1);
87182 break;
87183 case IPT_SO_GET_ENTRIES:
87184 ret = compat_get_entries(sock_net(sk), user, len);
87185@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
87186
87187 switch (cmd) {
87188 case IPT_SO_GET_INFO:
87189- ret = get_info(sock_net(sk), user, len, 0);
87190+ ret = get_info(sock_net(sk), user, *len, 0);
87191 break;
87192
87193 case IPT_SO_GET_ENTRIES:
87194diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
87195index dc454cc..5bb917f 100644
87196--- a/net/ipv4/ping.c
87197+++ b/net/ipv4/ping.c
87198@@ -844,7 +844,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
87199 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
87200 0, sock_i_ino(sp),
87201 atomic_read(&sp->sk_refcnt), sp,
87202- atomic_read(&sp->sk_drops), len);
87203+ atomic_read_unchecked(&sp->sk_drops), len);
87204 }
87205
87206 static int ping_seq_show(struct seq_file *seq, void *v)
87207diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
87208index 6f08991..55867ad 100644
87209--- a/net/ipv4/raw.c
87210+++ b/net/ipv4/raw.c
87211@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
87212 int raw_rcv(struct sock *sk, struct sk_buff *skb)
87213 {
87214 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
87215- atomic_inc(&sk->sk_drops);
87216+ atomic_inc_unchecked(&sk->sk_drops);
87217 kfree_skb(skb);
87218 return NET_RX_DROP;
87219 }
87220@@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
87221
87222 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
87223 {
87224+ struct icmp_filter filter;
87225+
87226 if (optlen > sizeof(struct icmp_filter))
87227 optlen = sizeof(struct icmp_filter);
87228- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
87229+ if (copy_from_user(&filter, optval, optlen))
87230 return -EFAULT;
87231+ raw_sk(sk)->filter = filter;
87232 return 0;
87233 }
87234
87235 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
87236 {
87237 int len, ret = -EFAULT;
87238+ struct icmp_filter filter;
87239
87240 if (get_user(len, optlen))
87241 goto out;
87242@@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
87243 if (len > sizeof(struct icmp_filter))
87244 len = sizeof(struct icmp_filter);
87245 ret = -EFAULT;
87246- if (put_user(len, optlen) ||
87247- copy_to_user(optval, &raw_sk(sk)->filter, len))
87248+ filter = raw_sk(sk)->filter;
87249+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
87250 goto out;
87251 ret = 0;
87252 out: return ret;
87253@@ -998,7 +1002,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
87254 0, 0L, 0,
87255 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
87256 0, sock_i_ino(sp),
87257- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
87258+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
87259 }
87260
87261 static int raw_seq_show(struct seq_file *seq, void *v)
87262diff --git a/net/ipv4/route.c b/net/ipv4/route.c
87263index a0fcc47..32e2c89 100644
87264--- a/net/ipv4/route.c
87265+++ b/net/ipv4/route.c
87266@@ -2552,34 +2552,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
87267 .maxlen = sizeof(int),
87268 .mode = 0200,
87269 .proc_handler = ipv4_sysctl_rtcache_flush,
87270+ .extra1 = &init_net,
87271 },
87272 { },
87273 };
87274
87275 static __net_init int sysctl_route_net_init(struct net *net)
87276 {
87277- struct ctl_table *tbl;
87278+ ctl_table_no_const *tbl = NULL;
87279
87280- tbl = ipv4_route_flush_table;
87281 if (!net_eq(net, &init_net)) {
87282- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
87283+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
87284 if (tbl == NULL)
87285 goto err_dup;
87286
87287 /* Don't export sysctls to unprivileged users */
87288 if (net->user_ns != &init_user_ns)
87289 tbl[0].procname = NULL;
87290- }
87291- tbl[0].extra1 = net;
87292+ tbl[0].extra1 = net;
87293+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
87294+ } else
87295+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
87296
87297- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
87298 if (net->ipv4.route_hdr == NULL)
87299 goto err_reg;
87300 return 0;
87301
87302 err_reg:
87303- if (tbl != ipv4_route_flush_table)
87304- kfree(tbl);
87305+ kfree(tbl);
87306 err_dup:
87307 return -ENOMEM;
87308 }
87309@@ -2602,7 +2602,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
87310
87311 static __net_init int rt_genid_init(struct net *net)
87312 {
87313- atomic_set(&net->rt_genid, 0);
87314+ atomic_set_unchecked(&net->rt_genid, 0);
87315 get_random_bytes(&net->ipv4.dev_addr_genid,
87316 sizeof(net->ipv4.dev_addr_genid));
87317 return 0;
87318diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c
87319index b236ef04..f962f19 100644
87320--- a/net/ipv4/syncookies.c
87321+++ b/net/ipv4/syncookies.c
87322@@ -348,8 +348,8 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
87323 * hasn't changed since we received the original syn, but I see
87324 * no easy way to do this.
87325 */
87326- flowi4_init_output(&fl4, 0, sk->sk_mark, RT_CONN_FLAGS(sk),
87327- RT_SCOPE_UNIVERSE, IPPROTO_TCP,
87328+ flowi4_init_output(&fl4, sk->sk_bound_dev_if, sk->sk_mark,
87329+ RT_CONN_FLAGS(sk), RT_SCOPE_UNIVERSE, IPPROTO_TCP,
87330 inet_sk_flowi_flags(sk),
87331 (opt && opt->srr) ? opt->faddr : ireq->rmt_addr,
87332 ireq->loc_addr, th->source, th->dest);
87333diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
87334index d84400b..62e066e 100644
87335--- a/net/ipv4/sysctl_net_ipv4.c
87336+++ b/net/ipv4/sysctl_net_ipv4.c
87337@@ -54,7 +54,7 @@ static int ipv4_local_port_range(ctl_table *table, int write,
87338 {
87339 int ret;
87340 int range[2];
87341- ctl_table tmp = {
87342+ ctl_table_no_const tmp = {
87343 .data = &range,
87344 .maxlen = sizeof(range),
87345 .mode = table->mode,
87346@@ -107,7 +107,7 @@ static int ipv4_ping_group_range(ctl_table *table, int write,
87347 int ret;
87348 gid_t urange[2];
87349 kgid_t low, high;
87350- ctl_table tmp = {
87351+ ctl_table_no_const tmp = {
87352 .data = &urange,
87353 .maxlen = sizeof(urange),
87354 .mode = table->mode,
87355@@ -138,7 +138,7 @@ static int proc_tcp_congestion_control(ctl_table *ctl, int write,
87356 void __user *buffer, size_t *lenp, loff_t *ppos)
87357 {
87358 char val[TCP_CA_NAME_MAX];
87359- ctl_table tbl = {
87360+ ctl_table_no_const tbl = {
87361 .data = val,
87362 .maxlen = TCP_CA_NAME_MAX,
87363 };
87364@@ -157,7 +157,7 @@ static int proc_tcp_available_congestion_control(ctl_table *ctl,
87365 void __user *buffer, size_t *lenp,
87366 loff_t *ppos)
87367 {
87368- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
87369+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
87370 int ret;
87371
87372 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
87373@@ -174,7 +174,7 @@ static int proc_allowed_congestion_control(ctl_table *ctl,
87374 void __user *buffer, size_t *lenp,
87375 loff_t *ppos)
87376 {
87377- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
87378+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
87379 int ret;
87380
87381 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
87382@@ -200,15 +200,17 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
87383 struct mem_cgroup *memcg;
87384 #endif
87385
87386- ctl_table tmp = {
87387+ ctl_table_no_const tmp = {
87388 .data = &vec,
87389 .maxlen = sizeof(vec),
87390 .mode = ctl->mode,
87391 };
87392
87393 if (!write) {
87394- ctl->data = &net->ipv4.sysctl_tcp_mem;
87395- return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
87396+ ctl_table_no_const tcp_mem = *ctl;
87397+
87398+ tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
87399+ return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
87400 }
87401
87402 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
87403@@ -235,7 +237,7 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
87404 int proc_tcp_fastopen_key(ctl_table *ctl, int write, void __user *buffer,
87405 size_t *lenp, loff_t *ppos)
87406 {
87407- ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
87408+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
87409 struct tcp_fastopen_context *ctxt;
87410 int ret;
87411 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
87412@@ -476,7 +478,7 @@ static struct ctl_table ipv4_table[] = {
87413 },
87414 {
87415 .procname = "ip_local_reserved_ports",
87416- .data = NULL, /* initialized in sysctl_ipv4_init */
87417+ .data = sysctl_local_reserved_ports,
87418 .maxlen = 65536,
87419 .mode = 0644,
87420 .proc_handler = proc_do_large_bitmap,
87421@@ -860,11 +862,10 @@ static struct ctl_table ipv4_net_table[] = {
87422
87423 static __net_init int ipv4_sysctl_init_net(struct net *net)
87424 {
87425- struct ctl_table *table;
87426+ ctl_table_no_const *table = NULL;
87427
87428- table = ipv4_net_table;
87429 if (!net_eq(net, &init_net)) {
87430- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
87431+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
87432 if (table == NULL)
87433 goto err_alloc;
87434
87435@@ -897,15 +898,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
87436
87437 tcp_init_mem(net);
87438
87439- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
87440+ if (!net_eq(net, &init_net))
87441+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
87442+ else
87443+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
87444 if (net->ipv4.ipv4_hdr == NULL)
87445 goto err_reg;
87446
87447 return 0;
87448
87449 err_reg:
87450- if (!net_eq(net, &init_net))
87451- kfree(table);
87452+ kfree(table);
87453 err_alloc:
87454 return -ENOMEM;
87455 }
87456@@ -927,16 +930,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
87457 static __init int sysctl_ipv4_init(void)
87458 {
87459 struct ctl_table_header *hdr;
87460- struct ctl_table *i;
87461-
87462- for (i = ipv4_table; i->procname; i++) {
87463- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
87464- i->data = sysctl_local_reserved_ports;
87465- break;
87466- }
87467- }
87468- if (!i->procname)
87469- return -EINVAL;
87470
87471 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
87472 if (hdr == NULL)
87473diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
87474index 9841a71..ef60409 100644
87475--- a/net/ipv4/tcp_input.c
87476+++ b/net/ipv4/tcp_input.c
87477@@ -4730,7 +4730,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
87478 * simplifies code)
87479 */
87480 static void
87481-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
87482+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
87483 struct sk_buff *head, struct sk_buff *tail,
87484 u32 start, u32 end)
87485 {
87486@@ -5847,6 +5847,7 @@ discard:
87487 tcp_paws_reject(&tp->rx_opt, 0))
87488 goto discard_and_undo;
87489
87490+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
87491 if (th->syn) {
87492 /* We see SYN without ACK. It is attempt of
87493 * simultaneous connect with crossed SYNs.
87494@@ -5897,6 +5898,7 @@ discard:
87495 goto discard;
87496 #endif
87497 }
87498+#endif
87499 /* "fifth, if neither of the SYN or RST bits is set then
87500 * drop the segment and return."
87501 */
87502@@ -5941,7 +5943,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
87503 goto discard;
87504
87505 if (th->syn) {
87506- if (th->fin)
87507+ if (th->fin || th->urg || th->psh)
87508 goto discard;
87509 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
87510 return 1;
87511diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
87512index d9130a9..00328ff 100644
87513--- a/net/ipv4/tcp_ipv4.c
87514+++ b/net/ipv4/tcp_ipv4.c
87515@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
87516 EXPORT_SYMBOL(sysctl_tcp_low_latency);
87517
87518
87519+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87520+extern int grsec_enable_blackhole;
87521+#endif
87522+
87523 #ifdef CONFIG_TCP_MD5SIG
87524 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
87525 __be32 daddr, __be32 saddr, const struct tcphdr *th);
87526@@ -1895,6 +1899,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
87527 return 0;
87528
87529 reset:
87530+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87531+ if (!grsec_enable_blackhole)
87532+#endif
87533 tcp_v4_send_reset(rsk, skb);
87534 discard:
87535 kfree_skb(skb);
87536@@ -1994,12 +2001,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
87537 TCP_SKB_CB(skb)->sacked = 0;
87538
87539 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
87540- if (!sk)
87541+ if (!sk) {
87542+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87543+ ret = 1;
87544+#endif
87545 goto no_tcp_socket;
87546-
87547+ }
87548 process:
87549- if (sk->sk_state == TCP_TIME_WAIT)
87550+ if (sk->sk_state == TCP_TIME_WAIT) {
87551+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87552+ ret = 2;
87553+#endif
87554 goto do_time_wait;
87555+ }
87556
87557 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
87558 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
87559@@ -2050,6 +2064,10 @@ no_tcp_socket:
87560 bad_packet:
87561 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
87562 } else {
87563+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87564+ if (!grsec_enable_blackhole || (ret == 1 &&
87565+ (skb->dev->flags & IFF_LOOPBACK)))
87566+#endif
87567 tcp_v4_send_reset(NULL, skb);
87568 }
87569
87570diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
87571index f35f2df..ccb5ca6 100644
87572--- a/net/ipv4/tcp_minisocks.c
87573+++ b/net/ipv4/tcp_minisocks.c
87574@@ -27,6 +27,10 @@
87575 #include <net/inet_common.h>
87576 #include <net/xfrm.h>
87577
87578+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87579+extern int grsec_enable_blackhole;
87580+#endif
87581+
87582 int sysctl_tcp_syncookies __read_mostly = 1;
87583 EXPORT_SYMBOL(sysctl_tcp_syncookies);
87584
87585@@ -742,7 +746,10 @@ embryonic_reset:
87586 * avoid becoming vulnerable to outside attack aiming at
87587 * resetting legit local connections.
87588 */
87589- req->rsk_ops->send_reset(sk, skb);
87590+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87591+ if (!grsec_enable_blackhole)
87592+#endif
87593+ req->rsk_ops->send_reset(sk, skb);
87594 } else if (fastopen) { /* received a valid RST pkt */
87595 reqsk_fastopen_remove(sk, req, true);
87596 tcp_reset(sk);
87597diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
87598index 17d659e..a9f50ee 100644
87599--- a/net/ipv4/tcp_output.c
87600+++ b/net/ipv4/tcp_output.c
87601@@ -2388,8 +2388,12 @@ int __tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb)
87602 */
87603 TCP_SKB_CB(skb)->when = tcp_time_stamp;
87604
87605- /* make sure skb->data is aligned on arches that require it */
87606- if (unlikely(NET_IP_ALIGN && ((unsigned long)skb->data & 3))) {
87607+ /* make sure skb->data is aligned on arches that require it
87608+ * and check if ack-trimming & collapsing extended the headroom
87609+ * beyond what csum_start can cover.
87610+ */
87611+ if (unlikely((NET_IP_ALIGN && ((unsigned long)skb->data & 3)) ||
87612+ skb_headroom(skb) >= 0xFFFF)) {
87613 struct sk_buff *nskb = __pskb_copy(skb, MAX_TCP_HEADER,
87614 GFP_ATOMIC);
87615 return nskb ? tcp_transmit_skb(sk, nskb, 0, GFP_ATOMIC) :
87616diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
87617index 4526fe6..1a34e43 100644
87618--- a/net/ipv4/tcp_probe.c
87619+++ b/net/ipv4/tcp_probe.c
87620@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
87621 if (cnt + width >= len)
87622 break;
87623
87624- if (copy_to_user(buf + cnt, tbuf, width))
87625+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
87626 return -EFAULT;
87627 cnt += width;
87628 }
87629diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
87630index b78aac3..e18230b 100644
87631--- a/net/ipv4/tcp_timer.c
87632+++ b/net/ipv4/tcp_timer.c
87633@@ -22,6 +22,10 @@
87634 #include <linux/gfp.h>
87635 #include <net/tcp.h>
87636
87637+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87638+extern int grsec_lastack_retries;
87639+#endif
87640+
87641 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
87642 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
87643 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
87644@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
87645 }
87646 }
87647
87648+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87649+ if ((sk->sk_state == TCP_LAST_ACK) &&
87650+ (grsec_lastack_retries > 0) &&
87651+ (grsec_lastack_retries < retry_until))
87652+ retry_until = grsec_lastack_retries;
87653+#endif
87654+
87655 if (retransmits_timed_out(sk, retry_until,
87656 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
87657 /* Has it gone just too far? */
87658diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
87659index 1f4d405..3524677 100644
87660--- a/net/ipv4/udp.c
87661+++ b/net/ipv4/udp.c
87662@@ -87,6 +87,7 @@
87663 #include <linux/types.h>
87664 #include <linux/fcntl.h>
87665 #include <linux/module.h>
87666+#include <linux/security.h>
87667 #include <linux/socket.h>
87668 #include <linux/sockios.h>
87669 #include <linux/igmp.h>
87670@@ -111,6 +112,10 @@
87671 #include <trace/events/skb.h>
87672 #include "udp_impl.h"
87673
87674+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87675+extern int grsec_enable_blackhole;
87676+#endif
87677+
87678 struct udp_table udp_table __read_mostly;
87679 EXPORT_SYMBOL(udp_table);
87680
87681@@ -569,6 +574,9 @@ found:
87682 return s;
87683 }
87684
87685+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
87686+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
87687+
87688 /*
87689 * This routine is called by the ICMP module when it gets some
87690 * sort of error condition. If err < 0 then the socket should
87691@@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
87692 dport = usin->sin_port;
87693 if (dport == 0)
87694 return -EINVAL;
87695+
87696+ err = gr_search_udp_sendmsg(sk, usin);
87697+ if (err)
87698+ return err;
87699 } else {
87700 if (sk->sk_state != TCP_ESTABLISHED)
87701 return -EDESTADDRREQ;
87702+
87703+ err = gr_search_udp_sendmsg(sk, NULL);
87704+ if (err)
87705+ return err;
87706+
87707 daddr = inet->inet_daddr;
87708 dport = inet->inet_dport;
87709 /* Open fast path for connected socket.
87710@@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
87711 udp_lib_checksum_complete(skb)) {
87712 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
87713 IS_UDPLITE(sk));
87714- atomic_inc(&sk->sk_drops);
87715+ atomic_inc_unchecked(&sk->sk_drops);
87716 __skb_unlink(skb, rcvq);
87717 __skb_queue_tail(&list_kill, skb);
87718 }
87719@@ -1194,6 +1211,10 @@ try_again:
87720 if (!skb)
87721 goto out;
87722
87723+ err = gr_search_udp_recvmsg(sk, skb);
87724+ if (err)
87725+ goto out_free;
87726+
87727 ulen = skb->len - sizeof(struct udphdr);
87728 copied = len;
87729 if (copied > ulen)
87730@@ -1227,7 +1248,7 @@ try_again:
87731 if (unlikely(err)) {
87732 trace_kfree_skb(skb, udp_recvmsg);
87733 if (!peeked) {
87734- atomic_inc(&sk->sk_drops);
87735+ atomic_inc_unchecked(&sk->sk_drops);
87736 UDP_INC_STATS_USER(sock_net(sk),
87737 UDP_MIB_INERRORS, is_udplite);
87738 }
87739@@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
87740
87741 drop:
87742 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
87743- atomic_inc(&sk->sk_drops);
87744+ atomic_inc_unchecked(&sk->sk_drops);
87745 kfree_skb(skb);
87746 return -1;
87747 }
87748@@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
87749 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
87750
87751 if (!skb1) {
87752- atomic_inc(&sk->sk_drops);
87753+ atomic_inc_unchecked(&sk->sk_drops);
87754 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
87755 IS_UDPLITE(sk));
87756 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
87757@@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
87758 goto csum_error;
87759
87760 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
87761+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87762+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
87763+#endif
87764 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
87765
87766 /*
87767@@ -2120,7 +2144,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
87768 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
87769 0, sock_i_ino(sp),
87770 atomic_read(&sp->sk_refcnt), sp,
87771- atomic_read(&sp->sk_drops), len);
87772+ atomic_read_unchecked(&sp->sk_drops), len);
87773 }
87774
87775 int udp4_seq_show(struct seq_file *seq, void *v)
87776diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
87777index a36d17e..96d099f 100644
87778--- a/net/ipv6/addrconf.c
87779+++ b/net/ipv6/addrconf.c
87780@@ -2272,7 +2272,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
87781 p.iph.ihl = 5;
87782 p.iph.protocol = IPPROTO_IPV6;
87783 p.iph.ttl = 64;
87784- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
87785+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
87786
87787 if (ops->ndo_do_ioctl) {
87788 mm_segment_t oldfs = get_fs();
87789@@ -4388,7 +4388,7 @@ int addrconf_sysctl_forward(ctl_table *ctl, int write,
87790 int *valp = ctl->data;
87791 int val = *valp;
87792 loff_t pos = *ppos;
87793- ctl_table lctl;
87794+ ctl_table_no_const lctl;
87795 int ret;
87796
87797 /*
87798@@ -4470,7 +4470,7 @@ int addrconf_sysctl_disable(ctl_table *ctl, int write,
87799 int *valp = ctl->data;
87800 int val = *valp;
87801 loff_t pos = *ppos;
87802- ctl_table lctl;
87803+ ctl_table_no_const lctl;
87804 int ret;
87805
87806 /*
87807diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
87808index fff5bdd..15194fb 100644
87809--- a/net/ipv6/icmp.c
87810+++ b/net/ipv6/icmp.c
87811@@ -973,7 +973,7 @@ ctl_table ipv6_icmp_table_template[] = {
87812
87813 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
87814 {
87815- struct ctl_table *table;
87816+ ctl_table_no_const *table;
87817
87818 table = kmemdup(ipv6_icmp_table_template,
87819 sizeof(ipv6_icmp_table_template),
87820diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
87821index 131dd09..f7ed64f 100644
87822--- a/net/ipv6/ip6_gre.c
87823+++ b/net/ipv6/ip6_gre.c
87824@@ -73,7 +73,7 @@ struct ip6gre_net {
87825 struct net_device *fb_tunnel_dev;
87826 };
87827
87828-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
87829+static struct rtnl_link_ops ip6gre_link_ops;
87830 static int ip6gre_tunnel_init(struct net_device *dev);
87831 static void ip6gre_tunnel_setup(struct net_device *dev);
87832 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
87833@@ -1337,7 +1337,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
87834 }
87835
87836
87837-static struct inet6_protocol ip6gre_protocol __read_mostly = {
87838+static struct inet6_protocol ip6gre_protocol = {
87839 .handler = ip6gre_rcv,
87840 .err_handler = ip6gre_err,
87841 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
87842@@ -1671,7 +1671,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
87843 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
87844 };
87845
87846-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
87847+static struct rtnl_link_ops ip6gre_link_ops = {
87848 .kind = "ip6gre",
87849 .maxtype = IFLA_GRE_MAX,
87850 .policy = ip6gre_policy,
87851@@ -1684,7 +1684,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
87852 .fill_info = ip6gre_fill_info,
87853 };
87854
87855-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
87856+static struct rtnl_link_ops ip6gre_tap_ops = {
87857 .kind = "ip6gretap",
87858 .maxtype = IFLA_GRE_MAX,
87859 .policy = ip6gre_policy,
87860diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
87861index a14f28b..b4b8956 100644
87862--- a/net/ipv6/ip6_tunnel.c
87863+++ b/net/ipv6/ip6_tunnel.c
87864@@ -87,7 +87,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
87865
87866 static int ip6_tnl_dev_init(struct net_device *dev);
87867 static void ip6_tnl_dev_setup(struct net_device *dev);
87868-static struct rtnl_link_ops ip6_link_ops __read_mostly;
87869+static struct rtnl_link_ops ip6_link_ops;
87870
87871 static int ip6_tnl_net_id __read_mostly;
87872 struct ip6_tnl_net {
87873@@ -1686,7 +1686,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
87874 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
87875 };
87876
87877-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
87878+static struct rtnl_link_ops ip6_link_ops = {
87879 .kind = "ip6tnl",
87880 .maxtype = IFLA_IPTUN_MAX,
87881 .policy = ip6_tnl_policy,
87882diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
87883index d1e2e8e..51c19ae 100644
87884--- a/net/ipv6/ipv6_sockglue.c
87885+++ b/net/ipv6/ipv6_sockglue.c
87886@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
87887 if (sk->sk_type != SOCK_STREAM)
87888 return -ENOPROTOOPT;
87889
87890- msg.msg_control = optval;
87891+ msg.msg_control = (void __force_kernel *)optval;
87892 msg.msg_controllen = len;
87893 msg.msg_flags = flags;
87894
87895diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
87896index 125a90d..2a11f36 100644
87897--- a/net/ipv6/netfilter/ip6_tables.c
87898+++ b/net/ipv6/netfilter/ip6_tables.c
87899@@ -1076,14 +1076,14 @@ static int compat_table_info(const struct xt_table_info *info,
87900 #endif
87901
87902 static int get_info(struct net *net, void __user *user,
87903- const int *len, int compat)
87904+ int len, int compat)
87905 {
87906 char name[XT_TABLE_MAXNAMELEN];
87907 struct xt_table *t;
87908 int ret;
87909
87910- if (*len != sizeof(struct ip6t_getinfo)) {
87911- duprintf("length %u != %zu\n", *len,
87912+ if (len != sizeof(struct ip6t_getinfo)) {
87913+ duprintf("length %u != %zu\n", len,
87914 sizeof(struct ip6t_getinfo));
87915 return -EINVAL;
87916 }
87917@@ -1120,7 +1120,7 @@ static int get_info(struct net *net, void __user *user,
87918 info.size = private->size;
87919 strcpy(info.name, name);
87920
87921- if (copy_to_user(user, &info, *len) != 0)
87922+ if (copy_to_user(user, &info, len) != 0)
87923 ret = -EFAULT;
87924 else
87925 ret = 0;
87926@@ -1974,7 +1974,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
87927
87928 switch (cmd) {
87929 case IP6T_SO_GET_INFO:
87930- ret = get_info(sock_net(sk), user, len, 1);
87931+ ret = get_info(sock_net(sk), user, *len, 1);
87932 break;
87933 case IP6T_SO_GET_ENTRIES:
87934 ret = compat_get_entries(sock_net(sk), user, len);
87935@@ -2021,7 +2021,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
87936
87937 switch (cmd) {
87938 case IP6T_SO_GET_INFO:
87939- ret = get_info(sock_net(sk), user, len, 0);
87940+ ret = get_info(sock_net(sk), user, *len, 0);
87941 break;
87942
87943 case IP6T_SO_GET_ENTRIES:
87944diff --git a/net/ipv6/netfilter/ip6t_NPT.c b/net/ipv6/netfilter/ip6t_NPT.c
87945index 83acc14..0ea43c7 100644
87946--- a/net/ipv6/netfilter/ip6t_NPT.c
87947+++ b/net/ipv6/netfilter/ip6t_NPT.c
87948@@ -57,7 +57,7 @@ static bool ip6t_npt_map_pfx(const struct ip6t_npt_tginfo *npt,
87949 if (pfx_len - i >= 32)
87950 mask = 0;
87951 else
87952- mask = htonl(~((1 << (pfx_len - i)) - 1));
87953+ mask = htonl((1 << (i - pfx_len + 32)) - 1);
87954
87955 idx = i / 32;
87956 addr->s6_addr32[idx] &= mask;
87957diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
87958index 2f3a018..8bca195 100644
87959--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
87960+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
87961@@ -89,12 +89,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
87962
87963 static int nf_ct_frag6_sysctl_register(struct net *net)
87964 {
87965- struct ctl_table *table;
87966+ ctl_table_no_const *table = NULL;
87967 struct ctl_table_header *hdr;
87968
87969- table = nf_ct_frag6_sysctl_table;
87970 if (!net_eq(net, &init_net)) {
87971- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
87972+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
87973 GFP_KERNEL);
87974 if (table == NULL)
87975 goto err_alloc;
87976@@ -102,9 +101,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
87977 table[0].data = &net->ipv6.frags.high_thresh;
87978 table[1].data = &net->ipv6.frags.low_thresh;
87979 table[2].data = &net->ipv6.frags.timeout;
87980- }
87981-
87982- hdr = register_net_sysctl(net, "net/netfilter", table);
87983+ hdr = register_net_sysctl(net, "net/netfilter", table);
87984+ } else
87985+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
87986 if (hdr == NULL)
87987 goto err_reg;
87988
87989@@ -112,8 +111,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
87990 return 0;
87991
87992 err_reg:
87993- if (!net_eq(net, &init_net))
87994- kfree(table);
87995+ kfree(table);
87996 err_alloc:
87997 return -ENOMEM;
87998 }
87999diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
88000index 70fa814..d70c28c 100644
88001--- a/net/ipv6/raw.c
88002+++ b/net/ipv6/raw.c
88003@@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
88004 {
88005 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
88006 skb_checksum_complete(skb)) {
88007- atomic_inc(&sk->sk_drops);
88008+ atomic_inc_unchecked(&sk->sk_drops);
88009 kfree_skb(skb);
88010 return NET_RX_DROP;
88011 }
88012@@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
88013 struct raw6_sock *rp = raw6_sk(sk);
88014
88015 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
88016- atomic_inc(&sk->sk_drops);
88017+ atomic_inc_unchecked(&sk->sk_drops);
88018 kfree_skb(skb);
88019 return NET_RX_DROP;
88020 }
88021@@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
88022
88023 if (inet->hdrincl) {
88024 if (skb_checksum_complete(skb)) {
88025- atomic_inc(&sk->sk_drops);
88026+ atomic_inc_unchecked(&sk->sk_drops);
88027 kfree_skb(skb);
88028 return NET_RX_DROP;
88029 }
88030@@ -604,7 +604,7 @@ out:
88031 return err;
88032 }
88033
88034-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
88035+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
88036 struct flowi6 *fl6, struct dst_entry **dstp,
88037 unsigned int flags)
88038 {
88039@@ -916,12 +916,15 @@ do_confirm:
88040 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
88041 char __user *optval, int optlen)
88042 {
88043+ struct icmp6_filter filter;
88044+
88045 switch (optname) {
88046 case ICMPV6_FILTER:
88047 if (optlen > sizeof(struct icmp6_filter))
88048 optlen = sizeof(struct icmp6_filter);
88049- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
88050+ if (copy_from_user(&filter, optval, optlen))
88051 return -EFAULT;
88052+ raw6_sk(sk)->filter = filter;
88053 return 0;
88054 default:
88055 return -ENOPROTOOPT;
88056@@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
88057 char __user *optval, int __user *optlen)
88058 {
88059 int len;
88060+ struct icmp6_filter filter;
88061
88062 switch (optname) {
88063 case ICMPV6_FILTER:
88064@@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
88065 len = sizeof(struct icmp6_filter);
88066 if (put_user(len, optlen))
88067 return -EFAULT;
88068- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
88069+ filter = raw6_sk(sk)->filter;
88070+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
88071 return -EFAULT;
88072 return 0;
88073 default:
88074@@ -1253,7 +1258,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
88075 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
88076 0,
88077 sock_i_ino(sp),
88078- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
88079+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
88080 }
88081
88082 static int raw6_seq_show(struct seq_file *seq, void *v)
88083diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
88084index d9ba8a2..f3f9e14 100644
88085--- a/net/ipv6/reassembly.c
88086+++ b/net/ipv6/reassembly.c
88087@@ -608,12 +608,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
88088
88089 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
88090 {
88091- struct ctl_table *table;
88092+ ctl_table_no_const *table = NULL;
88093 struct ctl_table_header *hdr;
88094
88095- table = ip6_frags_ns_ctl_table;
88096 if (!net_eq(net, &init_net)) {
88097- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
88098+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
88099 if (table == NULL)
88100 goto err_alloc;
88101
88102@@ -624,9 +623,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
88103 /* Don't export sysctls to unprivileged users */
88104 if (net->user_ns != &init_user_ns)
88105 table[0].procname = NULL;
88106- }
88107+ hdr = register_net_sysctl(net, "net/ipv6", table);
88108+ } else
88109+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
88110
88111- hdr = register_net_sysctl(net, "net/ipv6", table);
88112 if (hdr == NULL)
88113 goto err_reg;
88114
88115@@ -634,8 +634,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
88116 return 0;
88117
88118 err_reg:
88119- if (!net_eq(net, &init_net))
88120- kfree(table);
88121+ kfree(table);
88122 err_alloc:
88123 return -ENOMEM;
88124 }
88125diff --git a/net/ipv6/route.c b/net/ipv6/route.c
88126index 5845613..3af8fc7 100644
88127--- a/net/ipv6/route.c
88128+++ b/net/ipv6/route.c
88129@@ -2966,7 +2966,7 @@ ctl_table ipv6_route_table_template[] = {
88130
88131 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
88132 {
88133- struct ctl_table *table;
88134+ ctl_table_no_const *table;
88135
88136 table = kmemdup(ipv6_route_table_template,
88137 sizeof(ipv6_route_table_template),
88138diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
88139index cfba99b..20ca511 100644
88140--- a/net/ipv6/sit.c
88141+++ b/net/ipv6/sit.c
88142@@ -72,7 +72,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
88143 static int ipip6_tunnel_init(struct net_device *dev);
88144 static void ipip6_tunnel_setup(struct net_device *dev);
88145 static void ipip6_dev_free(struct net_device *dev);
88146-static struct rtnl_link_ops sit_link_ops __read_mostly;
88147+static struct rtnl_link_ops sit_link_ops;
88148
88149 static int sit_net_id __read_mostly;
88150 struct sit_net {
88151@@ -1463,7 +1463,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
88152 #endif
88153 };
88154
88155-static struct rtnl_link_ops sit_link_ops __read_mostly = {
88156+static struct rtnl_link_ops sit_link_ops = {
88157 .kind = "sit",
88158 .maxtype = IFLA_IPTUN_MAX,
88159 .policy = ipip6_policy,
88160diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
88161index e85c48b..b8268d3 100644
88162--- a/net/ipv6/sysctl_net_ipv6.c
88163+++ b/net/ipv6/sysctl_net_ipv6.c
88164@@ -40,7 +40,7 @@ static ctl_table ipv6_rotable[] = {
88165
88166 static int __net_init ipv6_sysctl_net_init(struct net *net)
88167 {
88168- struct ctl_table *ipv6_table;
88169+ ctl_table_no_const *ipv6_table;
88170 struct ctl_table *ipv6_route_table;
88171 struct ctl_table *ipv6_icmp_table;
88172 int err;
88173diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
88174index 8d19346..f122ba5 100644
88175--- a/net/ipv6/tcp_ipv6.c
88176+++ b/net/ipv6/tcp_ipv6.c
88177@@ -103,6 +103,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
88178 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
88179 }
88180
88181+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88182+extern int grsec_enable_blackhole;
88183+#endif
88184+
88185 static void tcp_v6_hash(struct sock *sk)
88186 {
88187 if (sk->sk_state != TCP_CLOSE) {
88188@@ -386,6 +390,7 @@ static void tcp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
88189
88190 if (dst)
88191 dst->ops->redirect(dst, sk, skb);
88192+ goto out;
88193 }
88194
88195 if (type == ICMPV6_PKT_TOOBIG) {
88196@@ -1440,6 +1445,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
88197 return 0;
88198
88199 reset:
88200+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88201+ if (!grsec_enable_blackhole)
88202+#endif
88203 tcp_v6_send_reset(sk, skb);
88204 discard:
88205 if (opt_skb)
88206@@ -1521,12 +1529,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
88207 TCP_SKB_CB(skb)->sacked = 0;
88208
88209 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
88210- if (!sk)
88211+ if (!sk) {
88212+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88213+ ret = 1;
88214+#endif
88215 goto no_tcp_socket;
88216+ }
88217
88218 process:
88219- if (sk->sk_state == TCP_TIME_WAIT)
88220+ if (sk->sk_state == TCP_TIME_WAIT) {
88221+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88222+ ret = 2;
88223+#endif
88224 goto do_time_wait;
88225+ }
88226
88227 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
88228 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
88229@@ -1575,6 +1591,10 @@ no_tcp_socket:
88230 bad_packet:
88231 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
88232 } else {
88233+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88234+ if (!grsec_enable_blackhole || (ret == 1 &&
88235+ (skb->dev->flags & IFF_LOOPBACK)))
88236+#endif
88237 tcp_v6_send_reset(NULL, skb);
88238 }
88239
88240diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
88241index fb08329..2d6919e 100644
88242--- a/net/ipv6/udp.c
88243+++ b/net/ipv6/udp.c
88244@@ -51,6 +51,10 @@
88245 #include <trace/events/skb.h>
88246 #include "udp_impl.h"
88247
88248+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88249+extern int grsec_enable_blackhole;
88250+#endif
88251+
88252 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
88253 {
88254 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
88255@@ -395,7 +399,7 @@ try_again:
88256 if (unlikely(err)) {
88257 trace_kfree_skb(skb, udpv6_recvmsg);
88258 if (!peeked) {
88259- atomic_inc(&sk->sk_drops);
88260+ atomic_inc_unchecked(&sk->sk_drops);
88261 if (is_udp4)
88262 UDP_INC_STATS_USER(sock_net(sk),
88263 UDP_MIB_INERRORS,
88264@@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
88265 return rc;
88266 drop:
88267 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
88268- atomic_inc(&sk->sk_drops);
88269+ atomic_inc_unchecked(&sk->sk_drops);
88270 kfree_skb(skb);
88271 return -1;
88272 }
88273@@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
88274 if (likely(skb1 == NULL))
88275 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
88276 if (!skb1) {
88277- atomic_inc(&sk->sk_drops);
88278+ atomic_inc_unchecked(&sk->sk_drops);
88279 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
88280 IS_UDPLITE(sk));
88281 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
88282@@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
88283 goto discard;
88284
88285 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
88286+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88287+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
88288+#endif
88289 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
88290
88291 kfree_skb(skb);
88292@@ -1379,7 +1386,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
88293 0,
88294 sock_i_ino(sp),
88295 atomic_read(&sp->sk_refcnt), sp,
88296- atomic_read(&sp->sk_drops));
88297+ atomic_read_unchecked(&sp->sk_drops));
88298 }
88299
88300 int udp6_seq_show(struct seq_file *seq, void *v)
88301diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
88302index a68c88c..d55b0c5 100644
88303--- a/net/irda/ircomm/ircomm_tty.c
88304+++ b/net/irda/ircomm/ircomm_tty.c
88305@@ -312,12 +312,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
88306 add_wait_queue(&port->open_wait, &wait);
88307
88308 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
88309- __FILE__, __LINE__, tty->driver->name, port->count);
88310+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
88311
88312 spin_lock_irqsave(&port->lock, flags);
88313 if (!tty_hung_up_p(filp)) {
88314 extra_count = 1;
88315- port->count--;
88316+ atomic_dec(&port->count);
88317 }
88318 spin_unlock_irqrestore(&port->lock, flags);
88319 port->blocked_open++;
88320@@ -353,7 +353,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
88321 }
88322
88323 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
88324- __FILE__, __LINE__, tty->driver->name, port->count);
88325+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
88326
88327 schedule();
88328 }
88329@@ -364,13 +364,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
88330 if (extra_count) {
88331 /* ++ is not atomic, so this should be protected - Jean II */
88332 spin_lock_irqsave(&port->lock, flags);
88333- port->count++;
88334+ atomic_inc(&port->count);
88335 spin_unlock_irqrestore(&port->lock, flags);
88336 }
88337 port->blocked_open--;
88338
88339 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
88340- __FILE__, __LINE__, tty->driver->name, port->count);
88341+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
88342
88343 if (!retval)
88344 port->flags |= ASYNC_NORMAL_ACTIVE;
88345@@ -444,12 +444,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
88346
88347 /* ++ is not atomic, so this should be protected - Jean II */
88348 spin_lock_irqsave(&self->port.lock, flags);
88349- self->port.count++;
88350+ atomic_inc(&self->port.count);
88351 spin_unlock_irqrestore(&self->port.lock, flags);
88352 tty_port_tty_set(&self->port, tty);
88353
88354 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
88355- self->line, self->port.count);
88356+ self->line, atomic_read(&self->port.count));
88357
88358 /* Not really used by us, but lets do it anyway */
88359 tty->low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
88360@@ -986,7 +986,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
88361 tty_kref_put(port->tty);
88362 }
88363 port->tty = NULL;
88364- port->count = 0;
88365+ atomic_set(&port->count, 0);
88366 spin_unlock_irqrestore(&port->lock, flags);
88367
88368 wake_up_interruptible(&port->open_wait);
88369@@ -1343,7 +1343,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
88370 seq_putc(m, '\n');
88371
88372 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
88373- seq_printf(m, "Open count: %d\n", self->port.count);
88374+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
88375 seq_printf(m, "Max data size: %d\n", self->max_data_size);
88376 seq_printf(m, "Max header size: %d\n", self->max_header_size);
88377
88378diff --git a/net/irda/iriap.c b/net/irda/iriap.c
88379index e71e85b..29340a9 100644
88380--- a/net/irda/iriap.c
88381+++ b/net/irda/iriap.c
88382@@ -495,8 +495,11 @@ static void iriap_getvaluebyclass_confirm(struct iriap_cb *self,
88383 /* case CS_ISO_8859_9: */
88384 /* case CS_UNICODE: */
88385 default:
88386- IRDA_DEBUG(0, "%s(), charset %s, not supported\n",
88387- __func__, ias_charset_types[charset]);
88388+ IRDA_DEBUG(0, "%s(), charset [%d] %s, not supported\n",
88389+ __func__, charset,
88390+ charset < ARRAY_SIZE(ias_charset_types) ?
88391+ ias_charset_types[charset] :
88392+ "(unknown)");
88393
88394 /* Aborting, close connection! */
88395 iriap_disconnect_request(self);
88396diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
88397index cd6f7a9..e63fe89 100644
88398--- a/net/iucv/af_iucv.c
88399+++ b/net/iucv/af_iucv.c
88400@@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
88401
88402 write_lock_bh(&iucv_sk_list.lock);
88403
88404- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
88405+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
88406 while (__iucv_get_sock_by_name(name)) {
88407 sprintf(name, "%08x",
88408- atomic_inc_return(&iucv_sk_list.autobind_name));
88409+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
88410 }
88411
88412 write_unlock_bh(&iucv_sk_list.lock);
88413diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
88414index df08250..02021fe 100644
88415--- a/net/iucv/iucv.c
88416+++ b/net/iucv/iucv.c
88417@@ -690,7 +690,7 @@ static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
88418 return NOTIFY_OK;
88419 }
88420
88421-static struct notifier_block __refdata iucv_cpu_notifier = {
88422+static struct notifier_block iucv_cpu_notifier = {
88423 .notifier_call = iucv_cpu_notify,
88424 };
88425
88426diff --git a/net/key/af_key.c b/net/key/af_key.c
88427index 5b426a6..970032b 100644
88428--- a/net/key/af_key.c
88429+++ b/net/key/af_key.c
88430@@ -3019,10 +3019,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
88431 static u32 get_acqseq(void)
88432 {
88433 u32 res;
88434- static atomic_t acqseq;
88435+ static atomic_unchecked_t acqseq;
88436
88437 do {
88438- res = atomic_inc_return(&acqseq);
88439+ res = atomic_inc_return_unchecked(&acqseq);
88440 } while (!res);
88441 return res;
88442 }
88443diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
88444index 49c48c6..9e72ff4 100644
88445--- a/net/mac80211/cfg.c
88446+++ b/net/mac80211/cfg.c
88447@@ -790,7 +790,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
88448 ret = ieee80211_vif_use_channel(sdata, chandef,
88449 IEEE80211_CHANCTX_EXCLUSIVE);
88450 }
88451- } else if (local->open_count == local->monitors) {
88452+ } else if (local_read(&local->open_count) == local->monitors) {
88453 local->_oper_channel = chandef->chan;
88454 local->_oper_channel_type = cfg80211_get_chandef_type(chandef);
88455 ieee80211_hw_config(local, 0);
88456@@ -2718,7 +2718,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
88457 else
88458 local->probe_req_reg--;
88459
88460- if (!local->open_count)
88461+ if (!local_read(&local->open_count))
88462 break;
88463
88464 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
88465diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
88466index 55d8f89..bec0c2b 100644
88467--- a/net/mac80211/ieee80211_i.h
88468+++ b/net/mac80211/ieee80211_i.h
88469@@ -28,6 +28,7 @@
88470 #include <net/ieee80211_radiotap.h>
88471 #include <net/cfg80211.h>
88472 #include <net/mac80211.h>
88473+#include <asm/local.h>
88474 #include "key.h"
88475 #include "sta_info.h"
88476 #include "debug.h"
88477@@ -910,7 +911,7 @@ struct ieee80211_local {
88478 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
88479 spinlock_t queue_stop_reason_lock;
88480
88481- int open_count;
88482+ local_t open_count;
88483 int monitors, cooked_mntrs;
88484 /* number of interfaces with corresponding FIF_ flags */
88485 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
88486diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
88487index 8be854e..ad72a69 100644
88488--- a/net/mac80211/iface.c
88489+++ b/net/mac80211/iface.c
88490@@ -546,7 +546,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
88491 break;
88492 }
88493
88494- if (local->open_count == 0) {
88495+ if (local_read(&local->open_count) == 0) {
88496 res = drv_start(local);
88497 if (res)
88498 goto err_del_bss;
88499@@ -591,7 +591,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
88500 break;
88501 }
88502
88503- if (local->monitors == 0 && local->open_count == 0) {
88504+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
88505 res = ieee80211_add_virtual_monitor(local);
88506 if (res)
88507 goto err_stop;
88508@@ -699,7 +699,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
88509 mutex_unlock(&local->mtx);
88510
88511 if (coming_up)
88512- local->open_count++;
88513+ local_inc(&local->open_count);
88514
88515 if (hw_reconf_flags)
88516 ieee80211_hw_config(local, hw_reconf_flags);
88517@@ -713,7 +713,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
88518 err_del_interface:
88519 drv_remove_interface(local, sdata);
88520 err_stop:
88521- if (!local->open_count)
88522+ if (!local_read(&local->open_count))
88523 drv_stop(local);
88524 err_del_bss:
88525 sdata->bss = NULL;
88526@@ -827,7 +827,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
88527 }
88528
88529 if (going_down)
88530- local->open_count--;
88531+ local_dec(&local->open_count);
88532
88533 switch (sdata->vif.type) {
88534 case NL80211_IFTYPE_AP_VLAN:
88535@@ -884,7 +884,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
88536
88537 ieee80211_recalc_ps(local, -1);
88538
88539- if (local->open_count == 0) {
88540+ if (local_read(&local->open_count) == 0) {
88541 if (local->ops->napi_poll)
88542 napi_disable(&local->napi);
88543 ieee80211_clear_tx_pending(local);
88544@@ -910,7 +910,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
88545 }
88546 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
88547
88548- if (local->monitors == local->open_count && local->monitors > 0)
88549+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
88550 ieee80211_add_virtual_monitor(local);
88551 }
88552
88553diff --git a/net/mac80211/main.c b/net/mac80211/main.c
88554index 1b087ff..bf600e9 100644
88555--- a/net/mac80211/main.c
88556+++ b/net/mac80211/main.c
88557@@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
88558 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
88559 IEEE80211_CONF_CHANGE_POWER);
88560
88561- if (changed && local->open_count) {
88562+ if (changed && local_read(&local->open_count)) {
88563 ret = drv_config(local, changed);
88564 /*
88565 * Goal:
88566diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
88567index 79a48f3..5e185c9 100644
88568--- a/net/mac80211/pm.c
88569+++ b/net/mac80211/pm.c
88570@@ -35,7 +35,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
88571 struct sta_info *sta;
88572 struct ieee80211_chanctx *ctx;
88573
88574- if (!local->open_count)
88575+ if (!local_read(&local->open_count))
88576 goto suspend;
88577
88578 ieee80211_scan_cancel(local);
88579@@ -73,7 +73,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
88580 cancel_work_sync(&local->dynamic_ps_enable_work);
88581 del_timer_sync(&local->dynamic_ps_timer);
88582
88583- local->wowlan = wowlan && local->open_count;
88584+ local->wowlan = wowlan && local_read(&local->open_count);
88585 if (local->wowlan) {
88586 int err = drv_suspend(local, wowlan);
88587 if (err < 0) {
88588@@ -187,7 +187,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
88589 mutex_unlock(&local->chanctx_mtx);
88590
88591 /* stop hardware - this must stop RX */
88592- if (local->open_count)
88593+ if (local_read(&local->open_count))
88594 ieee80211_stop_device(local);
88595
88596 suspend:
88597diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
88598index dd88381..eef4dd6 100644
88599--- a/net/mac80211/rate.c
88600+++ b/net/mac80211/rate.c
88601@@ -493,7 +493,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
88602
88603 ASSERT_RTNL();
88604
88605- if (local->open_count)
88606+ if (local_read(&local->open_count))
88607 return -EBUSY;
88608
88609 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
88610diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
88611index c97a065..ff61928 100644
88612--- a/net/mac80211/rc80211_pid_debugfs.c
88613+++ b/net/mac80211/rc80211_pid_debugfs.c
88614@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
88615
88616 spin_unlock_irqrestore(&events->lock, status);
88617
88618- if (copy_to_user(buf, pb, p))
88619+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
88620 return -EFAULT;
88621
88622 return p;
88623diff --git a/net/mac80211/util.c b/net/mac80211/util.c
88624index f11e8c5..08d0013 100644
88625--- a/net/mac80211/util.c
88626+++ b/net/mac80211/util.c
88627@@ -1380,7 +1380,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
88628 }
88629 #endif
88630 /* everything else happens only if HW was up & running */
88631- if (!local->open_count)
88632+ if (!local_read(&local->open_count))
88633 goto wake_up;
88634
88635 /*
88636diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
88637index 49e96df..63a51c3 100644
88638--- a/net/netfilter/Kconfig
88639+++ b/net/netfilter/Kconfig
88640@@ -936,6 +936,16 @@ config NETFILTER_XT_MATCH_ESP
88641
88642 To compile it as a module, choose M here. If unsure, say N.
88643
88644+config NETFILTER_XT_MATCH_GRADM
88645+ tristate '"gradm" match support'
88646+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
88647+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
88648+ ---help---
88649+ The gradm match allows to match on grsecurity RBAC being enabled.
88650+ It is useful when iptables rules are applied early on bootup to
88651+ prevent connections to the machine (except from a trusted host)
88652+ while the RBAC system is disabled.
88653+
88654 config NETFILTER_XT_MATCH_HASHLIMIT
88655 tristate '"hashlimit" match support'
88656 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
88657diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
88658index 3259697..54d5393 100644
88659--- a/net/netfilter/Makefile
88660+++ b/net/netfilter/Makefile
88661@@ -109,6 +109,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
88662 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
88663 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
88664 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
88665+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
88666 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
88667 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
88668 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
88669diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
88670index 6d6d8f2..a676749 100644
88671--- a/net/netfilter/ipset/ip_set_core.c
88672+++ b/net/netfilter/ipset/ip_set_core.c
88673@@ -1800,7 +1800,7 @@ done:
88674 return ret;
88675 }
88676
88677-static struct nf_sockopt_ops so_set __read_mostly = {
88678+static struct nf_sockopt_ops so_set = {
88679 .pf = PF_INET,
88680 .get_optmin = SO_IP_SET,
88681 .get_optmax = SO_IP_SET + 1,
88682diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
88683index 30e764a..c3b6a9d 100644
88684--- a/net/netfilter/ipvs/ip_vs_conn.c
88685+++ b/net/netfilter/ipvs/ip_vs_conn.c
88686@@ -554,7 +554,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
88687 /* Increase the refcnt counter of the dest */
88688 atomic_inc(&dest->refcnt);
88689
88690- conn_flags = atomic_read(&dest->conn_flags);
88691+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
88692 if (cp->protocol != IPPROTO_UDP)
88693 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
88694 flags = cp->flags;
88695@@ -899,7 +899,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
88696 atomic_set(&cp->refcnt, 1);
88697
88698 atomic_set(&cp->n_control, 0);
88699- atomic_set(&cp->in_pkts, 0);
88700+ atomic_set_unchecked(&cp->in_pkts, 0);
88701
88702 atomic_inc(&ipvs->conn_count);
88703 if (flags & IP_VS_CONN_F_NO_CPORT)
88704@@ -1180,7 +1180,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
88705
88706 /* Don't drop the entry if its number of incoming packets is not
88707 located in [0, 8] */
88708- i = atomic_read(&cp->in_pkts);
88709+ i = atomic_read_unchecked(&cp->in_pkts);
88710 if (i > 8 || i < 0) return 0;
88711
88712 if (!todrop_rate[i]) return 0;
88713diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
88714index 47edf5a..235b07d 100644
88715--- a/net/netfilter/ipvs/ip_vs_core.c
88716+++ b/net/netfilter/ipvs/ip_vs_core.c
88717@@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
88718 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
88719 /* do not touch skb anymore */
88720
88721- atomic_inc(&cp->in_pkts);
88722+ atomic_inc_unchecked(&cp->in_pkts);
88723 ip_vs_conn_put(cp);
88724 return ret;
88725 }
88726@@ -1691,7 +1691,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
88727 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
88728 pkts = sysctl_sync_threshold(ipvs);
88729 else
88730- pkts = atomic_add_return(1, &cp->in_pkts);
88731+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
88732
88733 if (ipvs->sync_state & IP_VS_STATE_MASTER)
88734 ip_vs_sync_conn(net, cp, pkts);
88735diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
88736index ec664cb..7f34a77 100644
88737--- a/net/netfilter/ipvs/ip_vs_ctl.c
88738+++ b/net/netfilter/ipvs/ip_vs_ctl.c
88739@@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
88740 ip_vs_rs_hash(ipvs, dest);
88741 write_unlock_bh(&ipvs->rs_lock);
88742 }
88743- atomic_set(&dest->conn_flags, conn_flags);
88744+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
88745
88746 /* bind the service */
88747 if (!dest->svc) {
88748@@ -1688,7 +1688,7 @@ proc_do_sync_ports(ctl_table *table, int write,
88749 * align with netns init in ip_vs_control_net_init()
88750 */
88751
88752-static struct ctl_table vs_vars[] = {
88753+static ctl_table_no_const vs_vars[] __read_only = {
88754 {
88755 .procname = "amemthresh",
88756 .maxlen = sizeof(int),
88757@@ -2081,7 +2081,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
88758 " %-7s %-6d %-10d %-10d\n",
88759 &dest->addr.in6,
88760 ntohs(dest->port),
88761- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
88762+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
88763 atomic_read(&dest->weight),
88764 atomic_read(&dest->activeconns),
88765 atomic_read(&dest->inactconns));
88766@@ -2092,7 +2092,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
88767 "%-7s %-6d %-10d %-10d\n",
88768 ntohl(dest->addr.ip),
88769 ntohs(dest->port),
88770- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
88771+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
88772 atomic_read(&dest->weight),
88773 atomic_read(&dest->activeconns),
88774 atomic_read(&dest->inactconns));
88775@@ -2562,7 +2562,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
88776
88777 entry.addr = dest->addr.ip;
88778 entry.port = dest->port;
88779- entry.conn_flags = atomic_read(&dest->conn_flags);
88780+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
88781 entry.weight = atomic_read(&dest->weight);
88782 entry.u_threshold = dest->u_threshold;
88783 entry.l_threshold = dest->l_threshold;
88784@@ -3098,7 +3098,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
88785 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
88786 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
88787 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
88788- (atomic_read(&dest->conn_flags) &
88789+ (atomic_read_unchecked(&dest->conn_flags) &
88790 IP_VS_CONN_F_FWD_MASK)) ||
88791 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
88792 atomic_read(&dest->weight)) ||
88793@@ -3688,7 +3688,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
88794 {
88795 int idx;
88796 struct netns_ipvs *ipvs = net_ipvs(net);
88797- struct ctl_table *tbl;
88798+ ctl_table_no_const *tbl;
88799
88800 atomic_set(&ipvs->dropentry, 0);
88801 spin_lock_init(&ipvs->dropentry_lock);
88802diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
88803index fdd89b9..bd96aa9 100644
88804--- a/net/netfilter/ipvs/ip_vs_lblc.c
88805+++ b/net/netfilter/ipvs/ip_vs_lblc.c
88806@@ -115,7 +115,7 @@ struct ip_vs_lblc_table {
88807 * IPVS LBLC sysctl table
88808 */
88809 #ifdef CONFIG_SYSCTL
88810-static ctl_table vs_vars_table[] = {
88811+static ctl_table_no_const vs_vars_table[] __read_only = {
88812 {
88813 .procname = "lblc_expiration",
88814 .data = NULL,
88815diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
88816index c03b6a3..8ce3681 100644
88817--- a/net/netfilter/ipvs/ip_vs_lblcr.c
88818+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
88819@@ -288,7 +288,7 @@ struct ip_vs_lblcr_table {
88820 * IPVS LBLCR sysctl table
88821 */
88822
88823-static ctl_table vs_vars_table[] = {
88824+static ctl_table_no_const vs_vars_table[] __read_only = {
88825 {
88826 .procname = "lblcr_expiration",
88827 .data = NULL,
88828diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
88829index 44fd10c..2a163b3 100644
88830--- a/net/netfilter/ipvs/ip_vs_sync.c
88831+++ b/net/netfilter/ipvs/ip_vs_sync.c
88832@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
88833 cp = cp->control;
88834 if (cp) {
88835 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
88836- pkts = atomic_add_return(1, &cp->in_pkts);
88837+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
88838 else
88839 pkts = sysctl_sync_threshold(ipvs);
88840 ip_vs_sync_conn(net, cp->control, pkts);
88841@@ -758,7 +758,7 @@ control:
88842 if (!cp)
88843 return;
88844 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
88845- pkts = atomic_add_return(1, &cp->in_pkts);
88846+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
88847 else
88848 pkts = sysctl_sync_threshold(ipvs);
88849 goto sloop;
88850@@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
88851
88852 if (opt)
88853 memcpy(&cp->in_seq, opt, sizeof(*opt));
88854- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
88855+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
88856 cp->state = state;
88857 cp->old_state = cp->state;
88858 /*
88859diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
88860index ee6b7a9..f9a89f6 100644
88861--- a/net/netfilter/ipvs/ip_vs_xmit.c
88862+++ b/net/netfilter/ipvs/ip_vs_xmit.c
88863@@ -1210,7 +1210,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
88864 else
88865 rc = NF_ACCEPT;
88866 /* do not touch skb anymore */
88867- atomic_inc(&cp->in_pkts);
88868+ atomic_inc_unchecked(&cp->in_pkts);
88869 goto out;
88870 }
88871
88872@@ -1332,7 +1332,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
88873 else
88874 rc = NF_ACCEPT;
88875 /* do not touch skb anymore */
88876- atomic_inc(&cp->in_pkts);
88877+ atomic_inc_unchecked(&cp->in_pkts);
88878 goto out;
88879 }
88880
88881diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
88882index 7df424e..a527b02 100644
88883--- a/net/netfilter/nf_conntrack_acct.c
88884+++ b/net/netfilter/nf_conntrack_acct.c
88885@@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
88886 #ifdef CONFIG_SYSCTL
88887 static int nf_conntrack_acct_init_sysctl(struct net *net)
88888 {
88889- struct ctl_table *table;
88890+ ctl_table_no_const *table;
88891
88892 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
88893 GFP_KERNEL);
88894diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
88895index e4a0c4f..c263f28 100644
88896--- a/net/netfilter/nf_conntrack_core.c
88897+++ b/net/netfilter/nf_conntrack_core.c
88898@@ -1529,6 +1529,10 @@ err_extend:
88899 #define DYING_NULLS_VAL ((1<<30)+1)
88900 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
88901
88902+#ifdef CONFIG_GRKERNSEC_HIDESYM
88903+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
88904+#endif
88905+
88906 static int nf_conntrack_init_net(struct net *net)
88907 {
88908 int ret;
88909@@ -1543,7 +1547,11 @@ static int nf_conntrack_init_net(struct net *net)
88910 goto err_stat;
88911 }
88912
88913+#ifdef CONFIG_GRKERNSEC_HIDESYM
88914+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
88915+#else
88916 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
88917+#endif
88918 if (!net->ct.slabname) {
88919 ret = -ENOMEM;
88920 goto err_slabname;
88921diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
88922index faa978f..1afb18f 100644
88923--- a/net/netfilter/nf_conntrack_ecache.c
88924+++ b/net/netfilter/nf_conntrack_ecache.c
88925@@ -186,7 +186,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
88926 #ifdef CONFIG_SYSCTL
88927 static int nf_conntrack_event_init_sysctl(struct net *net)
88928 {
88929- struct ctl_table *table;
88930+ ctl_table_no_const *table;
88931
88932 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
88933 GFP_KERNEL);
88934diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
88935index 884f2b3..d53b33a 100644
88936--- a/net/netfilter/nf_conntrack_helper.c
88937+++ b/net/netfilter/nf_conntrack_helper.c
88938@@ -55,7 +55,7 @@ static struct ctl_table helper_sysctl_table[] = {
88939
88940 static int nf_conntrack_helper_init_sysctl(struct net *net)
88941 {
88942- struct ctl_table *table;
88943+ ctl_table_no_const *table;
88944
88945 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
88946 GFP_KERNEL);
88947diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
88948index 51e928d..72a413a 100644
88949--- a/net/netfilter/nf_conntrack_proto.c
88950+++ b/net/netfilter/nf_conntrack_proto.c
88951@@ -51,7 +51,7 @@ nf_ct_register_sysctl(struct net *net,
88952
88953 static void
88954 nf_ct_unregister_sysctl(struct ctl_table_header **header,
88955- struct ctl_table **table,
88956+ ctl_table_no_const **table,
88957 unsigned int users)
88958 {
88959 if (users > 0)
88960diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
88961index e7185c6..4ad6c9c 100644
88962--- a/net/netfilter/nf_conntrack_standalone.c
88963+++ b/net/netfilter/nf_conntrack_standalone.c
88964@@ -470,7 +470,7 @@ static ctl_table nf_ct_netfilter_table[] = {
88965
88966 static int nf_conntrack_standalone_init_sysctl(struct net *net)
88967 {
88968- struct ctl_table *table;
88969+ ctl_table_no_const *table;
88970
88971 if (net_eq(net, &init_net)) {
88972 nf_ct_netfilter_header =
88973diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
88974index 7ea8026..bc9512d 100644
88975--- a/net/netfilter/nf_conntrack_timestamp.c
88976+++ b/net/netfilter/nf_conntrack_timestamp.c
88977@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
88978 #ifdef CONFIG_SYSCTL
88979 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
88980 {
88981- struct ctl_table *table;
88982+ ctl_table_no_const *table;
88983
88984 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
88985 GFP_KERNEL);
88986diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
88987index 9e31269..bc4c1b7 100644
88988--- a/net/netfilter/nf_log.c
88989+++ b/net/netfilter/nf_log.c
88990@@ -215,7 +215,7 @@ static const struct file_operations nflog_file_ops = {
88991
88992 #ifdef CONFIG_SYSCTL
88993 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
88994-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
88995+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
88996 static struct ctl_table_header *nf_log_dir_header;
88997
88998 static int nf_log_proc_dostring(ctl_table *table, int write,
88999@@ -246,14 +246,16 @@ static int nf_log_proc_dostring(ctl_table *table, int write,
89000 rcu_assign_pointer(nf_loggers[tindex], logger);
89001 mutex_unlock(&nf_log_mutex);
89002 } else {
89003+ ctl_table_no_const nf_log_table = *table;
89004+
89005 mutex_lock(&nf_log_mutex);
89006 logger = rcu_dereference_protected(nf_loggers[tindex],
89007 lockdep_is_held(&nf_log_mutex));
89008 if (!logger)
89009- table->data = "NONE";
89010+ nf_log_table.data = "NONE";
89011 else
89012- table->data = logger->name;
89013- r = proc_dostring(table, write, buffer, lenp, ppos);
89014+ nf_log_table.data = logger->name;
89015+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
89016 mutex_unlock(&nf_log_mutex);
89017 }
89018
89019diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
89020index f042ae5..30ea486 100644
89021--- a/net/netfilter/nf_sockopt.c
89022+++ b/net/netfilter/nf_sockopt.c
89023@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
89024 }
89025 }
89026
89027- list_add(&reg->list, &nf_sockopts);
89028+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
89029 out:
89030 mutex_unlock(&nf_sockopt_mutex);
89031 return ret;
89032@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
89033 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
89034 {
89035 mutex_lock(&nf_sockopt_mutex);
89036- list_del(&reg->list);
89037+ pax_list_del((struct list_head *)&reg->list);
89038 mutex_unlock(&nf_sockopt_mutex);
89039 }
89040 EXPORT_SYMBOL(nf_unregister_sockopt);
89041diff --git a/net/netfilter/nfnetlink_acct.c b/net/netfilter/nfnetlink_acct.c
89042index 589d686..dc3fd5d 100644
89043--- a/net/netfilter/nfnetlink_acct.c
89044+++ b/net/netfilter/nfnetlink_acct.c
89045@@ -49,6 +49,8 @@ nfnl_acct_new(struct sock *nfnl, struct sk_buff *skb,
89046 return -EINVAL;
89047
89048 acct_name = nla_data(tb[NFACCT_NAME]);
89049+ if (strlen(acct_name) == 0)
89050+ return -EINVAL;
89051
89052 list_for_each_entry(nfacct, &nfnl_acct_list, head) {
89053 if (strncmp(nfacct->name, acct_name, NFACCT_NAME_MAX) != 0)
89054diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
89055index 92fd8ec..3f6ea4b 100644
89056--- a/net/netfilter/nfnetlink_log.c
89057+++ b/net/netfilter/nfnetlink_log.c
89058@@ -72,7 +72,7 @@ struct nfulnl_instance {
89059 };
89060
89061 static DEFINE_SPINLOCK(instances_lock);
89062-static atomic_t global_seq;
89063+static atomic_unchecked_t global_seq;
89064
89065 #define INSTANCE_BUCKETS 16
89066 static struct hlist_head instance_table[INSTANCE_BUCKETS];
89067@@ -537,7 +537,7 @@ __build_packet_message(struct nfulnl_instance *inst,
89068 /* global sequence number */
89069 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
89070 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
89071- htonl(atomic_inc_return(&global_seq))))
89072+ htonl(atomic_inc_return_unchecked(&global_seq))))
89073 goto nla_put_failure;
89074
89075 if (data_len) {
89076diff --git a/net/netfilter/nfnetlink_queue_core.c b/net/netfilter/nfnetlink_queue_core.c
89077index 3158d87..39006c9 100644
89078--- a/net/netfilter/nfnetlink_queue_core.c
89079+++ b/net/netfilter/nfnetlink_queue_core.c
89080@@ -1064,8 +1064,10 @@ static int __init nfnetlink_queue_init(void)
89081
89082 #ifdef CONFIG_PROC_FS
89083 if (!proc_create("nfnetlink_queue", 0440,
89084- proc_net_netfilter, &nfqnl_file_ops))
89085+ proc_net_netfilter, &nfqnl_file_ops)) {
89086+ status = -ENOMEM;
89087 goto cleanup_subsys;
89088+ }
89089 #endif
89090
89091 register_netdevice_notifier(&nfqnl_dev_notifier);
89092diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
89093new file mode 100644
89094index 0000000..c566332
89095--- /dev/null
89096+++ b/net/netfilter/xt_gradm.c
89097@@ -0,0 +1,51 @@
89098+/*
89099+ * gradm match for netfilter
89100